LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ActionHolder_service.hh
Go to the documentation of this file.
1 // Declarations for the @ActionHolderService@ Art service.
2 
3 // @ActionHolderService@ is a globally-accessible service that manages the action
4 // objects for a simulation. An action object has a multitude of hooks into
5 // various points during event creation and processing. All action objects
6 // must be registered with this service in order to function.
7 
8 // Any class can @#include@ and access the @ActionHolderService@ service to get either
9 // a collection of registered action objects or a specific action object given
10 // a name.
11 
12 // Authors: Tasha Arvanitis, Adam Lyon
13 // Date: July 2012
14 
15 #ifndef artg4tk_services_ActionHolder_service_hh
16 #define artg4tk_services_ActionHolder_service_hh
17 
18 // Includes
20 #include "fhiclcpp/fwd.h"
21 
22 namespace art {
23  class ProducesCollector;
24  class Event;
25  class Run;
26 }
27 
28 #include <map>
29 
30 class G4Run;
31 class G4Event;
32 class G4Track;
33 class G4Step;
34 
35 // Everything for the Art G4 simulation goes in the @artg4tk@ namespace
36 namespace artg4tk {
37 
38  class ActionBase;
39  class RunActionBase;
40  class EventActionBase;
41  class TrackingActionBase;
42  class SteppingActionBase;
43  class StackingActionBase;
44  class PrimaryGeneratorActionBase;
45 
47  public:
49 
50  // This method registers the passed action object with the service
51  void registerAction(RunActionBase* const action);
52  void registerAction(EventActionBase* const action);
53  void registerAction(TrackingActionBase* const action);
54  void registerAction(SteppingActionBase* const action);
55  void registerAction(StackingActionBase* const action);
56  void registerAction(PrimaryGeneratorActionBase* const action);
57 
58  // Call ActionBase::initialize for each action
59  void initialize();
60 
61  // h3. Art-specific methods
62 
63  // Tell each action to notify Art of what it will be producing.
64  void callArtProduces(art::ProducesCollector& prod);
65 
66  // Set/get the current Art event
67  void
69  {
70  currentArtEvent_ = &e;
71  }
72  art::Event&
74  {
75  return (*currentArtEvent_);
76  }
77 
78  // Set/get the current Art Run
79  void
81  {
82  currentArtRun_ = &r;
83  }
84  art::Run&
86  {
87  return (*currentArtRun_);
88  }
89 
90  // h3. Action methods
91 
92  // h4. Event Actions
93  void beginOfEventAction(const G4Event*);
94  void endOfEventAction(const G4Event*);
95 
96  // h4. Tracking actions
97  void preUserTrackingAction(const G4Track*);
98  void postUserTrackingAction(const G4Track*);
99 
100  // h4. Stepping actions
101  void userSteppingAction(const G4Step*);
102 
103  // h4. Stacking actions
104  bool killNewTrack(const G4Track*);
105 
106  // h4. Primary Generator actions
107  void generatePrimaries(G4Event*);
108 
109  private:
110  // A collection of all our actions, arranged by name
111  std::map<std::string, RunActionBase*> runActionsMap_{};
112  std::map<std::string, EventActionBase*> eventActionsMap_{};
113  std::map<std::string, TrackingActionBase*> trackingActionsMap_{};
114  std::map<std::string, SteppingActionBase*> steppingActionsMap_{};
115  std::map<std::string, StackingActionBase*> stackingActionsMap_{};
116  std::map<std::string, PrimaryGeneratorActionBase*> primaryGeneratorActionsMap_{};
117 
118  // Hold on to the current Art event
119  art::Event* currentArtEvent_{nullptr};
120 
121  // Hold on to the current Art run
122  art::Run* currentArtRun_{nullptr};
123 
124  // An uber-collection of all registered actions, arranged by name
125  std::map<std::string, ActionBase*> allActionsMap_{};
126 
127  // Register the action
128  template <typename A>
129  void doRegisterAction(A* const action, std::map<std::string, A*>& actionMap);
130  };
131 } // namespace artg4tk
132 
134 
135 #endif /* artg4tk_services_ActionHolder_service_hh */
TRandom r
Definition: spectrum.C:23
Definition: Run.h:37
#define DECLARE_ART_SERVICE(svc, scope)
Definition: MVAAlg.h:12
Float_t e
Definition: plot.C:35