ATLAS Offline Software
Loading...
Searching...
No Matches
IOVTime.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef ATHENAKERNEL_IOVTIME_H
6#define ATHENAKERNEL_IOVTIME_H
7
18
19#include <compare>
20#include <iosfwd>
21#include <string>
22#include <stdint.h>
23#include <limits>
24#include <format>
25
26class MsgStream;
27class EventIDBase;
28
34class IOVTime {
35
36private:
43
44public:
45 static constexpr uint32_t MINRUN = std::numeric_limits<uint32_t>::min();
46
47 // We remove the top bit from MAXRUN to allow use of this to set
48 // CondDBKey which has a sign bit
49 static constexpr uint32_t MAXRUN = (std::numeric_limits<uint32_t>::max() >> 1);
50
51 static constexpr uint32_t MINEVENT = std::numeric_limits<uint32_t>::min();
52 static constexpr uint32_t MAXEVENT = (std::numeric_limits<uint32_t>::max());
53
54 static constexpr uint64_t MAXRETIME =( ((uint64_t) IOVTime::MAXRUN << 32) + IOVTime::MAXEVENT );
55 static constexpr uint64_t UNDEFRETIME = std::numeric_limits<uint64_t>::max();
56
57 static constexpr uint64_t MINTIMESTAMP = std::numeric_limits<uint64_t>::min();
58 // Set MAXTIMESTAMP to 63 bit max
59 static constexpr uint64_t MAXTIMESTAMP = (std::numeric_limits<uint64_t>::max() >> 1);
60 static constexpr uint64_t UNDEFTIMESTAMP = std::numeric_limits<uint64_t>::max();
61
62public:
68 public:
69 bool operator() ( const IOVTime& t1, const IOVTime& t2 ) const noexcept {
70 return t1.timestamp() > t2.timestamp();
71 }
72 bool operator() ( const IOVTime* t1, const IOVTime* t2 ) const noexcept {
73 return t1->timestamp() > t2->timestamp();
74 }
75 };
76
82 public:
83 bool operator() ( const IOVTime& t1, const IOVTime& t2 ) const noexcept {
84 return t1.re_time() > t2.re_time();
85 }
86 bool operator() ( const IOVTime* t1, const IOVTime* t2 ) const noexcept {
87 return t1->re_time() > t2->re_time();
88 }
89 };
90
91public:
96 explicit IOVTime( uint32_t run, uint32_t event );
97 explicit IOVTime( uint32_t run, uint32_t event,
98 uint64_t timestamp );
99 IOVTime( const EventIDBase& eid);
100
101 void setTimestamp( uint64_t timestamp ) noexcept;
102 void setRETime( uint64_t time ) noexcept;
103 void setRunEvent( uint32_t run, uint32_t event ) noexcept;
104 void reset() noexcept;
105
106 inline uint32_t run() const noexcept { return static_cast<uint32_t> (m_time>>32); }
107 inline uint32_t event() const noexcept { return static_cast<uint32_t> (m_time & 0xFFFFFFFF); }
108 inline uint64_t re_time() const noexcept { return m_time; }
109 inline uint64_t timestamp() const noexcept { return m_timestamp; }
110
111 bool isValid() const noexcept;
112 inline bool isTimestamp() const noexcept { return (m_status == IOVTime::TIMESTAMP ||
113 m_status== IOVTime::BOTH) ? 1 : 0; }
114 inline bool isRunEvent() const noexcept { return (m_status == IOVTime::RUN_EVT ||
115 m_status == IOVTime::BOTH) ? 1 : 0; }
116 inline bool isBoth() const noexcept { return (m_status == IOVTime::BOTH) ? 1 : 0; }
117
118 operator std::string() const;
119 operator EventIDBase() const;
120
121 friend std::strong_ordering operator<=>(const IOVTime& lhs, const IOVTime& rhs) noexcept;
122 friend bool operator==(const IOVTime& lhs, const IOVTime& rhs) noexcept;
123
124 friend std::ostream& operator<<(std::ostream& os, const IOVTime& rhs);
125 friend MsgStream& operator<<(MsgStream& os, const IOVTime& rhs);
126
127private:
128
130 uint64_t m_time;
131 uint64_t m_timestamp;
132};
133
134
135namespace std {
136
138template <>
139struct formatter<IOVTime>
140 : public formatter<string_view>
141{
142 template <class FmtContext>
143 FmtContext::iterator format (const IOVTime& io, FmtContext& ctx) const
144 {
145 return formatter<string_view>::format (static_cast<std::string>(io), ctx);
146 }
147};
148
149} // namespace std
150
151
152inline
153std::strong_ordering
154operator<=>(const IOVTime& lhs, const IOVTime& rhs) noexcept {
155 if (lhs.isTimestamp() && rhs.isTimestamp()) {
156 return lhs.m_timestamp <=> rhs.m_timestamp;
157 } else {
158 return lhs.m_time <=> rhs.m_time;
159 }
160}
161inline bool operator==(const IOVTime& lhs, const IOVTime& rhs) noexcept {
162 if (lhs.isTimestamp() && rhs.isTimestamp()) {
163 return lhs.m_timestamp == rhs.m_timestamp;
164 } else {
165 return lhs.m_time == rhs.m_time;
166 }
167}
168
169#endif
170
bool operator==(const IOVTime &lhs, const IOVTime &rhs) noexcept
Definition IOVTime.h:161
std::strong_ordering operator<=>(const IOVTime &lhs, const IOVTime &rhs) noexcept
Definition IOVTime.h:154
bool operator()(const IOVTime &t1, const IOVTime &t2) const noexcept
Definition IOVTime.h:83
bool operator()(const IOVTime &t1, const IOVTime &t2) const noexcept
Definition IOVTime.h:69
Basic time unit for IOVSvc.
Definition IOVTime.h:34
static constexpr uint64_t MAXTIMESTAMP
Definition IOVTime.h:59
static constexpr uint32_t MAXRUN
Definition IOVTime.h:49
void reset() noexcept
Definition IOVTime.cxx:108
bool isBoth() const noexcept
Definition IOVTime.h:116
IOVTime(uint64_t timestamp)
Definition IOVTime.h:94
void setRETime(uint64_t time) noexcept
Definition IOVTime.cxx:84
void setRunEvent(uint32_t run, uint32_t event) noexcept
Definition IOVTime.cxx:96
uint32_t event() const noexcept
Definition IOVTime.h:107
friend bool operator==(const IOVTime &lhs, const IOVTime &rhs) noexcept
Definition IOVTime.h:161
uint64_t timestamp() const noexcept
Definition IOVTime.h:109
IOVTime_type
Definition IOVTime.h:37
@ UNDEF
Definition IOVTime.h:38
@ TIMESTAMP
Definition IOVTime.h:39
@ BOTH
Definition IOVTime.h:41
@ RUN_EVT
Definition IOVTime.h:40
bool isValid() const noexcept
Definition IOVTime.cxx:117
static constexpr uint32_t MINEVENT
Definition IOVTime.h:51
static constexpr uint64_t MINTIMESTAMP
Definition IOVTime.h:57
static constexpr uint64_t UNDEFTIMESTAMP
Definition IOVTime.h:60
void setTimestamp(uint64_t timestamp) noexcept
Definition IOVTime.cxx:72
static constexpr uint64_t UNDEFRETIME
Definition IOVTime.h:55
uint32_t run() const noexcept
Definition IOVTime.h:106
static constexpr uint32_t MAXEVENT
Definition IOVTime.h:52
IOVTime_type m_status
Definition IOVTime.h:129
uint64_t re_time() const noexcept
Definition IOVTime.h:108
uint64_t m_time
Definition IOVTime.h:130
static constexpr uint32_t MINRUN
Definition IOVTime.h:45
bool isTimestamp() const noexcept
Definition IOVTime.h:112
friend std::ostream & operator<<(std::ostream &os, const IOVTime &rhs)
Definition IOVTime.cxx:192
friend std::strong_ordering operator<=>(const IOVTime &lhs, const IOVTime &rhs) noexcept
Definition IOVTime.h:154
IOVTime()
Definition IOVTime.h:92
uint64_t m_timestamp
Definition IOVTime.h:131
bool isRunEvent() const noexcept
Definition IOVTime.h:114
static constexpr uint64_t MAXRETIME
Definition IOVTime.h:54
STL namespace.
FmtContext::iterator format(const IOVTime &io, FmtContext &ctx) const
Definition IOVTime.h:143
int run(int argc, char *argv[])