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.

Referenced by negInfinity(), and plusInfinity().

24 { this->setNull(); }
void setNull()
Definition: Tm.cc:52

◆ Tm() [2/3]

Tm::Tm ( struct tm *  initTm)

Definition at line 27 of file Tm.cc.

27 { m_tm = *initTm; }
struct tm m_tm
Definition: Tm.h:122

◆ 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 }
void setToMicrosTime(uint64_t micros)
Definition: Tm.cc:126
void setToCmsNanoTime(uint64_t nanos)
Definition: Tm.cc:124
static const uint64_t PLUS_INF_MICROS
Definition: Tm.h:16
void setNull()
Definition: Tm.cc:52

◆ ~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.

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

42 { return m_tm; }
struct tm m_tm
Definition: Tm.h:122

◆ cmsNanoSeconds()

uint64_t Tm::cmsNanoSeconds ( ) const

Definition at line 90 of file Tm.cc.

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

90 { return microsTime() / 1000000 << 32; }
uint64_t microsTime() const
Definition: Tm.cc:94

◆ dumpTm()

void Tm::dumpTm ( )

Definition at line 202 of file Tm.cc.

References gather_cfg::cout.

202  {
203  cout << "=== dumpTm() ===" << endl;
204  cout << "tm_year " << m_tm.tm_year << endl;
205  cout << "tm_mon " << m_tm.tm_mon << endl;
206  cout << "tm_mday " << m_tm.tm_mday << endl;
207  cout << "tm_hour " << m_tm.tm_hour << endl;
208  cout << "tm_min " << m_tm.tm_min << endl;
209  cout << "tm_sec " << m_tm.tm_sec << endl;
210  cout << "tm_yday " << m_tm.tm_yday << endl;
211  cout << "tm_wday " << m_tm.tm_wday << endl;
212  cout << "tm_isdst " << m_tm.tm_isdst << endl;
213  cout << "================" << endl;
214 }
struct tm m_tm
Definition: Tm.h:122

◆ epoch()

uint64_t Tm::epoch ( ) const
inline

Definition at line 58 of file Tm.h.

References unixTime().

58 { return unixTime(); };
uint64_t unixTime() const
Definition: Tm.cc:92

◆ isNull()

int Tm::isNull ( ) const

Definition at line 44 of file Tm.cc.

Referenced by DateHandler::tmToDate().

44  {
45  if (m_tm.tm_year == 0 && m_tm.tm_mon == 0 && m_tm.tm_mday == 0) {
46  return 1;
47  } else {
48  return 0;
49  }
50 }
struct tm m_tm
Definition: Tm.h:122

◆ microsTime()

uint64_t Tm::microsTime ( ) const

Definition at line 94 of file Tm.cc.

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().

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

◆ negInfinity()

static Tm Tm::negInfinity ( )
inlinestatic

Definition at line 47 of file Tm.h.

References NEG_INF_MICROS, and Tm().

47 { return Tm(NEG_INF_MICROS); };
static const uint64_t NEG_INF_MICROS
Definition: Tm.h:14
Tm()
Definition: Tm.cc:24

◆ operator!=()

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

Definition at line 101 of file Tm.h.

References submitPVValidationJobs::t.

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

◆ operator+()

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

Definition at line 113 of file Tm.h.

References runTheMatrix::ret, and seconds().

113  {
114  Tm ret = *this;
115  ret += seconds;
116  return ret;
117  }
double seconds()
ret
prodAgent to be discontinued
Definition: Tm.h:13

◆ operator+=()

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

Definition at line 108 of file Tm.h.

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

108  {
110  return *this;
111  }
double seconds()
void setToMicrosTime(uint64_t micros)
Definition: Tm.cc:126
uint64_t microsTime() const
Definition: Tm.cc:94

◆ operator-=()

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

Definition at line 103 of file Tm.h.

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

103  {
105  return *this;
106  }
double seconds()
void setToMicrosTime(uint64_t micros)
Definition: Tm.cc:126
uint64_t microsTime() const
Definition: Tm.cc:94

◆ operator<()

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

Definition at line 91 of file Tm.h.

References microsTime(), and submitPVValidationJobs::t.

91 { return microsTime() < t.microsTime(); }
uint64_t microsTime() const
Definition: Tm.cc:94

◆ operator<=()

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

Definition at line 93 of file Tm.h.

References microsTime(), and submitPVValidationJobs::t.

93 { return microsTime() <= t.microsTime(); }
uint64_t microsTime() const
Definition: Tm.cc:94

◆ operator==()

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

Definition at line 95 of file Tm.h.

References m_tm, and submitPVValidationJobs::t.

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  }
struct tm m_tm
Definition: Tm.h:122

◆ plusInfinity()

static Tm Tm::plusInfinity ( )
inlinestatic

Definition at line 45 of file Tm.h.

References PLUS_INF_MICROS, and Tm().

45 { return Tm(PLUS_INF_MICROS); };
static const uint64_t PLUS_INF_MICROS
Definition: Tm.h:16
Tm()
Definition: Tm.cc:24

◆ setNull()

void Tm::setNull ( )

Definition at line 52 of file Tm.cc.

Referenced by LMFSextuple::LMFSextuple().

52  {
53  m_tm.tm_hour = 0;
54  m_tm.tm_isdst = 0;
55  m_tm.tm_mday = 0;
56  m_tm.tm_min = 0;
57  m_tm.tm_mon = 0;
58  m_tm.tm_sec = 0;
59  m_tm.tm_wday = 0;
60  m_tm.tm_yday = 0;
61  m_tm.tm_year = 0;
62 }
struct tm m_tm
Definition: Tm.h:122

◆ setToCmsNanoTime()

void Tm::setToCmsNanoTime ( uint64_t  nanos)

Definition at line 124 of file Tm.cc.

124 { setToMicrosTime((nanos >> 32) * 1000000); }
void setToMicrosTime(uint64_t micros)
Definition: Tm.cc:126

◆ setToCurrentGMTime()

void Tm::setToCurrentGMTime ( )

◆ setToCurrentLocalTime()

void Tm::setToCurrentLocalTime ( )

Definition at line 134 of file Tm.cc.

References submitPVValidationJobs::t, and hcalRecHitTable_cff::time.

134  {
135  time_t t = time(nullptr);
136  m_tm = *localtime(&t);
137 }
struct tm m_tm
Definition: Tm.h:122

◆ setToGMTime()

void Tm::setToGMTime ( time_t  t)

Definition at line 146 of file Tm.cc.

References submitPVValidationJobs::t.

Referenced by str().

146 { m_tm = *gmtime(&t); }
struct tm m_tm
Definition: Tm.h:122

◆ setToLocalTime()

void Tm::setToLocalTime ( time_t  t)

Definition at line 144 of file Tm.cc.

References submitPVValidationJobs::t.

144 { m_tm = *localtime(&t); }
struct tm m_tm
Definition: Tm.h:122

◆ setToMicrosTime()

void Tm::setToMicrosTime ( uint64_t  micros)

Definition at line 126 of file Tm.cc.

References submitPVValidationJobs::t.

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

126  {
127  time_t t = micros / 1000000;
128  if (t >= INT_MAX) {
129  t = INT_MAX;
130  }
131  m_tm = *gmtime(&t);
132 }
struct tm m_tm
Definition: Tm.h:122

◆ setToString()

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

Definition at line 148 of file Tm.cc.

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

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

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

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

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

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

64  {
65  if (this->isNull()) {
66  return "";
67  }
68 
78  char timebuf[20] = "";
79  if (this->microsTime() >= PLUS_INF_MICROS) {
80  sprintf(timebuf, "9999-12-12 23:59:59");
81  } else {
82  Tm dummy_Tm;
83  dummy_Tm.setToGMTime(this->microsTime() / 1000000);
84  struct tm dummy_tm = dummy_Tm.c_tm();
85  strftime(timebuf, 20, "%Y-%m-%d %H:%M:%S", &dummy_tm);
86  }
87  return string(timebuf);
88 }
struct tm c_tm() const
Definition: Tm.cc:42
void setToGMTime(time_t t)
Definition: Tm.cc:146
int isNull() const
Definition: Tm.cc:44
uint64_t microsTime() const
Definition: Tm.cc:94
static const uint64_t PLUS_INF_MICROS
Definition: Tm.h:16
Definition: Tm.h:13

◆ unixTime()

uint64_t Tm::unixTime ( ) const

Definition at line 92 of file Tm.cc.

Referenced by epoch().

92 { return microsTime() / 1000000; }
uint64_t microsTime() const
Definition: Tm.cc:94

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.

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().