SToGS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
SToGS_UserActionInitialization.hh
Go to the documentation of this file.
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 
27 #ifndef SToGS_UserActionInitialization_h
28 #define SToGS_UserActionInitialization_h 1
29 
30 #include "G4Version.hh"
31 #include "G4ios.hh"
32 #include "G4String.hh"
33 #include "G4UserRunAction.hh"
34 #include "G4UserEventAction.hh"
35 #include "G4UserTrackingAction.hh"
36 #include "G4UserSteppingAction.hh"
37 
38 #if G4VERSION_NUMBER < 1000
39 #else
40 #include "G4VUserActionInitialization.hh"
41 #endif
42 
43 #include <vector>
44 #include <utility>
45 
46 class G4VSensitiveDetector;
47 class G4VUserPrimaryGeneratorAction;
48 
49 
51 namespace SToGS {
53 
61  class AllActions : virtual public G4UserRunAction, virtual public G4UserEventAction, virtual public G4UserTrackingAction, virtual public G4UserSteppingAction
62  {
63  protected:
64  G4String fOption;
65 
66  public:
67  AllActions(G4String opt): G4UserRunAction(), G4UserEventAction(), G4UserTrackingAction(), G4UserSteppingAction(), fOption(opt)
68  {;}
69  virtual ~AllActions()
70  {;}
71 
72  virtual G4Run* GenerateRun()
73  {
74  return 0x0;
75  }
76  virtual void BeginOfRunAction(const G4Run * /*therun*/)
77  {
78  ;
79  }
80  virtual void EndOfRunAction(const G4Run * /*therun*/)
81  {
82  ;
83  }
84  virtual void BeginOfEventAction(const G4Event * /*event*/)
85  {
86  ;
87  }
88  virtual void EndOfEventAction(const G4Event * /*event*/)
89  {
90  ;
91  }
92  virtual void PreUserTrackingAction(const G4Track * /*atrack*/)
93  {
94  ;
95  }
96  virtual void PostUserTrackingAction(const G4Track * /*atrack*/)
97  {
98  ;
99  }
100  virtual void UserSteppingAction(const G4Step * /*step*/)
101  {
102  ;
103  }
104  };
106 
108  class RunAction : public G4UserRunAction
109  {
110  private:
111  G4UserRunAction *theRealAction;
112  public:
113  RunAction(G4UserRunAction *theaction = 0x0) : G4UserRunAction(), theRealAction(theaction)
114  {;}
115  virtual ~RunAction()
116  {;}
117 
118  public:
119  virtual G4Run* GenerateRun()
120  {
121  if (theRealAction)
122  return theRealAction->GenerateRun();
123  return G4UserRunAction::GenerateRun();
124  }
125  virtual void BeginOfRunAction(const G4Run *aRun)
126  {
127  if (theRealAction)
128  theRealAction->BeginOfRunAction(aRun);
129  }
130  virtual void EndOfRunAction(const G4Run* aRun)
131  {
132  if (theRealAction)
133  theRealAction->EndOfRunAction(aRun);
134  }
135 
136  };
138 
140  class EventAction : public G4UserEventAction
141  {
142  private:
143  G4UserEventAction *theRealAction;
144  public:
145  EventAction(G4UserEventAction *theaction = 0x0) : G4UserEventAction(), theRealAction(theaction)
146  {;}
147  virtual ~EventAction()
148  {;}
149  public:
150  virtual void BeginOfEventAction(const G4Event *event)
151  {
152  if (theRealAction)
153  theRealAction->BeginOfEventAction(event);
154  }
155  virtual void EndOfEventAction(const G4Event *event)
156  {
157  if (theRealAction)
158  theRealAction->EndOfEventAction(event);
159  }
160  };
162 
164  class TrackingAction : public G4UserTrackingAction
165  {
166  private:
167  G4UserTrackingAction *theRealAction;
168  public:
169  TrackingAction(G4UserTrackingAction *theaction = 0x0) : G4UserTrackingAction(), theRealAction(theaction)
170  {;}
171  virtual ~TrackingAction()
172  {;}
173  public:
174  virtual void PreUserTrackingAction(const G4Track* atrack);
175  virtual void PostUserTrackingAction(const G4Track *atrack);
176  };
178 
180  class SteppingAction : public G4UserSteppingAction
181  {
182  private:
183  G4UserSteppingAction *theRealAction;
184  public:
185  SteppingAction(G4UserSteppingAction *theaction = 0x0) : G4UserSteppingAction(), theRealAction(theaction)
186  {;}
187  virtual ~SteppingAction()
188  {;}
189  public:
190  virtual void UserSteppingAction(const G4Step *step)
191  {
192  if (theRealAction)
193  theRealAction->UserSteppingAction(step);
194  }
195  };
196 
198 
207 #if G4VERSION_NUMBER < 1000
209 #else
210  class UserActionInitialization : public G4VUserActionInitialization
211 #endif
212  {
213  protected:
215  mutable std::vector < AllActions *> fAllUserAction;
216 
217  protected:
220 
221  protected:
223  std::pair < G4String, G4String > fWhichGenerator;
224 
225  protected:
227  virtual G4VUserPrimaryGeneratorAction *GetGun(G4String which, G4String opt) const;
229 
232  void BuildAndRegister ( AllActions* ) const;
233  void Register ( AllActions* ) const;
234 
235  public:
236  UserActionInitialization(G4String which_user_action_opt, G4String which_gene, G4String which_gene_opt);
237  virtual ~UserActionInitialization();
238 
240 
242  std::pair < G4String, G4String > SetWhichGenerator(G4String which_gene, G4String option);
243 
245  static G4VSensitiveDetector *GetTrackerSD( G4String name = "/SToGS/SD/Tracker" );
247  static G4VSensitiveDetector *GetCopClusterSD( G4String name = "/SToGS/SD/CopCluster" );
248 
249 // INTERFACE provided for Geant4 < 10.0
250  public:
252 
255  virtual G4VUserPrimaryGeneratorAction *GetGun() const;
257 
259  virtual G4UserRunAction *GetRunAction() const = 0;
260  virtual G4UserEventAction *GetEventAction() const = 0;
261  virtual G4UserTrackingAction *GetTrackingAction() const = 0;
262  virtual G4UserSteppingAction *GetSteppingAction() const = 0;
263 
264 // INTERFACE in principle required for Geant4 > 10.0
266  virtual void BuildForMaster () const
267  {
268  G4cout << " ------ INF ------ from SToGS::AllInOneUserActionInitialization::BuildForMaster() " << G4endl;
269 #if G4VERSION_NUMBER < 1000
270  G4cout << " *** ERROR *** SToGS::AllInOneUserActionInitialization::BuildForMaster() should never be called by this version of Geant4 " << G4endl;
271 #else
272  // As real work is done by slaves, default is not RunManager for Master. Could be changed by overloading this method
273  SetUserAction( new SToGS::RunAction(0x0) ) ;
274 #endif
275  G4cout << " ------ END ------ from SToGS::AllInOneUserActionInitialization::BuildForMaster() " << G4endl;
276  }
277  virtual void Build () const = 0;
278  };
279 
281  template<typename _T> class AllInOneUserActionInitialization : public UserActionInitialization
282  {
283  public:
284  AllInOneUserActionInitialization(G4String which_user_action_opt, G4String which_gene, G4String which_gene_opt) :
285  UserActionInitialization(which_user_action_opt,which_gene,which_gene_opt)
286  {
287  ;
288  }
290  {
291  ;
292  }
293  virtual G4UserRunAction *GetRunAction() const
294  {
295  if ( fAllUserAction.size() == 0 ) {
296  fAllUserAction.push_back( new _T(fUserActionOption) );
297  }
298  return new SToGS::RunAction(fAllUserAction[0]);
299  }
300  virtual G4UserEventAction *GetEventAction() const
301  {
302  if ( fAllUserAction.size() == 0 ) {
303  fAllUserAction.push_back( new _T(fUserActionOption) );
304  }
305  return new SToGS::EventAction(fAllUserAction[0]);
306  }
307  virtual G4UserTrackingAction *GetTrackingAction() const
308  {
309  if ( fAllUserAction.size() == 0 ) {
310  fAllUserAction.push_back( new _T(fUserActionOption) );
311  }
312  return new SToGS::TrackingAction(fAllUserAction[0]);
313  }
314  virtual G4UserSteppingAction *GetSteppingAction() const
315  {
316  if ( fAllUserAction.size() == 0 ) {
317  fAllUserAction.push_back( new _T(fUserActionOption) );
318  }
319  return new SToGS::SteppingAction(fAllUserAction[0]);
320  }
321  virtual void Build () const
322  {
324  }
325  };
326 
327 
328 } // SToGS Namespace
329 
330 #endif
331 
332 
void BuildAndRegister(AllActions *) const
add the passed class to the list of allocated ones. It is required for a proper destruction ...
virtual G4UserRunAction * GetRunAction() const
depending on one string, select a given gun
virtual void EndOfEventAction(const G4Event *event)
virtual void BeginOfEventAction(const G4Event *)
virtual void PreUserTrackingAction(const G4Track *atrack)
virtual void PreUserTrackingAction(const G4Track *)
a G4 user's action manage by a single AllAction class
virtual void Build() const =0
virtual void EndOfRunAction(const G4Run *)
UserActionInitialization(G4String which_user_action_opt, G4String which_gene, G4String which_gene_opt)
SteppingAction(G4UserSteppingAction *theaction=0x0)
std::vector< AllActions * > fAllUserAction
list of allocated AllActions to delete them
Base class for a Run action that calls a concrete one.
Base class for a Tracking action that calls a concrete one.
virtual G4UserEventAction * GetEventAction() const
AllInOneUserActionInitialization(G4String which_user_action_opt, G4String which_gene, G4String which_gene_opt)
Base class for a Steeping action that calls a concrete one.
EventAction(G4UserEventAction *theaction=0x0)
virtual void BuildForMaster() const
provide default ... likely to be changed since RunManager may be different from Slave and Master ...
virtual G4UserTrackingAction * GetTrackingAction() const =0
virtual void BeginOfEventAction(const G4Event *event)
virtual void EndOfEventAction(const G4Event *)
static G4VSensitiveDetector * GetCopClusterSD(G4String name="/SToGS/SD/CopCluster")
to get a general SToGS Calorimeter. In Multi-threading mode, return a new instance otherwise a global...
Base class for a Event action that calls a concrete one.
TrackingAction(G4UserTrackingAction *theaction=0x0)
virtual void EndOfRunAction(const G4Run *aRun)
std::pair< G4String, G4String > fWhichGenerator
to keep what generator to be used. Defaut is "-","-", means the concrete implementation provides its ...
virtual void BeginOfRunAction(const G4Run *aRun)
RunAction(G4UserRunAction *theaction=0x0)
Base class to manage SToGS user's hooks + the generator.
virtual void UserSteppingAction(const G4Step *step)
static G4VSensitiveDetector * GetTrackerSD(G4String name="/SToGS/SD/Tracker")
to get a general SToGS tracker. In Multi-threading mode, return a new instance otherwise a global one...
virtual G4UserSteppingAction * GetSteppingAction() const =0
virtual void BeginOfRunAction(const G4Run *)
virtual G4VUserPrimaryGeneratorAction * GetGun() const
depending on one string, select a given gun
virtual G4UserRunAction * GetRunAction() const =0
depending on one string, select a given gun
virtual void UserSteppingAction(const G4Step *)
G4String fUserActionOption
action passed to the created user's actions if required
virtual void PostUserTrackingAction(const G4Track *atrack)
virtual void PostUserTrackingAction(const G4Track *)
std::pair< G4String, G4String > SetWhichGenerator(G4String which_gene, G4String option)
once allocated the generator associated with a UserActionInititialization could be changed here befor...
Base class that regroups in the same space all user's hooks. Convenient for sharing similar data...
virtual G4UserEventAction * GetEventAction() const =0
virtual G4UserSteppingAction * GetSteppingAction() const
virtual G4UserTrackingAction * GetTrackingAction() const