GGS(GenericGEANT4Simulation)Software  2.99.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Macros
Public Member Functions
GGSMultiUserAction Class Reference

A multiplexer container for user actions. More...

#include <GGSMultiUserAction.h>

Inheritance diagram for GGSMultiUserAction:
Inheritance graph
[legend]
Collaboration diagram for GGSMultiUserAction:
Collaboration graph
[legend]

Public Member Functions

 GGSMultiUserAction ()
 constructor.
 
 ~GGSMultiUserAction ()
 Destructor. More...
 
void AddAction (std::unique_ptr< GGSUserAction > &&userAction)
 Adds a general user action. More...
 
void AddAction (std::unique_ptr< G4UserSteppingAction > &&steppingAction)
 Adds a stepping action. More...
 
void AddAction (std::unique_ptr< G4UserTrackingAction > &&trackingAction)
 Adds a tracking action. More...
 
void AddAction (std::unique_ptr< G4UserEventAction > &&eventAction)
 Adds a event action. More...
 
void AddAction (std::unique_ptr< G4UserRunAction > &&runAction)
 Adds a run action. More...
 
void AddAction (std::unique_ptr< G4UserStackingAction > &&stackingAction)
 Adds a stacking action. More...
 
void UserSteppingAction (const G4Step *step)
 Override of UserSteppingAction method. More...
 
void PreUserTrackingAction (const G4Track *track)
 Override of PreUserTrackingAction method. More...
 
void PostUserTrackingAction (const G4Track *track)
 Override of PostUserTrackingAction method. More...
 
void BeginOfEventAction (const G4Event *event)
 Override of BeginOfEventAction method. More...
 
void EndOfEventAction (const G4Event *event)
 Override of EndOfEventAction method. More...
 
void BeginOfRunAction (const G4Run *run)
 Override of BeginOfRunAction method. More...
 
void EndOfRunAction (const G4Run *run)
 Override of EndOfRunAction method. More...
 
G4ClassificationOfNewTrack ClassifyNewTrack (const G4Track *aTrack)
 Override of ClassifyNewTrack method. More...
 
void NewStage ()
 Override of NewStage method. More...
 
void PrepareNewEvent ()
 Override of PrepareNewEvent method. More...
 
- Public Member Functions inherited from GGSUserAction
 GGSUserAction ()
 Constructor. More...
 
virtual ~GGSUserAction ()
 Destructor.
 
G4ClassificationOfNewTrack ClassifyNewTrack (const G4Track *)
 Override of the ClassifyNewTrack method. More...
 

Detailed Description

A multiplexer container for user actions.

This class is intended as an actions container. User can fill it with desired actions and the class will provide the necessary interface to GEANT4 kernel calls. The main aim of this software layer is to give the user the possibility to define and use the set of actions which is most suitable for the specific simulation. The class can contain general actions inheriting from GGSUserAction (which can do something at each simulation level) as well as actions inheriting from regular GEANT4 user actions (like G4UserEventAction, which acts only at the beginning and at the end of an event). The actions are NOT guaranteed to be executed in the same order they are added to the manager. The class in current implementation owns the actions it contains.

Definition at line 32 of file GGSMultiUserAction.h.

Constructor & Destructor Documentation

GGSMultiUserAction::~GGSMultiUserAction ( )

Destructor.

It destroys also the actions previously added to the manager.

Definition at line 23 of file GGSMultiUserAction.cpp.

23  {
24 
25  // Warning: this destructor will be called by ~G4RunManager, which runs after
26  // ~GGSRunManager. So at this stage the child GGSRunManager is no
27  // more available and thus the mother G4Manager must be referenced.
28  // TODO: handle the destruction of the actions manager inside ~GGSRunManager, when
29  // the GGSRunManager interface has been properly extended to handle the
30  // actions manager.
31  G4RunManager *runManager = G4RunManager::GetRunManager();
32  if (runManager->GetUserSteppingAction() == this)
33  runManager->SetUserAction((G4UserSteppingAction *)0);
34  if (runManager->GetUserTrackingAction() == this)
35  runManager->SetUserAction((G4UserTrackingAction *)0);
36  if (runManager->GetUserEventAction() == this)
37  runManager->SetUserAction((G4UserEventAction *)0);
38  if (runManager->GetUserRunAction() == this)
39  runManager->SetUserAction((G4UserRunAction *)0);
40  if (runManager->GetUserStackingAction() == this)
41  runManager->SetUserAction((G4UserStackingAction *)0);
42 }

Member Function Documentation

void GGSMultiUserAction::AddAction ( std::unique_ptr< GGSUserAction > &&  userAction)

Adds a general user action.

Parameters
userActionThe general user action to be added to the manager.

Definition at line 46 of file GGSMultiUserAction.cpp.

46  {
47  if (userAction) {
48  _userActions.push_back(std::move(userAction));
49  _userActions.back()->SetTrackingManagerPointer(fpTrackingManager);
50  }
51 }
void GGSMultiUserAction::AddAction ( std::unique_ptr< G4UserSteppingAction > &&  steppingAction)

Adds a stepping action.

Parameters
steppingActionThe stepping action to be added to the manager.

Definition at line 55 of file GGSMultiUserAction.cpp.

55  {
56  if (steppingAction) {
57  _steppingActions.push_back(std::move(steppingAction));
58  }
59 }
void GGSMultiUserAction::AddAction ( std::unique_ptr< G4UserTrackingAction > &&  trackingAction)

Adds a tracking action.

Parameters
trackingActionThe tracking action to be added to the manager.

Definition at line 63 of file GGSMultiUserAction.cpp.

63  {
64  if (trackingAction) {
65  _trackingActions.push_back(std::move(trackingAction));
66  _trackingActions.back()->SetTrackingManagerPointer(fpTrackingManager);
67  }
68 }
void GGSMultiUserAction::AddAction ( std::unique_ptr< G4UserEventAction > &&  eventAction)

Adds a event action.

Parameters
eventActionThe event action to be added to the manager.

Definition at line 72 of file GGSMultiUserAction.cpp.

72  {
73  if (eventAction) {
74  _eventActions.push_back(std::move(eventAction));
75  }
76 }
void GGSMultiUserAction::AddAction ( std::unique_ptr< G4UserRunAction > &&  runAction)

Adds a run action.

Parameters
runActionThe run action to be added to the manager.

Definition at line 80 of file GGSMultiUserAction.cpp.

80  {
81  if (runAction) {
82  _runActions.push_back(std::move(runAction));
83  }
84 }
void GGSMultiUserAction::AddAction ( std::unique_ptr< G4UserStackingAction > &&  stackingAction)

Adds a stacking action.

Parameters
stackingActionThe stacking action to be added to the manager.

Definition at line 88 of file GGSMultiUserAction.cpp.

88  {
89  if (stackingAction) {
90  _stackingActions.push_back(std::move(stackingAction));
91  }
92 }
void GGSMultiUserAction::BeginOfEventAction ( const G4Event *  event)

Override of BeginOfEventAction method.

This routine calls BeginOfEventAction for every general and event actions in the manager.

Parameters
eventThe current event.

Definition at line 135 of file GGSMultiUserAction.cpp.

135  {
136 
137  // Call routine for general actions
138  for (unsigned int i = 0; i < _userActions.size(); i++)
139  _userActions[i]->BeginOfEventAction(event);
140 
141  // Call routine for event actions
142  for (unsigned int i = 0; i < _eventActions.size(); i++)
143  _eventActions[i]->BeginOfEventAction(event);
144 }
void BeginOfEventAction(const G4Event *event)
Override of BeginOfEventAction method.
void GGSMultiUserAction::BeginOfRunAction ( const G4Run *  run)

Override of BeginOfRunAction method.

This routine calls BeginOfRunAction for every general and run actions in the manager.

Parameters
runThe current run.

Definition at line 167 of file GGSMultiUserAction.cpp.

167  {
168 
169  // Call routine for general actions
170  for (unsigned int i = 0; i < _userActions.size(); i++)
171  _userActions[i]->BeginOfRunAction(run);
172 
173  // Call routine for run actions
174  for (unsigned int i = 0; i < _runActions.size(); i++)
175  _runActions[i]->BeginOfRunAction(run);
176 }
void BeginOfRunAction(const G4Run *run)
Override of BeginOfRunAction method.
G4ClassificationOfNewTrack GGSMultiUserAction::ClassifyNewTrack ( const G4Track *  aTrack)

Override of ClassifyNewTrack method.

This routine calls ClassifyNewTrack for every general actions in the manager. If no general actions are present, or if none of them reimplements ClassifyNewTrack properly, it returns the return value of G4UserStackingAction::ClassifyNewTrack. If more actions are present and the classifications are not in agreement, the default classification given by G4UserStackingAction::ClassifyNewTrack will be returned;

Parameters
aTrackThe new track.

Definition at line 193 of file GGSMultiUserAction.cpp.

193  {
194 
195  int classif, actionClassif;
196  classif = -100;
197  GGSUserAction *classifierUA = nullptr;
198  G4UserStackingAction *classifierSA = nullptr;
199 
200  for (auto &actionPtr : _userActions) {
201  actionClassif = actionPtr->ClassifyNewTrack(aTrack);
202  if (actionClassif != -100) {
203  if (actionClassif != classif && classif != -100) {
204  G4ExceptionDescription ed;
205  std::string classifierUAClassName = typeid(*classifierUA).name();
206  auto *actionRawPtr = actionPtr.get(); // Call the unique_ptr method here to avoid a clang warning about possible
207  // side effects if calling it inside typeid
208  std::string thisUAClassName = typeid(*actionRawPtr).name();
209  ed << "Classification of track " << aTrack->GetTrackID() << " from GGS action " << classifierUAClassName << " ("
210  << classif << ") is different from classification from GGS action " << thisUAClassName << " ("
211  << actionClassif << ")";
212  G4Exception("GGSMultiUserAction::ClassifyNewTrack", "Clashing track classifications",
213  G4ExceptionSeverity::FatalException, ed);
214  } else {
215  classif = actionClassif;
216  classifierUA = actionPtr.get();
217  }
218  }
219  }
220  for (auto &actionPtr : _stackingActions) {
221  actionClassif = actionPtr->ClassifyNewTrack(aTrack);
222  if (actionClassif != classif && classif != -100) {
223  G4ExceptionDescription ed;
224  std::string classifierActionType, classifierClassName;
225  if (classifierUA != nullptr) {
226  classifierActionType = "GGS";
227  classifierClassName = typeid(*classifierUA).name();
228  } else if (classifierSA != nullptr) {
229  classifierActionType = "stacking";
230  classifierClassName = typeid(*classifierSA).name();
231  }
232  auto *actionRawPtr = actionPtr.get(); // Call the unique_ptr method here to avoid a clang warning about possible
233  // side effects if calling it inside typeid
234  auto thisSAClassName = typeid(*actionRawPtr).name();
235  ed << "Classification of track " << aTrack->GetTrackID() << " from " << classifierActionType << " action "
236  << classifierClassName << " (" << classif << ") is different from classification from stacking action "
237  << thisSAClassName << " (" << actionClassif << ")";
238  G4Exception("GGSMultiUserAction::ClassifyNewTrack", "Clashing track classifications",
239  G4ExceptionSeverity::FatalException, ed);
240  } else {
241  classif = actionClassif;
242  classifierSA = actionPtr.get();
243  }
244  }
245  if (classif == -100) {
246  return G4UserStackingAction::ClassifyNewTrack(aTrack);
247  } else {
248  return (G4ClassificationOfNewTrack)classif;
249  }
250 }
G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track *)
Override of the ClassifyNewTrack method.
Definition: GGSUserAction.h:54
Mother class for user actions in GGS.
Definition: GGSUserAction.h:27
void GGSMultiUserAction::EndOfEventAction ( const G4Event *  event)

Override of EndOfEventAction method.

This routine calls EndOfEventAction for every general and event actions in the manager.

Parameters
eventThe current event.

Definition at line 148 of file GGSMultiUserAction.cpp.

148  {
149 
150  GGSRunManagerExtensions &rmExt = dynamic_cast<GGSRunManagerExtensions &>(*(G4RunManager::GetRunManager()));
151  if (!(rmExt.IsCurrentEventKilled())) {
152 
153  // Call routine for general actions
154  for (unsigned int i = 0; i < _userActions.size(); i++)
155  _userActions[i]->EndOfEventAction(event);
156 
157  // Call routine for event actions
158  for (unsigned int i = 0; i < _eventActions.size(); i++)
159  _eventActions[i]->EndOfEventAction(event);
160 
161  GGSRootFileService::GetInstance()._FillDefaultEventsTrees();
162  }
163 }
Class with additional functionalities for run managers.
bool IsCurrentEventKilled()
Getter method for killed event flag.
static GGSRootFileService & GetInstance()
Get reference to GGSRootFileService unique instance.
void EndOfEventAction(const G4Event *event)
Override of EndOfEventAction method.
void GGSMultiUserAction::EndOfRunAction ( const G4Run *  run)

Override of EndOfRunAction method.

This routine calls EndOfRunAction for every general and run actions in the manager.

Parameters
runThe current run.

Definition at line 180 of file GGSMultiUserAction.cpp.

180  {
181 
182  // Call routine for general actions
183  for (unsigned int i = 0; i < _userActions.size(); i++)
184  _userActions[i]->EndOfRunAction(run);
185 
186  // Call routine for run actions
187  for (unsigned int i = 0; i < _runActions.size(); i++)
188  _runActions[i]->EndOfRunAction(run);
189 }
void EndOfRunAction(const G4Run *run)
Override of EndOfRunAction method.
void GGSMultiUserAction::NewStage ( )

Override of NewStage method.

This routine calls NewStage for every general and stacking actions in the manager.

Definition at line 254 of file GGSMultiUserAction.cpp.

254  {
255  for (unsigned int i = 0; i < _userActions.size(); i++) {
256  _userActions[i]->NewStage();
257  }
258 }
void GGSMultiUserAction::PostUserTrackingAction ( const G4Track *  track)

Override of PostUserTrackingAction method.

This routine calls PostUserTrackingAction for every general and tracking actions in the manager.

Parameters
trackThe current track.

Definition at line 122 of file GGSMultiUserAction.cpp.

122  {
123 
124  // Call routine for general actions
125  for (unsigned int i = 0; i < _userActions.size(); i++)
126  _userActions[i]->PostUserTrackingAction(track);
127 
128  // Call routine for tracking actions
129  for (unsigned int i = 0; i < _trackingActions.size(); i++)
130  _trackingActions[i]->PostUserTrackingAction(track);
131 }
void PostUserTrackingAction(const G4Track *track)
Override of PostUserTrackingAction method.
void GGSMultiUserAction::PrepareNewEvent ( )

Override of PrepareNewEvent method.

This routine calls PrepareNewEvent for every general and stacking actions in the manager.

Definition at line 262 of file GGSMultiUserAction.cpp.

262  {
263 
264  for (unsigned int i = 0; i < _userActions.size(); i++) {
265  _userActions[i]->PrepareNewEvent();
266  }
267 }
void GGSMultiUserAction::PreUserTrackingAction ( const G4Track *  track)

Override of PreUserTrackingAction method.

This routine calls PreUserTrackingAction for every general and tracking actions in the manager.

Parameters
trackThe current track.

Definition at line 109 of file GGSMultiUserAction.cpp.

109  {
110 
111  // Call routine for general actions
112  for (unsigned int i = 0; i < _userActions.size(); i++)
113  _userActions[i]->PreUserTrackingAction(track);
114 
115  // Call routine for tracking actions
116  for (unsigned int i = 0; i < _trackingActions.size(); i++)
117  _trackingActions[i]->PreUserTrackingAction(track);
118 }
void PreUserTrackingAction(const G4Track *track)
Override of PreUserTrackingAction method.
void GGSMultiUserAction::UserSteppingAction ( const G4Step *  step)

Override of UserSteppingAction method.

This routine calls UserSteppingAction for every general and stepping actions in the manager.

Parameters
stepThe current step.

Definition at line 96 of file GGSMultiUserAction.cpp.

96  {
97 
98  // Call routine for general actions
99  for (unsigned int i = 0; i < _userActions.size(); i++)
100  _userActions[i]->UserSteppingAction(step);
101 
102  // Call routine for stepping actions
103  for (unsigned int i = 0; i < _steppingActions.size(); i++)
104  _steppingActions[i]->UserSteppingAction(step);
105 }
void UserSteppingAction(const G4Step *step)
Override of UserSteppingAction method.

The documentation for this class was generated from the following files: