ATLAS Offline Software
Public Types | Public Member Functions | Private Attributes | List of all members
TimeDivider Class Reference

Helper class to divide time into intervals aligned with wall clock Once object is constructed say with arguments (6, 10, seconds) the time gets divided into 6 intervals each of 10s long. More...

#include <TimeDivider.h>

Collaboration diagram for TimeDivider:

Public Types

enum  unit { seconds, minutes }
 

Public Member Functions

 TimeDivider (unsigned int intervals, unsigned int duration, unit u)
 construct the TimeDivider More...
 
bool isPassed (time_t time, unsigned int &newinterval, unsigned int &oldinterval)
 method to know if one shoudl switch to new interval More...
 
unsigned int forcePassed (time_t time, unsigned int &oldinterval)
 method More...
 

Private Attributes

unsigned int m_intervals
 
unsigned int m_duration
 
unit m_unit
 
unsigned int m_current_interval
 
time_t m_beginning
 

Detailed Description

Helper class to divide time into intervals aligned with wall clock Once object is constructed say with arguments (6, 10, seconds) the time gets divided into 6 intervals each of 10s long.

If method isPassed is then called say for 17:00:01 it returns false and interval argument is set to 0, When next time function is called at 17:00:09 retult is the same. However if next call happens at 17:00:11 one gets return value == true and new interval == 1.

Definition at line 20 of file TimeDivider.h.

Member Enumeration Documentation

◆ unit

Enumerator
seconds 
minutes 

Definition at line 22 of file TimeDivider.h.

22 {seconds, minutes};

Constructor & Destructor Documentation

◆ TimeDivider()

TimeDivider::TimeDivider ( unsigned int  intervals,
unsigned int  duration,
unit  u 
)

construct the TimeDivider

Parameters
intervalsdefines number of intervals we want to divide time into
durationof the time interval
uis unit (either seconds or minutes)

Definition at line 10 of file TimeDivider.cxx.

11  : m_intervals(intervals),
13  m_unit(u),
15  unsigned int temp_iv;
16  time_t temp_time = time(0);
17  m_beginning = temp_time;
18  isPassed(temp_time, temp_iv, temp_iv);
19 }

Member Function Documentation

◆ forcePassed()

unsigned int TimeDivider::forcePassed ( time_t  time,
unsigned int &  oldinterval 
)

method

Parameters
timetime
intervalis interval in which we are now
Returns
true if one needs to switch to new interval

Definition at line 47 of file TimeDivider.cxx.

47  {
49  return std::max((time - m_beginning), (long int)1); // never return 0
50 }

◆ isPassed()

bool TimeDivider::isPassed ( time_t  time,
unsigned int &  newinterval,
unsigned int &  oldinterval 
)

method to know if one shoudl switch to new interval

Parameters
timetime
intervalis interval in which we are now
Returns
true if one needs to switch to new interval

Definition at line 21 of file TimeDivider.cxx.

21  {
22 
23  // convert to tm structure for seconds & minutes
24  struct tm t;
25  gmtime_r(&time, &t);
26  unsigned count = 0;
27  if (m_unit == seconds) {
28  count = t.tm_sec;
29  } else if ( m_unit == minutes ) {
30  count = t.tm_min;
31  }
32 
33  // calculate next interval
34  unsigned int iv = (count % (m_intervals*m_duration))/m_duration;
35 
36  // is new interval differnt than recently returned? If so signal it.
37  if ( m_current_interval != iv ) {
38  oldinterval = m_current_interval;
39  newinterval = m_current_interval = iv;
40  m_beginning = time;
41  return true;
42  }
43  newinterval = oldinterval = m_current_interval;
44  return false;
45 }

Member Data Documentation

◆ m_beginning

time_t TimeDivider::m_beginning
private

Definition at line 54 of file TimeDivider.h.

◆ m_current_interval

unsigned int TimeDivider::m_current_interval
private

Definition at line 53 of file TimeDivider.h.

◆ m_duration

unsigned int TimeDivider::m_duration
private

Definition at line 51 of file TimeDivider.h.

◆ m_intervals

unsigned int TimeDivider::m_intervals
private

Definition at line 50 of file TimeDivider.h.

◆ m_unit

unit TimeDivider::m_unit
private

Definition at line 52 of file TimeDivider.h.


The documentation for this class was generated from the following files:
max
#define max(a, b)
Definition: cfImp.cxx:41
TimeDivider::m_intervals
unsigned int m_intervals
Definition: TimeDivider.h:50
TimeDivider::isPassed
bool isPassed(time_t time, unsigned int &newinterval, unsigned int &oldinterval)
method to know if one shoudl switch to new interval
Definition: TimeDivider.cxx:21
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:83
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
TimeDivider::m_duration
unsigned int m_duration
Definition: TimeDivider.h:51
TimeDivider::m_beginning
time_t m_beginning
Definition: TimeDivider.h:54
getLatestRuns.interval
interval
Definition: getLatestRuns.py:24
PixelAthHitMonAlgCfg.duration
duration
Definition: PixelAthHitMonAlgCfg.py:152
TimeDivider::m_current_interval
unsigned int m_current_interval
Definition: TimeDivider.h:53
TimeDivider::seconds
@ seconds
Definition: TimeDivider.h:22
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
TimeDivider::minutes
@ minutes
Definition: TimeDivider.h:22
TimeDivider::m_unit
unit m_unit
Definition: TimeDivider.h:52