Project
Loading...
Searching...
No Matches
DecoderBase.cxx
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
16
20
21#include <cstring>
22#include <iostream>
23
24// o2::ctf::CTFIOSize iosize;
25#define ENCODER_PARANOID
26// o2::ctf::CTFIOSize iosize;
27#define ENCODER_VERBOSE
28
29#ifdef DECODER_PARANOID
30#warning "Building code with DecoderParanoid option. This may limit the speed."
31#endif
32#ifdef DECODER_VERBOSE
33#warning "Building code with DecoderVerbose option. This may limit the speed."
34#endif
35
36#define colorReset "\033[0m"
37#define colorRed "\033[1;31m"
38#define colorGreen "\033[1;32m"
39#define colorYellow "\033[1;33m"
40#define colorBlue "\033[1;34m"
41
42namespace o2
43{
44namespace tof
45{
46namespace compressed
47{
48
50
51template <typename RDH>
52bool DecoderBaseT<RDH>::processHBF()
53{
54
55#ifdef DECODER_VERBOSE
56 if (mDecoderVerbose) {
57 std::cout << colorBlue
58 << "--- PROCESS HBF"
59 << colorReset
60 << std::endl;
61 }
62#endif
63
64 if (mDecoderBufferSize <= 0) {
65 std::cout << colorRed
66 << " got an empty buffer, do nothing"
67 << colorReset
68 << std::endl;
69 return true;
70 }
71
72 mDecoderRDH = reinterpret_cast<const RDH*>(mDecoderPointer);
73 auto rdh = mDecoderRDH;
74
75 int iterations = 0;
77 while (!RDHUtils::getStop(*rdh)) {
78 iterations++;
79 if (iterations > 5) {
80 return true;
81 }
82#ifdef DECODER_VERBOSE
83 if (mDecoderVerbose) {
84 std::cout << colorBlue
85 << "--- RDH open/continue detected"
86 << colorReset
87 << std::endl;
89 }
90#endif
91
93 rdhHandler(rdh);
94
95 auto headerSize = RDHUtils::getHeaderSize(*rdh);
96 auto memorySize = RDHUtils::getMemorySize(*rdh);
97 auto offsetToNext = RDHUtils::getOffsetToNext(*rdh);
98 auto drmPayload = memorySize - headerSize;
99
100 bool isValidRDH = RDHUtils::checkRDH(*rdh, false);
101
103 if (isValidRDH && drmPayload > 0) {
104 std::memcpy(mDecoderSaveBuffer + mDecoderSaveBufferDataSize, reinterpret_cast<const char*>(rdh) + headerSize, drmPayload);
105 mDecoderSaveBufferDataSize += drmPayload;
106 }
107#ifdef DECODER_VERBOSE
108 else {
109 if (mDecoderVerbose) {
110 RDHUtils::checkRDH(*rdh); // verbose
111 }
112 }
113#endif
114
116 rdh = reinterpret_cast<const RDH*>(reinterpret_cast<const char*>(rdh) + offsetToNext);
117
119 if (reinterpret_cast<const char*>(rdh) < mDecoderBuffer + mDecoderBufferSize) {
120 continue;
121 }
122
124 return true;
125 }
126
127#ifdef DECODER_VERBOSE
128 if (mDecoderVerbose) {
129 std::cout << colorBlue
130 << "--- RDH close detected"
131 << colorReset
132 << std::endl;
134 }
135#endif
136
138 mDecoderPointer = reinterpret_cast<const uint32_t*>(mDecoderSaveBuffer);
139 mDecoderPointerMax = reinterpret_cast<const uint32_t*>(mDecoderSaveBuffer + mDecoderSaveBufferDataSize);
140 while (mDecoderPointer < mDecoderPointerMax) {
141 if (processDRM()) {
142 break;
143 }
144 }
145 mDecoderSaveBufferDataSize = 0;
146
148 rdhHandler(rdh);
149
150#ifdef DECODER_VERBOSE
151 if (mDecoderVerbose) {
152 std::cout << colorBlue
153 << "--- END PROCESS HBF"
154 << colorReset
155 << std::endl;
156 }
157#endif
158
160 mDecoderPointer = reinterpret_cast<const uint32_t*>(reinterpret_cast<const char*>(rdh) + RDHUtils::getOffsetToNext(*rdh));
161
163 if (reinterpret_cast<const char*>(mDecoderPointer) < mDecoderBuffer + mDecoderBufferSize) {
164 return false;
165 }
166
168 return true;
169}
170
171template <typename RDH>
172bool DecoderBaseT<RDH>::processDRM()
173{
174
175#ifdef DECODER_VERBOSE
176 if (mDecoderVerbose) {
177 std::cout << colorBlue << "--- PROCESS DRM"
178 << colorReset
179 << std::endl;
180 }
181#endif
182
183 if ((*mDecoderPointer & 0x80000000) != 0x80000000) {
184#ifdef DECODER_VERBOSE
185 if (mDecoderVerbose) {
186 printf(" %08x [ERROR] \n ", *mDecoderPointer);
187 }
188#endif
189 return true;
190 }
191
193 auto crateHeader = reinterpret_cast<const CrateHeader_t*>(mDecoderPointer);
194#ifdef DECODER_VERBOSE
195 if (mDecoderVerbose) {
196 printf(" %08x CrateHeader (drmID=%d) \n ", *mDecoderPointer, crateHeader->drmID);
197 }
198#endif
199 mDecoderPointer++;
200
202 auto crateOrbit = reinterpret_cast<const CrateOrbit_t*>(mDecoderPointer);
203#ifdef DECODER_VERBOSE
204 if (mDecoderVerbose) {
205 printf(" %08x CrateOrbit (orbit=0x%08x) \n ", *mDecoderPointer, crateOrbit->orbitID);
206 }
207#endif
208 mDecoderPointer++;
209
211 headerHandler(crateHeader, crateOrbit);
212
213 while (true) {
214
216 if (*mDecoderPointer & 0x80000000) {
217 auto crateTrailer = reinterpret_cast<const CrateTrailer_t*>(mDecoderPointer);
218#ifdef DECODER_VERBOSE
219 if (mDecoderVerbose) {
220 printf(" %08x CrateTrailer (numberOfDiagnostics=%d, numberOfErrors=%d) \n ", *mDecoderPointer, crateTrailer->numberOfDiagnostics, crateTrailer->numberOfErrors);
221 }
222#endif
223 mDecoderPointer++;
224 auto diagnostics = reinterpret_cast<const Diagnostic_t*>(mDecoderPointer);
225#ifdef DECODER_VERBOSE
226 if (mDecoderVerbose) {
227 for (int i = 0; i < crateTrailer->numberOfDiagnostics; ++i) {
228 auto diagnostic = reinterpret_cast<const Diagnostic_t*>(mDecoderPointer + i);
229 printf(" %08x Diagnostic (slotId=%d) \n ", *(mDecoderPointer + i), diagnostic->slotID);
230 }
231 }
232#endif
233 mDecoderPointer += crateTrailer->numberOfDiagnostics;
234 auto errors = reinterpret_cast<const Error_t*>(mDecoderPointer);
235#ifdef DECODER_VERBOSE
236 if (mDecoderVerbose) {
237 for (int i = 0; i < crateTrailer->numberOfErrors; ++i) {
238 auto error = reinterpret_cast<const Error_t*>(mDecoderPointer + i);
239 printf(" %08x Error (slotId=%d) \n ", *(mDecoderPointer + i), error->slotID);
240 }
241 }
242#endif
243 mDecoderPointer += crateTrailer->numberOfErrors;
244
246 trailerHandler(crateHeader, crateOrbit, crateTrailer, diagnostics, errors);
247
248 return false;
249 }
250
252 auto frameHeader = reinterpret_cast<const FrameHeader_t*>(mDecoderPointer);
253#ifdef DECODER_VERBOSE
254 if (mDecoderVerbose) {
255 printf(" %08x FrameHeader (numberOfHits=%d) \n ", *mDecoderPointer, frameHeader->numberOfHits);
256 }
257#endif
258 mDecoderPointer++;
259 auto packedHits = reinterpret_cast<const PackedHit_t*>(mDecoderPointer);
260#ifdef DECODER_VERBOSE
261 if (mDecoderVerbose) {
262 for (int i = 0; i < frameHeader->numberOfHits; ++i) {
263 auto packedHit = reinterpret_cast<const PackedHit_t*>(mDecoderPointer + 1);
264 printf(" %08x PackedHit (tdcID=%d) \n ", *(mDecoderPointer + 1), packedHit->tdcID);
265 packedHits++;
266 }
267 }
268#endif
269 mDecoderPointer += frameHeader->numberOfHits;
270
272 frameHandler(crateHeader, crateOrbit, frameHeader, packedHits);
273 }
274
276 return false;
277}
278
279template class DecoderBaseT<o2::header::RAWDataHeaderV4>;
280template class DecoderBaseT<o2::header::RAWDataHeaderV6>;
281template class DecoderBaseT<o2::header::RAWDataHeaderV7>;
282
283} // namespace compressed
284} // namespace tof
285} // namespace o2
#define colorBlue
#define colorRed
#define colorReset
int32_t i
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
static void printRDH(const RDHv4 &rdh)
Definition RDHUtils.cxx:26
static bool checkRDH(const RDHv4 &rdh, bool verbose=true, bool checkZeros=false)
Definition RDHUtils.cxx:133