ATLAS Offline Software
TestActionVPTimer.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // //
7 //$Id:TestActionVPTimer.h,v 1.0 2008/07/08 13:46:47 zmarshal Exp $//
8 // //
9 // TestActionVPTimer //
10 // Code for text output (into log file) //
11 // of information about the time spent simulating //
12 // various pieces of the detector and particles. //
13 // //
14 // Written by //
15 // Zachary Marshall, Caltech, USA //
16 // Wolfgang Ehrenfeld, University of Hamburg, Germany //
17 // Revised by //
18 // Kevin Sapp, Pitt, USA //
19 // //
20 // @version $Revision: 660034 $ //
21 // //
23 
24 #ifndef G4PROFILINGTOOLS_TestActionVPTimer_H
25 #define G4PROFILINGTOOLS_TestActionVPTimer_H
26 
27 #include "VolumeTreeNavigator.h"
28 
29 #include "G4Timer.hh"
30 #include "G4VPhysicalVolume.hh"
31 
32 #include <string>
33 #include <map>
34 #include <utility>
35 #include <vector>
36 #include <ostream>
37 #include <sstream>
38 
39 #include "G4UserEventAction.hh"
40 #include "G4UserRunAction.hh"
41 #include "G4UserSteppingAction.hh"
42 
43 // Forward declarations
44 class G4Run;
45 class G4Event;
46 class G4Step;
47 
48 namespace G4UA
49 {
50 
52  public G4UserEventAction, public G4UserRunAction, public G4UserSteppingAction
53  {
54 
55  public:
56 
57  struct Config
58  {
59  int dCALO=2;
60  int dBeam=2;
61  int dIDET=2;
62  int dMUON=2;
63  std::string dDetail="";
64  };
65 
67 
70 
71 
72  struct volumeData {
73  public:
75  this->tTotal += acc.tTotal;
76  this->tElectron += acc.tElectron;
77  this->tPhoton += acc.tPhoton;
78  this->tNeutron += acc.tNeutron;
79  this->tPion += acc.tPion;
80  this->tBaryon += acc.tBaryon;
81  this->tLepton += acc.tLepton;
82  this->tMeson += acc.tMeson;
83  this->tOther += acc.tOther;
84  return *this;
85  };
86 
87  double tTotal=0;
88  double tElectron=0;
89  double tPhoton=0;
90  double tNeutron=0;
91  double tPion=0;
92  double tBaryon=0;
93  double tLepton=0;
94  double tMeson=0;
95  double tOther=0;
96 
97  };
98 
99  typedef std::map<VolTree, TestActionVPTimer::volumeData> VolMap;
100  typedef VolMap::const_iterator VolIt;
101 
102  struct Report
103  {
104  // time_index is map<VolTree, TestActionVPTimer::volumeData>
105  // VolTree is vector< pair<physvol*,int> >
106 
108  int nev=0;
109  double runTime=0;
110 
111  void merge(const Report& rep){
112 
113  nev+=rep.nev;
114  runTime+=rep.runTime;
115 
116  // copy first map
117  if(time_index.empty()){
118  time_index=rep.time_index;
119  return;
120  }
121 
122  // must merge timers per particle and per tree
123  // loop on new report
124  for(auto& element:rep.time_index){
125 
126  // check if key exists
127  auto existing=time_index.find(element.first);
128  if(existing!=time_index.end()){
129  // sum timings (using volData)
130  existing->second+=element.second;
131  }
132  else {
133  // add new entry
134  time_index.insert(element);
135  }
136  }
137 
138  }
139  };
140 
141  const Report& getReport() const
142  { return m_report; }
143 
144  virtual void BeginOfEventAction(const G4Event*) override;
145  virtual void EndOfEventAction(const G4Event*) override;
146  virtual void BeginOfRunAction(const G4Run*) override;
147  virtual void EndOfRunAction(const G4Run*) override;
148  virtual void UserSteppingAction(const G4Step*) override;
149 
150  private:
153 
154  G4Timer* m_runTimer;
155  G4Timer* m_eventTimer;
156  G4Timer* v_timer;
157  double m_eventTime;
158 
160 
161  double TimerSum(G4Timer* timer) const;
162 
163  }; // class TestActionVPTimer
164 
166  inline double TestActionVPTimer::TimerSum(G4Timer* timer) const
167  {
168  if (timer == 0) return -999.;
169  timer->Stop();
170  return (timer->GetUserElapsed() + timer->GetSystemElapsed());
171  }
172 
173 } // namespace G4UA
174 
175 #endif // #define G4PROFILINGTOOLS_TestActionVPTimer_H
G4UA::TestActionVPTimer::Config::dBeam
int dBeam
Definition: TestActionVPTimer.h:60
G4UA::TestActionVPTimer::m_eventTimer
G4Timer * m_eventTimer
Timer for this event.
Definition: TestActionVPTimer.h:155
G4UA::TestActionVPTimer::m_report
Report m_report
Definition: TestActionVPTimer.h:152
G4UA::TestActionVPTimer::v_timer
G4Timer * v_timer
Timer activated for each volume.
Definition: TestActionVPTimer.h:156
G4UA
for nSW
Definition: CalibrationDefaultProcessing.h:19
make_hlt_rep.rep
rep
Definition: make_hlt_rep.py:32
G4UA::TestActionVPTimer::EndOfRunAction
virtual void EndOfRunAction(const G4Run *) override
Definition: TestActionVPTimer.cxx:82
G4UA::TestActionVPTimer::volumeData::tPhoton
double tPhoton
Time spent on photons in volume.
Definition: TestActionVPTimer.h:89
G4UA::TestActionVPTimer::Config::dIDET
int dIDET
Definition: TestActionVPTimer.h:61
G4UA::TestActionVPTimer::volumeData::tBaryon
double tBaryon
Time spent on other baryons in volume.
Definition: TestActionVPTimer.h:92
G4UA::TestActionVPTimer::BeginOfRunAction
virtual void BeginOfRunAction(const G4Run *) override
Definition: TestActionVPTimer.cxx:77
G4UA::TestActionVPTimer::Config::dMUON
int dMUON
Used for setting depths in jobOptions file.
Definition: TestActionVPTimer.h:62
G4UA::TestActionVPTimer::volumeData::tElectron
double tElectron
Time spent on e objects in volume.
Definition: TestActionVPTimer.h:88
G4UA::TestActionVPTimer::volumeData::tLepton
double tLepton
Time spent on other leptons in volume.
Definition: TestActionVPTimer.h:93
G4UA::TestActionVPTimer::m_config
Config m_config
Definition: TestActionVPTimer.h:151
G4UA::TestActionVPTimer::Config
Definition: TestActionVPTimer.h:58
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
python.utils.AtlRunQueryTimer.timer
def timer(name, disabled=False)
Definition: AtlRunQueryTimer.py:86
G4UA::TestActionVPTimer
Definition: TestActionVPTimer.h:53
G4UA::TestActionVPTimer::Report
Definition: TestActionVPTimer.h:103
G4UA::TestActionVPTimer::volumeData
Definition: TestActionVPTimer.h:72
G4UA::TestActionVPTimer::UserSteppingAction
virtual void UserSteppingAction(const G4Step *) override
Definition: TestActionVPTimer.cxx:88
G4UA::TestActionVPTimer::Config::dCALO
int dCALO
Definition: TestActionVPTimer.h:59
G4UA::TestActionVPTimer::m_eventTime
double m_eventTime
Double for storing this event time.
Definition: TestActionVPTimer.h:157
G4UA::TestActionVPTimer::Report::time_index
VolMap time_index
Definition: TestActionVPTimer.h:107
G4UA::TestActionVPTimer::Report::nev
int nev
number of processed events
Definition: TestActionVPTimer.h:108
G4UA::TestActionVPTimer::volumeData::tMeson
double tMeson
Time spent on all mesons in volume.
Definition: TestActionVPTimer.h:94
G4UA::TestActionVPTimer::TestActionVPTimer
TestActionVPTimer(const Config &config)
Definition: TestActionVPTimer.cxx:48
G4UA::TestActionVPTimer::m_runTimer
G4Timer * m_runTimer
Timer for the entire run.
Definition: TestActionVPTimer.h:154
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
G4UA::TestActionVPTimer::EndOfEventAction
virtual void EndOfEventAction(const G4Event *) override
Definition: TestActionVPTimer.cxx:71
VolumeTreeNavigator.h
G4UA::TestActionVPTimer::volumeData::operator+=
volumeData operator+=(const volumeData &acc)
< Structure of data for given volume
Definition: TestActionVPTimer.h:74
G4UA::TestActionVPTimer::volumeData::tNeutron
double tNeutron
Time spent on neutrons in volume.
Definition: TestActionVPTimer.h:90
VolTree
std::vector< VolID > VolTree
Definition: VolumeTreeNavigator.h:36
G4UA::TestActionVPTimer::v_history
VolTree v_history
Vector of the current volume history, used to assign times to each element.
Definition: TestActionVPTimer.h:159
G4UA::TestActionVPTimer::volumeData::tOther
double tOther
Time spent on all other particles in volume (mostly nuclei)
Definition: TestActionVPTimer.h:95
G4UA::TestActionVPTimer::volumeData::tPion
double tPion
Time spent on pions in volume.
Definition: TestActionVPTimer.h:91
G4UA::TestActionVPTimer::volumeData::tTotal
double tTotal
Overloaded += operator.
Definition: TestActionVPTimer.h:87
G4UA::TestActionVPTimer::TimerSum
double TimerSum(G4Timer *timer) const
Gets the time from the timer for summation.
Definition: TestActionVPTimer.h:166
G4UA::TestActionVPTimer::VolIt
VolMap::const_iterator VolIt
Definition: TestActionVPTimer.h:100
G4UA::TestActionVPTimer::Report::merge
void merge(const Report &rep)
Definition: TestActionVPTimer.h:111
G4UA::TestActionVPTimer::getReport
const Report & getReport() const
Definition: TestActionVPTimer.h:141
G4UA::TestActionVPTimer::Config::dDetail
std::string dDetail
Path to set detailed depth in jobOptions file.
Definition: TestActionVPTimer.h:63
G4UA::TestActionVPTimer::TestActionVPTimer
TestActionVPTimer(const TestActionVPTimer &)=delete
G4UA::TestActionVPTimer::VolMap
std::map< VolTree, TestActionVPTimer::volumeData > VolMap
Definition: TestActionVPTimer.h:99
G4UA::TestActionVPTimer::BeginOfEventAction
virtual void BeginOfEventAction(const G4Event *) override
Definition: TestActionVPTimer.cxx:65
G4UA::TestActionVPTimer::operator=
TestActionVPTimer & operator=(const TestActionVPTimer &)=delete
G4UA::TestActionVPTimer::Report::runTime
double runTime
Double for storing this run time.
Definition: TestActionVPTimer.h:109