ATLAS Offline Software
IOVTime.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef ATHENAKERNEL_IOVTIME_H
6 #define ATHENAKERNEL_IOVTIME_H
7 
20 #include <iosfwd>
21 #include <string>
22 #include <stdint.h>
23 #include <limits>
24 
25 class MsgStream;
26 class EventIDBase;
27 
33 class IOVTime {
34 
35 private:
36  enum IOVTime_type {
37  UNDEF = 0,
40  BOTH
41  };
42 
43 public:
45 
46  // We remove the top bit from MAXRUN to allow use of this to set
47  // CondDBKey which has a sign bit
48  static constexpr uint32_t MAXRUN = (std::numeric_limits<uint32_t>::max() >> 1);
49 
52 
53  static constexpr uint64_t MAXRETIME =( ((uint64_t) IOVTime::MAXRUN << 32) + IOVTime::MAXEVENT );
55 
57  // Set MAXTIMESTAMP to 63 bit max
60 
61 public:
67  public:
68  bool operator() ( const IOVTime& t1, const IOVTime& t2 ) const noexcept {
69  return t1.timestamp() > t2.timestamp();
70  }
71  bool operator() ( const IOVTime* t1, const IOVTime* t2 ) const noexcept {
72  return t1->timestamp() > t2->timestamp();
73  }
74  };
75 
81  public:
82  bool operator() ( const IOVTime& t1, const IOVTime& t2 ) const noexcept {
83  return t1.re_time() > t2.re_time();
84  }
85  bool operator() ( const IOVTime* t1, const IOVTime* t2 ) const noexcept {
86  return t1->re_time() > t2->re_time();
87  }
88  };
89 
90 public:
95  explicit IOVTime( uint32_t run, uint32_t event );
96  explicit IOVTime( uint32_t run, uint32_t event,
98  IOVTime( const EventIDBase& eid);
99 
100  void setTimestamp( uint64_t timestamp ) noexcept;
101  void setRETime( uint64_t time ) noexcept;
102  void setRunEvent( uint32_t run, uint32_t event ) noexcept;
103  void reset() noexcept;
104 
105  inline uint32_t run() const noexcept { return static_cast<uint32_t> (m_time>>32); }
106  inline uint32_t event() const noexcept { return static_cast<uint32_t> (m_time & 0xFFFFFFFF); }
107  inline uint64_t re_time() const noexcept { return m_time; }
108  inline uint64_t timestamp() const noexcept { return m_timestamp; }
109 
110  bool isValid() const noexcept;
111  inline bool isTimestamp() const noexcept { return (m_status == IOVTime::TIMESTAMP ||
112  m_status== IOVTime::BOTH) ? 1 : 0; }
113  inline bool isRunEvent() const noexcept { return (m_status == IOVTime::RUN_EVT ||
114  m_status == IOVTime::BOTH) ? 1 : 0; }
115  inline bool isBoth() const noexcept { return (m_status == IOVTime::BOTH) ? 1 : 0; }
116 
117  operator std::string() const;
118  operator EventIDBase() const;
119 
120  friend bool operator<(const IOVTime& lhs, const IOVTime& rhs) noexcept;
121  friend bool operator>(const IOVTime& lhs, const IOVTime& rhs) noexcept;
122  friend bool operator==(const IOVTime& lhs, const IOVTime& rhs) noexcept;
123  friend bool operator!=(const IOVTime& lhs, const IOVTime& rhs) noexcept;
124  friend bool operator>=(const IOVTime& lhs, const IOVTime& rhs) noexcept;
125  friend bool operator<=(const IOVTime& lhs, const IOVTime& rhs) noexcept;
126 
127  friend std::ostream& operator<<(std::ostream& os, const IOVTime& rhs);
128  friend MsgStream& operator<<(MsgStream& os, const IOVTime& rhs);
129 
130 private:
131 
135 };
136 
137 inline bool operator<(const IOVTime& lhs, const IOVTime& rhs) noexcept {
138  if (lhs.isTimestamp() && rhs.isTimestamp()) {
139  return lhs.m_timestamp < rhs.m_timestamp;
140  } else {
141  return lhs.m_time < rhs.m_time;
142  }
143 }
144 inline bool operator>(const IOVTime& lhs, const IOVTime& rhs) noexcept {
145  if (lhs.isTimestamp() && rhs.isTimestamp()) {
146  return lhs.m_timestamp > rhs.m_timestamp;
147  } else {
148  return lhs.m_time > rhs.m_time;
149  }
150 }
151 inline bool operator==(const IOVTime& lhs, const IOVTime& rhs) noexcept {
152  if (lhs.isTimestamp() && rhs.isTimestamp()) {
153  return lhs.m_timestamp == rhs.m_timestamp;
154  } else {
155  return lhs.m_time == rhs.m_time;
156  }
157 }
158 inline bool operator!=(const IOVTime& lhs, const IOVTime& rhs) noexcept {
159  return !(lhs == rhs) ;
160 }
161 inline bool operator>=(const IOVTime& lhs, const IOVTime& rhs) noexcept {
162  return !( lhs < rhs );
163 }
164 inline bool operator<=(const IOVTime& lhs, const IOVTime& rhs) noexcept {
165  return !( lhs > rhs );
166 }
167 
168 // template < class STR >
169 // inline STR& operator << (STR& os, const IOVTime& rhs) {
170 // os << rhs.m_time << ": [" << (rhs.m_time>>32) << ","
171 // << ( rhs.m_time & 0xFFFFFFFF ) << "]";
172 // return os;
173 // }
174 
175 #endif
176 
IOVTime::operator<<
friend std::ostream & operator<<(std::ostream &os, const IOVTime &rhs)
Definition: IOVTime.cxx:190
IOVTime::SortByRunEvent
Predicate. Used to sort by run and event number.
Definition: IOVTime.h:80
IOVTime::IOVTime_type
IOVTime_type
Definition: IOVTime.h:36
IOVTime::BOTH
@ BOTH
Definition: IOVTime.h:40
max
#define max(a, b)
Definition: cfImp.cxx:41
IOVTime::MAXRETIME
static constexpr uint64_t MAXRETIME
Definition: IOVTime.h:53
IOVTime::MAXRUN
static constexpr uint32_t MAXRUN
Definition: IOVTime.h:48
IOVTime::operator>
friend bool operator>(const IOVTime &lhs, const IOVTime &rhs) noexcept
Definition: IOVTime.h:144
IOVTime::event
uint32_t event() const noexcept
Definition: IOVTime.h:106
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
IOVTime::timestamp
uint64_t timestamp() const noexcept
Definition: IOVTime.h:108
ALFA_EventTPCnv_Dict::t1
std::vector< ALFA_RawDataCollection_p1 > t1
Definition: ALFA_EventTPCnvDict.h:43
IOVTime::re_time
uint64_t re_time() const noexcept
Definition: IOVTime.h:107
operator==
bool operator==(const IOVTime &lhs, const IOVTime &rhs) noexcept
Definition: IOVTime.h:151
IOVTime::operator<=
friend bool operator<=(const IOVTime &lhs, const IOVTime &rhs) noexcept
Definition: IOVTime.h:164
IOVTime::RUN_EVT
@ RUN_EVT
Definition: IOVTime.h:39
IOVTime::isBoth
bool isBoth() const noexcept
Definition: IOVTime.h:115
IOVTime::m_status
IOVTime_type m_status
Definition: IOVTime.h:132
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
IOVTime::isValid
bool isValid() const noexcept
Definition: IOVTime.cxx:117
operator!=
bool operator!=(const IOVTime &lhs, const IOVTime &rhs) noexcept
Definition: IOVTime.h:158
IOVTime::operator>=
friend bool operator>=(const IOVTime &lhs, const IOVTime &rhs) noexcept
Definition: IOVTime.h:161
IOVTime::MINRUN
static constexpr uint32_t MINRUN
Definition: IOVTime.h:44
operator<
bool operator<(const IOVTime &lhs, const IOVTime &rhs) noexcept
Definition: IOVTime.h:137
IOVTime::UNDEFTIMESTAMP
static constexpr uint64_t UNDEFTIMESTAMP
Definition: IOVTime.h:59
IOVTime
Basic time unit for IOVSvc. Hold time as a combination of run and event numbers.
Definition: IOVTime.h:33
operator>=
bool operator>=(const IOVTime &lhs, const IOVTime &rhs) noexcept
Definition: IOVTime.h:161
IOVTime::SortByRunEvent::operator()
bool operator()(const IOVTime &t1, const IOVTime &t2) const noexcept
Definition: IOVTime.h:82
IOVTime::reset
void reset() noexcept
Definition: IOVTime.cxx:108
IOVTime::isRunEvent
bool isRunEvent() const noexcept
Definition: IOVTime.h:113
IOVTime::MAXTIMESTAMP
static constexpr uint64_t MAXTIMESTAMP
Definition: IOVTime.h:58
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
IOVTime::isTimestamp
bool isTimestamp() const noexcept
Definition: IOVTime.h:111
IOVTime::m_timestamp
uint64_t m_timestamp
Definition: IOVTime.h:134
IOVTime::IOVTime
IOVTime()
Definition: IOVTime.h:91
IOVTime::setRETime
void setRETime(uint64_t time) noexcept
Definition: IOVTime.cxx:84
run
Definition: run.py:1
IOVTime::operator<
friend bool operator<(const IOVTime &lhs, const IOVTime &rhs) noexcept
Definition: IOVTime.h:137
IOVTime::setTimestamp
void setTimestamp(uint64_t timestamp) noexcept
Definition: IOVTime.cxx:72
IOVTime::operator==
friend bool operator==(const IOVTime &lhs, const IOVTime &rhs) noexcept
Definition: IOVTime.h:151
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
min
#define min(a, b)
Definition: cfImp.cxx:40
IOVTime::MAXEVENT
static constexpr uint32_t MAXEVENT
Definition: IOVTime.h:51
operator>
bool operator>(const IOVTime &lhs, const IOVTime &rhs) noexcept
Definition: IOVTime.h:144
IOVTime::MINEVENT
static constexpr uint32_t MINEVENT
Definition: IOVTime.h:50
operator<=
bool operator<=(const IOVTime &lhs, const IOVTime &rhs) noexcept
Definition: IOVTime.h:164
IOVTime::IOVTime
IOVTime(uint64_t timestamp)
Definition: IOVTime.h:93
IOVTime::UNDEF
@ UNDEF
Definition: IOVTime.h:37
ALFA_EventTPCnv_Dict::t2
std::vector< ALFA_RawDataContainer_p1 > t2
Definition: ALFA_EventTPCnvDict.h:44
IOVTime::UNDEFRETIME
static constexpr uint64_t UNDEFRETIME
Definition: IOVTime.h:54
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
IOVTime::SortByTimeStamp::operator()
bool operator()(const IOVTime &t1, const IOVTime &t2) const noexcept
Definition: IOVTime.h:68
IOVTime::setRunEvent
void setRunEvent(uint32_t run, uint32_t event) noexcept
Definition: IOVTime.cxx:96
IOVTime::operator!=
friend bool operator!=(const IOVTime &lhs, const IOVTime &rhs) noexcept
Definition: IOVTime.h:158
IOVTime::TIMESTAMP
@ TIMESTAMP
Definition: IOVTime.h:38
IOVTime::MINTIMESTAMP
static constexpr uint64_t MINTIMESTAMP
Definition: IOVTime.h:56
IOVTime::SortByTimeStamp
Predicate. Used to sort by time stamp.
Definition: IOVTime.h:66
IOVTime::m_time
uint64_t m_time
Definition: IOVTime.h:133