ATLAS Offline Software
JetTrigTimer.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "./JetTrigTimer.h"
6 #include <cassert>
7 
8 #include <sstream>
9 
10 
11 using namespace std::chrono;
12 
13 JetTrigTimer::JetTrigTimer(bool ns): m_nanoseconds(ns) {}
14 
16  // reset start time to now
17 
18  m_nCalls += 1;
20 }
21 
23  // reset stop time to now, calculate delta and sum delta.
24  // does not change the start time
25 
27  if(m_nanoseconds){
28  m_elapsedDelta += duration_cast<nanoseconds>(m_stop - m_start).count();
29  } else {
30  m_elapsedDelta += duration_cast<microseconds>(m_stop - m_start).count();
31  }
32 }
33 
34 
35 void JetTrigTimer::reset() noexcept {
36  // general reset
37 
38  m_nCalls = 0;
39  m_elapsedDelta = 0.;
40  m_nCalls = 0;
42  m_stop = m_start;
43 }
44 
45 std::string JetTrigTimer::read() const{
46  // reuturn curent data as a string
47 
48  auto record = read_bare();
49  auto delta = std::get<0>(record);
50  auto ncalls = std::get<1>(record);
51  auto units = std::get<2>(record);
52 
53  std::stringstream ss;
54  double avTime = ncalls == 0 ? 0. : delta / m_nCalls;
55  ss << "time("<<units <<"): " << delta << " nCalls: " << ncalls << " tav: "
56  << avTime;
57  return ss.str();
58 }
59 
60 std::tuple<double, int, std::string> JetTrigTimer::read_bare() const{
61  // reuturn curent data in numeric form
62 
63  return std::make_tuple(m_elapsedDelta, m_nCalls, units());
64 }
65 
67  // obtain current data as a string then reset the timer
68  auto s = read();
69  reset();
70  return s;
71 }
72 
73 
75  update();
77  return m_elapsedDelta;
78 }
79 
81  // update the current data, return the time since start()
82  return m_elapsedDelta;
83 }
84 
85 
86 std::string JetTrigTimer::units() const {
87  return m_nanoseconds ? "ns" : "us";
88 }
89 
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
JetTrigTimer::JetTrigTimer
JetTrigTimer(bool nanoseconds=false)
Definition: JetTrigTimer.cxx:13
JetTrigTimer::elapsed_to_update
double elapsed_to_update()
Definition: JetTrigTimer.cxx:80
JetTrigTimer::read_bare
std::tuple< double, int, std::string > read_bare() const
Definition: JetTrigTimer.cxx:60
JetTrigTimer::readAndReset
std::string readAndReset()
Definition: JetTrigTimer.cxx:66
JetTrigTimer::m_nCalls
std::size_t m_nCalls
Definition: JetTrigTimer.h:28
JetTrigTimer::read
std::string read() const
Definition: JetTrigTimer.cxx:45
JetTrigTimer::m_stop
std::chrono::system_clock::time_point m_stop
Definition: JetTrigTimer.h:30
JetTrigTimer::m_start
std::chrono::system_clock::time_point m_start
Definition: JetTrigTimer.h:29
JetTrigTimer::units
std::string units() const
Definition: JetTrigTimer.cxx:86
JetTrigTimer::update
void update()
Definition: JetTrigTimer.cxx:22
python.handimod.now
now
Definition: handimod.py:675
JetTrigTimer::elapsed_to_now
double elapsed_to_now()
Definition: JetTrigTimer.cxx:74
JetTrigTimer::m_elapsedDelta
double m_elapsedDelta
Definition: JetTrigTimer.h:32
JetTrigTimer.h
JetTrigTimer::reset
void reset() noexcept
Definition: JetTrigTimer.cxx:35
JetTrigTimer::m_nanoseconds
bool m_nanoseconds
Definition: JetTrigTimer.h:33
python.SystemOfUnits.ns
int ns
Definition: SystemOfUnits.py:130
JetTrigTimer::start
void start()
Definition: JetTrigTimer.cxx:15