ATLAS Offline Software
Loading...
Searching...
No Matches
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
44class G4Run;
45class G4Event;
46class G4Step;
47
48namespace 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
std::vector< VolID > VolTree
virtual void BeginOfRunAction(const G4Run *) override
TestActionVPTimer & operator=(const TestActionVPTimer &)=delete
double m_eventTime
Double for storing this event time.
std::map< VolTree, TestActionVPTimer::volumeData > VolMap
double TimerSum(G4Timer *timer) const
Gets the time from the timer for summation.
VolTree v_history
Vector of the current volume history, used to assign times to each element.
TestActionVPTimer(const Config &config)
G4Timer * m_eventTimer
Timer for this event.
virtual void EndOfEventAction(const G4Event *) override
VolMap::const_iterator VolIt
virtual void BeginOfEventAction(const G4Event *) override
TestActionVPTimer(const TestActionVPTimer &)=delete
virtual void UserSteppingAction(const G4Step *) override
G4Timer * v_timer
Timer activated for each volume.
virtual void EndOfRunAction(const G4Run *) override
const Report & getReport() const
G4Timer * m_runTimer
Timer for the entire run.
std::string dDetail
Path to set detailed depth in jobOptions file.
int dMUON
Used for setting depths in jobOptions file.
double runTime
Double for storing this run time.
int nev
number of processed events
double tMeson
Time spent on all mesons in volume.
double tBaryon
Time spent on other baryons in volume.
volumeData operator+=(const volumeData &acc)
< Structure of data for given volume
double tPhoton
Time spent on photons in volume.
double tTotal
Overloaded += operator.
double tPion
Time spent on pions in volume.
double tNeutron
Time spent on neutrons in volume.
double tOther
Time spent on all other particles in volume (mostly nuclei)
double tLepton
Time spent on other leptons in volume.
double tElectron
Time spent on e objects in volume.