GGS(GenericGEANT4Simulation)Software  2.7.0
 All Data Structures Namespaces Files Functions Variables Typedefs Macros
GGSUserActionsManager.cpp
Go to the documentation of this file.
1 /*
2  * GGSUserActionsManager.cpp
3  *
4  * Created on: 31 May 2011
5  * Author: Nicola Mori
6  */
7 
13 
14 #include "G4RunManager.hh"
15 
16 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
17 
18 GGSUserActionsManager *GGSUserActionsManager::_instance = 0;
19 
21  if (!_instance)
22  _instance = new GGSUserActionsManager();
23 
24  return _instance;
25 }
26 
27 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
28 
29 GGSUserActionsManager::GGSUserActionsManager() : GGSUserAction(), _messenger(new GGSUAManagerMessenger) {}
30 
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 
34 
35  // Delete general actions
36  for (unsigned int i = 0; i < _userActions.size(); i++)
37  if (_userActions[i]) {
38  delete _userActions[i];
39  }
40  // Delete stepping actions
41  for (unsigned int i = 0; i < _steppingActions.size(); i++)
42  if (_steppingActions[i]) {
43  delete _steppingActions[i];
44  }
45  // Delete tracking actions
46  for (unsigned int i = 0; i < _trackingActions.size(); i++)
47  if (_trackingActions[i]) {
48  delete _trackingActions[i];
49  }
50  // Delete event actions
51  for (unsigned int i = 0; i < _eventActions.size(); i++)
52  if (_eventActions[i]) {
53  delete _eventActions[i];
54  }
55  // Delete run actions
56  for (unsigned int i = 0; i < _runActions.size(); i++)
57  if (_runActions[i]) {
58  delete _runActions[i];
59  }
60 
61  // Warning: this destructor will be called by ~G4Manager, which runs after
62  // ~GGSRunManager. So at this stage the child GGSRunManager is no
63  // more available and thus the mother G4Manager must be referenced.
64  // TODO: handle the destruction of the actions manager inside ~GGSRunManager, when
65  // the GGSRunManager interface has been properly extended to handle the
66  // actions manager.
67  G4RunManager *runManager = G4RunManager::GetRunManager();
68  if (runManager->GetUserSteppingAction() == this)
69  runManager->SetUserAction((G4UserSteppingAction *)0);
70  if (runManager->GetUserTrackingAction() == this)
71  runManager->SetUserAction((G4UserTrackingAction *)0);
72  if (runManager->GetUserEventAction() == this)
73  runManager->SetUserAction((G4UserEventAction *)0);
74  if (runManager->GetUserRunAction() == this)
75  runManager->SetUserAction((G4UserRunAction *)0);
76  if (runManager->GetUserStackingAction() == this)
77  runManager->SetUserAction((G4UserStackingAction *)0);
78 
79  // delete messenger
80  delete _messenger;
81 }
82 
83 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
84 
86  if (userAction) {
87  _userActions.push_back(userAction);
88  _userActions.back()->SetTrackingManagerPointer(fpTrackingManager);
89  }
90 }
91 
92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
93 
94 void GGSUserActionsManager::AddAction(G4UserSteppingAction *steppingAction) {
95  if (steppingAction)
96  _steppingActions.push_back(steppingAction);
97 }
98 
99 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
100 
101 void GGSUserActionsManager::AddAction(G4UserTrackingAction *trackingAction) {
102  if (trackingAction) {
103  _trackingActions.push_back(trackingAction);
104  _trackingActions.back()->SetTrackingManagerPointer(fpTrackingManager);
105  }
106 }
107 
108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
109 
110 void GGSUserActionsManager::AddAction(G4UserEventAction *eventAction) {
111  if (eventAction)
112  _eventActions.push_back(eventAction);
113 }
114 
115 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
116 
117 void GGSUserActionsManager::AddAction(G4UserRunAction *runAction) {
118  if (runAction)
119  _runActions.push_back(runAction);
120 }
121 
122 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
123 
125 
126  // Call routine for general actions
127  for (unsigned int i = 0; i < _userActions.size(); i++)
128  _userActions[i]->UserSteppingAction(step);
129 
130  // Call routine for stepping actions
131  for (unsigned int i = 0; i < _steppingActions.size(); i++)
132  _steppingActions[i]->UserSteppingAction(step);
133 }
134 
135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
136 
138 
139  // Call routine for general actions
140  for (unsigned int i = 0; i < _userActions.size(); i++)
141  _userActions[i]->PreUserTrackingAction(track);
142 
143  // Call routine for tracking actions
144  for (unsigned int i = 0; i < _trackingActions.size(); i++)
145  _trackingActions[i]->PreUserTrackingAction(track);
146 }
147 
148 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
149 
151 
152  // Call routine for general actions
153  for (unsigned int i = 0; i < _userActions.size(); i++)
154  _userActions[i]->PostUserTrackingAction(track);
155 
156  // Call routine for tracking actions
157  for (unsigned int i = 0; i < _trackingActions.size(); i++)
158  _trackingActions[i]->PostUserTrackingAction(track);
159 }
160 
161 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
162 
163 void GGSUserActionsManager::BeginOfEventAction(const G4Event *event) {
164 
165  // Call routine for general actions
166  for (unsigned int i = 0; i < _userActions.size(); i++)
167  _userActions[i]->BeginOfEventAction(event);
168 
169  // Call routine for event actions
170  for (unsigned int i = 0; i < _eventActions.size(); i++)
171  _eventActions[i]->BeginOfEventAction(event);
172 }
173 
174 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
175 
176 void GGSUserActionsManager::EndOfEventAction(const G4Event *event) {
177 
178  if (!GGSRunManager::GetRunManager()->IsCurrentEventKilled()) {
179 
180  // Call routine for general actions
181  for (unsigned int i = 0; i < _userActions.size(); i++)
182  _userActions[i]->EndOfEventAction(event);
183 
184  // Call routine for event actions
185  for (unsigned int i = 0; i < _eventActions.size(); i++)
186  _eventActions[i]->EndOfEventAction(event);
187 
188  GGSRootFileService::GetInstance()._FillDefaultEventsTrees();
189  }
190 }
191 
192 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
193 
195 
196  // Call routine for general actions
197  for (unsigned int i = 0; i < _userActions.size(); i++)
198  _userActions[i]->BeginOfRunAction(run);
199 
200  // Call routine for run actions
201  for (unsigned int i = 0; i < _runActions.size(); i++)
202  _runActions[i]->BeginOfRunAction(run);
203 }
204 
205 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
206 
208 
209  // Call routine for general actions
210  for (unsigned int i = 0; i < _userActions.size(); i++)
211  _userActions[i]->EndOfRunAction(run);
212 
213  // Call routine for run actions
214  for (unsigned int i = 0; i < _runActions.size(); i++)
215  _runActions[i]->EndOfRunAction(run);
216 }
217 
218 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
219 
220 G4ClassificationOfNewTrack GGSUserActionsManager::ClassifyNewTrack(const G4Track *aTrack) {
221 
222  int classif, actionClassif;
223  classif = -100;
224 
225  for (unsigned int i = 0; i < _userActions.size(); i++) {
226  actionClassif = _userActions[i]->ClassifyNewTrack(aTrack);
227  if (actionClassif != -100) {
228  if (actionClassif != classif && classif != -100) {
229  return G4UserStackingAction::ClassifyNewTrack(aTrack);
230  } else
231  classif = actionClassif;
232  }
233  }
234  if (classif == -100)
235  return G4UserStackingAction::ClassifyNewTrack(aTrack);
236  else
237  return (G4ClassificationOfNewTrack)classif;
238 }
239 
240 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
241 
243  for (unsigned int i = 0; i < _userActions.size(); i++) {
244  _userActions[i]->NewStage();
245  }
246 }
247 
248 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
249 
251 
252  for (unsigned int i = 0; i < _userActions.size(); i++) {
253  _userActions[i]->PrepareNewEvent();
254  }
255 }
void EndOfRunAction(const G4Run *run)
Override of EndOfRunAction method.
void AddAction(GGSUserAction *userAction)
Adds a general user action.
void PreUserTrackingAction(const G4Track *track)
Override of PreUserTrackingAction method.
void PostUserTrackingAction(const G4Track *track)
Override of PostUserTrackingAction method.
G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track *aTrack)
Override of ClassifyNewTrack method.
void UserSteppingAction(const G4Step *step)
Override of UserSteppingAction method.
static GGSRunManager * GetRunManager()
Static getter function the run manager.
void BeginOfEventAction(const G4Event *event)
Override of BeginOfEventAction method.
void BeginOfRunAction(const G4Run *run)
Override of BeginOfRunAction method.
The GGS ser actions manager.
static GGSRootFileService & GetInstance()
Get reference to GGSRootFileService unique instance.
Messenger for the user actions manager.
Mother class for user actions in GGS.
Definition: GGSUserAction.h:27
void NewStage()
Override of NewStage method.
static GGSUserActionsManager * GetInstance()
Get the singleton instance.
void EndOfEventAction(const G4Event *event)
Override of EndOfEventAction method.
void PrepareNewEvent()
Override of PrepareNewEvent method.