| The Gaudi Framework v29r1 (5cd95fa2)

- 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 <iomanip>
17 #include <iostream>
18 #include <stdint.h>
19 #include <tuple>
20
29 class EventIDBase
30 {
31 public:
32 typedef unsigned int number_type;
33 typedef uint64_t event_number_t;
34
35 static const number_type UNDEFNUM;
36 static const event_number_t UNDEFEVT;
37
38 public:
40
41 EventIDBase(){};
42 EventIDBase( number_type run_number, event_number_t event_number, number_type time_stamp = UNDEFNUM,
43 number_type time_stamp_ns_offset = 0, number_type lumi_block = UNDEFNUM,
44 number_type bunch_crossing_id = 0 );
45 // Use default copy constructor.
46 virtual ~EventIDBase();
48
50 number_type run_number() const { return m_run_number; }
51
53 event_number_t event_number() const { return m_event_number; }
54
56 number_type time_stamp() const { return m_time_stamp; }
57
59 number_type time_stamp_ns_offset() const { return m_time_stamp_ns_offset; }
60
62 number_type lumi_block() const { return m_lumi_block; }
63
65 number_type bunch_crossing_id() const { return m_bunch_crossing_id; }
66
68 void set_run_number( number_type runNumber )
69 {
70 m_run_number = runNumber;
71 if ( m_event_number != UNDEFEVT ) setRE();
72 if ( m_lumi_block != UNDEFNUM ) setRL();
73 }
74
76 void set_event_number( event_number_t eventNumber )
77 {
78 m_event_number = eventNumber;
79 if ( m_run_number != UNDEFNUM ) setRE();
80 if ( m_lumi_block != UNDEFNUM ) setLE();
81 }
82
84 void set_time_stamp( number_type timeStamp )
85 {
86 m_time_stamp = timeStamp;
87 setTS();
88 }
89
91 void set_time_stamp_ns_offset( number_type timeStampNs ) { m_time_stamp_ns_offset = timeStampNs; }
92
94 void set_lumi_block( number_type lumiBlock )
95 {
96 m_lumi_block = lumiBlock;
97 if ( m_run_number != UNDEFNUM ) setRL();
98 if ( m_event_number != UNDEFEVT ) setLE();
99 }
100
102 void set_bunch_crossing_id( number_type bcid ) { m_bunch_crossing_id = bcid; }
103
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 friend bool operator>=( const EventIDBase& lhs, const EventIDBase& rhs );
111
112 bool isRunEvent() const;
113 bool isTimeStamp() const;
114 bool isLumiEvent() const;
115 bool isRunLumi() const;
116 bool isValid() const;
117
119 friend std::ostream& operator<<( std::ostream& os, const EventIDBase& rhs );
120
121 class SortByTimeStamp
122 {
123 public:
124 bool operator()( const EventIDBase& t1, const EventIDBase& t2 ) const
125 {
126 if ( t1.time_stamp() == t2.time_stamp() ) {
127 return t1.time_stamp_ns_offset() > t2.time_stamp_ns_offset();
128 } else {
129 return t1.time_stamp() > t2.time_stamp();
130 }
131 }
132 bool operator()( const EventIDBase* t1, const EventIDBase* t2 ) const { return ( SortByTimeStamp()( *t1, *t2 ) ); }
133 };
134
135 class SortByRunEvent
136 {
137 public:
138 bool operator()( const EventIDBase& t1, const EventIDBase& t2 ) const
139 {
140 if ( t1.run_number() == t2.run_number() ) {
141 return t1.event_number() > t2.event_number();
142 } else {
143 return t1.run_number() > t2.run_number();
144 }
145 }
146 bool operator()( const EventIDBase* t1, const EventIDBase* t2 ) const { return ( SortByRunEvent()( *t1, *t2 ) ); }
147 };
148
149 class SortByLumiEvent
150 {
151 public:
152 bool operator()( const EventIDBase& t1, const EventIDBase& t2 ) const
153 {
154 if ( t1.lumi_block() == t2.lumi_block() ) {
155 return t1.event_number() > t2.event_number();
156 } else {
157 return t1.lumi_block() > t2.lumi_block();
158 }
159 }
160 bool operator()( const EventIDBase* t1, const EventIDBase* t2 ) const { return ( SortByLumiEvent()( *t1, *t2 ) ); }
161 };
162
163 class SortByRunLumi
164 {
165 public:
166 bool operator()( const EventIDBase& t1, const EventIDBase& t2 ) const
167 {
168 if ( t1.run_number() == t2.run_number() ) {
169 return t1.lumi_block() > t2.lumi_block();
170 } else {
171 return t1.run_number() > t2.run_number();
172 }
173 }
174 bool operator()( const EventIDBase* t1, const EventIDBase* t2 ) const { return ( SortByRunLumi()( *t1, *t2 ) ); }
175 };
176
177 private:
178 enum Type { Invalid = 0, RunEvent = 1 << 1, TimeStamp = 1 << 2, LumiEvent = 1 << 3, RunLumi = 1 << 4 };
179
180 unsigned m_type{Invalid};
181
182 void setRE() { m_type = m_type | RunEvent; }
183 void setTS() { m_type = m_type | TimeStamp; }
184 void setLE() { m_type = m_type | LumiEvent; }
185 void setRL() { m_type = m_type | RunLumi; }
186
188 number_type m_run_number{UNDEFNUM};
189
191 event_number_t m_event_number{UNDEFEVT};
192
194 number_type m_time_stamp{UNDEFNUM};
195
197 number_type m_time_stamp_ns_offset{UNDEFNUM};
198
201 number_type m_lumi_block{UNDEFNUM};
202
204 number_type m_bunch_crossing_id{UNDEFNUM};
205 };
206
207 inline bool operator<( const EventIDBase& lhs, const EventIDBase& rhs )
208 {
209 // first try ordering by timestamp if both are non-zero
210 // then try ordering by run/lumi/event
211 // this assumes that both EventIDBase have the same set of values defined.
212
213 if ( lhs.isTimeStamp() && rhs.isTimeStamp() ) {
214 return ( lhs.m_time_stamp < rhs.m_time_stamp );
215 } else {
216 return ( std::tie( lhs.m_run_number, lhs.m_lumi_block, lhs.m_event_number ) <
217 std::tie( rhs.m_run_number, rhs.m_lumi_block, rhs.m_event_number ) );
218 }
219 }
220
221 inline bool operator>( const EventIDBase& lhs, const EventIDBase& rhs )
222 {
223 // first try ordering by timestamp if both are non-zero
224 // then try ordering by run/lumi/event
225 // this assumes that both EventIDBase have the same set of values defined.
226
227 if ( lhs.isTimeStamp() && rhs.isTimeStamp() ) {
228 return ( lhs.m_time_stamp > rhs.m_time_stamp );
229 } else {
230 return ( std::tie( lhs.m_run_number, lhs.m_lumi_block, lhs.m_event_number ) >
231 std::tie( rhs.m_run_number, rhs.m_lumi_block, rhs.m_event_number ) );
232 }
233 }
234
235 inline bool operator==( const EventIDBase& lhs, const EventIDBase& rhs )
236 {
237 // We assume that equality via run/event/lumi numbers is sufficient
238 return ( lhs.m_run_number == rhs.m_run_number && lhs.m_event_number == rhs.m_event_number &&
239 lhs.m_lumi_block == rhs.m_lumi_block );
240 }
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 inline bool operator>=( const EventIDBase& lhs, const EventIDBase& rhs ) { return !( lhs < rhs ); }
244
245 inline std::ostream& operator<<( std::ostream& os, const EventIDBase& rhs )
246 {
247 if ( rhs.m_type == EventIDBase::Invalid ) {
248 os << "[INVALID]";
249 return os;
250 }
251
252 os << "[" << rhs.m_run_number;
253
254 if ( rhs.m_event_number != EventIDBase::UNDEFEVT ) {
255 os << "," << rhs.m_event_number;
256 }
257
258 if ( rhs.isTimeStamp() ) {
259 os << ",t:" << rhs.m_time_stamp;
260 if ( rhs.m_time_stamp_ns_offset != 0 ) {
261 os << "." << std::setfill( '0' ) << std::setw( 9 ) << rhs.m_time_stamp_ns_offset;
262 }
263 }
264
265 if ( rhs.isLumiEvent() || rhs.isRunLumi() ) {
266 os << ",l:" << rhs.m_lumi_block;
267 }
268
269 if ( rhs.m_bunch_crossing_id != 0 ) {
270 os << ",b:" << rhs.m_bunch_crossing_id;
271 }
272 os << "]";
273 return os;
274 }
275
276 #endif // EVENTINFO_EVENTID_H
EventIDBase::set_time_stamp
void set_time_stamp(number_type timeStamp)
set time stamp
Definition: EventIDBase.h:84
EventIDBase::UNDEFNUM
static const number_type UNDEFNUM
Definition: EventIDBase.h:35
EventIDBase::set_time_stamp_ns_offset
void set_time_stamp_ns_offset(number_type timeStampNs)
set time stamp in ns
Definition: EventIDBase.h:91
EventIDBase::setLE
void setLE()
Definition: EventIDBase.h:184
EventIDBase::m_type
unsigned m_type
Definition: EventIDBase.h:180
EventIDBase::SortByLumiEvent::operator()
bool operator()(const EventIDBase &t1, const EventIDBase &t2) const
Definition: EventIDBase.h:152
EventIDBase::SortByLumiEvent::operator()
bool operator()(const EventIDBase *t1, const EventIDBase *t2) const
Definition: EventIDBase.h:160
EventIDBase::set_lumi_block
void set_lumi_block(number_type lumiBlock)
set luminosity block identifier
Definition: EventIDBase.h:94
EventIDBase::set_run_number
void set_run_number(number_type runNumber)
set run number
Definition: EventIDBase.h:68
EventIDBase::bunch_crossing_id
number_type bunch_crossing_id() const
bunch crossing ID, 32 bit unsigned
Definition: EventIDBase.h:65
std::tie
T tie(T...args)
EventIDBase::operator==
friend bool operator==(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:235
EventIDBase::operator<<
friend std::ostream & operator<<(std::ostream &os, const EventIDBase &rhs)
Extraction operators.
Definition: EventIDBase.h:245
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:197
EventIDBase::isRunLumi
bool isRunLumi() const
Definition: EventIDBase.cpp:54
EventIDBase::operator<=
friend bool operator<=(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:242
EventIDBase::set_bunch_crossing_id
void set_bunch_crossing_id(number_type bcid)
set bunch crossing ID
Definition: EventIDBase.h:102
EventIDBase::SortByTimeStamp
Definition: EventIDBase.h:121
EventIDBase::LumiEvent
Definition: EventIDBase.h:178
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:204
EventIDBase::setRE
void setRE()
Definition: EventIDBase.h:182
EventIDBase::lumi_block
number_type lumi_block() const
luminosity block identifier, 32 bit unsigned
Definition: EventIDBase.h:62
EventIDBase::SortByRunLumi
Definition: EventIDBase.h:163
EventIDBase::m_event_number
event_number_t m_event_number
event number
Definition: EventIDBase.h:191
EventIDBase::RunLumi
Definition: EventIDBase.h:178
EventIDBase::EventIDBase
EventIDBase()
Definition: EventIDBase.h:41
EventIDBase::time_stamp
number_type time_stamp() const
time stamp - posix time in seconds from 1970, 32 bit unsigned
Definition: EventIDBase.h:56
EventIDBase::SortByRunLumi::operator()
bool operator()(const EventIDBase *t1, const EventIDBase *t2) const
Definition: EventIDBase.h:174
EventIDBase::setRL
void setRL()
Definition: EventIDBase.h:185
EventIDBase::SortByLumiEvent
Definition: EventIDBase.h:149
std::setw
T setw(T...args)
EventIDBase::m_time_stamp
number_type m_time_stamp
posix time in seconds since 1970/01/01
Definition: EventIDBase.h:194
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:201
EventIDBase::isValid
bool isValid() const
Definition: EventIDBase.cpp:56
EventIDBase::SortByRunEvent::operator()
bool operator()(const EventIDBase *t1, const EventIDBase *t2) const
Definition: EventIDBase.h:146
EventIDBase::SortByRunEvent::operator()
bool operator()(const EventIDBase &t1, const EventIDBase &t2) const
Definition: EventIDBase.h:138
EventIDBase::Invalid
Definition: EventIDBase.h:178
EventIDBase::operator!=
friend bool operator!=(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:241
EventIDBase::SortByRunLumi::operator()
bool operator()(const EventIDBase &t1, const EventIDBase &t2) const
Definition: EventIDBase.h:166
std::setfill
T setfill(T...args)
EventIDBase::m_run_number
number_type m_run_number
run number
Definition: EventIDBase.h:188
EventIDBase::SortByRunEvent
Definition: EventIDBase.h:135
EventIDBase::set_event_number
void set_event_number(event_number_t eventNumber)
set event number
Definition: EventIDBase.h:76
EventIDBase::run_number
number_type run_number() const
run number - 32 bit unsigned
Definition: EventIDBase.h:50
EventIDBase::isRunEvent
bool isRunEvent() const
Definition: EventIDBase.cpp:48
EventIDBase::operator>
friend bool operator>(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:221
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:59
EventIDBase::RunEvent
Definition: EventIDBase.h:178
EventIDBase::operator<
friend bool operator<(const EventIDBase &lhs, const EventIDBase &rhs)
Comparison operators.
Definition: EventIDBase.h:207
EventIDBase::event_number_t
uint64_t event_number_t
Definition: EventIDBase.h:33
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:29
EventIDBase::number_type
unsigned int number_type
Definition: EventIDBase.h:32
EventIDBase::Type
Type
Definition: EventIDBase.h:178
EventIDBase::operator>=
friend bool operator>=(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:243
EventIDBase::TimeStamp
Definition: EventIDBase.h:178
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:132
EventIDBase::UNDEFEVT
static const event_number_t UNDEFEVT
Definition: EventIDBase.h:36
EventIDBase::SortByTimeStamp::operator()
bool operator()(const EventIDBase &t1, const EventIDBase &t2) const
Definition: EventIDBase.h:124
EventIDBase::setTS
void setTS()
Definition: EventIDBase.h:183
EventIDBase::event_number
event_number_t event_number() const
event number - 64 bit unsigned
Definition: EventIDBase.h:53