BOSS 6.6.4.p03
BESIII Offline Software System
Loading...
Searching...
No Matches
BesTimer Class Reference

#include <BesTimer.h>

Public Member Functions

 BesTimer (const std::string name)
 
std::string & name ()
 
float elapsed (void) const
 
double mean (void) const
 
double rms (void) const
 
int number_of_measurements (void) const
 
void propName (std::string name)
 
std::string & propName ()
 
unsigned int propVal ()
 
void propVal (unsigned int val)
 
double meanPropVal ()
 
double meanTimePerObject ()
 
bool operator< (BesTimer &it)
 
void start (void)
 
void stop (void)
 
void pause (void)
 
void resume (void)
 
void reset ()
 

Detailed Description

Definition at line 13 of file BesTimer.h.

Constructor & Destructor Documentation

◆ BesTimer()

BesTimer::BesTimer ( const std::string  name)

Definition at line 13 of file BesTimer.cxx.

14 : m_name (name) {
15 m_numberOfMeasurements = 0;
16 m_mean = 0.0;
17 m_ms = 0.0;
18 m_elapsed = 0.0;
19 m_started=false;
20 m_paused=false;
21 m_propVal = 0;
22 m_meanVal = 0;
23 m_meanTimePerObject = 0.0;
24 m_NmeanTimePerObject = 0;
25 }
std::string & name()
Definition: BesTimer.h:21

Member Function Documentation

◆ elapsed()

float BesTimer::elapsed ( void  ) const
inline

Definition at line 23 of file BesTimer.h.

23{ return (m_started? 0.0 : m_elapsed);}

Referenced by MagFieldReader::execute(), MdcFastTrkAlg::execute(), MixerAlg::execute(), and MixerAlg::nextEvent().

◆ mean()

double BesTimer::mean ( void  ) const
inline

Definition at line 25 of file BesTimer.h.

25{ return m_mean;}

◆ meanPropVal()

double BesTimer::meanPropVal ( )
inline

Definition at line 40 of file BesTimer.h.

40{ return m_meanVal;}

◆ meanTimePerObject()

double BesTimer::meanTimePerObject ( )
inline

Definition at line 41 of file BesTimer.h.

41{ return m_meanTimePerObject;}

◆ name()

std::string & BesTimer::name ( )
inline

Definition at line 21 of file BesTimer.h.

21{ return m_name; }

Referenced by operator<(), and propName().

◆ number_of_measurements()

int BesTimer::number_of_measurements ( void  ) const
inline

Definition at line 31 of file BesTimer.h.

31{ return m_numberOfMeasurements;}

◆ operator<()

bool BesTimer::operator< ( BesTimer it)
inline

Definition at line 44 of file BesTimer.h.

44{ return (this->name() < it.name());}

◆ pause()

void BesTimer::pause ( void  )

Definition at line 80 of file BesTimer.cxx.

80 {
81 struct timeval tv;
82
83 // only pause if started
84 // a pause while paused is ignored
85 if (m_paused || !m_started) return;
86 m_paused = true;
87 gettimeofday(&tv, 0);
88
89 float mtime;
90 int secs, usecs;
91
92 if (tv.tv_sec >= m_startTime.tv_sec) {
93 secs = tv.tv_sec - m_startTime.tv_sec;
94 } else {
95 secs = tv.tv_sec - m_startTime.tv_sec + SecsInDay;
96 }
97 usecs = tv.tv_usec - m_startTime.tv_usec;
98 mtime = static_cast<float>(secs)*1000. + static_cast<float>(usecs)/1000.;
99 m_elapsed += mtime; // time so far
100 }
#define SecsInDay
Definition: BesTimer.cxx:11

◆ propName() [1/2]

std::string & BesTimer::propName ( )
inline

Definition at line 35 of file BesTimer.h.

35{ return m_propName; }

◆ propName() [2/2]

void BesTimer::propName ( std::string  name)
inline

Definition at line 34 of file BesTimer.h.

34{ m_propName = name; }

Referenced by MdcFastTrkAlg::initialize(), and TrkReco::initialize().

◆ propVal() [1/2]

unsigned int BesTimer::propVal ( )
inline

Definition at line 37 of file BesTimer.h.

37{ return m_propVal;}

◆ propVal() [2/2]

void BesTimer::propVal ( unsigned int  val)
inline

Definition at line 38 of file BesTimer.h.

38{ m_propVal = val; }

◆ reset()

void BesTimer::reset ( )

Definition at line 114 of file BesTimer.cxx.

114 {
115 if (!m_started) {
116 m_elapsed = 0.0;
117 m_propVal = 0;
118 }
119 }

◆ resume()

void BesTimer::resume ( void  )

Definition at line 102 of file BesTimer.cxx.

102 {
103 struct timeval tv;
104
105 if (!m_started) {
106 start(); // resume acts as start if not started
107 } else if (m_paused) {
108 m_paused = false;
109 gettimeofday(&tv, 0);
110 m_startTime = tv;
111 }
112 }
void start(void)
Definition: BesTimer.cxx:27

◆ rms()

double BesTimer::rms ( void  ) const
inline

Definition at line 26 of file BesTimer.h.

26 {
27 double var = m_ms - m_mean*m_mean;
28 return (var > 0 ? sqrt(var) : 0.0);
29 }

◆ start()

void BesTimer::start ( void  )

Definition at line 27 of file BesTimer.cxx.

27 {
28 struct timeval tv;
29
30 m_started = true;
31 m_paused = false;
32 m_elapsed = 0.0;
33 m_propVal = 0;
34 // if already started, the start time will be over-written
35 gettimeofday(&tv, 0);
36 m_startTime = tv;
37 }

Referenced by MagFieldReader::execute(), MdcFastTrkAlg::execute(), TrkReco::execute(), MixerAlg::execute(), MixerAlg::nextEvent(), and resume().

◆ stop()

void BesTimer::stop ( void  )

Definition at line 39 of file BesTimer.cxx.

39 {
40 struct timeval tv;
41
42 if (!m_started) return;
43
44 gettimeofday(&tv, 0);
45 m_started = false;
46
47 if (!m_paused) {
48 float mtime;
49 int secs, usecs;
50
51 if (tv.tv_sec >= m_startTime.tv_sec) {
52 secs = tv.tv_sec - m_startTime.tv_sec;
53 } else {
54 secs = tv.tv_sec - m_startTime.tv_sec + SecsInDay;
55 }
56 usecs = tv.tv_usec - m_startTime.tv_usec;
57 mtime = static_cast<float>(secs)*1000. + static_cast<float>(usecs)/1000.;
58
59 // elapsed time
60 m_elapsed += mtime;
61
62 }
63
64 // statistics - mean, rms
65 double denom = static_cast <double> (++m_numberOfMeasurements);
66 double d = m_elapsed - m_mean;
67 m_mean += d / denom;
68 double dd = m_elapsed*m_elapsed - m_ms;
69 m_ms += dd / denom;
70
71 // mean property
72 m_meanVal += static_cast <double> (m_propVal - m_meanVal) / denom;
73 if (m_propVal !=0) {
74 double timePerObject = m_elapsed/static_cast <double>(m_propVal);
75 m_meanTimePerObject += static_cast <double> (timePerObject - m_meanTimePerObject) /
76 static_cast<double> (++m_NmeanTimePerObject);
77 }
78 }
double m_mean

Referenced by MagFieldReader::execute(), MdcFastTrkAlg::execute(), MixerAlg::execute(), and MixerAlg::nextEvent().


The documentation for this class was generated from the following files: