CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes | Friends
Tm Class Reference

#include <Tm.h>

Public Member Functions

struct tm c_tm () const
 
uint64_t cmsNanoSeconds () const
 
void dumpTm ()
 
uint64_t epoch () const
 
int isNull () const
 
uint64_t microsTime () const
 
bool operator!= (const Tm &t) const
 
const Tm operator+ (int seconds)
 
Tmoperator+= (int seconds)
 
Tmoperator-= (int seconds)
 
bool operator< (const Tm &t) const
 
bool operator<= (const Tm &t) const
 
bool operator== (const Tm &t) const
 
void setNull ()
 
void setToCmsNanoTime (uint64_t nanos)
 
void setToCurrentGMTime ()
 
void setToCurrentLocalTime ()
 
void setToGMTime (time_t t)
 
void setToLocalTime (time_t t)
 
void setToMicrosTime (uint64_t micros)
 
void setToString (const std::string s) noexcept(false)
 
std::string str () const
 
 Tm ()
 
 Tm (struct tm *initTm)
 
 Tm (uint64_t micros)
 
uint64_t unixTime () const
 
virtual ~Tm ()
 

Static Public Member Functions

static Tm negInfinity ()
 
static Tm plusInfinity ()
 

Private Attributes

struct tm m_tm
 

Static Private Attributes

static const uint64_t NEG_INF_MICROS = 0
 
static const uint64_t PLUS_INF_MICROS = (uint64_t)INT_MAX * 1000000
 

Friends

std::ostream & operator<< (std::ostream &out, const Tm &t)
 

Detailed Description

Definition at line 13 of file Tm.h.

Constructor & Destructor Documentation

◆ Tm() [1/3]

Tm::Tm ( )

Definition at line 24 of file Tm.cc.

24 { this->setNull(); }

Referenced by negInfinity(), and plusInfinity().

◆ Tm() [2/3]

Tm::Tm ( struct tm *  initTm)

Definition at line 27 of file Tm.cc.

27 { m_tm = *initTm; }

◆ Tm() [3/3]

Tm::Tm ( uint64_t  micros)

Definition at line 29 of file Tm.cc.

29  {
30  this->setNull();
31  if (micros > PLUS_INF_MICROS) {
32  //micros = PLUS_INF_MICROS;
33  this->setToCmsNanoTime(micros);
34  } else {
35  this->setToMicrosTime(micros);
36  }
37 }

◆ ~Tm()

Tm::~Tm ( )
virtual

Definition at line 40 of file Tm.cc.

40 {}

Member Function Documentation

◆ c_tm()

struct tm Tm::c_tm ( ) const

Definition at line 42 of file Tm.cc.

42  {
43  return m_tm;
44 }

Referenced by str(), and DateHandler::tmToDate().

◆ cmsNanoSeconds()

uint64_t Tm::cmsNanoSeconds ( ) const

Definition at line 92 of file Tm.cc.

92 { return microsTime() / 1000000 << 32; }

Referenced by popcon::EcalLaser_weekly_Handler::getNewObjects(), and popcon::EcalLaserHandler::getNewObjects().

◆ dumpTm()

void Tm::dumpTm ( )

Definition at line 204 of file Tm.cc.

204  {
205  cout << "=== dumpTm() ===" << endl;
206  cout << "tm_year " << m_tm.tm_year << endl;
207  cout << "tm_mon " << m_tm.tm_mon << endl;
208  cout << "tm_mday " << m_tm.tm_mday << endl;
209  cout << "tm_hour " << m_tm.tm_hour << endl;
210  cout << "tm_min " << m_tm.tm_min << endl;
211  cout << "tm_sec " << m_tm.tm_sec << endl;
212  cout << "tm_yday " << m_tm.tm_yday << endl;
213  cout << "tm_wday " << m_tm.tm_wday << endl;
214  cout << "tm_isdst " << m_tm.tm_isdst << endl;
215  cout << "================" << endl;
216 }

References gather_cfg::cout.

◆ epoch()

uint64_t Tm::epoch ( ) const
inline

Definition at line 58 of file Tm.h.

58 { return unixTime(); };

References unixTime().

◆ isNull()

int Tm::isNull ( ) const

Definition at line 46 of file Tm.cc.

46  {
47  if (m_tm.tm_year == 0 && m_tm.tm_mon == 0 && m_tm.tm_mday == 0) {
48  return 1;
49  } else {
50  return 0;
51  }
52 }

Referenced by DateHandler::tmToDate().

◆ microsTime()

uint64_t Tm::microsTime ( ) const

Definition at line 96 of file Tm.cc.

96  {
97  uint64_t result = 0;
98  /*
99  result += (uint64_t)ceil((m_tm.tm_year - 70 ) * 365.25) * 24 * 3600;
100  result += (m_tm.tm_yday) * 24 * 3600;
101  result += m_tm.tm_hour * 3600;
102  result += m_tm.tm_min * 60;
103  result += m_tm.tm_sec;
104  return (uint64_t) (result * 1000000);
105  */
106 
107  struct tm time_struct;
108  time_struct.tm_year = 1970 - 1900;
109  time_struct.tm_mon = 0;
110  time_struct.tm_mday = 1;
111  time_struct.tm_sec = 0;
112  time_struct.tm_min = 0;
113  time_struct.tm_hour = 0;
114  time_struct.tm_isdst = 0;
115 
116  time_t t1970 = mktime(&time_struct);
117  tm s = m_tm;
118  time_t t_this = mktime(&s);
119 
120  double x = difftime(t_this, t1970);
121  result = (uint64_t)x * 1000000;
122 
123  return result;
124 }

References mps_fire::result, alignCSCRings::s, and x.

Referenced by DataReducer< T >::getReducedDataList(), RunDCSMagnetDat::nowMicroseconds(), RunDCSLVDat::nowMicroseconds(), RunDCSHVDat::nowMicroseconds(), operator+=(), operator-=(), operator<(), operator<=(), RunDCSLVDat::setStatusForBarrel(), RunDCSHVDat::setStatusForBarrel(), RunDCSLVDat::setStatusForEndcaps(), and RunDCSHVDat::setStatusForEndcaps().

◆ negInfinity()

static Tm Tm::negInfinity ( )
inlinestatic

Definition at line 47 of file Tm.h.

47 { return Tm(NEG_INF_MICROS); };

References NEG_INF_MICROS, and Tm().

◆ operator!=()

bool Tm::operator!= ( const Tm t) const
inline

Definition at line 101 of file Tm.h.

101 { return !(t == *this); }

References OrderedSet::t.

◆ operator+()

const Tm Tm::operator+ ( int  seconds)
inline

Definition at line 113 of file Tm.h.

113  {
114  Tm ret = *this;
115  ret += seconds;
116  return ret;
117  }

References runTheMatrix::ret, and seconds().

◆ operator+=()

Tm& Tm::operator+= ( int  seconds)
inline

Definition at line 108 of file Tm.h.

108  {
110  return *this;
111  }

References microsTime(), seconds(), and setToMicrosTime().

◆ operator-=()

Tm& Tm::operator-= ( int  seconds)
inline

Definition at line 103 of file Tm.h.

103  {
105  return *this;
106  }

References microsTime(), seconds(), and setToMicrosTime().

◆ operator<()

bool Tm::operator< ( const Tm t) const
inline

Definition at line 91 of file Tm.h.

91 { return microsTime() < t.microsTime(); }

References microsTime(), and OrderedSet::t.

◆ operator<=()

bool Tm::operator<= ( const Tm t) const
inline

Definition at line 93 of file Tm.h.

93 { return microsTime() <= t.microsTime(); }

References microsTime(), and OrderedSet::t.

◆ operator==()

bool Tm::operator== ( const Tm t) const
inline

Definition at line 95 of file Tm.h.

95  {
96  return (m_tm.tm_hour == t.m_tm.tm_hour && m_tm.tm_isdst == t.m_tm.tm_isdst && m_tm.tm_mday == t.m_tm.tm_mday &&
97  m_tm.tm_min == t.m_tm.tm_min && m_tm.tm_mon == t.m_tm.tm_mon && m_tm.tm_sec == t.m_tm.tm_sec &&
98  m_tm.tm_wday == t.m_tm.tm_wday && m_tm.tm_yday == t.m_tm.tm_yday && m_tm.tm_year == t.m_tm.tm_year);
99  }

References m_tm, and OrderedSet::t.

◆ plusInfinity()

static Tm Tm::plusInfinity ( )
inlinestatic

Definition at line 45 of file Tm.h.

45 { return Tm(PLUS_INF_MICROS); };

References PLUS_INF_MICROS, and Tm().

◆ setNull()

void Tm::setNull ( )

Definition at line 54 of file Tm.cc.

54  {
55  m_tm.tm_hour = 0;
56  m_tm.tm_isdst = 0;
57  m_tm.tm_mday = 0;
58  m_tm.tm_min = 0;
59  m_tm.tm_mon = 0;
60  m_tm.tm_sec = 0;
61  m_tm.tm_wday = 0;
62  m_tm.tm_yday = 0;
63  m_tm.tm_year = 0;
64 }

Referenced by LMFSextuple::LMFSextuple().

◆ setToCmsNanoTime()

void Tm::setToCmsNanoTime ( uint64_t  nanos)

Definition at line 126 of file Tm.cc.

126 { setToMicrosTime((nanos >> 32) * 1000000); }

◆ setToCurrentGMTime()

void Tm::setToCurrentGMTime ( )

Definition at line 141 of file Tm.cc.

141  {
142  time_t t = time(nullptr);
143  m_tm = *gmtime(&t);
144 }

References OrderedSet::t, and ntuplemaker::time.

Referenced by LMFRunIOV::initialize(), RunDCSMagnetDat::nowMicroseconds(), RunDCSLVDat::nowMicroseconds(), RunDCSHVDat::nowMicroseconds(), and EcalPedOffset::writeDb().

◆ setToCurrentLocalTime()

void Tm::setToCurrentLocalTime ( )

Definition at line 136 of file Tm.cc.

136  {
137  time_t t = time(nullptr);
138  m_tm = *localtime(&t);
139 }

References OrderedSet::t, and ntuplemaker::time.

◆ setToGMTime()

void Tm::setToGMTime ( time_t  t)

Definition at line 148 of file Tm.cc.

148 { m_tm = *gmtime(&t); }

References OrderedSet::t.

Referenced by str().

◆ setToLocalTime()

void Tm::setToLocalTime ( time_t  t)

Definition at line 146 of file Tm.cc.

146 { m_tm = *localtime(&t); }

References OrderedSet::t.

◆ setToMicrosTime()

void Tm::setToMicrosTime ( uint64_t  micros)

Definition at line 128 of file Tm.cc.

128  {
129  time_t t = micros / 1000000;
130  if (t >= INT_MAX) {
131  t = INT_MAX;
132  }
133  m_tm = *gmtime(&t);
134 }

References OrderedSet::t.

Referenced by operator+=(), and operator-=().

◆ setToString()

void Tm::setToString ( const std::string  s)
noexcept

Definition at line 150 of file Tm.cc.

150  {
151  sscanf(s.c_str(),
152  "%04d-%02d-%02d %02d:%02d:%02d",
153  &m_tm.tm_year,
154  &m_tm.tm_mon,
155  &m_tm.tm_mday,
156  &m_tm.tm_hour,
157  &m_tm.tm_min,
158  &m_tm.tm_sec);
159 
160  try {
161  if (m_tm.tm_year > 9999 || m_tm.tm_year < 1900) {
162  throw(std::runtime_error("Year out of bounds"));
163  } else if (m_tm.tm_mon > 12 || m_tm.tm_mon < 1) {
164  throw(std::runtime_error("Month out of bounds"));
165  } else if (m_tm.tm_mday > 31 || m_tm.tm_mday < 1) {
166  throw(std::runtime_error("Day out of bounds"));
167  } else if (m_tm.tm_hour > 23 || m_tm.tm_mday < 0) {
168  throw(std::runtime_error("Hour out of bounds"));
169  } else if (m_tm.tm_min > 59 || m_tm.tm_min < 0) {
170  throw(std::runtime_error("Minute out of bounds"));
171  } else if (m_tm.tm_sec > 59 || m_tm.tm_sec < 0) {
172  throw(std::runtime_error("Day out of bounds"));
173  }
174 
175  if (m_tm.tm_year >= 2038) {
176  // take into account UNIX time limits
177  m_tm.tm_year = 2038;
178  if (m_tm.tm_mon > 1) {
179  m_tm.tm_mon = 1;
180  }
181  if (m_tm.tm_mday > 19) {
182  m_tm.tm_mday = 19;
183  }
184  if (m_tm.tm_hour > 3) {
185  m_tm.tm_hour = 3;
186  }
187  if (m_tm.tm_min > 14) {
188  m_tm.tm_min = 14;
189  }
190  if (m_tm.tm_sec > 7) {
191  m_tm.tm_sec = 7;
192  }
193  }
194  m_tm.tm_year -= 1900;
195  m_tm.tm_mon -= 1;
196  } catch (std::runtime_error &e) {
197  this->setNull();
198  string msg("Tm::setToString(): ");
199  msg.append(e.what());
200  throw(std::runtime_error(msg));
201  }
202 }

References MillePedeFileConverter_cfg::e, mps_check::msg, and alignCSCRings::s.

Referenced by LMFCorrCoefDat::fetchBetween(), RunDCSHVDat::fillTheMapByTime(), and LMFLmrSubIOV::getIOVIDsLaterThan().

◆ str()

string Tm::str ( ) const

"One hour shif" fix Create a temporary dummy object that is in GMT and use it to generate the output. This is to avoid the "one hour shift" related to the Summer time and the value of m_tm.tm_isdst, see [1]. It guaranties that the output is always in GMT / UTC. [1] https://hypernews.cern.ch/HyperNews/CMS/get/ecalDB/66.html

Definition at line 66 of file Tm.cc.

66  {
67  if (this->isNull()) {
68  return "";
69  }
70 
80  char timebuf[20] = "";
81  if (this->microsTime() >= PLUS_INF_MICROS) {
82  sprintf(timebuf, "9999-12-12 23:59:59");
83  } else {
84  Tm dummy_Tm;
85  dummy_Tm.setToGMTime(this->microsTime() / 1000000);
86  struct tm dummy_tm = dummy_Tm.c_tm();
87  strftime(timebuf, 20, "%Y-%m-%d %H:%M:%S", &dummy_tm);
88  }
89  return string(timebuf);
90 }

References c_tm(), setToGMTime(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by LMFSeqDat::fetchByRunNumber(), RunDCSHVDat::fillTheMapByTime(), LMFRunIOV::initialize(), EcalTPGDBApp::printIOV(), and LMFRunIOV::setSubRunEnd().

◆ unixTime()

uint64_t Tm::unixTime ( ) const

Definition at line 94 of file Tm.cc.

94 { return microsTime() / 1000000; }

Referenced by epoch().

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const Tm t 
)
friend

GO: the maximum UNIX time is restricted to INT_MAX, corresponding to 2038-01-19 03:14:07. Take it into account in str()

Definition at line 18 of file Tm.cc.

18  {
19  out << t.str();
20  return out;
21 }

Member Data Documentation

◆ m_tm

struct tm Tm::m_tm
private

Definition at line 122 of file Tm.h.

Referenced by operator==().

◆ NEG_INF_MICROS

const uint64_t Tm::NEG_INF_MICROS = 0
staticprivate

Definition at line 14 of file Tm.h.

Referenced by negInfinity().

◆ PLUS_INF_MICROS

const uint64_t Tm::PLUS_INF_MICROS = (uint64_t)INT_MAX * 1000000
staticprivate

Definition at line 16 of file Tm.h.

Referenced by plusInfinity().

runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:355
Tm::isNull
int isNull() const
Definition: Tm.cc:46
Tm::m_tm
struct tm m_tm
Definition: Tm.h:122
Tm::PLUS_INF_MICROS
static const uint64_t PLUS_INF_MICROS
Definition: Tm.h:16
gather_cfg.cout
cout
Definition: gather_cfg.py:144
Tm::Tm
Tm()
Definition: Tm.cc:24
mps_check.msg
tuple msg
Definition: mps_check.py:285
DDAxes::x
Tm::setToCmsNanoTime
void setToCmsNanoTime(uint64_t nanos)
Definition: Tm.cc:126
alignCSCRings.s
s
Definition: alignCSCRings.py:92
Tm::setToMicrosTime
void setToMicrosTime(uint64_t micros)
Definition: Tm.cc:128
seconds
double seconds()
Tm::NEG_INF_MICROS
static const uint64_t NEG_INF_MICROS
Definition: Tm.h:14
Tm::setToGMTime
void setToGMTime(time_t t)
Definition: Tm.cc:148
OrderedSet.t
t
Definition: OrderedSet.py:90
Tm
Definition: Tm.h:13
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Tm::unixTime
uint64_t unixTime() const
Definition: Tm.cc:94
Tm::microsTime
uint64_t microsTime() const
Definition: Tm.cc:96
Tm::setNull
void setNull()
Definition: Tm.cc:54
Tm::c_tm
struct tm c_tm() const
Definition: Tm.cc:42
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
mps_fire.result
result
Definition: mps_fire.py:303
ntuplemaker.time
time
Definition: ntuplemaker.py:310
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37