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 9.0.p1)


  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25 //                                                
 26 //                                                
 27 // Author: Mathieu Karamitros (kara (AT) cenbg    
 28 //                                                
 29 // History:                                       
 30 // -----------                                    
 31 // 10 Oct 2011 M.Karamitros created               
 32 //                                                
 33 // -------------------------------------------    
 34                                                   
 35 #include "G4ITGun.hh"                             
 36 #include "G4ITModelHandler.hh"                    
 37 #include "G4ITModelProcessor.hh"                  
 38 #include "G4ITStepProcessor.hh"                   
 39 #include "G4ITStepStatus.hh"                      
 40 #include "G4ITTrackingInteractivity.hh"           
 41 #include "G4ITTrackingManager.hh"                 
 42 #include "G4IosFlagsSaver.hh"                     
 43 #include "G4StateManager.hh"                      
 44 #include "G4SystemOfUnits.hh"                     
 45 #include "G4Timer.hh"                             
 46 #include "G4TrackingInformation.hh"               
 47 #include "G4UnitsTable.hh"                        
 48 #include "G4UserTimeStepAction.hh"                
 49 #include "G4VITStepModel.hh"                      
 50                                                   
 51 #include <G4AllITFinder.hh>                       
 52 #include <G4Scheduler.hh>                         
 53 #include <G4SchedulerMessenger.hh>                
 54                                                   
 55 #include <sstream>                                
 56                                                   
 57 #define DEBUG_MEM_STEPPING                        
 58 #define DEBUG_MEM_DETAILED_STEPPING               
 59                                                   
 60 #ifdef DEBUG_MEM                                  
 61 #  include "G4MemStat.hh"                         
 62 using namespace G4MemStat;                        
 63 using G4MemStat::MemStat;                         
 64 #endif                                            
 65                                                   
 66 #ifdef USE_COLOR                                  
 67 #  define RED "\033[0;31m"                        
 68 #  define LIGHT_RED "\33[1;31m"                   
 69 #  define GREEN "\033[32;40m"                     
 70 #  define GREEN_ON_BLUE "\033[1;32;44m"           
 71 #  define RESET_COLOR "\033[0m"                   
 72 #else                                             
 73 #  define RED ""                                  
 74 #  define LIGHT_RED ""                            
 75 #  define GREEN ""                                
 76 #  define GREEN_ON_BLUE ""                        
 77 #  define RESET_COLOR ""                          
 78 #endif                                            
 79                                                   
 80 using namespace std;                              
 81                                                   
 82 G4ThreadLocal G4Scheduler* G4Scheduler::fgSche    
 83                                                   
 84 template<typename T>                              
 85 inline G4bool IsInf(T value)                      
 86 {                                                 
 87   return std::numeric_limits<T>::has_infinity     
 88 }                                                 
 89 //____________________________________________    
 90                                                   
 91 G4Scheduler* G4Scheduler::Instance()              
 92 {                                                 
 93   if (fgScheduler == nullptr) fgScheduler = ne    
 94   return fgScheduler;                             
 95 }                                                 
 96 //____________________________________________    
 97                                                   
 98 G4bool G4Scheduler::Notify(G4ApplicationState     
 99 {                                                 
100   if (requestedState == G4State_Quit) {           
101     if (fVerbose >= 4) {                          
102       G4cout << "G4Scheduler received G4State_    
103     }                                             
104     Clear();                                      
105   }                                               
106   return true;                                    
107 }                                                 
108 //____________________________________________    
109                                                   
110 void G4Scheduler::DeleteInstance()                
111 {                                                 
112   delete fgScheduler;                             
113 }                                                 
114 //____________________________________________    
115                                                   
116 G4Scheduler::G4Scheduler() : fTrackContainer((    
117 {                                                 
118   Create();                                       
119 }                                                 
120                                                   
121 void G4Scheduler::Create()                        
122 {                                                 
123   fUseDefaultTimeSteps = true;                    
124   fUserUpperTimeLimit = -1;                       
125   fpGun = nullptr;                                
126   fContinue = true;                               
127   fpTrackingInteractivity = nullptr;              
128   fITStepStatus = eUndefined;                     
129   fpUserTimeSteps = nullptr;                      
130   fTimeStep = DBL_MAX;                            
131   fTSTimeStep = DBL_MAX;                          
132   fILTimeStep = DBL_MAX;                          
133   fPreviousTimeStep = DBL_MAX;                    
134   fZeroTimeCount = 0;                             
135   fMaxNZeroTimeStepsAllowed = 10000;              
136   fStartTime = 0;                                 
137   fTimeTolerance = 1 * picosecond;                
138   fEndTime = 1 * microsecond;                     
139   fGlobalTime = -1;                               
140   fInteractionStep = true;                        
141   fUsePreDefinedTimeSteps = false;                
142                                                   
143   fDefaultMinTimeStep = 1 * picosecond;           
144   fpStepProcessor = nullptr;                      
145   fpModelProcessor = nullptr;                     
146   fNbSteps = 0;                                   
147   fMaxSteps = -1;                                 
148   fRunning = false;                               
149   fInitialized = false;                           
150   fpUserTimeStepAction = nullptr;                 
151   fpModelHandler = new G4ITModelHandler();        
152   fpTrackingManager = new G4ITTrackingManager(    
153   fVerbose = 0;                                   
154   fWhyDoYouStop = false;                          
155   fDefinedMinTimeStep = -1.;                      
156   fReachedUserTimeLimit = false;                  
157   fStopTime = -1.;                                
158   fpMessenger = new G4SchedulerMessenger(this)    
159   fReactionSet = G4ITReactionSet::Instance();     
160   fMaxTimeStep = DBL_MAX;                         
161   // hoang add                                    
162   fResetScavenger = true;  // true by default     
163   G4ITTypeManager::Instance()->ReserveRessourc    
164 }                                                 
165                                                   
166 //____________________________________________    
167                                                   
168 G4Scheduler::~G4Scheduler()                       
169 {                                                 
170   if (fpMessenger != nullptr)  // is used as a    
171   {                                               
172     Clear();                                      
173   }                                               
174   fgScheduler = nullptr;                          
175 }                                                 
176                                                   
177 void G4Scheduler::Clear()                         
178 {                                                 
179   if (fpMessenger != nullptr) {                   
180     delete fpMessenger;                           
181     fpMessenger = nullptr;                        
182   }                                               
183   if (fpStepProcessor != nullptr) {               
184     delete fpStepProcessor;                       
185     fpStepProcessor = nullptr;                    
186   }                                               
187   if (fpModelProcessor != nullptr) {              
188     delete fpModelProcessor;                      
189     fpModelProcessor = nullptr;                   
190   }                                               
191                                                   
192   G4ITTypeManager::Instance()->ReleaseRessourc    
193   ClearList();                                    
194   if (fpTrackingManager != nullptr) {             
195     delete fpTrackingManager;                     
196     fpTrackingManager = nullptr;                  
197   }                                               
198                                                   
199   if (fReactionSet != nullptr) {                  
200     delete fReactionSet;                          
201     fReactionSet = nullptr;                       
202   }                                               
203                                                   
204   if (fpModelHandler != nullptr) {                
205     delete fpModelHandler;                        
206     fpModelHandler = nullptr;                     
207   }                                               
208 }                                                 
209                                                   
210 //____________________________________________    
211                                                   
212 void G4Scheduler::ClearList()                     
213 {                                                 
214   fTrackContainer.Clear();                        
215   G4AllITFinder::DeleteInstance();                
216 }                                                 
217                                                   
218 //____________________________________________    
219 void G4Scheduler::RegisterModel(G4VITStepModel    
220 {                                                 
221   fpModelHandler->RegisterModel(model, time);     
222 }                                                 
223                                                   
224 //____________________________________________    
225                                                   
226 void G4Scheduler::Initialize()                    
227 {                                                 
228   delete fpStepProcessor;                         
229   delete fpModelProcessor;                        
230                                                   
231   fpModelProcessor = new G4ITModelProcessor();    
232   fpModelProcessor->SetModelHandler(fpModelHan    
233   fpModelProcessor->SetTrackingManager(fpTrack    
234   fpStepProcessor = new G4ITStepProcessor();      
235   fpStepProcessor->SetTrackingManager(fpTracki    
236   fpTrackingManager->SetInteractivity(fpTracki    
237   if (fUsePreDefinedTimeSteps) {                  
238     if (fpUserTimeSteps == nullptr)  // Extra     
239     {                                             
240       G4ExceptionDescription exceptionDescript    
241       exceptionDescription << "You are asking     
242       G4Exception("G4Scheduler::FindUserPreDef    
243                   exceptionDescription);          
244       return;  // makes coverity happy            
245     }                                             
246   }                                               
247                                                   
248   fInitialized = true;                            
249 }                                                 
250                                                   
251 //____________________________________________    
252                                                   
253 void G4Scheduler::Reset()                         
254 {                                                 
255   fStartTime = 0;                                 
256   fUserUpperTimeLimit = -1;                       
257   fTimeStep = DBL_MAX;                            
258   fTSTimeStep = DBL_MAX;                          
259   fILTimeStep = DBL_MAX;                          
260   fPreviousTimeStep = DBL_MAX;                    
261   fGlobalTime = -1;                               
262   fInteractionStep = true;                        
263   fITStepStatus = eUndefined;                     
264   fZeroTimeCount = 0;                             
265                                                   
266   fNbSteps = 0;                                   
267   fContinue = true;                               
268   fReactionSet->CleanAllReaction();               
269 }                                                 
270 //____________________________________________    
271                                                   
272 void G4Scheduler::Process()                       
273 {                                                 
274 #ifdef G4VERBOSE                                  
275   if (fVerbose != 0) {                            
276     G4cout << "*** G4Scheduler starts processi    
277     if (fVerbose > 2)                             
278       G4cout << "_____________________________    
279                 "___________________________"     
280              << G4endl;                           
281   }                                               
282 #endif                                            
283                                                   
284   if (!fInitialized) {                            
285     Initialize();                                 
286   }                                               
287   fpModelProcessor->Initialize();                 
288   fpStepProcessor->Initialize();                  
289                                                   
290   if (fpGun != nullptr) fpGun->DefineTracks();    
291                                                   
292   if (fpTrackingInteractivity != nullptr) fpTr    
293                                                   
294   // ___________________                          
295   fRunning = true;                                
296   Reset();                                        
297                                                   
298   if (fResetScavenger) {                          
299     if (fpUserScavenger != nullptr) {             
300       fpUserScavenger->Reset();                   
301     }                                             
302   }                                               
303                                                   
304   if (fpUserTimeStepAction != nullptr) {          
305     fpUserTimeStepAction->StartProcessing();      
306   }                                               
307                                                   
308 #ifdef G4VERBOSE                                  
309   G4bool trackFound = false;                      
310   G4IosFlagsSaver iosfs(G4cout);                  
311   G4cout.precision(5);                            
312 #endif                                            
313                                                   
314   //==========================================    
315   // By default, before the G4Scheduler is lau    
316   // the delayed lists                            
317   //==========================================    
318                                                   
319   if (fTrackContainer.DelayListsNOTEmpty()) {     
320     fStartTime = fTrackContainer.GetNextTime()    
321 #ifdef G4VERBOSE                                  
322     trackFound = true;                            
323     G4Timer localtimer;                           
324     if (fVerbose > 1) {                           
325       localtimer.Start();                         
326     }                                             
327 #endif                                            
328     SynchronizeTracks();                          
329 #ifdef G4VERBOSE                                  
330     if (fVerbose > 1) {                           
331       localtimer.Stop();                          
332       G4cout << "G4Scheduler: process time= "     
333     }                                             
334 #endif                                            
335   }                                               
336 #ifdef G4VERBOSE                                  
337   if (fVerbose != 0) {                            
338     if (trackFound) {                             
339       G4cout << "*** G4Scheduler ends at time     
340       G4cout << "_____________________________    
341     }                                             
342     else {                                        
343       G4cout << "*** G4Scheduler did not start    
344                 "track was found to be process    
345              << G4endl;                           
346       G4cout << "_____________________________    
347     }                                             
348   }                                               
349 #endif                                            
350                                                   
351   fRunning = false;                               
352                                                   
353   if (fpUserTimeStepAction != nullptr) {          
354     fpUserTimeStepAction->EndProcessing();        
355   }                                               
356   // ___________________                          
357   EndTracking();                                  
358   ClearList();                                    
359   Reset();                                        
360                                                   
361   if (fpTrackingInteractivity != nullptr) {       
362     fpTrackingInteractivity->Finalize();          
363   }                                               
364 }                                                 
365                                                   
366 //____________________________________________    
367                                                   
368 G4double G4Scheduler::GetNextWatchedTime() con    
369 {                                                 
370   auto up = fWatchedTimes.upper_bound(fGlobalT    
371   if (up == fWatchedTimes.end()) {                
372     return DBL_MAX;                               
373   }                                               
374   return *up;                                     
375 }                                                 
376                                                   
377 //____________________________________________    
378                                                   
379 void G4Scheduler::SynchronizeTracks()             
380 {                                                 
381   fGlobalTime = fTrackContainer.GetNextTime();    
382   G4double tmpGlobalTime = fGlobalTime;           
383   G4double nextWatchedTime = -1;                  
384   G4bool carryOn = true;                          
385   while (fTrackContainer.MergeNextTimeToMainLi    
386     if (tmpGlobalTime != fGlobalTime) {           
387       fGlobalTime = tmpGlobalTime;                
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   }                                               
404 }                                                 
405                                                   
406 //____________________________________________    
407                                                   
408 G4bool G4Scheduler::CanICarryOn()                 
409 {                                                 
410   return fGlobalTime < fEndTime && (fMaxSteps     
411 }                                                 
412                                                   
413 //____________________________________________    
414                                                   
415 void G4Scheduler::PrintWhyDoYouStop()             
416 {                                                 
417 #ifdef G4VERBOSE                                  
418   if (fWhyDoYouStop) {                            
419     G4cout << "G4Scheduler has reached a stage    
420               " a transition or the end"          
421            << G4endl;                             
422                                                   
423     G4bool normalStop = false;                    
424                                                   
425     if (fGlobalTime >= fStopTime) {               
426       G4cout << "== G4Scheduler: I stop becaus    
427              << G4BestUnit(fStopTime, "Time")     
428       normalStop = true;                          
429     }                                             
430     if (!fTrackContainer.MainListsNOTEmpty())     
431     {                                             
432       G4cout << "G4Scheduler: I stop because t    
433                 "is empty"                        
434              << G4endl;                           
435       normalStop = true;                          
436     }                                             
437     if (fMaxSteps == -1 ? false : fNbSteps >=     
438       G4cout << "G4Scheduler: I stop because I    
439                 "number of steps="                
440              << fMaxSteps << G4endl;              
441       normalStop = true;                          
442     }                                             
443     if (fContinue && !normalStop) {               
444       G4cout << "G4Scheduler: It might be that    
445                 "I have been told so. You may     
446                 "member fContinue and usage of    
447              << G4endl;                           
448     }                                             
449   }                                               
450 #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                                                   
481 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_ST    
482   mem_second = MemoryUsage();                     
483   mem_diff = mem_second - mem_first;              
484   G4cout << "\t || MEM || After stepping, diff    
485 #endif                                            
486                                                   
487 #ifdef G4VERBOSE                                  
488   if (fVerbose > 2)                               
489     G4cout << "*** G4Scheduler has finished pr    
490            << G4BestUnit(fGlobalTime, "Time")     
491 #endif                                            
492 }                                                 
493 //____________________________________________    
494                                                   
495 void G4Scheduler::Stepping()                      
496 {                                                 
497   fTimeStep = fMaxTimeStep;                       
498                                                   
499   fTSTimeStep = DBL_MAX;                          
500   fILTimeStep = DBL_MAX;                          
501                                                   
502   fInteractionStep = false;                       
503   fReachedUserTimeLimit = false;                  
504                                                   
505   fITStepStatus = eUndefined;                     
506                                                   
507   // Start of step                                
508 #ifdef G4VERBOSE                                  
509   if (fVerbose > 2) {                             
510 #  ifdef USE_COLOR                                
511     G4cout << LIGHT_RED;                          
512 #  endif                                          
513     G4cout << "*** Start Of Step N°" << fNbSt    
514            << " ***" << G4endl;                   
515     G4cout << "Current Global time : " << G4Be    
516 #  ifdef USE_COLOR                                
517     G4cout << RESET_COLOR;                        
518 #  endif                                          
519   }                                               
520 #endif                                            
521                                                   
522 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE    
523   MemStat mem_first, mem_second, mem_diff;        
524 #endif                                            
525                                                   
526 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE    
527   mem_first = MemoryUsage();                      
528 #endif                                            
529                                                   
530   fDefinedMinTimeStep = GetLimitingTimeStep();    
531                                                   
532   if (fUsePreDefinedTimeSteps) {                  
533 #ifdef G4VERBOSE                                  
534     if (fVerbose > 2) {                           
535 #  ifdef USE_COLOR                                
536       G4cout << LIGHT_RED;                        
537 #  endif                                          
538       G4cout << "*** At time : " << G4BestUnit    
539              << " the chosen user time step is    
540              << " ***" << G4endl;                 
541 #  ifdef USE_COLOR                                
542       G4cout << RESET_COLOR;                      
543 #  endif                                          
544     }                                             
545 #endif                                            
546   }                                               
547                                                   
548   if (fpModelProcessor->GetComputeTimeStep())     
549   {                                               
550     fTSTimeStep = fpModelProcessor->CalculateM    
551     // => at least N (N = nb of tracks) loops     
552   }                                               
553   else if (fUseDefaultTimeSteps) {                
554     fTSTimeStep = fDefinedMinTimeStep;            
555   }                                               
556                                                   
557 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE    
558   mem_second = MemoryUsage();                     
559   mem_diff = mem_second - mem_first;              
560   G4cout << "|| MEM || After computing TS, dif    
561 #endif                                            
562                                                   
563 #ifdef G4VERBOSE                                  
564   if (fVerbose > 2) {                             
565 #  ifdef USE_COLOR                                
566     G4cout << LIGHT_RED;                          
567 #  endif                                          
568     G4cout << "*** Time stepper returned : " <    
569 #  ifdef USE_COLOR                                
570     G4cout << RESET_COLOR;                        
571 #  endif                                          
572   }                                               
573 #endif                                            
574                                                   
575 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE    
576   mem_first = MemoryUsage();                      
577 #endif                                            
578                                                   
579   // Call IL even if fTSTimeStep == 0             
580   // if fILTimeStep == 0 give the priority to     
581                                                   
582   fILTimeStep = fpStepProcessor->ComputeIntera    
583   // => at least N loops                          
584   // All process returns the physical step of     
585   // The transportation process calculates the    
586   // time step                                    
587                                                   
588 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE    
589   mem_second = MemoryUsage();                     
590   mem_diff = mem_second - mem_first;              
591   G4cout << "|| MEM || After IL, diff is : " <    
592 #endif                                            
593                                                   
594 #ifdef G4VERBOSE                                  
595   if (fVerbose > 2) {                             
596 #  ifdef USE_COLOR                                
597     G4cout << LIGHT_RED;                          
598 #  endif                                          
599     G4cout << "*** The minimum time returned b    
600            << G4BestUnit(fILTimeStep, "Time")     
601 #  ifdef USE_COLOR                                
602     G4cout << RESET_COLOR;                        
603 #  endif                                          
604   }                                               
605 #endif                                            
606                                                   
607 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE    
608   mem_first = MemoryUsage();                      
609 #endif                                            
610                                                   
611   if (fILTimeStep <= fTSTimeStep)                 
612   // Give the priority to the IL                  
613   {                                               
614     fInteractionStep = true;                      
615     fReactionSet->CleanAllReaction();             
616     fTimeStep = fILTimeStep;                      
617     fITStepStatus = eInteractionWithMedium;       
618     fpStepProcessor->PrepareLeadingTracks();      
619   }                                               
620   else {                                          
621     fInteractionStep = false;                     
622     fpStepProcessor->ResetLeadingTracks();        
623     fTimeStep = fTSTimeStep;                      
624     fITStepStatus = eCollisionBetweenTracks;      
625   }                                               
626                                                   
627   if (fGlobalTime + fTimeStep > fStopTime)        
628   // This check is done at every time step        
629   {                                               
630     fTimeStep = fStopTime - fGlobalTime;          
631     fITStepStatus = eInteractionWithMedium;  /    
632     fInteractionStep = true;                      
633     fReactionSet->CleanAllReaction();             
634     fpStepProcessor->ResetLeadingTracks();        
635   }                                               
636                                                   
637   if (fTimeStep == 0)  // < fTimeTolerance)       
638   {                                               
639     ++fZeroTimeCount;                             
640     if (fZeroTimeCount >= fMaxNZeroTimeStepsAl    
641       G4ExceptionDescription exceptionDescript    
642                                                   
643       exceptionDescription << "Too many zero t    
644       exceptionDescription << "The simulation     
645       exceptionDescription << "The maximum num    
646                            << fMaxNZeroTimeSte    
647       exceptionDescription << ".";                
648                                                   
649       G4Exception("G4Scheduler::Stepping", "Sc    
650                   exceptionDescription);          
651     }                                             
652   }                                               
653   else {                                          
654     fZeroTimeCount = 0;                           
655   }                                               
656                                                   
657   fReachedUserTimeLimit = (fTimeStep <= fDefin    
658                           || ((fTimeStep > fDe    
659                               && fabs(fTimeSte    
660                                                   
661   if (fpUserTimeStepAction != nullptr) fpUserT    
662     // TODO: pre/post                             
663                                                   
664 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE    
665   mem_second = MemoryUsage();                     
666   mem_diff = mem_second - mem_first;              
667   G4cout << "|| MEM || After LeadingTracks and    
668 #endif                                            
669                                                   
670 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE    
671   mem_first = MemoryUsage();                      
672 #endif                                            
673                                                   
674   fGlobalTime += fTimeStep;                       
675                                                   
676   // if fTSTimeStep > 0 => still need to call     
677   // if fILTimeStep < fTSTimeStep => call only    
678   // if fILTimeStep == fTSTimeStep => give the    
679   if (fTSTimeStep > 0 || fILTimeStep <= fTSTim    
680     fpStepProcessor->DoIt(fTimeStep);             
681   }                                               
682 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE    
683   mem_second = MemoryUsage();                     
684   mem_diff = mem_second - mem_first;              
685   G4cout << "|| MEM || After DoIT, diff is : "    
686 #endif                                            
687                                                   
688 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE    
689   mem_first = MemoryUsage();                      
690 #endif                                            
691                                                   
692   fpModelProcessor->ComputeTrackReaction(fITSt    
693                                          fReac    
694                                          fpUse    
695                                                   
696   ++fNbSteps;                                     
697                                                   
698   if (fpUserTimeStepAction != nullptr) {          
699     fpUserTimeStepAction->UserPostTimeStepActi    
700   }                                               
701                                                   
702   fPreviousTimeStep = fTimeStep;                  
703                                                   
704 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE    
705   mem_second = MemoryUsage();                     
706   mem_diff = mem_second - mem_first;              
707   G4cout << "|| MEM || After computing reactio    
708             "diff is : "                          
709          << mem_diff << G4endl;                   
710 #endif                                            
711                                                   
712   // End of step                                  
713 #ifdef G4VERBOSE                                  
714   if (fVerbose >= 2) {                            
715 #  ifdef USE_COLOR                                
716     G4cout << LIGHT_RED;                          
717 #  endif                                          
718                                                   
719     G4String interactionType;                     
720     GetCollisionType(interactionType);            
721                                                   
722     std::stringstream finalOutput;                
723                                                   
724     finalOutput << "*** End of step N°" << fN    
725                 << "\t T_i= " << G4BestUnit(fG    
726                 << "\t dt= " << G4BestUnit(fTi    
727                 << "\t T_f= " << G4BestUnit(fG    
728                 << G4endl;                        
729                                                   
730     if (fVerbose > 2) {                           
731       if (fReachedUserTimeLimit) {                
732         finalOutput << "It has also reached th    
733       }                                           
734       finalOutput << "________________________    
735                      "_______"                    
736                   << G4endl;                      
737     }                                             
738                                                   
739     G4cout << finalOutput.str();                  
740                                                   
741 #  ifdef USE_COLOR                                
742     G4cout << RESET_COLOR;                        
743 #  endif                                          
744   }                                               
745 #endif                                            
746 }                                                 
747 //____________________________________________    
748                                                   
749 G4double G4Scheduler::GetLimitingTimeStep() co    
750 {                                                 
751   if (fpUserTimeSteps == nullptr) return fDefa    
752   if (fabs(fGlobalTime - fUserUpperTimeLimit)     
753                                                   
754   auto it_fpUserTimeSteps_i = fpUserTimeSteps-    
755   auto it_fpUserTimeSteps_low = fpUserTimeStep    
756                                                   
757   if (it_fpUserTimeSteps_i == fpUserTimeSteps-    
758     it_fpUserTimeSteps_i--;                       
759     fUserUpperTimeLimit = fStopTime;              
760   }                                               
761   else if (fabs(fGlobalTime - it_fpUserTimeSte    
762     it_fpUserTimeSteps_i = it_fpUserTimeSteps_    
763     auto tmp_it = it_fpUserTimeSteps_low;         
764     ++tmp_it;                                     
765     if (tmp_it == fpUserTimeSteps->end()) {       
766       fUserUpperTimeLimit = fStopTime;            
767     }                                             
768     else {                                        
769       fUserUpperTimeLimit = tmp_it->first;        
770     }                                             
771   }                                               
772   else if (it_fpUserTimeSteps_i == it_fpUserTi    
773     fUserUpperTimeLimit = it_fpUserTimeSteps_i    
774     if (it_fpUserTimeSteps_i != fpUserTimeStep    
775   }                                               
776   else {                                          
777     fUserUpperTimeLimit = it_fpUserTimeSteps_i    
778     it_fpUserTimeSteps_i = it_fpUserTimeSteps_    
779   }                                               
780   return it_fpUserTimeSteps_i->second;            
781 }                                                 
782                                                   
783 //____________________________________________    
784                                                   
785 void G4Scheduler::FindUserPreDefinedTimeStep()    
786 {                                                 
787   if (fpUserTimeSteps == nullptr) {               
788     G4ExceptionDescription exceptionDescriptio    
789     exceptionDescription << "You are asking to    
790     G4Exception("G4Scheduler::FindUserPreDefin    
791                 exceptionDescription);            
792     return;  // makes coverity happy              
793   }                                               
794   auto fpUserTimeSteps_i = fpUserTimeSteps->up    
795   auto fpUserTimeSteps_low = fpUserTimeSteps->    
796                                                   
797   if (fpUserTimeSteps_i == fpUserTimeSteps->en    
798     fpUserTimeSteps_i--;                          
799   }                                               
800   else if (fabs(fGlobalTime - fpUserTimeSteps_    
801     // Case : fGlobalTime = X picosecond          
802     // and fpUserTimeSteps_low->first = X pico    
803     // but the precision is not good enough       
804     fpUserTimeSteps_i = fpUserTimeSteps_low;      
805   }                                               
806   else if (fpUserTimeSteps_i == fpUserTimeStep    
807     // "Normal" cases                             
808     fpUserTimeSteps_i--;                          
809   }                                               
810   else {                                          
811     fpUserTimeSteps_i = fpUserTimeSteps_low;      
812   }                                               
813                                                   
814   fDefinedMinTimeStep = fpUserTimeSteps_i->sec    
815 }                                                 
816                                                   
817 //____________________________________________    
818                                                   
819 void G4Scheduler::EndTracking()                   
820 {                                                 
821   if (fRunning) {                                 
822     G4ExceptionDescription exceptionDescriptio    
823     exceptionDescription << "End tracking is c    
824                                                   
825     G4Exception("G4Scheduler::EndTracking", "S    
826                 exceptionDescription);            
827   }                                               
828                                                   
829   while (fTrackContainer.DelayListsNOTEmpty())    
830     auto nextTime = fTrackContainer.GetNextTim    
831     fTrackContainer.MergeNextTimeToMainList(ne    
832   }                                               
833                                                   
834   fTrackContainer.MergeSecondariesWithMainList    
835                                                   
836   if (fTrackContainer.MainListsNOTEmpty()) {      
837     G4TrackManyList* mainList = fTrackContaine    
838     G4TrackManyList::iterator it = mainList->b    
839     G4TrackManyList::iterator end = mainList->    
840     for (; it != end; ++it) {                     
841       fpTrackingManager->EndTrackingWOKill(*it    
842     }                                             
843   }                                               
844                                                   
845   if (fTrackContainer.SecondaryListsNOTEmpty()    
846   {                                               
847     G4TrackManyList* secondaries = fTrackConta    
848     G4TrackManyList::iterator it = secondaries    
849     G4TrackManyList::iterator end = secondarie    
850                                                   
851     for (; it != end; ++it) {                     
852       fpTrackingManager->EndTrackingWOKill(*it    
853     }                                             
854   }                                               
855 }                                                 
856                                                   
857 //____________________________________________    
858 void G4Scheduler::SetInteractivity(G4ITTrackin    
859 {                                                 
860   fpTrackingInteractivity = interactivity;        
861   if (fpTrackingManager != nullptr) {             
862     fpTrackingManager->SetInteractivity(fpTrac    
863   }                                               
864 }                                                 
865                                                   
866 //____________________________________________    
867 void G4Scheduler::ForceReinitialization()         
868 {                                                 
869   fInitialized = false;                           
870   Initialize();                                   
871 }                                                 
872                                                   
873 size_t G4Scheduler::GetNTracks()                  
874 {                                                 
875   return fTrackContainer.GetNTracks();            
876 }                                                 
877 //____________________________________________    
878                                                   
879 void G4Scheduler::GetCollisionType(G4String& i    
880 {                                                 
881   switch (fITStepStatus) {                        
882     case eInteractionWithMedium:                  
883       interactionType = "eInteractionWithMediu    
884       break;                                      
885     case eCollisionBetweenTracks:                 
886       interactionType = "eCollisionBetweenTrac    
887       break;                                      
888     default:                                      
889       interactionType = "eCollisionBetweenTrac    
890       break;                                      
891   }                                               
892 }                                                 
893