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:54

◆ 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:128
void setToCmsNanoTime(uint64_t nanos)
Definition: Tm.cc:126
static const uint64_t PLUS_INF_MICROS
Definition: Tm.h:16
void setNull()
Definition: Tm.cc:54

◆ ~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  {
43  return m_tm;
44 }
struct tm m_tm
Definition: Tm.h:122

◆ cmsNanoSeconds()

uint64_t Tm::cmsNanoSeconds ( ) const

Definition at line 92 of file Tm.cc.

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

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

◆ dumpTm()

void Tm::dumpTm ( )

Definition at line 204 of file Tm.cc.

References gather_cfg::cout.

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 }
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:94

◆ isNull()

int Tm::isNull ( ) const

Definition at line 46 of file Tm.cc.

Referenced by DateHandler::tmToDate().

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

◆ microsTime()

uint64_t Tm::microsTime ( ) const

Definition at line 96 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().

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 }
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:128
uint64_t microsTime() const
Definition: Tm.cc:96

◆ 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:128
uint64_t microsTime() const
Definition: Tm.cc:96

◆ 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:96

◆ 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:96

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

Referenced by LMFSextuple::LMFSextuple().

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

◆ setToCmsNanoTime()

void Tm::setToCmsNanoTime ( uint64_t  nanos)

Definition at line 126 of file Tm.cc.

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

◆ setToCurrentGMTime()

void Tm::setToCurrentGMTime ( )

Definition at line 141 of file Tm.cc.

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

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

141  {
142  time_t t = time(nullptr);
143  m_tm = *gmtime(&t);
144 }
struct tm m_tm
Definition: Tm.h:122

◆ setToCurrentLocalTime()

void Tm::setToCurrentLocalTime ( )

Definition at line 136 of file Tm.cc.

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

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

◆ setToGMTime()

void Tm::setToGMTime ( time_t  t)

Definition at line 148 of file Tm.cc.

References submitPVValidationJobs::t.

Referenced by str().

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

◆ setToLocalTime()

void Tm::setToLocalTime ( time_t  t)

Definition at line 146 of file Tm.cc.

References submitPVValidationJobs::t.

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

◆ setToMicrosTime()

void Tm::setToMicrosTime ( uint64_t  micros)

Definition at line 128 of file Tm.cc.

References submitPVValidationJobs::t.

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

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

◆ setToString()

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

Definition at line 150 of file Tm.cc.

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

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

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 }
tuple msg
Definition: mps_check.py:286
void setNull()
Definition: Tm.cc:54
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 66 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().

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 }
struct tm c_tm() const
Definition: Tm.cc:42
void setToGMTime(time_t t)
Definition: Tm.cc:148
int isNull() const
Definition: Tm.cc:46
uint64_t microsTime() const
Definition: Tm.cc:96
static const uint64_t PLUS_INF_MICROS
Definition: Tm.h:16
Definition: Tm.h:13

◆ unixTime()

uint64_t Tm::unixTime ( ) const

Definition at line 94 of file Tm.cc.

Referenced by epoch().

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

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