LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
IOVTimeStamp.cxx
Go to the documentation of this file.
1 
14 #include "IOVTimeStamp.h"
15 #include "IOVDataConstants.h"
16 #include "IOVDataError.h"
17 #include <iomanip>
18 #include <limits>
19 #include <sstream>
20 
21 namespace lariov {
22 
27  {
29  throw IOVDataError("SubStamp of an IOVTimeStamp cannot have more than six digits!");
30  }
31  std::stringstream stream;
32  stream << fStamp << "." << std::setfill('0') << std::setw(kMAX_SUBSTAMP_LENGTH) << fSubStamp;
33  fDBStamp = stream.str();
34  }
35 
37  {
38  unsigned long stamp;
39  std::string substamp_str;
40  if (ts.find_first_of(".") == std::string::npos) {
41  stamp = std::stoul(ts);
42  substamp_str = "0";
43  }
44  else {
45  stamp = std::stoul(ts.substr(0, ts.find_first_of(".")));
46  substamp_str = ts.substr(ts.find_first_of(".") + 1);
47  }
48 
49  if (substamp_str.length() > kMAX_SUBSTAMP_LENGTH) {
50  throw IOVDataError("SubStamp of an IOVTimeStamp cannot have more than six digits!");
51  }
52  while (substamp_str.length() < kMAX_SUBSTAMP_LENGTH)
53  substamp_str += "0";
54  unsigned int substamp = std::stoi(substamp_str);
55 
56  return IOVTimeStamp(stamp, substamp);
57  }
58 
60  {
61  return IOVTimeStamp(0, 0);
62  }
63 
65  {
66  return IOVTimeStamp(std::numeric_limits<unsigned long>::max(), kMAX_SUBSTAMP_VALUE);
67  }
68 
71  {
72  if (this == &ts) return *this;
73  fStamp = ts.Stamp();
74  fSubStamp = ts.SubStamp();
75  fDBStamp = ts.DBStamp();
76  return *this;
77  }
78 
80  bool IOVTimeStamp::operator<(const IOVTimeStamp& ts) const
81  {
82  if (this->Stamp() < ts.Stamp())
83  return true;
84  else if (this->Stamp() == ts.Stamp() && this->SubStamp() < ts.SubStamp())
85  return true;
86  else
87  return false;
88  }
89 
91  bool IOVTimeStamp::operator==(const IOVTimeStamp& ts) const
92  {
93  if (fStamp == ts.Stamp() && fSubStamp == ts.SubStamp()) return true;
94  return false;
95  }
96 
98  bool IOVTimeStamp::operator!=(const IOVTimeStamp& ts) const
99  {
100  return !(*this == ts);
101  }
102 
104  {
105  if (*this < ts || *this == ts)
106  return true;
107  else
108  return false;
109  }
110 
112  {
113  if (!(*this < ts))
114  return true;
115  else
116  return false;
117  }
118 
119  bool IOVTimeStamp::operator>(const IOVTimeStamp& ts) const
120  {
121  if (!(*this <= ts))
122  return true;
123  else
124  return false;
125  }
126 }
static IOVTimeStamp MinTimeStamp()
bool operator==(const IOVTimeStamp &ts) const
implementation of equality operator
IOVTimeStamp(unsigned long stamp, unsigned int substamp=0)
Constructor.
Definition: IOVTimeStamp.h:28
bool operator>=(const IOVTimeStamp &ts) const
bool operator<(const IOVTimeStamp &ts) const
comparison operators
const std::string & DBStamp() const
Definition: IOVTimeStamp.h:39
Class def header for a class IOVTimeStamp.
bool operator<=(const IOVTimeStamp &ts) const
unsigned long SubStamp() const
Definition: IOVTimeStamp.h:38
const unsigned int kMAX_SUBSTAMP_VALUE
bool operator>(const IOVTimeStamp &ts) const
bool operator!=(const IOVTimeStamp &ts) const
remaining comparison operators implemented in terms of == and <
unsigned int fSubStamp
Definition: IOVTimeStamp.h:72
Filters for channels, events, etc.
unsigned long fStamp
Definition: IOVTimeStamp.h:71
unsigned long Stamp() const
Definition: IOVTimeStamp.h:37
Collection of exception classes for IOVData.
IOVTimeStamp & operator=(const IOVTimeStamp &ts)
assignment operator
const unsigned short kMAX_SUBSTAMP_LENGTH
static IOVTimeStamp GetFromString(const std::string &ts)
static IOVTimeStamp MaxTimeStamp()
std::string fDBStamp
Definition: IOVTimeStamp.h:74