The Gaudi Framework  v30r0 (c919700c)
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 
30 {
31 public:
32  typedef unsigned int number_type;
34 
35  static const number_type UNDEFNUM;
36  static const event_number_t UNDEFEVT;
37 
38 public:
40 
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 
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 
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 
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 
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 ) <
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 ) >
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 
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
void set_time_stamp(number_type timeStamp)
set time stamp
Definition: EventIDBase.h:84
static const number_type UNDEFNUM
Definition: EventIDBase.h:35
void set_time_stamp_ns_offset(number_type timeStampNs)
set time stamp in ns
Definition: EventIDBase.h:91
void setLE()
Definition: EventIDBase.h:184
unsigned m_type
Definition: EventIDBase.h:180
bool operator()(const EventIDBase &t1, const EventIDBase &t2) const
Definition: EventIDBase.h:152
bool operator()(const EventIDBase *t1, const EventIDBase *t2) const
Definition: EventIDBase.h:160
void set_lumi_block(number_type lumiBlock)
set luminosity block identifier
Definition: EventIDBase.h:94
void set_run_number(number_type runNumber)
set run number
Definition: EventIDBase.h:68
number_type bunch_crossing_id() const
bunch crossing ID, 32 bit unsigned
Definition: EventIDBase.h:65
T tie(T...args)
friend bool operator==(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:235
friend std::ostream & operator<<(std::ostream &os, const EventIDBase &rhs)
Extraction operators.
Definition: EventIDBase.h:245
number_type m_time_stamp_ns_offset
time stamp ns - ns time offset for time_stamp, 32 bit unsigned
Definition: EventIDBase.h:197
bool isRunLumi() const
Definition: EventIDBase.cpp:54
friend bool operator<=(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:242
void set_bunch_crossing_id(number_type bcid)
set bunch crossing ID
Definition: EventIDBase.h:102
unsigned long long uint64_t
Definition: instrset.h:143
number_type m_bunch_crossing_id
bunch crossing ID, 32 bit unsigned
Definition: EventIDBase.h:204
void setRE()
Definition: EventIDBase.h:182
number_type lumi_block() const
luminosity block identifier, 32 bit unsigned
Definition: EventIDBase.h:62
event_number_t m_event_number
event number
Definition: EventIDBase.h:191
number_type time_stamp() const
time stamp - posix time in seconds from 1970, 32 bit unsigned
Definition: EventIDBase.h:56
bool operator()(const EventIDBase *t1, const EventIDBase *t2) const
Definition: EventIDBase.h:174
void setRL()
Definition: EventIDBase.h:185
T setw(T...args)
number_type m_time_stamp
posix time in seconds since 1970/01/01
Definition: EventIDBase.h:194
number_type m_lumi_block
luminosity block number: the number which uniquely tags a luminosity block within a run ...
Definition: EventIDBase.h:201
bool isValid() const
Definition: EventIDBase.cpp:56
bool operator()(const EventIDBase *t1, const EventIDBase *t2) const
Definition: EventIDBase.h:146
bool operator()(const EventIDBase &t1, const EventIDBase &t2) const
Definition: EventIDBase.h:138
friend bool operator!=(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:241
bool operator()(const EventIDBase &t1, const EventIDBase &t2) const
Definition: EventIDBase.h:166
T setfill(T...args)
number_type m_run_number
run number
Definition: EventIDBase.h:188
void set_event_number(event_number_t eventNumber)
set event number
Definition: EventIDBase.h:76
number_type run_number() const
run number - 32 bit unsigned
Definition: EventIDBase.h:50
bool isRunEvent() const
Definition: EventIDBase.cpp:48
friend bool operator>(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:221
bool isTimeStamp() const
Definition: EventIDBase.cpp:50
number_type time_stamp_ns_offset() const
time stamp ns - ns time offset for time_stamp, 32 bit unsigned
Definition: EventIDBase.h:59
friend bool operator<(const EventIDBase &lhs, const EventIDBase &rhs)
Comparison operators.
Definition: EventIDBase.h:207
uint64_t event_number_t
Definition: EventIDBase.h:33
bool isLumiEvent() const
Definition: EventIDBase.cpp:52
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
Definition: EventIDBase.h:29
unsigned int number_type
Definition: EventIDBase.h:32
friend bool operator>=(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:243
virtual ~EventIDBase()
Definition: EventIDBase.cpp:46
STL class.
bool operator()(const EventIDBase *t1, const EventIDBase *t2) const
Definition: EventIDBase.h:132
static const event_number_t UNDEFEVT
Definition: EventIDBase.h:36
bool operator()(const EventIDBase &t1, const EventIDBase &t2) const
Definition: EventIDBase.h:124
void setTS()
Definition: EventIDBase.h:183
event_number_t event_number() const
event number - 64 bit unsigned
Definition: EventIDBase.h:53