Belle II Software development
RunManager Class Reference

The run manager controls the flow of the Geant4 program and manages the event loop(s) within a run. More...

#include <RunManager.h>

Inheritance diagram for RunManager:

Classes

class  SingletonDestroyer
 Destroyer class to delete the instance of the RunManager class when the program terminates. More...
 

Public Member Functions

void beginRun (int runNumber)
 Prepares Geant4 for a new run.
 
void processEvent (int evtNumber)
 Process a single event in Geant4.
 
void endRun ()
 Terminates a Geant4 run.
 
void destroy ()
 Destroys the RunManager at the end of the simulation.
 
void Initialize ()
 Initialize the Kernel.
 
void addAssemblyVolume (G4AssemblyVolume *vol)
 Register a G4AssemblyVolume.
 

Static Public Member Functions

static RunManagerInstance ()
 Static method to get a reference to the RunManager instance.
 

Private Member Functions

 RunManager ()
 The constructor is hidden to avoid that someone creates an instance of this class.
 
 RunManager (const RunManager &)
 Disable/Hide the copy constructor.
 
RunManageroperator= (const RunManager &)
 Disable/Hide the copy assignment operator.
 
virtual ~RunManager ()
 The RunManager destructor.
 

Private Attributes

std::vector< G4AssemblyVolume * > m_AssemblyVolumes
 Vector of pointers to G4AssemblyVolumes.
 
RandomEnginem_randomEngine
 Pointer to RandomEngine to avoid memory leak by creating it in the constructor and deleting it in the destructor.
 

Static Private Attributes

static RunManagerm_instance = NULL
 Pointer that saves the instance of this class.
 

Friends

class SingletonDestroyer
 

Detailed Description

The run manager controls the flow of the Geant4 program and manages the event loop(s) within a run.

The run manager is also responsible for managing initialization procedures, including methods in the user initialization classes. By definition of Geant4, this class has to be a singleton.

Definition at line 32 of file RunManager.h.

Constructor & Destructor Documentation

◆ RunManager()

RunManager ( )
private

The constructor is hidden to avoid that someone creates an instance of this class.

Definition at line 125 of file RunManager.cc.

125 : G4RunManager()
126{
127 m_AssemblyVolumes.clear();
128}
std::vector< G4AssemblyVolume * > m_AssemblyVolumes
Vector of pointers to G4AssemblyVolumes.
Definition: RunManager.h:87

◆ ~RunManager()

~RunManager ( )
privatevirtual

The RunManager destructor.

Definition at line 131 of file RunManager.cc.

132{
133}

Member Function Documentation

◆ addAssemblyVolume()

void addAssemblyVolume ( G4AssemblyVolume *  vol)
inline

Register a G4AssemblyVolume.

Definition at line 68 of file RunManager.h.

68{ m_AssemblyVolumes.push_back(vol); }

◆ beginRun()

void beginRun ( int  runNumber)

Prepares Geant4 for a new run.

Parameters
runNumberThe current number of the run.

Definition at line 49 of file RunManager.cc.

50{
51 //Initialize Geometry FIXME: done run independent at the moment
52 //InitializeGeometry();
53 //Check if all the necessary initializations have already be done.
54 if (ConfirmBeamOnCondition()) {
55 //Set run number
56 SetRunIDCounter(runNumber);
57
58 //Finish initialization
59 ConstructScoringWorlds();
60 RunInitialization();
61 } else {
62 B2FATAL("The Geant4 kernel was not initialized properly ! The method 'ConfirmBeamOnCondition()' failed. ");
63 }
64}

◆ destroy()

void destroy ( )

Destroys the RunManager at the end of the simulation.

Required by Geant4.

Definition at line 85 of file RunManager.cc.

86{
87 delete m_randomEngine;
88
89 if (m_instance == nullptr) return;
90
91 for (G4AssemblyVolume* assemblyVolume : m_AssemblyVolumes) delete assemblyVolume;
92 m_AssemblyVolumes.clear();
93
95 //Attention, ugly:
96 //Deleting the runmanager will cause Geant4 to open the geometry and clean up
97 //optimizations. This will modify the geometry and hurt parallel processing
98 //memory usage so we do not want to do this, the operating system
99 //will free the memory anyway.
100 //So what we do if we are in one of the child processes is to empty the
101 //list of pointers in the G4LogicalVolumeStore. This means Geant4 will
102 //not find the volumes and will not delete the optimizations. We also clear
103 //all the other stores which contain geometry information just to be sure
104 G4LogicalVolumeStore::GetInstance()->clear();
105 G4PhysicalVolumeStore::GetInstance()->clear();
106 G4SolidStore::GetInstance()->clear();
107 G4RegionStore::GetInstance()->clear();
108 //And we have to open the geometry to avoid warnings from the Stores which
109 //is now a trivial operation
110 G4GeometryManager::GetInstance()->OpenGeometry();
111 } else {
112 //If we are the framework process (a.k.a the parent or only process) we do
113 //the full cleanup. We could live with the same approach as for child
114 //processes but then valgrind will probably show huge memory leaks
115 delete m_instance;
116 }
117 m_instance = nullptr;
118}
static bool isOutputProcess()
Return true if the process is an output process.
Definition: ProcHandler.cc:232
static bool parallelProcessingUsed()
Returns true if multiple processes have been spawned, false in single-core mode.
Definition: ProcHandler.cc:226
RandomEngine * m_randomEngine
Pointer to RandomEngine to avoid memory leak by creating it in the constructor and deleting it in the...
Definition: RunManager.h:90
static RunManager * m_instance
Pointer that saves the instance of this class.
Definition: RunManager.h:84

◆ endRun()

void endRun ( )

Terminates a Geant4 run.

Definition at line 79 of file RunManager.cc.

80{
81 RunTermination();
82}

◆ Initialize()

void Initialize ( )

Initialize the Kernel.

Definition at line 35 of file RunManager.cc.

36{
38 //Set the random number engine
39 CLHEP::HepRandom::setTheEngine(m_randomEngine);
40
41 SetGeometryToBeOptimized(true);
42 //Set geometry to be Initialized because there won't be any before the beginRun
43 //FIXME: reverted to run independent
44 //geometryInitialized = true;
45 G4RunManager::Initialize();
46}
Interface class to make Geant4 use the Belle2 RandomGenerator.
Definition: RandomEngine.h:22

◆ Instance()

RunManager & Instance ( )
static

Static method to get a reference to the RunManager instance.

Returns
A reference to an instance of this class.

Definition at line 29 of file RunManager.cc.

30{
31 if (!m_instance) m_instance = new RunManager();
32 return *m_instance;
33}
RunManager()
The constructor is hidden to avoid that someone creates an instance of this class.
Definition: RunManager.cc:125

◆ processEvent()

void processEvent ( int  evtNumber)

Process a single event in Geant4.

Parameters
evtNumberThe current number of the event.

Definition at line 67 of file RunManager.cc.

68{
69 //Geant4 simulation
70 currentEvent = GenerateEvent(evtNumber);
71 eventManager->ProcessOneEvent(currentEvent);
72 AnalyzeEvent(currentEvent);
73 UpdateScoring();
74 StackPreviousEvent(currentEvent);
75 currentEvent = NULL;
76}

Friends And Related Function Documentation

◆ SingletonDestroyer

friend class SingletonDestroyer
friend

Definition at line 103 of file RunManager.h.

Member Data Documentation

◆ m_AssemblyVolumes

std::vector<G4AssemblyVolume*> m_AssemblyVolumes
private

Vector of pointers to G4AssemblyVolumes.

Definition at line 87 of file RunManager.h.

◆ m_instance

RunManager * m_instance = NULL
staticprivate

Pointer that saves the instance of this class.

Definition at line 84 of file RunManager.h.

◆ m_randomEngine

RandomEngine* m_randomEngine
private

Pointer to RandomEngine to avoid memory leak by creating it in the constructor and deleting it in the destructor.

Definition at line 90 of file RunManager.h.


The documentation for this class was generated from the following files: