Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 // G4RunManager 27 // 28 // Class description: 29 // 30 // This is a class for run control in Geant4 31 // 32 // For the sequential mode of Geant4 application, user must provide his 33 // own classes derived from the following three abstract classes and register 34 // them to the RunManager: 35 // G4VUserDetectorConstruction - Detector Geometry, Materials 36 // G4VUserPhysicsList - Particle types and Processes 37 // G4VUserPrimaryGeneratorAction - Event Generator selection 38 // 39 // In addition to the above mandatory classes, user can easily customise 40 // the default functionality of a Geant4 simulation by deriving his own 41 // classes from the following 5 user-action classes: 42 // G4UserRunAction - Actions for each Run 43 // G4UserEventAction - Actions for each Event 44 // G4UserStackingAction - Tracks Stacking selection 45 // G4UserTrackingAction - Actions for each Track 46 // G4UserSteppingAction - Actions for each Step 47 // 48 // User may use G4VUserActionInitialization class to instantiate any of 49 // the six user action-classes (1 mandatory + 6 optional). 50 // In this case, user's concrete G4VUserActionInitialization should be 51 // defined to the RunManager. 52 // 53 // If in multi-threaed mode, a user must provide his own classes derived 54 // from the following two abstract classes and register them to the 55 // G4MTRunManager or G4TaskingRunManager: 56 // G4VUserDetectorConstruction - Detector Geometry, Materials 57 // G4VUserPhysicsList - Particle types and Processes 58 // In addition, user may optionally specify the following: 59 // G4UserWorkerInitialization - Defining thread-local actions 60 // G4UserRunAction - Actions for entire Run 61 // 62 // In multi-threaded mode, the use of G4VUserActionInitialization 63 // is mandatory. 64 // In G4VUserActionInitialization, the user has to specify 65 // G4VUserPrimaryGeneratorAction class. In addition, the default 66 // functionality of a Geant4 simulation can be customised by making 67 // user's classes derived from the following 5 user-action classes: 68 // G4VUserPrimaryGeneratorAction - Event Generator selection 69 // G4UserRunAction - Actions for each tread-local Run 70 // G4UserEventAction - Actions for each Event 71 // G4UserStackingAction - Tracks Stacking selection 72 // G4UserTrackingAction - Actions for each Track 73 // G4UserSteppingAction - Actions for each Step 74 // 75 // G4RunManager MUST be constructed (either explicitly or through 76 // G4RunManagerFactory) by the user in the main() for enabling sequential 77 // mode operation of a Geant4 application. 78 // 79 // In multi-threaded mode, G4MTRunManager is the dedicated run manager 80 // which the user MUST construct (either explicitly or through 81 // G4RunManagerFactory) in the main(). 82 // 83 // Note: G4WorkerRunManager is the run manager for an individual thread, 84 // and is instantiated automatically; the user does not need to take care 85 // of instantiating/deleting it. 86 // Also, the behavior of the run control can be customised by deriving 87 // a user class from G4RunManager. In this case, the user should directly 88 // use the provided protected methods in this class for procedures he/she 89 // does not want to change. 90 // 91 // G4RunManager (or a derived class of it) MUST act as a singleton. 92 // The user MUST NOT construct more than one such object even if there 93 // are two different concrete implementations, nor its state can be reset 94 // to zero, once the object has been created. 95 // 96 // G4RunManager controls all of state changes. See G4ApplicationState.hh 97 // in intercoms category for the meaning of each application state. 98 99 // Original author: M.Asai, 1996 100 // -------------------------------------------------------------------- 101 #ifndef G4RunManager_hh 102 #define G4RunManager_hh 1 103 104 #include "G4Event.hh" 105 #include "G4EventManager.hh" 106 #include "G4RunManagerKernel.hh" 107 #include "globals.hh" 108 109 #include "rundefs.hh" 110 111 #include <algorithm> 112 #include <list> 113 114 // userAction classes 115 class G4VUserDetectorConstruction; 116 class G4VUserPhysicsList; 117 class G4UserWorkerInitialization; 118 class G4UserWorkerThreadInitialization; 119 class G4VUserActionInitialization; 120 class G4UserRunAction; 121 class G4VUserPrimaryGeneratorAction; 122 class G4UserEventAction; 123 class G4UserStackingAction; 124 class G4UserTrackingAction; 125 class G4UserSteppingAction; 126 127 class G4VPhysicalVolume; 128 class G4LogicalVolume; 129 class G4Region; 130 class G4Timer; 131 class G4RunMessenger; 132 class G4DCtable; 133 class G4Run; 134 class G4PrimaryTransformer; 135 class G4RunManagerFactory; 136 137 class G4RunManager 138 { 139 friend class G4RunManagerFactory; 140 141 public: 142 // Static method which returns the singleton pointer of G4RunManager 143 // or its derived class. 144 // Note this returns the per-thread singleton in case of a 145 // multi-threaded build. 146 static G4RunManager* GetRunManager(); 147 148 // The constructor and the destructor. The user must construct 149 // this class object at the beginning of his/her main() and must 150 // delete it at the bottom of the main(). 151 G4RunManager(); 152 virtual ~G4RunManager(); 153 154 // Forbidden copy constructor and assignment operator. 155 G4RunManager(const G4RunManager&) = delete; 156 G4RunManager& operator=(const G4RunManager&) = delete; 157 158 // This method starts an event loop of "n_event" events. The condition of 159 // Geant4 is examined before starting the event loop. This method must be 160 // invoked at 'Idle' state. The state will be changed to 'GeomClosed' 161 // during the event loop and will go back to 'Idle' when the loop is over 162 // or aborted. 163 // In case a string "macroFile" which represents the name of a macro file 164 // is provided, the macro file will be executed AT THE END of each event 165 // processing. In case "n_select" is greater than zero, at the end of the 166 // first "n_select" events, the macro file is executed. 167 virtual void BeamOn(G4int n_event, const char* macroFile = nullptr, G4int n_select = -1); 168 169 // This method invokes all the necessary initialisation procedures for an 170 // event loop. This method must be invoked at the Geant4 'PreInit' state 171 // or 'Idle'. The state will be changed to 'Init' during initialization 172 // procedures and then changed to 'Idle'. 173 // This method invokes two protected methods, InitializeGeometry() and 174 // InitializePhysics(). 175 // After some event loops, the user can invoke this method once again. 176 // It is required if the user changes geometry, physics process, and/or 177 // cut-off value. If the user forget the second invocation, the BeamOn() 178 // method will invoke this method (Note that this feature is not valid 179 // for the first initialization). 180 virtual void Initialize(); 181 182 // This method must be invoked if the geometry setup has been changed 183 // between runs. The flag "topologyIsChanged" will specify if the geometry 184 // topology is different from the original one used in the previous run; 185 // if not, it must be set to false, so that the original optimisation and 186 // navigation history are preserved. This method is invoked also at 187 // initialisation. 188 virtual void DefineWorldVolume(G4VPhysicalVolume* worldVol, G4bool topologyIsChanged = true); 189 190 // This method safely aborts the current event loop even if an event is 191 // in progress. This method is available for 'GeomClosed' and 'EventProc' 192 // Geant4 states. The application state will be changed to 'Idle', so that 193 // another event loop can be processed. 194 // If the "softAbort" flag is true, the event loop is aborted after 195 // processing the current event, while the current event is aborted if the 196 // flag is set to false. 197 virtual void AbortRun(G4bool softAbort = false); 198 199 // This method aborts the currently processing event, remaining events 200 // in the current event loop will be processed. This method is available 201 // only for 'EventProc' application state. 202 virtual void AbortEvent(); 203 204 // These methods are invoked from the Initialize() method for the 205 // initializations of geometry and physics processes. The user's concrete 206 // G4VUserDetectorConstruction class will be accessed from the method 207 // InitializeGeometry() and the G4VUserPhysicsList class will be accessed 208 // from the method InitializePhysics(). 209 virtual void InitializeGeometry(); 210 virtual void InitializePhysics(); 211 212 // These four methods are invoked from the BeamOn() method and they're 213 // invoked in this order. 214 // ConfirmBeamOnCondition() method checks if all the necessary 215 // initialisations have been done already. If the condition is not 216 // satisfied, false is returned and the following three methods will be 217 // skipped. 218 // The RunInitialization() method initialises a run. e.g., a G4Run class 219 // object is constructed in this method. 220 // The DoEventLoop() method controls an event loop. Arguments are the same 221 // as for the BeamOn() method. 222 // Inside the event loop, the two following methods are invoked at the 223 // beginning and at the end of each event. 224 // The RunTermination() method terminates a run processing. e.g., a G4Run 225 // class object is deleted in this method. If the user adopts ODBMS and 226 // wants to store the G4Run object, he/she must override this method. 227 virtual G4bool ConfirmBeamOnCondition(); 228 virtual void RunInitialization(); 229 virtual void DoEventLoop(G4int n_event, const char* macroFile = nullptr, G4int n_select = -1); 230 virtual void RunTermination(); 231 232 // Granular virtual methods invoked from DoEventLoop(). 233 virtual void InitializeEventLoop(G4int n_event, const char* macroFile = nullptr, 234 G4int n_select = -1); 235 virtual void ProcessOneEvent(G4int i_event); 236 virtual void TerminateOneEvent(); 237 virtual void TerminateEventLoop(); 238 239 // These two methods are invoked from DoEventLoop() at the beginning and 240 // at the end of each event processing. 241 // GenerateEvent() constructs a G4Event class object and invoke the user's 242 // G4VUserPrimaryGeneratorAction concrete class. If the user is adopting 243 // an ODBMS system and event objects have been created and stored in the 244 // data-base, he/she must override this method. 245 // AnalyzeEvent() stores an event to a data-base if a concrete 246 // G4VPersistentManager class is defined. 247 virtual G4Event* GenerateEvent(G4int i_event); 248 virtual void AnalyzeEvent(G4Event* anEvent); 249 250 // Dummy methods to dispatch generic inheritance calls from G4RunManager 251 // base class. 252 virtual void SetNumberOfThreads(G4int) {} 253 virtual G4int GetNumberOfThreads() const { return 1; } 254 255 // Dump information of a region. 256 void DumpRegion(const G4String& rname) const; 257 258 // Dump information of a region. 259 // If the pointer is NULL, all regions are shown. 260 void DumpRegion(G4Region* region = nullptr) const; 261 262 // This method must be invoked (or equivalent UI command can be used) 263 // in case the user changes his/her detector geometry after Initialize() 264 // method has been invoked. Then, at the beginning of the next BeamOn(), 265 // all necessary geometry optimisations will be made. 266 // The parameter "prop" has to be true if this C++ method is directly 267 // invoked. 268 void GeometryHasBeenModified(G4bool prop = true); 269 270 // This method must be invoked (or equivalent UI command can be used) 271 // in case the user needs his/her detector construction has to be 272 // re-invoked. Geometry optimisations will be also done. 273 // If the first parameter "destroyFirst" is true, G4SolidStore, 274 // G4LogicalVolumeStore and G4PhysicalVolumeStore are cleaned up, and 275 // thus all solids, logical volumes and physical volumes previously 276 // defined are deleted. 277 // The second parameter "prop" has to be true if this C++ method is 278 // directly invoked. 279 void ReinitializeGeometry(G4bool destroyFirst = false, G4bool prop = true); 280 281 // This method must be invoked (or equivalent UI command can be used) 282 // in case the user changes his/her physics process(es), e.g. (in)activate 283 // some processes. Once this method is invoked, regardless of cuts are 284 // changed or not, BuildPhysicsTable() of a PhysicsList is invoked for 285 // refreshing all physics tables. 286 inline void PhysicsHasBeenModified() { kernel->PhysicsHasBeenModified(); } 287 288 inline void CutOffHasBeenModified() 289 { 290 G4cerr << "CutOffHasBeenModified becomes obsolete." << G4endl; 291 G4cerr << "It is safe to remove invoking this method." << G4endl; 292 } 293 294 // This method may be used if the orientation and/or size of a 295 // particular physical volume has been modified while the rest of the 296 // geometries in the world has not been changed. This avoids the 297 // full re-optimisation of the entire geometry tree which is forced 298 // if GeometryHasBeenModified() method is invoked. 299 void ReOptimizeMotherOf(G4VPhysicalVolume*); 300 301 // Same as above, but the mother logical volume is specified instead. 302 void ReOptimize(G4LogicalVolume*); 303 304 inline void SetGeometryToBeOptimized(G4bool vl) 305 { 306 if (geometryToBeOptimized != vl) { 307 geometryToBeOptimized = vl; 308 kernel->GeometryHasBeenModified(); 309 kernel->SetGeometryToBeOptimized(vl); 310 } 311 } 312 inline G4bool GetGeometryToBeOptimized() { return geometryToBeOptimized; } 313 314 void GeometryDirectlyUpdated(G4bool val = true) { geometryDirectlyUpdated = val; } 315 316 // This is used only by workers thread to reset RNG engines from files 317 // that are event specific. Not implemented for sequential since run seed 318 // defines event seeds. 319 static G4bool IfGeometryHasBeenDestroyed(); 320 321 virtual void ConstructScoringWorlds(); 322 323 virtual void rndmSaveThisRun(); 324 virtual void rndmSaveThisEvent(); 325 virtual void RestoreRandomNumberStatus(const G4String& fileN); 326 virtual void RestoreRndmEachEvent(G4bool) 327 { /* No effect in SEQ */ 328 } 329 330 // Set user-actions and user-initialization to the kernel. 331 // Store respective user initialization and action classes. 332 // In MT mode, actions are shared among all threads, and should be set 333 // in the master thread, while user-actions are thread-private and each ` 334 // thread has private instances. Master thread does not have user-actions 335 // except for the (optional) run-action. 336 // User should instantiate the user-actions in the action-initialization 337 // and use that class' setters to set user-actions and *not* directly 338 // the methods provided here. 339 // Multiple Run, Event, Tracking and Stepping actions are allowed, the 340 // multiple instances will be appended to the current configuration. 341 // Multiple Stacking and PrimaryGeneration are not allowed. 342 virtual void SetUserInitialization(G4VUserDetectorConstruction* userInit); 343 virtual void SetUserInitialization(G4VUserPhysicsList* userInit); 344 virtual void SetUserInitialization(G4VUserActionInitialization* userInit); 345 virtual void SetUserInitialization(G4UserWorkerInitialization* userInit); 346 virtual void SetUserInitialization(G4UserWorkerThreadInitialization* userInit); 347 virtual void SetUserAction(G4UserRunAction* userAction); 348 virtual void SetUserAction(G4VUserPrimaryGeneratorAction* userAction); 349 virtual void SetUserAction(G4UserEventAction* userAction); 350 virtual void SetUserAction(G4UserStackingAction* userAction); 351 virtual void SetUserAction(G4UserTrackingAction* userAction); 352 virtual void SetUserAction(G4UserSteppingAction* userAction); 353 354 // Methods returning respective user initialization and action classes. 355 inline const G4VUserDetectorConstruction* GetUserDetectorConstruction() const 356 { 357 return userDetector; 358 } 359 inline const G4VUserPhysicsList* GetUserPhysicsList() const { return physicsList; } 360 inline const G4VUserActionInitialization* GetUserActionInitialization() const 361 { 362 return userActionInitialization; 363 } 364 inline G4VUserActionInitialization* GetNonConstUserActionInitialization() const 365 { 366 return userActionInitialization; 367 } 368 inline const G4UserWorkerInitialization* GetUserWorkerInitialization() const 369 { 370 return userWorkerInitialization; 371 } 372 inline const G4UserWorkerThreadInitialization* GetUserWorkerThreadInitialization() const 373 { 374 return userWorkerThreadInitialization; 375 } 376 inline const G4UserRunAction* GetUserRunAction() const { return userRunAction; } 377 inline const G4VUserPrimaryGeneratorAction* GetUserPrimaryGeneratorAction() const 378 { 379 return userPrimaryGeneratorAction; 380 } 381 inline const G4UserEventAction* GetUserEventAction() const { return userEventAction; } 382 inline const G4UserStackingAction* GetUserStackingAction() const { return userStackingAction; } 383 inline const G4UserTrackingAction* GetUserTrackingAction() const { return userTrackingAction; } 384 inline const G4UserSteppingAction* GetUserSteppingAction() const { return userSteppingAction; } 385 386 // Set the number of additional (optional) waiting stacks. 387 // This method must be invoked at 'PreInit', 'Init' or 'Idle' states. 388 // Once the user sets the number of additional waiting stacks, 389 // he/she can use the corresponding ENUM in G4ClassificationOfNewTrack. 390 inline void SetNumberOfAdditionalWaitingStacks(G4int iAdd) 391 { 392 eventManager->GetStackManager()->SetNumberOfAdditionalWaitingStacks(iAdd); 393 } 394 395 // Define the default classification for a newly arriving track. 396 // Default can be alternated by the UserStackingAction. 397 // G4ExceptionSeverity can be set to warn the user if the classification is changed 398 // by the UserStackingAction. 399 inline void SetDefaultClassification(G4TrackStatus ts, 400 G4ClassificationOfNewTrack val, 401 G4ExceptionSeverity es = G4ExceptionSeverity::IgnoreTheIssue) 402 { eventManager->GetStackManager()->SetDefaultClassification(ts,val,es); } 403 inline void SetDefaultClassification(const G4ParticleDefinition* pd, 404 G4ClassificationOfNewTrack val, 405 G4ExceptionSeverity es = G4ExceptionSeverity::IgnoreTheIssue) 406 { eventManager->GetStackManager()->SetDefaultClassification(pd,val,es); } 407 408 409 inline const G4String& GetVersionString() const { return kernel->GetVersionString(); } 410 411 inline void SetPrimaryTransformer(G4PrimaryTransformer* pt) 412 { 413 kernel->SetPrimaryTransformer(pt); 414 } 415 416 // if vl = 1 : status before primary particle generation is stored 417 // if vl = 2 : status before event processing (after primary particle 418 // generation) is stored 419 // if vl = 3 : both are stored 420 // if vl = 0 : none is stored (default). 421 inline void StoreRandomNumberStatusToG4Event(G4int vl) 422 { 423 storeRandomNumberStatusToG4Event = vl; 424 eventManager->StoreRandomNumberStatusToG4Event(vl); 425 } 426 427 inline G4int GetFlagRandomNumberStatusToG4Event() const 428 { 429 return storeRandomNumberStatusToG4Event; 430 } 431 432 inline void SetRandomNumberStore(G4bool flag) { storeRandomNumberStatus = flag; } 433 inline G4bool GetRandomNumberStore() const { return storeRandomNumberStatus; } 434 inline void SetRandomNumberStoreDir(const G4String& dir) 435 { 436 G4String dirStr = dir; 437 if (dirStr.back() != '/') dirStr += "/"; 438 #ifndef WIN32 439 G4String shellCmd = "mkdir -p "; 440 #else 441 std::replace(dirStr.begin(), dirStr.end(), '/', '\\'); 442 G4String shellCmd = "if not exist " + dirStr + " mkdir "; 443 #endif 444 shellCmd += dirStr; 445 randomNumberStatusDir = std::move(dirStr); 446 G4int sysret = system(shellCmd); 447 if (sysret != 0) { 448 G4String errmsg = "\"" + shellCmd + "\" returns non-zero value. Directory creation failed."; 449 G4Exception("GrRunManager::SetRandomNumberStoreDir", "Run0071", JustWarning, errmsg); 450 G4cerr << " return value = " << sysret << G4endl; 451 } 452 } 453 inline const G4String& GetRandomNumberStoreDir() const { return randomNumberStatusDir; } 454 inline const G4String& GetRandomNumberStatusForThisRun() const 455 { 456 return randomNumberStatusForThisRun; 457 } 458 inline const G4String& GetRandomNumberStatusForThisEvent() const 459 { 460 if (storeRandomNumberStatusToG4Event == 0 || storeRandomNumberStatusToG4Event == 2) { 461 G4Exception("GrRunManager::SetRandomNumberStoreDir", "Run0072", JustWarning, 462 "Random number status is not available for this event."); 463 } 464 return randomNumberStatusForThisEvent; 465 } 466 inline void SetRandomNumberStorePerEvent(G4bool flag) { rngStatusEventsFlag = flag; } 467 inline G4bool GetRandomNumberStorePerEvent() const { return rngStatusEventsFlag; } 468 469 inline void SetVerboseLevel(G4int vl) 470 { 471 verboseLevel = vl; 472 kernel->SetVerboseLevel(vl); 473 } 474 inline G4int GetVerboseLevel() const { return verboseLevel; } 475 inline G4int GetPrintProgress() { return printModulo; } 476 inline void SetPrintProgress(G4int i) { printModulo = i; } 477 478 // Sets the number of events to be kept after processing. That is, 479 // "val" previous events can be used with the most recent event for 480 // digitizing pileup. "val"+1 previous event is deleted. 481 // This method must be invoked before starting the event loop. 482 inline void SetNumberOfEventsToBeStored(G4int val) { n_perviousEventsToBeStored = val; } 483 484 // Returns the pointer to the current run. This method is available for 485 // 'GeomClosed' and 'EventProc' application states. 486 inline const G4Run* GetCurrentRun() const { return currentRun; } 487 inline G4Run* GetNonConstCurrentRun() const { return currentRun; } 488 489 // Returns the pointer to the current event. This method is available for 490 // 'EventProc' application state. 491 inline const G4Event* GetCurrentEvent() const { return currentEvent; } 492 493 // Returns the pointer to the "i" previous event. This method is available 494 // for 'EventProc' application state. In case the event loop has not yet 495 // reached the requested event, null will be returned. To use this method, 496 // SetNumberOfEventsToBeStored() method mentioned above must be invoked 497 // previously to the event loop. 498 inline const G4Event* GetPreviousEvent(G4int i) const 499 { 500 if (i >= 1 && i <= n_perviousEventsToBeStored) { 501 auto itr = previousEvents->cbegin(); 502 for (G4int j = 1; j < i; ++j) { 503 ++itr; 504 } 505 return *itr; 506 } 507 return nullptr; 508 } 509 510 // Set the run number counter. Initially, the counter is initialized 511 // to zero and incremented by one for every BeamOn(). 512 inline void SetRunIDCounter(G4int i) { runIDCounter = i; } 513 514 inline G4int GetNumberOfParallelWorld() const { return nParallelWorlds; } 515 inline void SetNumberOfEventsToBeProcessed(G4int val) { numberOfEventToBeProcessed = val; } 516 inline G4int GetNumberOfEventsToBeProcessed() const { return numberOfEventToBeProcessed; } 517 inline G4int GetNumberOfSelectEvents() const { return n_select_msg; } 518 inline const G4String& GetSelectMacro() const { return selectMacro; } 519 inline void SetDCtable(G4DCtable* DCtbl) { DCtable = DCtbl; } 520 521 enum RMType 522 { 523 sequentialRM, 524 masterRM, 525 workerRM, 526 subEventMasterRM, 527 subEventWorkerRM 528 }; 529 530 inline RMType GetRunManagerType() const { return runManagerType; } 531 532 // Following methods are used only for sub-event parallel mode. 533 // Actual explanations of these methods are found in G4SubEvtRunManager class 534 virtual void RegisterSubEventType(G4int, G4int) 535 { 536 G4Exception("G4RunManager::RegisterSubEventType","RunSE1000",FatalException, 537 "Base class method is invoked for a RunManager that is not sub-event parallel mode"); 538 } 539 virtual void MergeTrajectories(const G4SubEvent*,const G4Event*) 540 { 541 G4Exception("G4RunManager::MergeTrajectories","RunSE1001",FatalException, 542 "Base class method is invoked for a RunManager that is not sub-event parallel mode"); 543 } 544 virtual void UpdateScoringForSubEvent(const G4SubEvent*,const G4Event*) 545 { 546 G4Exception("G4RunManager::UpdateScoringForSubEvent","RunSE1001",FatalException, 547 "Base class method is invoked for a RunManager that is not sub-event parallel mode"); 548 } 549 virtual const G4SubEvent* GetSubEvent(G4int, G4bool&, 550 G4long&, G4long&, G4long&, G4bool) 551 { 552 G4Exception("G4RunManager::GetSubEvent","RunSE1002",FatalException, 553 "Base class method is invoked for a RunManager that is not sub-event parallel mode"); 554 return nullptr; 555 } 556 virtual void SubEventFinished(const G4SubEvent*,const G4Event*) 557 { 558 G4Exception("G4RunManager::SubEventFinished","RunSE1003",FatalException, 559 "Base class method is invoked for a RunManager that is not sub-event parallel mode"); 560 } 561 virtual G4int GetSubEventType() const 562 { 563 G4Exception("G4RunManager::GetSubEventType","RunSE1010",FatalException, 564 "Base class method is invoked for RunManager that is not a worker in sub-event parallel mode"); 565 return -1; 566 } 567 virtual void SetSubEventType(G4int) 568 { 569 G4Exception("G4RunManager::SetSubEventType","RunSE1011",FatalException, 570 "Base class method is invoked for RunManager that is not a worker in sub-event parallel mode"); 571 } 572 virtual std::size_t GetMaxNTrack() const 573 { return 0; } 574 virtual void TrajectoriesToBeMerged(G4bool) 575 { 576 G4Exception("G4RunManager::TrajectoriesToBeMerged","RunSE1001",FatalException, 577 "Base class method is invoked for a RunManager that is not sub-event parallel mode"); 578 } 579 580 virtual void ReportEventDeletion(const G4Event* evt); 581 582 // Forcing geometry voxelization at the time of constructing geometry during 583 // the initialization. If this is not set, voxelization is done when BeamOn 584 // starts. 585 inline void ResetNavigatorAtInitialization(G4bool val=true) 586 { if(kernel!=nullptr) kernel->ResetNavigatorAtInitialization(val); } 587 588 protected: 589 // This constructor is called in case of multi-threaded build. 590 G4RunManager(RMType rmType); 591 592 // This method is invoked at the end of processing each event 593 virtual void StackPreviousEvent(G4Event* anEvent); 594 595 // This method is invoked at the beginning of next run or when the 596 // program is quiting. So, we delete all the kept G4Event objects. 597 virtual void CleanUpPreviousEvents(); 598 599 // This method is invoked at the end of processing each event 600 // to delete any G4Event objects that are no longer needed. 601 virtual void CleanUpUnnecessaryEvents(G4int keepNEvents); 602 603 virtual void StoreRNGStatus(const G4String& filenamePrefix); 604 605 void UpdateScoring(const G4Event* evt = nullptr); 606 607 // Called by destructor to delete user detector. Note: the user detector 608 // is shared among threads, thus this should be re-implemented in derived 609 // classes that implement the worker model. 610 virtual void DeleteUserInitializations(); 611 612 protected: 613 G4RunManagerKernel* kernel = nullptr; 614 G4EventManager* eventManager = nullptr; 615 616 G4VUserDetectorConstruction* userDetector = nullptr; 617 G4VUserPhysicsList* physicsList = nullptr; 618 G4VUserActionInitialization* userActionInitialization = nullptr; 619 G4UserWorkerInitialization* userWorkerInitialization = nullptr; 620 G4UserWorkerThreadInitialization* userWorkerThreadInitialization = nullptr; 621 G4UserRunAction* userRunAction = nullptr; 622 G4VUserPrimaryGeneratorAction* userPrimaryGeneratorAction = nullptr; 623 G4UserEventAction* userEventAction = nullptr; 624 G4UserStackingAction* userStackingAction = nullptr; 625 G4UserTrackingAction* userTrackingAction = nullptr; 626 G4UserSteppingAction* userSteppingAction = nullptr; 627 628 G4bool geometryInitialized = false; 629 G4bool physicsInitialized = false; 630 G4bool runAborted = false; 631 G4bool initializedAtLeastOnce = false; 632 G4bool geometryToBeOptimized = true; 633 634 G4int runIDCounter = 0; 635 G4int verboseLevel = 0; 636 G4int printModulo = -1; 637 G4Timer* timer = nullptr; 638 G4DCtable* DCtable = nullptr; 639 640 G4Run* currentRun = nullptr; 641 G4Event* currentEvent = nullptr; 642 std::list<G4Event*>* previousEvents = nullptr; 643 G4int n_perviousEventsToBeStored = 0; 644 G4int numberOfEventToBeProcessed = 0; 645 646 G4bool storeRandomNumberStatus = false; 647 G4int storeRandomNumberStatusToG4Event = 0; 648 G4String randomNumberStatusDir = "./"; 649 G4String randomNumberStatusForThisRun = ""; 650 G4String randomNumberStatusForThisEvent = ""; 651 G4bool rngStatusEventsFlag = false; 652 653 G4VPhysicalVolume* currentWorld = nullptr; 654 655 G4int nParallelWorlds = 0; 656 657 G4String msgText = " "; 658 G4int n_select_msg = -1; 659 G4int numberOfEventProcessed = 0; 660 G4String selectMacro = ""; 661 G4bool fakeRun = false; 662 G4bool isScoreNtupleWriter = false; 663 664 G4bool geometryDirectlyUpdated = false; 665 666 RMType runManagerType; 667 668 // This Boolean flag has to be shared by all derived objects. 669 G4RUN_DLL static G4bool fGeometryHasBeenDestroyed; 670 671 private: 672 // Per-thread static instance of the run manager singleton. 673 static G4ThreadLocal G4RunManager* fRunManager; 674 675 G4RunMessenger* runMessenger = nullptr; 676 677 }; 678 679 #endif 680