LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
Timestamp.h
Go to the documentation of this file.
1 #ifndef canvas_Persistency_Provenance_Timestamp_h
2 #define canvas_Persistency_Provenance_Timestamp_h
3 
4 #include <cstdint>
5 #include <string>
6 
7 namespace art {
8  using TimeValue_t = std::uint64_t;
9 
10  class Timestamp {
11  public:
12  constexpr Timestamp(TimeValue_t const iValue)
13  : timeLow_{static_cast<std::uint32_t>(lowMask() & iValue)}
14  , timeHigh_{static_cast<std::uint32_t>(iValue >> 32)}
15  {}
16 
17  constexpr Timestamp()
20  {}
21 
22  constexpr TimeValue_t
23  value() const
24  {
25  return (static_cast<std::uint64_t>(timeHigh_) << 32) | timeLow_;
26  }
27 
28  constexpr std::uint32_t
29  timeLow() const
30  {
31  return timeLow_;
32  }
33  constexpr std::uint32_t
34  timeHigh() const
35  {
36  return timeHigh_;
37  }
38 
39  // ---------- const member functions ---------------------
40  constexpr bool
41  operator==(Timestamp const& iRHS) const
42  {
43  return timeHigh_ == iRHS.timeHigh_ && timeLow_ == iRHS.timeLow_;
44  }
45 
46  constexpr bool
47  operator!=(Timestamp const& iRHS) const
48  {
49  return !(*this == iRHS);
50  }
51 
52  constexpr bool
53  operator<(Timestamp const& iRHS) const
54  {
55  return timeHigh_ == iRHS.timeHigh_ ? timeLow_ < iRHS.timeLow_ :
56  timeHigh_ < iRHS.timeHigh_;
57  }
58 
59  constexpr bool
60  operator<=(Timestamp const& iRHS) const
61  {
62  return timeHigh_ == iRHS.timeHigh_ ? timeLow_ <= iRHS.timeLow_ :
63  timeHigh_ <= iRHS.timeHigh_;
64  }
65 
66  constexpr bool
67  operator>(Timestamp const& iRHS) const
68  {
69  return timeHigh_ == iRHS.timeHigh_ ? timeLow_ > iRHS.timeLow_ :
70  timeHigh_ > iRHS.timeHigh_;
71  }
72 
73  constexpr bool
74  operator>=(Timestamp const& iRHS) const
75  {
76  return timeHigh_ == iRHS.timeHigh_ ? timeLow_ >= iRHS.timeLow_ :
77  timeHigh_ >= iRHS.timeHigh_;
78  }
79 
80  // ---------- static member functions --------------------
81  static constexpr Timestamp
83  {
84  return Timestamp{0};
85  }
86  static constexpr Timestamp
88  {
89  return Timestamp{-1ull};
90  }
91  static constexpr Timestamp
93  {
94  return Timestamp{1};
95  }
96 
97  private:
98  std::uint32_t timeLow_;
99  std::uint32_t timeHigh_;
100 
101  static constexpr TimeValue_t
103  {
104  return 0xFFFFFFFF;
105  }
106  };
107 
108  // Prints out a string of the form YYYYMMDDTHHMMSS, where 'T' is the
109  // delimiter between the day and the time. Use this function if the
110  // art::TimeStamp object was constructed from calling time(nullptr).
111  std::string to_iso_string_assuming_unix_epoch(Timestamp const&);
112 }
113 #endif /* canvas_Persistency_Provenance_Timestamp_h */
114 
115 // Local Variables:
116 // mode: c++
117 // End:
constexpr std::uint32_t timeLow() const
Definition: Timestamp.h:29
constexpr bool operator!=(Timestamp const &iRHS) const
Definition: Timestamp.h:47
static constexpr Timestamp endOfTime()
Definition: Timestamp.h:87
constexpr std::uint32_t timeHigh() const
Definition: Timestamp.h:34
constexpr bool operator<=(Timestamp const &iRHS) const
Definition: Timestamp.h:60
static constexpr Timestamp beginOfTime()
Definition: Timestamp.h:92
constexpr bool operator<(Timestamp const &iRHS) const
Definition: Timestamp.h:53
constexpr TimeValue_t value() const
Definition: Timestamp.h:23
std::uint32_t timeHigh_
Definition: Timestamp.h:99
std::string to_iso_string_assuming_unix_epoch(Timestamp const &ts)
Definition: Timestamp.cc:8
constexpr bool operator>(Timestamp const &iRHS) const
Definition: Timestamp.h:67
static constexpr TimeValue_t lowMask()
Definition: Timestamp.h:102
static constexpr Timestamp invalidTimestamp()
Definition: Timestamp.h:82
std::uint64_t TimeValue_t
Definition: Timestamp.h:8
constexpr bool operator==(Timestamp const &iRHS) const
Definition: Timestamp.h:41
Definition: MVAAlg.h:12
constexpr bool operator>=(Timestamp const &iRHS) const
Definition: Timestamp.h:74
constexpr Timestamp(TimeValue_t const iValue)
Definition: Timestamp.h:12
std::uint32_t timeLow_
Definition: Timestamp.h:98
constexpr Timestamp()
Definition: Timestamp.h:17