forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRawPixelDecoder.cxx
More file actions
615 lines (581 loc) · 24.2 KB
/
RawPixelDecoder.cxx
File metadata and controls
615 lines (581 loc) · 24.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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
// Copyright 2019-2026 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 RawPixelDecoder.cxx
/// \brief Alpide pixel reader for raw data processing
#include "DetectorsRaw/RDHUtils.h"
#include "ITSMFTReconstruction/RawPixelDecoder.h"
#include "DPLUtils/DPLRawParser.h"
#include "Framework/InputRecordWalker.h"
#include "Framework/TimingInfo.h"
#include "Framework/DataRefUtils.h"
#include "CommonUtils/StringUtils.h"
#include "CommonUtils/VerbosityConfig.h"
#include <filesystem>
#ifdef WITH_OPENMP
#include <omp.h>
#endif
using namespace o2::itsmft;
using namespace o2::framework;
using RDHUtils = o2::raw::RDHUtils;
///______________________________________________________________
/// C-tor
template <class Mapping>
RawPixelDecoder<Mapping>::RawPixelDecoder()
{
mRUEntry.fill(-1); // no known links in the beginning
mTimerTFStart.Stop();
mTimerDecode.Stop();
mTimerFetchData.Stop();
mSelfName = o2::utils::Str::concat_string(Mapping::getName(), "Decoder");
DPLRawParser<>::setCheckIncompleteHBF(false); // Disable incomplete HBF checking, see ErrPacketCounterJump check in GBTLink.cxx
mInputFilter = {InputSpec{"filter", ConcreteDataTypeMatcher{Mapping::getOrigin(), o2::header::gDataDescriptionRawData}}}; // by default take all raw data
}
///______________________________________________________________
///
template <class Mapping>
void RawPixelDecoder<Mapping>::printReport(bool decstat, bool skipNoErr) const
{
double cpu = 0, real = 0;
auto& tmrS = const_cast<TStopwatch&>(mTimerTFStart);
LOGP(info, "{} Timing Start TF: CPU = {:.3e} Real = {:.3e} in {} slots", mSelfName, tmrS.CpuTime(), tmrS.RealTime(), tmrS.Counter() - 1);
cpu += tmrS.CpuTime();
real += tmrS.RealTime();
auto& tmrD = const_cast<TStopwatch&>(mTimerDecode);
LOGP(info, "{} Timing Decode: CPU = {:.3e} Real = {:.3e} in {} slots", mSelfName, tmrD.CpuTime(), tmrD.RealTime(), tmrD.Counter() - 1);
cpu += tmrD.CpuTime();
real += tmrD.RealTime();
auto& tmrF = const_cast<TStopwatch&>(mTimerFetchData);
LOGP(info, "{} Timing FetchData: CPU = {:.3e} Real = {:.3e} in {} slots", mSelfName, tmrF.CpuTime(), tmrF.RealTime(), tmrF.Counter() - 1);
cpu += tmrF.CpuTime();
real += tmrF.RealTime();
LOGP(info, "{} Timing Total: CPU = {:.3e} Real = {:.3e} in {} slots in {} mode", mSelfName, cpu, real, tmrS.Counter() - 1,
mDecodeNextAuto ? "AutoDecode" : "ExternalCall");
LOGP(info, "{} decoded {} hits in {} non-empty chips in {} ROFs with {} threads, {} external triggers", mSelfName, mNPixelsFired, mNChipsFired, mROFCounter, mNThreads, mNExtTriggers);
if (decstat) {
LOG(info) << "GBT Links decoding statistics" << (skipNoErr ? " (only links with errors are reported)" : "");
for (auto& lnk : mGBTLinks) {
lnk.statistics.print(skipNoErr);
lnk.chipStat.print(skipNoErr);
}
}
}
///______________________________________________________________
/// Decode next trigger for all links
template <class Mapping>
int RawPixelDecoder<Mapping>::decodeNextTrigger()
{
mNChipsFiredROF = 0;
mNPixelsFiredROF = 0;
mInteractionRecord.clear();
if (mROFRampUpStage && mSkipRampUpData) {
return -1;
}
int nru = mRUDecodeVec.size();
int prevNTrig = mExtTriggers.size();
do {
#ifdef WITH_OPENMP
#pragma omp parallel for schedule(dynamic) num_threads(mNThreads)
#endif
for (int iru = 0; iru < nru; iru++) {
collectROFCableData(iru);
}
mROFCounter++;
if (!doIRMajorityPoll()) {
continue; // no links with data
}
#ifdef WITH_OPENMP
#pragma omp parallel for schedule(dynamic) num_threads(mNThreads) reduction(+ : mNChipsFiredROF, mNPixelsFiredROF)
#endif
for (int iru = 0; iru < nru; iru++) {
auto& ru = mRUDecodeVec[iru];
if (ru.nNonEmptyLinks) {
ru.ROFRampUpStage = mROFRampUpStage;
mNPixelsFiredROF += ru.decodeROF(mMAP, mInteractionRecord, mVerifyDecoder);
mNChipsFiredROF += ru.nChipsFired;
} else {
ru.clearSeenChipIDs();
}
}
if (mNChipsFiredROF || (mAlloEmptyROFs && mNLinksDone < mNLinksInTF)) { // fill some statistics
mTrigger = mLinkForTriggers ? mLinkForTriggers->trigger : 0;
mNChipsFired += mNChipsFiredROF;
mNPixelsFired += mNPixelsFiredROF;
mCurRUDecodeID = 0; // getNextChipData will start from here
mLastReadChipID = -1;
break;
}
} while (mNLinksDone < mNLinksInTF);
mNExtTriggers += mExtTriggers.size() - prevNTrig;
ensureChipOrdering();
mTimerDecode.Stop();
return (mNLinksDone < mNLinksInTF) ? mNChipsFiredROF : -1;
}
///______________________________________________________________
/// prepare for new TF
template <class Mapping>
void RawPixelDecoder<Mapping>::startNewTF(InputRecord& inputs)
{
mTimerTFStart.Start(false);
for (auto& link : mGBTLinks) {
link.lastRDH = nullptr; // pointers will be invalid
link.clear(false, true); // clear data but not the statistics
}
for (auto& ru : mRUDecodeVec) {
ru.clear();
// ru.chipErrorsTF.clear(); // will be cleared in the collectDecodingErrors
ru.linkHBFToDump.clear();
ru.nLinksDone = 0;
}
setupLinks(inputs);
mNLinksDone = 0;
mExtTriggers.clear();
mTimerTFStart.Stop();
}
///______________________________________________________________
/// Collect cable data for the next ROF for given RU
template <class Mapping>
void RawPixelDecoder<Mapping>::collectROFCableData(int iru)
{
auto& ru = mRUDecodeVec[iru];
ru.clear();
for (int il = 0; il < RUDecodeData::MaxLinksPerRU; il++) {
auto* link = getGBTLink(ru.links[il]);
if (link && link->statusInTF == GBTLink::DataSeen) {
auto res = link->collectROFCableData(mMAP);
if (res == GBTLink::DataSeen || res == GBTLink::CachedDataExist) { // at the moment process only DataSeen
ru.nNonEmptyLinks++;
} else if (res == GBTLink::StoppedOnEndOfData || res == GBTLink::AbortedOnError) { // this link has exhausted its data or it has to be discarded due to the error
ru.nLinksDone++;
}
}
}
}
///______________________________________________________________
// do majority IR poll for synchronization
template <class Mapping>
bool RawPixelDecoder<Mapping>::doIRMajorityPoll()
{
mIRPoll.clear();
mInteractionRecord.clear();
for (auto& link : mGBTLinks) {
if (link.statusInTF == GBTLink::DataSeen) {
if (link.status == GBTLink::DataSeen || link.status == GBTLink::CachedDataExist) {
mIRPoll[link.ir]++;
if (mVerbosity >= GBTLink::Verbosity::VerboseHeaders) {
LOGP(info, "doIRMajorityPoll: {} contributes to poll {}", link.describe(), link.ir.asString());
}
} else if (link.status == GBTLink::StoppedOnEndOfData || link.status == GBTLink::AbortedOnError) {
link.statusInTF = GBTLink::StoppedOnEndOfData;
if (mVerbosity >= GBTLink::Verbosity::VerboseHeaders) {
LOGP(info, "doIRMajorityPoll: {} DONE, status = {}", link.describe(), int(link.status));
}
mNLinksDone++;
}
}
}
if (mNLinksDone == mNLinksInTF) {
if (mVerbosity >= GBTLink::Verbosity::VerboseHeaders) {
LOGP(info, "doIRMajorityPoll: All {} links registered in TF are done", mNLinksInTF);
}
return false;
}
int majIR = -1;
for (const auto& entIR : mIRPoll) {
if (entIR.second > majIR) {
majIR = entIR.second;
mInteractionRecord = entIR.first;
}
}
if (mInteractionRecord.isDummy()) {
if (mVerbosity >= GBTLink::Verbosity::VerboseHeaders) {
LOG(info) << "doIRMajorityPoll: did not find any valid IR";
}
return false;
}
if (mVerbosity >= GBTLink::Verbosity::VerboseHeaders) {
LOG(info) << "doIRMajorityPoll: " << mInteractionRecord.asString() << " majority = " << majIR << " for " << mNLinksInTF << " links seen, LinksDone = " << mNLinksDone;
}
return true;
}
///______________________________________________________________
/// Setup links checking the very RDH of every input
template <class Mapping>
void RawPixelDecoder<Mapping>::setupLinks(InputRecord& inputs)
{
constexpr uint32_t ROF_RAMP_FLAG = 0x1 << 4;
constexpr uint32_t LINK_RECOVERY_FLAG = 0x1 << 5;
mNLinksInTF = 0;
mCurRUDecodeID = NORUDECODED;
auto nLinks = mGBTLinks.size();
auto origin = (mUserDataOrigin == o2::header::gDataOriginInvalid) ? mMAP.getOrigin() : mUserDataOrigin;
auto datadesc = (mUserDataDescription == o2::header::gDataDescriptionInvalid) ? o2::header::gDataDescriptionRawData : mUserDataDescription;
if (mUserDataDescription != o2::header::gDataDescriptionInvalid) { // overwrite data filter descriptions with user
mInputFilter = {InputSpec{"filter", ConcreteDataTypeMatcher{origin, datadesc}}}; // TODO: for now assume all are requested and no explicit filter was set
}
// if we see requested data type input with 0xDEADBEEF subspec and 0 payload this means that the "delayed message"
// mechanism created it in absence of real data from upstream. Processor should send empty output to not block the workflow
{
static size_t contDeadBeef = 0; // number of times 0xDEADBEEF was seen continuously
std::vector<InputSpec> dummy{InputSpec{"dummy", ConcreteDataMatcher{origin, datadesc, 0xDEADBEEF}}};
for (const auto& ref : InputRecordWalker(inputs, dummy)) {
const auto dh = o2::framework::DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
auto payloadSize = o2::framework::DataRefUtils::getPayloadSize(ref);
if (payloadSize == 0) {
auto maxWarn = o2::conf::VerbosityConfig::Instance().maxWarnDeadBeef;
if (++contDeadBeef <= maxWarn) {
LOGP(warn, "Found input [{}/{}/{:#x}] TF#{} 1st_orbit:{} Payload {} : assuming no payload for all links in this TF{}",
dh->dataOrigin.str, dh->dataDescription.str, dh->subSpecification, dh->tfCounter, dh->firstTForbit, payloadSize,
contDeadBeef == maxWarn ? fmt::format(". {} such inputs in row received, stopping reporting", contDeadBeef) : "");
}
return;
}
}
contDeadBeef = 0; // if good data, reset the counter
}
mROFRampUpStage = false;
DPLRawParser parser(inputs, mInputFilter, o2::conf::VerbosityConfig::Instance().rawParserSeverity);
parser.setMaxFailureMessages(o2::conf::VerbosityConfig::Instance().maxWarnRawParser);
static size_t cntParserFailures = 0;
parser.setExtFailureCounter(&cntParserFailures);
uint32_t currSSpec = 0xffffffff; // dummy starting subspec
int linksAdded = 0;
uint16_t lr, dummy; // extraxted info from FEEId
for (auto it = parser.begin(); it != parser.end(); ++it) {
auto const* dh = it.o2DataHeader();
auto& lnkref = mSubsSpec2LinkID[dh->subSpecification];
const auto& rdh = *reinterpret_cast<const header::RDHAny*>(it.raw()); // RSTODO this is a hack in absence of generic header getter
const auto feeID = RDHUtils::getFEEID(rdh);
mMAP.expandFEEId(feeID, lr, dummy, dummy);
if (lnkref.entry == -1) { // new link needs to be added
lnkref.entry = int(mGBTLinks.size());
auto& lnk = mGBTLinks.emplace_back(RDHUtils::getCRUID(rdh), feeID, RDHUtils::getEndPointID(rdh), RDHUtils::getLinkID(rdh), lnkref.entry);
lnk.subSpec = dh->subSpecification;
lnk.wordLength = (lnk.expectPadding = (RDHUtils::getDataFormat(rdh) == 0)) ? o2::itsmft::GBTPaddedWordLength : o2::itsmft::GBTWordLength;
getCreateRUDecode(mMAP.FEEId2RUSW(feeID)); // make sure there is a RU for this link
lnk.verbosity = GBTLink::Verbosity(mVerbosity);
lnk.alwaysParseTrigger = mAlwaysParseTrigger;
if (mVerbosity >= GBTLink::Verbosity::VerboseHeaders) {
LOG(info) << mSelfName << " registered new " << lnk.describe() << " RUSW=" << int(mMAP.FEEId2RUSW(lnk.feeID));
}
linksAdded++;
}
auto& link = mGBTLinks[lnkref.entry];
if (currSSpec != dh->subSpecification) { // this is the 1st part for this link in this TF, next parts must follow contiguously!!!
currSSpec = dh->subSpecification;
if (link.statusInTF != GBTLink::None) {
static bool errorDone = false;
if (!errorDone) {
LOGP(error, "{} was already registered, inform PDP on-call about error!!!", link.describe());
errorDone = true;
}
}
link.statusInTF = GBTLink::DataSeen;
mNLinksInTF++;
}
auto detField = RDHUtils::getDetectorField(&rdh);
if (detField & ROF_RAMP_FLAG) {
mROFRampUpStage = true;
}
if ((detField & LINK_RECOVERY_FLAG) && (link.statusInTF != GBTLink::Recovery)) {
link.statusInTF = GBTLink::Recovery; // data will be discarded
link.rawData.clear();
uint8_t errRes = uint8_t(GBTLink::NoError);
link.accountLinkRecovery(RDHUtils::getHeartBeatIR(rdh));
mNLinksInTF--;
}
if (link.statusInTF != GBTLink::Recovery) {
link.cacheData(it.raw(), RDHUtils::getMemorySize(rdh));
}
}
if (linksAdded) { // new links were added, update link<->RU mapping, usually is done for 1st TF only
if (nLinks) {
if (mVerbosity >= GBTLink::Verbosity::VerboseHeaders) {
LOG(warn) << mSelfName << " New links appeared although the initialization was already done";
}
for (auto& ru : mRUDecodeVec) { // reset RU->link references since they may have been changed
memset(&ru.links[0], -1, RUDecodeData::MaxLinksPerRU * sizeof(int));
memset(&ru.cableLinkPtr[0], 0, RUDecodeData::MaxCablesPerRU * sizeof(GBTLink*));
}
}
// sort RUs in stave increasing order
std::sort(mRUDecodeVec.begin(), mRUDecodeVec.end(), [](const RUDecodeData& ruA, const RUDecodeData& ruB) -> bool { return ruA.ruSWID < ruB.ruSWID; });
for (auto i = 0; i < mRUDecodeVec.size(); i++) {
mRUEntry[mRUDecodeVec[i].ruSWID] = i;
}
nLinks = mGBTLinks.size();
// attach link to corresponding RU: this can be done once all RUs are created, to make sure their pointers don't change
for (int il = 0; il < nLinks; il++) {
auto& link = mGBTLinks[il];
bool newLinkAdded = (link.ruPtr == nullptr);
link.ruPtr = getRUDecode(mMAP.FEEId2RUSW(link.feeID)); // link to RU reference, reattach even it was already set before
uint16_t lr, ruOnLr, linkInRU;
mMAP.expandFEEId(link.feeID, lr, ruOnLr, linkInRU);
if (newLinkAdded) {
if (mVerbosity >= GBTLink::Verbosity::VerboseHeaders) {
LOGP(info, "{} Attaching {} to RU#{:02} (stave {:02} of layer {})", mSelfName, link.describe(), int(mMAP.FEEId2RUSW(link.feeID)), ruOnLr, lr);
}
}
link.idInRU = linkInRU;
link.ruPtr->links[linkInRU] = il; // RU to link reference
link.ruPtr->nLinks++;
}
}
// set the link extracting triggers
for (auto& link : mGBTLinks) {
if (link.statusInTF == GBTLink::DataSeen) { // designate 1st link with valid data to register triggers
link.extTrigVec = &mExtTriggers;
mLinkForTriggers = &link;
break;
}
}
}
///______________________________________________________________
/// get RU decode container for RU with given SW ID, if does not exist, create it
template <class Mapping>
RUDecodeData& RawPixelDecoder<Mapping>::getCreateRUDecode(int ruSW)
{
assert(ruSW < mMAP.getNRUs());
if (mRUEntry[ruSW] < 0) {
mRUEntry[ruSW] = mRUDecodeVec.size();
auto& ru = mRUDecodeVec.emplace_back();
ru.ruSWID = ruSW;
ru.ruInfo = mMAP.getRUInfoSW(ruSW); // info on the stave/RU
ru.chipsData.resize(mMAP.getNChipsOnRUType(ru.ruInfo->ruType));
ru.verbosity = mVerbosity;
if (mVerbosity >= GBTLink::Verbosity::VerboseHeaders) {
LOG(info) << mSelfName << " Defining container for RU " << ruSW << " at slot " << mRUEntry[ruSW];
}
}
return mRUDecodeVec[mRUEntry[ruSW]];
}
///______________________________________________________________________
template <class Mapping>
ChipPixelData* RawPixelDecoder<Mapping>::getNextChipData(std::vector<ChipPixelData>& chipDataVec)
{
// decode new RU if no cached non-empty chips
for (; mCurRUDecodeID < mRUDecodeVec.size(); mCurRUDecodeID++) {
auto& ru = mRUDecodeVec[mCurRUDecodeID];
if (ru.lastChipChecked < ru.nChipsFired) {
auto& chipData = ru.chipsData[ru.lastChipChecked++];
// assert(mLastReadChipID < chipData.getChipID());
if (mLastReadChipID >= chipData.getChipID()) {
if (!mROFRampUpStage) {
const int MaxErrLog = 2;
static int errLocCount = 0;
if (errLocCount < MaxErrLog) {
LOGP(warn, "Wrong order/duplication: encountered chip {} after processing chip {}, skipping.",
chipData.getChipID(), mLastReadChipID, ++errLocCount, MaxErrLog);
}
}
continue;
}
mLastReadChipID = chipData.getChipID();
chipDataVec[mLastReadChipID].swap(chipData);
return &chipDataVec[mLastReadChipID];
}
}
// will need to decode new trigger
if (!mDecodeNextAuto || decodeNextTrigger() < 0) { // no more data to decode
return nullptr;
}
return getNextChipData(chipDataVec);
}
///______________________________________________________________________
template <class Mapping>
bool RawPixelDecoder<Mapping>::getNextChipData(ChipPixelData& chipData)
{
/// read single chip data to the provided container
for (; mCurRUDecodeID < mRUDecodeVec.size(); mCurRUDecodeID++) {
auto& ru = mRUDecodeVec[mCurRUDecodeID];
if (ru.lastChipChecked < ru.nChipsFired) {
auto& ruchip = ru.chipsData[ru.lastChipChecked++];
assert(mLastReadChipID < chipData.getChipID());
mLastReadChipID = chipData.getChipID();
chipData.swap(ruchip);
return true;
}
}
// will need to decode new trigger
if (!mDecodeNextAuto || decodeNextTrigger() < 0) { // no more data to decode
return false;
}
return getNextChipData(chipData); // is it ok to use recursion here?
}
///______________________________________________________________________
template <>
void RawPixelDecoder<ChipMappingMFT>::ensureChipOrdering()
{
mOrderedChipsPtr.clear();
// define looping order, if mCurRUDecodeID < mRUDecodeVec.size(), this means that decodeNextTrigger() was called before
if (mCurRUDecodeID < mRUDecodeVec.size()) { // define sort order
for (; mCurRUDecodeID < mRUDecodeVec.size(); mCurRUDecodeID++) {
auto& ru = mRUDecodeVec[mCurRUDecodeID];
while (ru.lastChipChecked < ru.nChipsFired) {
mOrderedChipsPtr.push_back(&ru.chipsData[ru.lastChipChecked++]);
}
}
// sort in decreasing order
std::sort(mOrderedChipsPtr.begin(), mOrderedChipsPtr.end(), [](const ChipPixelData* a, const ChipPixelData* b) { return a->getChipID() > b->getChipID(); });
}
}
///______________________________________________________________________
template <>
ChipPixelData* RawPixelDecoder<ChipMappingMFT>::getNextChipData(std::vector<ChipPixelData>& chipDataVec)
{
if (!mOrderedChipsPtr.empty()) {
auto chipData = *mOrderedChipsPtr.back();
assert(mLastReadChipID < chipData.getChipID());
mLastReadChipID = chipData.getChipID();
chipDataVec[mLastReadChipID].swap(chipData);
mOrderedChipsPtr.pop_back();
return &chipDataVec[mLastReadChipID];
}
// will need to decode new trigger
if (!mDecodeNextAuto || decodeNextTrigger() < 0) { // no more data to decode
return nullptr;
}
return getNextChipData(chipDataVec);
}
///______________________________________________________________________
template <>
bool RawPixelDecoder<ChipMappingMFT>::getNextChipData(ChipPixelData& chipData)
{
if (!mOrderedChipsPtr.empty()) {
auto ruChip = *mOrderedChipsPtr.back();
assert(mLastReadChipID < ruChip.getChipID());
mLastReadChipID = ruChip.getChipID();
ruChip.swap(chipData);
mOrderedChipsPtr.pop_back();
return true;
}
// will need to decode new trigger
if (!mDecodeNextAuto || decodeNextTrigger() < 0) { // no more data to decode
return false;
}
return getNextChipData(chipData); // is it ok to use recursion here?
}
///______________________________________________________________________
template <class Mapping>
void RawPixelDecoder<Mapping>::setVerbosity(int v)
{
mVerbosity = v;
for (auto& link : mGBTLinks) {
link.verbosity = GBTLink::Verbosity(v);
}
}
///______________________________________________________________________
template <class Mapping>
void RawPixelDecoder<Mapping>::setNThreads(int n)
{
#ifdef WITH_OPENMP
mNThreads = n > 0 ? n : 1;
#else
LOG(warning) << mSelfName << " Multithreading is not supported, imposing single thread";
mNThreads = 1;
#endif
}
///______________________________________________________________________
template <class Mapping>
void RawPixelDecoder<Mapping>::clearStat(bool resetRaw)
{
// clear statistics
for (auto& lnk : mGBTLinks) {
lnk.clear(true, resetRaw);
}
mNChipsFiredROF = mNPixelsFiredROF = 0;
mNChipsFired = mNPixelsFired = mNExtTriggers = 0;
}
///______________________________________________________________________
template <class Mapping>
size_t RawPixelDecoder<Mapping>::produceRawDataDumps(int dump, const o2::framework::TimingInfo& tinfo)
{
size_t outSize = 0;
bool dumpFullTF = false;
for (auto& ru : mRUDecodeVec) {
if (ru.linkHBFToDump.size()) {
if (dump == int(GBTLink::RawDataDumps::DUMP_TF)) {
dumpFullTF = true;
break;
}
for (auto it : ru.linkHBFToDump) {
if (dump == int(GBTLink::RawDataDumps::DUMP_HBF)) {
const auto& lnk = mGBTLinks[mSubsSpec2LinkID[it.first >> 32].entry];
int entry = it.first & 0xffffffff;
bool allHBFs = false;
std::string fnm;
if (entry >= lnk.rawData.getNPieces()) {
allHBFs = true;
entry = 0;
fnm = fmt::format("{}{}rawdump_{}_run{}_tf_orb{}_full_feeID{:#06x}.raw", mRawDumpDirectory, mRawDumpDirectory.empty() ? "" : "/",
Mapping::getName(), tinfo.runNumber, tinfo.firstTForbit, lnk.feeID);
} else {
fnm = fmt::format("{}{}rawdump_{}_run{}_tf_orb{}_hbf_orb{}_feeID{:#06x}.raw", mRawDumpDirectory, mRawDumpDirectory.empty() ? "" : "/",
Mapping::getName(), tinfo.runNumber, tinfo.firstTForbit, it.second, lnk.feeID);
}
std::ofstream ostrm(fnm, std::ios::binary);
if (!ostrm.good()) {
LOG(error) << "failed to open " << fnm;
continue;
}
while (entry < lnk.rawData.getNPieces()) {
const auto* piece = lnk.rawData.getPiece(entry);
if (!allHBFs && RDHUtils::getHeartBeatOrbit(reinterpret_cast<const RDH*>(piece->data)) != it.second) {
break;
}
ostrm.write(reinterpret_cast<const char*>(piece->data), piece->size);
outSize += piece->size;
entry++;
}
LOG(info) << "produced " << std::filesystem::current_path().c_str() << '/' << fnm;
}
}
}
}
while (dumpFullTF) {
std::string fnm = fmt::format("rawdump_{}_run{}_tf_orb{}_full.raw",
Mapping::getName(), tinfo.runNumber, tinfo.firstTForbit);
std::ofstream ostrm(fnm, std::ios::binary);
if (!ostrm.good()) {
LOG(error) << "failed to open " << fnm;
break;
}
for (const auto& lnk : mGBTLinks) {
for (size_t i = 0; i < lnk.rawData.getNPieces(); i++) {
const auto* piece = lnk.rawData.getPiece(i);
ostrm.write(reinterpret_cast<const char*>(piece->data), piece->size);
outSize += piece->size;
}
}
LOG(info) << "produced " << std::filesystem::current_path().c_str() << '/' << fnm;
break;
}
return outSize;
}
///______________________________________________________________________
template <class Mapping>
void RawPixelDecoder<Mapping>::reset()
{
mTimerTFStart.Reset();
mTimerDecode.Reset();
mTimerFetchData.Reset();
for (auto& ru : mRUDecodeVec) {
for (auto& cab : ru.cableData) {
cab.clear();
}
}
for (auto& link : mGBTLinks) {
link.rofJumpWasSeen = false;
link.statusInTF = GBTLink::None;
}
clearStat(true);
}
template class o2::itsmft::RawPixelDecoder<o2::itsmft::ChipMappingITS>;
template class o2::itsmft::RawPixelDecoder<o2::itsmft::ChipMappingMFT>;