ATLAS Offline Software
IOVTime.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 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 
27  m_status(IOVTime::RUN_EVT),
28  m_timestamp(IOVTime::UNDEFTIMESTAMP)
29 {
30  m_time = ( (uint64_t) run << 32) + event;
31 }
32 
33 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
34 
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()) {
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 
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
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
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 {
112 }
113 
114 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
115 
116 bool
118 
119  // Cannot have BOTH undefined
122  return 0 ;
123  }
124 
125  // Check run/event to be < max
127  if ( run() > IOVTime::MAXRUN || event() > IOVTime::MAXEVENT ) {
128  return 0;
129  }
130  }
131 
132  // Check time < max
133  if (m_time == IOVTime::UNDEFRETIME) {
135  return 0;
136  }
137  }
138 
141  // May have both timestamp and run/event set
142  if ( run() > IOVTime::MAXRUN || event() > IOVTime::MAXEVENT ) {
143  return 0;
144  }
146  return 0;
147  }
148  }
149 
150  return 1;
151 
152 }
153 
154 IOVTime::operator std::string () const {
155  std::ostringstream os;
156  os << "[";
157  if (isRunEvent()) {
158  os << (m_time>>32) << "," << ( m_time & 0xFFFFFFFF );
159  }
160  if (isTimestamp()) {
161  if (isRunEvent()) os << ":";
162  os << m_timestamp;
163  }
164  os << "]";
165  return os.str();
166 }
167 
168 IOVTime::operator EventIDBase() const {
169  if (isBoth()) {
170  return EventIDBase(run(),EventIDBase::UNDEFEVT,
171  std::min(timestamp()/1000000000LL,(unsigned long long)(std::numeric_limits<unsigned int>::max()-1)),timestamp()%1000000000LL,
172  event());
173  } else if (isTimestamp()) {
174  return EventIDBase(EventIDBase::UNDEFNUM,EventIDBase::UNDEFEVT,
175  std::min(timestamp()/1000000000LL,(unsigned long long)(std::numeric_limits<unsigned int>::max()-1)),timestamp()%1000000000LL);
176  } else if (isRunEvent()) {
177  return EventIDBase(run(),EventIDBase::UNDEFEVT,
178  EventIDBase::UNDEFNUM,0,
179  event());
180  } else {
181  return EventIDBase();
182  }
183 }
184 
185 MsgStream &operator << (MsgStream& os, const IOVTime& rhs) {
186  os << (std::string) rhs;
187  return os;
188 }
189 
190 std::ostream& operator << (std::ostream& os, const IOVTime& rhs) {
191  os << (std::string) rhs;
192  return os;
193 }
194 
195 // std::ostrstream& operator << (std::ostrstream& os, const IOVTime& rhs) {
196 // os << (int) rhs.m_time << ": [" << (int) (rhs.m_time>>32) << ","
197 // << (int) ( rhs.m_time & 0xFFFFFFFF ) << "]";
198 // return os;
199 // }
IOVTime::BOTH
@ BOTH
Definition: IOVTime.h:40
max
#define max(a, b)
Definition: cfImp.cxx:41
IOVTime::MAXRUN
static constexpr uint32_t MAXRUN
Definition: IOVTime.h:48
IOVTime::event
uint32_t event() const noexcept
Definition: IOVTime.h:106
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
run
int run(int argc, char *argv[])
Definition: ttree2hdf5.cxx:28
IOVTime::RUN_EVT
@ RUN_EVT
Definition: IOVTime.h:39
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
IOVTime.h
Basic time unit for IOVSvc. Hold time as a combination of run and event numbers.
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
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
python.LArBadChannelDBAlg.xFFFFFFFF
xFFFFFFFF
Definition: LArBadChannelDBAlg.py:73
operator<<
MsgStream & operator<<(MsgStream &os, const IOVTime &rhs)
Definition: IOVTime.cxx:185
IOVTime::reset
void reset() noexcept
Definition: IOVTime.cxx:108
IOVTime::MAXTIMESTAMP
static constexpr uint64_t MAXTIMESTAMP
Definition: IOVTime.h:58
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
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::setTimestamp
void setTimestamp(uint64_t timestamp) noexcept
Definition: IOVTime.cxx:72
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
IOVTime::run
uint32_t run() const noexcept
Definition: IOVTime.h:105
IOVTime::UNDEF
@ UNDEF
Definition: IOVTime.h:37
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::setRunEvent
void setRunEvent(uint32_t run, uint32_t event) noexcept
Definition: IOVTime.cxx:96
IOVTime::TIMESTAMP
@ TIMESTAMP
Definition: IOVTime.h:38
IOVTime::m_time
uint64_t m_time
Definition: IOVTime.h:133