|
| 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 | +/// |
| 12 | +/// \file Trigger.h |
| 13 | +/// \author Antonio Franco - INFN Bari |
| 14 | +/// \version 1.0 |
| 15 | +/// \date 2/03/2021 |
| 16 | + |
| 17 | +#ifndef DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_TRIGGER_H_ |
| 18 | +#define DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_TRIGGER_H_ |
| 19 | + |
| 20 | +#include <vector> |
| 21 | +#include "TMath.h" |
| 22 | +#include "CommonDataFormat/TimeStamp.h" |
| 23 | +#include "CommonConstants/LHCConstants.h" |
| 24 | + |
| 25 | +namespace o2 |
| 26 | +{ |
| 27 | +namespace hmpid |
| 28 | +{ |
| 29 | + |
| 30 | +/// \class Trigger |
| 31 | +/// \brief HMPID Trigger declaration |
| 32 | +class Trigger |
| 33 | +{ |
| 34 | + public: |
| 35 | + // Trigger time Conversion Functions |
| 36 | + static inline uint64_t OrbitBcToEventId(uint32_t Orbit, uint16_t BC) { return ((Orbit << 12) | (0x0FFF & BC)); }; |
| 37 | + static inline uint32_t EventIdToOrbit(uint64_t EventId) { return (EventId >> 12); }; |
| 38 | + static inline uint16_t EventIdToBc(uint64_t EventId) { return (EventId & 0x0FFF); }; |
| 39 | + static double OrbitBcToTimeNs(uint32_t Orbit, uint16_t BC) { return (BC * o2::constants::lhc::LHCBunchSpacingNS + Orbit * o2::constants::lhc::LHCOrbitNS); }; |
| 40 | + static uint32_t TimeNsToOrbit(double TimeNs) { return (uint32_t)(TimeNs / o2::constants::lhc::LHCOrbitNS); }; |
| 41 | + static uint16_t TimeNsToBc(double TimeNs) { return (uint16_t)(std::fmod(TimeNs, o2::constants::lhc::LHCOrbitNS) / o2::constants::lhc::LHCBunchSpacingNS); }; |
| 42 | + static void TimeNsToOrbitBc(double TimeNs, uint32_t& Orbit, uint16_t& Bc) |
| 43 | + { |
| 44 | + Orbit = TimeNsToOrbit(TimeNs); |
| 45 | + Bc = TimeNsToBc(TimeNs); |
| 46 | + return; |
| 47 | + }; |
| 48 | + |
| 49 | + // Operators definition ! |
| 50 | + friend inline bool operator<(const Trigger& l, const Trigger& r) { return OrbitBcToEventId(l.mOrbit, l.mBc) < OrbitBcToEventId(r.mOrbit, r.mBc); }; |
| 51 | + friend inline bool operator==(const Trigger& l, const Trigger& r) { return OrbitBcToEventId(l.mOrbit, l.mBc) == OrbitBcToEventId(r.mOrbit, r.mBc); }; |
| 52 | + friend inline bool operator>(const Trigger& l, const Trigger& r) { return r < l; }; |
| 53 | + friend inline bool operator<=(const Trigger& l, const Trigger& r) { return !(l > r); }; |
| 54 | + friend inline bool operator>=(const Trigger& l, const Trigger& r) { return !(l < r); }; |
| 55 | + friend inline bool operator!=(const Trigger& l, const Trigger& r) { return !(l == r); }; |
| 56 | + |
| 57 | + // Digit ASCII format (Orbit,BunchCrossing)[LHC Time nSec] |
| 58 | + friend std::ostream& operator<<(std::ostream& os, const Trigger& d) |
| 59 | + { |
| 60 | + os << "(" << d.mOrbit << "," << d.mBc << ")[" << OrbitBcToTimeNs(d.mOrbit, d.mBc) << " ns]"; |
| 61 | + return os; |
| 62 | + }; |
| 63 | + |
| 64 | + public: |
| 65 | + Trigger() = default; |
| 66 | + Trigger(uint16_t bc, uint32_t orbit) |
| 67 | + { |
| 68 | + mBc = bc; |
| 69 | + mOrbit = orbit; |
| 70 | + }; |
| 71 | + uint32_t getOrbit() const { return mOrbit; } |
| 72 | + uint16_t getBc() const { return mBc; } |
| 73 | + uint64_t getTriggerID() const { return OrbitBcToEventId(mOrbit, mBc); } |
| 74 | + void setOrbit(uint32_t orbit) |
| 75 | + { |
| 76 | + mOrbit = orbit; |
| 77 | + return; |
| 78 | + } |
| 79 | + void setBC(uint16_t bc) |
| 80 | + { |
| 81 | + mBc = bc; |
| 82 | + return; |
| 83 | + } |
| 84 | + void setTriggerID(uint64_t trigger) |
| 85 | + { |
| 86 | + mOrbit = (trigger >> 12); |
| 87 | + mBc = (trigger & 0x0FFF); |
| 88 | + return; |
| 89 | + } |
| 90 | + |
| 91 | + private: |
| 92 | + // Members |
| 93 | + uint16_t mBc = 0.; |
| 94 | + uint32_t mOrbit = 0; |
| 95 | + |
| 96 | + ClassDefNV(Trigger, 2); |
| 97 | +}; |
| 98 | + |
| 99 | +} // namespace hmpid |
| 100 | +} // namespace o2 |
| 101 | + |
| 102 | +#endif /* DETECTORS_HMPID_BASE_INCLUDE_HMPIDBASE_TRIGGER_H_ */ |
0 commit comments