Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
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 // $Id: G4StateManager.cc 108402 2018-02-12 10:31:27Z gcosmo $
28 //
29 //
30 // ------------------------------------------------------------
31 // GEANT 4 class implementation file
32 //
33 // ---------------- G4StateManager ----------------
34 // by Gabriele Cosmo, November 1996
35 // ------------------------------------------------------------
36 
37 #include "G4StateManager.hh"
38 #include "G4ios.hh"
39 
40 // Initialization of the static pointer of the single class instance
41 //
44 
46  : theCurrentState(G4State_PreInit),
47  thePreviousState(G4State_PreInit),
48  theBottomDependent(0),
49  suppressAbortion(0),
50  msgptr(0),
51  exceptionHandler(0)
52 {
53 #ifdef G4MULTITHREADED
55 #endif
56 }
57 
59 {
60  G4VStateDependent* state=0;
61 
62  while (theDependentsList.size()>0)
63  {
64  state = theDependentsList.back();
65  theDependentsList.pop_back();
66  for (std::vector<G4VStateDependent*>::iterator
67  i=theDependentsList.begin(); i!=theDependentsList.end();)
68  {
69  if (*i==state)
70  {
71  i = theDependentsList.erase(i);
72  }
73  else
74  {
75  ++i;
76  }
77  }
78  if ( state ) { delete state; }
79  }
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 G4int
119 {
120  return (this == &right);
121 }
122 
123 G4int
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 
182 {
183  return theCurrentState;
184 }
185 
188 {
189  return thePreviousState;
190 }
191 
192 G4bool
194 { return SetNewState(requestedState,0); }
195 
196 G4bool
197 G4StateManager::SetNewState(G4ApplicationState requestedState, const char* msg)
198 {
199  if(requestedState==G4State_Abort && suppressAbortion>0)
200  {
201  if(suppressAbortion==2) { return false; }
202  if(theCurrentState==G4State_EventProc) { return false; }
203  }
204  msgptr = msg;
205  size_t i=0;
206  G4bool ack = true;
209 
210  while ((ack) && (i<theDependentsList.size()))
211  {
212  ack = theDependentsList[i]->Notify(requestedState);
213  i++;
214  }
216  {
217  ack = theBottomDependent->Notify(requestedState);
218  }
219 
220  if(!ack)
221  { thePreviousState = savedState; }
222  else
223  {
224  theCurrentState = requestedState;
225  if(verboseLevel>0)
226  {
227  G4cout<<"#### G4StateManager::SetNewState from "
229  <<GetStateString(requestedState)<<G4endl;
230  }
231  }
232  msgptr = 0;
233  return ack;
234 }
235 
238 {
239  G4VStateDependent* tmp = 0;
240  for (std::vector<G4VStateDependent*>::iterator i=theDependentsList.begin();
241  i!=theDependentsList.end();)
242  {
243  if (**i==*aDependent)
244  {
245  tmp = *i;
246  i = theDependentsList.erase(i);
247  }
248  else
249  {
250  ++i;
251  }
252  }
253  return tmp;
254 }
255 
256 G4String
258 {
259  G4String stateName;
260  switch(aState)
261  {
262  case G4State_PreInit:
263  stateName = "PreInit"; break;
264  case G4State_Init:
265  stateName = "Init"; break;
266  case G4State_Idle:
267  stateName = "Idle"; break;
268  case G4State_GeomClosed:
269  stateName = "GeomClosed"; break;
270  case G4State_EventProc:
271  stateName = "EventProc"; break;
272  case G4State_Quit:
273  stateName = "Quit"; break;
274  case G4State_Abort:
275  stateName = "Abort"; break;
276  default:
277  stateName = "Unknown"; break;
278  }
279  return stateName;
280 }
281 
282 void
284 {
285  verboseLevel = val;
286 }
287 
288 //void G4StateManager::Pause()
289 //{
290 // Pause("G4_pause> ");
291 //}
292 //
293 //void G4StateManager::Pause(const char* msg)
294 //{
295 // G4String msgS = msg;
296 // Pause(msgS);
297 //}
298 //
299 //void G4StateManager::Pause(G4String msg)
300 //{
301 // G4UImanager::GetUIpointer()->PauseSession(msg);
302 //}
static void SetVerboseLevel(G4int val)
G4bool SetNewState(G4ApplicationState requestedState)
#define G4endl
Definition: G4ios.hh:61
void G4iosInitialization()
Definition: G4ios.cc:107
const char * msgptr
G4ApplicationState thePreviousState
static G4int verboseLevel
G4int operator!=(const G4StateManager &right) const
Float_t tmp
static G4ThreadLocal G4StateManager * theStateManager
#define G4ThreadLocal
Definition: tls.hh:69
void G4iosFinalization()
Definition: G4ios.cc:108
bool G4bool
Definition: G4Types.hh:79
G4VStateDependent * theBottomDependent
G4bool RegisterDependent(G4VStateDependent *aDependent, G4bool bottom=false)
G4String GetStateString(G4ApplicationState aState) const
G4ApplicationState theCurrentState
G4int operator==(const G4StateManager &right) const
int G4int
Definition: G4Types.hh:78
std::vector< G4VStateDependent * > theDependentsList
G4VExceptionHandler * exceptionHandler
G4ApplicationState GetCurrentState() const
G4ApplicationState GetPreviousState() const
G4StateManager & operator=(const G4StateManager &right)
virtual G4bool Notify(G4ApplicationState requestedState)=0
G4GLOB_DLL std::ostream G4cout
G4VStateDependent * RemoveDependent(const G4VStateDependent *aDependent)
G4ApplicationState
G4bool DeregisterDependent(G4VStateDependent *aDependent)
static G4StateManager * GetStateManager()