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5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /global/management/src/G4StateManager.cc (Version 11.3.0) and /global/management/src/G4StateManager.cc (Version 3.0)


                                                   >>   1 // This code implementation is the intellectual property of
                                                   >>   2 // the GEANT4 collaboration.
  1 //                                                  3 //
  2 // ******************************************* <<   4 // By copying, distributing or modifying the Program (or any work
  3 // * License and Disclaimer                    <<   5 // based on the Program) you indicate your acceptance of this statement,
  4 // *                                           <<   6 // and all its terms.
  5 // * The  Geant4 software  is  copyright of th << 
  6 // * the Geant4 Collaboration.  It is provided << 
  7 // * conditions of the Geant4 Software License << 
  8 // * LICENSE and available at  http://cern.ch/ << 
  9 // * include a list of copyright holders.      << 
 10 // *                                           << 
 11 // * Neither the authors of this software syst << 
 12 // * institutes,nor the agencies providing fin << 
 13 // * work  make  any representation or  warran << 
 14 // * regarding  this  software system or assum << 
 15 // * use.  Please see the license in the file  << 
 16 // * for the full disclaimer and the limitatio << 
 17 // *                                           << 
 18 // * This  code  implementation is the result  << 
 19 // * technical work of the GEANT4 collaboratio << 
 20 // * By using,  copying,  modifying or  distri << 
 21 // * any work based  on the software)  you  ag << 
 22 // * use  in  resulting  scientific  publicati << 
 23 // * acceptance of all terms of the Geant4 Sof << 
 24 // ******************************************* << 
 25 //                                                  7 //
 26 // G4StateManager class implementation         <<   8 // $Id: G4StateManager.cc,v 1.2 2000/11/20 17:26:49 gcosmo Exp $
                                                   >>   9 // GEANT4 tag $Name: geant4-03-00 $
 27 //                                                 10 //
 28 // Authors: G.Cosmo, M.Asai - November 1996    <<  11 // 
 29 // ------------------------------------------- <<  12 // ------------------------------------------------------------
                                                   >>  13 //      GEANT 4 class implementation file 
                                                   >>  14 //
                                                   >>  15 //      For information related to this code contact:
                                                   >>  16 //      Geant4 Collaboration
                                                   >>  17 //      ---------------- G4StateManager ----------------
                                                   >>  18 //             by Gabriele Cosmo, November 1996
                                                   >>  19 // ------------------------------------------------------------
 30                                                    20 
 31 #include "G4StateManager.hh"                       21 #include "G4StateManager.hh"
 32 #include "G4ios.hh"                            << 
 33                                                    22 
 34 // Initialization of the static pointer of the     23 // Initialization of the static pointer of the single class instance
 35 //                                             <<  24 G4StateManager* G4StateManager::theStateManager = 0;
 36 G4ThreadLocal G4StateManager* G4StateManager:: << 
 37 G4int G4StateManager::verboseLevel             << 
 38                                                    25 
 39 // ------------------------------------------- << 
 40 G4StateManager::G4StateManager()                   26 G4StateManager::G4StateManager()
 41 {                                              <<  27 :theCurrentState(PreInit),thePreviousState(PreInit) 
 42 #ifdef G4MULTITHREADED                         <<  28 { theBottomDependent = 0; }
 43   G4iosInitialization();                       << 
 44 #endif                                         << 
 45 }                                              << 
 46                                                    29 
 47 G4StateManager::~G4StateManager()                  30 G4StateManager::~G4StateManager()
 48 {                                                  31 {
 49   G4VStateDependent* state = nullptr;          <<  32    theDependentsList.clearAndDestroy();
                                                   >>  33 }
 50                                                    34 
 51   while(!theDependentsList.empty())            <<  35 G4StateManager::G4StateManager(const G4StateManager &right)
 52   {                                            <<  36   : theCurrentState(right.theCurrentState),
 53     state = theDependentsList.back();          <<  37     thePreviousState(right.thePreviousState),
 54     theDependentsList.pop_back();              <<  38     theDependentsList(right.theDependentsList),
 55     for(auto i = theDependentsList.cbegin(); i <<  39     theBottomDependent(right.theBottomDependent)
 56     {                                          <<  40 {
 57       if(*i == state)                          << 
 58       {                                        << 
 59         i = theDependentsList.erase(i);        << 
 60       }                                        << 
 61       else                                     << 
 62       {                                        << 
 63         ++i;                                   << 
 64       }                                        << 
 65     }                                          << 
 66     delete state;                              << 
 67   }                                            << 
 68   theStateManager = nullptr;                   << 
 69 #ifdef G4MULTITHREADED_DEACTIVATE              << 
 70   G4iosFinalization();                         << 
 71 #endif                                         << 
 72 }                                                  41 }
 73                                                    42 
 74 // ------------------------------------------- <<  43 G4StateManager& G4StateManager::operator=(const G4StateManager &right)
 75 G4StateManager* G4StateManager::GetStateManage << 
 76 {                                                  44 {
 77   if(theStateManager == nullptr)               <<  45    if (&right == this) return *this;
 78   {                                            <<  46 
 79     theStateManager = new G4StateManager;      <<  47    theCurrentState = right.theCurrentState;
 80   }                                            <<  48    thePreviousState = right.thePreviousState;
 81   return theStateManager;                      <<  49    theDependentsList = right.theDependentsList;
                                                   >>  50    theBottomDependent = right.theBottomDependent;
                                                   >>  51 
                                                   >>  52    return *this;
 82 }                                                  53 }
 83                                                    54 
 84 // ------------------------------------------- <<  55 G4int G4StateManager::operator==(const G4StateManager &right) const
 85 G4bool G4StateManager::RegisterDependent(G4VSt << 
 86                                          G4boo << 
 87 {                                                  56 {
 88   G4bool ack = true;                           <<  57    return (this == &right);
 89   if(!bottom)                                  << 
 90   {                                            << 
 91     theDependentsList.push_back(aDependent);   << 
 92   }                                            << 
 93   else                                         << 
 94   {                                            << 
 95     if(theBottomDependent != nullptr)          << 
 96     {                                          << 
 97       theDependentsList.push_back(theBottomDep << 
 98     }                                          << 
 99     theBottomDependent = aDependent;           << 
100   }                                            << 
101   return ack;                                  << 
102 }                                                  58 }
103                                                    59 
104 // ------------------------------------------- <<  60 G4int G4StateManager::operator!=(const G4StateManager &right) const
105 G4bool G4StateManager::DeregisterDependent(G4V << 
106 {                                                  61 {
107   G4VStateDependent* tmp = nullptr;            <<  62    return (this != &right);
108   for(auto i = theDependentsList.cbegin(); i ! << 
109   {                                            << 
110     if(**i == *aDependent)                     << 
111     {                                          << 
112       tmp = *i;                                << 
113       i   = theDependentsList.erase(i);        << 
114     }                                          << 
115     else                                       << 
116     {                                          << 
117       ++i;                                     << 
118     }                                          << 
119   }                                            << 
120   return (tmp != nullptr);                     << 
121 }                                                  63 }
122                                                    64 
123 // ------------------------------------------- <<  65 
124 const G4ApplicationState& G4StateManager::GetC <<  66 G4StateManager* G4StateManager::GetStateManager()
125 {                                                  67 {
126   return theCurrentState;                      <<  68     if (!theStateManager)
                                                   >>  69         {
                                                   >>  70             theStateManager = new G4StateManager;
                                                   >>  71         }
                                                   >>  72     return theStateManager;    
                                                   >>  73 }
                                                   >>  74 
                                                   >>  75 G4bool G4StateManager::RegisterDependent(G4VStateDependent* aDependent,G4bool bottom)
                                                   >>  76 {
                                                   >>  77    G4bool ack=true;
                                                   >>  78    if(!bottom)
                                                   >>  79    { theDependentsList.insert(aDependent); }
                                                   >>  80    else
                                                   >>  81    { 
                                                   >>  82      if(theBottomDependent)
                                                   >>  83      { theDependentsList.insert(theBottomDependent); }
                                                   >>  84      theBottomDependent = aDependent;
                                                   >>  85    }
                                                   >>  86    return ack;
127 }                                                  87 }
128                                                    88 
129 // ------------------------------------------- <<  89 G4bool G4StateManager::DeregisterDependent(G4VStateDependent* aDependent)
130 const G4ApplicationState& G4StateManager::GetP << 
131 {                                                  90 {
132   return thePreviousState;                     <<  91    G4VStateDependent* aD = theDependentsList.remove(aDependent);
                                                   >>  92    return (aD != NULL);
133 }                                                  93 }
134                                                    94 
135 // ------------------------------------------- <<  95 G4ApplicationState G4StateManager::GetCurrentState()
136 G4bool G4StateManager::SetNewState(const G4App << 
137 {                                                  96 {
138   return SetNewState(requestedState, nullptr); <<  97    return theCurrentState;
139 }                                                  98 }
140                                                    99 
141 // ------------------------------------------- << 100 G4ApplicationState G4StateManager::GetPreviousState()
142 G4bool G4StateManager::SetNewState(const G4App << 
143                                    const char* << 
144 {                                                 101 {
145   if(requestedState == G4State_Abort && suppre << 102    return thePreviousState;
146   {                                            << 103 }
147     if(suppressAbortion == 2)                  << 
148     {                                          << 
149       return false;                            << 
150     }                                          << 
151     if(theCurrentState == G4State_EventProc)   << 
152     {                                          << 
153       return false;                            << 
154     }                                          << 
155   }                                            << 
156   msgptr                        = msg;         << 
157   std::size_t i                 = 0;           << 
158   G4bool ack                    = true;        << 
159   G4ApplicationState savedState = thePreviousS << 
160   thePreviousState              = theCurrentSt << 
161                                                   104 
162   while((ack) && (i < theDependentsList.size() << 105 G4bool G4StateManager::SetNewState(G4ApplicationState requestedState)
163   {                                            << 106 {
164     ack = theDependentsList[i]->Notify(request << 107    size_t i=0;
165     ++i;                                       << 108    G4bool ack = true;
166   }                                            << 109    G4ApplicationState savedState = thePreviousState;
167   if(theBottomDependent != nullptr)            << 110    thePreviousState = theCurrentState;
168   {                                            << 111    theCurrentState = requestedState;
169     ack = theBottomDependent->Notify(requested << 112    while ((ack) && (i<theDependentsList.entries())) {
170   }                                            << 113      ack = theDependentsList(i)->Notify(requestedState);
                                                   >> 114      i++;
                                                   >> 115    }
                                                   >> 116    if(theBottomDependent)
                                                   >> 117    { ack = theBottomDependent->Notify(requestedState); }
171                                                   118 
172   if(!ack)                                     << 119    if(!ack)
173   {                                            << 120    {
174     thePreviousState = savedState;             << 121      theCurrentState = thePreviousState;
175   }                                            << 122      thePreviousState = savedState;
176   else                                         << 123    }
177   {                                            << 124    return ack;
178     theCurrentState = requestedState;          << 
179     if(verboseLevel > 0)                       << 
180     {                                          << 
181       G4cout << "#### G4StateManager::SetNewSt << 
182              << GetStateString(thePreviousStat << 
183              << GetStateString(requestedState) << 
184     }                                          << 
185   }                                            << 
186   msgptr = nullptr;                            << 
187   return ack;                                  << 
188 }                                                 125 }
189                                                   126 
190 // ------------------------------------------- << 127 G4VStateDependent* G4StateManager::RemoveDependent(const G4VStateDependent* aDependent)
191 G4VStateDependent* G4StateManager::RemoveDepen << 
192   const G4VStateDependent* aDependent)         << 
193 {                                                 128 {
194   G4VStateDependent* tmp = nullptr;            << 129    return theDependentsList.remove(aDependent);
195   for(auto i = theDependentsList.cbegin(); i ! << 
196   {                                            << 
197     if(**i == *aDependent)                     << 
198     {                                          << 
199       tmp = *i;                                << 
200       i   = theDependentsList.erase(i);        << 
201     }                                          << 
202     else                                       << 
203     {                                          << 
204       ++i;                                     << 
205     }                                          << 
206   }                                            << 
207   return tmp;                                  << 
208 }                                                 130 }
209                                                   131 
210 // ------------------------------------------- << 132 G4String G4StateManager::GetStateString(G4ApplicationState aState)
211 G4String G4StateManager::GetStateString(const  << 
212 {                                                 133 {
213   G4String stateName;                             134   G4String stateName;
214   switch(aState)                                  135   switch(aState)
215   {                                               136   {
216     case G4State_PreInit:                      << 137     case PreInit:
217       stateName = "PreInit";                   << 138      stateName = "PreInit"; break;
218       break;                                   << 139     case Init:
219     case G4State_Init:                         << 140      stateName = "Init"; break;
220       stateName = "Init";                      << 141     case Idle:
221       break;                                   << 142      stateName = "Idle"; break;
222     case G4State_Idle:                         << 143     case GeomClosed:
223       stateName = "Idle";                      << 144      stateName = "GeomClosed"; break;
224       break;                                   << 145     case EventProc:
225     case G4State_GeomClosed:                   << 146      stateName = "EventProc"; break;
226       stateName = "GeomClosed";                << 147     case Quit:
227       break;                                   << 148      stateName = "Quit"; break;
228     case G4State_EventProc:                    << 149     case Abort:
229       stateName = "EventProc";                 << 150      stateName = "Abort"; break;
230       break;                                   << 
231     case G4State_Quit:                         << 
232       stateName = "Quit";                      << 
233       break;                                   << 
234     case G4State_Abort:                        << 
235       stateName = "Abort";                     << 
236       break;                                   << 
237     default:                                      151     default:
238       stateName = "Unknown";                   << 152      stateName = "Unknown";
239       break;                                   << 
240   }                                               153   }
241   return stateName;                               154   return stateName;
242 }                                                 155 }
243                                                   156 
244 // ------------------------------------------- << 157 //void G4StateManager::Pause()
245 void G4StateManager::SetVerboseLevel(G4int val << 158 //{
246                                                << 159 //  Pause("G4_pause> ");
247 // ------------------------------------------- << 160 //}
248 void G4StateManager::NotifyDeletion(const G4Ev << 161 //
249 {                                              << 162 //void G4StateManager::Pause(const char* msg)
250   for(auto& d : theDependentsList)             << 163 //{
251   { d->NotifyDeletion(evt); }                  << 164 //  G4String msgS = msg;
252 }                                              << 165 //  Pause(msgS);
                                                   >> 166 //}
                                                   >> 167 //
                                                   >> 168 //void G4StateManager::Pause(G4String msg)
                                                   >> 169 //{
                                                   >> 170 //  G4UImanager::GetUIpointer()->PauseSession(msg);
                                                   >> 171 //}
253                                                   172 
254 // ------------------------------------------- << 
255 void G4StateManager::NotifyDeletion(const G4Ru << 
256 {                                              << 
257   for(auto& d : theDependentsList)             << 
258   { d->NotifyDeletion(rn); }                   << 
259 }                                              << 
260                                                   173