| The Gaudi Framework v29r0 (ff2e7097)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

EventIDBase.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_EVENTIDBASE_H
2 #define GAUDIKERNEL_EVENTIDBASE_H 1
3
16 #include <iostream>
17 #include <stdint.h>
18 #include <tuple>
19
28 class EventIDBase
29 {
30 public:
31 typedef unsigned int number_type;
32 typedef uint64_t event_number_t;
33
34 static const number_type UNDEFNUM;
35 static const event_number_t UNDEFEVT;
36
37 public:
39
40 EventIDBase(){};
41 EventIDBase( number_type run_number, event_number_t event_number, number_type time_stamp = UNDEFNUM,
42 number_type time_stamp_ns_offset = 0, number_type lumi_block = UNDEFNUM,
43 number_type bunch_crossing_id = 0 );
44 // Use default copy constructor.
45 virtual ~EventIDBase();
47
49 number_type run_number() const { return m_run_number; }
50
52 event_number_t event_number() const { return m_event_number; }
53
55 number_type time_stamp() const { return m_time_stamp; }
56
58 number_type time_stamp_ns_offset() const { return m_time_stamp_ns_offset; }
59
61 number_type lumi_block() const { return m_lumi_block; }
62
64 number_type bunch_crossing_id() const { return m_bunch_crossing_id; }
65
67 void set_run_number( number_type runNumber )
68 {
69 m_run_number = runNumber;
70 if ( m_event_number != UNDEFEVT ) setRE();
71 if ( m_lumi_block != UNDEFNUM ) setRL();
72 }
73
75 void set_event_number( event_number_t eventNumber )
76 {
77 m_event_number = eventNumber;
78 if ( m_run_number != UNDEFNUM ) setRE();
79 if ( m_lumi_block != UNDEFNUM ) setLE();
80 }
81
83 void set_time_stamp( number_type timeStamp )
84 {
85 m_time_stamp = timeStamp;
86 setTS();
87 }
88
90 void set_time_stamp_ns_offset( number_type timeStampNs ) { m_time_stamp_ns_offset = timeStampNs; }
91
93 void set_lumi_block( number_type lumiBlock )
94 {
95 m_lumi_block = lumiBlock;
96 if ( m_run_number != UNDEFNUM ) setRL();
97 if ( m_event_number != UNDEFEVT ) setLE();
98 }
99
101 void set_bunch_crossing_id( number_type bcid ) { m_bunch_crossing_id = bcid; }
102
104 friend bool operator<( const EventIDBase& lhs, const EventIDBase& rhs );
105 friend bool operator>( const EventIDBase& lhs, const EventIDBase& rhs );
106 friend bool operator==( const EventIDBase& lhs, const EventIDBase& rhs );
107 friend bool operator!=( const EventIDBase& lhs, const EventIDBase& rhs );
108 friend bool operator<=( const EventIDBase& lhs, const EventIDBase& rhs );
109 friend bool operator>=( const EventIDBase& lhs, const EventIDBase& rhs );
110
111 bool isRunEvent() const;
112 bool isTimeStamp() const;
113 bool isLumiEvent() const;
114 bool isRunLumi() const;
115 bool isValid() const;
116
118 friend std::ostream& operator<<( std::ostream& os, const EventIDBase& rhs );
119
120 class SortByTimeStamp
121 {
122 public:
123 bool operator()( const EventIDBase& t1, const EventIDBase& t2 ) const
124 {
125 if ( t1.time_stamp() == t2.time_stamp() ) {
126 return t1.time_stamp_ns_offset() > t2.time_stamp_ns_offset();
127 } else {
128 return t1.time_stamp() > t2.time_stamp();
129 }
130 }
131 bool operator()( const EventIDBase* t1, const EventIDBase* t2 ) const { return ( SortByTimeStamp()( *t1, *t2 ) ); }
132 };
133
134 class SortByRunEvent
135 {
136 public:
137 bool operator()( const EventIDBase& t1, const EventIDBase& t2 ) const
138 {
139 if ( t1.run_number() == t2.run_number() ) {
140 return t1.event_number() > t2.event_number();
141 } else {
142 return t1.run_number() > t2.run_number();
143 }
144 }
145 bool operator()( const EventIDBase* t1, const EventIDBase* t2 ) const { return ( SortByRunEvent()( *t1, *t2 ) ); }
146 };
147
148 class SortByLumiEvent
149 {
150 public:
151 bool operator()( const EventIDBase& t1, const EventIDBase& t2 ) const
152 {
153 if ( t1.lumi_block() == t2.lumi_block() ) {
154 return t1.event_number() > t2.event_number();
155 } else {
156 return t1.lumi_block() > t2.lumi_block();
157 }
158 }
159 bool operator()( const EventIDBase* t1, const EventIDBase* t2 ) const { return ( SortByLumiEvent()( *t1, *t2 ) ); }
160 };
161
162 class SortByRunLumi
163 {
164 public:
165 bool operator()( const EventIDBase& t1, const EventIDBase& t2 ) const
166 {
167 if ( t1.run_number() == t2.run_number() ) {
168 return t1.lumi_block() > t2.lumi_block();
169 } else {
170 return t1.run_number() > t2.run_number();
171 }
172 }
173 bool operator()( const EventIDBase* t1, const EventIDBase* t2 ) const { return ( SortByRunLumi()( *t1, *t2 ) ); }
174 };
175
176 private:
177 enum Type { Invalid = 0, RunEvent = 1 << 1, TimeStamp = 1 << 2, LumiEvent = 1 << 3, RunLumi = 1 << 4 };
178
179 unsigned m_type{Invalid};
180
181 void setRE() { m_type = m_type | RunEvent; }
182 void setTS() { m_type = m_type | TimeStamp; }
183 void setLE() { m_type = m_type | LumiEvent; }
184 void setRL() { m_type = m_type | RunLumi; }
185
187 number_type m_run_number{UNDEFNUM};
188
190 event_number_t m_event_number{UNDEFEVT};
191
193 number_type m_time_stamp{UNDEFNUM};
194
196 number_type m_time_stamp_ns_offset{UNDEFNUM};
197
200 number_type m_lumi_block{UNDEFNUM};
201
203 number_type m_bunch_crossing_id{UNDEFNUM};
204 };
205
206 inline bool operator<( const EventIDBase& lhs, const EventIDBase& rhs )
207 {
208 // first try ordering by timestamp if both are non-zero
209 // then try ordering by run/lumi/event
210 // this assumes that both EventIDBase have the same set of values defined.
211
212 if ( lhs.isTimeStamp() && rhs.isTimeStamp() ) {
213 return ( lhs.m_time_stamp < rhs.m_time_stamp );
214 } else {
215 return ( std::tie( lhs.m_run_number, lhs.m_lumi_block, lhs.m_event_number ) <
216 std::tie( rhs.m_run_number, rhs.m_lumi_block, rhs.m_event_number ) );
217 }
218 }
219
220 inline bool operator>( const EventIDBase& lhs, const EventIDBase& rhs )
221 {
222 // first try ordering by timestamp if both are non-zero
223 // then try ordering by run/lumi/event
224 // this assumes that both EventIDBase have the same set of values defined.
225
226 if ( lhs.isTimeStamp() && rhs.isTimeStamp() ) {
227 return ( lhs.m_time_stamp > rhs.m_time_stamp );
228 } else {
229 return ( std::tie( lhs.m_run_number, lhs.m_lumi_block, lhs.m_event_number ) >
230 std::tie( rhs.m_run_number, rhs.m_lumi_block, rhs.m_event_number ) );
231 }
232 }
233
234 inline bool operator==( const EventIDBase& lhs, const EventIDBase& rhs )
235 {
236 // We assume that equality via run/event/lumi numbers is sufficient
237 return ( lhs.m_run_number == rhs.m_run_number && lhs.m_event_number == rhs.m_event_number &&
238 lhs.m_lumi_block == rhs.m_lumi_block );
239 }
240 inline bool operator!=( const EventIDBase& lhs, const EventIDBase& rhs ) { return !( lhs == rhs ); }
241 inline bool operator<=( const EventIDBase& lhs, const EventIDBase& rhs ) { return !( lhs > rhs ); }
242 inline bool operator>=( const EventIDBase& lhs, const EventIDBase& rhs ) { return !( lhs < rhs ); }
243
244 inline std::ostream& operator<<( std::ostream& os, const EventIDBase& rhs )
245 {
246 if ( rhs.m_type == EventIDBase::Invalid ) {
247 os << "[INVALID]";
248 return os;
249 }
250
251 os << "[" << rhs.m_run_number << "," << rhs.m_event_number;
252
253 if ( rhs.isTimeStamp() ) {
254 os << "," << rhs.m_time_stamp << ":" << rhs.m_time_stamp_ns_offset;
255 }
256
257 if ( rhs.isLumiEvent() || rhs.isRunLumi() ) {
258 os << ",l:" << rhs.m_lumi_block;
259 }
260
261 if ( rhs.m_bunch_crossing_id != 0 ) {
262 os << ",b:" << rhs.m_bunch_crossing_id;
263 }
264 os << "]";
265 return os;
266 }
267
268 #endif // EVENTINFO_EVENTID_H
EventIDBase::set_time_stamp
void set_time_stamp(number_type timeStamp)
set time stamp
Definition: EventIDBase.h:83
EventIDBase::UNDEFNUM
static const number_type UNDEFNUM
Definition: EventIDBase.h:34
EventIDBase::set_time_stamp_ns_offset
void set_time_stamp_ns_offset(number_type timeStampNs)
set time stamp in ns
Definition: EventIDBase.h:90
EventIDBase::setLE
void setLE()
Definition: EventIDBase.h:183
EventIDBase::m_type
unsigned m_type
Definition: EventIDBase.h:179
EventIDBase::SortByLumiEvent::operator()
bool operator()(const EventIDBase &t1, const EventIDBase &t2) const
Definition: EventIDBase.h:151
EventIDBase::SortByLumiEvent::operator()
bool operator()(const EventIDBase *t1, const EventIDBase *t2) const
Definition: EventIDBase.h:159
EventIDBase::set_lumi_block
void set_lumi_block(number_type lumiBlock)
set luminosity block identifier
Definition: EventIDBase.h:93
EventIDBase::set_run_number
void set_run_number(number_type runNumber)
set run number
Definition: EventIDBase.h:67
EventIDBase::bunch_crossing_id
number_type bunch_crossing_id() const
bunch crossing ID, 32 bit unsigned
Definition: EventIDBase.h:64
std::tie
T tie(T...args)
EventIDBase::operator==
friend bool operator==(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:234
EventIDBase::operator<<
friend std::ostream & operator<<(std::ostream &os, const EventIDBase &rhs)
Extraction operators.
Definition: EventIDBase.h:244
EventIDBase::m_time_stamp_ns_offset
number_type m_time_stamp_ns_offset
time stamp ns - ns time offset for time_stamp, 32 bit unsigned
Definition: EventIDBase.h:196
EventIDBase::isRunLumi
bool isRunLumi() const
Definition: EventIDBase.cpp:54
EventIDBase::operator<=
friend bool operator<=(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:241
EventIDBase::set_bunch_crossing_id
void set_bunch_crossing_id(number_type bcid)
set bunch crossing ID
Definition: EventIDBase.h:101
EventIDBase::SortByTimeStamp
Definition: EventIDBase.h:120
EventIDBase::LumiEvent
Definition: EventIDBase.h:177
uint64_t
unsigned long long uint64_t
Definition: instrset.h:143
EventIDBase::m_bunch_crossing_id
number_type m_bunch_crossing_id
bunch crossing ID, 32 bit unsigned
Definition: EventIDBase.h:203
EventIDBase::setRE
void setRE()
Definition: EventIDBase.h:181
EventIDBase::lumi_block
number_type lumi_block() const
luminosity block identifier, 32 bit unsigned
Definition: EventIDBase.h:61
EventIDBase::SortByRunLumi
Definition: EventIDBase.h:162
EventIDBase::m_event_number
event_number_t m_event_number
event number
Definition: EventIDBase.h:190
EventIDBase::RunLumi
Definition: EventIDBase.h:177
EventIDBase::EventIDBase
EventIDBase()
Definition: EventIDBase.h:40
EventIDBase::time_stamp
number_type time_stamp() const
time stamp - posix time in seconds from 1970, 32 bit unsigned
Definition: EventIDBase.h:55
EventIDBase::SortByRunLumi::operator()
bool operator()(const EventIDBase *t1, const EventIDBase *t2) const
Definition: EventIDBase.h:173
EventIDBase::setRL
void setRL()
Definition: EventIDBase.h:184
EventIDBase::SortByLumiEvent
Definition: EventIDBase.h:148
EventIDBase::m_time_stamp
number_type m_time_stamp
posix time in seconds since 1970/01/01
Definition: EventIDBase.h:193
EventIDBase::m_lumi_block
number_type m_lumi_block
luminosity block number: the number which uniquely tags a luminosity block within a run ...
Definition: EventIDBase.h:200
EventIDBase::isValid
bool isValid() const
Definition: EventIDBase.cpp:56
EventIDBase::SortByRunEvent::operator()
bool operator()(const EventIDBase *t1, const EventIDBase *t2) const
Definition: EventIDBase.h:145
EventIDBase::SortByRunEvent::operator()
bool operator()(const EventIDBase &t1, const EventIDBase &t2) const
Definition: EventIDBase.h:137
EventIDBase::Invalid
Definition: EventIDBase.h:177
EventIDBase::operator!=
friend bool operator!=(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:240
EventIDBase::SortByRunLumi::operator()
bool operator()(const EventIDBase &t1, const EventIDBase &t2) const
Definition: EventIDBase.h:165
EventIDBase::m_run_number
number_type m_run_number
run number
Definition: EventIDBase.h:187
EventIDBase::SortByRunEvent
Definition: EventIDBase.h:134
EventIDBase::set_event_number
void set_event_number(event_number_t eventNumber)
set event number
Definition: EventIDBase.h:75
EventIDBase::run_number
number_type run_number() const
run number - 32 bit unsigned
Definition: EventIDBase.h:49
EventIDBase::isRunEvent
bool isRunEvent() const
Definition: EventIDBase.cpp:48
EventIDBase::operator>
friend bool operator>(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:220
EventIDBase::isTimeStamp
bool isTimeStamp() const
Definition: EventIDBase.cpp:50
EventIDBase::time_stamp_ns_offset
number_type time_stamp_ns_offset() const
time stamp ns - ns time offset for time_stamp, 32 bit unsigned
Definition: EventIDBase.h:58
EventIDBase::RunEvent
Definition: EventIDBase.h:177
EventIDBase::operator<
friend bool operator<(const EventIDBase &lhs, const EventIDBase &rhs)
Comparison operators.
Definition: EventIDBase.h:206
EventIDBase::event_number_t
uint64_t event_number_t
Definition: EventIDBase.h:32
EventIDBase::isLumiEvent
bool isLumiEvent() const
Definition: EventIDBase.cpp:52
EventIDBase
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
Definition: EventIDBase.h:28
EventIDBase::number_type
unsigned int number_type
Definition: EventIDBase.h:31
EventIDBase::Type
Type
Definition: EventIDBase.h:177
EventIDBase::operator>=
friend bool operator>=(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:242
EventIDBase::TimeStamp
Definition: EventIDBase.h:177
EventIDBase::~EventIDBase
virtual ~EventIDBase()
Definition: EventIDBase.cpp:46
std::ostream
STL class.
EventIDBase::SortByTimeStamp::operator()
bool operator()(const EventIDBase *t1, const EventIDBase *t2) const
Definition: EventIDBase.h:131
EventIDBase::UNDEFEVT
static const event_number_t UNDEFEVT
Definition: EventIDBase.h:35
EventIDBase::SortByTimeStamp::operator()
bool operator()(const EventIDBase &t1, const EventIDBase &t2) const
Definition: EventIDBase.h:123
EventIDBase::setTS
void setTS()
Definition: EventIDBase.h:182
EventIDBase::event_number
event_number_t event_number() const
event number - 64 bit unsigned
Definition: EventIDBase.h:52