LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ActionHolder.cc
Go to the documentation of this file.
1 // Provides the implementation for the @ActionHolderService@ service.
2 // For more comprehensive documentation, see the header file ActionHolderService.hh
3 
4 // Authors: Tasha Arvanitis, Adam Lyon
5 // Date: July 2012
6 
7 // Includes
9 
16 
18 #include "range/v3/view.hpp"
19 
20 #include <algorithm>
21 #include <iostream>
22 
24 
26 // Message category
27 static std::string const msgctg = "ActionHolderService";
28 
29 // Constructor doesn't do much with the passed arguments, but does initialize
30 // the logger for the service
32 
33 // Register actions
34 template <typename A>
35 void
37  std::map<std::string, A*>& actionMap)
38 {
39  mf::LogDebug(msgctg) << "Registering action " << action->myName();
40 
41  // Check if the name exists in the specific action map
42  if (0 == actionMap.count(action->myName())) {
43  // Add the action!
44  actionMap.try_emplace(action->myName(), action);
45 
46  // Now, check whether the name exists in the overall map of all the actions
47  // If so, move on (don't throw an exception, since a single action may need
48  // to register in multiple maps). Otherwise, add it.
49  allActionsMap_.try_emplace(action->myName(), action);
50  }
51 
52  else {
53  // We already have this action in the specific action map - this is bad!
54  throw cet::exception("ActionHolderService")
55  << "Duplicate action named " << action->myName() << ".\n";
56  }
57 }
58 
59 void
61 {
62  std::cerr << "registering to runActionsMap_\n";
64 }
65 
66 void
68 {
69  std::cerr << "registering to eventActionsMap_\n";
71 }
72 
73 void
75 {
76  std::cerr << "registering to trackingActionsMap_\n";
78 }
79 
80 void
82 {
83  std::cerr << "registering to steppingActionsMap_\n";
85 }
86 
87 void
89 {
90  std::cerr << "registering to stackingActionsMap_\n";
92 }
93 
94 void
96 {
97  std::cerr << "registering to primaryGeneratorActionsMap_\n";
99 }
100 
101 // h3. Art-specific methods
102 void
104 {
105  for (auto action : eventActionsMap_ | values) {
106  action->callArtProduces(collector);
107  }
108 }
109 
110 void
112 {
113  for (auto action : allActionsMap_ | values) {
114  action->initialize();
115  }
116 }
117 
118 // h2. Action methods
119 
120 // h3. Event action methods
121 void
123 {
124  for (auto action : eventActionsMap_ | values) {
125  action->beginOfEventAction(theEvent);
126  }
127 }
128 
129 void
131 {
132  for (auto action : eventActionsMap_ | values) {
133  action->endOfEventAction(theEvent);
134  }
135 }
136 
137 // h3. Tracking action methods
138 void
140 {
141  for (auto action : trackingActionsMap_ | values) {
142  action->preUserTrackingAction(theTrack);
143  }
144 }
145 
146 void
148 {
149  for (auto action : trackingActionsMap_ | values) {
150  action->postUserTrackingAction(theTrack);
151  }
152 }
153 
154 // h3. Stepping actions
155 void
157 {
158  for (auto action : steppingActionsMap_ | values) {
159  action->userSteppingAction(theStep);
160  }
161 }
162 
163 // h3. Stacking actions
164 bool
166 {
167  for (auto action : stackingActionsMap_ | values) {
168  if (action->killNewTrack(newTrack)) {
169  return true;
170  }
171  }
172  return false;
173 }
174 
175 // h3. Primary generator actions
176 void
178 {
179  for (auto action : primaryGeneratorActionsMap_ | values) {
180  action->generatePrimaries(theEvent);
181  }
182 }
void postUserTrackingAction(const G4Track *)
bool killNewTrack(const G4Track *)
std::map< std::string, StackingActionBase * > stackingActionsMap_
void generatePrimaries(G4Event *)
void doRegisterAction(A *const action, std::map< std::string, A * > &actionMap)
Definition: ActionHolder.cc:36
void endOfEventAction(const G4Event *)
decltype(auto) values(Coll &&coll)
Range-for loop helper iterating across the values of the specified collection.
void callArtProduces(art::ProducesCollector &prod)
static std::string const msgctg
Definition: ActionHolder.cc:27
std::map< std::string, ActionBase * > allActionsMap_
std::map< std::string, RunActionBase * > runActionsMap_
void registerAction(RunActionBase *const action)
Definition: ActionHolder.cc:60
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
void preUserTrackingAction(const G4Track *)
ActionHolderService(fhicl::ParameterSet const &)
Definition: ActionHolder.cc:31
std::map< std::string, EventActionBase * > eventActionsMap_
void beginOfEventAction(const G4Event *)
std::map< std::string, SteppingActionBase * > steppingActionsMap_
void userSteppingAction(const G4Step *)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::map< std::string, PrimaryGeneratorActionBase * > primaryGeneratorActionsMap_
std::map< std::string, TrackingActionBase * > trackingActionsMap_