49 if (pld.count() == 0) {
55 uint16_t bcid = (diglet & bcidmask).to_ulong();
56 LOG(
debug) << bcid <<
" pld:" << pld;
58 if (linkCRU == o2::ctp::GBTLinkIDIntRec) {
62 if ((
ir.
orbit <= mTFOrbit) && ((int32_t)
ir.
bc < BCShiftCorrectionInps)) {
67 ir -= BCShiftCorrectionInps;
73 LOG(
debug) << bcid <<
" inputs case 0 bcid orbit " <<
orbit <<
" pld:" << pld;
75 if (
digits[
ir].CTPInputMask.count() == 0) {
77 LOG(
debug) << bcid <<
" inputs bcid case 1 orbit " <<
orbit <<
" pld:" << pld;
79 if (mErrorIR < mErrorMax) {
80 LOG(error) <<
"Two CTP IRs with the same timestamp:" <<
ir.
bc <<
" " <<
ir.
orbit <<
" pld:" << pld <<
" dig:" <<
digits[
ir];
87 LOG(error) <<
"Two digits with the same timestamp:" <<
ir.
bc <<
" " <<
ir.
orbit;
90 }
else if (linkCRU == o2::ctp::GBTLinkIDClassRec) {
105 LOG(
debug) << bcid <<
" class bcid case 0 orbit " <<
orbit <<
" pld:" << pld;
107 if (
digits[
ir].CTPClassMask.count() == 0) {
109 LOG(
debug) << bcid <<
" class bcid case 1 orbit " <<
orbit <<
" pld:" << pld;
111 if (mErrorTCR < mErrorMax) {
112 LOG(error) <<
"Two CTP Class masks for same timestamp";
119 LOG(error) <<
"Two digits with the same timestamp:" <<
ir.
bc <<
" " <<
ir.
orbit;
123 LOG(error) <<
"Unxpected CTP CRU link:" << linkCRU;
134 static int nwrites = 0;
135 uint64_t countsMBT = 0;
136 uint64_t countsMBV = 0;
137 std::map<o2::InteractionRecord, CTPDigit> digitsMap;
143 uint32_t payloadCTP = 0;
145 uint32_t size_gbt = 0;
148 for (
auto it = parser.
begin(); it != parser.
end(); ++it) {
152 mPadding = (o2::raw::RDHUtils::getDataFormat(rdh) == 0);
153 }
catch (std::exception& e) {
154 LOG(error) <<
"Failed to extract RDH, abandoning TF sending dummy output, exception was: " << e.what();
159 uint32_t stopBit = o2::raw::RDHUtils::getStop(rdh);
160 uint32_t packetCounter = o2::raw::RDHUtils::getPageCounter(rdh);
162 uint32_t rdhOrbit = o2::raw::RDHUtils::getHeartBeatOrbit(rdh);
163 uint32_t triggerType = o2::raw::RDHUtils::getTriggerType(rdh);
165 bool tf = (triggerType & TF_TRIGGERTYPE_MASK) && (packetCounter == 0);
166 bool hb = (triggerType & HB_TRIGGERTYPE_MASK) && (packetCounter == 0);
170 mTFOrbits.push_back(mTFOrbit);
172 static bool prt =
true;
174 LOG(info) <<
"RDH version:" <<
version <<
" Padding:" << mPadding;
177 auto feeID = o2::raw::RDHUtils::getFEEID(rdh);
178 auto linkCRU = (feeID & 0xf00) >> 8;
180 if (linkCRU == o2::ctp::GBTLinkIDIntRec) {
181 payloadCTP = o2::ctp::NIntRecPayload;
182 }
else if (linkCRU == o2::ctp::GBTLinkIDClassRec) {
183 payloadCTP = o2::ctp::NClassPayload;
188 LOG(error) <<
"Unxpected CTP CRU link:" << linkCRU;
190 LOG(
debug) <<
"RDH FEEid: " << feeID <<
" CTP CRU link:" << linkCRU <<
" Orbit:" << rdhOrbit <<
" triggerType:" << triggerType;
193 for (uint32_t
i = 0;
i < payloadCTP;
i++) {
199 if ((mDoLumi && payloadCTP == o2::ctp::NIntRecPayload) && !
tf) {
200 lumiPointsHBF1.emplace_back(
LumiInfo{rdhOrbit, 0, 0, countsMBT, countsMBV});
212 gsl::span<const uint8_t> payload(it.data(), it.size());
217 std::vector<gbtword80_t> gbtwords80;
229 gbtword80_t bcmask = std::bitset<80>(
"111111111111");
230 for (
auto payloadWord : payload) {
231 int wc = wordCount % wordSize;
233 if ((wc == 0) && (wordCount != 0)) {
234 if (gbtWord80.count() != 80) {
235 gbtwords80.push_back(gbtWord80);
240 for (
int i = 0;
i < 8;
i++) {
241 gbtWord80[wc * 8 +
i] = bool(
int(payloadWord) & (1 <<
i));
246 if ((gbtWord80.count() != 80) && (gbtWord80.count() > 0)) {
247 gbtwords80.push_back(gbtWord80);
250 for (
auto word : gbtwords80) {
251 std::vector<gbtword80_t> diglets;
254 for (
auto diglet : diglets) {
255 if (mDoLumi && payloadCTP == o2::ctp::NIntRecPayload) {
257 if (pld.count() != 0) {
260 pld = (diglet >> 12) & mVBAMask;
261 if (pld.count() != 0) {
268 LOG(
debug) <<
"diglet:" << diglet <<
" " << (diglet & bcmask).to_ullong();
269 ret =
addCTPDigit(linkCRU, rdhOrbit, diglet, pldmask, digitsMap);
272 if ((remnant.count() > 0) && stopBit) {
273 if (mDoLumi && payloadCTP == o2::ctp::NIntRecPayload) {
275 if (pld.count() != 0) {
278 pld = (remnant >> 12) & mVBAMask;
279 if (pld.count() != 0) {
286 ret =
addCTPDigit(linkCRU, rdhOrbit, remnant, pldmask, digitsMap);
287 LOG(
debug) <<
"diglet:" << remnant <<
" " << (remnant & bcmask).to_ullong();
292 lumiPointsHBF1.emplace_back(
LumiInfo{orbit0, 0, 0, countsMBT, countsMBV});
295 if (mDoDigits & mDecodeInps) {
296 uint64_t trgclassmask = 0xffffffffffffffff;
297 uint64_t trgclassmaskNOTRGDet = 0xffffffffffffffff;
305 if (mCheckConsistency) {
309 if (mDoDigits && !mDecodeInps) {
310 for (
auto const& dig : digitsMap) {
311 digits.push_back(dig.second);
316 if (nwrites < mErrorMax) {
318 std::ofstream dumpctp(
file.c_str(), std::ios::out | std::ios::binary);
319 if (!dumpctp.good()) {
320 LOGP(error,
"Failed to open file {}",
file);
322 LOGP(info,
"CTP dump file open {}",
file);
323 for (
auto it = parser.
begin(); it != parser.
end(); ++it) {
324 char* dataout = (
char*)(it.raw());
325 dumpctp.write(dataout, it.sizeTotal());
339 uint32_t payloadCTP = 0;
341 uint32_t size_gbt = 0;
344 std::array<int, o2::ctp::CTP_NCLASSES>
rates{};
345 std::array<int, o2::ctp::CTP_NCLASSES> ratesC{};
346 for (
auto it = parser.
begin(); it != parser.
end(); ++it) {
350 mPadding = (o2::raw::RDHUtils::getDataFormat(rdh) == 0);
351 }
catch (std::exception& e) {
352 LOG(error) <<
"Failed to extract RDH, abandoning TF sending dummy output, exception was: " << e.what();
357 uint32_t stopBit = o2::raw::RDHUtils::getStop(rdh);
358 uint32_t packetCounter = o2::raw::RDHUtils::getPageCounter(rdh);
360 uint32_t rdhOrbit = o2::raw::RDHUtils::getHeartBeatOrbit(rdh);
361 uint32_t triggerType = o2::raw::RDHUtils::getTriggerType(rdh);
363 bool tf = (triggerType & TF_TRIGGERTYPE_MASK) && (packetCounter == 0);
364 bool hb = (triggerType & HB_TRIGGERTYPE_MASK) && (packetCounter == 0);
368 mTFOrbits.push_back(mTFOrbit);
370 static bool prt =
true;
372 LOG(info) <<
"RDH version:" <<
version <<
" Padding:" << mPadding;
375 auto feeID = o2::raw::RDHUtils::getFEEID(rdh);
376 auto linkCRU = (feeID & 0xf00) >> 8;
378 if (linkCRU == o2::ctp::GBTLinkIDIntRec) {
379 payloadCTP = o2::ctp::NIntRecPayload;
380 }
else if (linkCRU == o2::ctp::GBTLinkIDClassRec) {
381 payloadCTP = o2::ctp::NClassPayload;
383 LOG(error) <<
"Unxpected CTP CRU link:" << linkCRU;
385 LOG(
debug) <<
"RDH FEEid: " << feeID <<
" CTP CRU link:" << linkCRU <<
" Orbit:" << rdhOrbit <<
" triggerType:" << triggerType;
388 for (uint32_t
i = 0;
i < payloadCTP;
i++) {
400 gsl::span<const uint8_t> payload(it.data(), it.size());
405 std::vector<gbtword80_t> gbtwords80;
411 gbtword80_t bcmask = std::bitset<80>(
"111111111111");
412 for (
auto payloadWord : payload) {
413 int wc = wordCount % wordSize;
415 if ((wc == 0) && (wordCount != 0)) {
416 if (gbtWord80.count() != 80) {
417 gbtwords80.push_back(gbtWord80);
422 for (
int i = 0;
i < 8;
i++) {
423 gbtWord80[wc * 8 +
i] = bool(
int(payloadWord) & (1 <<
i));
428 if ((gbtWord80.count() != 80) && (gbtWord80.count() > 0)) {
429 gbtwords80.push_back(gbtWord80);
432 for (
auto word : gbtwords80) {
433 std::vector<gbtword80_t> diglets;
436 for (
auto diglet : diglets) {
437 int nbits = payloadCTP - 12;
438 for (
int i = 0;
i < nbits;
i++) {
442 if (pld.count() != 0) {
443 if (linkCRU == o2::ctp::GBTLinkIDIntRec) {
453 if ((remnant.count() > 0) && stopBit) {
454 int nbits = payloadCTP - 12;
455 for (
int i = 0;
i < nbits;
i++) {
459 if (pld.count() != 0) {
460 if (linkCRU == o2::ctp::GBTLinkIDIntRec) {
471 std::map<int, int> ratesmap;
472 std::map<int, int> ratesmapC;
473 for (
int i = 0;
i < o2::ctp::CTP_NCLASSES;
i++) {
478 ratesmapC[ratesC[
i]] =
i;
482 std::string
message =
"Ringing inputs [MHz]:";
483 for (
auto const&
r : boost::adaptors::reverse(ratesmap)) {
487 std::string messageC =
"Ringing classes [MHz]:";
488 for (
auto const&
r : boost::adaptors::reverse(ratesmapC)) {
491 LOG(error) << messageC;
536 std::map<o2::InteractionRecord, CTPDigit> digitsMapShifted;
539 for (
auto const& dig : digitsMap) {
540 auto inpmask = dig.second.CTPInputMask;
541 auto inpmaskLM = inpmask & LMMASKInputs;
542 auto inpmaskL0 = inpmask & L0MASKInputs;
543 auto inpmaskL1 = inpmask & L1MASKInputs;
544 int lm = inpmaskLM.count() > 0;
545 int l0 = inpmaskL0.count() > 0;
546 int l1 = inpmaskL1.count() > 0;
547 int lut = lm + (l0 << 1) + (l1 << 2);
551 if (lut == 0 || lut == 1) {
552 digitsMapShifted[dig.first] = dig.second;
553 }
else if (lut == 2) {
554 shiftNew(dig.first, TFOrbit, inpmask, L0shift, 0, digitsMapShifted);
555 if (dig.second.CTPClassMask.count()) {
559 digitsMapShifted[dig.first] = digi;
561 }
else if (lut == 4) {
562 shiftNew(dig.first, TFOrbit, inpmask, L1shift, 1, digitsMapShifted);
563 if (dig.second.CTPClassMask.count()) {
565 digitsMapShifted[dig.first] = digi;
567 }
else if (lut == 6) {
568 shiftNew(dig.first, TFOrbit, inpmask, L0shift, 0, digitsMapShifted);
569 shiftNew(dig.first, TFOrbit, inpmask, L1shift, 1, digitsMapShifted);
570 if (dig.second.CTPClassMask.count()) {
572 digitsMapShifted[dig.first] = digi;
574 }
else if (lut == 3) {
575 shiftNew(dig.first, TFOrbit, inpmask, L0shift, 0, digitsMapShifted);
578 digitsMapShifted[dig.first] = digi;
579 }
else if (lut == 5) {
580 shiftNew(dig.first, TFOrbit, inpmask, L1shift, 1, digitsMapShifted);
582 digitsMapShifted[dig.first] = digi;
583 }
else if (lut == 7) {
584 shiftNew(dig.first, TFOrbit, inpmask, L0shift, 0, digitsMapShifted);
585 shiftNew(dig.first, TFOrbit, inpmask, L1shift, 1, digitsMapShifted);
587 digitsMapShifted[dig.first] = digi;
589 LOG(fatal) <<
"lut = " << lut;
592 for (
auto const& dig : digitsMapShifted) {
593 digits.push_back(dig.second);
602 static int nerror = 0;
603 for (
auto const& digit :
digits) {
605 for (
int i = 0;
i < digit.CTPClassMask.size();
i++) {
606 bool trgcls = trgclassmask & (1ull <<
i);
607 if (digit.CTPClassMask[
i] & trgcls) {
609 if (cls ==
nullptr) {
610 if (nerror < mErrorMax) {
611 LOG(error) <<
"Class mask index not found in CTP config:" <<
i;
617 mClassCountersA[
i]++;
622 uint64_t diginpmask = digit.CTPInputMask.to_ullong();
623 if (!((clsinpmask & diginpmask) == clsinpmask)) {
624 if (nerror < mErrorMax) {
625 LOG(error) <<
"Cls=>Inps: CTP class:" << cls->
name <<
" inpmask:" << clsinpmask <<
" not compatible with inputs mask:" << diginpmask;
636 if (cls.descriptor ==
nullptr) {
639 uint64_t clsinpmask = cls.descriptor->getInputsMask();
640 uint64_t diginpmask = digit.CTPInputMask.to_ullong();
641 uint64_t digclsmask = digit.CTPClassMask.to_ullong();
642 if ((clsinpmask & diginpmask) == clsinpmask) {
643 if (cls.classMask & trgclassmask) {
644 mClassCountersB[cls.getIndex()]++;
645 if ((cls.classMask & digclsmask) == 0) {
649 if (digit.intRecord.bc <
offset) {
650 if ((nerror < mErrorMax) && (cls.classMask & ~trgclassmaskNoTrgDet)) {
651 LOG(info) <<
"Inp=>Cls: CTP class:" << cls.name <<
" inpmask:" << clsinpmask <<
" cls mask:" << cls.classMask <<
" not found in digit:" << digit;
654 mClassErrorsB[cls.getIndex()]++;
664 if (mLostDueToShift) {
665 LOG(
debug) <<
"LOST classes because of shift:" << mLostDueToShift;