GGS(GenericGEANT4Simulation)Software  2.6.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() :
30  GGSUserAction(), _messenger(new GGSUAManagerMessenger) {
31 }
32 
33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
34 
36 
37  // Delete general actions
38  for (unsigned int i = 0; i < _userActions.size(); i++)
39  if (_userActions[i]) {
40  delete _userActions[i];
41  }
42  // Delete stepping actions
43  for (unsigned int i = 0; i < _steppingActions.size(); i++)
44  if (_steppingActions[i]) {
45  delete _steppingActions[i];
46  }
47  // Delete tracking actions
48  for (unsigned int i = 0; i < _trackingActions.size(); i++)
49  if (_trackingActions[i]) {
50  delete _trackingActions[i];
51  }
52  // Delete event actions
53  for (unsigned int i = 0; i < _eventActions.size(); i++)
54  if (_eventActions[i]) {
55  delete _eventActions[i];
56  }
57  // Delete run actions
58  for (unsigned int i = 0; i < _runActions.size(); i++)
59  if (_runActions[i]) {
60  delete _runActions[i];
61  }
62 
63  // Warning: this destructor will be called by ~G4Manager, which runs after
64  // ~GGSRunManager. So at this stage the child GGSRunManager is no
65  // more available and thus the mother G4Manager must be referenced.
66  // TODO: handle the destruction of the actions manager inside ~GGSRunManager, when
67  // the GGSRunManager interface has been properly extended to handle the
68  // actions manager.
69  G4RunManager *runManager = G4RunManager::GetRunManager();
70  if (runManager->GetUserSteppingAction() == this)
71  runManager->SetUserAction((G4UserSteppingAction*) 0);
72  if (runManager->GetUserTrackingAction() == this)
73  runManager->SetUserAction((G4UserTrackingAction*) 0);
74  if (runManager->GetUserEventAction() == this)
75  runManager->SetUserAction((G4UserEventAction*) 0);
76  if (runManager->GetUserRunAction() == this)
77  runManager->SetUserAction((G4UserRunAction*) 0);
78  if (runManager->GetUserStackingAction() == this)
79  runManager->SetUserAction((G4UserStackingAction*) 0);
80 
81  // delete messenger
82  delete _messenger;
83 }
84 
85 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
86 
88  if (userAction) {
89  _userActions.push_back(userAction);
90  _userActions.back()->SetTrackingManagerPointer(fpTrackingManager);
91  }
92 }
93 
94 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
95 
96 void GGSUserActionsManager::AddAction(G4UserSteppingAction *steppingAction) {
97  if (steppingAction)
98  _steppingActions.push_back(steppingAction);
99 }
100 
101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
102 
103 void GGSUserActionsManager::AddAction(G4UserTrackingAction *trackingAction) {
104  if (trackingAction) {
105  _trackingActions.push_back(trackingAction);
106  _trackingActions.back()->SetTrackingManagerPointer(fpTrackingManager);
107  }
108 }
109 
110 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
111 
112 void GGSUserActionsManager::AddAction(G4UserEventAction *eventAction) {
113  if (eventAction)
114  _eventActions.push_back(eventAction);
115 }
116 
117 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
118 
119 void GGSUserActionsManager::AddAction(G4UserRunAction *runAction) {
120  if (runAction)
121  _runActions.push_back(runAction);
122 }
123 
124 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
125 
127 
128  // Call routine for general actions
129  for (unsigned int i = 0; i < _userActions.size(); i++)
130  _userActions[i]->UserSteppingAction(step);
131 
132  // Call routine for stepping actions
133  for (unsigned int i = 0; i < _steppingActions.size(); i++)
134  _steppingActions[i]->UserSteppingAction(step);
135 }
136 
137 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
138 
140 
141  // Call routine for general actions
142  for (unsigned int i = 0; i < _userActions.size(); i++)
143  _userActions[i]->PreUserTrackingAction(track);
144 
145  // Call routine for tracking actions
146  for (unsigned int i = 0; i < _trackingActions.size(); i++)
147  _trackingActions[i]->PreUserTrackingAction(track);
148 }
149 
150 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
151 
153 
154  // Call routine for general actions
155  for (unsigned int i = 0; i < _userActions.size(); i++)
156  _userActions[i]->PostUserTrackingAction(track);
157 
158  // Call routine for tracking actions
159  for (unsigned int i = 0; i < _trackingActions.size(); i++)
160  _trackingActions[i]->PostUserTrackingAction(track);
161 
162 }
163 
164 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
165 
166 void GGSUserActionsManager::BeginOfEventAction(const G4Event *event) {
167 
168  // Call routine for general actions
169  for (unsigned int i = 0; i < _userActions.size(); i++)
170  _userActions[i]->BeginOfEventAction(event);
171 
172  // Call routine for event actions
173  for (unsigned int i = 0; i < _eventActions.size(); i++)
174  _eventActions[i]->BeginOfEventAction(event);
175 }
176 
177 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
178 
179 void GGSUserActionsManager::EndOfEventAction(const G4Event *event) {
180 
181  if (!GGSRunManager::GetRunManager()->IsCurrentEventKilled()) {
182 
183  // Call routine for general actions
184  for (unsigned int i = 0; i < _userActions.size(); i++)
185  _userActions[i]->EndOfEventAction(event);
186 
187  // Call routine for event actions
188  for (unsigned int i = 0; i < _eventActions.size(); i++)
189  _eventActions[i]->EndOfEventAction(event);
190 
191  GGSRootFileService::GetInstance()._FillDefaultEventsTrees();
192  }
193 }
194 
195 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
196 
198 
199  // Call routine for general actions
200  for (unsigned int i = 0; i < _userActions.size(); i++)
201  _userActions[i]->BeginOfRunAction(run);
202 
203  // Call routine for run actions
204  for (unsigned int i = 0; i < _runActions.size(); i++)
205  _runActions[i]->BeginOfRunAction(run);
206 }
207 
208 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
209 
211 
212  // Call routine for general actions
213  for (unsigned int i = 0; i < _userActions.size(); i++)
214  _userActions[i]->EndOfRunAction(run);
215 
216  // Call routine for run actions
217  for (unsigned int i = 0; i < _runActions.size(); i++)
218  _runActions[i]->EndOfRunAction(run);
219 }
220 
221 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
222 
223 G4ClassificationOfNewTrack GGSUserActionsManager::ClassifyNewTrack(const G4Track* aTrack) {
224 
225  int classif, actionClassif;
226  classif = -100;
227 
228  for (unsigned int i = 0; i < _userActions.size(); i++) {
229  actionClassif = _userActions[i]->ClassifyNewTrack(aTrack);
230  if (actionClassif != -100) {
231  if (actionClassif != classif && classif != -100) {
232  return G4UserStackingAction::ClassifyNewTrack(aTrack);
233  }
234  else
235  classif = actionClassif;
236  }
237  }
238  if (classif == -100)
239  return G4UserStackingAction::ClassifyNewTrack(aTrack);
240  else
241  return (G4ClassificationOfNewTrack) classif;
242 }
243 
244 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
245 
247  for (unsigned int i = 0; i < _userActions.size(); i++) {
248  _userActions[i]->NewStage();
249  }
250 }
251 
252 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
253 
255 
256  for (unsigned int i = 0; i < _userActions.size(); i++) {
257  _userActions[i]->PrepareNewEvent();
258  }
259 }
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.