ATLAS Offline Software
Loading...
Searching...
No Matches
G4UA::TestActionTimer Class Reference

User action to measure time spent in subdetectors. More...

#include <TestActionTimer.h>

Inheritance diagram for G4UA::TestActionTimer:
Collaboration diagram for G4UA::TestActionTimer:

Classes

struct  Report
 this holds all the data from individual threads that needs to be merged at EoR More...

Public Types

enum  {
  eEMB , eEMEC , eFC1 , eFC23 ,
  eFCO , eHEC , eCry , eLAr ,
  eHCB , ePre , eMu , ePx ,
  eSct , eITkPix , eITkStrip , eSev ,
  eTrt , eOther , eElec , ePos ,
  eGam , eNeut , eMax
}

Public Member Functions

 TestActionTimer ()
 constructor
 TestActionTimer (const TestActionTimer &)=delete
TestActionTimeroperator= (const TestActionTimer &)=delete
const ReportgetReport () const
virtual void BeginOfEventAction (const G4Event *) override
virtual void EndOfEventAction (const G4Event *) override
virtual void BeginOfRunAction (const G4Run *) override
virtual void EndOfRunAction (const G4Run *) override
virtual void UserSteppingAction (const G4Step *) override

Private Member Functions

double TimerSum (G4Timer *timer) const
 Gets the appropriate time from the timer for adding to the sum.
void PPanic ()
 Method to shut down all particle timers.
void VPanic ()
 Method to shut down all volume timers.
int ClassifyVolume (G4String &) const
 Method to sort out which volume we are in.

Private Attributes

Report m_report
G4Timer * m_runTimer
 Timer for the entire run.
G4Timer * m_eventTimer
 Timer for this event.
double m_eventTime
 Double for storing this event.
std::vector< G4Timer * > m_timer
 Vector of timers for each of the enum.

Detailed Description

User action to measure time spent in subdetectors.

    @author Zachary Marshall, Caltech, USA
    @author Wolfgang Ehrenfeld, University of Hamburg, Germany 

Definition at line 52 of file TestActionTimer.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
eEMB 
eEMEC 
eFC1 
eFC23 
eFCO 
eHEC 
eCry 
eLAr 
eHCB 
ePre 
eMu 
ePx 
eSct 
eITkPix 
eITkStrip 
eSev 
eTrt 
eOther 
eElec 
ePos 
eGam 
eNeut 
eMax 

Definition at line 97 of file TestActionTimer.h.

99 eElec, ePos, eGam, eNeut, eMax };

Constructor & Destructor Documentation

◆ TestActionTimer() [1/2]

G4UA::TestActionTimer::TestActionTimer ( )

constructor

Definition at line 61 of file TestActionTimer.cxx.

62 : m_report(),
63 m_runTimer(0),
64 m_eventTimer(0),
65 //m_runTime(0.),
66 m_eventTime(0.)//,
67 //m_histSvc("THistSvc",name)
68 {
69 m_report.timeName.resize(eMax);
70 m_report.timeName[eEMB] = "EMB";
71 m_report.timeName[eEMEC] = "EMEC";
72 m_report.timeName[eFC1] = "FC1";
73 m_report.timeName[eFC23] = "FC23";
74 m_report.timeName[eFCO] = "FCO";
75 m_report.timeName[eHEC] = "HEC";
76 m_report.timeName[eCry] = "Cry";
77 m_report.timeName[eLAr] = "LAr";
78 m_report.timeName[eHCB] = "HCB";
79 m_report.timeName[eITkPix] = "ITkPixel";
80 m_report.timeName[eITkStrip] = "ITkStrip";
81 m_report.timeName[ePre] = "Pre";
82 m_report.timeName[eMu] = "Mu";
83 m_report.timeName[ePx] = "Px";
84 m_report.timeName[eTrt] = "TRT";
85 m_report.timeName[eSev] = "IDServ";
86 m_report.timeName[eSct] = "SCT";
87 m_report.timeName[eOther] = "Other";
88
89 m_report.timeName[eElec] = "Elec";
90 m_report.timeName[ePos] = "Pos";
91 m_report.timeName[eGam] = "Gam";
92 m_report.timeName[eNeut] = "Neut";
93
94 G4cout<< "TestActionTimer::Constructor: Labels "
95 <<" Run Event ";
96 for (int i(0); i < eMax; ++i) G4cout << m_report.timeName[i] << " ";
97 G4cout << "Particle Dead" << G4endl;
98
99 // init timers
100
101 m_runTimer = new G4Timer();
102 m_runTimer->Start();
103
104 // create all timers, start and stop, init counters
105 for (int i(0); i < eMax; ++i) {
106 G4Timer* timer = new G4Timer();
107 timer->Start();
108
109 m_timer.push_back(timer);
110 m_report.time.push_back(0.);
111 }
112
113 PPanic();
114 VPanic();
115
116#ifdef _myDebug
117 G4cout << "TestActionTimer::Constructor done" << G4endl;
118#endif
119 }
G4Timer * m_runTimer
Timer for the entire run.
G4Timer * m_eventTimer
Timer for this event.
std::vector< G4Timer * > m_timer
Vector of timers for each of the enum.
double m_eventTime
Double for storing this event.
void PPanic()
Method to shut down all particle timers.
void VPanic()
Method to shut down all volume timers.
timer(name, disabled=False)

◆ TestActionTimer() [2/2]

G4UA::TestActionTimer::TestActionTimer ( const TestActionTimer & )
delete

Member Function Documentation

◆ BeginOfEventAction()

void G4UA::TestActionTimer::BeginOfEventAction ( const G4Event * )
overridevirtual

Definition at line 121 of file TestActionTimer.cxx.

122 {
123 m_report.nev++;
124
125 if (m_eventTimer != 0) {
126 delete m_eventTimer;
127 m_eventTimer = 0;
128 }
129 m_eventTime = 0.;
130 m_eventTimer = new G4Timer();
131 m_eventTimer->Start();
132
133 m_runTimer->Start();
134 }

◆ BeginOfRunAction()

void G4UA::TestActionTimer::BeginOfRunAction ( const G4Run * )
overridevirtual

Definition at line 145 of file TestActionTimer.cxx.

146 {
147 m_report.runTime=0.;
148 m_runTimer->Start();
149 }

◆ ClassifyVolume()

int G4UA::TestActionTimer::ClassifyVolume ( G4String & nomstr) const
private

Method to sort out which volume we are in.

Definition at line 275 of file TestActionTimer.cxx.

276 {
277 std::string_view nom(nomstr); //Avoid copying characters during comparison
278 if( nom.length() >= 17 &&
279 nom.substr(13,4) == "EMEC" ){
280 return eEMEC;
281 }
282 else if ( nom.length() >= 16 &&
283 nom.substr(13,3) == "EMB" ){
284 return eEMB;
285 }
286 else if( nom.length() >= 25 &&
287 nom.substr(21,4) == "Cryo" ) {
288 return eCry;
289 }
290 else if( nom.length() >= 26 &&
291 nom.substr(13,13) == "FCAL::Module1"){
292 return eFC1;
293 }
294 else if( nom.length() >= 25 &&
295 nom.substr(13,12) == "FCAL::Module" ){
296 return eFC23;
297 }
298 else if ( nom.length() >= 17 &&
299 nom.substr(13,4) == "FCAL" ){
300 return eFCO;
301 }
302 else if ( nom.length() >= 16 &&
303 nom.substr(13,3) == "HEC" ){
304 return eHEC;
305 }
306 else if( nom.length() >= 31 &&
307 nom.substr(21,10) == "Presampler" ) {
308 return ePre;
309 }
310 else if ( nom.length() >= 3 &&
311 nom.substr(0,3) == "LAr" ){
312 return eLAr;
313 }
314 else if( ( (nom.length() >= 4 &&
315 nom.substr(0,4) == "Muon") ||
316 nom.substr(0,4) == "MUON" ) ||
317 ( nom.length() >= 9 &&
318 nom.substr(0,9) == "DriftTube" ) ||
319 G4StrContains(nom, "MDT") ||
320 ( nom.length() >= 12 &&
321 nom.substr(0,12) == "SensitiveGas" ) ||
322 G4StrContains(nom, "MDT") ||
323 G4StrContains(nom, "station") ){
324 return eMu;
325 }
326 else if ( nom.length() >= 8 &&
327 nom.substr(0,8) == "ITkPixel" ){
328 return eITkPix;
329 }
330 else if ( nom.length() >= 8 &&
331 nom.substr(0,8) == "ITkStrip" ){
332 return eITkStrip;
333 }
334 else if ((nom.length() >= 5 &&
335 nom.substr(0,5) == "Pixel") ||
336 nom == "Outside Barrel Service"){
337 return ePx;
338 }
339 else if ( nom.length() >= 3 &&
340 nom.substr(0,3) == "SCT" ){
341 return eSct;
342 }
343 else if ( ( nom.length() >= 3 &&
344 nom.substr(0,3) == "TRT" ) ||
345 nom == "GasMANeg" ){
346 return eTrt;
347 }
348 else if ( nom.length() >= 4 &&
349 nom.substr(0,4) == "Tile"){
350 return eHCB;
351 }
352 else if ( ( nom.length() >= 12 &&
353 nom.substr(0,12) == "InDetServMat" ) ||
354 ( nom.length() >= 4 &&
355 nom.substr(0,4) == "IDET" ) ||
356 ( nom.length() >= 3 &&
357 nom.substr(0,3) == "ITK" ) ||
358 ( nom.length() >= 8 &&
359 nom.substr(0,8) == "BeamPipe" ) ||
360 ( nom.length() >= 7 &&
361 nom.substr(0,7) == "Section" ) ||
362 ( nom.length() >= 3 &&
363 ( nom.substr(0,3) == "BLM" ||
364 nom.substr(0,3) == "BCM" ||
365 nom.substr(0,3) == "PLR" ) ) ||
366 ( nom.length() >= 8 &&
367 nom.substr(0,8) == "BCMPrime" ) ){
368 return eSev;
369 }
370 return eOther;
371 }
bool G4StrContains(const G4String &s, const char *v)

◆ EndOfEventAction()

void G4UA::TestActionTimer::EndOfEventAction ( const G4Event * )
overridevirtual

Definition at line 136 of file TestActionTimer.cxx.

137 {
138 m_report.runTime += TimerSum(m_runTimer);
140
141 VPanic();
142 PPanic();
143 }
double TimerSum(G4Timer *timer) const
Gets the appropriate time from the timer for adding to the sum.

◆ EndOfRunAction()

void G4UA::TestActionTimer::EndOfRunAction ( const G4Run * )
overridevirtual

Definition at line 151 of file TestActionTimer.cxx.

152 {
153 std::cerr<<"TestActionTimer::EndOfRunAction "<< m_report.runTime <<std::endl;
154 m_report.runTime += TimerSum(m_runTimer);
155 VPanic();
156 PPanic();
157 }

◆ getReport()

const Report & G4UA::TestActionTimer::getReport ( ) const
inline

Definition at line 85 of file TestActionTimer.h.

86 { return m_report; }

◆ operator=()

TestActionTimer & G4UA::TestActionTimer::operator= ( const TestActionTimer & )
delete

◆ PPanic()

void G4UA::TestActionTimer::PPanic ( )
private

Method to shut down all particle timers.

Definition at line 231 of file TestActionTimer.cxx.

232 {
233#ifdef _myDebug
234 G4cout << "TestActionTimer::PPanic" << G4endl;
235#endif
236
237 // stop all particle counters and add time
238 for (int i(eElec); i < eMax; ++i) {
239 G4Timer* timer = m_timer[i];
240#ifdef _myDebug
241 G4cout << "TestActionTimer::PPanic stopping counter i:" << i << " " << timer << G4endl;
242#endif
243 if (!timer->IsValid()){
244 m_report.time[i] += TimerSum(timer);
245 }
246 }
247
248#ifdef _myDebug
249 G4cout << "TestActionTimer::PPanic done" << G4endl;
250#endif
251 }

◆ TimerSum()

double G4UA::TestActionTimer::TimerSum ( G4Timer * timer) const
private

Gets the appropriate time from the timer for adding to the sum.

Definition at line 224 of file TestActionTimer.cxx.

225 {
226 if (timer == 0) return -999.;
227 timer->Stop();
228 return (timer->GetUserElapsed() + timer->GetSystemElapsed());
229 }

◆ UserSteppingAction()

void G4UA::TestActionTimer::UserSteppingAction ( const G4Step * aStep)
overridevirtual

Definition at line 159 of file TestActionTimer.cxx.

160 {
161 // HERE IS WHERE WE BEGIN OUR CLOCKING
162
163 // Get basic information about the event
164 G4Track* track = aStep->GetTrack();
165
166 G4String thePrePVname = track->GetVolume()->GetName();
167 G4String thePostPVname;
168 if (track->GetNextVolume() != 0) {
169 thePostPVname = track->GetNextVolume()->GetName();
170 } else {
171 thePostPVname = "OutOfWorld";
172 }
173
174 // Check what volume we are in. If the volume does not agree with the clock, kill the clock
175 G4Timer* timer = 0;
176 int preIndex = ClassifyVolume( thePrePVname );
177 int postIndex=-1;
178 if (thePrePVname != thePostPVname){
179 timer = m_timer[preIndex];
180 if (!timer->IsValid()){ m_report.time[preIndex] += TimerSum(timer); } else { VPanic(); }
181
182 // Now start the appropriate clock
183 postIndex = ClassifyVolume( thePostPVname );
184 m_timer[postIndex]->Start();
185
186 // Otherwise it's going into "out of world"
187 } else {
188 timer = m_timer[preIndex];
189 if (timer->IsValid()) {
190 VPanic(); timer->Start();
191 }
192 }
193
194 // Now for the particle based timers
195 if (track->GetDefinition() == G4Electron::ElectronDefinition() ){
196 if ( m_timer[eElec]->IsValid() ){
197 m_timer[eElec]->Start();
198 }
199 } else if (!m_timer[eElec]->IsValid()){
201 }
202 if (track->GetDefinition() == G4Positron::PositronDefinition() ){
203 if ( m_timer[ePos]->IsValid() ){
204 m_timer[ePos]->Start();
205 }
206 } else if (!m_timer[ePos]->IsValid()){
207 m_report.time[ePos] += TimerSum(m_timer[ePos]);
208 }
209 if (track->GetDefinition() == G4Gamma::GammaDefinition() &&
210 m_timer[eGam]->IsValid()){
211 m_timer[eGam]->Start();
212 } else if ( !m_timer[eGam]->IsValid() ){
213 m_report.time[eGam] += TimerSum(m_timer[eGam]);
214 }
215 if (track->GetDefinition() == G4Neutron::NeutronDefinition() &&
216 m_timer[eNeut]->IsValid()){
217 m_timer[eNeut]->Start();
218 } else if ( !m_timer[eNeut]->IsValid() ){
220 }
221 }
int ClassifyVolume(G4String &) const
Method to sort out which volume we are in.

◆ VPanic()

void G4UA::TestActionTimer::VPanic ( )
private

Method to shut down all volume timers.

Definition at line 253 of file TestActionTimer.cxx.

254 {
255#ifdef _myDebug
256 G4cout << "TestActionTimer::VPanic" << G4endl;
257#endif
258
259 // stop all volume counters and add time
260 for (int i(0); i <= eOther; ++i) {
261 G4Timer* timer = m_timer[i];
262#ifdef _myDebug
263 G4cout << "TestActionTimer::VPanic stopping counter i:" << i << " " << timer << G4endl;
264#endif
265 if (!timer->IsValid()){
266 m_report.time[i] += TimerSum(timer);
267 }
268 }
269
270#ifdef _myDebug
271 G4cout << "TestActionTimer::VPanic done" << G4endl;
272#endif
273 }

Member Data Documentation

◆ m_eventTime

double G4UA::TestActionTimer::m_eventTime
private

Double for storing this event.

Definition at line 107 of file TestActionTimer.h.

◆ m_eventTimer

G4Timer* G4UA::TestActionTimer::m_eventTimer
private

Timer for this event.

Definition at line 106 of file TestActionTimer.h.

◆ m_report

Report G4UA::TestActionTimer::m_report
private

Definition at line 103 of file TestActionTimer.h.

◆ m_runTimer

G4Timer* G4UA::TestActionTimer::m_runTimer
private

Timer for the entire run.

Definition at line 105 of file TestActionTimer.h.

◆ m_timer

std::vector<G4Timer*> G4UA::TestActionTimer::m_timer
private

Vector of timers for each of the enum.

Definition at line 109 of file TestActionTimer.h.


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