5#ifndef MUONBYTESTREAM_RPCROD_DECODER_H
6#define MUONBYTESTREAM_RPCROD_DECODER_H
12#include "GaudiKernel/GaudiException.h"
13#include "GaudiKernel/ServiceHandle.h"
14#include "GaudiKernel/ToolHandle.h"
27#include "eformat/Issue.h"
28#include "eformat/SourceIdentifier.h"
37 inline bool ensure_more_data(
int index,
int size, MsgStream& log,
bool& printMessage,
const std::string& message) {
39 if (printMessage && log.level() <= MSG::WARNING) {
40 log << MSG::WARNING <<
"Unexpected end of RPC data: " << message <<
endmsg;
55 virtual StatusCode
finalize()
override;
60 const bool& decodeSL)
const override;
84 inline std::vector<uint16_t>
get16bits(
BS data,
const int size,
const int nHeader,
const int nFooter)
const;
86 inline std::vector<uint16_t>
get16bits_v301(
BS data,
const int size,
const int nHeader,
const int nFooter)
const;
96 Gaudi::Property<int>
m_nobxs {
this,
"NOBXS", 8,
"Number of bunch crossings in readout"};
117 StatusCode
sc = StatusCode::SUCCESS;
122 for (
int i = ini; i < end; i++) {
123 decoded = ((*pdata)[i] & 0xf000) >> 12;
126 if (decoded == 0x9) {
133 sc = StatusCode::FAILURE;
139 else if (decoded == 0xe) {
145 sc = StatusCode::FAILURE;
150 else if (decoded == 0x5) {
156 sc = StatusCode::FAILURE;
162 else if (decoded == 0x6) {
165 }
else if (previous == 8) {
170 sc = StatusCode::FAILURE;
176 else if (decoded == 0xc) {
182 sc = StatusCode::FAILURE;
188 else if (decoded == 0x8) {
194 sc = StatusCode::FAILURE;
200 else if (decoded == 0x4) {
201 if (previous == -1 || previous == 6) {
203 if (matrix.checkCRC8((
ubit16)(*pdata)[i])) {
206 sc = StatusCode::RECOVERABLE;
211 sc = StatusCode::FAILURE;
217 else if (decoded == 0xa) {
223 sc = StatusCode::FAILURE;
229 else if (decoded == 0x7) {
235 sc = StatusCode::FAILURE;
241 else if (decoded == 0xd) {
247 sc = StatusCode::FAILURE;
253 else if (decoded == 0xf) {
254 if (previous == 9 || previous == -1) {
259 sc = StatusCode::FAILURE;
264 else if (decoded == 0xb) {
265 if (previous == 10) {
272 sc = StatusCode::FAILURE;
279 sc = StatusCode::FAILURE;
288 log << MSG::INFO <<
" ============ FINAL RPC DATA FORMAT STAT. =========== " <<
endmsg;
290 log << MSG::INFO <<
" RX Header Errors............." << tmp <<
endmsg;
303 log << MSG::INFO <<
" ==================================================== " <<
endmsg;
307 const std::vector<IdentifierHash>& collections,
311 }
catch (eformat::Issue& ex) {
313 return StatusCode::FAILURE;
316 if (RPC_SECTORLOGIC ==
nullptr) {
ATH_MSG_DEBUG(
"RPC_SECTORLOGIC is null, so we will skip decoding the sector logic information"); }
320 robFrag.rod_data(
data);
323 uint32_t version = robFrag.rod_version();
324 uint32_t sourceId = robFrag.source_id();
325 uint32_t rod_sourceId = robFrag.rod_source_id();
326 uint16_t subDetector = (sourceId & 0xff0000) >> 16;
328 ATH_MSG_VERBOSE(
"ROD version: " << MSG::hex << version << MSG::dec <<
" ROB source ID: " << MSG::hex << sourceId << MSG::dec
329 <<
" ROD source ID: " << MSG::hex << rod_sourceId << MSG::dec <<
" Subdetector: " << MSG::hex
330 << subDetector << MSG::dec);
333 bool isSimulated = (
data[0] == 0xee1234ee) ?
true :
false;
336 if (((version & 0x03000000) == 0x03000000) && (
data[2] != 0x00) && ((
data[0] & 0xffff0000) == 0)) {
339 }
else if (version == 0x2400000 || isSimulated) {
342 }
else if (((version & 0x03000000) == 0x03000000) &&
343 ((
data[0] & 0xffff0000) != 0))
359 std::map<Identifier, RpcPad*> mapOfCollections;
369 if (alreadyPresent) {
370 ATH_MSG_DEBUG(
"RPC RDO collection already exist with collection hash = " <<
static_cast<unsigned int>(it)
371 <<
" converting is skipped!");
373 ATH_MSG_DEBUG(
"Created new Pad Collection Hash ID = " <<
static_cast<unsigned int>(it));
377 mapOfCollections[coll->
identify()] = coll;
382 if (mapOfCollections.empty()) {
383 ATH_MSG_VERBOSE(
"mapOfCollections is empty; fillCollectionsFromRob_v302 will not be called");
384 cnv_sc = StatusCode::SUCCESS;
390 if (cnv_sc != StatusCode::SUCCESS) {
391 if (cnv_sc == StatusCode::RECOVERABLE) {
399 for (
const std::map<Identifier, RpcPad*>::value_type& it : mapOfCollections) {
405 ATH_MSG_DEBUG(
"RpcPad collection with hash " << (
int)(it.second)->identifyHash()
406 <<
" was already decoded in a parallel view");
409 StatusCode status_lock = lock.
addOrDelete(std::unique_ptr<RpcPad>(it.second));
411 if (status_lock != StatusCode::SUCCESS) {
412 ATH_MSG_ERROR(
"Failed to add RPC PAD collection to container with hash " << (
int)(it.second)->identifyHash());
414 ATH_MSG_DEBUG(
"Adding RpcPad collection with hash " << (
int)(it.second)->identifyHash()
415 <<
" to the RpcPad Container | size = " << (it.second)->size());
428 ATH_MSG_DEBUG(
"RPC RDO collection already exist with collection hash = " <<
static_cast<unsigned int>(it)
429 <<
" converting is skipped!");
431 ATH_MSG_VERBOSE(
" Created new Pad Collection Hash ID = " <<
static_cast<unsigned int>(it));
444 if (cnv_sc.isFailure()) {
ATH_MSG_VERBOSE(
"Error into the RPC fillCollections decoding"); }
448 StatusCode status_lock = lock.
addOrDelete(std::unique_ptr<RpcPad>(coll));
451 if (status_lock != StatusCode::SUCCESS) {
452 ATH_MSG_ERROR(
"Failed to add RPC PAD collection to container");
455 ATH_MSG_DEBUG(
"Adding RpcPad collection with hash " << (
int)(it)
456 <<
" to the RpcPad Container | size = " << coll->
size());
469 bool skipSectorLogicDecoding = (sectorLogicContainer ==
nullptr);
470 if (skipSectorLogicDecoding)
ATH_MSG_DEBUG(
"Skip SectorLogic decoding, so SLROC.decodeFragment is not being processed");
482 const int size = p.size();
490 if (size > 0 && msgLvl(MSG::VERBOSE)) {
491 msg(MSG::VERBOSE) <<
"The size of this ROD-read is " << size <<
endmsg;
493 char decoded_char[1000];
494 for (
int i = 0; i < size; i++) {
495 decoded = (p[i] & 0xf000) >> 12;
496 if (decoded < 0x4) sprintf(decoded_char,
"Hit data");
497 if (decoded == 0x4) sprintf(decoded_char,
"CM Footer");
498 if (decoded == 0x5) sprintf(decoded_char,
"PAD Header");
499 if (decoded == 0x6) sprintf(decoded_char,
"PAD/SL Subheader");
500 if (decoded == 0x7) sprintf(decoded_char,
"PAD Footer");
501 if (decoded == 0x8) sprintf(decoded_char,
"CM Subheader");
502 if (decoded == 0x9) sprintf(decoded_char,
"RX Header");
503 if (decoded == 0xa) sprintf(decoded_char,
"PAD Prefooter");
504 if (decoded == 0xb) sprintf(decoded_char,
"RX Footer");
505 if (decoded == 0xc) sprintf(decoded_char,
"CM Header");
506 if (decoded == 0xd) sprintf(decoded_char,
"SL Header");
507 if (decoded == 0xe) sprintf(decoded_char,
"RX Subheader");
508 if (decoded == 0xf) sprintf(decoded_char,
"SL Footer");
510 msg(MSG::VERBOSE) <<
"word " << i <<
" = " << MSG::hex << p[i] << MSG::dec <<
" " << MSG::hex << decoded << MSG::dec <<
" "
511 << decoded_char <<
endmsg;
517 return StatusCode::FAILURE;
520 if (msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"The source ID is: " << MSG::hex << sourceId <<
endmsg;
522 uint16_t sectorForCabling = 0;
526 uint16_t SLindex = 0;
533 bool foundPad =
false;
535 if (msgLvl(MSG::VERBOSE))
536 msg(MSG::VERBOSE) <<
"The offline ID request for conversion is "
539 bool isSLHeader =
false;
540 bool isSLSubHeader =
false;
541 bool isSLFooter =
false;
542 bool isSLFragment =
false;
543 bool isRXHeader =
false;
544 bool isRXFooter =
false;
545 bool isPADFragment =
false;
546 bool isPadHeader =
false;
547 bool isPadSubHeader =
false;
548 bool isPadPreFooter =
false;
549 bool isPadFooter =
false;
561 unsigned short int PadID = 99;
562 uint16_t slfel1id = 0;
565 uint16_t slstatus = 0;
567 unsigned int SLBodyWords = 0;
568 unsigned int SL_data_sise = 500;
569 unsigned short int SLBuff[500];
573 uint16_t subDetectorID = (sourceId & 0xff0000) >> 16;
575 uint16_t side = (subDetectorID == eformat::MUON_RPC_BARREL_A_SIDE) ? 1 : 0;
577 if (msgLvl(MSG::VERBOSE)) {
578 msg(MSG::VERBOSE) <<
"subDetectorID = 0x" << MSG::hex << subDetectorID << MSG::dec <<
endmsg;
580 msg(MSG::VERBOSE) <<
"rodID = 0x" << MSG::hex << rodId << MSG::dec <<
endmsg;
581 msg(MSG::VERBOSE) <<
"The side is " << side <<
endmsg;
586 for (uint16_t i = 0; i < size; ++i) {
592 isPadSubHeader =
false;
593 isPadPreFooter =
false;
596 isSLSubHeader =
false;
598 uint32_t currentWord = p[i];
602 if (!skipSectorLogicDecoding) { SLROS.
decodeFragment(currentWord, recField); }
606 isSLFragment =
false;
607 isPADFragment =
false;
609 isPadSubHeader =
true;
614 isSLFragment =
false;
616 isPadPreFooter =
true;
622 isPADFragment =
false;
625 isSLFragment =
false;
627 isSLSubHeader =
true;
631 if (skipSectorLogicDecoding) {
633 isSLSubHeader =
false;
634 isSLFragment =
false;
641 if (msgLvl(MSG::VERBOSE)) {
642 char decoded_char[256];
644 sprintf(decoded_char,
" RX Header");
645 }
else if (isRXFooter) {
646 sprintf(decoded_char,
" RX Footer");
647 }
else if (isSLHeader) {
648 sprintf(decoded_char,
" SL Header");
649 }
else if (isSLSubHeader) {
650 sprintf(decoded_char,
" SL SubHeader");
651 }
else if (isSLFooter) {
652 sprintf(decoded_char,
" SL Footer");
653 }
else if (isPadHeader) {
654 sprintf(decoded_char,
" Pad Header");
655 }
else if (isPadSubHeader) {
656 sprintf(decoded_char,
" Pad SubHeader");
657 }
else if (isPadPreFooter) {
658 sprintf(decoded_char,
" Pad PreFooter");
659 }
else if (isPadFooter) {
660 sprintf(decoded_char,
" Pad Footer");
661 }
else if (isSLFragment) {
662 sprintf(decoded_char,
" SL Fragment");
663 }
else if (isPADFragment) {
664 sprintf(decoded_char,
" Pad Fragment");
666 sprintf(decoded_char,
" Undecoded");
669 msg(MSG::VERBOSE) << i <<
" -->current data word is " << MSG::hex << currentWord << MSG::dec << decoded_char <<
endmsg;
672 if (msgLvl(MSG::VERBOSE)) {
673 msg(MSG::VERBOSE) <<
" this is a RX Header " <<
endmsg;
674 msg(MSG::VERBOSE) <<
" Sector ID=" << RXROS.
RXid() <<
endmsg;
682 uint16_t rxid = RXROS.
RXid();
683 sectorForCabling = 2 * rodId + rxid;
684 sector = side * 32 + sectorForCabling;
689 sectorForCabling = 7;
693 sectorForCabling = 8;
697 sectorForCabling = 8;
700 }
else if (isRXFooter) {
702 }
else if (isSLHeader || isSLFragment || isSLSubHeader || isSLFooter) {
708 slfel1id = SLROS.
fel1id();
711 ATH_MSG_VERBOSE(
" SL Header: slfel1id " << slfel1id <<
" slid: " << slid);
712 }
else if (isSLSubHeader) {
719 else if (isSLFooter) {
720 if (SLindex > 1) {
ATH_MSG_VERBOSE(
"More than 2 SL fragments in sector " << sector); }
722 if (msgLvl(MSG::VERBOSE)) {
723 msg(MSG::VERBOSE) <<
" Number of data words in SectorLogicReadOut= " << SLBodyWords <<
endmsg;
724 msg(MSG::VERBOSE) <<
" TEST SL: " << foundSL <<
endmsg;
727 for (
unsigned short j = 0; j < SLBodyWords; j++) {
728 msg(MSG::VERBOSE) <<
" SL data word " << j <<
" : " << MSG::hex << SLBuff[j] << MSG::dec <<
endmsg;
737 if (sectorLogicContainer && !sectorLogicContainer->
findSector(sector, side)) {
738 slstatus = SLROS.
status();
742 bool inputHeaderFound =
false;
743 bool outputHeaderFound =
false;
744 ATH_MSG_VERBOSE(
"New RpcSectorLogic: sector=" << sector <<
" fel1id=" << slfel1id <<
" BCID=" << slbcid);
746 uint16_t rowinBcid = 999;
747 uint16_t slPadId = 999;
761 uint16_t triggerBcid;
766 inputHeaderFound =
true;
768 if (!inputHeaderFound) {
779 new RpcSLTriggerHit(rowinBcid, slPadId, ptid, roi, outerPlane, overlapPhi, overlapEta, triggerBcid);
782 ATH_MSG_VERBOSE(
"New input RpcSLTriggerHit: ptid, roi= " << ptid <<
" " << roi);
786 outputHeaderFound =
true;
788 if (!outputHeaderFound) {
790 if (msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"ERROR: outputSLHeader missing !!" <<
endmsg;
796 for (
int icand = 0; icand < SLROS.
nTriggerCand(); ++icand) {
802 overlapEta, triggerBcid);
806 ATH_MSG_VERBOSE(
"New output RpcSLTriggerHit: ptid, roi= " << ptid <<
" " << roi);
815 if (sectorLogicContainer) sectorLogicContainer->
push_back(sl);
817 if (sectorLogicContainer && !sectorLogicContainer->
setSector(sector, side)) {
818 ATH_MSG_VERBOSE(
"Sector " << sector <<
" decoded more than once in SL");
823 if (SLBodyWords >= SL_data_sise) {
825 return StatusCode::FAILURE;
827 SLBuff[SLBodyWords] = currentWord;
831 }
else if (isPadHeader || isPADFragment) {
837 if (recField ==
'H') {
838 PadID = PDROS.
padid();
851 side = (sector < 32) ? 0 : 1;
852 uint16_t sectorLogic = sector - side * 32;
855 if (!rpcCabling->
giveOfflineId(side, sectorLogic, PadID, padOfflineId)) {
856 if (msgLvl(MSG::VERBOSE))
857 msg(MSG::VERBOSE) <<
"Cannot retrieve the OfflineID for the PAD n. " << PadID <<
" at side " << side
858 <<
" and sector " << sectorLogic <<
endmsg;
860 if (msgLvl(MSG::VERBOSE))
861 msg(MSG::VERBOSE) <<
"ID " <<
m_idHelperSvc->rpcIdHelper().show_to_string(padOfflineId)
862 <<
" associated to PAD n. " << PadID <<
" at side " << side <<
" and sector " << sectorLogic
867 if (thisPadOfflineId == padOfflineId) {
868 if (msgLvl(MSG::VERBOSE))
869 msg(MSG::VERBOSE) <<
" match found with ID " <<
m_idHelperSvc->rpcIdHelper().show_to_string(thisPadOfflineId)
870 <<
" requested for the conversion; return this collection" <<
endmsg;
874 v.setOnlineId(PadID);
878 v.setLvl1Id(PDROS.
l1id());
881 if (msgLvl(MSG::VERBOSE))
882 msg(MSG::VERBOSE) <<
" match NOT found with ID "
883 <<
m_idHelperSvc->rpcIdHelper().show_to_string(thisPadOfflineId)
884 <<
" requested for the conversion" <<
endmsg;
889 if (recField ==
'S') {
891 v.setBcId(PDROS.
bcid());
892 if (msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"Found the subheader, setting bcid to: " << PDROS.
bcid() <<
endmsg;
896 if (recField ==
'P') {
897 if (msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"Found the prefooter" <<
endmsg;
899 v.setStatus(PDROS.
status());
901 if (currentWord & 0x0fff) {
902 if (msgLvl(MSG::VERBOSE))
903 msg(MSG::VERBOSE) <<
"Pad Busy status not zero ! value: " << MSG::hex << (currentWord & 0x0fff) << MSG::dec
908 if (recField ==
'F') {
909 if (msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
" Pad Footer " <<
endmsg;
911 if (msgLvl(MSG::VERBOSE) && PDROS.
errorCode() != 0) {
912 msg(MSG::VERBOSE) <<
"Pad Error flag not zero ! value: " << MSG::hex << PDROS.
errorCode() << MSG::dec <<
endmsg;
920 if (!(PadID > 3 && sector % 2 > 0)) {
return StatusCode::SUCCESS; }
924 isPadFooter ? isPADFragment = false : isPADFragment =
true;
926 if (msgLvl(MSG::VERBOSE)) {
927 msg(MSG::VERBOSE) <<
" current word " << MSG::hex << currentWord << MSG::dec <<
endmsg;
929 msg(MSG::VERBOSE) <<
" ==isPADFragment= " << isPADFragment <<
endmsg;
930 msg(MSG::VERBOSE) <<
" calling pushword: " << MSG::hex << currentWord << MSG::dec <<
endmsg;
945 matrixROS = matrix->getHeader();
946 uint16_t cmaId = matrixROS.
cmid();
947 uint16_t fel1id = matrixROS.
fel1id();
949 matrixROS = matrix->getSubHeader();
950 uint16_t febcid = matrixROS.
febcid();
952 if (msgLvl(MSG::VERBOSE))
953 msg(MSG::VERBOSE) <<
"Creating a new CM, cmaId=" << cmaId <<
" fel1id=" << fel1id <<
" febcid=" << febcid
959 matrixROS = matrix->getFooter();
965 for (
int i = 0; i < matrix->numberOfBodyWords(); ++i) {
966 matrixROS = matrix->getCMAHit(i);
968 uint16_t bcid = matrixROS.
bcid();
969 uint16_t time = matrixROS.
time();
970 uint16_t ijk = matrixROS.
ijk();
975 uint16_t channel = matrixROS.
channel();
979 <<
" ijk=" << ijk <<
" channel=" << channel);
983 }
else if (ijk == 7) {
984 uint16_t overlap = matrixROS.
overlap();
989 <<
" ijk=" << ijk <<
" overlap=" << overlap
997 v.push_back(coinMatrix);
1008 return StatusCode::SUCCESS;
1016 bool skipSectorLogicDecoding = (sectorLogicContainer ==
nullptr);
1017 if (skipSectorLogicDecoding)
ATH_MSG_DEBUG(
"Skip SectorLogic decoding, so SLROC.decodeFragment is not being processed");
1020 if (msgLvl(MSG::VERBOSE)) {
1021 msg(MSG::VERBOSE) <<
"**********Decoder dumping the words******** " <<
endmsg;
1022 if (data_size > 0) {
1023 msg(MSG::VERBOSE) <<
"The size of this ROD-read is " << data_size <<
endmsg;
1024 for (
unsigned int i = 0; i < data_size; i++)
1025 msg(MSG::VERBOSE) <<
"word " << i <<
" = " << MSG::hex <<
data[i] << MSG::dec <<
endmsg;
1030 uint16_t side = (subDetector == eformat::MUON_RPC_BARREL_A_SIDE) ? 1 : 0;
1033 uint16_t sector = 0;
1036 uint16_t SLindex = 0;
1043 bool foundPad =
false;
1045 bool isSLHeader =
false;
1046 bool isSLFooter =
false;
1047 bool isSLFragment =
false;
1048 bool isRXHeader =
false;
1049 bool isRXFooter =
false;
1050 bool isPADFragment =
false;
1051 bool isPadHeader =
false;
1052 bool isPadSubHeader =
false;
1053 bool isPadPreFooter =
false;
1054 bool isPadFooter =
false;
1065 unsigned short int PadID = 99;
1066 unsigned int SLBodyWords = 0;
1067 unsigned int SL_data_size = 500;
1068 unsigned short int SLBuff[500];
1070 std::unique_ptr<RpcSectorLogic> sl{};
1072 for (uint16_t i = 0; i < data_size; ++i) {
1077 isPadHeader =
false;
1078 isPadSubHeader =
false;
1079 isPadPreFooter =
false;
1080 isPadFooter =
false;
1083 uint32_t currentWord =
data[i];
1086 ATH_MSG_VERBOSE(
" -->current data word is " << std::hex << currentWord << std::dec);
1093 if (RXROS.
isHeader() && !isSLFragment)
1095 else if (RXROS.
isFooter() && !isSLFragment)
1097 else if (PDROS.
isHeader() && !isSLFragment)
1100 isPadSubHeader =
true;
1102 isPadPreFooter =
true;
1103 else if (PDROS.
isFooter() && !isSLFragment)
1111 if (skipSectorLogicDecoding) {
1113 isSLFragment =
false;
1118 if (msgLvl(MSG::VERBOSE)) {
1119 msg(MSG::VERBOSE) <<
" RX Header: " << isRXHeader <<
" RX Footer: " << isRXFooter <<
endmsg;
1120 msg(MSG::VERBOSE) <<
" Pad Header: " << isPadHeader <<
" Pad SubHeader: " << isPadSubHeader
1121 <<
" Pad PreFooter: " << isPadPreFooter <<
" Pad Footer: " << isPadFooter <<
endmsg;
1122 msg(MSG::VERBOSE) <<
" isPADFragment: " << isPADFragment <<
endmsg;
1123 msg(MSG::VERBOSE) <<
" SL Header: " << isSLHeader <<
" SL Footer: " << isSLFooter <<
endmsg;
1124 msg(MSG::VERBOSE) <<
" isSLFragment: " << isSLFragment <<
endmsg;
1130 if (msgLvl(MSG::VERBOSE)) {
1131 msg(MSG::VERBOSE) <<
" this is a RX Header " <<
endmsg;
1132 msg(MSG::VERBOSE) <<
" Sector ID=" << RXROS.
RXid() <<
endmsg;
1146 if (sectorLogicContainer && !sectorLogicContainer->
findSector(sector, 0)) {
1148 sl = std::make_unique<RpcSectorLogic>(sector, 0, 0, errorCode);
1150 }
else if (sectorLogicContainer) {
1153 if ((*itSL)->sectorId() == sector) {
1160 }
else if (isRXFooter) {
1162 if (msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
" this is a RX Footer " <<
endmsg;
1164 }
else if (isSLHeader || isSLFragment) {
1165 isSLFooter ? isSLFragment = false : isSLFragment =
true;
1173 if (msgLvl(MSG::VERBOSE)) {
1180 if (isSLHeader) SLBodyWords = 0;
1183 else if (isSLFooter) {
1185 if (SLindex > 1) {
msg(MSG::ERROR) <<
"More than 2 SL fragments in sector " << sector <<
endmsg; }
1189 msg(MSG::VERBOSE) <<
" Number of data words in SectorLogicReadOut= " << SLBodyWords <<
endmsg;
1190 msg(MSG::VERBOSE) <<
" TEST SL: " << foundSL <<
endmsg;
1195 for (
unsigned short j = 0; j < SLBodyWords; j++) {
1196 msg(MSG::VERBOSE) <<
" SL data word " << j <<
" : " << std::hex << SLBuff[j] << MSG::dec <<
endmsg;
1204 if (sectorLogicContainer && !sectorLogicContainer->
findSector(sector, SLindex)) {
1207 uint16_t nSLlink = 2;
1208 uint16_t nSLgate = 7;
1211 for (
int igate = 0; igate < nSLgate; ++igate) {
1212 for (
int ilink = 0; ilink < nSLlink; ++ilink) {
1213 uint16_t ptid = sectorLogic->
ptid(ilink, igate);
1216 uint16_t cmadd = sectorLogic->
cmadd(ilink, igate);
1218 uint16_t bcid = igate;
1219 uint16_t tower = ilink + 2 * SLindex;
1221 uint16_t opl = sectorLogic->
opl(ilink, igate);
1222 uint16_t ovphi = sectorLogic->
ovphi(ilink, igate);
1223 uint16_t oveta = sectorLogic->
oveta(ilink, igate);
1225 uint16_t triggerBcid = sectorLogic->
bcid(ilink, igate);
1229 sl->push_back(slHit);
1238 if (SLindex == 0) { sl->addTriggerRate(sectorLogic->
padTriggerRate(1)); }
1243 for (
int icount = 0; icount < nSLcount; ++icount) {
1245 sl->addCounter(counter);
1251 if (SLindex == 0 && sectorLogicContainer) { sectorLogicContainer->
push_back(std::move(sl)); }
1258 if (SLBodyWords >= SL_data_size) {
1259 if (msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"Sector Logic payload corrupted" <<
endmsg;
1260 return StatusCode::FAILURE;
1262 SLBuff[SLBodyWords] = currentWord;
1266 }
else if (isPadHeader || isPADFragment) {
1269 msg(MSG::VERBOSE) <<
" Pad Header or Pad Fragment " <<
endmsg;
1274 if (recField ==
'H') {
1275 PadID = PDROS.
padid();
1277 uint16_t status = 0;
1279 side = (sector < 32) ? 0 : 1;
1280 uint16_t sectorLogic = sector - side * 32;
1282 msg(MSG::VERBOSE) <<
" Pad Identifier= " << PadID <<
" Status: " << status <<
endmsg;
1289 if (!rpcCabling->
giveOfflineId(side, sectorLogic, PadID, padOfflineId)) {
1290 if (msgLvl(MSG::VERBOSE))
1291 msg(MSG::VERBOSE) <<
"Cannot retrieve the OfflineID for the PAD n. " << PadID <<
" at side " << side
1292 <<
" and sector " << sectorLogic <<
endmsg;
1293 }
else if (msgLvl(MSG::VERBOSE))
1294 msg(MSG::VERBOSE) <<
"ID " <<
m_idHelperSvc->rpcIdHelper().show_to_string(padOfflineId) <<
" associated to PAD n. "
1295 << PadID <<
" at side " << side <<
" and sector " << sectorLogic <<
endmsg;
1298 if (thisPadOfflineId == padOfflineId) {
1299 if (msgLvl(MSG::VERBOSE))
1300 msg(MSG::VERBOSE) <<
" match found with ID " <<
m_idHelperSvc->rpcIdHelper().show_to_string(thisPadOfflineId)
1301 <<
" requested for the conversion; return this collection" <<
endmsg;
1305 msg(MSG::VERBOSE) <<
"Found the pad to convert !" <<
endmsg;
1307 v.setOnlineId(PadID);
1308 v.setStatus(status);
1309 v.setSector(sector);
1312 v.setLvl1Id(PDROS.
l1id());
1315 if (msgLvl(MSG::VERBOSE))
1316 msg(MSG::VERBOSE) <<
" match NOT found with ID "
1317 <<
m_idHelperSvc->rpcIdHelper().show_to_string(thisPadOfflineId)
1318 <<
" requested for the conversion" <<
endmsg;
1323 if (recField ==
'S') {
1325 v.setBcId(PDROS.
bcid());
1327 msg(MSG::VERBOSE) <<
"Found the subheader, setting bcid to: " << PDROS.
bcid() <<
endmsg;
1332 if (recField ==
'F') {
1334 msg(MSG::VERBOSE) <<
" Pad Footer " <<
endmsg;
1339 return StatusCode::SUCCESS;
1343 isPadFooter ? isPADFragment = false : isPADFragment =
true;
1346 msg(MSG::VERBOSE) <<
" current word " << std::hex << currentWord << MSG::dec <<
endmsg;
1348 msg(MSG::VERBOSE) <<
" ==isPADFragment= " << isPADFragment <<
endmsg;
1349 msg(MSG::VERBOSE) <<
" calling pushword: " << std::hex << currentWord << MSG::dec <<
endmsg;
1365 matrixROS = matrix->getHeader();
1366 uint16_t cmaId = matrixROS.
cmid();
1367 uint16_t fel1id = matrixROS.
fel1id();
1369 matrixROS = matrix->getSubHeader();
1370 uint16_t febcid = matrixROS.
febcid();
1373 msg(MSG::VERBOSE) <<
"Creating a new CM, cmaId=" << cmaId <<
" fel1id=" << fel1id <<
" febcid=" << febcid <<
endmsg;
1382 for (
int i = 0; i < matrix->numberOfBodyWords(); ++i) {
1383 matrixROS = matrix->getCMAHit(i);
1385 uint16_t bcid = matrixROS.
bcid();
1386 uint16_t time = matrixROS.
time();
1387 uint16_t ijk = matrixROS.
ijk();
1392 uint16_t channel = matrixROS.
channel();
1395 msg(MSG::VERBOSE) <<
"Adding a fired channel, bcid=" << bcid <<
" time="
1396 <<
" ijk=" << ijk <<
" channel=" << channel <<
endmsg;
1400 }
else if (ijk == 7) {
1401 uint16_t overlap = matrixROS.
overlap();
1405 msg(MSG::VERBOSE) <<
"Adding a fired channel, bcid=" << bcid <<
" time="
1406 <<
" ijk=" << ijk <<
" overlap=" << overlap <<
" threshold=" <<
threshold <<
endmsg;
1413 v.push_back(coinMatrix);
1423 return StatusCode::SUCCESS;
1430 const int rodHeader = 8;
1431 const int rodFooter = 3;
1432 bool printMessage =
true;
1446 if (msgLvl(MSG::VERBOSE))
1447 msg(MSG::VERBOSE) <<
"The offline ID request for conversion is "
1452 std::vector<uint16_t> v16 =
get16bits(
data, data_size, rodHeader, rodFooter);
1454 int word16Count = 0;
1455 int size16 = v16.size();
1457 assert(size16 > 0 && size16 == (
int)(2 * (data_size - rodHeader - rodFooter)));
1474 if (msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"subDetectorID = 0x" << MSG::hex << subDetectorID << MSG::dec <<
endmsg;
1476 uint16_t side = (subDetectorID == eformat::MUON_RPC_BARREL_A_SIDE) ? 0 : 1;
1479 if (msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"rodID = 0x" << MSG::hex << rodId << MSG::dec <<
endmsg;
1481 assert(rodId <= 15);
1484 char rxHeader =
'U';
1485 if (!
ensure_more_data(word16Count, size16,
msg(), printMessage,
"start of data"))
return StatusCode::FAILURE;
1486 uint16_t receiverHeaderFragment = v16[word16Count];
1488 if (rxHeader ==
'H') {
1490 if (msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"Found a receiver header " <<
endmsg;
1491 }
else if (msgLvl(MSG::VERBOSE))
1492 msg(MSG::VERBOSE) <<
"RpcROD_Decoder::ERROR : Expecting a receiver header "
1494 <<
" Fragment ID is " << MSG::hex << rxHeader << MSG::dec <<
endmsg;
1496 while (rxHeader ==
'H' && word16Count < size16) {
1497 if (msgLvl(MSG::VERBOSE))
1498 msg(MSG::VERBOSE) <<
"The receiver header word is " << MSG::hex << receiverHeaderFragment << MSG::dec <<
endmsg;
1499 uint16_t slogic = 2 * rodId + rxReadout.
RXid();
1500 uint16_t sectorID = side * 32 + slogic;
1501 assert(slogic <= 31);
1502 char padHeader =
'U';
1503 uint16_t padHeaderFragment = v16[word16Count];
1505 if (padHeader ==
'H') {
1507 if (msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"Found a pad header " <<
endmsg;
1508 }
else if (msgLvl(MSG::VERBOSE))
1509 msg(MSG::VERBOSE) <<
"Rpc_ROD_Decoder::ERROR : Expecting a pad header "
1510 <<
" Fragment ID is " << padHeader <<
endmsg;
1512 while (padHeader ==
'H') {
1513 uint16_t padId = padReadout.
padid();
1515 uint16_t status = 0;
1521 if (!rpcCabling->
giveOfflineId(side, slogic, padId, padOfflineId)) {
1522 if (msgLvl(MSG::VERBOSE))
1523 msg(MSG::VERBOSE) <<
"Cannot retrieve the OfflineID for the PAD n. " << padId <<
" at side " << side
1524 <<
" and sector " << slogic <<
endmsg;
1525 }
else if (msgLvl(MSG::VERBOSE))
1526 msg(MSG::VERBOSE) <<
"ID " <<
m_idHelperSvc->rpcIdHelper().show_to_string(padOfflineId) <<
" associated to PAD n. "
1527 << padId <<
" at side " << side <<
" and sector " << slogic <<
endmsg;
1534 if (thisPadOfflineId == padOfflineId) {
1535 if (msgLvl(MSG::VERBOSE))
1536 msg(MSG::VERBOSE) <<
"Found the collection to return "
1538 v.setOnlineId(padId);
1539 v.setStatus(status);
1540 v.setSector(sectorID);
1542 if (msgLvl(MSG::VERBOSE))
1543 msg(MSG::VERBOSE) <<
m_idHelperSvc->rpcIdHelper().show_to_string(thisPadOfflineId)
1546 char cmaHeader =
'U';
1548 uint16_t cmaHeaderFragment = v16[word16Count];
1550 if (cmaHeader ==
'H') {
1552 if (msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"Found a cma header" <<
endmsg;
1553 }
else if (msgLvl(MSG::VERBOSE))
1554 msg(MSG::VERBOSE) <<
"RpcROD_Decoder::ERROR : Expecting a cma header"
1555 <<
" Fragment ID is " << cmaHeader <<
endmsg;
1557 while (cmaHeader ==
'H') {
1558 uint16_t cmaId = matrixReadout.
cmid();
1559 uint16_t fel1id = matrixReadout.
fel1id();
1560 char cmaSubHeader =
'U';
1561 uint16_t febcid =
static_cast<uint16_t
>(-1);
1563 uint16_t cmaSubHeaderFragment = v16[word16Count];
1564 matrixReadout.
decodeFragment(cmaSubHeaderFragment, cmaSubHeader);
1565 if (cmaSubHeader ==
'S') {
1566 febcid = matrixReadout.
febcid();
1568 if (msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"Found a cma sub-header" <<
endmsg;
1569 }
else if (msgLvl(MSG::VERBOSE))
1570 msg(MSG::VERBOSE) <<
"RpcROD_Decoder::ERROR : Expecting a cma sub-header"
1571 <<
" Fragment ID is " << cmaSubHeader <<
endmsg;
1576 uint16_t cmaBodyFragment = v16[word16Count];
1578 if (cmaBody ==
'B') {
1580 if (msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"Found a cma body " << MSG::hex << cmaBodyFragment <<
endmsg;
1581 }
else if (msgLvl(MSG::VERBOSE))
1582 msg(MSG::VERBOSE) <<
"Expecting cma body"
1583 <<
" Fragment ID is " << cmaBody <<
endmsg;
1584 while (cmaBody ==
'B') {
1585 uint16_t bcid = matrixReadout.
bcid();
1586 uint16_t time = matrixReadout.
time();
1587 uint16_t ijk = matrixReadout.
ijk();
1591 uint16_t channel = matrixReadout.
channel();
1594 }
else if (ijk == 7) {
1596 uint16_t overlap = matrixReadout.
overlap();
1600 if (msgLvl(MSG::VERBOSE))
1601 msg(MSG::VERBOSE) <<
"RpcROD_Decoder::ERROR : Wrong ijk value " << ijk <<
"in cma body " <<
endmsg;
1608 cmaBodyFragment = v16[word16Count];
1610 if (cmaBody ==
'B') {
1612 if (msgLvl(MSG::VERBOSE))
1613 msg(MSG::VERBOSE) <<
"Found a cma body"
1614 <<
" " << MSG::hex << cmaBodyFragment << MSG::dec <<
endmsg;
1616 ATH_MSG_VERBOSE(
" No more body fragment found " << cmaBody <<
" " << MSG::hex << cmaBodyFragment << MSG::dec);
1617 if (msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"End of a cma body" <<
endmsg;
1619 char cmaFooter =
'U';
1625 uint16_t cmaFooterFragment = v16[word16Count];
1627 if (cmaFooter ==
'F') {
1628 uint16_t crc = matrixReadout.
crc();
1632 ATH_MSG_ERROR(
"Trying to call null coinMatrix - this should never happen!");
1634 if (msgLvl(MSG::VERBOSE))
1635 msg(MSG::VERBOSE) <<
"Found a cma Footer " << MSG::hex << cmaFooterFragment << MSG::dec <<
endmsg;
1637 if (msgLvl(MSG::VERBOSE))
1638 msg(MSG::VERBOSE) <<
"RpcROD_Decoder::ERROR : Expecting a cma Footer"
1639 <<
" Fragment ID is " << cmaFooter <<
" " << MSG::hex << cmaFooterFragment << MSG::dec
1643 if (thisPadOfflineId == padOfflineId)
1644 v.push_back(coinMatrix);
1649 cmaHeaderFragment = v16[word16Count];
1651 if (cmaHeader ==
'H') {
1653 if (msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"Found a cma header" <<
endmsg;
1654 }
else if (msgLvl(MSG::VERBOSE))
1655 msg(MSG::VERBOSE) <<
"End of all CMAs" <<
endmsg;
1657 char padFooter =
'U';
1658 uint16_t errorCode =
static_cast<uint16_t
>(-1);
1660 uint16_t padFooterFragment = v16[word16Count];
1662 if (padFooter ==
'F') {
1665 if (msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"Found a pad footer " <<
endmsg;
1666 if (thisPadOfflineId == padOfflineId) {
1667 v.setErrorCode(errorCode);
1669 return StatusCode::FAILURE;
1671 }
else if (msgLvl(MSG::VERBOSE))
1672 msg(MSG::VERBOSE) <<
"RpcROD_Decoder::ERROR : Expecting a pad footer "
1673 <<
" Fragment ID is " << padFooter <<
" " << MSG::hex << padFooterFragment << MSG::dec <<
endmsg;
1675 padHeaderFragment = v16[word16Count];
1677 if (padHeader ==
'H') {
1679 if (msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"Found a pad header " <<
endmsg;
1680 }
else if (msgLvl(MSG::VERBOSE))
1681 msg(MSG::VERBOSE) <<
"End of all pads " <<
endmsg;
1684 char rxFooter =
'U';
1686 uint16_t receiverFooterFragment = v16[word16Count];
1688 if (rxFooter ==
'F') {
1690 if (msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"Found a receiver footer " <<
endmsg;
1691 }
else if (msgLvl(MSG::VERBOSE))
1692 msg(MSG::VERBOSE) <<
"RpcROD_Decoder::ERROR : Expecting a receiver footer "
1693 <<
" Fragment ID is " << rxFooter <<
" " << MSG::hex << receiverFooterFragment << MSG::dec <<
endmsg;
1695 if (word16Count < size16) {
1696 receiverHeaderFragment = v16[word16Count];
1698 if (rxHeader ==
'H') {
1700 if (msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"Found a receiver header " <<
endmsg;
1701 }
else if (msgLvl(MSG::VERBOSE))
1702 msg(MSG::VERBOSE) <<
"End of all receivers " <<
endmsg;
1709 return StatusCode::FAILURE;
1713 uint32_t mask = 0x0000FFFF;
1714 uint32_t pos[2] = {16, 0};
1716 std::vector<uint16_t>
result;
1718 for (
int i = nHeader; i < (size - nFooter); i++) {
1719 for (uint32_t j = 0; j < 2; j++) {
1720 uint32_t vshift = v32[i] >> pos[j];
1721 uint16_t fragment = (uint16_t)(vshift & mask);
1722 result.push_back(fragment);
1729 uint32_t mask = 0x0000FFFF;
1730 uint32_t pos[2] = {0, 16};
1732 std::vector<uint16_t>
result;
1734 for (
int i = nHeader; i < (size - nFooter); i++) {
1735 for (uint32_t j = 0; j < 2; j++) {
1736 uint32_t vshift = v32[i] >> pos[j];
1737 uint16_t fragment = (uint16_t)(vshift & mask);
1738 result.push_back(fragment);
#define ATH_MSG_VERBOSE(x)
char data[hepevt_bytes_allocation_ATLAS]
Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Current RpcCoinMatrix
Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Current Athena::TPCnvVers::Current RpcPad
unsigned short int ubit16
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DataModel_detail::iterator< DataVector > iterator
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
StatusCode addOrDelete(std::unique_ptr< T > ptr)
IDC_WriteHandle getWriteHandle(IdentifierHash hash)
virtual bool tryAddFromCache(IdentifierHash hashId) override final
Looks in the cache to see if item already exists if not it returns false, If it does exist it incorpo...
This is a "hash" representation of an Identifier.
ubit16 decodeFragment(ubit16 inputWord, char &field)
SG::ReadCondHandleKey< RpcCablingCondData > m_rpcReadKey
virtual StatusCode initialize() override
StatusCode fillCollection_v300(BS data, const uint32_t data_size, RpcPad &v, const uint16_t &subDetector, RpcSectorLogicContainer *) const
fill RpcPads from a block of integers New version for data format 3.0 (ATLAS cosmics)
bool isSector13Data() const
std::vector< uint16_t > get16bits(BS data, const int size, const int nHeader, const int nFooter) const
IntegerProperty m_specialROBNumber
StatusCode fillCollections(const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment &robFrag, RpcPadContainer &rdoIdc, const std::vector< IdentifierHash > &collections, RpcSectorLogicContainer *, const bool &decodeSL) const override
StatusCode fillCollection_v240(BS data, const uint32_t data_size, RpcPad &v) const
fill RpcPads from a block of integers Decode collection for old data format 2.4.0
Gaudi::Property< int > m_nobxs
virtual ~RpcROD_Decoder()=default
StatusCode fillCollectionsFromRob_v302(BS data, const uint32_t data_size, std::map< Identifier, RpcPad * > &vmap, const uint32_t &sourceId, RpcSectorLogicContainer *, const bool &decodeSL) const
RpcROD_Decoder(const std::string &type, const std::string &name, const IInterface *p)
OFFLINE_FRAGMENTS_NAMESPACE::PointerType BS
std::vector< uint16_t > get16bits_v301(BS data, const int size, const int nHeader, const int nFooter) const
BooleanProperty m_sector13Data
IntegerProperty m_maxprinterror
virtual StatusCode finalize() override
std::atomic_int m_RPCcheckfail[13]
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
StatusCode fillCollection_v302(BS data, const uint32_t data_size, RpcPad &v, const uint32_t &sourceId, RpcSectorLogicContainer *) const
fill RpcPads from a block of integers New version for data format 3.1 (ATLAS cosmics - NEW RPC READOU...
StatusCode checkdataformat(std::vector< uint16_t > *, int, int) const
int specialROBNumber() const
StatusCode fillCollection_v302new(BS data, const uint32_t data_size, RpcPad &v, const uint32_t &sourceId, RpcSectorLogicContainer *, const bool &) const
void printcheckformat() const
ubit16 decodeFragment(ubit16 inputWord, char &field)
MatrixReadOut * CMFragment()
SectorLogicReadOut * SLFragment()
int pushWord(const ubit16 inword, uint NOBXS)
ubit16 getSourceIDSubdetectorID()
ubit16 getSourceIDRODID()
void decodeSourceID(RODword sourceID)
int pushWord(const ubit16 inword, uint NOBXS)
MatrixReadOut * CMFragment()
SectorLogicRXReadOut * SLFragment()
ubit16 decodeFragment(ubit16 inputWord, char &field)
bool giveOfflineId(const unsigned short int side, const unsigned short int sector, const unsigned short int padId, Identifier &id) const
Identifier identifier(int i) const
Use IdentifiableContainer with RpcPad.
Identifier identify() const
void setIsInput(bool isInput)
bool setSector(uint16_t sectorId, const uint16_t side=0)
Flag the sector as already decoded.
bool findSector(const uint16_t sectorId, const uint16_t side=0) const
Check if the sector has already been decoded.
void setHasMoreThan2TriggerCand(const bool a)
ubit16 outputOverlap(int nCand) const
ubit16 decodeFragment(ubit16 inputWord, char &field)
ubit16 outputTriggerBcid(int) const
ubit16 outputThreshold(int nCand) const
ubit16 inputTriggerBcid() const
ubit16 outputRowinBcid() const
ubit16 nTriggerCand() const
ubit16 hasMoreThan2TriggerCand() const
ubit16 outputRoi(int nCand) const
ubit16 inputPadId() const
ubit16 inputOverlapPhi() const
ubit16 inputOverlapEta() const
ubit16 inputThreshold() const
ubit16 inputRowinBcid() const
ubit16 inputOuterPlane() const
uint16_t numberOfInputWords()
uint16_t readSLHitCurrent()
ubit16 decodeFragment(ubit16 inputWord, char &field)
ubit16 ptid(ubit16 indexLink, ubit16 indexGate)
ubit16 oveta(ubit16 indexLink, ubit16 indexGate)
ubit16 opl(ubit16 indexLink, ubit16 indexGate)
ubit16 ovphi(ubit16 indexLink, ubit16 indexGate)
ubit16 numberOfCounterWords()
float padTriggerRate(ubit16 padAddress)
ubit16 cmadd(ubit16 indexLink, ubit16 indexGate)
ubit16 bcid(ubit16 indexLink, ubit16 indexGate)
ubit16 readSLCounterCurrent()
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
bool ensure_more_data(int index, int size, MsgStream &log, bool &printMessage, const std::string &message)
const DataType * PointerType
eformat::ROBFragment< PointerType > ROBFragment