ATLAS Offline Software
AlgorithmTimerWrapper.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 
9 //
10 // includes
11 //
12 
14 
15 #include <EventLoop/MessageCheck.h>
16 #include <RootCoreUtils/Assert.h>
17 #include <iomanip>
18 #include <ios>
19 
20 //
21 // method implementations
22 //
23 
24 namespace EL
25 {
27  testInvariant () const
28  {
29  }
30 
31 
32 
34  AlgorithmTimerWrapper (std::unique_ptr<IAlgorithmWrapper>&& val_algorithm)
35  : m_algorithm (std::move (val_algorithm))
36  {
37  RCU_NEW_INVARIANT (this);
38  }
39 
40 
41 
42  std::string_view AlgorithmTimerWrapper ::
43  getName () const
44  {
45  RCU_READ_INVARIANT (this);
46  return m_algorithm->getName();
47  }
48 
49 
50 
52  hasName (const std::string& name) const
53  {
54  RCU_READ_INVARIANT (this);
55  return m_algorithm->hasName (name);
56  }
57 
58 
59 
60  std::unique_ptr<IAlgorithmWrapper> AlgorithmTimerWrapper ::
61  makeClone() const
62  {
63  using namespace msgEventLoop;
64  RCU_READ_INVARIANT (this);
65 
66  return std::make_unique<AlgorithmTimerWrapper> (m_algorithm->makeClone());
67  }
68 
69 
70 
73  {
74  RCU_READ_INVARIANT (this);
75  return m_algorithm->getLegacyAlg();
76  }
77 
78 
79 
81  initialize (const AlgorithmWorkerData& workerData)
82  {
83  using namespace msgEventLoop;
84  RCU_CHANGE_INVARIANT (this);
85 
86  auto start = clock_type::now();
87  auto result = m_algorithm->initialize (workerData);
88  auto stop = clock_type::now();
90  return result;
91  }
92 
93 
94 
96  execute ()
97  {
98  using namespace msgEventLoop;
99  RCU_CHANGE_INVARIANT (this);
100 
101  auto start = clock_type::now();
102  auto result = m_algorithm->execute ();
103  auto stop = clock_type::now();
104  m_time_event += stop - start;
105  return result;
106  }
107 
108 
109 
111  postExecute ()
112  {
113  using namespace msgEventLoop;
114  RCU_CHANGE_INVARIANT (this);
115 
116  auto start = clock_type::now();
117  auto result = m_algorithm->postExecute ();
118  auto stop = clock_type::now();
119  m_time_event += stop - start;
120  return result;
121  }
122 
123 
124 
126  finalize ()
127  {
128  using namespace msgEventLoop;
129  RCU_CHANGE_INVARIANT (this);
130 
131  auto start = clock_type::now();
132  auto result = m_algorithm->finalize ();
133  auto stop = clock_type::now();
134  m_time_global += stop - start;
135  auto seconds = std::chrono::duration<float>(1);
136  std::ostringstream str;
137  str << std::setprecision(2) << std::fixed << "algorithm timer: " << m_algorithm->getName() << " " << (m_time_event/seconds) << " " << (m_time_file/seconds) << " " << (m_time_global/seconds);
138  ANA_MSG_INFO (str.str());
139  return result;
140  }
141 
142 
143 
145  fileExecute ()
146  {
147  using namespace msgEventLoop;
148  RCU_CHANGE_INVARIANT (this);
149 
150  auto start = clock_type::now();
151  auto result = m_algorithm->fileExecute ();
152  auto stop = clock_type::now();
153  m_time_file += stop - start;
154  return result;
155  }
156 
157 
158 
161  {
162  using namespace msgEventLoop;
163  RCU_CHANGE_INVARIANT (this);
164 
165  auto start = clock_type::now();
166  auto result = m_algorithm->beginInputFile ();
167  auto stop = clock_type::now();
168  m_time_file += stop - start;
169  return result;
170  }
171 
172 
173 
175  endInputFile ()
176  {
177  using namespace msgEventLoop;
178  RCU_CHANGE_INVARIANT (this);
179 
180  auto start = clock_type::now();
181  auto result = m_algorithm->endInputFile ();
182  auto stop = clock_type::now();
183  m_time_file += stop - start;
184  return result;
185  }
186 }
EL::AlgorithmTimerWrapper::hasName
virtual bool hasName(const std::string &name) const override
whether this algorithm has the given name
Definition: AlgorithmTimerWrapper.cxx:52
get_generator_info.result
result
Definition: get_generator_info.py:21
EL::AlgorithmTimerWrapper::testInvariant
void testInvariant() const
test the invariant of this object
Definition: AlgorithmTimerWrapper.cxx:27
EL::AlgorithmTimerWrapper::getLegacyAlg
virtual Algorithm * getLegacyAlg() override
get the legacy algorithm, if we wrap one
Definition: AlgorithmTimerWrapper.cxx:72
EL::AlgorithmTimerWrapper::finalize
virtual StatusCode finalize() override
call finalize on the algorithm
Definition: AlgorithmTimerWrapper.cxx:126
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
AlgorithmTimerWrapper.h
EL::AlgorithmTimerWrapper::initialize
virtual StatusCode initialize(const AlgorithmWorkerData &workerData) override
call initialize on the algorithm
Definition: AlgorithmTimerWrapper.cxx:81
PixelModuleFeMask_create_db.stop
int stop
Definition: PixelModuleFeMask_create_db.py:76
EL::AlgorithmTimerWrapper::m_algorithm
std::unique_ptr< IAlgorithmWrapper > m_algorithm
the actual algorithm
Definition: AlgorithmTimerWrapper.h:82
Assert.h
MessageCheck.h
EL::AlgorithmTimerWrapper::endInputFile
virtual ::StatusCode endInputFile() override
call endInputFile on the algorithm
Definition: AlgorithmTimerWrapper.cxx:175
EL::AlgorithmTimerWrapper::getName
virtual std::string_view getName() const override
Definition: AlgorithmTimerWrapper.cxx:43
python.handimod.now
now
Definition: handimod.py:675
EL::Algorithm
Definition: Algorithm.h:22
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
EL::AlgorithmTimerWrapper::execute
virtual StatusCode execute() override
call execute on the algorithm
Definition: AlgorithmTimerWrapper.cxx:96
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
EL::AlgorithmTimerWrapper::beginInputFile
virtual ::StatusCode beginInputFile() override
call beginInputFile on the algorithm
Definition: AlgorithmTimerWrapper.cxx:160
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
EL::AlgorithmTimerWrapper::fileExecute
virtual ::StatusCode fileExecute() override
call fileExecute on the algorithm
Definition: AlgorithmTimerWrapper.cxx:145
python.LArCalib_HVCorrConfig.seconds
seconds
Definition: LArCalib_HVCorrConfig.py:86
EL::AlgorithmTimerWrapper::m_time_file
clock_type::duration m_time_file
Definition: AlgorithmTimerWrapper.h:86
EL::AlgorithmTimerWrapper::m_time_global
clock_type::duration m_time_global
the timers for different calls
Definition: AlgorithmTimerWrapper.h:85
EL::AlgorithmTimerWrapper::AlgorithmTimerWrapper
AlgorithmTimerWrapper()
standard default constructor for serialization
Definition: AlgorithmTimerWrapper.h:40
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
EL::AlgorithmWorkerData
all the external components an algorithm needs before initialization (in EventLoop)
Definition: AlgorithmWorkerData.h:34
EL::AlgorithmTimerWrapper::postExecute
virtual StatusCode postExecute() override
call postExecute on the algorithm
Definition: AlgorithmTimerWrapper.cxx:111
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
EL::AlgorithmTimerWrapper::m_time_event
clock_type::duration m_time_event
Definition: AlgorithmTimerWrapper.h:87
str
Definition: BTagTrackIpAccessor.cxx:11
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229
EL::AlgorithmTimerWrapper::makeClone
virtual std::unique_ptr< IAlgorithmWrapper > makeClone() const override
make a clone of this algorithm
Definition: AlgorithmTimerWrapper.cxx:61
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233