ATLAS Offline Software
Loading...
Searching...
No Matches
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
bool isPassed (time_t time, unsigned int &newinterval, unsigned int &oldinterval)
 method to know if one shoudl switch to new interval
unsigned int forcePassed (time_t time, unsigned int &oldinterval)
 method

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.

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),
12 m_duration(duration),
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}
time_t m_beginning
Definition TimeDivider.h:54
unsigned int m_intervals
Definition TimeDivider.h:50
unsigned int m_current_interval
Definition TimeDivider.h:53
bool isPassed(time_t time, unsigned int &newinterval, unsigned int &oldinterval)
method to know if one shoudl switch to new interval
unsigned int m_duration
Definition TimeDivider.h:51
time(flags, cells_name, *args, **kw)

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;
41 return true;
42 }
43 newinterval = oldinterval = m_current_interval;
44 return false;
45}
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146

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: