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;
34 
35  static const number_type UNDEFNUM;
36  static const event_number_t UNDEFEVT;
37 public:
38 
39 
41 
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 
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 
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 
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) <
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 
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
void set_time_stamp(number_type timeStamp)
set time stamp
Definition: EventIDBase.h:78
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:81
void setLE()
Definition: EventIDBase.h:162
unsigned m_type
Definition: EventIDBase.h:158
void set_lumi_block(number_type lumiBlock)
set luminosity block identifier
Definition: EventIDBase.h:86
void set_run_number(number_type runNumber)
set run number
Definition: EventIDBase.h:72
number_type bunch_crossing_id() const
bunch crossing ID, 32 bit unsigned
Definition: EventIDBase.h:69
number_type m_lumiBlock
luminosity block number: the number which uniquely tags a luminosity block within a run ...
Definition: EventIDBase.h:178
T tie(T...args)
friend bool operator==(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:203
friend std::ostream & operator<<(std::ostream &os, const EventIDBase &rhs)
Extraction operators.
Definition: EventIDBase.h:221
number_type m_time_stamp_ns_offset
time stamp ns - ns time offset for time_stamp, 32 bit unsigned
Definition: EventIDBase.h:174
friend bool operator<=(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:214
void set_bunch_crossing_id(number_type bcid)
set bunch crossing ID
Definition: EventIDBase.h:89
unsigned long long uint64_t
Definition: instrset.h:144
number_type m_bunch_crossing_id
bunch crossing ID, 32 bit unsigned
Definition: EventIDBase.h:181
void setRE()
Definition: EventIDBase.h:160
number_type lumi_block() const
luminosity block identifier, 32 bit unsigned
Definition: EventIDBase.h:66
event_number_t m_event_number
event number
Definition: EventIDBase.h:168
number_type time_stamp() const
time stamp - posix time in seconds from 1970, 32 bit unsigned
Definition: EventIDBase.h:60
number_type m_time_stamp
posix time in seconds since 1970/01/01
Definition: EventIDBase.h:171
bool isValid() const
Definition: EventIDBase.cpp:69
friend bool operator!=(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:211
number_type m_run_number
run number
Definition: EventIDBase.h:165
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:54
bool isRunEvent() const
Definition: EventIDBase.cpp:54
friend bool operator>(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:208
bool isTimeStamp() const
Definition: EventIDBase.cpp:59
number_type time_stamp_ns_offset() const
time stamp ns - ns time offset for time_stamp, 32 bit unsigned
Definition: EventIDBase.h:63
friend bool operator<(const EventIDBase &lhs, const EventIDBase &rhs)
Comparison operators.
Definition: EventIDBase.h:185
uint64_t event_number_t
Definition: EventIDBase.h:33
bool isLumiEvent() const
Definition: EventIDBase.cpp:64
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:217
virtual ~EventIDBase()
Definition: EventIDBase.cpp:50
STL class.
static const event_number_t UNDEFEVT
Definition: EventIDBase.h:36
bool operator()(const EventIDBase &t1, const EventIDBase &t2) const
Definition: EventIDBase.h:109
void setTS()
Definition: EventIDBase.h:161
event_number_t event_number() const
event number - 64 bit unsigned
Definition: EventIDBase.h:57