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 | 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) throw (std::runtime_error)
 
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::Tm ( )

Definition at line 24 of file Tm.cc.

Referenced by negInfinity(), and plusInfinity().

25 {
26  this->setNull();
27 }
void setNull()
Definition: Tm.cc:74
Tm::Tm ( struct tm *  initTm)

Definition at line 32 of file Tm.cc.

33 {
34  m_tm = *initTm;
35 }
struct tm m_tm
Definition: Tm.h:142
Tm::Tm ( uint64_t  micros)

Definition at line 37 of file Tm.cc.

38 {
39  this->setNull();
40  if (micros > PLUS_INF_MICROS) {
41  //micros = PLUS_INF_MICROS;
42  this->setToCmsNanoTime(micros);
43  } else {
44  this->setToMicrosTime(micros);
45  }
46 }
void setToMicrosTime(uint64_t micros)
Definition: Tm.cc:162
void setToCmsNanoTime(uint64_t nanos)
Definition: Tm.cc:158
static const uint64_t PLUS_INF_MICROS
Definition: Tm.h:16
void setNull()
Definition: Tm.cc:74
Tm::~Tm ( )
virtual

Definition at line 50 of file Tm.cc.

51 {
52 }

Member Function Documentation

struct tm Tm::c_tm ( ) const

Definition at line 56 of file Tm.cc.

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

57 {
58  return m_tm;
59 }
struct tm m_tm
Definition: Tm.h:142
uint64_t Tm::cmsNanoSeconds ( ) const

Definition at line 116 of file Tm.cc.

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

117 {
118  return microsTime()/1000000 << 32;
119 }
uint64_t microsTime() const
Definition: Tm.cc:126
void Tm::dumpTm ( )

Definition at line 244 of file Tm.cc.

References gather_cfg::cout.

245 {
246  cout << "=== dumpTm() ===" << endl;
247  cout << "tm_year " << m_tm.tm_year << endl;
248  cout << "tm_mon " << m_tm.tm_mon << endl;
249  cout << "tm_mday " << m_tm.tm_mday << endl;
250  cout << "tm_hour " << m_tm.tm_hour << endl;
251  cout << "tm_min " << m_tm.tm_min << endl;
252  cout << "tm_sec " << m_tm.tm_sec << endl;
253  cout << "tm_yday " << m_tm.tm_yday << endl;
254  cout << "tm_wday " << m_tm.tm_wday << endl;
255  cout << "tm_isdst " << m_tm.tm_isdst << endl;
256  cout << "================" << endl;
257 }
tuple cout
Definition: gather_cfg.py:121
struct tm m_tm
Definition: Tm.h:142
uint64_t Tm::epoch ( ) const
inline

Definition at line 66 of file Tm.h.

References unixTime().

66 { return unixTime(); };
uint64_t unixTime() const
Definition: Tm.cc:121
int Tm::isNull ( ) const

Definition at line 63 of file Tm.cc.

Referenced by DateHandler::tmToDate().

64 {
65  if (m_tm.tm_year == 0
66  && m_tm.tm_mon == 0
67  && m_tm.tm_mday == 0 ) {
68  return 1;
69  } else { return 0; }
70 }
struct tm m_tm
Definition: Tm.h:142
uint64_t Tm::microsTime ( ) const

Definition at line 126 of file Tm.cc.

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

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

127 {
128  uint64_t result = 0;
129  /*
130  result += (uint64_t)ceil((m_tm.tm_year - 70 ) * 365.25) * 24 * 3600;
131  result += (m_tm.tm_yday) * 24 * 3600;
132  result += m_tm.tm_hour * 3600;
133  result += m_tm.tm_min * 60;
134  result += m_tm.tm_sec;
135  return (uint64_t) (result * 1000000);
136  */
137 
138  struct tm time_struct;
139  time_struct.tm_year=1970-1900;
140  time_struct.tm_mon=0;
141  time_struct.tm_mday=1;
142  time_struct.tm_sec=0;
143  time_struct.tm_min=0;
144  time_struct.tm_hour=0;
145  time_struct.tm_isdst=0;
146 
147  time_t t1970=mktime(&time_struct);
148  tm s = m_tm;
149  time_t t_this=mktime(&s);
150 
151  double x= difftime(t_this,t1970);
152  result =(uint64_t) x*1000000;
153 
154  return result;
155 
156 }
tuple result
Definition: query.py:137
unsigned long long uint64_t
Definition: Time.h:15
Definition: DDAxes.h:10
struct tm m_tm
Definition: Tm.h:142
static Tm Tm::negInfinity ( )
inlinestatic

Definition at line 52 of file Tm.h.

References NEG_INF_MICROS, and Tm().

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

Definition at line 121 of file Tm.h.

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

Definition at line 133 of file Tm.h.

References run_regression::ret, and seconds().

133  {
134  Tm ret = *this;
135  ret += seconds;
136  return ret;
137  }
double seconds()
Definition: Tm.h:13
Tm& Tm::operator+= ( int  seconds)
inline

Definition at line 128 of file Tm.h.

References microsTime(), and setToMicrosTime().

128  {
130  return *this;
131  }
double seconds()
uint64_t microsTime() const
Definition: Tm.cc:126
void setToMicrosTime(uint64_t micros)
Definition: Tm.cc:162
Tm& Tm::operator-= ( int  seconds)
inline

Definition at line 123 of file Tm.h.

References microsTime(), and setToMicrosTime().

123  {
125  return *this;
126  }
double seconds()
uint64_t microsTime() const
Definition: Tm.cc:126
void setToMicrosTime(uint64_t micros)
Definition: Tm.cc:162
bool Tm::operator< ( const Tm t) const
inline

Definition at line 99 of file Tm.h.

References microsTime().

100  {
101  return microsTime() < t.microsTime();
102  }
uint64_t microsTime() const
Definition: Tm.cc:126
bool Tm::operator<= ( const Tm t) const
inline

Definition at line 104 of file Tm.h.

References microsTime().

105  {
106  return microsTime() <= t.microsTime();
107  }
uint64_t microsTime() const
Definition: Tm.cc:126
bool Tm::operator== ( const Tm t) const
inline

Definition at line 109 of file Tm.h.

References m_tm.

110  { return (m_tm.tm_hour == t.m_tm.tm_hour &&
111  m_tm.tm_isdst == t.m_tm.tm_isdst &&
112  m_tm.tm_mday == t.m_tm.tm_mday &&
113  m_tm.tm_min == t.m_tm.tm_min &&
114  m_tm.tm_mon == t.m_tm.tm_mon &&
115  m_tm.tm_sec == t.m_tm.tm_sec &&
116  m_tm.tm_wday == t.m_tm.tm_wday &&
117  m_tm.tm_yday == t.m_tm.tm_yday &&
118  m_tm.tm_year == t.m_tm.tm_year);
119  }
struct tm m_tm
Definition: Tm.h:142
static Tm Tm::plusInfinity ( )
inlinestatic

Definition at line 46 of file Tm.h.

References PLUS_INF_MICROS, and Tm().

Referenced by LMFSeqDat::LMFSeqDat().

47  {
48  return Tm(PLUS_INF_MICROS);
49  };
static const uint64_t PLUS_INF_MICROS
Definition: Tm.h:16
Tm()
Definition: Tm.cc:24
void Tm::setNull ( )

Definition at line 74 of file Tm.cc.

Referenced by LMFSextuple::LMFSextuple().

75 {
76  m_tm.tm_hour = 0;
77  m_tm.tm_isdst = 0;
78  m_tm.tm_mday = 0;
79  m_tm.tm_min = 0;
80  m_tm.tm_mon = 0;
81  m_tm.tm_sec = 0;
82  m_tm.tm_wday = 0;
83  m_tm.tm_yday = 0;
84  m_tm.tm_year = 0;
85 }
struct tm m_tm
Definition: Tm.h:142
void Tm::setToCmsNanoTime ( uint64_t  nanos)

Definition at line 158 of file Tm.cc.

158  {
159  setToMicrosTime((nanos >> 32) * 1000000);
160 }
void setToMicrosTime(uint64_t micros)
Definition: Tm.cc:162
void Tm::setToCurrentGMTime ( )
void Tm::setToCurrentLocalTime ( )

Definition at line 171 of file Tm.cc.

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

Referenced by popcon::EcalLaserHandler::getNewObjects().

172 {
173  time_t t = time(NULL);
174  m_tm = *localtime( &t );
175 }
#define NULL
Definition: scimark2.h:8
struct tm m_tm
Definition: Tm.h:142
void Tm::setToGMTime ( time_t  t)

Definition at line 188 of file Tm.cc.

Referenced by str().

189 {
190  m_tm = *gmtime( &t );
191 }
struct tm m_tm
Definition: Tm.h:142
void Tm::setToLocalTime ( time_t  t)

Definition at line 183 of file Tm.cc.

184 {
185  m_tm = *localtime( &t );
186 }
struct tm m_tm
Definition: Tm.h:142
void Tm::setToMicrosTime ( uint64_t  micros)

Definition at line 162 of file Tm.cc.

References lumiQTWidget::t.

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

163 {
164  time_t t = micros / 1000000;
165  if (t >= INT_MAX) {
166  t = INT_MAX;
167  }
168  m_tm = *gmtime(&t);
169 }
struct tm m_tm
Definition: Tm.h:142
void Tm::setToString ( const std::string  s)
throw (std::runtime_error
)

Definition at line 193 of file Tm.cc.

References alignCSCRings::e, lumiQueryAPI::msg, and alignCSCRings::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().

195 {
196  sscanf(s.c_str(), "%04d-%02d-%02d %02d:%02d:%02d",
197  &m_tm.tm_year, &m_tm.tm_mon, &m_tm.tm_mday,
198  &m_tm.tm_hour, &m_tm.tm_min, &m_tm.tm_sec);
199 
200  try {
201  if (m_tm.tm_year > 9999 || m_tm.tm_year < 1900) {
202  throw(std::runtime_error("Year out of bounds"));
203  } else if (m_tm.tm_mon > 12 || m_tm.tm_mon < 1) {
204  throw(std::runtime_error("Month out of bounds"));
205  } else if (m_tm.tm_mday > 31 || m_tm.tm_mday < 1) {
206  throw(std::runtime_error("Day out of bounds"));
207  } else if (m_tm.tm_hour > 23 || m_tm.tm_mday < 0) {
208  throw(std::runtime_error("Hour out of bounds"));
209  } else if (m_tm.tm_min > 59 || m_tm.tm_min < 0) {
210  throw(std::runtime_error("Minute out of bounds"));
211  } else if (m_tm.tm_sec > 59 || m_tm.tm_sec < 0) {
212  throw(std::runtime_error("Day out of bounds"));
213  }
214 
215  if (m_tm.tm_year >= 2038) {
216  // take into account UNIX time limits
217  m_tm.tm_year = 2038;
218  if (m_tm.tm_mon > 1) {
219  m_tm.tm_mon = 1;
220  }
221  if (m_tm.tm_mday > 19) {
222  m_tm.tm_mday = 19;
223  }
224  if (m_tm.tm_hour > 3) {
225  m_tm.tm_hour = 3;
226  }
227  if (m_tm.tm_min > 14) {
228  m_tm.tm_min = 14;
229  }
230  if (m_tm.tm_sec > 7) {
231  m_tm.tm_sec = 7;
232  }
233  }
234  m_tm.tm_year -= 1900;
235  m_tm.tm_mon -= 1;
236  } catch (std::runtime_error &e) {
237  this->setNull();
238  string msg("Tm::setToString(): ");
239  msg.append(e.what());
240  throw(std::runtime_error(msg));
241  }
242 }
void setNull()
Definition: Tm.cc:74
struct tm m_tm
Definition: Tm.h:142
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 89 of file Tm.cc.

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

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

90 {
91  if (this->isNull()) {
92  return "";
93  }
94 
104  char timebuf[20] = "";
105  if (this->microsTime() >= PLUS_INF_MICROS) {
106  sprintf(timebuf, "9999-12-12 23:59:59");
107  } else {
108  Tm dummy_Tm;
109  dummy_Tm.setToGMTime(this->microsTime()/1000000);
110  struct tm dummy_tm = dummy_Tm.c_tm();
111  strftime(timebuf, 20, "%Y-%m-%d %H:%M:%S", &dummy_tm);
112  }
113  return string(timebuf);
114 }
struct tm c_tm() const
Definition: Tm.cc:56
uint64_t microsTime() const
Definition: Tm.cc:126
void setToGMTime(time_t t)
Definition: Tm.cc:188
int isNull() const
Definition: Tm.cc:63
static const uint64_t PLUS_INF_MICROS
Definition: Tm.h:16
Definition: Tm.h:13
uint64_t Tm::unixTime ( ) const

Definition at line 121 of file Tm.cc.

Referenced by epoch().

122 {
123  return microsTime()/1000000;
124 }
uint64_t microsTime() const
Definition: Tm.cc:126

Friends And Related Function Documentation

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 }
tuple out
Definition: dbtoconf.py:99
std::string str() const
Definition: Tm.cc:89

Member Data Documentation

struct tm Tm::m_tm
private

Definition at line 142 of file Tm.h.

Referenced by operator==().

const uint64_t Tm::NEG_INF_MICROS = 0
staticprivate

Definition at line 14 of file Tm.h.

Referenced by negInfinity().

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

Definition at line 16 of file Tm.h.

Referenced by plusInfinity().