| The Gaudi Framework v32r1 (f65d50dc)

EventIDBase.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_EVENTIDBASE_H
2 #define GAUDIKERNEL_EVENTIDBASE_H 1
3
16 #include <cstdint>
17 #include <iomanip>
18 #include <iostream>
19 #include <tuple>
20
21 #include "GaudiKernel/compose.h"
22 namespace details {
23 template <typename lambda>
24 struct arg_helper : public arg_helper<decltype( &lambda::operator() )> {};
25 template <typename T, typename Ret, typename Arg>
26 struct arg_helper<Ret ( T::* )( Arg ) const> {
27 using type = Arg;
28 };
29
30 // given a unary lambda whose argument is of type Arg_t,
31 // argument_t<lambda> will be equal to Arg_t
32 template <typename lambda>
33 using argument_t = typename arg_helper<lambda>::type;
34
35 template <typename Fun>
36 auto add_deref( Fun f ) {
37 return compose( f, [=]( auto*... p ) { return f( *p... ); } );
38 }
39
40 template <typename Proj, typename Cmp = std::greater<>>
41 auto make_cmp( Proj p, Cmp cmp = {} ) {
42 static_assert( std::is_reference_v<argument_t<Proj>>, "must be a reference" );
43 static_assert( std::is_const_v<std::remove_reference_t<argument_t<Proj>>>, "must be const" );
44 return [=]( argument_t<Proj> lhs, argument_t<Proj> rhs ) { return cmp( p( lhs ), p( rhs ) ); };
45 }
46 } // namespace details
47
56 class EventIDBase {
57 public:
58 typedef unsigned int number_type;
59 typedef uint64_t event_number_t;
60
61 static const number_type UNDEFNUM;
62 static const event_number_t UNDEFEVT;
63
64 friend class EventIDRange;
65
66 public:
68
69 EventIDBase(){};
70 EventIDBase( number_type run_number, event_number_t event_number, number_type time_stamp = UNDEFNUM,
71 number_type time_stamp_ns_offset = 0, number_type lumi_block = UNDEFNUM,
72 number_type bunch_crossing_id = 0 );
73
74 EventIDBase( std::tuple<number_type, number_type, event_number_t> run_lumi_ev,
75 std::tuple<number_type, number_type> time_stamp, number_type bunch_crossing_id );
76
77 // Use default copy constructor.
78 virtual ~EventIDBase() = default;
80
82 number_type run_number() const { return m_run_number; }
83
85 event_number_t event_number() const { return m_event_number; }
86
88 number_type time_stamp() const { return m_time_stamp; }
89
91 number_type time_stamp_ns_offset() const { return m_time_stamp_ns_offset; }
92
94 number_type lumi_block() const { return m_lumi_block; }
95
97 number_type bunch_crossing_id() const { return m_bunch_crossing_id; }
98
100 void set_run_number( number_type runNumber ) {
101 m_run_number = runNumber;
102 if ( m_event_number != UNDEFEVT ) setRE();
103 if ( m_lumi_block != UNDEFNUM ) setRL();
104 }
105
107 void set_event_number( event_number_t eventNumber ) {
108 m_event_number = eventNumber;
109 if ( m_run_number != UNDEFNUM ) setRE();
110 if ( m_lumi_block != UNDEFNUM ) setLE();
111 }
112
114 void set_time_stamp( number_type timeStamp ) {
115 m_time_stamp = timeStamp;
116 setTS();
117 }
118
120 void set_time_stamp_ns_offset( number_type timeStampNs ) { m_time_stamp_ns_offset = timeStampNs; }
121
123 void set_lumi_block( number_type lumiBlock ) {
124 m_lumi_block = lumiBlock;
125 if ( m_run_number != UNDEFNUM ) setRL();
126 if ( m_event_number != UNDEFEVT ) setLE();
127 }
128
130 void set_bunch_crossing_id( number_type bcid ) { m_bunch_crossing_id = bcid; }
131
133 friend bool operator==( const EventIDBase& lhs, const EventIDBase& rhs );
134 friend bool operator<( const EventIDBase& lhs, const EventIDBase& rhs );
135 friend bool operator>( const EventIDBase& lhs, const EventIDBase& rhs ) { return rhs < lhs; }
136 friend bool operator!=( const EventIDBase& lhs, const EventIDBase& rhs ) { return !( lhs == rhs ); }
137 friend bool operator<=( const EventIDBase& lhs, const EventIDBase& rhs ) { return !( lhs > rhs ); }
138 friend bool operator>=( const EventIDBase& lhs, const EventIDBase& rhs ) { return !( lhs < rhs ); }
139
140 friend EventIDBase min( const EventIDBase& lhs, const EventIDBase& rhs );
141 friend EventIDBase max( const EventIDBase& lhs, const EventIDBase& rhs );
142
143 bool isRunEvent() const { return m_type & RunEvent; }
144 bool isTimeStamp() const { return m_type & TimeStamp; }
145 bool isLumiEvent() const { return m_type & LumiEvent; }
146 bool isRunLumi() const { return m_type & RunLumi; }
147 bool isValid() const { return m_type != Invalid; }
148
150 friend std::ostream& operator<<( std::ostream& os, const EventIDBase& rhs );
151
152 static auto SortByTimeStamp() {
153 return ::details::add_deref( ::details::make_cmp(
154 []( const EventIDBase& e ) { return std::tie( e.m_time_stamp, e.m_time_stamp_ns_offset ); } ) );
155 };
156
157 static auto SortByRunEvent() {
158 return ::details::add_deref(
159 ::details::make_cmp( []( const EventIDBase& e ) { return std::tie( e.m_run_number, e.m_event_number ); } ) );
160 };
161
162 static auto SortByLumiEvent() {
163 return ::details::add_deref(
164 ::details::make_cmp( []( const EventIDBase& e ) { return std::tie( e.m_lumi_block, e.m_event_number ); } ) );
165 };
166
167 static auto SortByRunLumi() {
168 return ::details::add_deref(
169 ::details::make_cmp( []( const EventIDBase& e ) { return std::tie( e.m_run_number, e.m_lumi_block ); } ) );
170 };
171
172 private:
173 enum Type { Invalid = 0, RunEvent = 1 << 1, TimeStamp = 1 << 2, LumiEvent = 1 << 3, RunLumi = 1 << 4 };
174
175 unsigned m_type{Invalid};
176
177 void setRE() { m_type |= RunEvent; }
178 void setTS() { m_type |= TimeStamp; }
179 void setLE() { m_type |= LumiEvent; }
180 void setRL() { m_type |= RunLumi; }
181
183 number_type m_run_number{UNDEFNUM};
184
186 event_number_t m_event_number{UNDEFEVT};
187
189 number_type m_time_stamp{UNDEFNUM};
190
192 number_type m_time_stamp_ns_offset{UNDEFNUM};
193
196 number_type m_lumi_block{UNDEFNUM};
197
199 number_type m_bunch_crossing_id{UNDEFNUM};
200 };
201
202 inline EventIDBase min( const EventIDBase& lhs, const EventIDBase& rhs ) {
203
204 //"min" is easy b/c the numbers denoting invalidty for TS or Run/Event/LB are the
205 // largest possible numbers, so naturally larger than any valid number
206
207 return EventIDBase( std::min( std::tie( lhs.m_run_number, lhs.m_lumi_block, lhs.m_event_number ),
208 std::tie( rhs.m_run_number, rhs.m_lumi_block, rhs.m_event_number ) ),
209 std::min( std::tie( lhs.m_time_stamp, lhs.m_time_stamp_ns_offset ),
210 std::tie( rhs.m_time_stamp, rhs.m_time_stamp_ns_offset ) ),
211 lhs.bunch_crossing_id() // bcid doesn't really matter here
212 );
213 }
214
215 inline EventIDBase max( const EventIDBase& lhs, const EventIDBase& rhs ) {
216
217 //"max" is much trickier because we need to handle invalid number explicilty by
218 // checking if a EventIDBase is TS or Run/Lumi
219
220 std::tuple<EventIDBase::number_type, EventIDBase::number_type, EventIDBase::event_number_t> run_lumi_ev;
221 std::tuple<EventIDBase::number_type, EventIDBase::number_type> time_stamp;
222
223 if ( lhs.isTimeStamp() && rhs.isTimeStamp() ) { // both time-stamp, compare them
224 time_stamp = std::max( std::tie( lhs.m_time_stamp, lhs.m_time_stamp_ns_offset ),
225 std::tie( rhs.m_time_stamp, rhs.m_time_stamp_ns_offset ) );
226 } else if ( lhs.isTimeStamp() ) { // only lhs time-stamp: Use it
227 time_stamp = std::tie( lhs.m_time_stamp, lhs.m_time_stamp_ns_offset );
228 } else { // otherwise use rhs time-stamp which might be UNDEFNUM (in case both input values are Run-Lumi only)
229 time_stamp = std::tie( rhs.m_time_stamp, rhs.m_time_stamp_ns_offset );
230 }
231
232 if ( lhs.isRunLumi() && rhs.isRunLumi() ) { // both run-lumi, compare them
233 run_lumi_ev = std::max( std::tie( lhs.m_run_number, lhs.m_lumi_block, lhs.m_event_number ),
234 std::tie( rhs.m_run_number, rhs.m_lumi_block, rhs.m_event_number ) );
235
236 } else if ( lhs.isRunLumi() ) { // only lhs run-lumi: Use it
237 run_lumi_ev = std::tie( lhs.m_run_number, lhs.m_lumi_block, lhs.m_event_number );
238 } else { // otherwise use rhs run-lumi which might be UNDEFNUM (in case both input values are TS-only)
239 run_lumi_ev = std::tie( rhs.m_run_number, rhs.m_lumi_block, rhs.m_event_number );
240 }
241
242 return EventIDBase( run_lumi_ev, time_stamp, lhs.bunch_crossing_id() );
243 }
244
245 inline bool operator<( const EventIDBase& lhs, const EventIDBase& rhs ) {
246 // first try ordering by timestamp if both are non-zero
247 // then try ordering by run/lumi/event
248 // this assumes that both EventIDBase have the same set of values defined.
249
250 if ( lhs.isTimeStamp() && rhs.isTimeStamp() ) {
251 return lhs.m_time_stamp < rhs.m_time_stamp;
252 } else {
253 return std::tie( lhs.m_run_number, lhs.m_lumi_block, lhs.m_event_number ) <
254 std::tie( rhs.m_run_number, rhs.m_lumi_block, rhs.m_event_number );
255 }
256 }
257
258 inline bool operator==( const EventIDBase& lhs, const EventIDBase& rhs ) {
259 // We assume that equality via run/event/lumi numbers is sufficient
260 return ( lhs.m_run_number == rhs.m_run_number && lhs.m_event_number == rhs.m_event_number &&
261 lhs.m_lumi_block == rhs.m_lumi_block );
262 }
263
264 inline std::ostream& operator<<( std::ostream& os, const EventIDBase& rhs ) {
265 if ( rhs.m_type == EventIDBase::Invalid ) return os << "[INVALID]";
266
267 const char* separator = "";
268 os << "[";
269 if ( rhs.m_run_number != EventIDBase::UNDEFNUM ) {
270 os << rhs.m_run_number;
271 separator = ",";
272 }
273
274 if ( rhs.m_event_number != EventIDBase::UNDEFEVT ) {
275 os << separator << rhs.m_event_number;
276 separator = ",";
277 }
278
279 if ( rhs.isTimeStamp() ) {
280 os << separator << "t:" << rhs.m_time_stamp;
281 if ( rhs.m_time_stamp_ns_offset != 0 ) {
282 os << "." << std::setfill( '0' ) << std::setw( 9 ) << rhs.m_time_stamp_ns_offset;
283 }
284 separator = ",";
285 }
286
287 if ( rhs.isLumiEvent() || rhs.isRunLumi() ) {
288 os << separator << "l:" << rhs.m_lumi_block;
289 separator = ",";
290 }
291
292 if ( rhs.m_bunch_crossing_id != 0 ) { os << separator << "b:" << rhs.m_bunch_crossing_id; }
293 os << "]";
294 return os;
295 }
296
297 #endif // EVENTINFO_EVENTID_H
EventIDBase::set_time_stamp
void set_time_stamp(number_type timeStamp)
set time stamp
Definition: EventIDBase.h:114
EventIDBase::UNDEFNUM
static const number_type UNDEFNUM
Definition: EventIDBase.h:61
operator<<
std::ostream & operator<<(std::ostream &os, const EventIDBase &rhs)
Definition: EventIDBase.h:264
EventIDBase::set_time_stamp_ns_offset
void set_time_stamp_ns_offset(number_type timeStampNs)
set time stamp in ns
Definition: EventIDBase.h:120
EventIDBase::max
friend EventIDBase max(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:215
EventIDBase::setLE
void setLE()
Definition: EventIDBase.h:179
EventIDBase::m_type
unsigned m_type
Definition: EventIDBase.h:175
EventIDBase::isRunLumi
bool isRunLumi() const
Definition: EventIDBase.h:146
EventIDBase::SortByLumiEvent
static auto SortByLumiEvent()
Definition: EventIDBase.h:162
EventIDBase::set_lumi_block
void set_lumi_block(number_type lumiBlock)
set luminosity block identifier
Definition: EventIDBase.h:123
EventIDBase::set_run_number
void set_run_number(number_type runNumber)
set run number
Definition: EventIDBase.h:100
EventIDBase::SortByRunEvent
static auto SortByRunEvent()
Definition: EventIDBase.h:157
compose.h
std::tie
T tie(T... args)
EventIDBase::operator==
friend bool operator==(const EventIDBase &lhs, const EventIDBase &rhs)
Comparison operators.
Definition: EventIDBase.h:258
EventIDBase::SortByTimeStamp
static auto SortByTimeStamp()
Definition: EventIDBase.h:152
EventIDBase::~EventIDBase
virtual ~EventIDBase()=default
EventIDBase::operator<<
friend std::ostream & operator<<(std::ostream &os, const EventIDBase &rhs)
Extraction operators.
Definition: EventIDBase.h:264
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:192
EventIDBase::operator<=
friend bool operator<=(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:137
min
EventIDBase min(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:202
EventIDBase::set_bunch_crossing_id
void set_bunch_crossing_id(number_type bcid)
set bunch crossing ID
Definition: EventIDBase.h:130
details::add_deref
auto add_deref(Fun f)
Definition: EventIDBase.h:36
EventIDBase::LumiEvent
Definition: EventIDBase.h:173
uint64_t
unsigned long long uint64_t
Definition: instrset.h:143
EventIDBase::lumi_block
number_type lumi_block() const
luminosity block identifier, 32 bit unsigned
Definition: EventIDBase.h:94
EventIDBase::m_bunch_crossing_id
number_type m_bunch_crossing_id
bunch crossing ID, 32 bit unsigned
Definition: EventIDBase.h:199
EventIDBase::setRE
void setRE()
Definition: EventIDBase.h:177
EventIDBase::m_event_number
event_number_t m_event_number
event number
Definition: EventIDBase.h:186
EventIDBase::RunLumi
Definition: EventIDBase.h:173
EventIDBase::EventIDBase
EventIDBase()
Definition: EventIDBase.h:69
max
EventIDBase max(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:215
EventIDBase::event_number
event_number_t event_number() const
event number - 64 bit unsigned
Definition: EventIDBase.h:85
EventIDBase::setRL
void setRL()
Definition: EventIDBase.h:180
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:189
std::min
T min(T... args)
EventIDBase::run_number
number_type run_number() const
run number - 32 bit unsigned
Definition: EventIDBase.h:82
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:196
details::arg_helper< Ret(T::*)(Arg) const >::type
Arg type
Definition: EventIDBase.h:27
details
Definition: AnyDataWrapper.h:10
EventIDBase::Invalid
Definition: EventIDBase.h:173
details::argument_t
typename arg_helper< lambda >::type argument_t
Definition: EventIDBase.h:33
EventIDRange
Event ID Range object.
Definition: EventIDRange.h:23
EventIDBase::operator!=
friend bool operator!=(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:136
std::setfill
T setfill(T... args)
compose
auto compose(lambda_ts &&... lambdas)
Definition: compose.h:36
details::arg_helper
Definition: EventIDBase.h:24
EventIDBase::m_run_number
number_type m_run_number
run number
Definition: EventIDBase.h:183
EventIDBase::time_stamp
number_type time_stamp() const
time stamp - posix time in seconds from 1970, 32 bit unsigned
Definition: EventIDBase.h:88
EventIDBase::set_event_number
void set_event_number(event_number_t eventNumber)
set event number
Definition: EventIDBase.h:107
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:91
operator==
bool operator==(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:258
std::max
T max(T... args)
EventIDBase::operator>
friend bool operator>(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:135
std::tuple
EventIDBase::isValid
bool isValid() const
Definition: EventIDBase.h:147
operator<
bool operator<(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:245
EventIDBase::SortByRunLumi
static auto SortByRunLumi()
Definition: EventIDBase.h:167
EventIDBase::isLumiEvent
bool isLumiEvent() const
Definition: EventIDBase.h:145
EventIDBase::RunEvent
Definition: EventIDBase.h:173
EventIDBase::operator<
friend bool operator<(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:245
EventIDBase::event_number_t
uint64_t event_number_t
Definition: EventIDBase.h:59
EventIDBase::isRunEvent
bool isRunEvent() const
Definition: EventIDBase.h:143
details::make_cmp
auto make_cmp(Proj p, Cmp cmp={})
Definition: EventIDBase.h:41
EventIDBase::min
friend EventIDBase min(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:202
EventIDBase
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
Definition: EventIDBase.h:56
EventIDBase::number_type
unsigned int number_type
Definition: EventIDBase.h:58
EventIDBase::Type
Type
Definition: EventIDBase.h:173
EventIDBase::operator>=
friend bool operator>=(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:138
EventIDBase::TimeStamp
Definition: EventIDBase.h:173
std::ostream
STL class.
EventIDBase::bunch_crossing_id
number_type bunch_crossing_id() const
bunch crossing ID, 32 bit unsigned
Definition: EventIDBase.h:97
EventIDBase::UNDEFEVT
static const event_number_t UNDEFEVT
Definition: EventIDBase.h:62
EventIDBase::isTimeStamp
bool isTimeStamp() const
Definition: EventIDBase.h:144
EventIDBase::setTS
void setTS()
Definition: EventIDBase.h:178