forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompressedDecodingTask.cxx
More file actions
332 lines (287 loc) · 12.9 KB
/
CompressedDecodingTask.cxx
File metadata and controls
332 lines (287 loc) · 12.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// @file CompressedDecodingTask.cxx
/// @author Francesco Noferini
/// @since 2020-02-25
/// @brief TOF compressed data decoding task
#include "TOFWorkflowUtils/CompressedDecodingTask.h"
#include "Framework/ControlService.h"
#include "Framework/ConfigParamRegistry.h"
#include "CommonUtils/StringUtils.h"
#include "Headers/RAWDataHeader.h"
#include "DataFormatsTOF/CompressedDataFormat.h"
#include "DetectorsRaw/HBFUtils.h"
#include "DataFormatsParameters/GRPObject.h"
#include "Framework/WorkflowSpec.h"
#include "Framework/Logger.h"
#include "DetectorsRaw/RDHUtils.h"
using namespace o2::framework;
namespace o2
{
namespace tof
{
using RDHUtils = o2::raw::RDHUtils;
void CompressedDecodingTask::init(InitContext& ic)
{
LOG(INFO) << "CompressedDecoding init";
mMaskNoise = ic.options().get<bool>("mask-noise");
mNoiseRate = ic.options().get<int>("noise-counts");
mRowFilter = ic.options().get<bool>("row-filter");
if (mMaskNoise)
mDecoder.maskNoiseRate(mNoiseRate);
auto finishFunction = [this]() {
LOG(INFO) << "CompressedDecoding finish";
};
ic.services().get<CallbackService>().set(CallbackService::Id::Stop, finishFunction);
mTimer.Stop();
mTimer.Reset();
}
void CompressedDecodingTask::postData(ProcessingContext& pc)
{
mHasToBePosted = false;
mDecoder.FillWindows();
// send output message
std::vector<o2::tof::Digit>* alldigits = mDecoder.getDigitPerTimeFrame();
std::vector<o2::tof::ReadoutWindowData>* row = mDecoder.getReadoutWindowData();
if (mRowFilter)
row = mDecoder.getReadoutWindowDataFiltered();
ReadoutWindowData* last = nullptr;
o2::InteractionRecord lastIR;
int lastval = 0;
if (!row->empty()) {
last = &row->back();
lastval = last->first() + last->size();
lastIR = last->mFirstIR;
}
/*
int nwindowperTF = o2::raw::HBFUtils::Instance().getNOrbitsPerTF() * 3;
while (row->size() < nwindowperTF) {
// complete timeframe with empty readout windows
auto& dummy = row->emplace_back(lastval, 0);
dummy.mFirstIR = lastIR;
}
while (row->size() > nwindowperTF) {
// remove extra readout windows after a check they are empty
row->pop_back();
}
*/
int n_tof_window = row->size();
int n_orbits = n_tof_window / 3;
int digit_size = alldigits->size();
// LOG(INFO) << "TOF: N tof window decoded = " << n_tof_window << "(orbits = " << n_orbits << ") with " << digit_size << " digits";
// add digits in the output snapshot
pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "DIGITS", 0, Lifetime::Timeframe}, *alldigits);
pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "READOUTWINDOW", 0, Lifetime::Timeframe}, *row);
std::vector<uint32_t>& patterns = mDecoder.getPatterns();
pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "PATTERNS", 0, Lifetime::Timeframe}, patterns);
std::vector<uint64_t>& errors = mDecoder.getErrors();
pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "ERRORS", 0, Lifetime::Timeframe}, errors);
// RS this is a hack to be removed once we have correct propagation of the firstTForbit by the framework
auto setFirstTFOrbit = [&](const Output& spec, uint32_t orb) {
auto* hd = pc.outputs().findMessageHeader(spec);
if (!hd) {
throw std::runtime_error(o2::utils::concat_string("failed to find output message header for ", spec.origin.str, "/", spec.description.str, "/", std::to_string(spec.subSpec)));
}
hd->firstTForbit = orb;
};
setFirstTFOrbit(Output{o2::header::gDataOriginTOF, "DIGITS", 0, Lifetime::Timeframe}, mInitOrbit);
setFirstTFOrbit(Output{o2::header::gDataOriginTOF, "READOUTWINDOW", 0, Lifetime::Timeframe}, mInitOrbit);
mDecoder.clear();
mNTF++;
mNCrateOpenTF = 0;
mNCrateCloseTF = 0;
}
void CompressedDecodingTask::run(ProcessingContext& pc)
{
mTimer.Start(false);
if (pc.inputs().getNofParts(0) && !mConetMode) {
//RS set the 1st orbit of the TF from the O2 header, relying on rdhHandler is not good (in fact, the RDH might be eliminated in the derived data)
const auto* dh = o2::header::get<o2::header::DataHeader*>(pc.inputs().getByPos(0).header);
mInitOrbit = dh->firstTForbit;
}
mDecoder.setFirstIR({0, mInitOrbit});
/** loop over inputs routes **/
for (auto iit = pc.inputs().begin(), iend = pc.inputs().end(); iit != iend; ++iit) {
if (!iit.isValid())
continue;
/** loop over input parts **/
for (auto const& ref : iit) {
const auto* headerIn = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
auto payloadIn = ref.payload;
auto payloadInSize = headerIn->payloadSize;
DecoderBase::setDecoderBuffer(payloadIn);
DecoderBase::setDecoderBufferSize(payloadInSize);
DecoderBase::run();
}
}
if ((mNCrateOpenTF == 72 || mConetMode) && mNCrateOpenTF == mNCrateCloseTF)
mHasToBePosted = true;
if (mHasToBePosted) {
postData(pc);
}
mTimer.Stop();
}
void CompressedDecodingTask::endOfStream(EndOfStreamContext& ec)
{
LOGF(INFO, "TOF CompressedDecoding total timing: Cpu: %.3e Real: %.3e s in %d slots",
mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1);
}
void CompressedDecodingTask::headerHandler(const CrateHeader_t* crateHeader, const CrateOrbit_t* crateOrbit)
{
if (mConetMode) {
LOG(DEBUG) << "Crate found" << crateHeader->drmID;
mInitOrbit = crateOrbit->orbitID;
mNCrateOpenTF++;
}
}
void CompressedDecodingTask::trailerHandler(const CrateHeader_t* crateHeader, const CrateOrbit_t* crateOrbit,
const CrateTrailer_t* crateTrailer, const Diagnostic_t* diagnostics,
const Error_t* errors)
{
if (mConetMode) {
LOG(DEBUG) << "Crate closed" << crateHeader->drmID;
mNCrateCloseTF++;
}
// Diagnostics used to fill digit patterns
auto numberOfDiagnostics = crateTrailer->numberOfDiagnostics;
auto numberOfErrors = crateTrailer->numberOfErrors;
for (int i = 0; i < numberOfDiagnostics; i++) {
const uint32_t* val = reinterpret_cast<const uint32_t*>(&(diagnostics[i]));
mDecoder.addPattern(*val, crateHeader->drmID, crateOrbit->orbitID, crateHeader->bunchID);
int islot = (*val & 15);
printf("DRM = %d (orbit = %d) slot = %d: \n", crateHeader->drmID, crateOrbit->orbitID, islot);
if (islot == 1) {
if (o2::tof::diagnostic::DRM_HEADER_MISSING & *val)
printf("DRM_HEADER_MISSING\n");
if (o2::tof::diagnostic::DRM_TRAILER_MISSING & *val)
printf("DRM_TRAILER_MISSING\n");
if (o2::tof::diagnostic::DRM_FEEID_MISMATCH & *val)
printf("DRM_FEEID_MISMATCH\n");
if (o2::tof::diagnostic::DRM_ORBIT_MISMATCH & *val)
printf("DRM_ORBIT_MISMATCH\n");
if (o2::tof::diagnostic::DRM_CRC_MISMATCH & *val)
printf("DRM_CRC_MISMATCH\n");
if (o2::tof::diagnostic::DRM_ENAPARTMASK_DIFFER & *val)
printf("DRM_ENAPARTMASK_DIFFER\n");
if (o2::tof::diagnostic::DRM_CLOCKSTATUS_WRONG & *val)
printf("DRM_CLOCKSTATUS_WRONG\n");
if (o2::tof::diagnostic::DRM_FAULTSLOTMASK_NOTZERO & *val)
printf("DRM_FAULTSLOTMASK_NOTZERO\n");
if (o2::tof::diagnostic::DRM_READOUTTIMEOUT_NOTZERO & *val)
printf("DRM_READOUTTIMEOUT_NOTZERO\n");
if (o2::tof::diagnostic::DRM_EVENTWORDS_MISMATCH & *val)
printf("DRM_EVENTWORDS_MISMATCH\n");
if (o2::tof::diagnostic::DRM_MAXDIAGNOSTIC_BIT & *val)
printf("DRM_MAXDIAGNOSTIC_BIT\n");
} else if (islot == 2) {
if (o2::tof::diagnostic::LTM_HEADER_MISSING & *val)
printf("LTM_HEADER_MISSING\n");
if (o2::tof::diagnostic::LTM_TRAILER_MISSING & *val)
printf("LTM_TRAILER_MISSING\n");
if (o2::tof::diagnostic::LTM_HEADER_UNEXPECTED & *val)
printf("LTM_HEADER_UNEXPECTED\n");
if (o2::tof::diagnostic::LTM_MAXDIAGNOSTIC_BIT & *val)
printf("LTM_MAXDIAGNOSTIC_BIT\n");
} else if (islot < 13) {
if (o2::tof::diagnostic::TRM_HEADER_MISSING & *val)
printf("TRM_HEADER_MISSING\n");
if (o2::tof::diagnostic::TRM_TRAILER_MISSING & *val)
printf("TRM_TRAILER_MISSING\n");
if (o2::tof::diagnostic::TRM_CRC_MISMATCH & *val)
printf("TRM_CRC_MISMATCH\n");
if (o2::tof::diagnostic::TRM_HEADER_UNEXPECTED & *val)
printf("TRM_HEADER_UNEXPECTED\n");
if (o2::tof::diagnostic::TRM_EVENTCNT_MISMATCH & *val)
printf("TRM_EVENTCNT_MISMATCH\n");
if (o2::tof::diagnostic::TRM_EMPTYBIT_NOTZERO & *val)
printf("TRM_EMPTYBIT_NOTZERO\n");
if (o2::tof::diagnostic::TRM_LBIT_NOTZERO & *val)
printf("TRM_LBIT_NOTZERO\n");
if (o2::tof::diagnostic::TRM_FAULTSLOTBIT_NOTZERO & *val)
printf("TRM_FAULTSLOTBIT_NOTZERO\n");
if (o2::tof::diagnostic::TRM_EVENTWORDS_MISMATCH & *val)
printf("TRM_EVENTWORDS_MISMATCH\n");
if (o2::tof::diagnostic::TRM_DIAGNOSTIC_SPARE1 & *val)
printf("TRM_DIAGNOSTIC_SPARE1\n");
if (o2::tof::diagnostic::TRM_DIAGNOSTIC_SPARE2 & *val)
printf("TRM_DIAGNOSTIC_SPARE2\n");
if (o2::tof::diagnostic::TRM_DIAGNOSTIC_SPARE3 & *val)
printf("TRM_DIAGNOSTIC_SPARE3\n");
if (o2::tof::diagnostic::TRM_MAXDIAGNOSTIC_BIT & *val)
printf("TRM_MAXDIAGNOSTIC_BIT\n");
if (o2::tof::diagnostic::TRMCHAIN_HEADER_MISSING & *val)
printf("TRMCHAIN_HEADER_MISSING\n");
if (o2::tof::diagnostic::TRMCHAIN_TRAILER_MISSING & *val)
printf("TRMCHAIN_TRAILER_MISSING\n");
if (o2::tof::diagnostic::TRMCHAIN_STATUS_NOTZERO & *val)
printf("TRMCHAIN_STATUS_NOTZERO\n");
if (o2::tof::diagnostic::TRMCHAIN_EVENTCNT_MISMATCH & *val)
printf("TRMCHAIN_EVENTCNT_MISMATCH\n");
if (o2::tof::diagnostic::TRMCHAIN_TDCERROR_DETECTED & *val)
printf("TRMCHAIN_TDCERROR_DETECTED\n");
if (o2::tof::diagnostic::TRMCHAIN_BUNCHCNT_MISMATCH & *val)
printf("TRMCHAIN_BUNCHCNT_MISMATCH\n");
if (o2::tof::diagnostic::TRMCHAIN_DIAGNOSTIC_SPARE1 & *val)
printf("TRMCHAIN_DIAGNOSTIC_SPARE1\n");
if (o2::tof::diagnostic::TRMCHAIN_DIAGNOSTIC_SPARE2 & *val)
printf("TRMCHAIN_DIAGNOSTIC_SPARE2\n");
if (o2::tof::diagnostic::TRMCHAIN_MAXDIAGNOSTIC_BIT & *val)
printf("TRMCHAIN_MAXDIAGNOSTIC_BIT\n");
}
printf("------\n");
}
for (int i = 0; i < numberOfErrors; i++) {
const uint32_t* val = reinterpret_cast<const uint32_t*>(&(errors[i]));
mDecoder.addError(*val, crateHeader->drmID);
}
}
void CompressedDecodingTask::rdhHandler(const o2::header::RAWDataHeader* rdh)
{
// rdh close
const auto& rdhr = *rdh;
if (RDHUtils::getStop(rdhr) && RDHUtils::getHeartBeatOrbit(rdhr) == o2::raw::HBFUtils::Instance().getNOrbitsPerTF() - 1 + mInitOrbit) {
mNCrateCloseTF++;
// printf("New TF close RDH %d\n", int(rdh->feeId));
return;
}
// rdh open
if ((RDHUtils::getPageCounter(rdhr) == 0) && (RDHUtils::getTriggerType(rdhr) & o2::trigger::TF)) {
mNCrateOpenTF++;
mInitOrbit = RDHUtils::getHeartBeatOrbit(rdhr); // RSTODO this may be eliminated once the framework will start to propagated the dh.firstTForbit
// printf("New TF open RDH %d\n", int(rdh->feeId));
}
};
void CompressedDecodingTask::frameHandler(const CrateHeader_t* crateHeader, const CrateOrbit_t* crateOrbit,
const FrameHeader_t* frameHeader, const PackedHit_t* packedHits)
{
for (int i = 0; i < frameHeader->numberOfHits; ++i) {
auto packedHit = packedHits + i;
mDecoder.InsertDigit(crateHeader->drmID, frameHeader->trmID, packedHit->tdcID, packedHit->chain, packedHit->channel, crateOrbit->orbitID, crateHeader->bunchID, frameHeader->frameID << 13, packedHit->time, packedHit->tot);
}
};
DataProcessorSpec getCompressedDecodingSpec(const std::string& inputDesc, bool conet)
{
std::vector<OutputSpec> outputs;
outputs.emplace_back(o2::header::gDataOriginTOF, "DIGITS", 0, Lifetime::Timeframe);
outputs.emplace_back(o2::header::gDataOriginTOF, "READOUTWINDOW", 0, Lifetime::Timeframe);
outputs.emplace_back(o2::header::gDataOriginTOF, "PATTERNS", 0, Lifetime::Timeframe);
outputs.emplace_back(o2::header::gDataOriginTOF, "ERRORS", 0, Lifetime::Timeframe);
return DataProcessorSpec{
"tof-compressed-decoder",
select(std::string("x:TOF/" + inputDesc).c_str()),
outputs,
AlgorithmSpec{adaptFromTask<CompressedDecodingTask>(conet)},
Options{
{"row-filter", VariantType::Bool, false, {"Filter empty row"}},
{"mask-noise", VariantType::Bool, false, {"Flag to mask noisy digits"}},
{"noise-counts", VariantType::Int, 1000, {"Counts in a single (TF) payload"}}}};
}
} // namespace tof
} // namespace o2