151 B2WARNING(
"Unpacking SVDShaperDigits to a non-empty pre-existing \n"
152 <<
"StoreArray. This can lead to undesired behaviour. At least\n"
153 <<
"remember to use SVDShaperDigitSorter in your path and \n"
154 <<
"set the silentlyAppend parameter of SVDUnpacker to true.");
164 size_t currentDiagIdx = size_t(-1);
167 B2ERROR(
"Missing valid EventMetaData." << std::endl <<
"No SVDShaperDigit produced for this event!");
171 bool nAPVmatch =
true;
172 bool badMapping =
false;
173 bool badHeader =
false;
174 bool badTrailer =
false;
175 bool missedHeader =
false;
176 bool missedTrailer =
false;
179 bool isSetEventInfo =
false;
182 bool isSetNAPVsamples =
false;
184 unsigned short nAPVheaders = 999;
185 uint64_t seenAPVHeaders = 0;
187 unsigned short nEntries_rawSVD =
m_rawSVD.getEntries();
190 short fadc = 255, apv = 63;
193 int cachedChipID = -1;
197 std::vector<unsigned short> nWords;
198 std::vector<uint32_t*> data32tab;
199 vector<uint32_t> crc16vec;
201 unsigned short cntFADCboards = 0;
202 for (
unsigned int i = 0; i < nEntries_rawSVD; i++) {
206 for (
unsigned int j = 0; j < numEntries_rawSVD; j++) {
210 nWords.resize(maxNumOfCh);
211 data32tab.resize(maxNumOfCh);
212 for (
unsigned int k = 0; k < maxNumOfCh; k++) {
217 unsigned short ftbError = 0;
218 unsigned short trgType = 0;
219 unsigned short trgNumber = 0;
220 unsigned short daqMode = -1;
221 unsigned short daqType = 0;
224 unsigned short apvErrors;
225 unsigned short pipAddr;
226 unsigned short ftbFlags = 0;
227 unsigned short apvErrorsOR = 0;
229 bool is3sampleData =
false;
230 bool is6sampleData =
false;
232 for (
unsigned int buf = 0; buf < maxNumOfCh; buf++) {
234 if (data32tab[buf] ==
nullptr || nWords[buf] == 0) {
235 if (data32tab[buf] !=
nullptr || nWords[buf] != 0) {
236 B2WARNING(
"Invalid combination of buffer pointer and nWords:" <<
237 LogVar(
"COPPER/PCIe40 ID", i) <<
238 LogVar(
"COPPER/PCIe40 Entry", j) <<
239 LogVar(
"COPPER/PCIe40 Channel", buf) <<
240 LogVar(
"data32tab[buf]", data32tab[buf]) <<
241 LogVar(
"nWords[buf]", nWords[buf]));
245 if (
m_printRaw)
printB2Debug(data32tab[buf], data32tab[buf], &data32tab[buf][nWords[buf] - 1], nWords[buf]);
249 missedHeader =
false;
250 missedTrailer =
false;
255 uint32_t* data32_it = data32tab[buf];
256 short strip, sample[6];
262 for (; data32_it != &data32tab[buf][nWords[buf]]; data32_it++) {
267 crc16vec.push_back(htonl(
m_data32));
272 crc16vec.push_back(htonl(*data32_it));
278 if (ftbError != 240) {
282 switch (ftbError - 240) {
284 B2ERROR(
"FADC Event Number is different from (FTB & TTD) Event Numbers");
287 B2ERROR(
"TTD Event Number is different from (FTB & FADC) Event Numbers");
290 B2ERROR(
"FTB Event Number is different from (TTD & FADC) Event Numbers");
293 B2ERROR(
"(FTB, TTD & FADC) Event Numbers are different from each other");
296 B2ERROR(
"Problem with errorsField variable in FTB Header" <<
LogVar(
"abnormal value", ftbError));
302 (eventNo & 0xFFFFFF)) {
306 B2ERROR(
"Event number mismatch detected! The event number given by EventMetaData object is different from the one in the FTB Header."
307 <<
LogVar(
"Expected event number & 0xFFFFFF",
308 (eventNo & 0xFFFFFF)) <<
LogVar(
"Event number in the FTB",
m_FTBHeader.eventNumber));
315 crc16vec.push_back(htonl(
m_data32));
328 if (daqType) daqMode = 3;
336 is3sampleData =
false;
337 is6sampleData =
false;
339 if (daqMode == 0) B2ERROR(
"SVDDataFormatCheck: the event " << eventNo <<
340 " is apparently taken with 1-sample mode, this is not expected.");
341 if (daqMode == 1) is3sampleData =
true;
342 if (daqMode == 2) is6sampleData =
true;
350 B2ERROR(
"Event number mismatch detected! The event number given by EventMetaData object is different from the one in the FADC Header. "
351 <<
LogVar(
"Event number", eventNo) <<
LogVar(
"FADC", fadc) <<
LogVar(
"Trigger number LSByte reported by the FADC",
360 if (!isSetEventInfo) {
372 isSetEventInfo =
true;
383 seenAPVHeaders |= (uint64_t(1) << apv);
390 if (apvErrors != 0) {
397 m_diagnostics.emplace_back(trgNumber, trgType, pipAddr, cmc1, cmc2, apvErrors, ftbError,
true,
399 badHeader, missedHeader, missedTrailer,
403 m_apvsByPipeline.push_back((uint32_t(pipAddr) << 16) | (uint32_t(fadc) << 8) | uint32_t(apv));
406 if (pipAddr == 255) {
409 if (
m_data_A.check == 0) B2ERROR(
"The strip data frame is detected for the special SEU recovery mode. " <<
LogVar(
"pipline address",
410 pipAddr) <<
"This is unexpected!");
434 if (!isSetNAPVsamples) {
436 isSetNAPVsamples =
true;
439 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!");
442 crc16vec.push_back(htonl(
m_data32));
453 if (!isSetNAPVsamples) {
455 isSetNAPVsamples =
true;
458 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!");
464 const int chipID = (int(fadc) << 8) |
int(apv);
465 if (chipID != cachedChipID) {
466 cachedSensorInfo =
m_map->getSensorInfo(fadc, apv);
467 cachedChipID = chipID;
469 if (cachedSensorInfo.m_sensorID) {
470 const short cellID =
m_map->getStripNumber(strip, cachedSensorInfo);
475 | (uint64_t(cachedSensorInfo.m_uSide ? 0 : 1) << 47)
476 | (uint64_t(uint16_t(cellID) ^ 0x8000) << 31)
481 B2FATAL(
"Respective FADC/APV combination not found -->> incorrect payload in the database! ");
494 if (
APVmap->find(fadc) ==
APVmap->end()) badMapping =
true;
497 unsigned short nAPVs =
APVmap->count(fadc);
499 if (nAPVheaders == 0) {
500 m_diagnostics.emplace_back(0, 0, 0, 0, 0, 0, ftbError,
true, nAPVmatch, badHeader, 0, 0, fadc, 0);
504 if (nAPVs != nAPVheaders) {
506 for (
const auto& fadcApv : *
APVmap) {
507 if (fadcApv.first != fadc)
continue;
508 if (!((seenAPVHeaders >> fadcApv.second) & 1)) {
510 auto missingRec =
m_missingAPVs.find(make_pair(fadcApv.first, fadcApv.second));
513 if (missingRec->second.first > eventNo)
514 missingRec->second.first = eventNo;
515 if (missingRec->second.second < eventNo)
516 missingRec->second.second = eventNo;
521 make_pair(fadcApv.first, fadcApv.second),
522 make_pair(eventNo, eventNo)
525 int(fadcApv.second)) <<
LogVar(
"FADC",
526 int(fadcApv.first)));
536 if ((ftbFlags >> 5) != 0) badTrailer =
true;
540 B2ERROR(
" FTB Flags variable has an active error bit(s)" <<
LogVar(
"on FADC number", fadc));
542 if (ftbFlags & 16) B2ERROR(
"----> CRC error has been detected. Data might be corrupted!");
543 if (ftbFlags & 8) B2ERROR(
"----> Bad Event indication has been detected. Data might be corrupted!");
544 if (ftbFlags & 4) B2ERROR(
"----> Double Header has been detected. Data might be corrupted!");
545 if (ftbFlags & 2) B2ERROR(
"----> Time Out has been detected. Data might be corrupted!");
546 if (ftbFlags & 1) B2ERROR(
"----> Event Too Long! Data might be corrupted!");
565 boost::crc_optimal<16, 0x8005, 0xFFFF, 0, false, false> bcrc;
566 bcrc.process_bytes(crc16vec.data(), crc16vec.size() *
sizeof(uint32_t));
567 unsigned int checkCRC = bcrc.checksum();
570 B2WARNING(
"FTB CRC16 checksum DOES NOT MATCH" <<
LogVar(
"for FADC no.", fadc));
580 if (!(
seenHeadersAndTrailers & 1)) {B2ERROR(
"Missing FTB Header is detected. SVD data might be corrupted!" <<
LogVar(
"Event number", eventNo) <<
LogVar(
"FADC", fadc)); missedHeader =
true;}
581 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;}
582 if (!(
seenHeadersAndTrailers & 4)) {B2ERROR(
"Missing FADC Trailer is detected. SVD data might be corrupted!" <<
LogVar(
"Event number", eventNo) <<
LogVar(
"FADC", fadc)); missedTrailer =
true;}
583 if (!(
seenHeadersAndTrailers & 8)) {B2ERROR(
"Missing FTB Trailer is detected. SVD data might be corrupted!" <<
LogVar(
"Event number", eventNo) <<
LogVar(
"FADC", fadc)); missedTrailer =
true;}
586 for (
size_t d = bufDiagStart; d <
m_diagnostics.size(); d++) {
589 p.setFTBFlags(ftbFlags);
590 p.setApvErrorOR(apvErrorsOR);
591 p.setAPVMatch(nAPVmatch);
592 p.setBadMapping(badMapping);
593 p.setBadTrailer(badTrailer);
594 p.setMissedHeader(missedHeader);
595 p.setMissedTrailer(missedTrailer);
608 LogVar(
"# of data objects in rawSVD",
613 p.setFADCMatch(
false);
628 const unsigned short fadcNo = (*it >> 8) & 0xff;
629 const unsigned short apvNo = *it & 0xff;
631 auto seuRec =
m_seuRecMap.find(make_pair(fadcNo, apvNo));
633 if (seuRec->second.first > eventNo)
634 seuRec->second.first = eventNo;
635 if (seuRec->second.second < eventNo)
636 seuRec->second.second = eventNo;
640 make_pair(fadcNo, apvNo),
641 make_pair(eventNo, eventNo)
644 B2ERROR(
"Special Recovery Data (Dummy APV Header) found due to the detection of Single Event Upset (SEU)!!!" <<
LogVar(
"APV",
645 int(apvNo)) <<
LogVar(
"FADC",
int(fadcNo)) <<
LogVar(
"Event number", eventNo));
649 if (pp.getFADCNumber() == fadcNo and pp.getAPVNumber() == apvNo)
650 pp.setSEURecoData(
true);
657 unsigned short majorPipeline = 0;
658 size_t majorCount = 0;
659 unsigned short nPipelines = 0;
665 if (e - b > majorCount) { majorCount = e - b; majorPipeline = pip; }
672 p.setEmuPipelineAddress(majorPipeline);
674 unsigned short apvsByPipelineSize = nPipelines;
675 if (majorCount > 0 && majorPipeline == 255) apvsByPipelineSize = 1;
678 if (apvsByPipelineSize > 1)
683 if (pip == majorPipeline or pip == 255) { b = e;
continue; }
684 for (
size_t k = b; k < e; k++) {
688 auto upsetRec =
m_upsetAPVs.find(make_pair(fadcNo, apvNo));
691 if (upsetRec->second.first > eventNo)
692 upsetRec->second.first = eventNo;
693 if (upsetRec->second.second < eventNo)
694 upsetRec->second.second = eventNo;
699 make_pair(fadcNo, apvNo),
700 make_pair(eventNo, eventNo)
704 int(fadcNo)) <<
LogVar(
"Event number", eventNo));
709 if (pp.getFADCNumber() == fadcNo and pp.getAPVNumber() == apvNo)
710 pp.setUpsetAPV(
true);
723 uint64_t lastKeptStrip = ~uint64_t(0);
726 if ((key >> 31) == lastKeptStrip)
continue;
727 lastKeptStrip = key >> 31;
732 if ((
m_killUpsetDigits && d.getPipelineAddress() != d.getEmuPipelineAddress()) || d.getFTBError() != 240
733 || d.getFTBFlags() || d.getAPVError() || !(d.getAPVMatch()) || !(d.getFADCMatch())
735 || d.getBadMapping() || d.getUpsetAPV() || d.getMissedHeader() || d.getMissedTrailer())
continue;