|
| 1 | +// Copyright CERN and copyright holders of ALICE O2. This software is |
| 2 | +// distributed under the terms of the GNU General Public License v3 (GPL |
| 3 | +// Version 3), copied verbatim in the file "COPYING". |
| 4 | +// |
| 5 | +// See http://alice-o2.web.cern.ch/license for full licensing information. |
| 6 | +// |
| 7 | +// In applying this license CERN does not waive the privileges and immunities |
| 8 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 9 | +// or submit itself to any jurisdiction. |
| 10 | + |
| 11 | +/// @brief Interaction record encoding BC, orbit, time |
| 12 | + |
| 13 | +#ifndef ALICEO2_INTERACTIONRECORD_H |
| 14 | +#define ALICEO2_INTERACTIONRECORD_H |
| 15 | + |
| 16 | +#include <Rtypes.h> |
| 17 | +#include <iosfwd> |
| 18 | +#include <cmath> |
| 19 | +#include "CommonConstants/LHCConstants.h" |
| 20 | + |
| 21 | +namespace o2 |
| 22 | +{ |
| 23 | +struct InteractionRecord { |
| 24 | + double timeNS = 0.; ///< time in NANOSECONDS from start of run (period=0, orbit=0) |
| 25 | + int bc = 0; ///< bunch crossing ID of interaction |
| 26 | + int orbit = 0; ///< LHC orbit |
| 27 | + int period = 0; ///< LHC period since beginning of run (if >0 -> time precision loss) |
| 28 | + |
| 29 | + InteractionRecord() = default; |
| 30 | + |
| 31 | + InteractionRecord(double tNS) |
| 32 | + { |
| 33 | + setFromNS(tNS); |
| 34 | + } |
| 35 | + |
| 36 | + InteractionRecord(int b, int orb, int per = 0) : bc(b), orbit(orb), period(per) |
| 37 | + { |
| 38 | + timeNS = bc2ns(bc, orbit, period); |
| 39 | + } |
| 40 | + |
| 41 | + void setFromNS(double ns) |
| 42 | + { |
| 43 | + timeNS = ns; |
| 44 | + bc = ns2bc(ns, orbit, period); |
| 45 | + } |
| 46 | + |
| 47 | + static double bc2ns(int bc, int orbit, int period) |
| 48 | + { |
| 49 | + double t = bc * o2::constants::lhc::LHCBunchSpacingNS + orbit * o2::constants::lhc::LHCOrbitNS; |
| 50 | + return period ? t + o2::constants::lhc::PeriodDurationNS : t; |
| 51 | + } |
| 52 | + |
| 53 | + static int ns2bc(double ns, int& orb, int& per) |
| 54 | + { |
| 55 | + per = ns / o2::constants::lhc::PeriodDurationNS; |
| 56 | + if (per) { |
| 57 | + ns -= per * o2::constants::lhc::PeriodDurationNS; |
| 58 | + } |
| 59 | + orb = ns / o2::constants::lhc::LHCOrbitNS; |
| 60 | + ns -= orb * o2::constants::lhc::LHCOrbitNS; |
| 61 | + return std::round(ns / o2::constants::lhc::LHCBunchSpacingNS); |
| 62 | + } |
| 63 | + |
| 64 | + void print() const; |
| 65 | + |
| 66 | + ClassDefNV(InteractionRecord, 1); |
| 67 | +}; |
| 68 | +} |
| 69 | + |
| 70 | +#endif |
0 commit comments