|
17 | 17 | #include "DataFormatsCTP/TriggerOffsetsParam.h" |
18 | 18 | #include "CTPReconstruction/RawDataDecoder.h" |
19 | 19 | #include "DataFormatsCTP/Configuration.h" |
| 20 | +#include "DetectorsBase/GRPGeomHelper.h" |
| 21 | +#include <boost/range/adaptor/reversed.hpp> |
20 | 22 |
|
21 | 23 | using namespace o2::ctp; |
22 | 24 |
|
@@ -174,6 +176,7 @@ int RawDataDecoder::decodeRaw(o2::framework::InputRecord& inputs, std::vector<o2 |
174 | 176 | } |
175 | 177 | auto feeID = o2::raw::RDHUtils::getFEEID(rdh); // 0 = IR, 1 = TCR |
176 | 178 | auto linkCRU = (feeID & 0xf00) >> 8; |
| 179 | + // LOG(info) << "CRU link:" << linkCRU; |
177 | 180 | if (linkCRU == o2::ctp::GBTLinkIDIntRec) { |
178 | 181 | payloadCTP = o2::ctp::NIntRecPayload; |
179 | 182 | } else if (linkCRU == o2::ctp::GBTLinkIDClassRec) { |
@@ -319,6 +322,166 @@ int RawDataDecoder::decodeRaw(o2::framework::InputRecord& inputs, std::vector<o2 |
319 | 322 | return ret; |
320 | 323 | } |
321 | 324 | // |
| 325 | +int RawDataDecoder::decodeRawFatal(o2::framework::InputRecord& inputs, std::vector<o2::framework::InputSpec>& filter) |
| 326 | +{ |
| 327 | + o2::framework::DPLRawParser parser(inputs, filter); |
| 328 | + uint32_t payloadCTP = 0; |
| 329 | + gbtword80_t remnant = 0; |
| 330 | + uint32_t size_gbt = 0; |
| 331 | + mTFOrbit = 0; |
| 332 | + uint32_t orbit0 = 0; |
| 333 | + std::array<int, o2::ctp::CTP_NCLASSES> rates{}; |
| 334 | + std::array<int, o2::ctp::CTP_NCLASSES> ratesC{}; |
| 335 | + for (auto it = parser.begin(); it != parser.end(); ++it) { |
| 336 | + const o2::header::RDHAny* rdh = nullptr; |
| 337 | + try { |
| 338 | + rdh = reinterpret_cast<const o2::header::RDHAny*>(it.raw()); |
| 339 | + mPadding = (o2::raw::RDHUtils::getDataFormat(rdh) == 0); |
| 340 | + } catch (std::exception& e) { |
| 341 | + LOG(error) << "Failed to extract RDH, abandoning TF sending dummy output, exception was: " << e.what(); |
| 342 | + // dummyOutput(); |
| 343 | + return 1; |
| 344 | + } |
| 345 | + // auto triggerOrbit = o2::raw::RDHUtils::getTriggerOrbit(rdh); |
| 346 | + uint32_t stopBit = o2::raw::RDHUtils::getStop(rdh); |
| 347 | + uint32_t packetCounter = o2::raw::RDHUtils::getPageCounter(rdh); |
| 348 | + uint32_t version = o2::raw::RDHUtils::getVersion(rdh); |
| 349 | + uint32_t rdhOrbit = o2::raw::RDHUtils::getHeartBeatOrbit(rdh); |
| 350 | + uint32_t triggerType = o2::raw::RDHUtils::getTriggerType(rdh); |
| 351 | + // std::cout << "diff orbits:" << triggerOrbit - rdhOrbit << std::endl; |
| 352 | + bool tf = (triggerType & TF_TRIGGERTYPE_MASK) && (packetCounter == 0); |
| 353 | + bool hb = (triggerType & HB_TRIGGERTYPE_MASK) && (packetCounter == 0); |
| 354 | + if (tf) { |
| 355 | + mTFOrbit = rdhOrbit; |
| 356 | + // std::cout << "tforbit==================>" << mTFOrbit << " " << std::hex << mTFOrbit << std::endl; |
| 357 | + mTFOrbits.push_back(mTFOrbit); |
| 358 | + } |
| 359 | + static bool prt = true; |
| 360 | + if (prt) { |
| 361 | + LOG(info) << "RDH version:" << version << " Padding:" << mPadding; |
| 362 | + prt = false; |
| 363 | + } |
| 364 | + auto feeID = o2::raw::RDHUtils::getFEEID(rdh); // 0 = IR, 1 = TCR |
| 365 | + auto linkCRU = (feeID & 0xf00) >> 8; |
| 366 | + // LOG(info) << "CRU link:" << linkCRU; |
| 367 | + if (linkCRU == o2::ctp::GBTLinkIDIntRec) { |
| 368 | + payloadCTP = o2::ctp::NIntRecPayload; |
| 369 | + } else if (linkCRU == o2::ctp::GBTLinkIDClassRec) { |
| 370 | + payloadCTP = o2::ctp::NClassPayload; |
| 371 | + } else { |
| 372 | + LOG(error) << "Unxpected CTP CRU link:" << linkCRU; |
| 373 | + } |
| 374 | + LOG(debug) << "RDH FEEid: " << feeID << " CTP CRU link:" << linkCRU << " Orbit:" << rdhOrbit << " triggerType:" << triggerType; |
| 375 | + // LOG(info) << "remnant :" << remnant.count(); |
| 376 | + gbtword80_t pldmask = 0; |
| 377 | + for (uint32_t i = 0; i < payloadCTP; i++) { |
| 378 | + pldmask[12 + i] = 1; |
| 379 | + } |
| 380 | + // std::cout << (orbit0 != rdhOrbit) << " comp " << (mTFOrbit==rdhOrbit) << std::endl; |
| 381 | + // if(orbit0 != rdhOrbit) { |
| 382 | + if (hb) { |
| 383 | + remnant = 0; |
| 384 | + size_gbt = 0; |
| 385 | + orbit0 = rdhOrbit; |
| 386 | + // std::cout << "orbit0============>" << std::dec << orbit0 << " " << std::hex << orbit0 << std::endl; |
| 387 | + } |
| 388 | + // Create 80 bit words |
| 389 | + gsl::span<const uint8_t> payload(it.data(), it.size()); |
| 390 | + gbtword80_t gbtWord80; |
| 391 | + gbtWord80.set(); |
| 392 | + int wordCount = 0; |
| 393 | + int wordSize = 10; |
| 394 | + std::vector<gbtword80_t> gbtwords80; |
| 395 | + // mPadding = 0; |
| 396 | + if (mPadding == 1) { |
| 397 | + wordSize = 16; |
| 398 | + } |
| 399 | + // LOG(info) << ii << " payload size:" << payload.size(); |
| 400 | + gbtword80_t bcmask = std::bitset<80>("111111111111"); |
| 401 | + for (auto payloadWord : payload) { |
| 402 | + int wc = wordCount % wordSize; |
| 403 | + // LOG(info) << wordCount << ":" << wc << " payload:" << int(payloadWord); |
| 404 | + if ((wc == 0) && (wordCount != 0)) { |
| 405 | + if (gbtWord80.count() != 80) { |
| 406 | + gbtwords80.push_back(gbtWord80); |
| 407 | + } |
| 408 | + gbtWord80.set(); |
| 409 | + } |
| 410 | + if (wc < 10) { |
| 411 | + for (int i = 0; i < 8; i++) { |
| 412 | + gbtWord80[wc * 8 + i] = bool(int(payloadWord) & (1 << i)); |
| 413 | + } |
| 414 | + } |
| 415 | + wordCount++; |
| 416 | + } |
| 417 | + if ((gbtWord80.count() != 80) && (gbtWord80.count() > 0)) { |
| 418 | + gbtwords80.push_back(gbtWord80); |
| 419 | + } |
| 420 | + // decode 80 bits payload |
| 421 | + for (auto word : gbtwords80) { |
| 422 | + std::vector<gbtword80_t> diglets; |
| 423 | + gbtword80_t gbtWord = word; |
| 424 | + makeGBTWordInverse(diglets, gbtWord, remnant, size_gbt, payloadCTP); |
| 425 | + for (auto diglet : diglets) { |
| 426 | + int nbits = payloadCTP - 12; |
| 427 | + for (int i = 0; i < nbits; i++) { |
| 428 | + gbtword80_t mask = 1ull << i; |
| 429 | + gbtword80_t pld = (diglet >> 12) & mask; |
| 430 | + // LOG(info) << "diglet:" << diglet << " pld:" << pld; |
| 431 | + if (pld.count() != 0) { |
| 432 | + if (linkCRU == o2::ctp::GBTLinkIDIntRec) { |
| 433 | + rates[i]++; |
| 434 | + } else { |
| 435 | + ratesC[i]++; |
| 436 | + } |
| 437 | + } |
| 438 | + } |
| 439 | + // LOG(debug) << "diglet:" << diglet << " " << (diglet & bcmask).to_ullong(); |
| 440 | + } |
| 441 | + } |
| 442 | + if ((remnant.count() > 0) && stopBit) { |
| 443 | + int nbits = payloadCTP - 12; |
| 444 | + for (int i = 0; i < nbits; i++) { |
| 445 | + gbtword80_t mask = 1ull << i; |
| 446 | + gbtword80_t pld = (remnant >> 12) & mask; |
| 447 | + // LOG(info) << "diglet:" << remnant << " pld:" << pld; |
| 448 | + if (pld.count() != 0) { |
| 449 | + if (linkCRU == o2::ctp::GBTLinkIDIntRec) { |
| 450 | + rates[i]++; |
| 451 | + } else { |
| 452 | + ratesC[i]++; |
| 453 | + } |
| 454 | + } |
| 455 | + } |
| 456 | + remnant = 0; |
| 457 | + } |
| 458 | + } |
| 459 | + // print max rates |
| 460 | + std::map<int, int> ratesmap; |
| 461 | + std::map<int, int> ratesmapC; |
| 462 | + for (int i = 0; i < o2::ctp::CTP_NCLASSES; i++) { |
| 463 | + if (rates[i]) { |
| 464 | + ratesmap[rates[i]] = i; |
| 465 | + } |
| 466 | + if (ratesC[i]) { |
| 467 | + ratesmapC[ratesC[i]] = i; |
| 468 | + } |
| 469 | + } |
| 470 | + auto nhb = o2::base::GRPGeomHelper::getNHBFPerTF(); |
| 471 | + std::string message = "Ringing inputs [MHz]:"; |
| 472 | + for (auto const& r : boost::adaptors::reverse(ratesmap)) { |
| 473 | + // LOG(error) << r.second; |
| 474 | + message += " " + o2::ctp::CTPInputsConfiguration::getInputNameFromIndex(r.second + 1) + ":" + std::to_string(r.first / 32. / o2::constants::lhc::LHCOrbitMUS); |
| 475 | + } |
| 476 | + std::string messageC = "Ringing classes [MHz]:"; |
| 477 | + for (auto const& r : boost::adaptors::reverse(ratesmapC)) { |
| 478 | + messageC += " class" + std::to_string(r.second) + ":" + std::to_string(r.first / 32. / o2::constants::lhc::LHCOrbitMUS); |
| 479 | + } |
| 480 | + LOG(error) << messageC; |
| 481 | + LOG(fatal) << message; |
| 482 | + return 0; |
| 483 | +} |
| 484 | +// |
322 | 485 | int RawDataDecoder::decodeRaw(o2::framework::InputRecord& inputs, std::vector<o2::framework::InputSpec>& filter, std::vector<CTPDigit>& digits, std::vector<LumiInfo>& lumiPointsHBF1) |
323 | 486 | { |
324 | 487 | o2::pmr::vector<CTPDigit> pmrdigits; |
|
0 commit comments