CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes
Tm Class Reference

#include <Tm.h>

Public Member Functions

struct tm c_tm () const
 
void dumpTm ()
 
int isNull () const
 
uint64_t microsTime () const
 
bool operator!= (const Tm &t) const
 
Tmoperator+= (int seconds)
 
Tmoperator-= (int seconds)
 
bool operator== (const Tm &t) const
 
void setNull ()
 
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) throw (std::runtime_error)
 
std::string str () const
 
 Tm ()
 
 Tm (struct tm *initTm)
 
 Tm (uint64_t micros)
 
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
 

Detailed Description

Definition at line 14 of file Tm.h.

Constructor & Destructor Documentation

Tm::Tm ( )

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 19 of file Tm.cc.

Referenced by negInfinity(), and plusInfinity().

20 {
21  this->setNull();
22 }
void setNull()
Definition: Tm.cc:67
Tm::Tm ( struct tm *  initTm)

Definition at line 27 of file Tm.cc.

28 {
29  m_tm = *initTm;
30 }
struct tm m_tm
Definition: Tm.h:116
Tm::Tm ( uint64_t  micros)

Definition at line 32 of file Tm.cc.

33 {
34  this->setNull();
35  if (micros > PLUS_INF_MICROS) {
36  micros = PLUS_INF_MICROS;
37  }
38  this->setToMicrosTime(micros);
39 }
void setToMicrosTime(uint64_t micros)
Definition: Tm.cc:141
static const uint64_t PLUS_INF_MICROS
Definition: Tm.h:17
void setNull()
Definition: Tm.cc:67
Tm::~Tm ( )
virtual

Definition at line 43 of file Tm.cc.

44 {
45 }

Member Function Documentation

struct tm Tm::c_tm ( ) const

Definition at line 49 of file Tm.cc.

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

50 {
51  return m_tm;
52 }
struct tm m_tm
Definition: Tm.h:116
void Tm::dumpTm ( )

Definition at line 223 of file Tm.cc.

References gather_cfg::cout.

224 {
225  cout << "=== dumpTm() ===" << endl;
226  cout << "tm_year " << m_tm.tm_year << endl;
227  cout << "tm_mon " << m_tm.tm_mon << endl;
228  cout << "tm_mday " << m_tm.tm_mday << endl;
229  cout << "tm_hour " << m_tm.tm_hour << endl;
230  cout << "tm_min " << m_tm.tm_min << endl;
231  cout << "tm_sec " << m_tm.tm_sec << endl;
232  cout << "tm_yday " << m_tm.tm_yday << endl;
233  cout << "tm_wday " << m_tm.tm_wday << endl;
234  cout << "tm_isdst " << m_tm.tm_isdst << endl;
235  cout << "================" << endl;
236 }
tuple cout
Definition: gather_cfg.py:41
struct tm m_tm
Definition: Tm.h:116
int Tm::isNull ( ) const

Definition at line 56 of file Tm.cc.

Referenced by DateHandler::tmToDate().

57 {
58  if (m_tm.tm_year == 0
59  && m_tm.tm_mon == 0
60  && m_tm.tm_mday == 0 ) {
61  return 1;
62  } else { return 0; }
63 }
struct tm m_tm
Definition: Tm.h:116
uint64_t Tm::microsTime ( ) const

Definition at line 109 of file Tm.cc.

References query::result, asciidump::s, and x.

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

110 {
111  uint64_t result = 0;
112  /*
113  result += (uint64_t)ceil((m_tm.tm_year - 70 ) * 365.25) * 24 * 3600;
114  result += (m_tm.tm_yday) * 24 * 3600;
115  result += m_tm.tm_hour * 3600;
116  result += m_tm.tm_min * 60;
117  result += m_tm.tm_sec;
118  return (uint64_t) (result * 1000000);
119  */
120 
121  struct tm time_struct;
122  time_struct.tm_year=1970-1900;
123  time_struct.tm_mon=0;
124  time_struct.tm_mday=1;
125  time_struct.tm_sec=0;
126  time_struct.tm_min=0;
127  time_struct.tm_hour=0;
128  time_struct.tm_isdst=0;
129 
130  time_t t1970=mktime(&time_struct);
131  tm s = m_tm;
132  time_t t_this=mktime(&s);
133 
134  double x= difftime(t_this,t1970);
135  result =(uint64_t) x*1000000;
136 
137  return result;
138 
139 }
tuple result
Definition: query.py:137
unsigned long long uint64_t
Definition: Time.h:15
string s
Definition: asciidump.py:422
Definition: DDAxes.h:10
struct tm m_tm
Definition: Tm.h:116
static Tm Tm::negInfinity ( )
inlinestatic

Definition at line 53 of file Tm.h.

References NEG_INF_MICROS, and Tm().

54  {
55  return Tm(NEG_INF_MICROS);
56  };
static const uint64_t NEG_INF_MICROS
Definition: Tm.h:15
Tm()
Definition: Tm.cc:19
bool Tm::operator!= ( const Tm t) const
inline

Definition at line 104 of file Tm.h.

104 { return !(t == *this); }
Tm& Tm::operator+= ( int  seconds)
inline

Definition at line 110 of file Tm.h.

References microsTime(), and setToMicrosTime().

110  {
112  return *this;
113  }
double seconds()
uint64_t microsTime() const
Definition: Tm.cc:109
void setToMicrosTime(uint64_t micros)
Definition: Tm.cc:141
Tm& Tm::operator-= ( int  seconds)
inline

Definition at line 106 of file Tm.h.

References microsTime(), and setToMicrosTime().

106  {
108  return *this;
109  }
double seconds()
uint64_t microsTime() const
Definition: Tm.cc:109
void setToMicrosTime(uint64_t micros)
Definition: Tm.cc:141
bool Tm::operator== ( const Tm t) const
inline

Definition at line 92 of file Tm.h.

References m_tm.

93  { return (m_tm.tm_hour == t.m_tm.tm_hour &&
94  m_tm.tm_isdst == t.m_tm.tm_isdst &&
95  m_tm.tm_mday == t.m_tm.tm_mday &&
96  m_tm.tm_min == t.m_tm.tm_min &&
97  m_tm.tm_mon == t.m_tm.tm_mon &&
98  m_tm.tm_sec == t.m_tm.tm_sec &&
99  m_tm.tm_wday == t.m_tm.tm_wday &&
100  m_tm.tm_yday == t.m_tm.tm_yday &&
101  m_tm.tm_year == t.m_tm.tm_year);
102  }
struct tm m_tm
Definition: Tm.h:116
static Tm Tm::plusInfinity ( )
inlinestatic

Definition at line 47 of file Tm.h.

References PLUS_INF_MICROS, and Tm().

Referenced by LMFSeqDat::LMFSeqDat().

48  {
49  return Tm(PLUS_INF_MICROS);
50  };
static const uint64_t PLUS_INF_MICROS
Definition: Tm.h:17
Tm()
Definition: Tm.cc:19
void Tm::setNull ( )

Definition at line 67 of file Tm.cc.

68 {
69  m_tm.tm_hour = 0;
70  m_tm.tm_isdst = 0;
71  m_tm.tm_mday = 0;
72  m_tm.tm_min = 0;
73  m_tm.tm_mon = 0;
74  m_tm.tm_sec = 0;
75  m_tm.tm_wday = 0;
76  m_tm.tm_yday = 0;
77  m_tm.tm_year = 0;
78 }
struct tm m_tm
Definition: Tm.h:116
void Tm::setToCurrentGMTime ( )
void Tm::setToCurrentLocalTime ( )

Definition at line 150 of file Tm.cc.

References NULL, matplotRender::t, and cond::rpcobgas::time.

151 {
152  time_t t = time(NULL);
153  m_tm = *localtime( &t );
154 }
#define NULL
Definition: scimark2.h:8
struct tm m_tm
Definition: Tm.h:116
void Tm::setToGMTime ( time_t  t)

Definition at line 167 of file Tm.cc.

Referenced by str().

168 {
169  m_tm = *gmtime( &t );
170 }
struct tm m_tm
Definition: Tm.h:116
void Tm::setToLocalTime ( time_t  t)

Definition at line 162 of file Tm.cc.

163 {
164  m_tm = *localtime( &t );
165 }
struct tm m_tm
Definition: Tm.h:116
void Tm::setToMicrosTime ( uint64_t  micros)

Definition at line 141 of file Tm.cc.

References matplotRender::t.

Referenced by popcon::EcalLaserHandler::getNewObjects(), operator+=(), and operator-=().

142 {
143  time_t t = micros / 1000000;
144  if (t >= INT_MAX) {
145  t = INT_MAX;
146  }
147  m_tm = *gmtime(&t);
148 }
struct tm m_tm
Definition: Tm.h:116
void Tm::setToString ( const std::string  s)
throw (std::runtime_error
)

Definition at line 172 of file Tm.cc.

References runTheMatrix::msg, and asciidump::s.

Referenced by LMFCorrCoefDat::fetchAfter(), LMFCorrCoefDat::fetchBetween(), RunDCSHVDat::fillTheMapByTime(), LMFRunIOV::getDBInsertionTime(), LMFLmrSubIOV::getIOVIDsLaterThan(), popcon::EcalLaserHandler::getNewObjects(), LMFLmrSubIOV::getParameters(), LMFSeqDat::getSequenceStart(), LMFSeqDat::getSequenceStop(), LMFRunIOV::getSubRunEnd(), and LMFRunIOV::getSubRunStart().

174 {
175  sscanf(s.c_str(), "%04d-%02d-%02d %02d:%02d:%02d",
176  &m_tm.tm_year, &m_tm.tm_mon, &m_tm.tm_mday,
177  &m_tm.tm_hour, &m_tm.tm_min, &m_tm.tm_sec);
178 
179  try {
180  if (m_tm.tm_year > 9999 || m_tm.tm_year < 1900) {
181  throw(std::runtime_error("Year out of bounds"));
182  } else if (m_tm.tm_mon > 12 || m_tm.tm_mon < 1) {
183  throw(std::runtime_error("Month out of bounds"));
184  } else if (m_tm.tm_mday > 31 || m_tm.tm_mday < 1) {
185  throw(std::runtime_error("Day out of bounds"));
186  } else if (m_tm.tm_hour > 23 || m_tm.tm_mday < 0) {
187  throw(std::runtime_error("Hour out of bounds"));
188  } else if (m_tm.tm_min > 59 || m_tm.tm_min < 0) {
189  throw(std::runtime_error("Minute out of bounds"));
190  } else if (m_tm.tm_sec > 59 || m_tm.tm_sec < 0) {
191  throw(std::runtime_error("Day out of bounds"));
192  }
193 
194  if (m_tm.tm_year >= 2038) {
195  // take into account UNIX time limits
196  m_tm.tm_year = 2038;
197  if (m_tm.tm_mon > 1) {
198  m_tm.tm_mon = 1;
199  }
200  if (m_tm.tm_mday > 19) {
201  m_tm.tm_mday = 19;
202  }
203  if (m_tm.tm_hour > 3) {
204  m_tm.tm_hour = 3;
205  }
206  if (m_tm.tm_min > 14) {
207  m_tm.tm_min = 14;
208  }
209  if (m_tm.tm_sec > 7) {
210  m_tm.tm_sec = 7;
211  }
212  }
213  m_tm.tm_year -= 1900;
214  m_tm.tm_mon -= 1;
215  } catch (std::runtime_error &e) {
216  this->setNull();
217  string msg("Tm::setToString(): ");
218  msg.append(e.what());
219  throw(std::runtime_error(msg));
220  }
221 }
string s
Definition: asciidump.py:422
void setNull()
Definition: Tm.cc:67
struct tm m_tm
Definition: Tm.h:116
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 82 of file Tm.cc.

References c_tm(), and setToGMTime().

Referenced by LMFCorrCoefDat::fetchBetween(), LMFSeqDat::fetchByRunNumber(), RunDCSHVDat::fillTheMapByTime(), LMFCorrCoefDat::getCorrections(), popcon::EcalLaserHandler::getNewObjects(), LMFRunIOV::getParameters(), LMFSeqDat::getParameters(), DataReducer< T >::getReducedDataList(), LMFRunIOV::initialize(), LMFSeqDat::LMFSeqDat(), EcalTPGDBApp::printIOV(), LMFUnique::sequencePostfix(), LMFSeqDat::setSequenceStart(), LMFSeqDat::setSequenceStop(), LMFRunIOV::setSubRunEnd(), and LMFRunIOV::setSubRunStart().

83 {
84  if (this->isNull()) {
85  return "";
86  }
87 
97  char timebuf[20] = "";
98  if (this->microsTime() >= PLUS_INF_MICROS) {
99  sprintf(timebuf, "9999-12-12 23:59:59");
100  } else {
101  Tm dummy_Tm;
102  dummy_Tm.setToGMTime(this->microsTime()/1000000);
103  struct tm dummy_tm = dummy_Tm.c_tm();
104  strftime(timebuf, 20, "%Y-%m-%d %H:%M:%S", &dummy_tm);
105  }
106  return string(timebuf);
107 }
struct tm c_tm() const
Definition: Tm.cc:49
uint64_t microsTime() const
Definition: Tm.cc:109
void setToGMTime(time_t t)
Definition: Tm.cc:167
int isNull() const
Definition: Tm.cc:56
static const uint64_t PLUS_INF_MICROS
Definition: Tm.h:17
Definition: Tm.h:14

Member Data Documentation

struct tm Tm::m_tm
private

Definition at line 116 of file Tm.h.

Referenced by operator==().

const uint64_t Tm::NEG_INF_MICROS = 0
staticprivate

Definition at line 15 of file Tm.h.

Referenced by negInfinity().

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

Definition at line 17 of file Tm.h.

Referenced by plusInfinity().