UserActionManager.h
Go to the documentation of this file.
1 /// LArG4::UserActionManager.h
2 /// 18-Sep-2007 Bill Seligman
3 ///
4 /// 27-Jan-2009 <seligman@nevis.columbia.edu> Revised for LArSoft.
5 ///
6 /// In my experience, people barely understand what the UserAction
7 /// interface does. So why do we need a UserActionManager class?
8 ///
9 /// Suppose I've written a class that inherits from UserAction that
10 /// makes histograms. You've written a class that inherits from
11 /// UserAction to write events to a disk file. Jane has written an
12 /// UserAction that makes ntuples. A big massive 500-CPU-hour run of
13 /// G4 is planned, and we're all planning how to put our user-action
14 /// classes together.
15 ///
16 /// By using a UserActionManager class, each one of us can develop our
17 /// own user-action classes independently. Then, when we have the big
18 /// run, the user-action classes can be put successively called by the
19 /// UserActionManager without changing any of the classes.
20 ///
21 /// Another feature is the ability to separate different user-action
22 /// functions. For example, you don't have to mix your code that
23 /// writes hits with the code that makes histograms; the code can be
24 /// put into separate classes.
25 ///
26 /// 18-Sep-2007: Make this a true "Manager" class by turning it into a
27 /// singleton. Give the UserAction-derived classes access to the
28 /// Geant4 user-class managers.
29 ///
30 /// 2012-08-17: <rhatcher@fnal.gov> Add G4UserStackingAction interfaces.
31 /// By default these aren't invoked unless the UserAction::ProvidesStacking()
32 /// returns "true". Generally there should be only one such in the managed
33 /// list, but if there are and they can't agree on the track classification
34 /// then prioritize them in what seems a sensible manner.
35 
36 #ifndef G4BASE_UserActionManager_H
37 #define G4BASE_UserActionManager_H
38 
39 #include "nutools/G4Base/UserAction.h"
40 
41 #include "Geant4/G4UserRunAction.hh"
42 #include "Geant4/G4UserEventAction.hh"
43 #include "Geant4/G4UserTrackingAction.hh"
44 #include "Geant4/G4UserSteppingAction.hh"
45 #include "Geant4/G4UserStackingAction.hh"
46 
47 #include "Geant4/G4Run.hh"
48 #include "Geant4/G4Event.hh"
49 #include "Geant4/G4Track.hh"
50 #include "Geant4/G4Step.hh"
51 
52 #include "Geant4/G4EventManager.hh"
53 #include "Geant4/G4TrackingManager.hh"
54 #include "Geant4/G4SteppingManager.hh"
55 
56 #include <vector>
57 
58 namespace g4b {
59 
60  class UserActionManager : public G4UserRunAction
61  , public G4UserEventAction
62  , public G4UserTrackingAction
63  , public G4UserSteppingAction
64  , public G4UserStackingAction {
65  public:
66 
67  // Access to instance:
68  static UserActionManager* Instance();
69 
70  virtual ~UserActionManager();
71 
72  // Delete all the UserAction classes we manage.
73  void Close();
74 
75  G4int GetSize() const { return fuserActions.size(); }
76  UserAction* GetAction(G4int i) const { return fuserActions[i]; }
77  UserAction* GetAction(std::string const& name) const;
78  G4int GetIndex(std::string const& name) const;
79 
80  void PrintActionList(std::string const& opt) const;
81 
82  static void AddAndAdoptAction(UserAction* a){ fuserActions.push_back(a); }
83 
84  // G4UserRunAction interfaces
85  virtual void BeginOfRunAction (const G4Run* );
86  virtual void EndOfRunAction (const G4Run* );
87  // G4UserEventAction interfaces
88  virtual void BeginOfEventAction (const G4Event*);
89  virtual void EndOfEventAction (const G4Event*);
90  // G4UserTrackingAction interfaces
91  virtual void PreUserTrackingAction (const G4Track*);
92  virtual void PostUserTrackingAction(const G4Track*);
93  // G4UserSteppingAction interface
94  virtual void UserSteppingAction (const G4Step* );
95  // G4UserStackingAction interfaces
96  virtual G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track*);
97  virtual void NewStage();
98  virtual void PrepareNewEvent();
99  virtual bool DoesAnyActionProvideStacking(); // do any managed UserActions do stacking
100 
101  // "Mysterious accessors": Where do the pointers to these managers
102  // come from? They are all defined in the G4User*Action classes.
103  // Use care when calling these accessors; for example, the
104  // SteppingManager is probably not available in a TrackingAction
105  // method. Keep the heirarchy in mind: Run > Event > Track > Step.
106  G4EventManager* GetEventManager() const { return fpEventManager; }
107  G4TrackingManager* GetTrackingManager() const { return fpTrackingManager; }
108  G4SteppingManager* GetSteppingManager() const { return fpSteppingManager; }
109 
110  private:
111  typedef std::vector<UserAction*> fuserActions_t;
113  static fuserActions_t fuserActions;
114 
115  protected:
116  // The constructor is protected according to the standard
117  // singleton pattern.
119 
120  };
121 
122 } // namespace g4b
123 
124 #endif // G4BASE_UserActionManager_H
static QCString name
Definition: declinfo.cpp:673
UserAction * GetAction(G4int i) const
virtual bool DoesAnyActionProvideStacking()
std::string string
Definition: nybbler.cc:12
opt
Definition: train.py:196
intermediate_table::const_iterator const_iterator
virtual void UserSteppingAction(const G4Step *)
G4EventManager * GetEventManager() const
virtual void BeginOfEventAction(const G4Event *)
virtual void EndOfEventAction(const G4Event *)
G4int GetIndex(std::string const &name) const
static void AddAndAdoptAction(UserAction *a)
G4TrackingManager * GetTrackingManager() const
virtual void BeginOfRunAction(const G4Run *)
fuserActions_t::const_iterator fuserActions_ptr_t
basic interface to Geant4 for ART-based software
std::vector< UserAction * > fuserActions_t
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
void PrintActionList(std::string const &opt) const
static UserActionManager * Instance()
virtual void EndOfRunAction(const G4Run *)
static fuserActions_t fuserActions
virtual G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track *)
virtual void PostUserTrackingAction(const G4Track *)
G4SteppingManager * GetSteppingManager() const
virtual void PreUserTrackingAction(const G4Track *)