forked from AliceO2Group/QualityControl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecodingTask.cxx
More file actions
389 lines (315 loc) · 12.2 KB
/
DecodingTask.cxx
File metadata and controls
389 lines (315 loc) · 12.2 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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// 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 DecodingTask.cxx
/// \author Sebastien Perrin
///
#include "MCH/DecodingTask.h"
#include "MUONCommon/Helpers.h"
#include "DetectorsRaw/RDHUtils.h"
#include "QualityControl/QcInfoLogger.h"
#include "Framework/WorkflowSpec.h"
#include "Framework/DataRefUtils.h"
#include "MCHRawElecMap/Mapper.h"
#include "MCHRawDecoder/PageDecoder.h"
#include "MCHRawDecoder/ErrorCodes.h"
#include "MCHBase/DecoderError.h"
#include "MCHBase/HeartBeatPacket.h"
#include <TH1I.h>
using namespace o2;
using namespace o2::framework;
using namespace o2::mch;
using namespace o2::mch::raw;
using RDH = o2::header::RDHAny;
using namespace o2::quality_control_modules::muon;
namespace o2::quality_control_modules::muonchambers
{
template <typename T>
void DecodingTask::publishObject(T* histo, std::string drawOption, std::string displayHints, bool statBox, bool isExpert)
{
histo->SetOption(drawOption.c_str());
if (!statBox) {
histo->SetStats(0);
}
mAllHistograms.push_back(histo);
getObjectsManager()->startPublishing(histo);
getObjectsManager()->setDefaultDrawOptions(histo, drawOption);
getObjectsManager()->setDisplayHint(histo, displayHints);
}
//_____________________________________________________________________________
void DecodingTask::createErrorHistos()
{
const uint32_t nElecXbins = NumberOfDualSampas;
// Number of decoding errors, grouped by chamber ID and normalized to the number of processed TF
mHistogramErrorsFEC = std::make_unique<TH2FRatio>("DecodingErrors_Elec", "Error Code vs. FEC ID", nElecXbins, 0, nElecXbins, getErrorCodesSize(), 0, getErrorCodesSize(), true);
{
TAxis* ax = mHistogramErrorsFEC->GetYaxis();
for (int i = 0; i < getErrorCodesSize(); i++) {
ax->SetBinLabel(i + 1, errorCodeAsString(1 << i).c_str());
ax->ChangeLabel(i + 1, 45);
}
}
publishObject(mHistogramErrorsFEC.get(), "colz", "gridy logz", false, false);
}
//_____________________________________________________________________________
void DecodingTask::createHeartBeatHistos()
{
const uint32_t nElecXbins = NumberOfDualSampas;
// Heart-beat packets time distribution and synchronization errors
mHistogramHBTimeFEC = std::make_unique<TH2FRatio>("HBTime_Elec", "HB time vs. FEC ID", nElecXbins, 0, nElecXbins, 40, mHBExpectedBc - 20, mHBExpectedBc + 20, true);
mHistogramHBTimeFEC->Sumw2(kFALSE);
publishObject(mHistogramHBTimeFEC.get(), "colz", "logz", false, false);
uint64_t max = ((static_cast<uint64_t>(0x100000) / 100) + 1) * 100;
mHistogramHBCoarseTimeFEC = std::make_unique<TH2FRatio>("HBCoarseTime_Elec", "HB time vs. FEC ID (coarse)", nElecXbins, 0, nElecXbins, 100, 0, max, true);
mHistogramHBCoarseTimeFEC->Sumw2(kFALSE);
publishObject(mHistogramHBCoarseTimeFEC.get(), "colz", "", false, false);
mSyncStatusFEC = std::make_unique<TH2FRatio>("SyncStatus_Elec", "Heart-beat status vs. FEC ID", nElecXbins, 0, nElecXbins, 3, 0, 3, true);
mSyncStatusFEC->Sumw2(kFALSE);
mSyncStatusFEC->GetYaxis()->SetBinLabel(1, "OK");
mSyncStatusFEC->GetYaxis()->SetBinLabel(2, "Out-of-sync");
mSyncStatusFEC->GetYaxis()->SetBinLabel(3, "Missing");
publishObject(mSyncStatusFEC.get(), "colz", "gridy", false, false);
}
//_____________________________________________________________________________
void DecodingTask::initialize(o2::framework::InitContext& /*ic*/)
{
ILOG(Debug, Devel) << "initialize DecodingErrorsTask" << ENDM;
// expected bunch-crossing value in heart-beat packets
mHBExpectedBc = getConfigurationParameter<int>(mCustomParameters, "HBExpectedBc", mHBExpectedBc);
mElec2DetMapper = createElec2DetMapper<ElectronicMapperGenerated>();
mHistogramTimeFramesCount = std::make_unique<TH1I>("TimeFramesCount", "Number of Time Frames", 1, 0, 1);
publishObject(mHistogramTimeFramesCount.get(), "hist", "", true, false);
createErrorHistos();
createHeartBeatHistos();
}
//_____________________________________________________________________________
void DecodingTask::startOfActivity(const Activity& activity)
{
ILOG(Debug, Devel) << "startOfActivity : " << activity.mId << ENDM;
}
//_____________________________________________________________________________
void DecodingTask::startOfCycle()
{
ILOG(Debug, Devel) << "startOfCycle" << ENDM;
}
//_____________________________________________________________________________
void DecodingTask::decodeTF(framework::ProcessingContext& pc)
{
// get the input buffer
auto& inputs = pc.inputs();
DPLRawParser parser(inputs, o2::framework::select(""));
for (auto it = parser.begin(), end = parser.end(); it != end; ++it) {
auto const* raw = it.raw();
if (!raw) {
continue;
}
size_t payloadSize = it.size();
gsl::span<const std::byte> buffer(reinterpret_cast<const std::byte*>(raw), sizeof(RDH) + payloadSize);
decodeBuffer(buffer);
}
}
//_____________________________________________________________________________
void DecodingTask::decodeReadout(const o2::framework::DataRef& input)
{
// get the input buffer
if (input.spec->binding != "readout") {
return;
}
const auto* header = o2::framework::DataRefUtils::getHeader<header::DataHeader*>(input);
if (!header) {
return;
}
size_t payloadSize = o2::framework::DataRefUtils::getPayloadSize(input);
if (payloadSize == 0) {
return;
}
auto const* raw = input.payload;
gsl::span<const std::byte> buffer(reinterpret_cast<const std::byte*>(raw), payloadSize);
decodeBuffer(buffer);
}
//_____________________________________________________________________________
void DecodingTask::decodeBuffer(gsl::span<const std::byte> buf)
{
// RDH source ID for the MCH system
static constexpr int sMCHSourceId = 10;
size_t bufSize = buf.size();
size_t pageStart = 0;
while (bufSize > pageStart) {
const RDH* rdh = reinterpret_cast<const RDH*>(&(buf[pageStart]));
auto rdhHeaderSize = o2::raw::RDHUtils::getHeaderSize(rdh);
if (rdhHeaderSize != 64) {
break;
}
auto pageSize = o2::raw::RDHUtils::getOffsetToNext(rdh);
// skip all buffers that do not belong to MCH
auto sourceId = o2::raw::RDHUtils::getSourceID(rdh);
if (sourceId != sMCHSourceId) {
continue;
}
gsl::span<const std::byte> page(reinterpret_cast<const std::byte*>(rdh), pageSize);
decodePage(page);
pageStart += pageSize;
}
}
//_____________________________________________________________________________
void DecodingTask::decodePage(gsl::span<const std::byte> page)
{
auto errorHandler = [&](DsElecId dsElecId, int8_t chip, uint32_t error) {
int feeId{ -1 };
uint32_t solarId = dsElecId.solarId();
uint32_t dsAddr = dsElecId.elinkId();
plotError(solarId, dsAddr, chip, error);
};
if (!mDecoder) {
o2::mch::raw::DecodedDataHandlers handlers;
handlers.sampaErrorHandler = errorHandler;
mDecoder = o2::mch::raw::createPageDecoder(page, handlers);
}
mDecoder(page);
}
//_____________________________________________________________________________
void DecodingTask::processErrors(framework::ProcessingContext& pc)
{
auto rawerrors = pc.inputs().get<gsl::span<o2::mch::DecoderError>>("rawerrors");
for (auto& error : rawerrors) {
plotError(error.getSolarID(), error.getDsID(), error.getChip(), error.getError());
}
}
//_____________________________________________________________________________
void DecodingTask::plotError(uint16_t solarId, int dsAddr, int chip, uint32_t error)
{
int fecId = -1;
o2::mch::raw::DsElecId dsElecId{ solarId, static_cast<uint8_t>(dsAddr / 5), static_cast<uint8_t>(dsAddr % 5) };
if (auto opt = mElec2DetMapper(dsElecId); opt.has_value()) {
o2::mch::raw::DsDetId dsDetId = opt.value();
fecId = getDsIndex(dsDetId);
}
if (fecId < 0) {
return;
}
uint32_t errMask = 1;
for (int i = 0; i < getErrorCodesSize(); i++) {
// Fill the error histogram if the i-th bin is set in the error word
if ((error & errMask) != 0) {
mHistogramErrorsFEC->getNum()->Fill(fecId, 0.5 + i);
}
errMask <<= 1;
}
}
//_____________________________________________________________________________
void DecodingTask::processHBPackets(framework::ProcessingContext& pc)
{
std::fill(mHBcount.begin(), mHBcount.end(), HBCount());
auto hbpackets = pc.inputs().get<gsl::span<o2::mch::HeartBeatPacket>>("hbpackets");
for (auto& hbp : hbpackets) {
plotHBPacket(hbp.getSolarID(), hbp.getDsID(), hbp.getChip(), hbp.getBunchCrossing());
}
updateSyncErrors();
}
//_____________________________________________________________________________
void DecodingTask::plotHBPacket(uint16_t solarId, int dsAddr, int chip, uint32_t bc)
{
int mBcMin{ mHBExpectedBc - 2 };
int mBcMax{ mHBExpectedBc + 2 };
int fecId = -1;
o2::mch::raw::DsElecId dsElecId{ solarId, static_cast<uint8_t>(dsAddr / 5), static_cast<uint8_t>(dsAddr % 5) };
if (auto opt = mElec2DetMapper(dsElecId); opt.has_value()) {
o2::mch::raw::DsDetId dsDetId = opt.value();
fecId = getDsIndex(dsDetId);
}
if (fecId < 0) {
return;
}
mHistogramHBCoarseTimeFEC->getNum()->Fill(fecId, bc);
if (bc < mHistogramHBTimeFEC->getNum()->GetYaxis()->GetXmin()) {
bc = mHistogramHBTimeFEC->getNum()->GetYaxis()->GetXmin();
}
if (bc > mHistogramHBTimeFEC->getNum()->GetYaxis()->GetXmax()) {
bc = mHistogramHBTimeFEC->getNum()->GetYaxis()->GetXmax();
}
mHistogramHBTimeFEC->getNum()->Fill(fecId, bc);
if (bc >= mBcMin && bc <= mBcMax) {
mHBcount[fecId].nSync += 1;
} else {
mHBcount[fecId].nOutOfSync += 1;
}
}
//_____________________________________________________________________________
void DecodingTask::updateSyncErrors()
{
for (size_t fecId = 0; fecId < mHBcount.size(); fecId++) {
bool isOutOfSync = false;
if (mHBcount[fecId].nOutOfSync > 0) {
isOutOfSync = true;
}
bool isMissing = false;
if (mHBcount[fecId].nSync < 1.5) {
isMissing = true;
}
if (!isOutOfSync && !isMissing) {
mSyncStatusFEC->getNum()->Fill(0.5 + fecId, 0);
}
if (isOutOfSync) {
mSyncStatusFEC->getNum()->Fill(0.5 + fecId, 1);
}
if (isMissing) {
mSyncStatusFEC->getNum()->Fill(0.5 + fecId, 2);
}
}
}
//_____________________________________________________________________________
void DecodingTask::monitorData(o2::framework::ProcessingContext& ctx)
{
for (auto&& input : ctx.inputs()) {
if (input.spec->binding == "readout") {
decodeReadout(input);
}
if (input.spec->binding == "TF") {
decodeTF(ctx);
}
if (input.spec->binding == "rawerrors") {
processErrors(ctx);
}
if (input.spec->binding == "hbpackets") {
processHBPackets(ctx);
}
}
mHistogramTimeFramesCount->Fill(0.5);
}
//_____________________________________________________________________________
void DecodingTask::endOfCycle()
{
ILOG(Debug, Devel) << "endOfCycle" << ENDM;
int nTF = static_cast<int>(mHistogramTimeFramesCount->GetBinContent(1));
mHistogramErrorsFEC->getDen()->SetBinContent(1, 1, nTF);
mHistogramHBTimeFEC->getDen()->SetBinContent(1, 1, nTF);
mHistogramHBCoarseTimeFEC->getDen()->SetBinContent(1, 1, nTF);
mSyncStatusFEC->getDen()->SetBinContent(1, 1, nTF);
mHistogramErrorsFEC->update();
mHistogramHBCoarseTimeFEC->update();
mHistogramHBTimeFEC->update();
mSyncStatusFEC->update();
}
//_____________________________________________________________________________
void DecodingTask::endOfActivity(const Activity& /*activity*/)
{
ILOG(Debug, Devel) << "endOfActivity" << ENDM;
}
//_____________________________________________________________________________
void DecodingTask::reset()
{
// clean all the monitor objects here
ILOG(Info, Devel) << "Resetting the histograms" << ENDM;
for (auto h : mAllHistograms) {
h->Reset("ICES");
}
}
} // namespace o2::quality_control_modules::muonchambers