ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4StateManager.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4StateManager.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 //
28 //
29 // ------------------------------------------------------------
30 // GEANT 4 class implementation file
31 //
32 // ---------------- G4StateManager ----------------
33 // by Gabriele Cosmo, November 1996
34 // ------------------------------------------------------------
35 
36 #include "G4StateManager.hh"
37 #include "G4ios.hh"
38 
39 // Initialization of the static pointer of the single class instance
40 //
43 
45  : theCurrentState(G4State_PreInit),
46  thePreviousState(G4State_PreInit),
47  theBottomDependent(0),
48  suppressAbortion(0),
49  msgptr(0),
50  exceptionHandler(0)
51 {
52 #ifdef G4MULTITHREADED
54 #endif
55 }
56 
58 {
59  G4VStateDependent* state=0;
60 
61  while (theDependentsList.size()>0)
62  {
63  state = theDependentsList.back();
64  theDependentsList.pop_back();
65  for (std::vector<G4VStateDependent*>::iterator
66  i=theDependentsList.begin(); i!=theDependentsList.end();)
67  {
68  if (*i==state)
69  {
70  i = theDependentsList.erase(i);
71  }
72  else
73  {
74  ++i;
75  }
76  }
77  if ( state ) { delete state; }
78  }
79  theStateManager = 0;
80 #ifdef G4MULTITHREADED_DEACTIVATE
82 #endif
83 }
84 
85 // -------------------------------------------------------------------------
86 // No matter how copy-constructor and operators below are implemented ...
87 // just dummy implementations, since not relevant for the singleton and
88 // declared private.
89 //
91  : theCurrentState(right.theCurrentState),
92  thePreviousState(right.thePreviousState),
93  theDependentsList(right.theDependentsList),
94  theBottomDependent(right.theBottomDependent),
95  suppressAbortion(right.suppressAbortion),
96  msgptr(right.msgptr),
97  exceptionHandler(right.exceptionHandler)
98 {
99 }
100 
103 {
104  if (&right == this) { return *this; }
105 
111  msgptr = right.msgptr;
113 
114  return *this;
115 }
116 
117 G4bool
119 {
120  return (this == &right);
121 }
122 
123 G4bool
125 {
126  return (this != &right);
127 }
128 //
129 // -------------------------------------------------------------------------
130 
133 {
134  if (!theStateManager)
135  {
137  }
138  return theStateManager;
139 }
140 
141 G4bool
143 {
144  G4bool ack=true;
145  if(!bottom)
146  {
147  theDependentsList.push_back(aDependent);
148  }
149  else
150  {
152  {
154  }
155  theBottomDependent = aDependent;
156  }
157  return ack;
158 }
159 
160 G4bool
162 {
163  G4VStateDependent* tmp = 0;
164  for (std::vector<G4VStateDependent*>::iterator i=theDependentsList.begin();
165  i!=theDependentsList.end();)
166  {
167  if (**i==*aDependent)
168  {
169  tmp = *i;
170  i = theDependentsList.erase(i);
171  }
172  else
173  {
174  ++i;
175  }
176  }
177  return (tmp != 0);
178 }
179 
180 const G4ApplicationState&
182 {
183  return theCurrentState;
184 }
185 
186 const G4ApplicationState&
188 {
189  return thePreviousState;
190 }
191 
192 G4bool
194 { return SetNewState(requestedState,0); }
195 
196 G4bool
198  const char* msg)
199 {
200  if(requestedState==G4State_Abort && suppressAbortion>0)
201  {
202  if(suppressAbortion==2) { return false; }
203  if(theCurrentState==G4State_EventProc) { return false; }
204  }
205  msgptr = msg;
206  size_t i=0;
207  G4bool ack = true;
210 
211  while ((ack) && (i<theDependentsList.size()))
212  {
213  ack = theDependentsList[i]->Notify(requestedState);
214  i++;
215  }
217  {
218  ack = theBottomDependent->Notify(requestedState);
219  }
220 
221  if(!ack)
222  { thePreviousState = savedState; }
223  else
224  {
225  theCurrentState = requestedState;
226  if(verboseLevel>0)
227  {
228  G4cout<<"#### G4StateManager::SetNewState from "
230  <<GetStateString(requestedState)<<G4endl;
231  }
232  }
233  msgptr = 0;
234  return ack;
235 }
236 
239 {
240  G4VStateDependent* tmp = 0;
241  for (std::vector<G4VStateDependent*>::iterator i=theDependentsList.begin();
242  i!=theDependentsList.end();)
243  {
244  if (**i==*aDependent)
245  {
246  tmp = *i;
247  i = theDependentsList.erase(i);
248  }
249  else
250  {
251  ++i;
252  }
253  }
254  return tmp;
255 }
256 
257 G4String
259 {
260  G4String stateName;
261  switch(aState)
262  {
263  case G4State_PreInit:
264  stateName = "PreInit"; break;
265  case G4State_Init:
266  stateName = "Init"; break;
267  case G4State_Idle:
268  stateName = "Idle"; break;
269  case G4State_GeomClosed:
270  stateName = "GeomClosed"; break;
271  case G4State_EventProc:
272  stateName = "EventProc"; break;
273  case G4State_Quit:
274  stateName = "Quit"; break;
275  case G4State_Abort:
276  stateName = "Abort"; break;
277  default:
278  stateName = "Unknown"; break;
279  }
280  return stateName;
281 }
282 
283 void
285 {
286  verboseLevel = val;
287 }