IOVTimeStamp.cxx
Go to the documentation of this file.
1 /**
2  * \file IOVTimeStamp.cxx
3  *
4  * \ingroup IOVData
5  *
6  * \brief Implementation for class IOVTimeStamp
7  *
8  * @author eberly@fnal.gov
9  */
10 
11 /** \addtogroup IOVData
12 
13  @{*/
14 #include "IOVTimeStamp.h"
15 #include "IOVDataError.h"
16 #include "IOVDataConstants.h"
17 #include <sstream>
18 #include <limits>
19 #include <iomanip>
20 
21 namespace lariov {
22 
23 
24  /**Create unique database timestamp of the form <fStamp>.<fSubStamp>,
25  where fSubStamp is prepended with zeroes to ensure six digits
26  */
29  throw IOVDataError("SubStamp of an IOVTimeStamp cannot have more than six digits!");
30  }
31  std::stringstream stream;
33  fDBStamp = stream.str();
34  }
35 
37  unsigned long stamp;
38  std::string substamp_str;
39  if (ts.find_first_of(".") == std::string::npos) {
40  stamp = std::stoul(ts);
41  substamp_str = "0";
42  }
43  else {
44  stamp = std::stoul(ts.substr(0, ts.find_first_of(".")));
45  substamp_str = ts.substr(ts.find_first_of(".")+1);
46  }
47 
48  if (substamp_str.length() > kMAX_SUBSTAMP_LENGTH) {
49  throw IOVDataError("SubStamp of an IOVTimeStamp cannot have more than six digits!");
50  }
51  while (substamp_str.length() < kMAX_SUBSTAMP_LENGTH) substamp_str += "0";
52  unsigned int substamp = std::stoi(substamp_str);
53 
54  return IOVTimeStamp(stamp,substamp);
55  }
56 
58  return IOVTimeStamp(0,0);
59  }
60 
63  }
64 
65  ///implementation of assignment operator
67  if (this == &ts) return *this;
68  fStamp = ts.Stamp();
69  fSubStamp = ts.SubStamp();
70  fDBStamp = ts.DBStamp();
71  return *this;
72  }
73 
74  ///implementation of operator<
75  bool IOVTimeStamp::operator<(const IOVTimeStamp& ts) const {
76  if (this->Stamp() < ts.Stamp()) return true;
77  else if (this->Stamp() == ts.Stamp() && this->SubStamp() < ts.SubStamp()) return true;
78  else return false;
79  }
80 
81  ///implementation of equality operator
82  bool IOVTimeStamp::operator==(const IOVTimeStamp& ts) const {
83  if ( fStamp == ts.Stamp() && fSubStamp == ts.SubStamp() ) return true;
84  return false;
85  }
86 
87  ///remaining comparison operators implemented in terms of == and <
88  bool IOVTimeStamp::operator!=(const IOVTimeStamp& ts) const {
89  return !( *this == ts);
90  }
91 
92  bool IOVTimeStamp::operator<=(const IOVTimeStamp& ts) const {
93  if ( *this < ts || *this == ts) return true;
94  else return false;
95  }
96 
97  bool IOVTimeStamp::operator>=(const IOVTimeStamp& ts) const {
98  if ( !( *this < ts) ) return true;
99  else return false;
100  }
101 
102  bool IOVTimeStamp::operator>(const IOVTimeStamp& ts) const {
103  if ( !( *this <= ts) ) return true;
104  else return false;
105  }
106 }
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:29
std::string string
Definition: nybbler.cc:12
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 <
static int max(int a, int b)
unsigned int fSubStamp
Definition: IOVTimeStamp.h:71
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
Filters for channels, events, etc.
unsigned long fStamp
Definition: IOVTimeStamp.h:70
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()
Q_EXPORT QTSManip setfill(int f)
Definition: qtextstream.h:337
std::string fDBStamp
Definition: IOVTimeStamp.h:73