ATLAS Offline Software
Loading...
Searching...
No Matches
JetTrigTimer.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "./JetTrigTimer.h"
6#include <cassert>
7
8#include <sstream>
9
10
11using namespace std::chrono;
12
14
16 // reset start time to now
17
18 m_nCalls += 1;
19 m_start = system_clock::now();
20}
21
23 // reset stop time to now, calculate delta and sum delta.
24 // does not change the start time
25
26 m_stop = system_clock::now();
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
35void JetTrigTimer::reset() noexcept {
36 // general reset
37
38 m_nCalls = 0;
39 m_elapsedDelta = 0.;
40 m_nCalls = 0;
41 m_start = std::chrono::system_clock::now();
43}
44
45std::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 const 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
60std::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();
76 m_start = system_clock::now();
77 return m_elapsedDelta;
78}
79
81 // update the current data, return the time since start()
82 return m_elapsedDelta;
83}
84
85
86std::string JetTrigTimer::units() const {
87 return m_nanoseconds ? "ns" : "us";
88}
89
static Double_t ss
std::string readAndReset()
std::string units() const
double m_elapsedDelta
std::string read() const
JetTrigTimer(bool nanoseconds=false)
std::size_t m_nCalls
std::chrono::system_clock::time_point m_start
double elapsed_to_update()
std::chrono::system_clock::time_point m_stop
void reset() noexcept
double elapsed_to_now()
std::tuple< double, int, std::string > read_bare() const