Project
Loading...
Searching...
No Matches
CTFCoder.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_FV0_CTFCODER_H
17#define O2_FV0_CTFCODER_H
18
19#include "DataFormatsFV0/CTF.h"
25
26class TTree;
27
28namespace o2
29{
30namespace fv0
31{
32
33class CTFCoder final : public o2::ctf::CTFCoderBase
34{
35 public:
36 CTFCoder(o2::ctf::CTFCoderBase::OpType op, const std::string& ctfdictOpt = "none") : o2::ctf::CTFCoderBase(op, CTF::getNBlocks(), o2::detectors::DetID::FV0, 1.f, ctfdictOpt) {}
37 ~CTFCoder() final = default;
38
40 template <typename VEC>
41 o2::ctf::CTFIOSize encode(VEC& buff, const gsl::span<const Digit>& digitVec, const gsl::span<const ChannelData>& channelVec);
42
44 template <typename VDIG, typename VCHAN>
45 o2::ctf::CTFIOSize decode(const CTF::base& ec, VDIG& digitVec, VCHAN& channelVec);
46
47 void createCoders(const std::vector<char>& bufVec, o2::ctf::CTFCoderBase::OpType op) final;
48
49 private:
51 template <int MAJOR_VERSION, int MINOR_VERSION>
52 void compress(CompressedDigits& cd, const gsl::span<const Digit>& digitVec, const gsl::span<const ChannelData>& channelVec);
53 size_t estimateCompressedSize(const CompressedDigits& cc);
54
56 template <int MAJOR_VERSION, int MINOR_VERSION, typename VDIG, typename VCHAN>
57 void decompress(const CompressedDigits& cd, VDIG& digitVec, VCHAN& channelVec);
58
59 void appendToTree(TTree& tree, CTF& ec);
60 void readFromTree(TTree& tree, int entry, std::vector<Digit>& digitVec, std::vector<ChannelData>& channelVec);
61 void assignDictVersion(o2::ctf::CTFDictHeader& h) const final;
62};
63
65template <typename VEC>
66o2::ctf::CTFIOSize CTFCoder::encode(VEC& buff, const gsl::span<const Digit>& digitVec, const gsl::span<const ChannelData>& channelVec)
67{
69 // what to do which each field: see o2::ctd::Metadata explanation
70 constexpr MD optField[CTF::getNBlocks()] = {
71 MD::EENCODE_OR_PACK, // BLC_bcInc
72 MD::EENCODE_OR_PACK, // BLC_orbitInc
73 MD::EENCODE_OR_PACK, // BLC_nChan
74 MD::EENCODE_OR_PACK, // BLC_idChan
75 MD::EENCODE_OR_PACK, // BLC_cfdTime
76 MD::EENCODE_OR_PACK, // BLC_qtcAmpl
77 // extra slot was added in the end
78 MD::EENCODE_OR_PACK, // BLC_trigger
79 MD::EENCODE_OR_PACK // BLC_qtcChain
80 };
84 compress<1, 0>(cd, digitVec, channelVec);
85 } else {
86 compress<1, 1>(cd, digitVec, channelVec);
87 }
88 } else {
89 compress<1, 1>(cd, digitVec, channelVec);
90 }
91 // book output size with some margin
92 auto szIni = estimateCompressedSize(cd);
93 buff.resize(szIni);
94
95 auto ec = CTF::create(buff);
96 using ECB = CTF::base;
97
98 ec->setHeader(cd.header);
99 assignDictVersion(static_cast<o2::ctf::CTFDictHeader&>(ec->getHeader()));
100 ec->setANSHeader(mANSVersion);
101 // at every encoding the buffer might be autoexpanded, so we don't work with fixed pointer ec
102 o2::ctf::CTFIOSize iosize;
103#define ENCODEFV0(part, slot, bits) CTF::get(buff.data())->encode(part, int(slot), bits, optField[int(slot)], &buff, mCoders[int(slot)], getMemMarginFactor());
104 // clang-format off
105 iosize += ENCODEFV0(cd.bcInc, CTF::BLC_bcInc, 0);
106 iosize += ENCODEFV0(cd.orbitInc, CTF::BLC_orbitInc, 0);
107 iosize += ENCODEFV0(cd.nChan, CTF::BLC_nChan, 0);
108 iosize += ENCODEFV0(cd.idChan , CTF::BLC_idChan, 0);
109 iosize += ENCODEFV0(cd.cfdTime, CTF::BLC_cfdTime, 0);
110 iosize += ENCODEFV0(cd.qtcAmpl, CTF::BLC_qtcAmpl, 0);
111 // extra slot was added in the end
112 iosize += ENCODEFV0(cd.trigger, CTF::BLC_trigger, 0);
113 iosize += ENCODEFV0(cd.qtcChain, CTF::BLC_qtcChain, 0);
114 // clang-format on
115 CTF::get(buff.data())->print(getPrefix(), mVerbosity);
116 finaliseCTFOutput<CTF>(buff);
117 iosize.rawIn = sizeof(Digit) * digitVec.size() + sizeof(ChannelData) * channelVec.size();
118 return iosize;
119}
120
122template <typename VDIG, typename VCHAN>
123o2::ctf::CTFIOSize CTFCoder::decode(const CTF::base& ec, VDIG& digitVec, VCHAN& channelVec)
124{
126 cd.header = ec.getHeader();
127 const auto& hd = static_cast<const o2::ctf::CTFDictHeader&>(cd.header);
130 o2::ctf::CTFIOSize iosize;
131#define DECODEFV0(part, slot) ec.decode(part, int(slot), mCoders[int(slot)])
132 // clang-format off
133 iosize += DECODEFV0(cd.bcInc, CTF::BLC_bcInc);
134 iosize += DECODEFV0(cd.orbitInc, CTF::BLC_orbitInc);
135 iosize += DECODEFV0(cd.nChan, CTF::BLC_nChan);
136 iosize += DECODEFV0(cd.idChan, CTF::BLC_idChan);
137 iosize += DECODEFV0(cd.cfdTime, CTF::BLC_cfdTime);
138 iosize += DECODEFV0(cd.qtcAmpl, CTF::BLC_qtcAmpl);
139 // extra slot was added in the end
140 iosize += DECODEFV0(cd.trigger, CTF::BLC_trigger);
141 iosize += DECODEFV0(cd.qtcChain, CTF::BLC_qtcChain);
142 // triggers and qtcChain were added later, in old data they are absent:
143 if (cd.trigger.empty()) {
144 cd.trigger.resize(cd.header.nTriggers);
145 }
146 if (cd.qtcChain.empty()) {
147 cd.qtcChain.resize(cd.cfdTime.size());
148 }
149 // clang-format on
150 //
151 if (hd.minorVersion == 0 && hd.majorVersion == 1) {
152 decompress<1, 0>(cd, digitVec, channelVec);
153 } else {
154 decompress<1, 1>(cd, digitVec, channelVec);
155 }
156 iosize.rawIn = sizeof(Digit) * digitVec.size() + sizeof(ChannelData) * channelVec.size();
157 return iosize;
158}
159
161template <int MAJOR_VERSION, int MINOR_VERSION, typename VDIG, typename VCHAN>
162void CTFCoder::decompress(const CompressedDigits& cd, VDIG& digitVec, VCHAN& channelVec)
163{
164 digitVec.clear();
165 channelVec.clear();
166 digitVec.reserve(cd.header.nTriggers);
167 channelVec.reserve(cd.idChan.size());
168
169 uint32_t firstEntry = 0, clCount = 0, chipCount = 0;
171 if (mBCShift && ir.toLong() >= mBCShift) {
172 ir -= mBCShift;
173 }
174 for (uint32_t idig = 0; idig < cd.header.nTriggers; idig++) {
175 // restore ROFRecord
176 if (cd.orbitInc[idig]) { // non-0 increment => new orbit
177 ir.bc = cd.bcInc[idig]; // bcInc has absolute meaning
178 ir.orbit += cd.orbitInc[idig];
179 } else {
180 ir.bc += cd.bcInc[idig];
181 }
182 const auto& params = FV0DigParam::Instance();
183 int triggerGate = params.mTime_trg_gate;
184 firstEntry = channelVec.size();
185 uint8_t chID = 0;
186 int8_t nChanA = 0, nChanC = 0;
188 int16_t timeA = 0, timeC = Triggers::DEFAULT_TIME;
189 for (uint8_t ic = 0; ic < cd.nChan[idig]; ic++) {
190 auto icc = channelVec.size();
191 if constexpr (MINOR_VERSION == 0 && MAJOR_VERSION == 1) {
192 // Old decoding procedure, mostly for Pilot Beam in October 2021
193 chID += cd.idChan[icc];
194 } else {
195 // New decoding procedure, w/o sorted ChID requriment
196 chID = cd.idChan[icc];
197 }
198 const auto& chan = channelVec.emplace_back(chID, cd.cfdTime[icc], cd.qtcAmpl[icc], cd.qtcChain[icc]);
199 if (std::abs(chan.CFDTime) < triggerGate) {
200 amplA += chan.QTCAmpl;
201 timeA += chan.CFDTime;
202 nChanA++;
203 }
204 }
205 if (nChanA) {
206 timeA /= nChanA;
207 amplA *= 0.125;
208 } else {
211 }
212 Triggers trig;
213 trig.setTriggers(cd.trigger[idig], nChanA, nChanC, amplA, amplC, timeA, timeC);
214 digitVec.emplace_back(firstEntry, cd.nChan[idig], ir, trig, idig);
215 }
216}
218template <int MAJOR_VERSION, int MINOR_VERSION>
219void CTFCoder::compress(CompressedDigits& cd, const gsl::span<const Digit>& digitVec, const gsl::span<const ChannelData>& channelVec)
220{
221 // convert digits/channel to their compressed version
222 cd.clear();
223 cd.header.det = mDet;
224 if (!digitVec.size()) {
225 return;
226 }
227 uint32_t firstDig = digitVec.size(), nDigSel = digitVec.size(), nChanSel = channelVec.size();
228 std::vector<bool> reject(digitVec.size());
229 if (mIRFrameSelector.isSet()) {
230 for (size_t id = 0; id < digitVec.size(); id++) {
231 if (mIRFrameSelector.check(digitVec[id].mIntRecord) < 0) {
232 reject[id] = true;
233 nDigSel--;
234 nChanSel -= digitVec[id].ref.getEntries();
235 } else if (firstDig == digitVec.size()) {
236 firstDig = id;
237 }
238 }
239 } else {
240 firstDig = 0;
241 }
242 if (nDigSel == 0) { // nothing is selected
243 return;
244 }
245 const auto& dig0 = digitVec[firstDig];
246 cd.header.nTriggers = nDigSel;
247 cd.header.firstOrbit = dig0.getOrbit();
248 cd.header.firstBC = dig0.getBC();
249 cd.header.triggerGate = FV0DigParam::Instance().mTime_trg_gate;
250
251 cd.trigger.resize(cd.header.nTriggers);
252 cd.bcInc.resize(cd.header.nTriggers);
253 cd.orbitInc.resize(cd.header.nTriggers);
254 cd.nChan.resize(cd.header.nTriggers);
255
256 cd.idChan.resize(nChanSel);
257 cd.qtcChain.resize(nChanSel);
258 cd.cfdTime.resize(nChanSel);
259 cd.qtcAmpl.resize(nChanSel);
260
261 uint16_t prevBC = cd.header.firstBC;
262 uint32_t prevOrbit = cd.header.firstOrbit;
263 uint32_t ccount = 0, dcount = 0;
264 for (uint32_t idig = 0; idig < digitVec.size(); idig++) {
265 if (reject[idig]) {
266 continue;
267 }
268 const auto& digit = digitVec[idig];
269 const auto chanels = digit.getBunchChannelData(channelVec); // we assume the channels are sorted
270
271 // fill trigger info
272 cd.trigger[dcount] = digit.getTriggers().getTriggersignals();
273 if (prevOrbit == digit.getOrbit()) {
274 cd.bcInc[dcount] = digit.getBC() - prevBC;
275 cd.orbitInc[dcount] = 0;
276 } else {
277 cd.bcInc[dcount] = digit.getBC();
278 cd.orbitInc[dcount] = digit.getOrbit() - prevOrbit;
279 }
280 prevBC = digit.getBC();
281 prevOrbit = digit.getOrbit();
282 // fill channels info
283 cd.nChan[dcount] = chanels.size();
284 if (!cd.nChan[dcount]) {
285 LOG(debug) << "Digits with no channels";
286 dcount++;
287 continue;
288 }
289 uint8_t prevChan = 0;
290 for (uint8_t ic = 0; ic < cd.nChan[dcount]; ic++) {
291 if constexpr (MINOR_VERSION == 0 && MAJOR_VERSION == 1) {
292 cd.idChan[ccount] = chanels[ic].ChId - prevChan; // Old method, lets keep it for a while
293 } else {
294 cd.idChan[ccount] = chanels[ic].ChId;
295 }
296 cd.qtcChain[ccount] = chanels[ic].ChainQTC;
297 cd.cfdTime[ccount] = chanels[ic].CFDTime;
298 cd.qtcAmpl[ccount] = chanels[ic].QTCAmpl;
299 prevChan = chanels[ic].ChId;
300 ccount++;
301 }
302 dcount++;
303 }
304}
305
306} // namespace fv0
307} // namespace o2
308
309#endif // O2_FV0_CTFCODER_H
Declarations for CTFCoderBase class (support of external dictionaries)
Class to describe fired triggered and/or stored channels for the BC and to refer to channel data.
std::ostringstream debug
Definitions for FV0 CTF data.
Container class to store time and charge values of single FV0 channel.
#define ENCODEFV0(part, slot, bits)
#define DECODEFV0(part, slot)
uint64_t nChanC
int64_t timeC
uint64_t nChanA
int64_t amplA
int64_t timeA
int64_t amplC
Configurable digitization parameters.
unsigned short int uint16_t
unsigned int uint32_t
uint32_t op
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder int32_t
Class for time synchronization of RawReader instances.
void checkDictVersion(const CTFDictHeader &h) const
ctf::ANSHeader mANSVersion
CTFDictHeader mExtHeader
std::string getPrefix() const
o2::utils::IRFrameSelector mIRFrameSelector
<<======================== Auxiliary classes =======================<<
static auto get(void *head)
cast arbitrary buffer head to container class. Head is supposed to respect the alignment
const H & getHeader() const
void print(const std::string &prefix="", int verbosity=1) const
print itself
EncodedBlocks< CTFHeader, N, uint32_t > base
static auto create(void *head, size_t sz)
create container from arbitrary buffer of predefined size (in bytes!!!). Head is supposed to respect ...
Static class with identifiers, bitmasks and names for ALICE detectors.
Definition DetID.h:60
static const int16_t DEFAULT_AMP
Definition Triggers.h:51
static const int16_t DEFAULT_TIME
Definition Triggers.h:50
void setTriggers(uint8_t trgsig, uint8_t chanA, uint8_t chanC, int32_t aamplA, int32_t aamplC, int16_t atimeA, int16_t atimeC)
Definition Triggers.h:103
o2::ctf::CTFIOSize encode(VEC &buff, const gsl::span< const Digit > &digitVec, const gsl::span< const ChannelData > &channelVec)
entropy-encode digits to buffer with CTF
Definition CTFCoder.h:66
o2::ctf::CTFIOSize decode(const CTF::base &ec, VDIG &digitVec, VCHAN &channelVec)
entropy decode clusters from buffer with CTF
Definition CTFCoder.h:123
CTFCoder(o2::ctf::CTFCoderBase::OpType op, const std::string &ctfdictOpt="none")
Definition CTFCoder.h:36
void createCoders(const std::vector< char > &bufVec, o2::ctf::CTFCoderBase::OpType op) final
Definition CTFCoder.cxx:52
~CTFCoder() final=default
long check(o2::dataformats::IRFrame fr, size_t bwd=0, size_t fwd=0)
GLenum const GLfloat * params
Definition glcorearb.h:272
GLuint id
Definition glcorearb.h:650
o2::fit::Triggers Triggers
Definition Digit.h:35
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
Detector header base.
bool isValidDictTimeStamp() const
uint32_t nTriggers
Definition CTF.h:30
uint16_t firstBC
1st orbit of TF
Definition CTF.h:32
uint32_t firstOrbit
number of triggers in TF
Definition CTF.h:31
wrapper for the Entropy-encoded clusters of the TF
Definition CTF.h:62
@ BLC_orbitInc
Definition CTF.h:67
@ BLC_bcInc
Definition CTF.h:66
@ BLC_idChan
Definition CTF.h:70
@ BLC_qtcAmpl
Definition CTF.h:72
@ BLC_cfdTime
Definition CTF.h:71
@ BLC_nChan
Definition CTF.h:68
@ BLC_trigger
Definition CTF.h:75
@ BLC_qtcChain
Definition CTF.h:76
Intermediate, compressed but not yet entropy-encoded digits.
Definition CTF.h:38
std::vector< uint8_t > qtcChain
Definition CTF.h:52
std::vector< int16_t > qtcAmpl
Definition CTF.h:51
std::vector< int16_t > bcInc
Definition CTF.h:44
std::vector< uint8_t > nChan
Definition CTF.h:46
std::vector< uint8_t > idChan
Definition CTF.h:49
std::vector< int16_t > cfdTime
Definition CTF.h:50
std::vector< uint8_t > trigger
Definition CTF.h:43
std::vector< int32_t > orbitInc
Definition CTF.h:45
std::vector< o2::mch::ChannelCode > cc
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
o2::InteractionRecord ir(0, 0)
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))