ATLAS Offline Software
Loading...
Searching...
No Matches
G4SimTimer.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef G4USERACTIONS_G4UA_G4SIMTIMER_H
6#define G4USERACTIONS_G4UA_G4SIMTIMER_H
7
8#include <cassert>
9
10// Infrastructure includes
12
13// Geant4 includes
14#include "G4Timer.hh"
15#include "G4UserEventAction.hh"
16#include <G4UserRunAction.hh>
17
18// Forward declarations
19class G4Event;
20class G4Run;
21
22namespace G4UA
23{
24
42 class G4SimTimer : public G4UserEventAction, public G4UserRunAction, public AthMessaging
43 {
44
45 public:
46
48 struct Report
49 {
51 Report();
52
53 // Total runtime
54 G4Timer runtime;
57 unsigned int nEvent;
59 double eventTime;
63 std::pair<double, double> meanAndSigma();
64
65 void merge(const Report& rep){
66 // only one of the report instance (the master run action) will have a valid runtime
67 if(rep.runtime.IsValid()){
68 assert(!runtime.IsValid());
69 runtime = rep.runtime;
70 }
71 nEvent += rep.nEvent;
72 eventTime += rep.eventTime;
73 eventTimeSquared += rep.eventTimeSquared;
74 }
75 };
76
78 G4SimTimer();
79
81 virtual void BeginOfRunAction(const G4Run* run) override final;
82
84 virtual void EndOfRunAction(const G4Run* run) override final;
85
87 virtual void BeginOfEventAction(const G4Event* event) override final;
88
90 virtual void EndOfEventAction(const G4Event* event) override final;
91
93 const Report& getReport() const
94 { return m_results; }
95
96 private:
97
99 G4Timer m_eventTimer;
100
103
106
107 }; // class G4SimTimer
108
109} // namespace G4UA
110
111#endif // G4USERACTIONS_G4UA_G4SIMTIMER_H
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
virtual void EndOfRunAction(const G4Run *run) override final
End timing this Geant4 run.
G4Timer m_eventTimer
My private instance of an event timer.
Definition G4SimTimer.h:99
const Report & getReport() const
Retrieve my timing results.
Definition G4SimTimer.h:93
virtual void EndOfEventAction(const G4Event *event) override final
Finish timing this Geant4 event.
virtual void BeginOfRunAction(const G4Run *run) override final
Start timing this Geant4 run.
Report m_results
My timing results.
Definition G4SimTimer.h:102
G4SimTimer()
Constructor.
virtual void BeginOfEventAction(const G4Event *event) override final
Start timing this Geant4 event.
bool m_firstEvent
Used to skip the first event.
Definition G4SimTimer.h:105
Simple struct which holds timing results for an action instance.
Definition G4SimTimer.h:49
std::pair< double, double > meanAndSigma()
Calculate the mean and sample std dev.
double eventTime
Accumulated event time.
Definition G4SimTimer.h:59
Report()
Initializes the variables.
unsigned int nEvent
Number of timed G4 events (we skip the first).
Definition G4SimTimer.h:57
double eventTimeSquared
Accumulated squared event time.
Definition G4SimTimer.h:61
void merge(const Report &rep)
Definition G4SimTimer.h:65
int run(int argc, char *argv[])