Project
Loading...
Searching...
No Matches
CTFHelper.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
15
16#ifndef O2_CTP_CTF_HELPER_H
17#define O2_CTP_CTF_HELPER_H
18
19#include "DataFormatsCTP/CTF.h"
22#include <gsl/span>
23
24namespace o2
25{
26namespace ctp
27{
28
30{
31
32 public:
33 CTFHelper(const gsl::span<const CTPDigit>& data) : mData(data) {}
34
35 static constexpr int CTPInpNBytes = CTP_NINPUTS / 8 + (CTP_NINPUTS % 8 > 0);
36 static constexpr int CTPClsNBytes = CTP_NCLASSES / 8 + (CTP_NCLASSES % 8 > 0);
37
39 {
40 CTFHeader h{o2::detectors::DetID::CTP, 0, 1, 0, // dummy timestamp, version 1.0
41 lumi.counts, lumi.countsFV0, lumi.nHBFCounted, lumi.nHBFCountedFV0, lumi.orbit,
42 uint32_t(mData.size()), 0, 0, uint16_t(lumi.inp1), uint16_t(lumi.inp2)};
43 if (mData.size()) {
44 h.firstOrbit = mData[0].intRecord.orbit;
45 h.firstBC = mData[0].intRecord.bc;
46 }
47 return h;
48 }
49
50 size_t getSize() const { return mData.size() * sizeof(CTPDigit); }
51
52 //>>> =========================== ITERATORS ========================================
53
54 template <typename I, typename D, typename T, int M = 1>
55 class _Iter
56 {
57 public:
58 using difference_type = std::ptrdiff_t;
59 using value_type = T;
60 using pointer = const T*;
61 using reference = const T&;
62 using iterator_category = std::random_access_iterator_tag;
63
64 _Iter(const gsl::span<const D>& data, bool end = false) : mData(data), mIndex(end ? M * data.size() : 0){};
65 _Iter() = default;
66
67 inline I& operator++() noexcept
68 {
69 ++mIndex;
70 return static_cast<I&>(*this);
71 }
72
73 inline I operator++(int)
74 {
75 I res = *(static_cast<I*>(this));
76 ++mIndex;
77 return res;
78 }
79
80 inline I& operator--() noexcept
81 {
82 mIndex--;
83 return static_cast<I&>(*this);
84 }
85
86 inline I operator--(int)
87 {
88 I res = *(static_cast<I*>(this));
89 --mIndex;
90 return res;
91 }
92
94 {
95 mIndex += i;
96 return static_cast<I&>(*this);
97 }
98
100 {
101 I res = *(const_cast<I*>(static_cast<const I*>(this)));
102 return res += i;
103 }
104
106 {
107 mIndex -= i;
108 return static_cast<I&>(*this);
109 }
110
112 {
113 I res = *(const_cast<I*>(static_cast<const I*>(this)));
114 return res -= i;
115 }
116
117 difference_type operator-(const I& other) const noexcept { return mIndex - other.mIndex; }
118
119 inline friend I operator+(difference_type i, const I& iter) { return iter + i; };
120
121 bool operator!=(const I& other) const noexcept { return mIndex != other.mIndex; }
122 bool operator==(const I& other) const noexcept { return mIndex == other.mIndex; }
123 bool operator>(const I& other) const noexcept { return mIndex > other.mIndex; }
124 bool operator<(const I& other) const noexcept { return mIndex < other.mIndex; }
125 bool operator>=(const I& other) const noexcept { return mIndex >= other.mIndex; }
126 bool operator<=(const I& other) const noexcept { return mIndex <= other.mIndex; }
127
128 protected:
129 gsl::span<const D> mData{};
131 };
132
133 //_______________________________________________
134 // BC difference wrt previous if in the same orbit, otherwise the abs.value.
135 // For the very 1st entry return 0 (diff wrt 1st BC in the CTF header)
136 class Iter_bcIncTrig : public _Iter<Iter_bcIncTrig, CTPDigit, int16_t>
137 {
138 public:
139 using _Iter<Iter_bcIncTrig, CTPDigit, int16_t>::_Iter;
141 {
142 if (mIndex) {
143 if (mData[mIndex].intRecord.orbit == mData[mIndex - 1].intRecord.orbit) {
144 return value_type(mData[mIndex].intRecord.bc - mData[mIndex - 1].intRecord.bc);
145 } else {
146 return value_type(mData[mIndex].intRecord.bc);
147 }
148 }
149 return 0;
150 }
152 {
153 size_t id = mIndex + i;
154 if (id) {
155 if (mData[id].intRecord.orbit == mData[id - 1].intRecord.orbit) {
156 return value_type(mData[id].intRecord.bc - mData[id - 1].intRecord.bc);
157 } else {
158 return value_type(mData[id].intRecord.bc);
159 }
160 }
161 return 0;
162 }
163 };
164
165 //_______________________________________________
166 // Orbit difference wrt previous. For the very 1st entry return 0 (diff wrt 1st BC in the CTF header)
167 class Iter_orbitIncTrig : public _Iter<Iter_orbitIncTrig, CTPDigit, int32_t>
168 {
169 public:
170 using _Iter<Iter_orbitIncTrig, CTPDigit, int32_t>::_Iter;
171 value_type operator*() const { return value_type(mIndex ? mData[mIndex].intRecord.orbit - mData[mIndex - 1].intRecord.orbit : 0); }
173 {
174 size_t id = mIndex + i;
175 return value_type(id ? mData[id].intRecord.orbit - mData[id - 1].intRecord.orbit : 0);
176 }
177 };
178
179 //_______________________________________________
180 class Iter_bytesInput : public _Iter<Iter_bytesInput, CTPDigit, uint8_t, CTPInpNBytes>
181 {
182 public:
185 {
186 return static_cast<uint8_t>(((mData[mIndex / CTPInpNBytes].CTPInputMask.to_ullong()) >> (8 * (mIndex % CTPInpNBytes))) & 0xff);
187 }
189 {
190 size_t id = mIndex + i;
191 return static_cast<uint8_t>(((mData[id / CTPInpNBytes].CTPInputMask.to_ullong()) >> (8 * (id % CTPInpNBytes))) & 0xff);
192 }
193 };
194
195 //_______________________________________________
196 class Iter_bytesClass : public _Iter<Iter_bytesClass, CTPDigit, uint8_t, CTPClsNBytes>
197 {
198 public:
201 {
202 return static_cast<uint8_t>(((mData[mIndex / CTPClsNBytes].CTPClassMask.to_ullong()) >> (8 * (mIndex % CTPClsNBytes))) & 0xff);
203 }
205 {
206 size_t id = mIndex + i;
207 return static_cast<uint8_t>(((mData[id / CTPClsNBytes].CTPClassMask.to_ullong()) >> (8 * (id % CTPClsNBytes))) & 0xff);
208 }
209 };
210
211 //<<< =========================== ITERATORS ========================================
212
213 Iter_bcIncTrig begin_bcIncTrig() const { return Iter_bcIncTrig(mData, false); }
214 Iter_bcIncTrig end_bcIncTrig() const { return Iter_bcIncTrig(mData, true); }
215
217 Iter_orbitIncTrig end_orbitIncTrig() const { return Iter_orbitIncTrig(mData, true); }
218
219 Iter_bytesInput begin_bytesInput() const { return Iter_bytesInput(mData, false); }
220 Iter_bytesInput end_bytesInput() const { return Iter_bytesInput(mData, true); }
221
222 Iter_bytesClass begin_bytesClass() const { return Iter_bytesClass(mData, false); }
223 Iter_bytesClass end_bytesClass() const { return Iter_bytesClass(mData, true); }
224
225 private:
226 const gsl::span<const o2::ctp::CTPDigit> mData;
227};
228
229} // namespace ctp
230} // namespace o2
231
232#endif
Definitions for CTP CTF data.
definition of CTPDigit, CTPInputDigit
int32_t i
uint32_t res
Definition RawData.h:0
Class for time synchronization of RawReader instances.
value_type operator[](difference_type i) const
Definition CTFHelper.h:151
value_type operator[](difference_type i) const
Definition CTFHelper.h:204
value_type operator[](difference_type i) const
Definition CTFHelper.h:188
value_type operator[](difference_type i) const
Definition CTFHelper.h:172
I & operator++() noexcept
Definition CTFHelper.h:67
friend I operator+(difference_type i, const I &iter)
Definition CTFHelper.h:119
std::ptrdiff_t difference_type
Definition CTFHelper.h:58
difference_type mIndex
Definition CTFHelper.h:130
I operator-(difference_type i) const
Definition CTFHelper.h:111
bool operator==(const I &other) const noexcept
Definition CTFHelper.h:122
bool operator>(const I &other) const noexcept
Definition CTFHelper.h:123
I & operator-=(difference_type i) noexcept
Definition CTFHelper.h:105
difference_type operator-(const I &other) const noexcept
Definition CTFHelper.h:117
bool operator<=(const I &other) const noexcept
Definition CTFHelper.h:126
I & operator--() noexcept
Definition CTFHelper.h:80
gsl::span< const D > mData
Definition CTFHelper.h:129
bool operator!=(const I &other) const noexcept
Definition CTFHelper.h:121
I operator+(difference_type i) const
Definition CTFHelper.h:99
bool operator<(const I &other) const noexcept
Definition CTFHelper.h:124
bool operator>=(const I &other) const noexcept
Definition CTFHelper.h:125
_Iter(const gsl::span< const D > &data, bool end=false)
Definition CTFHelper.h:64
std::random_access_iterator_tag iterator_category
Definition CTFHelper.h:62
I & operator+=(difference_type i) noexcept
Definition CTFHelper.h:93
Iter_bytesClass begin_bytesClass() const
Definition CTFHelper.h:222
Iter_bcIncTrig end_bcIncTrig() const
Definition CTFHelper.h:214
static constexpr int CTPClsNBytes
Definition CTFHelper.h:36
Iter_bcIncTrig begin_bcIncTrig() const
Definition CTFHelper.h:213
Iter_bytesInput begin_bytesInput() const
Definition CTFHelper.h:219
CTFHelper(const gsl::span< const CTPDigit > &data)
Definition CTFHelper.h:33
Iter_orbitIncTrig begin_orbitIncTrig() const
Definition CTFHelper.h:216
static constexpr int CTPInpNBytes
Definition CTFHelper.h:35
CTFHeader createHeader(const LumiInfo &lumi)
Definition CTFHelper.h:38
size_t getSize() const
Definition CTFHelper.h:50
Iter_bytesClass end_bytesClass() const
Definition CTFHelper.h:223
Iter_bytesInput end_bytesInput() const
Definition CTFHelper.h:220
Iter_orbitIncTrig end_orbitIncTrig() const
Definition CTFHelper.h:217
static constexpr ID CTP
Definition DetID.h:79
GLsizeiptr size
Definition glcorearb.h:659
GLuint GLuint end
Definition glcorearb.h:469
GLboolean * data
Definition glcorearb.h:298
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Header for a single CTF.
Definition CTF.h:29
VectorOfTObjectPtrs other
LumiInfo lumi