LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ArtG4RunManager.hh
Go to the documentation of this file.
1 #ifndef artg4tk_geantInit_ArtG4RunManager_hh
2 #define artg4tk_geantInit_ArtG4RunManager_hh
3 //
4 // Override the G4RunManager class so that the ArtG4 framework can drive
5 // the event loop.
6 //
7 // Original author Rob Kutschke (Mu2e)
8 //
9 // In G4RunManager, the event loop is entered when the user calls BeamOn().
10 // This does some initialization, calls DoEventLoop() and does some termination.
11 //
12 // This class inherits from G4RunManager and replaces the BeamOn method
13 // by breaking it into four pieces, BeamOnBeginRun(), BeamOnOneEvent(), BeamOnEndEvent()
14 // and BeamOnEndRun(). The first piece is called from the beginRun() method
15 // of this module; the second and third pieces are called from the process() method of
16 // this module; and the last piece is called rom the endRun() method of this
17 // module.
18 //
19 // The user initialization of G4 must be complete before calling BeamOnBeginRun().
20 //
21 // Notes:
22 // 1) G4RunManager is an oddly implemented singleton. Those who access methods
23 // via the instance pointer in the base will never want to access any of the
24 // methods in this class. So we do not need an instance pointer to this class.
25 //
26 // 2) ArtG4 does not plan to change G4Run numbers within a single framework job.
27 //
28 // 3) The original G4RunManager had a local variable _i_event
29 
30 // Included from Geant4
31 //#include "Geant4/G4RunManager.hh"
32 #include "G4RunManager.hh"
33 
34 namespace artg4tk {
35 
36  class ArtG4RunManager : public G4RunManager {
37 
38  public:
40  virtual ~ArtG4RunManager();
41 
42  // The four methods that break up BeamOn into 4 pieces.
43  virtual void BeamOnBeginRun(unsigned int runNumber,
44  const char* macroFile = 0,
45  G4int n_select = -1);
46  virtual void BeamOnDoOneEvent(int eventNumber);
47  virtual void BeamOnEndEvent();
48  virtual void BeamOnEndRun();
49 
50  // ArtG4 specific accessors.
51  G4Event const*
53  {
54  return currentEvent;
55  }
56  G4Timer const*
57  getG4Timer() const
58  {
59  return timer;
60  }
61 
62  G4double
64  {
65  return realElapsed_;
66  }
67  G4double
69  {
70  return systemElapsed_;
71  }
72  G4double
74  {
75  return userElapsed_;
76  }
77 
78  private:
79  // Private and unimplemented to prevent copying.
82 
83  // A test to see if this works.
84  G4Event* previousEvent_;
85 
86  // The variables below correspond to local variables in G4RunManager::BeamOn.
87  // or G4RunManager::DoEventLoop. They need to be member data here because
88  // the BeaonOn method of the base is spread across three methods in this class.
89  // These variables are reset at the start of a run and remain valid until the
90  // end of the run; this emulates the behaviour in the base.
91 
92  // Name of the macro file to be run after the first n_select events.
93  char const* macroFile_;
94 
95  // Number of events after which to run the macro file. If negative
96  // then never run the macro.
97  G4int n_select_;
98 
99  // The number of events completed so far.
100  // This was called i_event in G4RunManager but I did not like the name.
101  G4int nProcessed_;
102 
103  // Counters for cumulative time spent processing events.
104  G4double realElapsed_;
105  G4double systemElapsed_;
106  G4double userElapsed_;
107 
108  // The command that executes the macro file.
110  };
111 
112 } // end namespace artg4tk.
113 
114 #endif /* artg4tk_geantInit_ArtG4RunManager_hh */
virtual void BeamOnDoOneEvent(int eventNumber)
G4Timer const * getG4Timer() const
virtual void BeamOnBeginRun(unsigned int runNumber, const char *macroFile=0, G4int n_select=-1)
G4double userElapsedTime() const
G4Event const * getCurrentEvent() const
ArtG4RunManager & operator=(ArtG4RunManager const &)
G4double systemElapsedTime() const
G4double realElapsedTime() const