Project
Loading...
Searching...
No Matches
InteractionRecord.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13
14#ifndef ALICEO2_INTERACTIONRECORD_H
15#define ALICEO2_INTERACTIONRECORD_H
16
17#include "GPUCommonRtypes.h"
18#ifndef GPUCA_ALIGPUCODE
19#include <iosfwd>
20#include <cstdint>
21#endif
22#include <cmath>
24
25namespace o2
26{
28 // information about bunch crossing and orbit
29 static constexpr uint16_t DummyBC = 0xffff;
30 static constexpr uint32_t DummyOrbit = 0xffffffff;
34 uint16_t bc = DummyBC;
35 uint32_t orbit = DummyOrbit;
36
37 constexpr InteractionRecord() = default;
38
40 {
41 setFromNS(tNS);
42 }
43
44 constexpr InteractionRecord(uint16_t b, uint32_t orb) : bc(b), orbit(orb)
45 {
46 }
47
50
51 void clear()
52 {
53 bc = 0xffff;
54 orbit = 0xffffffff;
55 }
56
57 bool isDummy() const
58 {
60 }
61
62 void setFromNS(double ns)
63 {
64 bc = ns2bc(ns, orbit);
65 }
66
67 static double bc2ns(int bc, unsigned int orbit)
68 {
70 }
71
72 static int ns2bc(double ns, unsigned int& orb)
73 {
74 long nb = std::round(ns / o2::constants::lhc::LHCBunchSpacingNS);
77 }
78
79 double bc2ns() const
80 {
81 return bc2ns(bc, orbit);
82 }
83
85 {
86 return (bc == other.bc) && (orbit == other.orbit);
87 }
88
90 {
91 return (bc != other.bc) || (orbit != other.orbit);
92 }
93
95 {
96 // return difference in bunch-crossings
97 int64_t diffBC = int(bc) - other.bc;
98 if (orbit != other.orbit) {
99 diffBC += (int64_t(orbit) - other.orbit) * o2::constants::lhc::LHCMaxBunches;
100 }
101 return diffBC;
102 }
103
105 {
106 // return difference in bunch-crossings in ns
108 }
109
111 {
112 // return difference in bunch-crossings in us
114 }
115
116 int64_t toLong() const
117 {
118 // return as single long number
119 return (int64_t(orbit) * o2::constants::lhc::LHCMaxBunches) + bc;
120 }
121
122 void setFromLong(int64_t l)
123 {
124 // set from long BC counter
127 }
128
129 static InteractionRecord long2IR(int64_t l)
130 {
131 // set from long BC counter
132 return {uint16_t(l % o2::constants::lhc::LHCMaxBunches), uint32_t(l / o2::constants::lhc::LHCMaxBunches)};
133 }
134
136 {
137 return (orbit == other.orbit) ? (bc > other.bc) : (orbit > other.orbit);
138 }
139
141 {
142 return !((*this) < other);
143 }
144
146 {
147 return (orbit == other.orbit) ? (bc < other.bc) : (orbit < other.orbit);
148 }
149
151 {
152 return !((*this) > other);
153 }
154
156 {
157 // prefix decrement operator
158 if (!bc--) {
159 orbit--;
161 if (orbit == DummyOrbit) { // wrapped?
162 orbit = 0;
163 bc = 0;
164 }
165 }
166 return InteractionRecord(*this);
167 }
168
170 {
171 // postfix decrement operator, no check for orbit wrap
172 InteractionRecord tmp(*this);
173 if (!bc--) {
174 orbit--;
176 if (orbit == DummyOrbit) { // wrapped?
177 orbit = 0;
178 bc = 0;
179 }
180 }
181 return tmp;
182 }
183
185 {
186 // prefix increment operator
188 orbit++;
189 bc = 0;
190 if (orbit == 0) { // wrapped?
193 }
194 }
195 return InteractionRecord(*this);
196 }
197
199 {
200 // postfix increment operator
201 InteractionRecord tmp(*this);
203 orbit++;
204 bc = 0;
205 if (orbit == 0) { // wrapped?
208 }
209 }
210 return tmp;
211 }
212
214 {
215 // bc self-addition operator, avoid wrapping
216 auto l = toLong();
217 if (dbc >= 0) {
218 if (MaxGlobalBCs - dbc < l) {
219 l = MaxGlobalBCs;
220 dbc = 0;
221 }
222 } else {
223 if (l < -dbc) {
224 l = 0;
225 dbc = 0;
226 }
227 }
228 l += dbc;
231 return *this;
232 }
233
235 {
236 // bc self-subtraction operator
237 return operator+=(-dbc);
238 }
239
241 {
242 // InteractionRecord self-addition operator
243 return operator+=(add.toLong());
244 }
245
247 {
248 // InteractionRecord self-subtraction operator
249 return operator-=(add.toLong());
250 }
251
252 InteractionRecord operator+(int64_t dbc) const
253 {
254 // bc addition operator
255 InteractionRecord tmp(*this);
256 tmp += dbc;
257 return tmp;
258 }
259
260 InteractionRecord operator-(int64_t dbc) const
261 {
262 // bc subtraction operator
263 InteractionRecord tmp(*this);
264 tmp -= dbc;
265 return tmp;
266 }
267
269 {
270 // InteractionRecord addition operator, no check for orbit wrap
271 InteractionRecord tmp(*this);
272 tmp += add;
273 return tmp;
274 }
275
277 {
278 // InteractionRecord subtraction operator, no check for orbit wrap
279 InteractionRecord tmp(*this);
280 tmp -= add;
281 return tmp;
282 }
283
284#ifndef GPUCA_ALIGPUCODE
285 void print() const;
286 std::string asString() const;
287 friend std::ostream& operator<<(std::ostream& stream, InteractionRecord const& ir);
288#endif
290};
291
293 double timeInBCNS = 0.;
294
296
299 {
300 }
301
304 {
305 timeInBCNS = tNS - bc2ns();
306 }
307
309 void setFromNS(double tNS)
310 {
312 timeInBCNS = tNS - bc2ns();
313 }
314
315 void clear()
316 {
318 timeInBCNS = 0.;
319 }
320
321 double getTimeOffsetWrtBC() const
322 {
323 return timeInBCNS;
324 }
325
327 double getTimeNS() const
328 {
329 return timeInBCNS + bc2ns();
330 }
331
333 {
334 return this->InteractionRecord::operator==(other) && (timeInBCNS == other.timeInBCNS);
335 }
336
338 {
339 return this->InteractionRecord::operator!=(other) || (timeInBCNS != other.timeInBCNS);
340 }
341
343 {
344 return (this->InteractionRecord::operator>(other)) || (this->InteractionRecord::operator==(other) && (timeInBCNS > other.timeInBCNS));
345 }
346
348 {
349 return !((*this) < other);
350 }
351
353 {
354 return (this->InteractionRecord::operator<(other)) || (this->InteractionRecord::operator==(other) && (timeInBCNS < other.timeInBCNS));
355 }
356
358 {
359 return !((*this) > other);
360 }
361
362#ifndef GPUCA_ALIGPUCODE
363 void print() const;
364 std::string asString() const;
365 friend std::ostream& operator<<(std::ostream& stream, InteractionTimeRecord const& ir);
366#endif
367
369};
370} // namespace o2
371
372namespace std
373{
374// defining std::hash for InteractionRecord to be used with std containers
375template <>
376struct hash<o2::InteractionRecord> {
377 public:
379 {
380 return ir.toLong();
381 }
382};
383} // namespace std
384
385#endif
Header to collect LHC related constants.
GLenum src
Definition glcorearb.h:1767
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLuint GLuint stream
Definition glcorearb.h:1806
constexpr double LHCBunchSpacingMUS
constexpr int LHCMaxBunches
constexpr double LHCBunchSpacingNS
constexpr double LHCOrbitNS
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
static constexpr InteractionRecord getIRMaxBC()
InteractionRecord operator-(const InteractionRecord &add) const
bool operator==(const InteractionRecord &other) const
InteractionRecord & operator+=(int64_t dbc)
bool operator!=(const InteractionRecord &other) const
InteractionRecord operator+(const InteractionRecord &add) const
bool operator<(const InteractionRecord &other) const
static int ns2bc(double ns, unsigned int &orb)
uint32_t orbit
LHC orbit.
bool operator>(const InteractionRecord &other) const
InteractionRecord operator-(int64_t dbc) const
InteractionRecord & operator-=(const InteractionRecord &add)
ClassDefNV(InteractionRecord, 3)
std::string asString() const
bool operator>=(const InteractionRecord &other) const
bool operator<=(const InteractionRecord &other) const
uint16_t bc
bunch crossing ID of interaction
static constexpr int64_t MaxGlobalBCs
InteractionRecord(const InteractionRecord &src)=default
static constexpr uint32_t DummyOrbit
InteractionRecord operator++(int)
InteractionRecord operator--(int)
static double bc2ns(int bc, unsigned int orbit)
InteractionRecord & operator=(const InteractionRecord &src)=default
InteractionRecord operator+(int64_t dbc) const
static constexpr double DummyTime
InteractionRecord operator--()
InteractionRecord operator++()
InteractionRecord & operator-=(int64_t dbc)
InteractionRecord & operator+=(const InteractionRecord &add)
int64_t differenceInBC(const InteractionRecord &other) const
constexpr InteractionRecord(uint16_t b, uint32_t orb)
constexpr InteractionRecord()=default
void setFromLong(int64_t l)
float differenceInBCMUS(const InteractionRecord &other) const
friend std::ostream & operator<<(std::ostream &stream, InteractionRecord const &ir)
float differenceInBCNS(const InteractionRecord &other) const
static constexpr uint16_t DummyBC
static InteractionRecord long2IR(int64_t l)
void setFromNS(double ns)
ClassDefNV(InteractionTimeRecord, 1)
InteractionTimeRecord(const InteractionRecord &ir, double t_in_bc)
create from the interaction record and time in the bunch (in ns)
bool operator!=(const InteractionTimeRecord &other) const
bool operator<(const InteractionTimeRecord &other) const
bool operator>=(const InteractionTimeRecord &other) const
bool operator==(const InteractionTimeRecord &other) const
void setFromNS(double tNS)
set the from the abs. (since orbit=0/bc=0) time in NS
friend std::ostream & operator<<(std::ostream &stream, InteractionTimeRecord const &ir)
double timeInBCNS
time in NANOSECONDS relative to orbit/bc
double getTimeNS() const
get time in ns from orbit=0/bc=0
bool operator>(const InteractionTimeRecord &other) const
bool operator<=(const InteractionTimeRecord &other) const
InteractionTimeRecord(double tNS)
create from the abs. (since orbit=0/bc=0) time in NS
size_t operator()(const o2::InteractionRecord &ir) const
VectorOfTObjectPtrs other
o2::InteractionRecord ir(0, 0)