| The Gaudi Framework v28r2-patches (bc4ad17a)

- 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 <tuple>
18 #include <stdint.h>
19
20
29 class EventIDBase {
30 public:
31
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 public:
38
39
41
42 EventIDBase() {};
43 EventIDBase(number_type run_number,
44 event_number_t event_number,
45 number_type time_stamp=UNDEFNUM,
46 number_type time_stamp_ns_offset=0,
47 number_type lumi_block=UNDEFNUM,
48 number_type bunch_crossing_id=0);
49 // Use default copy constructor.
50 virtual ~EventIDBase();
52
54 number_type run_number () const { return m_run_number; }
55
57 event_number_t event_number () const { return m_event_number; }
58
60 number_type time_stamp () const { return m_time_stamp; }
61
63 number_type time_stamp_ns_offset () const { return m_time_stamp_ns_offset; }
64
66 number_type lumi_block () const { return m_lumiBlock; }
67
69 number_type bunch_crossing_id () const { return m_bunch_crossing_id; }
70
72 void set_run_number (number_type runNumber) { m_run_number = runNumber; setRE();}
73
75 void set_event_number (event_number_t eventNumber) { m_event_number = eventNumber; }
76
78 void set_time_stamp (number_type timeStamp) { m_time_stamp = timeStamp; setTS();}
79
81 void set_time_stamp_ns_offset (number_type timeStampNs) {
82 m_time_stamp_ns_offset = timeStampNs;
83 }
84
86 void set_lumi_block (number_type lumiBlock) { m_lumiBlock = lumiBlock; setLE(); }
87
89 void set_bunch_crossing_id (number_type bcid) { m_bunch_crossing_id = bcid; }
90
92 friend bool operator<(const EventIDBase& lhs, const EventIDBase& rhs);
93 friend bool operator>(const EventIDBase& lhs, const EventIDBase& rhs);
94 friend bool operator==(const EventIDBase& lhs, const EventIDBase& rhs);
95 friend bool operator!=(const EventIDBase& lhs, const EventIDBase& rhs);
96 friend bool operator<=(const EventIDBase& lhs, const EventIDBase& rhs);
97 friend bool operator>=(const EventIDBase& lhs, const EventIDBase& rhs);
98
99 bool isRunEvent() const;
100 bool isTimeStamp() const;
101 bool isLumiEvent() const;
102 bool isValid() const;
103
105 friend std::ostream& operator<<(std::ostream& os, const EventIDBase& rhs);
106
107 class SortByTimeStamp {
108 public:
109 bool operator() ( const EventIDBase& t1, const EventIDBase& t2 ) const {
110 if (t1.time_stamp() == t2.time_stamp()) {
111 return t1.time_stamp_ns_offset() > t2.time_stamp_ns_offset();
112 } else {
113 return t1.time_stamp() > t2.time_stamp();
114 }
115 }
116 bool operator() ( const EventIDBase* t1, const EventIDBase* t2 ) const {
117 return ( SortByTimeStamp()(*t1,*t2) );
118 }
119 };
120
121 class SortByRunEvent {
122 public:
123 bool operator() ( const EventIDBase& t1, const EventIDBase& t2 ) const {
124 if (t1.run_number() == t2.run_number()) {
125 return t1.event_number() > t2.event_number();
126 } else {
127 return t1.run_number() > t2.run_number();
128 }
129 }
130 bool operator() ( const EventIDBase* t1, const EventIDBase* t2 ) const {
131 return ( SortByRunEvent()(*t1,*t2) );
132 }
133 };
134
135 class SortByLumiEvent {
136 public:
137 bool operator() ( const EventIDBase& t1, const EventIDBase& t2 ) const {
138 if (t1.lumi_block() == t2.lumi_block()) {
139 return t1.event_number() > t2.event_number();
140 } else {
141 return t1.lumi_block() > t2.lumi_block();
142 }
143 }
144 bool operator() ( const EventIDBase* t1, const EventIDBase* t2 ) const {
145 return ( SortByLumiEvent()(*t1,*t2) );
146 }
147 };
148
149 private:
150
151 enum Type {
152 Invalid = 0,
153 RunEvent = 1 << 1,
154 TimeStamp = 1 << 2,
155 LumiEvent = 1 << 3
156 };
157
158 unsigned m_type {Invalid};
159
160 void setRE() { m_type = m_type | RunEvent; }
161 void setTS() { m_type = m_type | TimeStamp; }
162 void setLE() { m_type = m_type | LumiEvent; }
163
165 number_type m_run_number {UNDEFNUM};
166
168 event_number_t m_event_number {UNDEFEVT};
169
171 number_type m_time_stamp {UNDEFNUM};
172
174 number_type m_time_stamp_ns_offset {UNDEFNUM};
175
178 number_type m_lumiBlock {UNDEFNUM};
179
181 number_type m_bunch_crossing_id {UNDEFNUM};
182
183 };
184
185 inline bool operator<(const EventIDBase& lhs, const EventIDBase& rhs) {
186 // first try ordering by timestamp if both are non-zero
187 // then try ordering by lumi/event if both have non-zero lumi
188 // then order by run/event
189
190 if (lhs.isTimeStamp() && rhs.isTimeStamp()) {
191 return (lhs.m_time_stamp < rhs.m_time_stamp);
192 } else {
193 if (lhs.isLumiEvent() && rhs.isLumiEvent()) {
194 return (std::tie(lhs.m_lumiBlock, lhs.m_event_number) <
195 std::tie(rhs.m_lumiBlock, rhs.m_event_number) );
196 } else {
197 return (std::tie(lhs.m_run_number, lhs.m_event_number) <
198 std::tie(rhs.m_run_number, rhs.m_event_number) );
199 }
200 }
201 }
202
203 inline bool operator==(const EventIDBase& lhs, const EventIDBase& rhs) {
204 // We assume that equality via run/event numbers is sufficient
205 return ( lhs.m_run_number == rhs.m_run_number &&
206 lhs.m_event_number == rhs.m_event_number );
207 }
208 inline bool operator>(const EventIDBase& lhs, const EventIDBase& rhs) {
209 return !( (lhs < rhs) || (lhs == rhs));
210 }
211 inline bool operator!=(const EventIDBase& lhs, const EventIDBase& rhs) {
212 return !(lhs == rhs);
213 }
214 inline bool operator<=(const EventIDBase& lhs, const EventIDBase& rhs) {
215 return !(lhs > rhs);
216 }
217 inline bool operator>=(const EventIDBase& lhs, const EventIDBase& rhs) {
218 return !(lhs < rhs);
219 }
220
221 inline std::ostream& operator<<(std::ostream& os, const EventIDBase& rhs) {
222 if (rhs.m_type == EventIDBase::Invalid) {
223 os << "[INVALID]";
224 return os;
225 }
226
227 os << "["
228 << rhs.m_run_number
229 << "," << rhs.m_event_number;
230
231 if ( rhs.isTimeStamp() != 0 ) {
232 os << "," << rhs.m_time_stamp << ":" << rhs.m_time_stamp_ns_offset;
233 }
234
235 if ( rhs.isLumiEvent() != 0) {
236 os << ",l:" << rhs.m_lumiBlock;
237 }
238
239 if ( rhs.m_bunch_crossing_id != 0) {
240 os << ",b:" << rhs.m_bunch_crossing_id;
241 }
242 os << "]";
243 return os;
244 }
245
246 #endif // EVENTINFO_EVENTID_H
EventIDBase::set_time_stamp
void set_time_stamp(number_type timeStamp)
set time stamp
Definition: EventIDBase.h:78
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:81
EventIDBase::setLE
void setLE()
Definition: EventIDBase.h:162
EventIDBase::m_type
unsigned m_type
Definition: EventIDBase.h:158
EventIDBase::set_lumi_block
void set_lumi_block(number_type lumiBlock)
set luminosity block identifier
Definition: EventIDBase.h:86
EventIDBase::set_run_number
void set_run_number(number_type runNumber)
set run number
Definition: EventIDBase.h:72
EventIDBase::bunch_crossing_id
number_type bunch_crossing_id() const
bunch crossing ID, 32 bit unsigned
Definition: EventIDBase.h:69
EventIDBase::m_lumiBlock
number_type m_lumiBlock
luminosity block number: the number which uniquely tags a luminosity block within a run ...
Definition: EventIDBase.h:178
std::tie
T tie(T...args)
EventIDBase::operator==
friend bool operator==(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:203
EventIDBase::operator<<
friend std::ostream & operator<<(std::ostream &os, const EventIDBase &rhs)
Extraction operators.
Definition: EventIDBase.h:221
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:174
EventIDBase::operator<=
friend bool operator<=(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:214
EventIDBase::set_bunch_crossing_id
void set_bunch_crossing_id(number_type bcid)
set bunch crossing ID
Definition: EventIDBase.h:89
EventIDBase::SortByTimeStamp
Definition: EventIDBase.h:107
EventIDBase::LumiEvent
Definition: EventIDBase.h:155
uint64_t
unsigned long long uint64_t
Definition: instrset.h:144
EventIDBase::m_bunch_crossing_id
number_type m_bunch_crossing_id
bunch crossing ID, 32 bit unsigned
Definition: EventIDBase.h:181
EventIDBase::setRE
void setRE()
Definition: EventIDBase.h:160
EventIDBase::lumi_block
number_type lumi_block() const
luminosity block identifier, 32 bit unsigned
Definition: EventIDBase.h:66
EventIDBase::m_event_number
event_number_t m_event_number
event number
Definition: EventIDBase.h:168
EventIDBase::EventIDBase
EventIDBase()
Definition: EventIDBase.h:42
EventIDBase::time_stamp
number_type time_stamp() const
time stamp - posix time in seconds from 1970, 32 bit unsigned
Definition: EventIDBase.h:60
EventIDBase::SortByLumiEvent
Definition: EventIDBase.h:135
EventIDBase::m_time_stamp
number_type m_time_stamp
posix time in seconds since 1970/01/01
Definition: EventIDBase.h:171
EventIDBase::isValid
bool isValid() const
Definition: EventIDBase.cpp:69
EventIDBase::Invalid
Definition: EventIDBase.h:152
EventIDBase::operator!=
friend bool operator!=(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:211
EventIDBase::m_run_number
number_type m_run_number
run number
Definition: EventIDBase.h:165
EventIDBase::SortByRunEvent
Definition: EventIDBase.h:121
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:54
EventIDBase::isRunEvent
bool isRunEvent() const
Definition: EventIDBase.cpp:54
EventIDBase::operator>
friend bool operator>(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:208
EventIDBase::isTimeStamp
bool isTimeStamp() const
Definition: EventIDBase.cpp:59
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:63
EventIDBase::RunEvent
Definition: EventIDBase.h:153
EventIDBase::operator<
friend bool operator<(const EventIDBase &lhs, const EventIDBase &rhs)
Comparison operators.
Definition: EventIDBase.h:185
EventIDBase::event_number_t
uint64_t event_number_t
Definition: EventIDBase.h:33
EventIDBase::isLumiEvent
bool isLumiEvent() const
Definition: EventIDBase.cpp:64
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:151
EventIDBase::operator>=
friend bool operator>=(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:217
EventIDBase::TimeStamp
Definition: EventIDBase.h:154
EventIDBase::~EventIDBase
virtual ~EventIDBase()
Definition: EventIDBase.cpp:50
std::ostream
STL class.
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:109
EventIDBase::setTS
void setTS()
Definition: EventIDBase.h:161
EventIDBase::event_number
event_number_t event_number() const
event number - 64 bit unsigned
Definition: EventIDBase.h:57