149 B2WARNING(
"Unpacking SVDShaperDigits to a non-empty pre-existing \n"
150 <<
"StoreArray. This can lead to undesired behaviour. At least\n"
151 <<
"remember to use SVDShaperDigitSorter in your path and \n"
152 <<
"set the silentlyAppend parameter of SVDUnpacker to true.");
162 size_t currentDiagIdx = size_t(-1);
165 B2ERROR(
"Missing valid EventMetaData." << std::endl <<
"No SVDShaperDigit produced for this event!");
169 bool nAPVmatch =
true;
170 bool badMapping =
false;
171 bool badHeader =
false;
172 bool badTrailer =
false;
173 bool missedHeader =
false;
174 bool missedTrailer =
false;
177 bool isSetEventInfo =
false;
180 bool isSetNAPVsamples =
false;
182 unsigned short nAPVheaders = 999;
183 uint64_t seenAPVHeaders = 0;
185 unsigned short nEntries_rawSVD =
m_rawSVD.getEntries();
188 short fadc = 255, apv = 63;
191 int cachedChipID = -1;
195 std::vector<unsigned short> nWords;
196 std::vector<uint32_t*> data32tab;
197 vector<uint32_t> crc16vec;
199 unsigned short cntFADCboards = 0;
200 for (
unsigned int i = 0; i < nEntries_rawSVD; i++) {
204 for (
unsigned int j = 0; j < numEntries_rawSVD; j++) {
208 nWords.resize(maxNumOfCh);
209 data32tab.resize(maxNumOfCh);
210 for (
unsigned int k = 0; k < maxNumOfCh; k++) {
215 unsigned short ftbError = 0;
216 unsigned short trgType = 0;
217 unsigned short trgNumber = 0;
218 unsigned short daqMode = -1;
219 unsigned short daqType = 0;
222 unsigned short apvErrors;
223 unsigned short pipAddr;
224 unsigned short ftbFlags = 0;
225 unsigned short apvErrorsOR = 0;
227 bool is3sampleData =
false;
228 bool is6sampleData =
false;
230 for (
unsigned int buf = 0; buf < maxNumOfCh; buf++) {
232 if (data32tab[buf] ==
nullptr || nWords[buf] == 0) {
233 if (data32tab[buf] !=
nullptr || nWords[buf] != 0) {
234 B2WARNING(
"Invalid combination of buffer pointer and nWords:" <<
235 LogVar(
"COPPER/PCIe40 ID", i) <<
236 LogVar(
"COPPER/PCIe40 Entry", j) <<
237 LogVar(
"COPPER/PCIe40 Channel", buf) <<
238 LogVar(
"data32tab[buf]", data32tab[buf]) <<
239 LogVar(
"nWords[buf]", nWords[buf]));
243 if (
m_printRaw)
printB2Debug(data32tab[buf], data32tab[buf], &data32tab[buf][nWords[buf] - 1], nWords[buf]);
247 missedHeader =
false;
248 missedTrailer =
false;
253 uint32_t* data32_it = data32tab[buf];
254 short strip, sample[6];
260 for (; data32_it != &data32tab[buf][nWords[buf]]; data32_it++) {
265 crc16vec.push_back(htonl(
m_data32));
270 crc16vec.push_back(htonl(*data32_it));
276 if (ftbError != 240) {
280 switch (ftbError - 240) {
282 B2ERROR(
"FADC Event Number is different from (FTB & TTD) Event Numbers");
285 B2ERROR(
"TTD Event Number is different from (FTB & FADC) Event Numbers");
288 B2ERROR(
"FTB Event Number is different from (TTD & FADC) Event Numbers");
291 B2ERROR(
"(FTB, TTD & FADC) Event Numbers are different from each other");
294 B2ERROR(
"Problem with errorsField variable in FTB Header" <<
LogVar(
"abnormal value", ftbError));
300 (eventNo & 0xFFFFFF)) {
304 B2ERROR(
"Event number mismatch detected! The event number given by EventMetaData object is different from the one in the FTB Header."
305 <<
LogVar(
"Expected event number & 0xFFFFFF",
306 (eventNo & 0xFFFFFF)) <<
LogVar(
"Event number in the FTB",
m_FTBHeader.eventNumber));
313 crc16vec.push_back(htonl(
m_data32));
326 if (daqType) daqMode = 3;
334 is3sampleData =
false;
335 is6sampleData =
false;
337 if (daqMode == 0) B2ERROR(
"SVDDataFormatCheck: the event " << eventNo <<
338 " is apparently taken with 1-sample mode, this is not expected.");
339 if (daqMode == 1) is3sampleData =
true;
340 if (daqMode == 2) is6sampleData =
true;
348 B2ERROR(
"Event number mismatch detected! The event number given by EventMetaData object is different from the one in the FADC Header. "
349 <<
LogVar(
"Event number", eventNo) <<
LogVar(
"FADC", fadc) <<
LogVar(
"Trigger number LSByte reported by the FADC",
358 if (!isSetEventInfo) {
370 isSetEventInfo =
true;
381 seenAPVHeaders |= (uint64_t(1) << apv);
388 if (apvErrors != 0) {
395 m_diagnostics.emplace_back(trgNumber, trgType, pipAddr, cmc1, cmc2, apvErrors, ftbError,
true,
397 badHeader, missedHeader, missedTrailer,
401 m_apvsByPipeline.push_back((uint32_t(pipAddr) << 16) | (uint32_t(fadc) << 8) | uint32_t(apv));
404 if (pipAddr == 255) {
407 if (
m_data_A.check == 0) B2ERROR(
"The strip data frame is detected for the special SEU recovery mode. " <<
LogVar(
"pipline address",
408 pipAddr) <<
"This is unexpected!");
432 if (!isSetNAPVsamples) {
434 isSetNAPVsamples =
true;
437 B2ERROR(
"DAQMode value (indicating 3-sample acquisition mode) doesn't correspond to the actual number of samples (6) in the data! The data might be corrupted!");
440 crc16vec.push_back(htonl(
m_data32));
451 if (!isSetNAPVsamples) {
453 isSetNAPVsamples =
true;
456 B2ERROR(
"DAQMode value (indicating 6-sample acquisition mode) doesn't correspond to the actual number of samples (3) in the data! The data might be corrupted!");
462 const int chipID = (int(fadc) << 8) |
int(apv);
463 if (chipID != cachedChipID) {
464 cachedSensorInfo =
m_map->getSensorInfo(fadc, apv);
465 cachedChipID = chipID;
467 if (cachedSensorInfo.m_sensorID) {
468 const short cellID =
m_map->getStripNumber(strip, cachedSensorInfo);
473 | (uint64_t(cachedSensorInfo.m_uSide ? 0 : 1) << 47)
474 | (uint64_t(uint16_t(cellID) ^ 0x8000) << 31)
479 B2FATAL(
"Respective FADC/APV combination not found -->> incorrect payload in the database! ");
492 if (
APVmap->find(fadc) ==
APVmap->end()) badMapping =
true;
495 unsigned short nAPVs =
APVmap->count(fadc);
497 if (nAPVheaders == 0) {
498 m_diagnostics.emplace_back(0, 0, 0, 0, 0, 0, ftbError,
true, nAPVmatch, badHeader, 0, 0, fadc, 0);
502 if (nAPVs != nAPVheaders) {
504 for (
const auto& fadcApv : *
APVmap) {
505 if (fadcApv.first != fadc)
continue;
506 if (!((seenAPVHeaders >> fadcApv.second) & 1)) {
508 auto missingRec =
m_missingAPVs.find(make_pair(fadcApv.first, fadcApv.second));
511 if (missingRec->second.first > eventNo)
512 missingRec->second.first = eventNo;
513 if (missingRec->second.second < eventNo)
514 missingRec->second.second = eventNo;
519 make_pair(fadcApv.first, fadcApv.second),
520 make_pair(eventNo, eventNo)
523 int(fadcApv.second)) <<
LogVar(
"FADC",
524 int(fadcApv.first)));
534 if ((ftbFlags >> 5) != 0) badTrailer =
true;
538 B2ERROR(
" FTB Flags variable has an active error bit(s)" <<
LogVar(
"on FADC number", fadc));
540 if (ftbFlags & 16) B2ERROR(
"----> CRC error has been detected. Data might be corrupted!");
541 if (ftbFlags & 8) B2ERROR(
"----> Bad Event indication has been detected. Data might be corrupted!");
542 if (ftbFlags & 4) B2ERROR(
"----> Double Header has been detected. Data might be corrupted!");
543 if (ftbFlags & 2) B2ERROR(
"----> Time Out has been detected. Data might be corrupted!");
544 if (ftbFlags & 1) B2ERROR(
"----> Event Too Long! Data might be corrupted!");
563 boost::crc_optimal<16, 0x8005, 0xFFFF, 0, false, false> bcrc;
564 bcrc.process_bytes(crc16vec.data(), crc16vec.size() *
sizeof(uint32_t));
565 unsigned int checkCRC = bcrc.checksum();
568 B2WARNING(
"FTB CRC16 checksum DOES NOT MATCH" <<
LogVar(
"for FADC no.", fadc));
578 if (!(
seenHeadersAndTrailers & 1)) {B2ERROR(
"Missing FTB Header is detected. SVD data might be corrupted!" <<
LogVar(
"Event number", eventNo) <<
LogVar(
"FADC", fadc)); missedHeader =
true;}
579 if (!(
seenHeadersAndTrailers & 2)) {B2ERROR(
"Missing FADC Header is detected -> related FADC number couldn't be retrieved. SVD data might be corrupted! " <<
LogVar(
"Event number", eventNo) <<
LogVar(
"previous FADC", fadc)); missedHeader =
true;}
580 if (!(
seenHeadersAndTrailers & 4)) {B2ERROR(
"Missing FADC Trailer is detected. SVD data might be corrupted!" <<
LogVar(
"Event number", eventNo) <<
LogVar(
"FADC", fadc)); missedTrailer =
true;}
581 if (!(
seenHeadersAndTrailers & 8)) {B2ERROR(
"Missing FTB Trailer is detected. SVD data might be corrupted!" <<
LogVar(
"Event number", eventNo) <<
LogVar(
"FADC", fadc)); missedTrailer =
true;}
584 for (
size_t d = bufDiagStart; d <
m_diagnostics.size(); d++) {
587 p.setFTBFlags(ftbFlags);
588 p.setApvErrorOR(apvErrorsOR);
589 p.setAPVMatch(nAPVmatch);
590 p.setBadMapping(badMapping);
591 p.setBadTrailer(badTrailer);
592 p.setMissedHeader(missedHeader);
593 p.setMissedTrailer(missedTrailer);
606 LogVar(
"# of data objects in rawSVD",
611 p.setFADCMatch(
false);
626 const unsigned short fadcNo = (*it >> 8) & 0xff;
627 const unsigned short apvNo = *it & 0xff;
629 auto seuRec =
m_seuRecMap.find(make_pair(fadcNo, apvNo));
631 if (seuRec->second.first > eventNo)
632 seuRec->second.first = eventNo;
633 if (seuRec->second.second < eventNo)
634 seuRec->second.second = eventNo;
638 make_pair(fadcNo, apvNo),
639 make_pair(eventNo, eventNo)
642 B2ERROR(
"Special Recovery Data (Dummy APV Header) found due to the detection of Single Event Upset (SEU)!!!" <<
LogVar(
"APV",
643 int(apvNo)) <<
LogVar(
"FADC",
int(fadcNo)) <<
LogVar(
"Event number", eventNo));
647 if (pp.getFADCNumber() == fadcNo and pp.getAPVNumber() == apvNo)
648 pp.setSEURecoData(
true);
655 unsigned short majorPipeline = 0;
656 size_t majorCount = 0;
657 unsigned short nPipelines = 0;
663 if (e - b > majorCount) { majorCount = e - b; majorPipeline = pip; }
670 p.setEmuPipelineAddress(majorPipeline);
672 unsigned short apvsByPipelineSize = nPipelines;
673 if (majorCount > 0 && majorPipeline == 255) apvsByPipelineSize = 1;
676 if (apvsByPipelineSize > 1)
681 if (pip == majorPipeline or pip == 255) { b = e;
continue; }
682 for (
size_t k = b; k < e; k++) {
686 auto upsetRec =
m_upsetAPVs.find(make_pair(fadcNo, apvNo));
689 if (upsetRec->second.first > eventNo)
690 upsetRec->second.first = eventNo;
691 if (upsetRec->second.second < eventNo)
692 upsetRec->second.second = eventNo;
697 make_pair(fadcNo, apvNo),
698 make_pair(eventNo, eventNo)
702 int(fadcNo)) <<
LogVar(
"Event number", eventNo));
707 if (pp.getFADCNumber() == fadcNo and pp.getAPVNumber() == apvNo)
708 pp.setUpsetAPV(
true);
721 uint64_t lastKeptStrip = ~uint64_t(0);
724 if ((key >> 31) == lastKeptStrip)
continue;
725 lastKeptStrip = key >> 31;
730 if ((
m_killUpsetDigits && d.getPipelineAddress() != d.getEmuPipelineAddress()) || d.getFTBError() != 240
731 || d.getFTBFlags() || d.getAPVError() || !(d.getAPVMatch()) || !(d.getFADCMatch())
733 || d.getBadMapping() || d.getUpsetAPV() || d.getMissedHeader() || d.getMissedTrailer())
continue;