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_ZDC_CTF_HELPER_H
17#define O2_ZDC_CTF_HELPER_H
18
19#ifdef NDEBUG
20#undef NDEBUG
21#endif
22
23#include "DataFormatsZDC/CTF.h"
24#include <gsl/span>
25
26namespace o2
27{
28namespace zdc
29{
30
32{
33
34 public:
35 CTFHelper(const gsl::span<const BCData>& trgData,
36 const gsl::span<const ChannelData>& chanData,
37 const gsl::span<const OrbitData>& pedData)
38 : mTrigData(trgData), mChanData(chanData), mEOData(pedData) {}
39
41 {
42 CTFHeader h{o2::detectors::DetID::ZDC, 0, 1, 0, // dummy timestamp, version 1.0
43 uint32_t(mTrigData.size()), uint32_t(mChanData.size()), uint32_t(mEOData.size()), 0, 0, 0};
44 if (mTrigData.size()) {
45 h.firstOrbit = mTrigData[0].ir.orbit;
46 h.firstBC = mTrigData[0].ir.bc;
47 }
48 if (mEOData.size()) {
49 h.firstOrbitEOData = mEOData[0].ir.orbit;
50 h.firstScaler = mEOData[0].scaler; // then we store increments
51 }
52 return h;
53 }
54
55 size_t getSize() const { return mTrigData.size() * sizeof(BCData) + mChanData.size() * sizeof(ChannelData) + mEOData.size() * sizeof(OrbitData); }
56
57 //>>> =========================== ITERATORS ========================================
58
59 template <typename I, typename D, typename T, int M = 1>
60 class _Iter
61 {
62 public:
63 using difference_type = std::ptrdiff_t;
64 using value_type = T;
65 using pointer = const T*;
66 using reference = const T&;
67 using iterator_category = std::random_access_iterator_tag;
68
69 _Iter(const gsl::span<const D>& data, bool end = false) : mData(data), mIndex(end ? M * data.size() : 0){};
70 _Iter() = default;
71
72 inline I& operator++() noexcept
73 {
74 ++mIndex;
75 return static_cast<I&>(*this);
76 }
77
78 inline I operator++(int)
79 {
80 I res = *(static_cast<I*>(this));
81 ++mIndex;
82 return res;
83 }
84
85 inline I& operator--() noexcept
86 {
87 mIndex--;
88 return static_cast<I&>(*this);
89 }
90
91 inline I operator--(int)
92 {
93 I res = *(static_cast<I*>(this));
94 --mIndex;
95 return res;
96 }
97
99 {
100 mIndex += i;
101 return static_cast<I&>(*this);
102 }
103
105 {
106 I res = *(const_cast<I*>(static_cast<const I*>(this)));
107 return res += i;
108 }
109
111 {
112 mIndex -= i;
113 return static_cast<I&>(*this);
114 }
115
117 {
118 I res = *(const_cast<I*>(static_cast<const I*>(this)));
119 return res -= i;
120 }
121
122 difference_type operator-(const I& other) const noexcept { return mIndex - other.mIndex; }
123
124 inline friend I operator+(difference_type i, const I& iter) { return iter + i; };
125
126 bool operator!=(const I& other) const noexcept { return mIndex != other.mIndex; }
127 bool operator==(const I& other) const noexcept { return mIndex == other.mIndex; }
128 bool operator>(const I& other) const noexcept { return mIndex > other.mIndex; }
129 bool operator<(const I& other) const noexcept { return mIndex < other.mIndex; }
130 bool operator>=(const I& other) const noexcept { return mIndex >= other.mIndex; }
131 bool operator<=(const I& other) const noexcept { return mIndex <= other.mIndex; }
132
133 protected:
134 gsl::span<const D> mData{};
136 };
137
138 //_______________________________________________
139 // BC difference wrt previous if in the same orbit, otherwise the abs.value.
140 // For the very 1st entry return 0 (diff wrt 1st BC in the CTF header)
141 class Iter_bcIncTrig : public _Iter<Iter_bcIncTrig, BCData, int16_t>
142 {
143 public:
144 using _Iter<Iter_bcIncTrig, BCData, int16_t>::_Iter;
146 {
147 if (mIndex) {
148 if (mData[mIndex].ir.orbit == mData[mIndex - 1].ir.orbit) {
149 return value_type(mData[mIndex].ir.bc - mData[mIndex - 1].ir.bc);
150 } else {
151 return value_type(mData[mIndex].ir.bc);
152 }
153 }
154 return 0;
155 }
157 {
158 size_t id = mIndex + i;
159 if (id) {
160 if (mData[id].ir.orbit == mData[id - 1].ir.orbit) {
161 return value_type(mData[id].ir.bc - mData[id - 1].ir.bc);
162 } else {
163 return value_type(mData[id].ir.bc);
164 }
165 }
166 return 0;
167 }
168 };
169
171 //_______________________________________________
172 // Orbit difference wrt previous. For the very 1st entry return 0 (diff wrt 1st BC in the CTF header)
173 class Iter_orbitIncTrig : public _Iter<Iter_orbitIncTrig, BCData, int32_t>
174 {
175 public:
176 using _Iter<Iter_orbitIncTrig, BCData, int32_t>::_Iter;
177 value_type operator*() const { return value_type(mIndex ? mData[mIndex].ir.orbit - mData[mIndex - 1].ir.orbit : 0); }
179 {
180 size_t id = mIndex + i;
181 return value_type(id ? mData[id].ir.orbit - mData[id - 1].ir.orbit : 0);
182 }
183 };
184
185 //_______________________________________________
186 // Modules trigger words, NModules words per trigger, iterate over the BCData and its modules
187 class Iter_moduleTrig : public _Iter<Iter_moduleTrig, BCData, uint16_t, NModules>
188 {
189 public:
190 using _Iter<Iter_moduleTrig, BCData, uint16_t, NModules>::_Iter;
191 value_type operator*() const { return mData[mIndex / NModules].moduleTriggers[mIndex % NModules]; }
193 {
194 size_t id = mIndex + i;
195 return mData[id / NModules].moduleTriggers[id % NModules];
196 }
197 };
198
199 //_______________________________________________
200 // ZDC channels pattern word: 32b word is saved as 2 16 bit words
201 class Iter_channelsHL : public _Iter<Iter_channelsHL, BCData, uint16_t, 2>
202 {
203 public:
204 using _Iter<Iter_channelsHL, BCData, uint16_t, 2>::_Iter;
205 value_type operator*() const { return uint16_t(mIndex & 0x1 ? mData[mIndex / 2].channels : mData[mIndex / 2].channels >> 16); }
207 {
208 size_t id = mIndex + i;
209 return uint16_t(id & 0x1 ? mData[id / 2].channels : mData[id / 2].channels >> 16);
210 }
211 };
212
213 //_______________________________________________
214 // ZDC trigger word: 32b word is saved as 2 16 bit words
215 class Iter_triggersHL : public _Iter<Iter_triggersHL, BCData, uint16_t, 2>
216 {
217 public:
218 using _Iter<Iter_triggersHL, BCData, uint16_t, 2>::_Iter;
219 value_type operator*() const { return uint16_t(mIndex & 0x1 ? mData[mIndex / 2].triggers : mData[mIndex / 2].triggers >> 16); }
221 {
222 size_t id = mIndex + i;
223 return uint16_t(id & 0x1 ? mData[id / 2].triggers : mData[id / 2].triggers >> 16);
224 }
225 };
226
227 //_______________________________________________
228 // Alice external trigger word
229 class Iter_extTriggers : public _Iter<Iter_extTriggers, BCData, uint8_t>
230 {
231 public:
232 using _Iter<Iter_extTriggers, BCData, uint8_t>::_Iter;
233 value_type operator*() const { return mData[mIndex].ext_triggers; }
234 value_type operator[](difference_type i) const { return mData[mIndex + i].ext_triggers; }
235 };
236
237 //_______________________________________________
238 // Number of channels for trigger
239 class Iter_nchanTrig : public _Iter<Iter_nchanTrig, BCData, uint16_t>
240 {
241 public:
242 using _Iter<Iter_nchanTrig, BCData, uint16_t>::_Iter;
243 value_type operator*() const { return mData[mIndex].ref.getEntries(); }
244 value_type operator[](difference_type i) const { return mData[mIndex + i].ref.getEntries(); }
245 };
246
248
249 //_______________________________________________
250 class Iter_chanID : public _Iter<Iter_chanID, ChannelData, uint8_t>
251 {
252 public:
253 using _Iter<Iter_chanID, ChannelData, uint8_t>::_Iter;
254 value_type operator*() const { return mData[mIndex].id; }
256 };
257
258 //_______________________________________________
259 class Iter_chanData : public _Iter<Iter_chanData, ChannelData, uint16_t, NTimeBinsPerBC>
260 {
261 public:
265 {
266 size_t id = mIndex + i;
267 return mData[id / NTimeBinsPerBC].data[id % NTimeBinsPerBC];
268 }
269 };
270
272
273 //_______________________________________________
274 // Orbit difference wrt previous. For the very 1st entry return 0 (diff wrt 1st BC in the CTF header)
275 class Iter_orbitIncEOD : public _Iter<Iter_orbitIncEOD, OrbitData, int32_t>
276 {
277 public:
278 using _Iter<Iter_orbitIncEOD, OrbitData, int32_t>::_Iter;
279 value_type operator*() const { return value_type(mIndex ? mData[mIndex].ir.orbit - mData[mIndex - 1].ir.orbit : 0); }
281 {
282 size_t id = mIndex + i;
283 return value_type(id ? mData[id].ir.orbit - mData[id - 1].ir.orbit : 0);
284 }
285 };
286
287 //_______________________________________________
288 class Iter_pedData : public _Iter<Iter_pedData, OrbitData, uint16_t, NChannels>
289 {
290 public:
291 using _Iter<Iter_pedData, OrbitData, uint16_t, NChannels>::_Iter;
294 {
295 size_t id = mIndex + i;
296 return mData[id / NChannels].data[id % NChannels];
297 }
298 };
299
300 //_______________________________________________
301 class Iter_sclInc : public _Iter<Iter_sclInc, OrbitData, int16_t, NChannels>
302 {
303 public:
306 {
307 // define with respect to previous orbit
308 int slot = mIndex / NChannels, chan = mIndex % NChannels;
309 return value_type(slot ? mData[slot].scaler[chan] - mData[slot - 1].scaler[chan] : 0);
310 }
312 {
313 size_t id = mIndex + i;
314 int slot = id / NChannels, chan = id % NChannels;
315 return value_type(slot ? mData[slot].scaler[chan] - mData[slot - 1].scaler[chan] : 0);
316 }
317 };
318
319 //<<< =========================== ITERATORS ========================================
320
321 Iter_bcIncTrig begin_bcIncTrig() const { return Iter_bcIncTrig(mTrigData, false); }
322 Iter_bcIncTrig end_bcIncTrig() const { return Iter_bcIncTrig(mTrigData, true); }
323
324 Iter_orbitIncTrig begin_orbitIncTrig() const { return Iter_orbitIncTrig(mTrigData, false); }
325 Iter_orbitIncTrig end_orbitIncTrig() const { return Iter_orbitIncTrig(mTrigData, true); }
326
327 Iter_moduleTrig begin_moduleTrig() const { return Iter_moduleTrig(mTrigData, false); }
328 Iter_moduleTrig end_moduleTrig() const { return Iter_moduleTrig(mTrigData, true); }
329
330 Iter_channelsHL begin_channelsHL() const { return Iter_channelsHL(mTrigData, false); }
331 Iter_channelsHL end_channelsHL() const { return Iter_channelsHL(mTrigData, true); }
332
333 Iter_triggersHL begin_triggersHL() const { return Iter_triggersHL(mTrigData, false); }
334 Iter_triggersHL end_triggersHL() const { return Iter_triggersHL(mTrigData, true); }
335
336 Iter_extTriggers begin_extTriggers() const { return Iter_extTriggers(mTrigData, false); }
337 Iter_extTriggers end_extTriggers() const { return Iter_extTriggers(mTrigData, true); }
338
339 Iter_nchanTrig begin_nchanTrig() const { return Iter_nchanTrig(mTrigData, false); }
340 Iter_nchanTrig end_nchanTrig() const { return Iter_nchanTrig(mTrigData, true); }
341
342 Iter_chanID begin_chanID() const { return Iter_chanID(mChanData, false); }
343 Iter_chanID end_chanID() const { return Iter_chanID(mChanData, true); }
344
345 Iter_chanData begin_chanData() const { return Iter_chanData(mChanData, false); }
346 Iter_chanData end_chanData() const { return Iter_chanData(mChanData, true); }
347
348 Iter_orbitIncEOD begin_orbitIncEOD() const { return Iter_orbitIncEOD(mEOData, false); }
349 Iter_orbitIncEOD end_orbitIncEOD() const { return Iter_orbitIncEOD(mEOData, true); }
350
351 Iter_pedData begin_pedData() const { return Iter_pedData(mEOData, false); }
352 Iter_pedData end_pedData() const { return Iter_pedData(mEOData, true); }
353
354 Iter_sclInc begin_sclInc() const { return Iter_sclInc(mEOData, false); }
355 Iter_sclInc end_sclInc() const { return Iter_sclInc(mEOData, true); }
356
357 private:
358 const gsl::span<const o2::zdc::BCData> mTrigData;
359 const gsl::span<const o2::zdc::ChannelData> mChanData;
360 const gsl::span<const o2::zdc::OrbitData> mEOData;
361};
362
363} // namespace zdc
364} // namespace o2
365
366#endif
int32_t i
uint32_t res
Definition RawData.h:0
Definitions for ZDC CTF data.
Class for time synchronization of RawReader instances.
static constexpr ID ZDC
Definition DetID.h:74
value_type operator[](difference_type i) const
Definition CTFHelper.h:156
value_type operator[](difference_type i) const
Definition CTFHelper.h:264
value_type operator*() const
Definition CTFHelper.h:254
value_type operator[](difference_type i) const
Definition CTFHelper.h:255
value_type operator[](difference_type i) const
Definition CTFHelper.h:206
value_type operator[](difference_type i) const
Definition CTFHelper.h:234
value_type operator[](difference_type i) const
Definition CTFHelper.h:192
value_type operator[](difference_type i) const
Definition CTFHelper.h:244
value_type operator[](difference_type i) const
Definition CTFHelper.h:280
value_type operator[](difference_type i) const
Definition CTFHelper.h:178
value_type operator[](difference_type i) const
Definition CTFHelper.h:293
value_type operator*() const
Definition CTFHelper.h:292
value_type operator[](difference_type i) const
Definition CTFHelper.h:311
value_type operator*() const
Definition CTFHelper.h:305
value_type operator[](difference_type i) const
Definition CTFHelper.h:220
friend I operator+(difference_type i, const I &iter)
Definition CTFHelper.h:124
bool operator>=(const I &other) const noexcept
Definition CTFHelper.h:130
bool operator<(const I &other) const noexcept
Definition CTFHelper.h:129
difference_type operator-(const I &other) const noexcept
Definition CTFHelper.h:122
bool operator>(const I &other) const noexcept
Definition CTFHelper.h:128
I operator-(difference_type i) const
Definition CTFHelper.h:116
I & operator+=(difference_type i) noexcept
Definition CTFHelper.h:98
difference_type mIndex
Definition CTFHelper.h:135
bool operator!=(const I &other) const noexcept
Definition CTFHelper.h:126
I & operator++() noexcept
Definition CTFHelper.h:72
_Iter(const gsl::span< const D > &data, bool end=false)
Definition CTFHelper.h:69
bool operator==(const I &other) const noexcept
Definition CTFHelper.h:127
bool operator<=(const I &other) const noexcept
Definition CTFHelper.h:131
std::random_access_iterator_tag iterator_category
Definition CTFHelper.h:67
I & operator--() noexcept
Definition CTFHelper.h:85
gsl::span< const D > mData
Definition CTFHelper.h:134
I & operator-=(difference_type i) noexcept
Definition CTFHelper.h:110
std::ptrdiff_t difference_type
Definition CTFHelper.h:63
I operator+(difference_type i) const
Definition CTFHelper.h:104
Iter_sclInc end_sclInc() const
Definition CTFHelper.h:355
Iter_extTriggers end_extTriggers() const
Definition CTFHelper.h:337
Iter_bcIncTrig end_bcIncTrig() const
Definition CTFHelper.h:322
Iter_triggersHL end_triggersHL() const
Definition CTFHelper.h:334
Iter_chanID begin_chanID() const
Definition CTFHelper.h:342
CTFHeader createHeader()
Definition CTFHelper.h:40
CTFHelper(const gsl::span< const BCData > &trgData, const gsl::span< const ChannelData > &chanData, const gsl::span< const OrbitData > &pedData)
Definition CTFHelper.h:35
Iter_moduleTrig begin_moduleTrig() const
Definition CTFHelper.h:327
Iter_bcIncTrig begin_bcIncTrig() const
Definition CTFHelper.h:321
size_t getSize() const
Definition CTFHelper.h:55
Iter_pedData end_pedData() const
Definition CTFHelper.h:352
Iter_orbitIncEOD end_orbitIncEOD() const
Definition CTFHelper.h:349
Iter_moduleTrig end_moduleTrig() const
Definition CTFHelper.h:328
Iter_channelsHL end_channelsHL() const
Definition CTFHelper.h:331
Iter_orbitIncTrig begin_orbitIncTrig() const
Definition CTFHelper.h:324
Iter_orbitIncTrig end_orbitIncTrig() const
Definition CTFHelper.h:325
Iter_triggersHL begin_triggersHL() const
Definition CTFHelper.h:333
Iter_nchanTrig begin_nchanTrig() const
Definition CTFHelper.h:339
Iter_sclInc begin_sclInc() const
Definition CTFHelper.h:354
Iter_chanData end_chanData() const
Definition CTFHelper.h:346
Iter_orbitIncEOD begin_orbitIncEOD() const
Definition CTFHelper.h:348
Iter_pedData begin_pedData() const
Definition CTFHelper.h:351
Iter_channelsHL begin_channelsHL() const
Definition CTFHelper.h:330
Iter_chanID end_chanID() const
Definition CTFHelper.h:343
Iter_extTriggers begin_extTriggers() const
Definition CTFHelper.h:336
Iter_chanData begin_chanData() const
Definition CTFHelper.h:345
Iter_nchanTrig end_nchanTrig() const
Definition CTFHelper.h:340
GLsizeiptr size
Definition glcorearb.h:659
GLuint GLuint end
Definition glcorearb.h:469
GLboolean * data
Definition glcorearb.h:298
struct o2::upgrades_utils::@463 zdc
structure to keep FT0 information
constexpr int NModules
Definition Constants.h:68
constexpr int NTimeBinsPerBC
Definition Constants.h:53
constexpr int NChannels
Definition Constants.h:65
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
uint32_t orbit
LHC orbit.
uint16_t bc
bunch crossing ID of interaction
Header for a single CTF.
Definition CTF.h:32
VectorOfTObjectPtrs other
o2::InteractionRecord ir(0, 0)
std::vector< ChannelData > channels