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;
302 if (mCheckConsistency) {
306 if (mDoDigits && !mDecodeInps) {
307 for (
auto const& dig : digitsMap) {
308 digits.push_back(dig.second);
313 if (nwrites < mErrorMax) {
315 std::ofstream dumpctp(
file.c_str(), std::ios::out | std::ios::binary);
316 if (!dumpctp.good()) {
317 LOGP(error,
"Failed to open file {}",
file);
319 LOGP(info,
"CTP dump file open {}",
file);
320 for (
auto it = parser.
begin(); it != parser.
end(); ++it) {
321 char* dataout = (
char*)(it.raw());
322 dumpctp.write(dataout, it.sizeTotal());
336 uint32_t payloadCTP = 0;
338 uint32_t size_gbt = 0;
341 std::array<int, o2::ctp::CTP_NCLASSES>
rates{};
342 std::array<int, o2::ctp::CTP_NCLASSES> ratesC{};
343 for (
auto it = parser.
begin(); it != parser.
end(); ++it) {
347 mPadding = (o2::raw::RDHUtils::getDataFormat(rdh) == 0);
348 }
catch (std::exception& e) {
349 LOG(error) <<
"Failed to extract RDH, abandoning TF sending dummy output, exception was: " << e.what();
354 uint32_t stopBit = o2::raw::RDHUtils::getStop(rdh);
355 uint32_t packetCounter = o2::raw::RDHUtils::getPageCounter(rdh);
357 uint32_t rdhOrbit = o2::raw::RDHUtils::getHeartBeatOrbit(rdh);
358 uint32_t triggerType = o2::raw::RDHUtils::getTriggerType(rdh);
360 bool tf = (triggerType & TF_TRIGGERTYPE_MASK) && (packetCounter == 0);
361 bool hb = (triggerType & HB_TRIGGERTYPE_MASK) && (packetCounter == 0);
365 mTFOrbits.push_back(mTFOrbit);
367 static bool prt =
true;
369 LOG(info) <<
"RDH version:" <<
version <<
" Padding:" << mPadding;
372 auto feeID = o2::raw::RDHUtils::getFEEID(rdh);
373 auto linkCRU = (feeID & 0xf00) >> 8;
375 if (linkCRU == o2::ctp::GBTLinkIDIntRec) {
376 payloadCTP = o2::ctp::NIntRecPayload;
377 }
else if (linkCRU == o2::ctp::GBTLinkIDClassRec) {
378 payloadCTP = o2::ctp::NClassPayload;
380 LOG(error) <<
"Unxpected CTP CRU link:" << linkCRU;
382 LOG(
debug) <<
"RDH FEEid: " << feeID <<
" CTP CRU link:" << linkCRU <<
" Orbit:" << rdhOrbit <<
" triggerType:" << triggerType;
385 for (uint32_t
i = 0;
i < payloadCTP;
i++) {
397 gsl::span<const uint8_t> payload(it.data(), it.size());
402 std::vector<gbtword80_t> gbtwords80;
408 gbtword80_t bcmask = std::bitset<80>(
"111111111111");
409 for (
auto payloadWord : payload) {
410 int wc = wordCount % wordSize;
412 if ((wc == 0) && (wordCount != 0)) {
413 if (gbtWord80.count() != 80) {
414 gbtwords80.push_back(gbtWord80);
419 for (
int i = 0;
i < 8;
i++) {
420 gbtWord80[wc * 8 +
i] = bool(
int(payloadWord) & (1 <<
i));
425 if ((gbtWord80.count() != 80) && (gbtWord80.count() > 0)) {
426 gbtwords80.push_back(gbtWord80);
429 for (
auto word : gbtwords80) {
430 std::vector<gbtword80_t> diglets;
433 for (
auto diglet : diglets) {
434 int nbits = payloadCTP - 12;
435 for (
int i = 0;
i < nbits;
i++) {
439 if (pld.count() != 0) {
440 if (linkCRU == o2::ctp::GBTLinkIDIntRec) {
450 if ((remnant.count() > 0) && stopBit) {
451 int nbits = payloadCTP - 12;
452 for (
int i = 0;
i < nbits;
i++) {
456 if (pld.count() != 0) {
457 if (linkCRU == o2::ctp::GBTLinkIDIntRec) {
468 std::map<int, int> ratesmap;
469 std::map<int, int> ratesmapC;
470 for (
int i = 0;
i < o2::ctp::CTP_NCLASSES;
i++) {
475 ratesmapC[ratesC[
i]] =
i;
479 std::string
message =
"Ringing inputs [MHz]:";
480 for (
auto const&
r : boost::adaptors::reverse(ratesmap)) {
484 std::string messageC =
"Ringing classes [MHz]:";
485 for (
auto const&
r : boost::adaptors::reverse(ratesmapC)) {
488 LOG(error) << messageC;
539 std::map<o2::InteractionRecord, CTPDigit> digitsMapShifted;
542 for (
auto const& dig : digitsMap) {
543 auto inpmask = dig.second.CTPInputMask;
544 auto inpmaskLM = inpmask & LMMASKInputs;
545 auto inpmaskL0 = inpmask & L0MASKInputs;
546 auto inpmaskL1 = inpmask & L1MASKInputs;
547 int lm = inpmaskLM.count() > 0;
548 int l0 = inpmaskL0.count() > 0;
549 int l1 = inpmaskL1.count() > 0;
550 int lut = lm + (l0 << 1) + (l1 << 2);
554 if (lut == 0 || lut == 1) {
555 digitsMapShifted[dig.first] = dig.second;
556 }
else if (lut == 2) {
557 shiftNew(dig.first, TFOrbit, inpmask, L0shift, 0, digitsMapShifted);
558 if (dig.second.CTPClassMask.count()) {
562 digitsMapShifted[dig.first] = digi;
564 }
else if (lut == 4) {
565 shiftNew(dig.first, TFOrbit, inpmask, L1shift, 1, digitsMapShifted);
566 if (dig.second.CTPClassMask.count()) {
568 digitsMapShifted[dig.first] = digi;
570 }
else if (lut == 6) {
571 shiftNew(dig.first, TFOrbit, inpmask, L0shift, 0, digitsMapShifted);
572 shiftNew(dig.first, TFOrbit, inpmask, L1shift, 1, digitsMapShifted);
573 if (dig.second.CTPClassMask.count()) {
575 digitsMapShifted[dig.first] = digi;
577 }
else if (lut == 3) {
578 shiftNew(dig.first, TFOrbit, inpmask, L0shift, 0, digitsMapShifted);
581 digitsMapShifted[dig.first] = digi;
582 }
else if (lut == 5) {
583 shiftNew(dig.first, TFOrbit, inpmask, L1shift, 1, digitsMapShifted);
585 digitsMapShifted[dig.first] = digi;
586 }
else if (lut == 7) {
587 shiftNew(dig.first, TFOrbit, inpmask, L0shift, 0, digitsMapShifted);
588 shiftNew(dig.first, TFOrbit, inpmask, L1shift, 1, digitsMapShifted);
590 digitsMapShifted[dig.first] = digi;
592 LOG(fatal) <<
"lut = " << lut;
595 for (
auto const& dig : digitsMapShifted) {
597 if ((d.CTPInputMask & LMMASKInputs).count()) {
600 if ((d.CTPInputMask & L0MASKInputs).count()) {
603 if ((d.CTPInputMask & L1MASKInputs).count()) {
606 if ((d.CTPClassMask).to_ulong() & trgclassmask) {
607 if (d.CTPInputMask.count()) {
619 digits.push_back(dig.second);
623 LOG(error) <<
"LM:" << nLM <<
" L0:" << nL0 <<
" L1:" << nL1 <<
" TwI:" << nTwI <<
" Trigger classes wo input:" << nTwoI;
627 LOG(warn) <<
" Trigger classes wo input from diff latency 1:" << nTwoIlost;