ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthenaKernel
src
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
18
#include "
AthenaKernel/IOVTime.h
"
19
#include "GaudiKernel/MsgStream.h"
20
#include "GaudiKernel/EventIDBase.h"
21
22
//
24
//
25
26
IOVTime::IOVTime
(uint32_t
run
, uint32_t
event
):
27
m_status
(
IOVTime
::
RUN_EVT
),
28
m_timestamp
(
IOVTime
::
UNDEFTIMESTAMP
)
29
{
30
m_time
= ( (uint64_t)
run
<< 32) +
event
;
31
}
32
33
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
34
35
IOVTime::IOVTime
( uint32_t
run
, uint32_t
event
,
36
uint64_t time):
37
m_status
(
IOVTime
::
BOTH
),
m_timestamp
(time)
38
{
39
m_time
= ( (uint64_t)
run
<< 32) +
event
;
40
}
41
42
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
43
44
IOVTime::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()) {
52
m_status
=
IOVTime::BOTH
;
53
}
else
{
54
m_status
=
IOVTime::RUN_EVT
;
55
}
56
}
else
if
(eid.isLumiEvent()) {
57
m_time
= ( (uint64_t) eid.lumi_block() << 32) + eid.event_number();
58
if
(eid.isTimeStamp()) {
59
m_status
=
IOVTime::BOTH
;
60
}
else
{
61
m_status
=
IOVTime::RUN_EVT
;
62
}
63
}
else
{
64
m_status
=
IOVTime::TIMESTAMP
;
65
}
66
67
}
68
69
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
70
71
void
72
IOVTime::setTimestamp
( uint64_t
timestamp
)
noexcept
{
73
if
(
isRunEvent
()) {
74
m_status
=
IOVTime::BOTH
;
75
}
else
{
76
m_status
=
IOVTime::TIMESTAMP
;
77
}
78
m_timestamp
=
timestamp
;
79
}
80
81
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
82
83
void
84
IOVTime::setRETime
( uint64_t time )
noexcept
{
85
if
(
isTimestamp
()) {
86
m_status
=
IOVTime::BOTH
;
87
}
else
{
88
m_status
=
IOVTime::RUN_EVT
;
89
}
90
m_time
= time;
91
}
92
93
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
94
95
void
96
IOVTime::setRunEvent
( uint32_t
run
, uint32_t
event
)
noexcept
{
97
if
(
isTimestamp
()) {
98
m_status
=
IOVTime::BOTH
;
99
}
else
{
100
m_status
=
IOVTime::RUN_EVT
;
101
}
102
m_time
= ( (uint64_t)
run
<< 32) +
event
;
103
}
104
105
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
106
107
void
108
IOVTime::reset
() noexcept {
109
m_status
=
IOVTime::UNDEF
;
110
m_time
=
IOVTime::UNDEFRETIME
;
111
m_timestamp
=
IOVTime::UNDEFTIMESTAMP
;
112
}
113
114
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
115
116
bool
117
IOVTime::isValid
()
const
noexcept {
118
119
// Cannot have BOTH undefined
120
if
(
m_timestamp
==
IOVTime::UNDEFTIMESTAMP
&&
121
m_time
==
IOVTime::UNDEFRETIME
) {
122
return
0 ;
123
}
124
125
// Check run/event to be < max
126
if
(
m_timestamp
==
IOVTime::UNDEFTIMESTAMP
) {
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
134
if
(
m_time
==
IOVTime::UNDEFRETIME
) {
135
if
(
m_timestamp
>
IOVTime::MAXTIMESTAMP
) {
136
return
0;
137
}
138
}
139
140
if
(
m_timestamp
!=
IOVTime::UNDEFTIMESTAMP
&&
141
m_time
!=
IOVTime::UNDEFRETIME
) {
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
}
147
if
(
m_timestamp
>
IOVTime::MAXTIMESTAMP
) {
148
return
0;
149
}
150
}
151
152
return
1;
153
154
}
155
156
IOVTime::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
170
IOVTime::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
187
MsgStream &
operator <<
(MsgStream& os,
const
IOVTime
& rhs) {
188
os << (std::string) rhs;
189
return
os;
190
}
191
192
std::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
// }
operator<<
MsgStream & operator<<(MsgStream &os, const IOVTime &rhs)
Definition
IOVTime.cxx:187
IOVTime.h
Basic time unit for IOVSvc.
IOVTime::MAXTIMESTAMP
static constexpr uint64_t MAXTIMESTAMP
Definition
IOVTime.h:58
IOVTime::MAXRUN
static constexpr uint32_t MAXRUN
Definition
IOVTime.h:48
IOVTime::reset
void reset() noexcept
Definition
IOVTime.cxx:108
IOVTime::isBoth
bool isBoth() const noexcept
Definition
IOVTime.h:115
IOVTime::setRETime
void setRETime(uint64_t time) noexcept
Definition
IOVTime.cxx:84
IOVTime::setRunEvent
void setRunEvent(uint32_t run, uint32_t event) noexcept
Definition
IOVTime.cxx:96
IOVTime::event
uint32_t event() const noexcept
Definition
IOVTime.h:106
IOVTime::timestamp
uint64_t timestamp() const noexcept
Definition
IOVTime.h:108
IOVTime::UNDEF
@ UNDEF
Definition
IOVTime.h:37
IOVTime::TIMESTAMP
@ TIMESTAMP
Definition
IOVTime.h:38
IOVTime::BOTH
@ BOTH
Definition
IOVTime.h:40
IOVTime::RUN_EVT
@ RUN_EVT
Definition
IOVTime.h:39
IOVTime::isValid
bool isValid() const noexcept
Definition
IOVTime.cxx:117
IOVTime::UNDEFTIMESTAMP
static constexpr uint64_t UNDEFTIMESTAMP
Definition
IOVTime.h:59
IOVTime::setTimestamp
void setTimestamp(uint64_t timestamp) noexcept
Definition
IOVTime.cxx:72
IOVTime::UNDEFRETIME
static constexpr uint64_t UNDEFRETIME
Definition
IOVTime.h:54
IOVTime::run
uint32_t run() const noexcept
Definition
IOVTime.h:105
IOVTime::m_status
IOVTime_type m_status
Definition
IOVTime.h:132
IOVTime::m_time
uint64_t m_time
Definition
IOVTime.h:133
IOVTime::isTimestamp
bool isTimestamp() const noexcept
Definition
IOVTime.h:111
IOVTime::IOVTime
IOVTime()
Definition
IOVTime.h:91
IOVTime::m_timestamp
uint64_t m_timestamp
Definition
IOVTime.h:134
IOVTime::isRunEvent
bool isRunEvent() const noexcept
Definition
IOVTime.h:113
const
run
int run(int argc, char *argv[])
Definition
ttree2hdf5.cxx:28
Generated on
for ATLAS Offline Software by
1.17.0