The Gaudi Framework  v29r0 (ff2e7097)
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 
29 {
30 public:
31  typedef unsigned int number_type;
33 
34  static const number_type UNDEFNUM;
35  static const event_number_t UNDEFEVT;
36 
37 public:
39 
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 
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 
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 
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 
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 ) <
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 ) >
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 
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
void set_time_stamp(number_type timeStamp)
set time stamp
Definition: EventIDBase.h:83
static const number_type UNDEFNUM
Definition: EventIDBase.h:34
void set_time_stamp_ns_offset(number_type timeStampNs)
set time stamp in ns
Definition: EventIDBase.h:90
void setLE()
Definition: EventIDBase.h:183
unsigned m_type
Definition: EventIDBase.h:179
bool operator()(const EventIDBase &t1, const EventIDBase &t2) const
Definition: EventIDBase.h:151
bool operator()(const EventIDBase *t1, const EventIDBase *t2) const
Definition: EventIDBase.h:159
void set_lumi_block(number_type lumiBlock)
set luminosity block identifier
Definition: EventIDBase.h:93
void set_run_number(number_type runNumber)
set run number
Definition: EventIDBase.h:67
number_type bunch_crossing_id() const
bunch crossing ID, 32 bit unsigned
Definition: EventIDBase.h:64
T tie(T...args)
friend bool operator==(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:234
friend std::ostream & operator<<(std::ostream &os, const EventIDBase &rhs)
Extraction operators.
Definition: EventIDBase.h:244
number_type m_time_stamp_ns_offset
time stamp ns - ns time offset for time_stamp, 32 bit unsigned
Definition: EventIDBase.h:196
bool isRunLumi() const
Definition: EventIDBase.cpp:54
friend bool operator<=(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:241
void set_bunch_crossing_id(number_type bcid)
set bunch crossing ID
Definition: EventIDBase.h:101
unsigned long long uint64_t
Definition: instrset.h:143
number_type m_bunch_crossing_id
bunch crossing ID, 32 bit unsigned
Definition: EventIDBase.h:203
void setRE()
Definition: EventIDBase.h:181
number_type lumi_block() const
luminosity block identifier, 32 bit unsigned
Definition: EventIDBase.h:61
event_number_t m_event_number
event number
Definition: EventIDBase.h:190
number_type time_stamp() const
time stamp - posix time in seconds from 1970, 32 bit unsigned
Definition: EventIDBase.h:55
bool operator()(const EventIDBase *t1, const EventIDBase *t2) const
Definition: EventIDBase.h:173
void setRL()
Definition: EventIDBase.h:184
number_type m_time_stamp
posix time in seconds since 1970/01/01
Definition: EventIDBase.h:193
number_type m_lumi_block
luminosity block number: the number which uniquely tags a luminosity block within a run ...
Definition: EventIDBase.h:200
bool isValid() const
Definition: EventIDBase.cpp:56
bool operator()(const EventIDBase *t1, const EventIDBase *t2) const
Definition: EventIDBase.h:145
bool operator()(const EventIDBase &t1, const EventIDBase &t2) const
Definition: EventIDBase.h:137
friend bool operator!=(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:240
bool operator()(const EventIDBase &t1, const EventIDBase &t2) const
Definition: EventIDBase.h:165
number_type m_run_number
run number
Definition: EventIDBase.h:187
void set_event_number(event_number_t eventNumber)
set event number
Definition: EventIDBase.h:75
number_type run_number() const
run number - 32 bit unsigned
Definition: EventIDBase.h:49
bool isRunEvent() const
Definition: EventIDBase.cpp:48
friend bool operator>(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:220
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:58
friend bool operator<(const EventIDBase &lhs, const EventIDBase &rhs)
Comparison operators.
Definition: EventIDBase.h:206
uint64_t event_number_t
Definition: EventIDBase.h:32
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:28
unsigned int number_type
Definition: EventIDBase.h:31
friend bool operator>=(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:242
virtual ~EventIDBase()
Definition: EventIDBase.cpp:46
STL class.
bool operator()(const EventIDBase *t1, const EventIDBase *t2) const
Definition: EventIDBase.h:131
static const event_number_t UNDEFEVT
Definition: EventIDBase.h:35
bool operator()(const EventIDBase &t1, const EventIDBase &t2) const
Definition: EventIDBase.h:123
void setTS()
Definition: EventIDBase.h:182
event_number_t event_number() const
event number - 64 bit unsigned
Definition: EventIDBase.h:52