ATLAS Offline Software
Loading...
Searching...
No Matches
IOVTime.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5/*****************************************************************************
6 *
7 * IOVTime.cxx
8 * IOVSvc
9 *
10 * Author: Charles Leggett
11 * $Id: IOVTime.cxx,v 1.10 2005-10-05 13:42:31 schaffer Exp $
12 *
13 * Basic time unit for IOVSvc.
14 * Hold time as a combination of run and event numbers
15 *
16 *****************************************************************************/
17
19#include "GaudiKernel/MsgStream.h"
20#include "GaudiKernel/EventIDBase.h"
21
22//
24//
25
26IOVTime::IOVTime(uint32_t run, uint32_t event):
29{
30 m_time = ( (uint64_t) run << 32) + event;
31}
32
33/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
34
35IOVTime::IOVTime( uint32_t run, uint32_t event,
36 uint64_t time):
38{
39 m_time = ( (uint64_t) run << 32) + event;
40}
41
42/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
43
44IOVTime::IOVTime(const EventIDBase& eid)
45{
46 m_time = 0;
47 m_timestamp = eid.time_stamp()*1000000000LL + eid.time_stamp_ns_offset();
48
49 if (eid.isRunEvent()) {
50 m_time = ( (uint64_t) eid.run_number() << 32) + eid.event_number();
51 if (eid.isTimeStamp()) {
53 } else {
55 }
56 } else if (eid.isLumiEvent()) {
57 m_time = ( (uint64_t) eid.lumi_block() << 32) + eid.event_number();
58 if (eid.isTimeStamp()) {
60 } else {
62 }
63 } else {
65 }
66
67}
68
69/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
70
71void
72IOVTime::setTimestamp( uint64_t timestamp ) noexcept {
73 if (isRunEvent()) {
75 } else {
77 }
79}
80
81/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
82
83void
84IOVTime::setRETime( uint64_t time ) noexcept {
85 if (isTimestamp()) {
87 } else {
89 }
90 m_time = time;
91}
92
93/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
94
95void
96IOVTime::setRunEvent( uint32_t run, uint32_t event ) noexcept {
97 if (isTimestamp()) {
99 } else {
101 }
102 m_time = ( (uint64_t) run << 32) + event;
103}
104
105/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
106
107void
113
114/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
115
116bool
118
119 // Cannot have BOTH undefined
122 return 0 ;
123 }
124
125 // Check run/event to be < max
127 // event() can never be more than MAXEVENT, by construction.
128 if ( run() > IOVTime::MAXRUN /*|| event() > IOVTime::MAXEVENT*/ ) {
129 return 0;
130 }
131 }
132
133 // Check time < max
136 return 0;
137 }
138 }
139
142 // May have both timestamp and run/event set
143 // event() can never be more than MAXEVENT, by construction.
144 if ( run() > IOVTime::MAXRUN /*|| event() > IOVTime::MAXEVENT*/ ) {
145 return 0;
146 }
148 return 0;
149 }
150 }
151
152 return 1;
153
154}
155
156IOVTime::operator std::string () const {
157 std::ostringstream os;
158 os << "[";
159 if (isRunEvent()) {
160 os << (m_time>>32) << "," << ( m_time & 0xFFFFFFFF );
161 }
162 if (isTimestamp()) {
163 if (isRunEvent()) os << ":";
164 os << m_timestamp;
165 }
166 os << "]";
167 return os.str();
168}
169
170IOVTime::operator EventIDBase() const {
171 if (isBoth()) {
172 return EventIDBase(run(),EventIDBase::UNDEFEVT,
173 std::min(timestamp()/1000000000LL,(unsigned long long)(std::numeric_limits<unsigned int>::max()-1)),timestamp()%1000000000LL,
174 event());
175 } else if (isTimestamp()) {
176 return EventIDBase(EventIDBase::UNDEFNUM,EventIDBase::UNDEFEVT,
177 std::min(timestamp()/1000000000LL,(unsigned long long)(std::numeric_limits<unsigned int>::max()-1)),timestamp()%1000000000LL);
178 } else if (isRunEvent()) {
179 return EventIDBase(run(),EventIDBase::UNDEFEVT,
180 EventIDBase::UNDEFNUM,0,
181 event());
182 } else {
183 return EventIDBase();
184 }
185}
186
187MsgStream &operator << (MsgStream& os, const IOVTime& rhs) {
188 os << (std::string) rhs;
189 return os;
190}
191
192std::ostream& operator << (std::ostream& os, const IOVTime& rhs) {
193 os << (std::string) rhs;
194 return os;
195}
196
197// std::ostrstream& operator << (std::ostrstream& os, const IOVTime& rhs) {
198// os << (int) rhs.m_time << ": [" << (int) (rhs.m_time>>32) << ","
199// << (int) ( rhs.m_time & 0xFFFFFFFF ) << "]";
200// return os;
201// }
MsgStream & operator<<(MsgStream &os, const IOVTime &rhs)
Definition IOVTime.cxx:187
Basic time unit for IOVSvc.
static constexpr uint64_t MAXTIMESTAMP
Definition IOVTime.h:58
static constexpr uint32_t MAXRUN
Definition IOVTime.h:48
void reset() noexcept
Definition IOVTime.cxx:108
bool isBoth() const noexcept
Definition IOVTime.h:115
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:106
uint64_t timestamp() const noexcept
Definition IOVTime.h:108
@ UNDEF
Definition IOVTime.h:37
@ TIMESTAMP
Definition IOVTime.h:38
@ BOTH
Definition IOVTime.h:40
@ RUN_EVT
Definition IOVTime.h:39
bool isValid() const noexcept
Definition IOVTime.cxx:117
static constexpr uint64_t UNDEFTIMESTAMP
Definition IOVTime.h:59
void setTimestamp(uint64_t timestamp) noexcept
Definition IOVTime.cxx:72
static constexpr uint64_t UNDEFRETIME
Definition IOVTime.h:54
uint32_t run() const noexcept
Definition IOVTime.h:105
IOVTime_type m_status
Definition IOVTime.h:132
uint64_t m_time
Definition IOVTime.h:133
bool isTimestamp() const noexcept
Definition IOVTime.h:111
IOVTime()
Definition IOVTime.h:91
uint64_t m_timestamp
Definition IOVTime.h:134
bool isRunEvent() const noexcept
Definition IOVTime.h:113
Definition run.py:1