Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/processes/electromagnetic/dna/management/src/G4Scheduler.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.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 /processes/electromagnetic/dna/management/src/G4Scheduler.cc (Version 11.3.0) and /processes/electromagnetic/dna/management/src/G4Scheduler.cc (Version 10.1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
                                                   >>  26 // $Id: G4Scheduler.cc 60494 2012-07-12 14:49:30Z gcosmo $
 26 //                                                 27 //
 27 // Author: Mathieu Karamitros (kara (AT) cenbg     28 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr)
 28 //                                                 29 //
 29 // History:                                        30 // History:
 30 // -----------                                     31 // -----------
 31 // 10 Oct 2011 M.Karamitros created                32 // 10 Oct 2011 M.Karamitros created
 32 //                                                 33 //
 33 // -------------------------------------------     34 // -------------------------------------------------------------------
 34                                                    35 
 35 #include "G4ITGun.hh"                          <<  36 #include <G4AllITFinder.hh>
 36 #include "G4ITModelHandler.hh"                 <<  37 #include <G4Scheduler.hh>
                                                   >>  38 #include <G4SchedulerMessenger.hh>
                                                   >>  39 
                                                   >>  40 #include "G4SystemOfUnits.hh"
 37 #include "G4ITModelProcessor.hh"                   41 #include "G4ITModelProcessor.hh"
 38 #include "G4ITStepProcessor.hh"                    42 #include "G4ITStepProcessor.hh"
 39 #include "G4ITStepStatus.hh"                   <<  43 #include "G4IT.hh"
 40 #include "G4ITTrackingInteractivity.hh"        <<  44 #include "G4ITReactionChange.hh"
                                                   >>  45 #include "G4ITModelHandler.hh"
                                                   >>  46 #include "G4VITStepModel.hh"
                                                   >>  47 #include "G4UserTimeStepAction.hh"
 41 #include "G4ITTrackingManager.hh"                  48 #include "G4ITTrackingManager.hh"
 42 #include "G4IosFlagsSaver.hh"                  <<  49 #include "G4ITTrackingInteractivity.hh"
 43 #include "G4StateManager.hh"                   << 
 44 #include "G4SystemOfUnits.hh"                  << 
 45 #include "G4Timer.hh"                          << 
 46 #include "G4TrackingInformation.hh"                50 #include "G4TrackingInformation.hh"
 47 #include "G4UnitsTable.hh"                         51 #include "G4UnitsTable.hh"
 48 #include "G4UserTimeStepAction.hh"             <<  52 #include "G4ITStepStatus.hh"
 49 #include "G4VITStepModel.hh"                   <<  53 #include "G4ITGun.hh"
 50                                                <<  54 #include "G4StateManager.hh"
 51 #include <G4AllITFinder.hh>                    <<  55 #include "G4Timer.hh"
 52 #include <G4Scheduler.hh>                      << 
 53 #include <G4SchedulerMessenger.hh>             << 
 54                                                << 
 55 #include <sstream>                                 56 #include <sstream>
 56                                                    57 
                                                   >>  58 //#define DEBUG_MEM 1
 57 #define DEBUG_MEM_STEPPING                         59 #define DEBUG_MEM_STEPPING
 58 #define DEBUG_MEM_DETAILED_STEPPING                60 #define DEBUG_MEM_DETAILED_STEPPING
                                                   >>  61 //#define DEBUG_MEM_DOIT
 59                                                    62 
 60 #ifdef DEBUG_MEM                                   63 #ifdef DEBUG_MEM
 61 #  include "G4MemStat.hh"                      <<  64 #include "G4MemStat.hh"
 62 using namespace G4MemStat;                         65 using namespace G4MemStat;
 63 using G4MemStat::MemStat;                          66 using G4MemStat::MemStat;
 64 #endif                                             67 #endif
 65                                                    68 
                                                   >>  69 //COLOR FOR DEBUGING
                                                   >>  70 //#define USE_COLOR 1
                                                   >>  71 
 66 #ifdef USE_COLOR                                   72 #ifdef USE_COLOR
 67 #  define RED "\033[0;31m"                     <<  73 #define RED  "\033[0;31m"
 68 #  define LIGHT_RED "\33[1;31m"                <<  74 #define LIGHT_RED  "\33[1;31m"
 69 #  define GREEN "\033[32;40m"                  <<  75 #define GREEN "\033[32;40m"
 70 #  define GREEN_ON_BLUE "\033[1;32;44m"        <<  76 #define GREEN_ON_BLUE "\033[1;32;44m"
 71 #  define RESET_COLOR "\033[0m"                <<  77 #define RESET_COLOR "\033[0m"
 72 #else                                              78 #else
 73 #  define RED ""                               <<  79 #define RED  ""
 74 #  define LIGHT_RED ""                         <<  80 #define LIGHT_RED  ""
 75 #  define GREEN ""                             <<  81 #define GREEN ""
 76 #  define GREEN_ON_BLUE ""                     <<  82 #define GREEN_ON_BLUE ""
 77 #  define RESET_COLOR ""                       <<  83 #define RESET_COLOR ""
 78 #endif                                             84 #endif
 79                                                    85 
 80 using namespace std;                               86 using namespace std;
 81                                                    87 
 82 G4ThreadLocal G4Scheduler* G4Scheduler::fgSche <<  88 G4ThreadLocal G4Scheduler* G4Scheduler::fgScheduler(0);
 83                                                    89 
 84 template<typename T>                           <<  90 class IosFlagSaver
 85 inline G4bool IsInf(T value)                   << 
 86 {                                                  91 {
 87   return std::numeric_limits<T>::has_infinity  <<  92 public:
 88 }                                              <<  93   explicit IosFlagSaver(std::ostream& _ios) :
                                                   >>  94       ios(_ios), f(_ios.flags())
                                                   >>  95   {
                                                   >>  96   }
                                                   >>  97   ~IosFlagSaver()
                                                   >>  98   {
                                                   >>  99     ios.flags(f);
                                                   >> 100   }
                                                   >> 101 
                                                   >> 102   // IosFlagSaver(const IosFlagSaver &rhs) = delete;
                                                   >> 103   // IosFlagSaver& operator= (const IosFlagSaver& rhs) = delete;
                                                   >> 104 
                                                   >> 105 private:
                                                   >> 106   std::ostream& ios;
                                                   >> 107   std::ios::fmtflags f;
                                                   >> 108 };
                                                   >> 109 
                                                   >> 110 template<typename T>
                                                   >> 111   inline bool IsInf(T value)
                                                   >> 112   {
                                                   >> 113     return std::numeric_limits<T>::has_infinity
                                                   >> 114         && value == std::numeric_limits<T>::infinity();
                                                   >> 115   }
 89 //____________________________________________    116 //_________________________________________________________________________
 90                                                   117 
 91 G4Scheduler* G4Scheduler::Instance()              118 G4Scheduler* G4Scheduler::Instance()
 92 {                                                 119 {
 93   if (fgScheduler == nullptr) fgScheduler = ne << 120   if (fgScheduler == 0) fgScheduler = new G4Scheduler();
 94   return fgScheduler;                             121   return fgScheduler;
 95 }                                                 122 }
 96 //____________________________________________    123 //_________________________________________________________________________
 97                                                   124 
 98 G4bool G4Scheduler::Notify(G4ApplicationState     125 G4bool G4Scheduler::Notify(G4ApplicationState requestedState)
 99 {                                                 126 {
100   if (requestedState == G4State_Quit) {        << 127   if (requestedState == G4State_Quit)
101     if (fVerbose >= 4) {                       << 128   {
                                                   >> 129     if (fVerbose >= 4)
                                                   >> 130     {
102       G4cout << "G4Scheduler received G4State_    131       G4cout << "G4Scheduler received G4State_Quit" << G4endl;
103     }                                             132     }
104     Clear();                                      133     Clear();
                                                   >> 134     //DeleteInstance();
105   }                                               135   }
106   return true;                                    136   return true;
107 }                                                 137 }
108 //____________________________________________    138 //_________________________________________________________________________
109                                                   139 
110 void G4Scheduler::DeleteInstance()                140 void G4Scheduler::DeleteInstance()
111 {                                                 141 {
112   delete fgScheduler;                          << 142   if (fgScheduler)
                                                   >> 143   {
                                                   >> 144     delete fgScheduler;
                                                   >> 145   }
113 }                                                 146 }
114 //____________________________________________    147 //_________________________________________________________________________
115                                                   148 
116 G4Scheduler::G4Scheduler() : fTrackContainer(( << 149 G4Scheduler::G4Scheduler() :
                                                   >> 150     G4VScheduler(), G4VStateDependent(),
                                                   >> 151     fTrackContainer((G4ITTrackHolder&)*G4ITTrackHolder::Instance())
117 {                                                 152 {
118   Create();                                       153   Create();
119 }                                                 154 }
120                                                   155 
121 void G4Scheduler::Create()                        156 void G4Scheduler::Create()
122 {                                                 157 {
123   fUseDefaultTimeSteps = true;                    158   fUseDefaultTimeSteps = true;
124   fUserUpperTimeLimit = -1;                       159   fUserUpperTimeLimit = -1;
125   fpGun = nullptr;                             << 160   fpGun = 0;
126   fContinue = true;                               161   fContinue = true;
127   fpTrackingInteractivity = nullptr;           << 162 //  fpMainList = 0;
                                                   >> 163 //  fpWaitingList = 0;
                                                   >> 164   fpTrackingInteractivity = 0;
                                                   >> 165 
128   fITStepStatus = eUndefined;                     166   fITStepStatus = eUndefined;
129   fpUserTimeSteps = nullptr;                   << 167 
                                                   >> 168   fpUserTimeSteps = 0;
                                                   >> 169 
130   fTimeStep = DBL_MAX;                            170   fTimeStep = DBL_MAX;
131   fTSTimeStep = DBL_MAX;                          171   fTSTimeStep = DBL_MAX;
132   fILTimeStep = DBL_MAX;                          172   fILTimeStep = DBL_MAX;
133   fPreviousTimeStep = DBL_MAX;                    173   fPreviousTimeStep = DBL_MAX;
                                                   >> 174 
134   fZeroTimeCount = 0;                             175   fZeroTimeCount = 0;
135   fMaxNZeroTimeStepsAllowed = 10000;           << 176   fMaxNZeroTimeStepsAllowed = 10;
                                                   >> 177 
136   fStartTime = 0;                                 178   fStartTime = 0;
                                                   >> 179   fComputeTimeStep = false;
                                                   >> 180   fComputeReaction = false;
137   fTimeTolerance = 1 * picosecond;                181   fTimeTolerance = 1 * picosecond;
138   fEndTime = 1 * microsecond;                     182   fEndTime = 1 * microsecond;
139   fGlobalTime = -1;                               183   fGlobalTime = -1;
140   fInteractionStep = true;                        184   fInteractionStep = true;
141   fUsePreDefinedTimeSteps = false;                185   fUsePreDefinedTimeSteps = false;
142                                                   186 
143   fDefaultMinTimeStep = 1 * picosecond;           187   fDefaultMinTimeStep = 1 * picosecond;
144   fpStepProcessor = nullptr;                   << 188 
145   fpModelProcessor = nullptr;                  << 189   fpStepProcessor = 0;
                                                   >> 190   //    fpMasterStepProcessor = 0 ;
                                                   >> 191 
                                                   >> 192   fpModelProcessor = 0;
                                                   >> 193   //    fpMasterModelProcessor= 0;
                                                   >> 194 
146   fNbSteps = 0;                                   195   fNbSteps = 0;
147   fMaxSteps = -1;                                 196   fMaxSteps = -1;
                                                   >> 197 
148   fRunning = false;                               198   fRunning = false;
149   fInitialized = false;                           199   fInitialized = false;
150   fpUserTimeStepAction = nullptr;              << 200 
                                                   >> 201   fpUserTimeStepAction = 0;
                                                   >> 202   fpTrackingManager = 0;
                                                   >> 203 
                                                   >> 204   fNbTracks = -1;
151   fpModelHandler = new G4ITModelHandler();        205   fpModelHandler = new G4ITModelHandler();
152   fpTrackingManager = new G4ITTrackingManager(    206   fpTrackingManager = new G4ITTrackingManager();
                                                   >> 207 
153   fVerbose = 0;                                   208   fVerbose = 0;
154   fWhyDoYouStop = false;                          209   fWhyDoYouStop = false;
155   fDefinedMinTimeStep = -1.;                      210   fDefinedMinTimeStep = -1.;
156   fReachedUserTimeLimit = false;                  211   fReachedUserTimeLimit = false;
157   fStopTime = -1.;                             << 212   fTmpEndTime = -1.;
158   fpMessenger = new G4SchedulerMessenger(this) << 213   fTmpGlobalTime = -1.;
159   fReactionSet = G4ITReactionSet::Instance();  << 214 
160   fMaxTimeStep = DBL_MAX;                      << 215   fSteppingMsg = new G4SchedulerMessenger(this);
161   // hoang add                                 << 216 
162   fResetScavenger = true;  // true by default  << 
163   G4ITTypeManager::Instance()->ReserveRessourc    217   G4ITTypeManager::Instance()->ReserveRessource();
164 }                                                 218 }
165                                                   219 
166 //____________________________________________    220 //_________________________________________________________________________
167                                                   221 
168 G4Scheduler::~G4Scheduler()                       222 G4Scheduler::~G4Scheduler()
169 {                                                 223 {
170   if (fpMessenger != nullptr)  // is used as a << 224 
                                                   >> 225   if (fSteppingMsg) // is used as a flag to know whether the manager was cleared
171   {                                               226   {
172     Clear();                                      227     Clear();
173   }                                               228   }
174   fgScheduler = nullptr;                       << 229   fgScheduler = 0;
                                                   >> 230 
                                                   >> 231 //  if (fVerbose >= 1)
                                                   >> 232 //  {
                                                   >> 233 //    G4cout << "G4Scheduler is being deleted. Bye :) !" << G4endl;
                                                   >> 234 //  }
175 }                                                 235 }
176                                                   236 
177 void G4Scheduler::Clear()                         237 void G4Scheduler::Clear()
178 {                                                 238 {
179   if (fpMessenger != nullptr) {                << 239 //  if (fVerbose) G4cout << "*** G4Scheduler is being cleared ***" << G4endl;
180     delete fpMessenger;                        << 240 
181     fpMessenger = nullptr;                     << 241   if(fSteppingMsg)
                                                   >> 242   {
                                                   >> 243     delete fSteppingMsg;
                                                   >> 244     fSteppingMsg = 0;
182   }                                               245   }
183   if (fpStepProcessor != nullptr) {            << 246   if(fpStepProcessor)
                                                   >> 247   {
184     delete fpStepProcessor;                       248     delete fpStepProcessor;
185     fpStepProcessor = nullptr;                 << 249     fpStepProcessor = 0;
186   }                                               250   }
187   if (fpModelProcessor != nullptr) {           << 251   if(fpModelProcessor)
                                                   >> 252   {
188     delete fpModelProcessor;                      253     delete fpModelProcessor;
189     fpModelProcessor = nullptr;                << 254     fpModelProcessor = 0;
190   }                                               255   }
191                                                << 256   if(fpModelHandler)
192   G4ITTypeManager::Instance()->ReleaseRessourc << 257   {
                                                   >> 258     delete fpModelHandler;
                                                   >> 259     fpModelHandler = 0;
                                                   >> 260   }
                                                   >> 261   //    if(fpMasterStepProcessor) delete fpMasterStepProcessor ;
                                                   >> 262   //    if(fpMasterModelProcessor) delete fpMasterModelProcessor ;
                                                   >> 263   G4ITTypeManager::Instance() -> ReleaseRessource();
193   ClearList();                                    264   ClearList();
194   if (fpTrackingManager != nullptr) {          << 265   if(fpTrackingManager)
                                                   >> 266   {
195     delete fpTrackingManager;                     267     delete fpTrackingManager;
196     fpTrackingManager = nullptr;               << 268     fpTrackingManager = 0;
197   }                                            << 
198                                                << 
199   if (fReactionSet != nullptr) {               << 
200     delete fReactionSet;                       << 
201     fReactionSet = nullptr;                    << 
202   }                                               269   }
203                                                   270 
204   if (fpModelHandler != nullptr) {             << 271   /*
205     delete fpModelHandler;                     << 272    * DEBUG
206     fpModelHandler = nullptr;                  << 273    * assert(G4StateManager::GetStateManager()->
207   }                                            << 274    * DeregisterDependent(this) == true);
                                                   >> 275    */
208 }                                                 276 }
209                                                   277 
210 //____________________________________________    278 //_________________________________________________________________________
211                                                   279 
212 void G4Scheduler::ClearList()                     280 void G4Scheduler::ClearList()
213 {                                                 281 {
                                                   >> 282 //  if (fNbTracks == 0) return;
                                                   >> 283 
214   fTrackContainer.Clear();                        284   fTrackContainer.Clear();
                                                   >> 285 
                                                   >> 286   fNbTracks = -1;
                                                   >> 287 
215   G4AllITFinder::DeleteInstance();                288   G4AllITFinder::DeleteInstance();
216 }                                                 289 }
217                                                   290 
218 //____________________________________________    291 //_________________________________________________________________________
219 void G4Scheduler::RegisterModel(G4VITStepModel << 292 void G4Scheduler::RegisterModel(G4VITStepModel* model, double time)
220 {                                                 293 {
221   fpModelHandler->RegisterModel(model, time);     294   fpModelHandler->RegisterModel(model, time);
222 }                                                 295 }
223                                                   296 
224 //____________________________________________    297 //_________________________________________________________________________
225                                                   298 
226 void G4Scheduler::Initialize()                    299 void G4Scheduler::Initialize()
227 {                                                 300 {
228   delete fpStepProcessor;                      << 301   if (fpStepProcessor)
229   delete fpModelProcessor;                     << 302   {
                                                   >> 303     delete fpStepProcessor;
                                                   >> 304   }
                                                   >> 305   if (fpModelProcessor)
                                                   >> 306   {
                                                   >> 307     delete fpModelProcessor;
                                                   >> 308   }
                                                   >> 309   // if(fpMasterModelProcessor)
                                                   >> 310   // {
                                                   >> 311   //     delete fpMasterModelProcessor;
                                                   >> 312   // }
                                                   >> 313 
                                                   >> 314   //______________________________________________________________
230                                                   315 
231   fpModelProcessor = new G4ITModelProcessor();    316   fpModelProcessor = new G4ITModelProcessor();
232   fpModelProcessor->SetModelHandler(fpModelHan    317   fpModelProcessor->SetModelHandler(fpModelHandler);
233   fpModelProcessor->SetTrackingManager(fpTrack << 318 
                                                   >> 319   // fpMasterModelProcessor = new G4ITModelProcessor();
                                                   >> 320   // fpMasterModelProcessor->SetModelHandler(fpModelHandler);
                                                   >> 321   // fpModelProcessor      = fpMasterModelProcessor;
                                                   >> 322 
                                                   >> 323   //______________________________________________________________
                                                   >> 324 
234   fpStepProcessor = new G4ITStepProcessor();      325   fpStepProcessor = new G4ITStepProcessor();
235   fpStepProcessor->SetTrackingManager(fpTracki    326   fpStepProcessor->SetTrackingManager(fpTrackingManager);
                                                   >> 327 
236   fpTrackingManager->SetInteractivity(fpTracki    328   fpTrackingManager->SetInteractivity(fpTrackingInteractivity);
237   if (fUsePreDefinedTimeSteps) {               << 329 
238     if (fpUserTimeSteps == nullptr)  // Extra  << 330   // fpMasterStepProcessor = new G4ITStepProcessor();
239     {                                          << 331   // fpMasterStepProcessor->SetTrackingManager(fpTrackingManager);
240       G4ExceptionDescription exceptionDescript << 332   // fpStepProcessor = fpMasterStepProcessor ;
241       exceptionDescription << "You are asking  << 333 
242       G4Exception("G4Scheduler::FindUserPreDef << 334   if (fpModelHandler->GetTimeStepComputerFlag()) fComputeTimeStep = true;
243                   exceptionDescription);       << 335   if (fpModelHandler->GetReactionProcessFlag()) fComputeReaction = true;
244       return;  // makes coverity happy         << 336   //______________________________________________________________
245     }                                          << 
246   }                                            << 
247                                                   337 
248   fInitialized = true;                            338   fInitialized = true;
249 }                                                 339 }
250                                                << 
251 //____________________________________________    340 //_________________________________________________________________________
252                                                   341 
253 void G4Scheduler::Reset()                         342 void G4Scheduler::Reset()
254 {                                                 343 {
255   fStartTime = 0;                                 344   fStartTime = 0;
256   fUserUpperTimeLimit = -1;                       345   fUserUpperTimeLimit = -1;
257   fTimeStep = DBL_MAX;                            346   fTimeStep = DBL_MAX;
258   fTSTimeStep = DBL_MAX;                          347   fTSTimeStep = DBL_MAX;
259   fILTimeStep = DBL_MAX;                          348   fILTimeStep = DBL_MAX;
260   fPreviousTimeStep = DBL_MAX;                    349   fPreviousTimeStep = DBL_MAX;
261   fGlobalTime = -1;                               350   fGlobalTime = -1;
262   fInteractionStep = true;                        351   fInteractionStep = true;
263   fITStepStatus = eUndefined;                     352   fITStepStatus = eUndefined;
264   fZeroTimeCount = 0;                             353   fZeroTimeCount = 0;
265                                                   354 
266   fNbSteps = 0;                                   355   fNbSteps = 0;
267   fContinue = true;                               356   fContinue = true;
268   fReactionSet->CleanAllReaction();            << 357   fReactingTracks.clear();
                                                   >> 358   fLeadingTracks.clear();
269 }                                                 359 }
270 //____________________________________________    360 //_________________________________________________________________________
271                                                   361 
272 void G4Scheduler::Process()                       362 void G4Scheduler::Process()
273 {                                                 363 {
                                                   >> 364 
274 #ifdef G4VERBOSE                                  365 #ifdef G4VERBOSE
275   if (fVerbose != 0) {                         << 366   if (fVerbose)
                                                   >> 367   {
276     G4cout << "*** G4Scheduler starts processi    368     G4cout << "*** G4Scheduler starts processing " << G4endl;
277     if (fVerbose > 2)                          << 369     if(fVerbose > 2)
278       G4cout << "_____________________________ << 370     G4cout << "___________________________________________"
279                 "___________________________"  << 371     "___________________________" << G4endl;
280              << G4endl;                        << 
281   }                                               372   }
282 #endif                                            373 #endif
283                                                   374 
284   if (!fInitialized) {                         << 375   if (fInitialized == false) Initialize();
285     Initialize();                              << 376 
286   }                                            << 377   // fpTrackingManager->Initialize();
287   fpModelProcessor->Initialize();                 378   fpModelProcessor->Initialize();
288   fpStepProcessor->Initialize();                  379   fpStepProcessor->Initialize();
289                                                   380 
290   if (fpGun != nullptr) fpGun->DefineTracks(); << 381   // TODO
                                                   >> 382   // fpMasterModelProcessor->Initialize();
                                                   >> 383   // fpMasterStepProcessor->Initialize();
291                                                   384 
292   if (fpTrackingInteractivity != nullptr) fpTr << 385   if (fpGun) fpGun->DefineTracks();
                                                   >> 386 
                                                   >> 387   if (fpTrackingInteractivity) fpTrackingInteractivity->Initialize();
293                                                   388 
294   // ___________________                          389   // ___________________
295   fRunning = true;                                390   fRunning = true;
296   Reset();                                        391   Reset();
297                                                   392 
298   if (fResetScavenger) {                       << 393   if (fpUserTimeStepAction) fpUserTimeStepAction->StartProcessing();
299     if (fpUserScavenger != nullptr) {          << 
300       fpUserScavenger->Reset();                << 
301     }                                          << 
302   }                                            << 
303                                                << 
304   if (fpUserTimeStepAction != nullptr) {       << 
305     fpUserTimeStepAction->StartProcessing();   << 
306   }                                            << 
307                                                   394 
308 #ifdef G4VERBOSE                                  395 #ifdef G4VERBOSE
309   G4bool trackFound = false;                      396   G4bool trackFound = false;
310   G4IosFlagsSaver iosfs(G4cout);               << 
311   G4cout.precision(5);                         << 
312 #endif                                            397 #endif
313                                                   398 
314   //==========================================    399   //===========================================================================
315   // By default, before the G4Scheduler is lau    400   // By default, before the G4Scheduler is launched, the tracks are pushed to
316   // the delayed lists                            401   // the delayed lists
317   //==========================================    402   //===========================================================================
318                                                   403 
319   if (fTrackContainer.DelayListsNOTEmpty()) {  << 404   if(fTrackContainer.DelayListsNOTEmpty())
                                                   >> 405   {
320     fStartTime = fTrackContainer.GetNextTime()    406     fStartTime = fTrackContainer.GetNextTime();
321 #ifdef G4VERBOSE                                  407 #ifdef G4VERBOSE
322     trackFound = true;                            408     trackFound = true;
323     G4Timer localtimer;                           409     G4Timer localtimer;
324     if (fVerbose > 1) {                        << 410     if(fVerbose>1)
                                                   >> 411     {
325       localtimer.Start();                         412       localtimer.Start();
326     }                                             413     }
327 #endif                                            414 #endif
328     SynchronizeTracks();                          415     SynchronizeTracks();
329 #ifdef G4VERBOSE                                  416 #ifdef G4VERBOSE
330     if (fVerbose > 1) {                        << 417     if(fVerbose>1)
                                                   >> 418     {
331       localtimer.Stop();                          419       localtimer.Stop();
332       G4cout << "G4Scheduler: process time= "  << 420       G4cout << "G4Scheduler: process time= "<< localtimer << G4endl;
333     }                                             421     }
334 #endif                                            422 #endif
335   }                                               423   }
                                                   >> 424 
                                                   >> 425 //  //---------------------------------
                                                   >> 426 //  // TODO: This could be removed ?
                                                   >> 427 //  if(fTrackContainer.MainListsNOTEmpty()
                                                   >> 428 //      && (fMaxSteps == -1 ? true : fNbSteps < fMaxSteps)
                                                   >> 429 //      && fGlobalTime < fEndTime
                                                   >> 430 //      && fContinue == true)
                                                   >> 431 //{
                                                   >> 432 //#ifdef G4VERBOSE
                                                   >> 433 //    trackFound = true;
                                                   >> 434 //#endif
                                                   >> 435 //    DoProcess();
                                                   >> 436 //}
                                                   >> 437 //  //---------------------------------
                                                   >> 438 
336 #ifdef G4VERBOSE                                  439 #ifdef G4VERBOSE
337   if (fVerbose != 0) {                         << 440   if(fVerbose)
338     if (trackFound) {                          << 441   {
339       G4cout << "*** G4Scheduler ends at time  << 442     if(trackFound)
                                                   >> 443     {
                                                   >> 444       G4cout << "*** G4Scheduler ends at time : "
                                                   >> 445       << G4BestUnit(fGlobalTime,"Time") << G4endl;
340       G4cout << "_____________________________    446       G4cout << "___________________________________" << G4endl;
341     }                                             447     }
342     else {                                     << 448     else
                                                   >> 449     {
343       G4cout << "*** G4Scheduler did not start    450       G4cout << "*** G4Scheduler did not start because no "
344                 "track was found to be process << 451       "track was found to be processed"<< G4endl;
345              << G4endl;                        << 
346       G4cout << "_____________________________    452       G4cout << "___________________________________" << G4endl;
347     }                                             453     }
348   }                                               454   }
349 #endif                                            455 #endif
350                                                   456 
351   fRunning = false;                               457   fRunning = false;
352                                                   458 
353   if (fpUserTimeStepAction != nullptr) {       << 459   if (fpUserTimeStepAction) fpUserTimeStepAction->EndProcessing();
354     fpUserTimeStepAction->EndProcessing();     << 460 
355   }                                            << 
356   // ___________________                          461   // ___________________
357   EndTracking();                                  462   EndTracking();
358   ClearList();                                    463   ClearList();
                                                   >> 464 
359   Reset();                                        465   Reset();
360                                                   466 
361   if (fpTrackingInteractivity != nullptr) {    << 467   if (fpTrackingInteractivity) fpTrackingInteractivity->Finalize();
362     fpTrackingInteractivity->Finalize();       << 
363   }                                            << 
364 }                                                 468 }
365                                                << 
366 //____________________________________________    469 //_________________________________________________________________________
367                                                   470 
368 G4double G4Scheduler::GetNextWatchedTime() con << 471 void G4Scheduler::SynchronizeTracks()
369 {                                                 472 {
370   auto up = fWatchedTimes.upper_bound(fGlobalT << 473 //  if(fTrackContainer.WaitingListsNOTEmpty())
371   if (up == fWatchedTimes.end()) {             << 474 //   {
372     return DBL_MAX;                            << 475 //    G4ExceptionDescription exceptionDescription;
373   }                                            << 476 //    exceptionDescription
374   return *up;                                  << 477 //        << "There is a waiting track list (fpWaitingList != 0).";
375 }                                              << 478 //    exceptionDescription
                                                   >> 479 //        << " When G4Scheduler::SynchronizeTracks() is called, ";
                                                   >> 480 //    exceptionDescription
                                                   >> 481 //        << "no more tracks should remain in the fpWaitingList.";
                                                   >> 482 //    G4Exception("G4Scheduler::SynchronizeTracks", "ITScheduler002",
                                                   >> 483 //                FatalErrorInArgument, exceptionDescription);
                                                   >> 484 //  }
                                                   >> 485 
                                                   >> 486   // Backup main list and time feature
                                                   >> 487   // Reminder : the main list here, should
                                                   >> 488   // have the biggest global time
                                                   >> 489   //  fTrackContainer.MoveMainToWaitingList();
                                                   >> 490   // TODO: not yet supported
376                                                   491 
377 //____________________________________________ << 492   fTmpGlobalTime = fGlobalTime;
                                                   >> 493   fTmpEndTime = fEndTime;
378                                                   494 
379 void G4Scheduler::SynchronizeTracks()          << 
380 {                                              << 
381   fGlobalTime = fTrackContainer.GetNextTime();    495   fGlobalTime = fTrackContainer.GetNextTime();
382   G4double tmpGlobalTime = fGlobalTime;           496   G4double tmpGlobalTime = fGlobalTime;
383   G4double nextWatchedTime = -1;               << 497   while(fTrackContainer.MergeNextTimeToMainList(tmpGlobalTime))
384   G4bool carryOn = true;                       << 498   {
385   while (fTrackContainer.MergeNextTimeToMainLi << 499 //    assert(tmpGlobalTime == fGlobalTime);
386     if (tmpGlobalTime != fGlobalTime) {        << 500     fEndTime =  min(fTrackContainer.GetNextTime(), fTmpEndTime);
387       fGlobalTime = tmpGlobalTime;             << 501     DoProcess();
388     };                                         << 
389     fStopTime = min(fTrackContainer.GetNextTim << 
390     while ((nextWatchedTime = GetNextWatchedTi << 
391            && (carryOn = CanICarryOn()))       << 
392     {                                          << 
393       fStopTime = min(nextWatchedTime, fEndTim << 
394       DoProcess();                             << 
395     }                                          << 
396                                                << 
397     carryOn = CanICarryOn();                   << 
398                                                << 
399     if (nextWatchedTime > fEndTime && carryOn) << 
400       fStopTime = min(fTrackContainer.GetNextT << 
401       DoProcess();                             << 
402     }                                          << 
403   }                                               502   }
404 }                                                 503 }
405                                                << 
406 //____________________________________________    504 //_________________________________________________________________________
407                                                   505 
408 G4bool G4Scheduler::CanICarryOn()              << 506 void G4Scheduler::DoProcess()
                                                   >> 507 // We split it from the Process() method to avoid repeating code in SynchronizeTracks
409 {                                                 508 {
410   return fGlobalTime < fEndTime && (fMaxSteps  << 509   if (fpUserTimeStepAction) fpUserTimeStepAction->NewStage();
411 }                                              << 
412                                                   510 
413 //____________________________________________ << 511 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING)
                                                   >> 512   MemStat mem_first, mem_second, mem_diff;
                                                   >> 513 #endif
                                                   >> 514 
                                                   >> 515 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING)
                                                   >> 516   mem_first = MemoryUsage();
                                                   >> 517 #endif
                                                   >> 518 
                                                   >> 519   while (fGlobalTime < fEndTime
                                                   >> 520          && fTrackContainer.MainListsNOTEmpty()
                                                   >> 521          && (fMaxSteps == -1 ? true : fNbSteps < fMaxSteps)
                                                   >> 522          && fContinue == true)
                                                   >> 523   {
                                                   >> 524 //    G4cout << "Mainlist size : " << fTrackContainer.GetMainList()->size()
                                                   >> 525 //        << G4endl;
                                                   >> 526 
                                                   >> 527     Stepping();
                                                   >> 528 
                                                   >> 529 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING)
                                                   >> 530     mem_second = MemoryUsage();
                                                   >> 531     mem_diff = mem_second-mem_first;
                                                   >> 532     G4cout << "\t || MEM || After step " << fNbSteps << ", diff is : "
                                                   >> 533     << mem_diff << G4endl;
                                                   >> 534 #endif
                                                   >> 535   }
414                                                   536 
415 void G4Scheduler::PrintWhyDoYouStop()          << 
416 {                                              << 
417 #ifdef G4VERBOSE                                  537 #ifdef G4VERBOSE
418   if (fWhyDoYouStop) {                         << 538   if (fWhyDoYouStop)
                                                   >> 539   {
419     G4cout << "G4Scheduler has reached a stage    540     G4cout << "G4Scheduler has reached a stage: it might be"
420               " a transition or the end"       << 541            " a transition or the end"
421            << G4endl;                             542            << G4endl;
422                                                   543 
423     G4bool normalStop = false;                    544     G4bool normalStop = false;
424                                                   545 
425     if (fGlobalTime >= fStopTime) {            << 546     if(fGlobalTime >= fEndTime)
426       G4cout << "== G4Scheduler: I stop becaus << 547     {
427              << G4BestUnit(fStopTime, "Time")  << 548       G4cout << "== G4Scheduler: I stop because I reached the final time : "
                                                   >> 549       << G4BestUnit(fEndTime,"Time") << " =="<< G4endl;
428       normalStop = true;                          550       normalStop = true;
429     }                                             551     }
430     if (!fTrackContainer.MainListsNOTEmpty())  << 552     if(fTrackContainer.MainListsNOTEmpty()  == false) // is empty
431     {                                             553     {
432       G4cout << "G4Scheduler: I stop because t << 554       G4cout << "G4Scheduler: I stop because the current main list of tracks"
433                 "is empty"                     << 555       "is empty"
434              << G4endl;                        << 556       << G4endl;
435       normalStop = true;                          557       normalStop = true;
436     }                                             558     }
437     if (fMaxSteps == -1 ? false : fNbSteps >=  << 559     if(fMaxSteps == -1 ? false : fNbSteps >= fMaxSteps)
                                                   >> 560     {
438       G4cout << "G4Scheduler: I stop because I    561       G4cout << "G4Scheduler: I stop because I reached the maximum allowed "
439                 "number of steps="             << 562       "number of steps=" << fMaxSteps
440              << fMaxSteps << G4endl;           << 563       << G4endl;
441       normalStop = true;                          564       normalStop = true;
442     }                                             565     }
443     if (fContinue && !normalStop) {            << 566     if(fContinue && normalStop == false)
                                                   >> 567     {
444       G4cout << "G4Scheduler: It might be that    568       G4cout << "G4Scheduler: It might be that I stop because "
445                 "I have been told so. You may  << 569       "I have been told so. You may check "
446                 "member fContinue and usage of << 570       "member fContinue and usage of the method G4Scheduler::Stop()."
447              << G4endl;                        << 571       << G4endl;
448     }                                             572     }
449   }                                               573   }
450 #endif                                            574 #endif
451 }                                              << 
452                                                << 
453 //____________________________________________ << 
454                                                << 
455 void G4Scheduler::DoProcess()                  << 
456 {                                              << 
457   if (fpUserTimeStepAction != nullptr) fpUserT << 
458                                                << 
459 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_ST << 
460   MemStat mem_first, mem_second, mem_diff;     << 
461 #endif                                         << 
462                                                << 
463 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_ST << 
464   mem_first = MemoryUsage();                   << 
465 #endif                                         << 
466                                                << 
467   while (fGlobalTime < fStopTime && fTrackCont << 
468          && (fMaxSteps == -1 ? true : fNbSteps << 
469   {                                            << 
470     Stepping();                                << 
471                                                << 
472 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_ST << 
473     mem_second = MemoryUsage();                << 
474     mem_diff = mem_second - mem_first;         << 
475     G4cout << "\t || MEM || After step " << fN << 
476 #endif                                         << 
477   }                                            << 
478                                                << 
479   PrintWhyDoYouStop();                         << 
480                                                   575 
481 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_ST << 576 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING)
482   mem_second = MemoryUsage();                     577   mem_second = MemoryUsage();
483   mem_diff = mem_second - mem_first;           << 578   mem_diff = mem_second-mem_first;
484   G4cout << "\t || MEM || After stepping, diff    579   G4cout << "\t || MEM || After stepping, diff is : " << mem_diff << G4endl;
485 #endif                                            580 #endif
486                                                   581 
487 #ifdef G4VERBOSE                                  582 #ifdef G4VERBOSE
488   if (fVerbose > 2)                            << 583   if (fVerbose > 2) G4cout
489     G4cout << "*** G4Scheduler has finished pr << 584       << "*** G4Scheduler has finished processing a track list at time : "
490            << G4BestUnit(fGlobalTime, "Time")  << 585       << G4BestUnit(fGlobalTime, "Time") << G4endl;
491 #endif                                            586 #endif
492 }                                                 587 }
493 //____________________________________________    588 //_________________________________________________________________________
494                                                   589 
495 void G4Scheduler::Stepping()                      590 void G4Scheduler::Stepping()
496 {                                                 591 {
497   fTimeStep = fMaxTimeStep;                    << 592   IosFlagSaver iosfs(G4cout);
                                                   >> 593   fTimeStep = DBL_MAX;
498                                                   594 
499   fTSTimeStep = DBL_MAX;                          595   fTSTimeStep = DBL_MAX;
500   fILTimeStep = DBL_MAX;                          596   fILTimeStep = DBL_MAX;
501                                                   597 
502   fInteractionStep = false;                       598   fInteractionStep = false;
503   fReachedUserTimeLimit = false;                  599   fReachedUserTimeLimit = false;
504                                                   600 
505   fITStepStatus = eUndefined;                     601   fITStepStatus = eUndefined;
506                                                   602 
507   // Start of step                                603   // Start of step
508 #ifdef G4VERBOSE                                  604 #ifdef G4VERBOSE
509   if (fVerbose > 2) {                          << 605   if (fVerbose > 2)
510 #  ifdef USE_COLOR                             << 606   {
                                                   >> 607 #ifdef USE_COLOR
511     G4cout << LIGHT_RED;                          608     G4cout << LIGHT_RED;
512 #  endif                                       << 609 #endif
513     G4cout << "*** Start Of Step N°" << fNbSt << 610     G4cout << "*** Start Of Step N°" << fNbSteps + 1 << " ***" << G4endl;
514            << " ***" << G4endl;                << 611     G4cout << "Current Global time : " << G4BestUnit(fGlobalTime, "Time")
515     G4cout << "Current Global time : " << G4Be << 612            <<G4endl;
516 #  ifdef USE_COLOR                             << 613 #ifdef USE_COLOR
517     G4cout << RESET_COLOR;                        614     G4cout << RESET_COLOR;
518 #  endif                                       << 615 #endif
519   }                                               616   }
520 #endif                                            617 #endif
521                                                   618 
522 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE << 619 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
523   MemStat mem_first, mem_second, mem_diff;        620   MemStat mem_first, mem_second, mem_diff;
524 #endif                                            621 #endif
525                                                   622 
526 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE << 623 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
527   mem_first = MemoryUsage();                      624   mem_first = MemoryUsage();
528 #endif                                            625 #endif
529                                                   626 
530   fDefinedMinTimeStep = GetLimitingTimeStep();    627   fDefinedMinTimeStep = GetLimitingTimeStep();
531                                                   628 
532   if (fUsePreDefinedTimeSteps) {               << 629   if (fUsePreDefinedTimeSteps)
                                                   >> 630   {
                                                   >> 631     if (fpUserTimeSteps == 0) // Extra checking, is it necessary ?
                                                   >> 632     {
                                                   >> 633       G4ExceptionDescription exceptionDescription;
                                                   >> 634       exceptionDescription
                                                   >> 635         << "You are asking to use user defined steps but you did not give any.";
                                                   >> 636       G4Exception("G4Scheduler::FindUserPreDefinedTimeStep",
                                                   >> 637                   "ITScheduler004", FatalErrorInArgument,
                                                   >> 638                   exceptionDescription);
                                                   >> 639       return; // makes coverity happy
                                                   >> 640     }
533 #ifdef G4VERBOSE                                  641 #ifdef G4VERBOSE
534     if (fVerbose > 2) {                        << 642     if (fVerbose > 2)
535 #  ifdef USE_COLOR                             << 643     {
                                                   >> 644 #ifdef USE_COLOR
536       G4cout << LIGHT_RED;                        645       G4cout << LIGHT_RED;
537 #  endif                                       << 646 #endif
538       G4cout << "*** At time : " << G4BestUnit    647       G4cout << "*** At time : " << G4BestUnit(fGlobalTime, "Time")
539              << " the chosen user time step is << 648              << " the chosen user time step is : "
540              << " ***" << G4endl;              << 649              << G4BestUnit(fDefinedMinTimeStep, "Time") << " ***" << G4endl;
541 #  ifdef USE_COLOR                             << 650 #ifdef USE_COLOR
542       G4cout << RESET_COLOR;                      651       G4cout << RESET_COLOR;
543 #  endif                                       << 652 #endif
544     }                                             653     }
545 #endif                                            654 #endif
546   }                                               655   }
547                                                   656 
548   if (fpModelProcessor->GetComputeTimeStep())  << 657   if (fComputeTimeStep)
549   {                                               658   {
550     fTSTimeStep = fpModelProcessor->CalculateM << 659     CalculateMinTimeStep(); // => at least N (N = nb of tracks) loops
551     // => at least N (N = nb of tracks) loops  << 
552   }                                               660   }
553   else if (fUseDefaultTimeSteps) {             << 661   else if(fUseDefaultTimeSteps)
                                                   >> 662   {
554     fTSTimeStep = fDefinedMinTimeStep;            663     fTSTimeStep = fDefinedMinTimeStep;
555   }                                               664   }
556                                                   665 
557 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE << 666 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
558   mem_second = MemoryUsage();                     667   mem_second = MemoryUsage();
559   mem_diff = mem_second - mem_first;           << 668   mem_diff = mem_second-mem_first;
560   G4cout << "|| MEM || After computing TS, dif    669   G4cout << "|| MEM || After computing TS, diff is : " << mem_diff << G4endl;
561 #endif                                            670 #endif
562                                                   671 
563 #ifdef G4VERBOSE                                  672 #ifdef G4VERBOSE
564   if (fVerbose > 2) {                          << 673   if (fVerbose > 2)
565 #  ifdef USE_COLOR                             << 674   {
                                                   >> 675 #ifdef USE_COLOR
566     G4cout << LIGHT_RED;                          676     G4cout << LIGHT_RED;
567 #  endif                                       << 677 #endif
568     G4cout << "*** Time stepper returned : " < << 678     G4cout << "*** Time stepper returned : " << G4BestUnit(fTSTimeStep, "Time")
569 #  ifdef USE_COLOR                             << 679            << " ***" << G4endl;
                                                   >> 680 #ifdef USE_COLOR
570     G4cout << RESET_COLOR;                        681     G4cout << RESET_COLOR;
571 #  endif                                       << 682 #endif
572   }                                               683   }
573 #endif                                            684 #endif
574                                                   685 
575 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE << 686 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
576   mem_first = MemoryUsage();                      687   mem_first = MemoryUsage();
577 #endif                                            688 #endif
578                                                   689 
579   // Call IL even if fTSTimeStep == 0             690   // Call IL even if fTSTimeStep == 0
580   // if fILTimeStep == 0 give the priority to     691   // if fILTimeStep == 0 give the priority to DoIt processes
581                                                << 692   ComputeInteractionLength(); // => at least N loops
582   fILTimeStep = fpStepProcessor->ComputeIntera << 
583   // => at least N loops                       << 
584   // All process returns the physical step of     693   // All process returns the physical step of interaction
585   // The transportation process calculates the << 694   // using the approximation : E = cste along the step
                                                   >> 695   // Only the transportation calculates the corresponding
586   // time step                                    696   // time step
587                                                   697 
588 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE << 698 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
589   mem_second = MemoryUsage();                     699   mem_second = MemoryUsage();
590   mem_diff = mem_second - mem_first;           << 700   mem_diff = mem_second-mem_first;
591   G4cout << "|| MEM || After IL, diff is : " <    701   G4cout << "|| MEM || After IL, diff is : " << mem_diff << G4endl;
592 #endif                                            702 #endif
593                                                   703 
594 #ifdef G4VERBOSE                                  704 #ifdef G4VERBOSE
595   if (fVerbose > 2) {                          << 705   if (fVerbose > 2)
596 #  ifdef USE_COLOR                             << 706   {
                                                   >> 707 #ifdef USE_COLOR
597     G4cout << LIGHT_RED;                          708     G4cout << LIGHT_RED;
598 #  endif                                       << 709 #endif
599     G4cout << "*** The minimum time returned b    710     G4cout << "*** The minimum time returned by the processes is : "
600            << G4BestUnit(fILTimeStep, "Time")     711            << G4BestUnit(fILTimeStep, "Time") << " ***" << G4endl;
601 #  ifdef USE_COLOR                             << 712 #ifdef USE_COLOR
602     G4cout << RESET_COLOR;                        713     G4cout << RESET_COLOR;
603 #  endif                                       << 714 #endif
604   }                                               715   }
605 #endif                                            716 #endif
606                                                   717 
607 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE << 718 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
608   mem_first = MemoryUsage();                      719   mem_first = MemoryUsage();
609 #endif                                            720 #endif
610                                                   721 
611   if (fILTimeStep <= fTSTimeStep)                 722   if (fILTimeStep <= fTSTimeStep)
612   // Give the priority to the IL               << 723     // Give the priority to the IL
613   {                                               724   {
614     fInteractionStep = true;                      725     fInteractionStep = true;
615     fReactionSet->CleanAllReaction();          << 726     fReactingTracks.clear(); // Give the priority to the IL
616     fTimeStep = fILTimeStep;                      727     fTimeStep = fILTimeStep;
617     fITStepStatus = eInteractionWithMedium;       728     fITStepStatus = eInteractionWithMedium;
618     fpStepProcessor->PrepareLeadingTracks();   << 
619   }                                               729   }
620   else {                                       << 730   else
                                                   >> 731   {
621     fInteractionStep = false;                     732     fInteractionStep = false;
622     fpStepProcessor->ResetLeadingTracks();     << 733     ResetLeadingTracks();
623     fTimeStep = fTSTimeStep;                      734     fTimeStep = fTSTimeStep;
624     fITStepStatus = eCollisionBetweenTracks;      735     fITStepStatus = eCollisionBetweenTracks;
625   }                                               736   }
626                                                   737 
627   if (fGlobalTime + fTimeStep > fStopTime)     << 738   if (fGlobalTime + fTimeStep > fEndTime)
628   // This check is done at every time step     << 739   // This check is done at very time step
629   {                                               740   {
630     fTimeStep = fStopTime - fGlobalTime;       << 741     fTimeStep = fEndTime - fGlobalTime;
631     fITStepStatus = eInteractionWithMedium;  / << 742     fITStepStatus = eInteractionWithMedium; // ie: transportation
632     fInteractionStep = true;                      743     fInteractionStep = true;
633     fReactionSet->CleanAllReaction();          << 744     fReactingTracks.clear();
634     fpStepProcessor->ResetLeadingTracks();     << 745     ResetLeadingTracks();
635   }                                               746   }
636                                                   747 
637   if (fTimeStep == 0)  // < fTimeTolerance)    << 748   if (fTimeStep == 0) // < fTimeTolerance)
638   {                                               749   {
639     ++fZeroTimeCount;                          << 750     fZeroTimeCount++;
640     if (fZeroTimeCount >= fMaxNZeroTimeStepsAl << 751     if (fZeroTimeCount >= fMaxNZeroTimeStepsAllowed)
                                                   >> 752     {
641       G4ExceptionDescription exceptionDescript    753       G4ExceptionDescription exceptionDescription;
642                                                   754 
643       exceptionDescription << "Too many zero t    755       exceptionDescription << "Too many zero time steps were detected. ";
644       exceptionDescription << "The simulation     756       exceptionDescription << "The simulation is probably stuck. ";
645       exceptionDescription << "The maximum num << 757       exceptionDescription
646                            << fMaxNZeroTimeSte << 758           << "The maximum number of zero time steps is currently : "
                                                   >> 759           << fMaxNZeroTimeStepsAllowed;
647       exceptionDescription << ".";                760       exceptionDescription << ".";
648                                                   761 
649       G4Exception("G4Scheduler::Stepping", "Sc << 762       G4Exception("G4Scheduler::Stepping", "ITSchedulerNullTimeSteps",
650                   exceptionDescription);       << 763                   FatalErrorInArgument, exceptionDescription);
651     }                                             764     }
652   }                                               765   }
653   else {                                       << 766   else
                                                   >> 767   {
654     fZeroTimeCount = 0;                           768     fZeroTimeCount = 0;
655   }                                               769   }
656                                                   770 
657   fReachedUserTimeLimit = (fTimeStep <= fDefin << 771   fReachedUserTimeLimit =
658                           || ((fTimeStep > fDe << 772       ((fTimeStep <= fDefinedMinTimeStep) || ((fTimeStep > fDefinedMinTimeStep)
659                               && fabs(fTimeSte << 773           && fabs(fTimeStep - fDefinedMinTimeStep) < fTimeTolerance)) ?
                                                   >> 774           true : false;
660                                                   775 
661   if (fpUserTimeStepAction != nullptr) fpUserT << 776   if (fpUserTimeStepAction) fpUserTimeStepAction->UserPreTimeStepAction();
662     // TODO: pre/post                          << 777   // TODO: pre/post
663                                                   778 
664 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE << 779 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
665   mem_second = MemoryUsage();                     780   mem_second = MemoryUsage();
666   mem_diff = mem_second - mem_first;           << 781   mem_diff = mem_second-mem_first;
667   G4cout << "|| MEM || After LeadingTracks and << 782   G4cout << "|| MEM || After LeadingTracks and UserPreTimeStepAction: "
                                                   >> 783          << mem_diff << G4endl;
668 #endif                                            784 #endif
669                                                   785 
670 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE << 786 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
671   mem_first = MemoryUsage();                      787   mem_first = MemoryUsage();
672 #endif                                            788 #endif
673                                                   789 
674   fGlobalTime += fTimeStep;                    << 790   // if fTSTimeStep > 0 => needs to call the transportation process
675                                                << 791   // if fILTimeStep < fTSTimeStep => call DoIt processes
676   // if fTSTimeStep > 0 => still need to call  << 
677   // if fILTimeStep < fTSTimeStep => call only << 
678   // if fILTimeStep == fTSTimeStep => give the    792   // if fILTimeStep == fTSTimeStep => give the priority to the DoIt processes
679   if (fTSTimeStep > 0 || fILTimeStep <= fTSTim << 793   if (fTSTimeStep > 0 || fILTimeStep <= fTSTimeStep)
680     fpStepProcessor->DoIt(fTimeStep);          << 794   {
                                                   >> 795     //        G4cout << "Will call DoIT" << G4endl;
                                                   >> 796     DoIt();
                                                   >> 797 
                                                   >> 798     fTrackContainer.MergeSecondariesWithMainList();
                                                   >> 799     KillTracks();
681   }                                               800   }
682 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE << 801   // else
                                                   >> 802   // {
                                                   >> 803   //   G4cout << "fTSTimeStep : " << fTSTimeStep << G4endl;
                                                   >> 804   //   G4cout << "fILTimeStep : " << fILTimeStep << G4endl;
                                                   >> 805   // }
                                                   >> 806 
                                                   >> 807 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
683   mem_second = MemoryUsage();                     808   mem_second = MemoryUsage();
684   mem_diff = mem_second - mem_first;           << 809   mem_diff = mem_second-mem_first;
685   G4cout << "|| MEM || After DoIT, diff is : "    810   G4cout << "|| MEM || After DoIT, diff is : " << mem_diff << G4endl;
686 #endif                                            811 #endif
687                                                   812 
688 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE << 813   fGlobalTime += fTimeStep;
                                                   >> 814 
                                                   >> 815 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
689   mem_first = MemoryUsage();                      816   mem_first = MemoryUsage();
690 #endif                                            817 #endif
691                                                   818 
692   fpModelProcessor->ComputeTrackReaction(fITSt << 819   ComputeTrackReaction();
693                                          fReac << 820 
694                                          fpUse << 821   fTrackContainer.MergeSecondariesWithMainList();
695                                                   822 
696   ++fNbSteps;                                  << 823   fTrackContainer.KillTracks();
697                                                   824 
698   if (fpUserTimeStepAction != nullptr) {       << 825   fNbSteps++;
                                                   >> 826 
                                                   >> 827   if (fpUserTimeStepAction)
                                                   >> 828   {
699     fpUserTimeStepAction->UserPostTimeStepActi    829     fpUserTimeStepAction->UserPostTimeStepAction();
700   }                                               830   }
701                                                   831 
702   fPreviousTimeStep = fTimeStep;                  832   fPreviousTimeStep = fTimeStep;
703                                                   833 
704 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE << 834 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
705   mem_second = MemoryUsage();                     835   mem_second = MemoryUsage();
706   mem_diff = mem_second - mem_first;           << 836   mem_diff = mem_second-mem_first;
707   G4cout << "|| MEM || After computing reactio    837   G4cout << "|| MEM || After computing reactions + UserPostTimeStepAction, "
708             "diff is : "                       << 838   "diff is : " << mem_diff << G4endl;
709          << mem_diff << G4endl;                << 
710 #endif                                            839 #endif
711                                                   840 
712   // End of step                                  841   // End of step
713 #ifdef G4VERBOSE                                  842 #ifdef G4VERBOSE
714   if (fVerbose >= 2) {                         << 843     if (fVerbose >= 2)
715 #  ifdef USE_COLOR                             << 844     {
716     G4cout << LIGHT_RED;                       << 845 #ifdef USE_COLOR
717 #  endif                                       << 846       G4cout << LIGHT_RED;
                                                   >> 847 #endif
718                                                   848 
719     G4String interactionType;                  << 849       G4String interactionType;
720     GetCollisionType(interactionType);         << 850       GetCollisionType(interactionType);
721                                                   851 
722     std::stringstream finalOutput;             << 852       std::stringstream finalOutput;
723                                                   853 
724     finalOutput << "*** End of step N°" << fN << 854       finalOutput << "*** End of step N°" << fNbSteps
725                 << "\t T_i= " << G4BestUnit(fG << 855              << "\t T_i= " << G4BestUnit(fGlobalTime-fTimeStep, "Time")
726                 << "\t dt= " << G4BestUnit(fTi << 856              << "\t dt= " << G4BestUnit(fTimeStep, "Time")
727                 << "\t T_f= " << G4BestUnit(fG << 857              << "\t T_f= " << G4BestUnit(fGlobalTime, "Time")
728                 << G4endl;                     << 858              << "\t " << interactionType
                                                   >> 859              << G4endl;
729                                                   860 
730     if (fVerbose > 2) {                        << 861       if(fVerbose>2)
731       if (fReachedUserTimeLimit) {             << 862       {
732         finalOutput << "It has also reached th << 863         if(fReachedUserTimeLimit)
                                                   >> 864         {
                                                   >> 865           finalOutput << "It has also reached the user time limit" << G4endl;
                                                   >> 866         }
                                                   >> 867         finalOutput << "_______________________________________________________________"
                                                   >> 868             "_______"<< G4endl;
733       }                                           869       }
734       finalOutput << "________________________ << 
735                      "_______"                 << 
736                   << G4endl;                   << 
737     }                                          << 
738                                                   870 
739     G4cout << finalOutput.str();               << 871       G4cout << finalOutput.str();
740                                                   872 
741 #  ifdef USE_COLOR                             << 873 #ifdef USE_COLOR
742     G4cout << RESET_COLOR;                     << 874       G4cout << RESET_COLOR;
743 #  endif                                       << 875 #endif
744   }                                            << 876     }
745 #endif                                            877 #endif
                                                   >> 878 
746 }                                                 879 }
747 //____________________________________________    880 //_________________________________________________________________________
748                                                   881 
749 G4double G4Scheduler::GetLimitingTimeStep() co << 882 double G4Scheduler::GetLimitingTimeStep() const
750 {                                                 883 {
751   if (fpUserTimeSteps == nullptr) return fDefa << 884   if (fpUserTimeSteps == 0) return fDefaultMinTimeStep;
752   if (fabs(fGlobalTime - fUserUpperTimeLimit)  << 885   if (fabs(fGlobalTime - fUserUpperTimeLimit) < fTimeTolerance)
753                                                << 886     return fDefinedMinTimeStep;
754   auto it_fpUserTimeSteps_i = fpUserTimeSteps- << 887 
755   auto it_fpUserTimeSteps_low = fpUserTimeStep << 888   map<double, double>::const_iterator it_fpUserTimeSteps_i = fpUserTimeSteps
                                                   >> 889       ->upper_bound(fGlobalTime);
                                                   >> 890   map<double, double>::const_iterator it_fpUserTimeSteps_low = fpUserTimeSteps
                                                   >> 891       ->lower_bound(fGlobalTime);
                                                   >> 892 
                                                   >> 893   // DEBUG
                                                   >> 894   // G4cout << "fGlobalTime : " << G4BestUnit(fGlobalTime,"Time")
                                                   >> 895   //            << G4endl;
                                                   >> 896   // G4cout << "fpUserTimeSteps_i : "
                                                   >> 897   //        <<"<"<<G4BestUnit(it_fpUserTimeSteps->first,"Time")
                                                   >> 898   //        <<", "<< G4BestUnit(it_fpUserTimeSteps->second,"Time")<<">"
                                                   >> 899   //        << "\t fpUserTimeSteps_low : "
                                                   >> 900   //        <<"<"<<G4BestUnit(fpUserTimeSteps_low->first,"Time")<<", "*
                                                   >> 901   //        << G4BestUnit(fpUserTimeSteps_low->second,"Time")<<">"
                                                   >> 902   //        << G4endl;
756                                                   903 
757   if (it_fpUserTimeSteps_i == fpUserTimeSteps- << 904   if (it_fpUserTimeSteps_i == fpUserTimeSteps->end())
                                                   >> 905   {
758     it_fpUserTimeSteps_i--;                       906     it_fpUserTimeSteps_i--;
759     fUserUpperTimeLimit = fStopTime;           << 907     fUserUpperTimeLimit = fEndTime;
760   }                                               908   }
761   else if (fabs(fGlobalTime - it_fpUserTimeSte << 909   else if (fabs(fGlobalTime - it_fpUserTimeSteps_low->first) < fTimeTolerance)
                                                   >> 910   {
                                                   >> 911     // Case : fGlobalTime = X picosecond
                                                   >> 912     // and fpUserTimeSteps_low->first = X picosecond
                                                   >> 913     // but the precision is not good enough
762     it_fpUserTimeSteps_i = it_fpUserTimeSteps_    914     it_fpUserTimeSteps_i = it_fpUserTimeSteps_low;
763     auto tmp_it = it_fpUserTimeSteps_low;      << 915     map<double, double>::const_iterator tmp_it = it_fpUserTimeSteps_low;
764     ++tmp_it;                                  << 916     tmp_it++;
765     if (tmp_it == fpUserTimeSteps->end()) {    << 917     if (tmp_it == fpUserTimeSteps->end())
766       fUserUpperTimeLimit = fStopTime;         << 918     {
                                                   >> 919       fUserUpperTimeLimit = fEndTime;
767     }                                             920     }
768     else {                                     << 921     else
769       fUserUpperTimeLimit = tmp_it->first;     << 922     {
                                                   >> 923       fUserUpperTimeLimit = tmp_it->second;
770     }                                             924     }
771   }                                               925   }
772   else if (it_fpUserTimeSteps_i == it_fpUserTi << 926   else if (it_fpUserTimeSteps_i == it_fpUserTimeSteps_low)
773     fUserUpperTimeLimit = it_fpUserTimeSteps_i << 927   {
774     if (it_fpUserTimeSteps_i != fpUserTimeStep << 928     // "Normal" cases
                                                   >> 929     fUserUpperTimeLimit = it_fpUserTimeSteps_i->second;
                                                   >> 930     it_fpUserTimeSteps_i--;
775   }                                               931   }
776   else {                                       << 932   else
777     fUserUpperTimeLimit = it_fpUserTimeSteps_i << 933   {
                                                   >> 934     fUserUpperTimeLimit = it_fpUserTimeSteps_i->second;
778     it_fpUserTimeSteps_i = it_fpUserTimeSteps_    935     it_fpUserTimeSteps_i = it_fpUserTimeSteps_low;
779   }                                               936   }
                                                   >> 937 
780   return it_fpUserTimeSteps_i->second;            938   return it_fpUserTimeSteps_i->second;
781 }                                                 939 }
782                                                   940 
783 //____________________________________________    941 //_________________________________________________________________________
784                                                   942 
785 void G4Scheduler::FindUserPreDefinedTimeStep()    943 void G4Scheduler::FindUserPreDefinedTimeStep()
786 {                                                 944 {
787   if (fpUserTimeSteps == nullptr) {            << 945 
                                                   >> 946   if (fpUserTimeSteps == 0)
                                                   >> 947   {
788     G4ExceptionDescription exceptionDescriptio    948     G4ExceptionDescription exceptionDescription;
789     exceptionDescription << "You are asking to << 949     exceptionDescription
790     G4Exception("G4Scheduler::FindUserPreDefin << 950         << "You are asking to use user defined steps but you did not give any.";
791                 exceptionDescription);         << 951     G4Exception("G4Scheduler::FindUserPreDefinedTimeStep",
792     return;  // makes coverity happy           << 952                 "ITScheduler004", FatalErrorInArgument, exceptionDescription);
793   }                                            << 953     return; // makes coverity happy
794   auto fpUserTimeSteps_i = fpUserTimeSteps->up << 954   }
795   auto fpUserTimeSteps_low = fpUserTimeSteps-> << 955   map<double, double>::iterator fpUserTimeSteps_i =
                                                   >> 956       fpUserTimeSteps->upper_bound(fGlobalTime);
                                                   >> 957   map<double, double>::iterator fpUserTimeSteps_low = fpUserTimeSteps
                                                   >> 958       ->lower_bound(fGlobalTime);
                                                   >> 959 
                                                   >> 960   // DEBUG
                                                   >> 961   // G4cout << "fGlobalTime : " << G4BestUnit(fGlobalTime,"Time") << G4endl;
                                                   >> 962   // G4cout << "fpUserTimeSteps_i : "
                                                   >> 963   // <<"<"<<G4BestUnit(fpUserTimeSteps_i->first,"Time")<<", "
                                                   >> 964   // << G4BestUnit(fpUserTimeSteps_i->second,"Time")<<">"
                                                   >> 965   // << "\t fpUserTimeSteps_low : "
                                                   >> 966   // <<"<"<<G4BestUnit(fpUserTimeSteps_low->first,"Time")<<", "
                                                   >> 967   // << G4BestUnit(fpUserTimeSteps_low->second,"Time")<<">"
                                                   >> 968   // << G4endl;
796                                                   969 
797   if (fpUserTimeSteps_i == fpUserTimeSteps->en << 970   if (fpUserTimeSteps_i == fpUserTimeSteps->end())
                                                   >> 971   {
798     fpUserTimeSteps_i--;                          972     fpUserTimeSteps_i--;
799   }                                               973   }
800   else if (fabs(fGlobalTime - fpUserTimeSteps_ << 974   else if (fabs(fGlobalTime - fpUserTimeSteps_low->first) < fTimeTolerance)
                                                   >> 975   {
801     // Case : fGlobalTime = X picosecond          976     // Case : fGlobalTime = X picosecond
802     // and fpUserTimeSteps_low->first = X pico    977     // and fpUserTimeSteps_low->first = X picosecond
803     // but the precision is not good enough       978     // but the precision is not good enough
804     fpUserTimeSteps_i = fpUserTimeSteps_low;      979     fpUserTimeSteps_i = fpUserTimeSteps_low;
805   }                                               980   }
806   else if (fpUserTimeSteps_i == fpUserTimeStep << 981   else if (fpUserTimeSteps_i == fpUserTimeSteps_low)
                                                   >> 982   {
807     // "Normal" cases                             983     // "Normal" cases
808     fpUserTimeSteps_i--;                          984     fpUserTimeSteps_i--;
809   }                                               985   }
810   else {                                       << 986   else
                                                   >> 987   {
811     fpUserTimeSteps_i = fpUserTimeSteps_low;      988     fpUserTimeSteps_i = fpUserTimeSteps_low;
812   }                                               989   }
813                                                   990 
814   fDefinedMinTimeStep = fpUserTimeSteps_i->sec    991   fDefinedMinTimeStep = fpUserTimeSteps_i->second;
815 }                                                 992 }
                                                   >> 993 //_________________________________________________________________________
                                                   >> 994 
                                                   >> 995 void G4Scheduler::CalculateMinTimeStep()
                                                   >> 996 {
                                                   >> 997 
                                                   >> 998   if (fpModelProcessor == 0)
                                                   >> 999   //        if(fpMasterModelProcessor == 0)
                                                   >> 1000   {
                                                   >> 1001     G4ExceptionDescription exceptionDescription;
                                                   >> 1002     exceptionDescription
                                                   >> 1003         << "There is no G4ITModelProcessor to hande IT reaction. ";
                                                   >> 1004     exceptionDescription
                                                   >> 1005         << "You probably did not initialize the G4Scheduler. ";
                                                   >> 1006     exceptionDescription
                                                   >> 1007         << "Just do G4Scheduler::Instance()->Initialize(); ";
                                                   >> 1008     exceptionDescription << " but only after initializing the run manager.";
                                                   >> 1009     G4Exception("G4Scheduler::CalculateMinStep", "ITScheduler005",
                                                   >> 1010                 FatalErrorInArgument, exceptionDescription);
                                                   >> 1011     return; // makes coverity happy
                                                   >> 1012   }
                                                   >> 1013 
                                                   >> 1014 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
                                                   >> 1015   MemStat mem_first, mem_second, mem_diff;
                                                   >> 1016 #endif
                                                   >> 1017 
                                                   >> 1018 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
                                                   >> 1019   mem_first = MemoryUsage();
                                                   >> 1020 #endif
                                                   >> 1021 
                                                   >> 1022   fpModelProcessor->InitializeStepper(fGlobalTime, fDefinedMinTimeStep);
                                                   >> 1023   // TODO
                                                   >> 1024   // fpMasterModelProcessor -> InitializeStepper(fGlobalTime, fDefinedMinTimeStep) ;
                                                   >> 1025 
                                                   >> 1026 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
                                                   >> 1027   mem_second = MemoryUsage();
                                                   >> 1028   mem_diff = mem_second-mem_first;
                                                   >> 1029   G4cout << "\t || MEM || G4Scheduler::CalculateMinTimeStep || After "
                                                   >> 1030       "computing fpModelProcessor -> InitializeStepper, diff is : "
                                                   >> 1031       << mem_diff
                                                   >> 1032       << G4endl;
                                                   >> 1033 #endif
                                                   >> 1034 
                                                   >> 1035 //  G4TrackList::iterator fpMainList_i = fpMainList->begin();
                                                   >> 1036 
                                                   >> 1037   G4TrackManyList* mainList = fTrackContainer.GetMainList();
                                                   >> 1038   G4TrackManyList::iterator it = mainList->begin();
                                                   >> 1039   G4TrackManyList::iterator end = mainList->end();
                                                   >> 1040 
                                                   >> 1041   for (; it != end; it++)
                                                   >> 1042   {
                                                   >> 1043     G4Track * track = *it;
                                                   >> 1044 
                                                   >> 1045     if (track == 0)
                                                   >> 1046     {
                                                   >> 1047       G4ExceptionDescription exceptionDescription;
                                                   >> 1048       exceptionDescription << "No track found.";
                                                   >> 1049       G4Exception("G4Scheduler::CalculateMinStep", "ITScheduler006",
                                                   >> 1050                   FatalErrorInArgument, exceptionDescription);
                                                   >> 1051       return; // makes coverity happy
                                                   >> 1052     }
                                                   >> 1053 
                                                   >> 1054 #ifdef DEBUG
                                                   >> 1055     G4cout << "*_* " << GetIT(track)->GetName()
                                                   >> 1056         << " ID: " << track->GetTrackID()
                                                   >> 1057         <<  " at time : " << track->GetGlobalTime()
                                                   >> 1058         << G4endl;
                                                   >> 1059 #endif
                                                   >> 1060 
                                                   >> 1061     G4TrackStatus trackStatus = track->GetTrackStatus();
                                                   >> 1062     if (trackStatus == fStopAndKill || trackStatus == fStopButAlive)
                                                   >> 1063     {
                                                   >> 1064       continue;
                                                   >> 1065     }
                                                   >> 1066 
                                                   >> 1067     // This Extract... was thought for MT mode at the track level
                                                   >> 1068     //ExtractTimeStepperData(fpModelProcessor) ;
                                                   >> 1069 
                                                   >> 1070     fpModelProcessor->CalculateTimeStep(track, fDefinedMinTimeStep);
                                                   >> 1071 
                                                   >> 1072     // if MT mode at track level, this command should be displaced
                                                   >> 1073     ExtractTimeStepperData(fpModelProcessor);
                                                   >> 1074   }
                                                   >> 1075 
                                                   >> 1076 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
                                                   >> 1077   mem_second = MemoryUsage();
                                                   >> 1078   mem_diff = mem_second-mem_first;
                                                   >> 1079   G4cout << "\t || MEM || G4Scheduler::CalculateMinTimeStep || "
                                                   >> 1080       "After looping on tracks, diff is : " << mem_diff << G4endl;
                                                   >> 1081 #endif
                                                   >> 1082 }
                                                   >> 1083 //_________________________________________________________________________
                                                   >> 1084 
                                                   >> 1085 void G4Scheduler::ExtractTimeStepperData(G4ITModelProcessor* MP)
                                                   >> 1086 {
                                                   >> 1087   G4Track* track = (G4Track*) MP->GetTrack();
                                                   >> 1088   if (track == 0)
                                                   >> 1089   {
                                                   >> 1090     MP->CleanProcessor();
                                                   >> 1091     return;
                                                   >> 1092   }
                                                   >> 1093 
                                                   >> 1094   const std::vector<std::vector<G4VITStepModel*> >* model =
                                                   >> 1095       MP->GetCurrentModel();
                                                   >> 1096 
                                                   >> 1097   for (unsigned i = 0; i < model->size(); i++)
                                                   >> 1098   {
                                                   >> 1099     for (unsigned j = 0; j < (*model)[i].size(); j++)
                                                   >> 1100     {
                                                   >> 1101       G4VITStepModel* mod = (*model)[i][j];
                                                   >> 1102 
                                                   >> 1103       if (mod == 0)
                                                   >> 1104       {
                                                   >> 1105         continue;
                                                   >> 1106       }
                                                   >> 1107 
                                                   >> 1108       G4VITTimeStepComputer* stepper(mod->GetTimeStepper());
                                                   >> 1109 
                                                   >> 1110       G4double sampledMinTimeStep(stepper->GetSampledMinTimeStep());
                                                   >> 1111       G4TrackVectorHandle reactants(stepper->GetReactants());
                                                   >> 1112 
                                                   >> 1113       if (sampledMinTimeStep < fTSTimeStep)
                                                   >> 1114       {
                                                   >> 1115         /*
                                                   >> 1116          // DEBUG SPECIAL CASE
                                                   >> 1117          if(!reactants)
                                                   >> 1118          {
                                                   >> 1119          G4ExceptionDescription exceptionDescription ;
                                                   >> 1120          exceptionDescription << "No reactants were found by the time stepper.";
                                                   >> 1121          G4Exception("G4Scheduler::ExtractTimeStepperData","ITScheduler007",
                                                   >> 1122          FatalErrorInArgument,exceptionDescription);
                                                   >> 1123          continue ;
                                                   >> 1124          }
                                                   >> 1125          */
                                                   >> 1126 
                                                   >> 1127         fTSTimeStep = sampledMinTimeStep;
                                                   >> 1128         fReactingTracks.clear();
                                                   >> 1129         if (bool(reactants))
                                                   >> 1130         {
                                                   >> 1131           // G4cout << "*** (1) G4Scheduler::ExtractTimeStepperData insert
                                                   >> 1132           //          reactants for " << GetIT(track)->GetName() << G4endl;
                                                   >> 1133           // G4cout << "bool(reactants) = " << bool(reactants) << G4endl;
                                                   >> 1134           // G4cout << reactants->size() << G4endl;
                                                   >> 1135           // G4cout << GetIT(reactants->operator[](0))->GetName() << G4endl;
                                                   >> 1136 
                                                   >> 1137           fReactingTracks.insert(make_pair(track, reactants));
                                                   >> 1138           stepper->ResetReactants();
                                                   >> 1139         }
                                                   >> 1140       }
                                                   >> 1141       else if (fTSTimeStep == sampledMinTimeStep)
                                                   >> 1142       {
                                                   >> 1143         /*
                                                   >> 1144          // DEBUG SPECIAL CASE
                                                   >> 1145          if(!reactants)
                                                   >> 1146          {
                                                   >> 1147          G4ExceptionDescription exceptionDescription ;
                                                   >> 1148          exceptionDescription << "No reactants were found by the time stepper.";
                                                   >> 1149          G4Exception("G4Scheduler::ExtractTimeStepperData","ITScheduler008",
                                                   >> 1150          FatalErrorInArgument,exceptionDescription);
                                                   >> 1151          continue ;
                                                   >> 1152          }
                                                   >> 1153          */
                                                   >> 1154         if (bool(reactants))
                                                   >> 1155         {
                                                   >> 1156           // G4cout << "*** (2) G4Scheduler::ExtractTimeStepperData insert
                                                   >> 1157           //          reactants for " << GetIT(track)->GetName() << G4endl;
                                                   >> 1158           // G4cout << "bool(reactants) = " << bool(reactants) << G4endl;
                                                   >> 1159           // G4cout << "trackA : " << GetIT(track)->GetName()
                                                   >> 1160           //        << " ("<< track->GetTrackID() << ")" << G4endl;
                                                   >> 1161           // G4cout << reactants->size() << G4endl;
                                                   >> 1162           // G4cout << GetIT(reactants->operator[](0))->GetName() << G4endl;
                                                   >> 1163 
                                                   >> 1164           fReactingTracks.insert(make_pair(track, reactants));
                                                   >> 1165           stepper->ResetReactants();
                                                   >> 1166         }
                                                   >> 1167       }
                                                   >> 1168       else
                                                   >> 1169       {
                                                   >> 1170         if (bool(reactants))
                                                   >> 1171         {
                                                   >> 1172           stepper->ResetReactants();
                                                   >> 1173         }
                                                   >> 1174       }
                                                   >> 1175     }
                                                   >> 1176   }
                                                   >> 1177 
                                                   >> 1178   MP->CleanProcessor();
                                                   >> 1179 }
                                                   >> 1180 //_________________________________________________________________________
                                                   >> 1181 
                                                   >> 1182 void G4Scheduler::ComputeInteractionLength()
                                                   >> 1183 {
                                                   >> 1184   G4TrackManyList* mainList = fTrackContainer.GetMainList();
                                                   >> 1185   G4TrackManyList::iterator it = mainList ->begin();
                                                   >> 1186   G4TrackManyList::iterator end = mainList ->end();
                                                   >> 1187 
                                                   >> 1188   fpStepProcessor->SetPreviousStepTime(fPreviousTimeStep);
816                                                   1189 
                                                   >> 1190   for (; it != end; it++)
                                                   >> 1191   {
                                                   >> 1192     G4Track * track = *it;
                                                   >> 1193 
                                                   >> 1194 #ifdef DEBUG
                                                   >> 1195     G4cout << "*CIL* " << GetIT(track)->GetName()
                                                   >> 1196         << " ID: " << track->GetTrackID()
                                                   >> 1197         <<  " at time : " << track->GetGlobalTime()
                                                   >> 1198         << G4endl;
                                                   >> 1199 #endif
                                                   >> 1200 
                                                   >> 1201     fpStepProcessor->DefinePhysicalStepLength(track);
                                                   >> 1202 
                                                   >> 1203     if (fpStepProcessor->GetTrack()) ExtractILData(fpStepProcessor);
                                                   >> 1204   }
                                                   >> 1205 }
817 //____________________________________________    1206 //_________________________________________________________________________
818                                                   1207 
819 void G4Scheduler::EndTracking()                << 1208 void G4Scheduler::ExtractILData(G4ITStepProcessor* SP)
                                                   >> 1209 {
                                                   >> 1210   G4Track* track = SP->GetTrack();
                                                   >> 1211   if (!track)
                                                   >> 1212   {
                                                   >> 1213     SP->CleanProcessor();
                                                   >> 1214     return;
                                                   >> 1215   }
                                                   >> 1216   if (track->GetTrackStatus() == fStopAndKill)
                                                   >> 1217   {
                                                   >> 1218     fTrackContainer.GetMainList()->pop(track);
                                                   >> 1219     EndTracking(track);
                                                   >> 1220     //return;
                                                   >> 1221   }
                                                   >> 1222 
                                                   >> 1223   if (IsInf(SP->GetInteractionTime()))
                                                   >> 1224   {
                                                   >> 1225     // G4cout << "!!!!!!!!!!!! IS INF " << track->GetTrackID() << G4endl;
                                                   >> 1226     SP->CleanProcessor();
                                                   >> 1227     return;
                                                   >> 1228   }
                                                   >> 1229   else if (SP->GetInteractionTime() < fILTimeStep - DBL_EPSILON)
                                                   >> 1230   {
                                                   >> 1231     // G4cout << "!!!!!!!!!!!! TEMPS DIFFERENTS "
                                                   >> 1232     //    << track->GetTrackID() << G4endl;
                                                   >> 1233 
                                                   >> 1234     ResetLeadingTracks();
                                                   >> 1235 
                                                   >> 1236     fILTimeStep = SP -> GetInteractionTime();
                                                   >> 1237 
                                                   >> 1238 //    G4cout << "Will set leading step to true for time  :"
                                                   >> 1239 //           << SP -> GetInteractionTime() << " against fTimeStep : "
                                                   >> 1240 //           << G4BestUnit(fILTimeStep, "Time") << " the trackID is : " << track->GetTrackID()
                                                   >> 1241 //           << G4endl;
                                                   >> 1242 
                                                   >> 1243     GetIT(track)->GetTrackingInfo()->SetLeadingStep(true);
                                                   >> 1244     fLeadingTracks.push_back(track);
                                                   >> 1245   }
                                                   >> 1246   else if(fabs(fILTimeStep - SP -> GetInteractionTime()) < DBL_EPSILON )
                                                   >> 1247   {
                                                   >> 1248 
                                                   >> 1249     // G4cout << "!!!!!!!!!!!! MEME TEMPS " << track->GetTrackID() << G4endl;
                                                   >> 1250     // G4cout << "Will set leading step to true for time  :"
                                                   >> 1251     //        << SP -> GetInteractionTime() << " against fTimeStep : "
                                                   >> 1252     //        << fTimeStep << " the trackID is : " << track->GetTrackID()<< G4endl;
                                                   >> 1253     GetIT(track)->GetTrackingInfo()->SetLeadingStep(true);
                                                   >> 1254     fLeadingTracks.push_back(track);
                                                   >> 1255   }
                                                   >> 1256   // else
                                                   >> 1257   // {
                                                   >> 1258   //     G4cout << "!!!! Bigger time : " << "currentTime : "<<fILTimeStep
                                                   >> 1259   //  << " proposedTime : " << SP -> GetInteractionTime() << G4endl;
                                                   >> 1260   // }
                                                   >> 1261 
                                                   >> 1262   SP->CleanProcessor();
                                                   >> 1263 }
                                                   >> 1264 //_________________________________________________________________________
                                                   >> 1265 
                                                   >> 1266 void G4Scheduler::DoIt()
                                                   >> 1267 
                                                   >> 1268 // Call the process having the min step length or just propagate the track on the given time step
                                                   >> 1269 
                                                   >> 1270 // If the track is "leading the step" (ie one of its process has been selected
                                                   >> 1271 // as the one having the minimum time step over all tracks and processes),
                                                   >> 1272 // it will undergo its selected processes. Otherwise, it will just propagate the track
                                                   >> 1273 // on the given time step.
                                                   >> 1274 
                                                   >> 1275 {
                                                   >> 1276 
                                                   >> 1277 #ifdef G4VERBOSE
                                                   >> 1278   if (fVerbose > 3)
                                                   >> 1279   {
                                                   >> 1280 #ifdef USE_COLOR
                                                   >> 1281       G4cout << LIGHT_RED;
                                                   >> 1282 #endif
                                                   >> 1283     G4cout << "*** G4Scheduler::DoIt ***" << G4endl;
                                                   >> 1284     G4cout << setw(18) << left << "#Name"
                                                   >> 1285     << setw(15) << "trackID"
                                                   >> 1286     << setw(35) << "Position"
                                                   >> 1287     << setw(25) << "Pre step volume"
                                                   >> 1288     << setw(25) << "Post step volume"
                                                   >> 1289     << setw(22) << "Process"
                                                   >> 1290     << G4endl;
                                                   >> 1291 #ifdef USE_COLOR
                                                   >> 1292       G4cout << RESET_COLOR;
                                                   >> 1293 #endif
                                                   >> 1294   }
                                                   >> 1295 #endif
                                                   >> 1296 
                                                   >> 1297   G4TrackManyList* mainList = fTrackContainer.GetMainList();
                                                   >> 1298   G4TrackManyList::iterator it = mainList->end();
                                                   >> 1299   it--;
                                                   >> 1300   size_t initialSize = mainList->size();
                                                   >> 1301 
                                                   >> 1302 //  G4cout << "initialSize = " << initialSize << G4endl;
                                                   >> 1303 
                                                   >> 1304   for(size_t i = 0 ; i < initialSize ; i++)
                                                   >> 1305   {
                                                   >> 1306 
                                                   >> 1307 //    G4cout << "i = " << i << G4endl;
                                                   >> 1308 
                                                   >> 1309     G4Track* track = *it;
                                                   >> 1310     if (!track)
                                                   >> 1311     {
                                                   >> 1312       G4ExceptionDescription exceptionDescription;
                                                   >> 1313       exceptionDescription << "No track was pop back the main track list.";
                                                   >> 1314       G4Exception("G4Scheduler::DoIt", "ITScheduler009",
                                                   >> 1315           FatalErrorInArgument, exceptionDescription);
                                                   >> 1316     }
                                                   >> 1317 
                                                   >> 1318 #ifdef DEBUG
                                                   >> 1319 #ifdef USE_COLOR
                                                   >> 1320       G4cout << LIGHT_RED;
                                                   >> 1321 #endif
                                                   >> 1322     G4cout << "*DoIt* " << GetIT(track)->GetName()
                                                   >> 1323             << " ID: " << track->GetTrackID()
                                                   >> 1324             <<  " at time : " << track->GetGlobalTime()
                                                   >> 1325             << G4endl;
                                                   >> 1326 #ifdef USE_COLOR
                                                   >> 1327       G4cout << RESET_COLOR;
                                                   >> 1328 #endif
                                                   >> 1329 #endif
                                                   >> 1330 //    G4TrackManyList::iterator next_it (it);
                                                   >> 1331 //    next_it--;
                                                   >> 1332 //    it = next_it;
                                                   >> 1333 
                                                   >> 1334     it--;
                                                   >> 1335 
                                                   >> 1336 #ifdef G4VERBOSE
                                                   >> 1337     /////
                                                   >> 1338     // PRE STEP VERBOSE
                                                   >> 1339     if(fVerbose > 3)
                                                   >> 1340     {
                                                   >> 1341       G4String volumeName;
                                                   >> 1342 
                                                   >> 1343       G4TouchableHandle nextTouchable = track->GetNextTouchableHandle();
                                                   >> 1344       G4VPhysicalVolume* volume (0);
                                                   >> 1345 
                                                   >> 1346       if(nextTouchable
                                                   >> 1347           && (volume = nextTouchable->GetVolume()))
                                                   >> 1348       {
                                                   >> 1349         volumeName = volume->GetName();
                                                   >> 1350 
                                                   >> 1351         if(volume->IsParameterised() || volume->IsReplicated())
                                                   >> 1352         {
                                                   >> 1353           volumeName+=" ";
                                                   >> 1354           volumeName+=nextTouchable->GetReplicaNumber();
                                                   >> 1355         }
                                                   >> 1356       }
                                                   >> 1357       else
                                                   >> 1358       {
                                                   >> 1359         volumeName = "OutOfWorld";
                                                   >> 1360       }
                                                   >> 1361 
                                                   >> 1362       G4cout << setw(18) << left << GetIT(track)->GetName()
                                                   >> 1363       << setw(15) << track->GetTrackID()
                                                   >> 1364       << std::setprecision(3)
                                                   >> 1365       << setw(35) << G4String(G4BestUnit(track->GetPosition(), "Length"))
                                                   >> 1366       << setw(25) << volumeName
                                                   >> 1367       << setw(25) << "---"
                                                   >> 1368       << G4endl;
                                                   >> 1369     }
                                                   >> 1370 #endif
                                                   >> 1371 
                                                   >> 1372 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DOIT)
                                                   >> 1373     MemStat mem_first, mem_second, mem_diff;
                                                   >> 1374 #endif
                                                   >> 1375 
                                                   >> 1376 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DOIT)
                                                   >> 1377     mem_first = MemoryUsage();
                                                   >> 1378 #endif
                                                   >> 1379 
                                                   >> 1380     //  G4cout << " G4Scheduler::DoIt -- fTimeStep="
                                                   >> 1381 //    << fTimeStep << G4endl;
                                                   >> 1382     fpStepProcessor->Stepping(track, fTimeStep);
                                                   >> 1383 
                                                   >> 1384 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DOIT)
                                                   >> 1385     MemStat mem_intermediaire = MemoryUsage();
                                                   >> 1386     mem_diff = mem_intermediaire-mem_first;
                                                   >> 1387     G4cout << "\t\t >> || MEM || In DoIT with track "
                                                   >> 1388         << track->GetTrackID() << ", diff is : " << mem_diff << G4endl;
                                                   >> 1389 #endif
                                                   >> 1390 
                                                   >> 1391     ExtractDoItData(fpStepProcessor);
                                                   >> 1392 
                                                   >> 1393 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DOIT)
                                                   >> 1394     mem_second = MemoryUsage();
                                                   >> 1395     mem_diff = mem_second-mem_first;
                                                   >> 1396     G4cout << "\t >> || MEM || In DoIT with track "
                                                   >> 1397         << track->GetTrackID()
                                                   >> 1398         << ", diff is : " << mem_diff << G4endl;
                                                   >> 1399 #endif
                                                   >> 1400 
                                                   >> 1401 #ifdef G4VERBOSE
                                                   >> 1402     /////
                                                   >> 1403     // POST STEP VERBOSE
                                                   >> 1404     if(fVerbose > 3)
                                                   >> 1405     {
                                                   >> 1406       G4cout << setw(18) << left << GetIT(track)->GetName()
                                                   >> 1407       << setw(15) << track->GetTrackID()
                                                   >> 1408       << std::setprecision(3)
                                                   >> 1409       << setw(35) << G4String(G4BestUnit(track->GetPosition(), "Length" ))
                                                   >> 1410       << setw(25) << "---";
                                                   >> 1411 
                                                   >> 1412       G4TouchableHandle nextTouchable = track->GetNextTouchableHandle();
                                                   >> 1413       G4VPhysicalVolume* volume (0);
                                                   >> 1414 
                                                   >> 1415       if(nextTouchable
                                                   >> 1416           && (volume = nextTouchable->GetVolume()))
                                                   >> 1417       {
                                                   >> 1418         G4String volumeName = volume->GetName();
                                                   >> 1419 
                                                   >> 1420         if(volume->IsParameterised() || volume->IsReplicated())
                                                   >> 1421         {
                                                   >> 1422           volumeName+=" ";
                                                   >> 1423           volumeName+=nextTouchable->GetReplicaNumber();
                                                   >> 1424         }
                                                   >> 1425 
                                                   >> 1426         G4cout << setw(25) << volumeName;
                                                   >> 1427       }
                                                   >> 1428       else
                                                   >> 1429       {
                                                   >> 1430         G4cout << setw(25) << "OutOfWorld";
                                                   >> 1431       }
                                                   >> 1432       if(track->GetStep()->GetPostStepPoint()->GetProcessDefinedStep())
                                                   >> 1433       {
                                                   >> 1434         G4cout << setw(22)
                                                   >> 1435             << track->GetStep()->GetPostStepPoint()->GetProcessDefinedStep()
                                                   >> 1436         ->GetProcessName();
                                                   >> 1437       }
                                                   >> 1438       else
                                                   >> 1439       {
                                                   >> 1440         G4cout << "---";
                                                   >> 1441       }
                                                   >> 1442       G4cout << G4endl;
                                                   >> 1443 
                                                   >> 1444       if(fVerbose > 4)
                                                   >> 1445       {
                                                   >> 1446         const G4TrackVector* secondaries = 0;
                                                   >> 1447         if((secondaries = track->GetStep()->GetSecondary()))
                                                   >> 1448         {
                                                   >> 1449           if(secondaries->empty() == false)
                                                   >> 1450           {
                                                   >> 1451             G4cout << "\t\t ---->";
                                                   >> 1452             for(size_t j = 0; j < secondaries->size(); j++)
                                                   >> 1453             {
                                                   >> 1454               G4cout << GetIT((*secondaries)[j])->GetName()
                                                   >> 1455                   << "("<<(*secondaries)[j]->GetTrackID() << ")"<< " ";
                                                   >> 1456             }
                                                   >> 1457             G4cout << G4endl;
                                                   >> 1458           }
                                                   >> 1459         }
                                                   >> 1460       }
                                                   >> 1461     }
                                                   >> 1462 #endif
                                                   >> 1463   }
                                                   >> 1464 }
                                                   >> 1465 //_________________________________________________________________________
                                                   >> 1466 
                                                   >> 1467 void G4Scheduler::ExtractDoItData(G4ITStepProcessor* SP)
                                                   >> 1468 {
                                                   >> 1469 
                                                   >> 1470   G4Track* track = SP->GetTrack();
                                                   >> 1471   if (!track)
                                                   >> 1472   {
                                                   >> 1473     SP->CleanProcessor();
                                                   >> 1474     return;
                                                   >> 1475   }
                                                   >> 1476 
                                                   >> 1477   G4TrackStatus status = track->GetTrackStatus();
                                                   >> 1478 
                                                   >> 1479   switch (status)
                                                   >> 1480   {
                                                   >> 1481     case fAlive:
                                                   >> 1482     case fStopButAlive:
                                                   >> 1483     case fSuspend:
                                                   >> 1484     case fPostponeToNextEvent:
                                                   >> 1485     default:
                                                   >> 1486       PushSecondaries(SP);
                                                   >> 1487       break;
                                                   >> 1488 
                                                   >> 1489     case fStopAndKill:
                                                   >> 1490       PushSecondaries(SP);
                                                   >> 1491       G4TrackList::Pop(track);
                                                   >> 1492       EndTracking(track);
                                                   >> 1493       break;
                                                   >> 1494 
                                                   >> 1495     case fKillTrackAndSecondaries:
                                                   >> 1496       G4TrackVector* secondaries = SP->GetSecondaries();
                                                   >> 1497       if (secondaries)
                                                   >> 1498       {
                                                   >> 1499         for (size_t i = 0; i < secondaries->size(); i++)
                                                   >> 1500         {
                                                   >> 1501           delete (*secondaries)[i];
                                                   >> 1502         }
                                                   >> 1503         secondaries->clear();
                                                   >> 1504       }
                                                   >> 1505       G4TrackList::Pop(track);
                                                   >> 1506       EndTracking(track);
                                                   >> 1507       break;
                                                   >> 1508   }
                                                   >> 1509   SP->CleanProcessor();
                                                   >> 1510 }
                                                   >> 1511 //_________________________________________________________________________
                                                   >> 1512 
                                                   >> 1513 void G4Scheduler::PushSecondaries(G4ITStepProcessor* SP)
                                                   >> 1514 {
                                                   >> 1515   G4TrackVector* secondaries = SP->GetSecondaries();
                                                   >> 1516   if (!secondaries || secondaries->empty())
                                                   >> 1517   {
                                                   >> 1518     // DEBUG
                                                   >> 1519     //      G4cout << "NO SECONDARIES !!! " << G4endl;
                                                   >> 1520     return;
                                                   >> 1521   }
                                                   >> 1522 
                                                   >> 1523   // DEBUG
                                                   >> 1524   //    G4cout << "There are secondaries : "<< secondaries -> size() << G4endl ;
                                                   >> 1525 
                                                   >> 1526   G4TrackVector::iterator secondaries_i = secondaries->begin();
                                                   >> 1527 
                                                   >> 1528   for (; secondaries_i != secondaries->end(); secondaries_i++)
                                                   >> 1529   {
                                                   >> 1530     G4Track* secondary = *secondaries_i;
                                                   >> 1531     fTrackContainer._PushTrack(secondary);
                                                   >> 1532   }
                                                   >> 1533 }
                                                   >> 1534 
                                                   >> 1535 //_________________________________________________________________________
                                                   >> 1536 
                                                   >> 1537 void G4Scheduler::ComputeTrackReaction()
                                                   >> 1538 {
                                                   >> 1539   if (fReactingTracks.empty())
                                                   >> 1540   {
                                                   >> 1541     return;
                                                   >> 1542   }
                                                   >> 1543 
                                                   >> 1544   if (fITStepStatus == eCollisionBetweenTracks)
                                                   >> 1545   //        if(fInteractionStep == false)
                                                   >> 1546   {
                                                   >> 1547     fpModelProcessor->FindReaction(&fReactingTracks, fTimeStep,
                                                   >> 1548                                    fPreviousTimeStep, fReachedUserTimeLimit);
                                                   >> 1549     // TODO
                                                   >> 1550     // A ne faire uniquement si le temps choisis est celui calculé par le time stepper
                                                   >> 1551     // Sinon utiliser quelque chose comme : fModelProcessor->FindReaction(&fMainList);
                                                   >> 1552 
                                                   >> 1553     std::vector<G4ITReactionChange*> * reactionInfo_v = fpModelProcessor
                                                   >> 1554         ->GetReactionInfo();
                                                   >> 1555     std::vector<G4ITReactionChange*>::iterator reactionInfo_i = reactionInfo_v
                                                   >> 1556         ->begin();
                                                   >> 1557 
                                                   >> 1558     for (; reactionInfo_i != reactionInfo_v->end(); reactionInfo_i++)
                                                   >> 1559     {
                                                   >> 1560       G4ITReactionChange* changes = (*reactionInfo_i);
                                                   >> 1561       G4Track* trackA = const_cast<G4Track*>(changes->GetTrackA());
                                                   >> 1562       G4Track* trackB = const_cast<G4Track*>(changes->GetTrackB());
                                                   >> 1563 
                                                   >> 1564       if (trackA == 0 || trackB == 0 || trackA->GetTrackStatus() == fStopAndKill
                                                   >> 1565           || trackB->GetTrackStatus() == fStopAndKill) continue;
                                                   >> 1566 
                                                   >> 1567       G4int nbSecondaries = changes->GetNumberOfSecondaries();
                                                   >> 1568 
                                                   >> 1569       if (fpUserTimeStepAction)
                                                   >> 1570       {
                                                   >> 1571         const vector<G4Track*>* productsVector = changes->GetfSecondary();
                                                   >> 1572         fpUserTimeStepAction->UserReactionAction(*trackA, *trackB,
                                                   >> 1573                                                  *productsVector);
                                                   >> 1574       }
                                                   >> 1575 
                                                   >> 1576 #ifdef G4VERBOSE
                                                   >> 1577       if (fVerbose)
                                                   >> 1578       {
                                                   >> 1579         G4cout << "At time : " << setw(7) << G4BestUnit(fGlobalTime, "Time")
                                                   >> 1580                << " Reaction : " << GetIT(trackA)->GetName() << " ("
                                                   >> 1581                << trackA->GetTrackID() << ") + " << GetIT(trackB)->GetName()
                                                   >> 1582                << " (" << trackB->GetTrackID() << ") -> ";
                                                   >> 1583       }
                                                   >> 1584 #endif
                                                   >> 1585 
                                                   >> 1586       if (nbSecondaries > 0)
                                                   >> 1587       {
                                                   >> 1588         for (int i = 0; i < nbSecondaries; i++)
                                                   >> 1589         {
                                                   >> 1590 #ifdef G4VERBOSE
                                                   >> 1591           if (fVerbose && i != 0) G4cout << " + ";
                                                   >> 1592 #endif
                                                   >> 1593 
                                                   >> 1594           G4Track* secondary = changes->GetSecondary(i);
                                                   >> 1595           fTrackContainer._PushTrack(secondary);
                                                   >> 1596           GetIT(secondary)->SetParentID(trackA->GetTrackID(),
                                                   >> 1597                                         trackB->GetTrackID());
                                                   >> 1598 
                                                   >> 1599           if (secondary->GetGlobalTime() - fGlobalTime > fTimeTolerance)
                                                   >> 1600           {
                                                   >> 1601             G4ExceptionDescription exceptionDescription;
                                                   >> 1602             exceptionDescription
                                                   >> 1603                 << "The time of the secondary should not be bigger than the"
                                                   >> 1604                     " current global time."
                                                   >> 1605                 << " This may cause synchronization problem. If the process you"
                                                   >> 1606                     " are using required "
                                                   >> 1607                 << "such feature please contact the developpers."
                                                   >> 1608                 << G4endl
                                                   >> 1609                 << "The global time in the step manager : "
                                                   >> 1610                 << G4BestUnit(fGlobalTime,"Time")
                                                   >> 1611                 << G4endl
                                                   >> 1612                 << "The global time of the track : "
                                                   >> 1613                 << G4BestUnit(secondary->GetGlobalTime(),"Time")
                                                   >> 1614                 << G4endl;
                                                   >> 1615 
                                                   >> 1616             G4Exception("G4Scheduler::ComputeInteractionBetweenTracks",
                                                   >> 1617                         "ITScheduler010", FatalErrorInArgument,
                                                   >> 1618                         exceptionDescription);
                                                   >> 1619           }
                                                   >> 1620 
                                                   >> 1621 #ifdef G4VERBOSE
                                                   >> 1622           if (fVerbose) G4cout << GetIT(secondary)->GetName() << " ("
                                                   >> 1623                                << secondary->GetTrackID() << ")";
                                                   >> 1624 #endif
                                                   >> 1625         }
                                                   >> 1626       }
                                                   >> 1627       else
                                                   >> 1628       {
                                                   >> 1629 #ifdef G4VERBOSE
                                                   >> 1630         if (fVerbose) G4cout << "No product";
                                                   >> 1631 #endif
                                                   >> 1632       }
                                                   >> 1633 #ifdef G4VERBOSE
                                                   >> 1634       if (fVerbose) G4cout << G4endl;
                                                   >> 1635 #endif
                                                   >> 1636       if (trackA->GetTrackID() == 0 || trackB->GetTrackID() == 0)
                                                   >> 1637       {
                                                   >> 1638         G4Track* track = 0;
                                                   >> 1639         if (trackA->GetTrackID() == 0) track = trackA;
                                                   >> 1640         else track = trackB;
                                                   >> 1641 
                                                   >> 1642         G4ExceptionDescription exceptionDescription;
                                                   >> 1643         exceptionDescription
                                                   >> 1644             << "The problem was found for the reaction between tracks :"
                                                   >> 1645             << trackA->GetParticleDefinition()->GetParticleName() << " ("
                                                   >> 1646             << trackA->GetTrackID() << ") & "
                                                   >> 1647             << trackB->GetParticleDefinition()->GetParticleName() << " ("
                                                   >> 1648             << trackB->GetTrackID() << "). \n";
                                                   >> 1649 
                                                   >> 1650         if (track->GetStep() == 0)
                                                   >> 1651         {
                                                   >> 1652           exceptionDescription << "Also no step was found"
                                                   >> 1653                                << " ie track->GetStep() == 0 \n";
                                                   >> 1654         }
                                                   >> 1655 
                                                   >> 1656         exceptionDescription << "Parent ID of trackA : "
                                                   >> 1657                              << trackA->GetParentID() << "\n";
                                                   >> 1658         exceptionDescription << "Parent ID of trackB : "
                                                   >> 1659                              << trackB->GetParentID() << "\n";
                                                   >> 1660 
                                                   >> 1661         exceptionDescription
                                                   >> 1662             << "The ID of one of the reaction track was not setup.";
                                                   >> 1663         G4Exception("G4Scheduler::ComputeInteractionBetweenTracks",
                                                   >> 1664                     "ITScheduler011", FatalErrorInArgument,
                                                   >> 1665                     exceptionDescription);
                                                   >> 1666       }
                                                   >> 1667 
                                                   >> 1668       if (changes->WereParentsKilled())
                                                   >> 1669       {
                                                   >> 1670         // DEBUG
                                                   >> 1671         // G4cout << "Erasing tracks : "
                                                   >> 1672         //  << "trackA at time : " << G4BestUnit(trackA->GetGlobalTime() , "Time")
                                                   >> 1673         //  << "\t trackB at time : "<< G4BestUnit(trackB->GetGlobalTime(), "Time")
                                                   >> 1674         //  << "\t GlobalTime : " << G4BestUnit(fGlobalTime, "Time")
                                                   >> 1675         //  << G4endl;
                                                   >> 1676 
                                                   >> 1677         trackA->SetTrackStatus(fStopAndKill);
                                                   >> 1678         trackB->SetTrackStatus(fStopAndKill);
                                                   >> 1679 
                                                   >> 1680         G4TrackList::Pop(trackA);
                                                   >> 1681         G4TrackList::Pop(trackB);
                                                   >> 1682         EndTracking(trackA);
                                                   >> 1683         EndTracking(trackB);
                                                   >> 1684       }
                                                   >> 1685 
                                                   >> 1686       delete changes;
                                                   >> 1687     }
                                                   >> 1688 
                                                   >> 1689     reactionInfo_v->clear(); // never null because point to a non-pointer member of ModelProcessor
                                                   >> 1690   }
                                                   >> 1691   // DEBUG
                                                   >> 1692   //else
                                                   >> 1693   //{
                                                   >> 1694   //    G4cout << "fInteractionStep == true" << G4endl ;
                                                   >> 1695   //}
                                                   >> 1696 
                                                   >> 1697   fReactingTracks.clear();
                                                   >> 1698 }
                                                   >> 1699 
                                                   >> 1700 //_________________________________________________________________________
                                                   >> 1701 
                                                   >> 1702 void G4Scheduler::AddTrackID(G4Track* track)
820 {                                                 1703 {
821   if (fRunning) {                              << 1704   if (fNbTracks == 0) fNbTracks = -1;
                                                   >> 1705   track->SetTrackID(fNbTracks);
                                                   >> 1706   fNbTracks--;
                                                   >> 1707 }
                                                   >> 1708 
                                                   >> 1709 //_________________________________________________________________________
                                                   >> 1710 
                                                   >> 1711 void G4Scheduler::PushTrack(G4Track* track)
                                                   >> 1712 {
                                                   >> 1713   if (fRunning)
                                                   >> 1714   {
822     G4ExceptionDescription exceptionDescriptio    1715     G4ExceptionDescription exceptionDescription;
823     exceptionDescription << "End tracking is c << 1716     exceptionDescription
                                                   >> 1717         << "G4Scheduler::PushTrack : You are trying to push tracks while the "
                                                   >> 1718             "ITScheduler is running";
                                                   >> 1719     G4Exception("G4Scheduler::PushTrack", "ITScheduler012",
                                                   >> 1720                 FatalErrorInArgument, exceptionDescription);
                                                   >> 1721   }
                                                   >> 1722   fTrackContainer._PushTrack(track);
                                                   >> 1723 }
                                                   >> 1724 //_________________________________________________________________________
                                                   >> 1725 
                                                   >> 1726 void G4Scheduler::KillTracks()
                                                   >> 1727 {
                                                   >> 1728   fTrackContainer.KillTracks();
                                                   >> 1729 }
                                                   >> 1730 //_________________________________________________________________________
                                                   >> 1731 
                                                   >> 1732 void G4Scheduler::ResetLeadingTracks()
                                                   >> 1733 {
                                                   >> 1734   if (fLeadingTracks.empty() == false)
                                                   >> 1735   {
                                                   >> 1736     std::vector<G4Track*>::iterator fLeadingTracks_i = fLeadingTracks.begin();
                                                   >> 1737 
                                                   >> 1738     while (fLeadingTracks_i != fLeadingTracks.end())
                                                   >> 1739     {
                                                   >> 1740       G4Track* track = *fLeadingTracks_i;
                                                   >> 1741       if (track)
                                                   >> 1742       {
                                                   >> 1743         G4IT* ITrack = GetIT(*fLeadingTracks_i);
                                                   >> 1744         if (ITrack)
                                                   >> 1745         {
                                                   >> 1746           GetIT(*fLeadingTracks_i)->GetTrackingInfo()->SetLeadingStep(false);
                                                   >> 1747         }
                                                   >> 1748       }
824                                                   1749 
825     G4Exception("G4Scheduler::EndTracking", "S << 1750       fLeadingTracks_i++;
826                 exceptionDescription);         << 1751       continue;
                                                   >> 1752     }
                                                   >> 1753 
                                                   >> 1754     fLeadingTracks.clear();
827   }                                               1755   }
                                                   >> 1756 }
828                                                   1757 
829   while (fTrackContainer.DelayListsNOTEmpty()) << 1758 //_________________________________________________________________________
830     auto nextTime = fTrackContainer.GetNextTim << 1759 
831     fTrackContainer.MergeNextTimeToMainList(ne << 1760 void G4Scheduler::EndTracking(G4Track* trackToBeKilled)
                                                   >> 1761 {
                                                   >> 1762   fpTrackingManager->EndTracking(trackToBeKilled);
                                                   >> 1763   fTrackContainer.PushToKill(trackToBeKilled);
                                                   >> 1764 }
                                                   >> 1765 //_________________________________________________________________________
                                                   >> 1766 
                                                   >> 1767 void G4Scheduler::EndTracking()
                                                   >> 1768 {
                                                   >> 1769   if (fRunning)
                                                   >> 1770   {
                                                   >> 1771     G4ExceptionDescription exceptionDescription;
                                                   >> 1772     exceptionDescription
                                                   >> 1773         << "End tracking is called while G4Scheduler is still running."
                                                   >> 1774         << G4endl;
                                                   >> 1775 
                                                   >> 1776     G4Exception("G4Scheduler::EndTracking", "ITScheduler017",
                                                   >> 1777                 FatalErrorInArgument, exceptionDescription);
832   }                                               1778   }
833                                                   1779 
834   fTrackContainer.MergeSecondariesWithMainList    1780   fTrackContainer.MergeSecondariesWithMainList();
835                                                   1781 
836   if (fTrackContainer.MainListsNOTEmpty()) {   << 1782   if (fTrackContainer.MainListsNOTEmpty())
                                                   >> 1783   {
837     G4TrackManyList* mainList = fTrackContaine    1784     G4TrackManyList* mainList = fTrackContainer.GetMainList();
838     G4TrackManyList::iterator it = mainList->b    1785     G4TrackManyList::iterator it = mainList->begin();
839     G4TrackManyList::iterator end = mainList->    1786     G4TrackManyList::iterator end = mainList->end();
840     for (; it != end; ++it) {                  << 1787     for (; it != end; it++)
841       fpTrackingManager->EndTrackingWOKill(*it << 1788     {
                                                   >> 1789       fpTrackingManager->EndTracking(*it);
842     }                                             1790     }
843   }                                               1791   }
844                                                   1792 
845   if (fTrackContainer.SecondaryListsNOTEmpty() << 1793   if (fTrackContainer.SecondaryListsNOTEmpty()) // should be empty
846   {                                               1794   {
847     G4TrackManyList* secondaries = fTrackConta    1795     G4TrackManyList* secondaries = fTrackContainer.GetSecondariesList();
848     G4TrackManyList::iterator it = secondaries    1796     G4TrackManyList::iterator it = secondaries->begin();
849     G4TrackManyList::iterator end = secondarie    1797     G4TrackManyList::iterator end = secondaries->end();
850                                                   1798 
851     for (; it != end; ++it) {                  << 1799     for (; it != end; it++)
852       fpTrackingManager->EndTrackingWOKill(*it << 1800     {
                                                   >> 1801       fpTrackingManager->EndTracking(*it);
853     }                                             1802     }
854   }                                               1803   }
855 }                                                 1804 }
856                                                   1805 
857 //____________________________________________    1806 //_________________________________________________________________________
858 void G4Scheduler::SetInteractivity(G4ITTrackin    1807 void G4Scheduler::SetInteractivity(G4ITTrackingInteractivity* interactivity)
859 {                                                 1808 {
860   fpTrackingInteractivity = interactivity;        1809   fpTrackingInteractivity = interactivity;
861   if (fpTrackingManager != nullptr) {          << 1810   if (fpTrackingManager) fpTrackingManager->SetInteractivity(
862     fpTrackingManager->SetInteractivity(fpTrac << 1811       fpTrackingInteractivity);
863   }                                            << 
864 }                                                 1812 }
865                                                   1813 
866 //____________________________________________    1814 //_________________________________________________________________________
867 void G4Scheduler::ForceReinitialization()         1815 void G4Scheduler::ForceReinitialization()
868 {                                                 1816 {
869   fInitialized = false;                           1817   fInitialized = false;
870   Initialize();                                   1818   Initialize();
871 }                                                 1819 }
872                                                   1820 
                                                   >> 1821 //_________________________________________________________________________
                                                   >> 1822 G4Scheduler::G4Scheduler(const G4Scheduler&) :
                                                   >> 1823     G4VScheduler(), G4VStateDependent(),
                                                   >> 1824 fTrackContainer((G4ITTrackHolder&)*G4ITTrackHolder::Instance())
                                                   >> 1825 
                                                   >> 1826 {
                                                   >> 1827   Create();
                                                   >> 1828 }
                                                   >> 1829 
                                                   >> 1830 //_________________________________________________________________________
                                                   >> 1831 G4Scheduler& G4Scheduler::operator=(const G4Scheduler& right)
                                                   >> 1832 {
                                                   >> 1833   if (this != &right)
                                                   >> 1834   {
                                                   >> 1835     Create();
                                                   >> 1836   }
                                                   >> 1837   return *this;
                                                   >> 1838 }
                                                   >> 1839 
873 size_t G4Scheduler::GetNTracks()                  1840 size_t G4Scheduler::GetNTracks()
874 {                                                 1841 {
875   return fTrackContainer.GetNTracks();            1842   return fTrackContainer.GetNTracks();
876 }                                                 1843 }
877 //____________________________________________    1844 //_________________________________________________________________________
878                                                   1845 
879 void G4Scheduler::GetCollisionType(G4String& i    1846 void G4Scheduler::GetCollisionType(G4String& interactionType)
880 {                                                 1847 {
881   switch (fITStepStatus) {                     << 1848   switch(fITStepStatus)
                                                   >> 1849   {
882     case eInteractionWithMedium:                  1850     case eInteractionWithMedium:
883       interactionType = "eInteractionWithMediu    1851       interactionType = "eInteractionWithMedium";
884       break;                                      1852       break;
885     case eCollisionBetweenTracks:                 1853     case eCollisionBetweenTracks:
886       interactionType = "eCollisionBetweenTrac    1854       interactionType = "eCollisionBetweenTracks";
887       break;                                      1855       break;
888     default:                                      1856     default:
889       interactionType = "eCollisionBetweenTrac    1857       interactionType = "eCollisionBetweenTracks";
890       break;                                      1858       break;
891   }                                               1859   }
892 }                                                 1860 }
                                                   >> 1861 
893                                                   1862