ATLAS Offline Software
AlgorithmTimer.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 ATHENAKERNEL_ALGORITHMTIMER_H
6 #define ATHENAKERNEL_ALGORITHMTIMER_H
7 
16 // Framework includes
17 #include "GaudiKernel/ServiceHandle.h"
18 
19 // System includes
20 #include <time.h>
21 #include <signal.h>
22 #ifdef __APPLE__
23 #include <sys/signal.h>
24 #include <sys/time.h>
25 #endif
26 
27 // STL includes
28 #include <functional>
29 #include <string>
30 #include <list>
31 
32 #ifdef __APPLE__
33 typedef sigval sigval_t;
34 typedef itimerval timer_t;
35 #endif //MacOSX
36 
37 namespace Athena {
38 
39  //forward declarations
40  class ScopedTimer;
41 
42  namespace AlgorithmTimerHandler
43  {
44  void onAlarmThread(sigval_t sv);
45  }
46 
87  {
89 
90  public:
91 
96  {
97  DEFAULT = 0x0,
98  USEREALTIME = 0x1,
99  };
100 
101  typedef std::function<void()> callbackFct_t;
102 
109  AlgorithmTimer(unsigned int milliseconds,
110  callbackFct_t callback = NULL,
112 
116  ~AlgorithmTimer();
117 
121  void start() { start(m_timeout); }
122 
127  void start(unsigned int milliseconds);
128 
133  void start(ScopedTimer& scope);
134 
138  unsigned int stop();
139 
143  unsigned int timeLeft() const;
144 
148  unsigned int timeout() const { return m_timeout; }
149 
153  void SetGDBCoreDumpDetails(unsigned int details)
154  { m_gdb_details = details; };
155 
156  protected:
157 
158  unsigned int m_timeout;
159  struct sigevent m_sigevent;
160  timer_t m_timerid;
162  std::atomic_bool m_active;
163 
164 
165  private:
166  // Dummies
170 
172 
173  unsigned int m_gdb_details;
174  };
175 
176 
182  class ScopedTimer {
183  friend class AlgorithmTimer;
184  public:
185  ScopedTimer(unsigned int milliseconds) : m_timeout(milliseconds), m_timer(0) {}
187  private:
188  unsigned int m_timeout;
190  };
191 
192 } // namespace Athena
193 
194 #endif
Athena::AlgorithmTimer::abortJob
callbackFct_t abortJob()
Definition: AlgorithmTimer.cxx:166
Athena::AlgorithmTimer::AlgorithmTimerConfig
AlgorithmTimerConfig
Configuration flags for AlgorithmTimer.
Definition: AlgorithmTimer.h:96
python.compareTCTs.details
details
Definition: compareTCTs.py:214
02DownloadFromGrid.scope
string scope
Definition: 02DownloadFromGrid.py:6
Athena::ScopedTimer
Helper class to create a "scoped cook timer" without having to declare the CookTimer itself within th...
Definition: AlgorithmTimer.h:182
Athena::AlgorithmTimer::m_timeout
unsigned int m_timeout
timeout in milliseconds
Definition: AlgorithmTimer.h:154
Athena::AlgorithmTimer::m_timerid
timer_t m_timerid
timer ID
Definition: AlgorithmTimer.h:160
Athena::AlgorithmTimer::AlgorithmTimer
AlgorithmTimer(const AlgorithmTimer &)
no copying allowed
Athena::AlgorithmTimer::m_gdb_details
unsigned int m_gdb_details
Definition: AlgorithmTimer.h:173
runLayerRecalibration.callback
callback
Definition: runLayerRecalibration.py:64
Athena::AlgorithmTimer::timeLeft
unsigned int timeLeft() const
Returns the time left in milliseconds.
Definition: AlgorithmTimer.cxx:155
Athena::AlgorithmTimer::DEFAULT
@ DEFAULT
default
Definition: AlgorithmTimer.h:97
Athena::AlgorithmTimer::USEREALTIME
@ USEREALTIME
use real time instead of system time
Definition: AlgorithmTimer.h:98
python.ConfigurableDb.conf
def conf
Definition: ConfigurableDb.py:282
Athena::AlgorithmTimer::stop
unsigned int stop()
Stop the timer and return the time left in [ms].
Definition: AlgorithmTimer.cxx:136
Athena::AlgorithmTimerHandler::onAlarmThread
void onAlarmThread(sigval_t sv)
Function called by signals delivered via threads.
Definition: AlgorithmTimer.cxx:42
Athena::AlgorithmTimer::timeout
unsigned int timeout() const
Returns the currently set timeout (in milliseconds)
Definition: AlgorithmTimer.h:148
Athena
Some weak symbol referencing magic...
Definition: AthLegacySequence.h:21
Athena::ScopedTimer::m_timer
AlgorithmTimer * m_timer
AlgorithmTimer instance, set by AlgorithmTimer::start()
Definition: AlgorithmTimer.h:189
Athena::ScopedTimer::m_timeout
unsigned int m_timeout
Timeout in milliseconds.
Definition: AlgorithmTimer.h:188
Athena::AlgorithmTimer::AlgorithmTimer
AlgorithmTimer()
no default constructor
Athena::AlgorithmTimer::start
void start()
(Re)start the timer with the last timeout used
Definition: AlgorithmTimer.h:121
Athena::AlgorithmTimer::callbackFct_t
std::function< void()> callbackFct_t
Definition: AlgorithmTimer.h:101
Athena::ScopedTimer::~ScopedTimer
~ScopedTimer()
Definition: AlgorithmTimer.h:186
Athena::AlgorithmTimer::operator=
AlgorithmTimer & operator=(const AlgorithmTimer &)
no copying allowed
Athena::AlgorithmTimer::m_active
std::atomic_bool m_active
flag protecting race condition at stop
Definition: AlgorithmTimer.h:162
Athena::ScopedTimer::ScopedTimer
ScopedTimer(unsigned int milliseconds)
Definition: AlgorithmTimer.h:185
Athena::AlgorithmTimer::SetGDBCoreDumpDetails
void SetGDBCoreDumpDetails(unsigned int details)
set the levelof details for (optional) gdb core dump
Definition: AlgorithmTimer.h:153
Athena::AlgorithmTimer::m_onAlarm
callbackFct_t m_onAlarm
user callback
Definition: AlgorithmTimer.h:161
LArCellConditions.sv
bool sv
Definition: LArCellConditions.py:45
Athena::AlgorithmTimer::~AlgorithmTimer
~AlgorithmTimer()
Destroy and disable the timer.
Definition: AlgorithmTimer.cxx:106
Athena::AlgorithmTimer::m_sigevent
struct sigevent m_sigevent
for signal handler
Definition: AlgorithmTimer.h:159
Athena::AlgorithmTimer
Timer that invokes a user callback once the time is reached.
Definition: AlgorithmTimer.h:87