ATLAS Offline Software
TestActionVPTimerTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "VolumeTreeNavigator.h"
7 #include <algorithm>
8 #include <iomanip>
9 #include <ios>
10 
11 using std::map;
12 using std::max;
13 using std::string;
14 using std::setw;
15 using std::ios;
16 using std::make_pair;
17 using std::pair;
18 using std::find;
19 using std::vector;
20 
21 namespace G4UA
22 {
23 
24  //----------------------------------------------------------------------------
25  // Formats print string for timer output
26  inline std::string vPrFmt (double time, double nEv, double tRun, int depth, const std::string& id)
27  {
28  std::string dprnt = stringify(depth);
29  if (depth == -999) dprnt = " ";
30  std::ostringstream oss;
31  oss << std::setw(12) << time << std::setw(12) << time/nEv << std::setw(12) << time/tRun
32  << std::setw(6) << dprnt << " " << id;
33  return oss.str();
34  }
35 
36  typedef std::map<VolTree, TestActionVPTimer::volumeData> VolMap;
37  typedef VolMap::const_iterator VolIt;
38 
39  //----------------------------------------------------------------------------
41  const std::string& name,
42  const IInterface* parent)
44  {
45  declareProperty("CaloDepth",m_config.dCALO);
46  declareProperty("BeamPipeDepth",m_config.dBeam);
47  declareProperty("InDetDepth",m_config.dIDET);
48  declareProperty("MuonDepth",m_config.dMUON);
49  declareProperty("DetailDepth",m_config.dDetail);
50  }
51 
52  //----------------------------------------------------------------------------
53  std::unique_ptr<TestActionVPTimer>
55  {
56  ATH_MSG_DEBUG("Constructing a TestActionVPTimer");
57  auto action = std::make_unique<TestActionVPTimer>(m_config);
58  actionList.runActions.push_back( action.get() );
59  actionList.eventActions.push_back( action.get() );
60  actionList.steppingActions.push_back( action.get() );
61  return action;
62  }
63 
64  //----------------------------------------------------------------------------
66  {
67  // We shouldn't need this. End-run actions should be called by Geant4.
68  // I'll leave this here, commented out for now, for reference.
69  //for(auto& tidAction : m_actions) {
70  // ((G4UserRunAction*)tidAction.second)->EndOfRunAction(0);
71  //}
72 
73  // Accumulate results across threads
76 
77  if(m_report.time_index.size()){
78 
79  VolTree topPV; // vector< pair<physvol*,int> >
80  // time_index is map<VolTree, TestActionVPTimer::volumeData>
81 
82  topPV.push_back(m_report.time_index.begin()->first.front());
83  TestActionVPTimer::volumeData atlasData = m_report.time_index.find(topPV)->second;
84  G4double DeadTime = m_report.runTime - atlasData.tTotal;
85 
86  ATH_MSG_INFO("Runtime " << m_report.runTime
87  << " Dead Time " << DeadTime );
88 
89  if (m_report.nev != 0){
90  ATH_MSG_INFO("******* Beginning timer dump *******" );
91 
92  ATH_MSG_INFO(setw(12) << "Time" << setw(12) << "per Event" << setw(12)
93  << "per Run" << setw(6) << "Depth" << " Location/Particle" );
94  ATH_MSG_INFO(vPrFmt(m_report.runTime, m_report.nev, atlasData.tTotal, -999, " Event Average") );
95  ATH_MSG_INFO(vPrFmt(DeadTime, m_report.nev, atlasData.tTotal, -999, " Dead/Initialization") );
96 
97  ATH_MSG_INFO("\n******* Data by volume/select particles *******");
98  ATH_MSG_INFO("Data printed in reverse tree order (mother following daughter)");
99 
100  TreeOut(topPV, atlasData.tTotal);
101  // for (VolIt c = v_time_index.begin(); c != v_time_index.end(); c++) {
102  // TimerPrint(*c, atlasData.tTotal, c->first.size());
103  // }
104 
105  ATH_MSG_INFO( "\n******* Data by particle/category *******");
106 
107  ATH_MSG_INFO(vPrFmt(atlasData.tElectron, m_report.nev, atlasData.tTotal, -999, "e+/-" ) );
108  ATH_MSG_INFO(vPrFmt(atlasData.tPhoton, m_report.nev, atlasData.tTotal, -999, "gamma" ) );
109  ATH_MSG_INFO(vPrFmt(atlasData.tNeutron, m_report.nev, atlasData.tTotal, -999, "neutron") );
110  ATH_MSG_INFO(vPrFmt(atlasData.tPion, m_report.nev, atlasData.tTotal, -999, "pi+/-/0") );
111  ATH_MSG_INFO(vPrFmt(atlasData.tBaryon, m_report.nev, atlasData.tTotal, -999, "baryon" ) );
112  ATH_MSG_INFO(vPrFmt(atlasData.tLepton, m_report.nev, atlasData.tTotal, -999, "lepton" ) );
113  ATH_MSG_INFO(vPrFmt(atlasData.tMeson, m_report.nev, atlasData.tTotal, -999, "meson" ) );
114  ATH_MSG_INFO(vPrFmt(atlasData.tOther, m_report.nev, atlasData.tTotal, -999, "other" ) );
115 
116  } else { ATH_MSG_WARNING("******* No events timed! *******"); }
117  } else { ATH_MSG_WARNING("******* No Timing information recorded! *******"); }
118 
119  return StatusCode::SUCCESS;
120  }
121 
122  //----------------------------------------------------------------------------
123  void TestActionVPTimerTool::TreeOut(const VolTree& id, const double tAtlas, int depth)
124  {
125  VolIt v = m_report.time_index.find(id);
126  if (v != m_report.time_index.end()) {
127  depth++;
128  for (VolIt c = m_report.time_index.begin(); c != m_report.time_index.end(); ++c) {
129  VolTree check = c->first;
130  check.pop_back();
131  if (id == check) TreeOut(c->first, tAtlas, depth);
132  }
133  TimerPrint(*v, tAtlas, depth);
134  }
135  }
136 
137  //----------------------------------------------------------------------------
138  // Prints information about time by particle type and volume (modify to suit)
139  inline void TestActionVPTimerTool::TimerPrint(std::pair<VolTree, TestActionVPTimer::volumeData> vp,
140  const double tTotal, const int depth) const
141  {
142  G4VPhysicalVolume* pv = vp.first.back().first;
143  std::string physical = stringify(pv->GetName());
144  std::string copyNo = stringify(vp.first.back().second);
145  std::string mother = "";
146  if (vp.first.size() != 1) mother = stringify( (vp.first.end()-2)->first->GetName() );
147  ATH_MSG_INFO(vPrFmt(vp.second.tTotal, m_report.nev, tTotal, depth-1, physical+"_"+copyNo+" "+mother) );
148  ATH_MSG_INFO(vPrFmt(vp.second.tElectron, m_report.nev, tTotal, depth-1, " - electrons & positrons") );
149  ATH_MSG_INFO(vPrFmt(vp.second.tPhoton, m_report.nev, tTotal, depth-1, " - photons") );
150  ATH_MSG_INFO(vPrFmt(vp.second.tNeutron, m_report.nev, tTotal, depth-1, " - neutrons") );
151  ATH_MSG_INFO(vPrFmt(vp.second.tPion, m_report.nev, tTotal, depth-1, " - pions") );
152 
153  double tOther = vp.second.tTotal - vp.second.tElectron - vp.second.tPhoton - vp.second.tNeutron - vp.second.tPion;
154  ATH_MSG_INFO(vPrFmt(tOther, m_report.nev, m_report.runTime, depth-1, " - other particles") );
155  }
156 
157 } // namespace G4UA
G4UA::TestActionVPTimer::Config::dBeam
int dBeam
Definition: TestActionVPTimer.h:60
G4UA::VolMap
std::map< VolTree, TestActionVPTimer::volumeData > VolMap
Definition: TestActionVPTimerTool.cxx:36
G4UA::G4AtlasUserActions
Struct for passing around user actions.
Definition: IUserActionTool.h:32
egammaParameters::depth
@ depth
pointing depth of the shower as calculated in egammaqgcld
Definition: egammaParamDefs.h:276
max
#define max(a, b)
Definition: cfImp.cxx:41
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
G4UA
for nSW
Definition: CalibrationDefaultProcessing.h:19
G4UA::TestActionVPTimerTool::m_report
TestActionVPTimer::Report m_report
holds data to be reported at end of run
Definition: TestActionVPTimerTool.h:44
G4UA::TestActionVPTimerTool::TimerPrint
void TimerPrint(std::pair< VolTree, TestActionVPTimer::volumeData >, const double tTotal, const int depth=0) const
Definition: TestActionVPTimerTool.cxx:139
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::TestActionVPTimerTool::m_config
TestActionVPTimer::Config m_config
holds the runtime configuration
Definition: TestActionVPTimerTool.h:42
G4UA::TestActionVPTimer::volumeData::tBaryon
double tBaryon
Time spent on other baryons in volume.
Definition: TestActionVPTimer.h:92
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::ThreadSpecificUserAction::accumulate
void accumulate(ResultType &result, Mapper mapOp, Reducer reduceOp)
Accumulate results across user actions with specified operations.
Definition: ThreadSpecificUserAction.h:88
G4UA::TestActionVPTimer::volumeData::tLepton
double tLepton
Time spent on other leptons in volume.
Definition: TestActionVPTimer.h:93
G4UA::TestActionVPTimerTool::TreeOut
void TreeOut(const VolTree &, const double tAtlas, int depth=0)
Definition: TestActionVPTimerTool.cxx:123
G4UA::vPrFmt
std::string vPrFmt(double time, double nEv, double tRun, int depth, const std::string &id)
Definition: TestActionVPTimerTool.cxx:26
G4UA::TestActionVPTimer
Definition: TestActionVPTimer.h:53
G4UA::TestActionVPTimer::volumeData
Definition: TestActionVPTimer.h:72
G4UA::TestActionVPTimer::Config::dCALO
int dCALO
Definition: TestActionVPTimer.h:59
G4UA::TestActionVPTimerTool::TestActionVPTimerTool
TestActionVPTimerTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
Definition: TestActionVPTimerTool.cxx:40
stringify
std::string stringify(T obj)
Definition: VolumeTreeNavigator.h:73
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
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
G4UA::TestActionVPTimer::volumeData::tMeson
double tMeson
Time spent on all mesons in volume.
Definition: TestActionVPTimer.h:94
G4UA::UserActionToolBase< TestActionVPTimer >::m_actions
ThreadSpecificUserAction< TestActionVPTimer > m_actions
Thread-specific storage of the user action.
Definition: UserActionToolBase.h:63
test_pyathena.parent
parent
Definition: test_pyathena.py:15
VolumeTreeNavigator.h
G4UA::TestActionVPTimer::volumeData::tNeutron
double tNeutron
Time spent on neutrons in volume.
Definition: TestActionVPTimer.h:90
G4UA::VolIt
VolMap::const_iterator VolIt
Definition: TestActionVPTimerTool.cxx:37
VolTree
std::vector< VolID > VolTree
Definition: VolumeTreeNavigator.h:36
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:194
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
G4UA::TestActionVPTimerTool::finalize
virtual StatusCode finalize() override
Triggers report merging from threads.
Definition: TestActionVPTimerTool.cxx:65
G4UA::G4AtlasUserActions::runActions
std::vector< G4UserRunAction * > runActions
Definition: IUserActionTool.h:33
LArNewCalib_Delay_OFC_Cali.check
check
Definition: LArNewCalib_Delay_OFC_Cali.py:208
TestActionVPTimerTool.h
G4UA::UserActionToolBase
abstract template utility base-class for G4 user-action tools.
Definition: UserActionToolBase.h:33
python.PyAthena.v
v
Definition: PyAthena.py:157
G4UA::TestActionVPTimer::volumeData::tOther
double tOther
Time spent on all other particles in volume (mostly nuclei)
Definition: TestActionVPTimer.h:95
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
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
python.CaloScaleNoiseConfig.action
action
Definition: CaloScaleNoiseConfig.py:77
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
python.changerun.pv
pv
Definition: changerun.py:81
G4UA::G4AtlasUserActions::eventActions
std::vector< G4UserEventAction * > eventActions
Definition: IUserActionTool.h:34
G4UA::TestActionVPTimer::Report::merge
void merge(const Report &rep)
Definition: TestActionVPTimer.h:111
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
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::G4AtlasUserActions::steppingActions
std::vector< G4UserSteppingAction * > steppingActions
Definition: IUserActionTool.h:36
python.compressB64.c
def c
Definition: compressB64.py:93
G4UA::TestActionVPTimerTool::makeAndFillAction
virtual std::unique_ptr< TestActionVPTimer > makeAndFillAction(G4AtlasUserActions &) override final
Create action for this thread.
Definition: TestActionVPTimerTool.cxx:54
G4UA::TestActionVPTimer::Report::runTime
double runTime
Double for storing this run time.
Definition: TestActionVPTimer.h:109