21 const IInterface*
parent) :
52 if (element->swapPhiReadoutDirection()) {
57 return StatusCode::SUCCESS;
137 ATH_MSG_INFO(
"SCT BytestreamCnv summary: unknown data-> "
142 ATH_MSG_INFO(
"SCT BytestreamCnv summary: ROD status word-> "
146 ATH_MSG_INFO(
"SCT BytestreamCnv summary: ROB status word-> "
150 ATH_MSG_INFO(
"SCT BytestreamCnv summary: ROB status word-> "
162 return StatusCode::SUCCESS;
171 const EventContext& ctx,
172 const std::vector<IdentifierHash>* vecHash)
const
176 const uint32_t robID{robFrag.rod_source_id()};
179 const uint32_t rodDataType{robFrag.rod_detev_type()};
180 const bool rodSimulatedData{
static_cast<bool>((rodDataType >> 20) & 0
x1)};
181 if (rodSimulatedData)
ATH_CHECK(
addRODError(robID, SCT_ByteStreamErrors::RODSimulatedData, errs));
184 const bool superCondensedMode{
static_cast<bool>((rodDataType >> 21) & 0
x1)};
189 if (robFrag.nstatus()!=0) {
191 robFrag.status(robStatus);
192 if ((*robStatus)!=0) {
193 ATH_MSG_DEBUG(
"ROB status word for robID " << std::hex << robID
194 <<
" is non-zero " << (*robStatus) << std::dec);
197 sc = StatusCode::RECOVERABLE;
199 if (((*robStatus) >> 27) & 0
x1) {
200 ATH_MSG_DEBUG(
"ROB status word for robID " << std::hex << robID
201 << std::dec <<
" indicates data truncation.");
206 if ((((*robStatus) >> 29) & 0
x1) or (((*robStatus) >> 31) & 0
x1)) {
207 ATH_MSG_DEBUG(
"ROB status word for robID " << std::hex << robID
208 << std::dec <<
" indicates resource was masked off.");
218 const long unsigned int vecRODStatusSize{robFrag.rod_nstatus()};
220 robFrag.rod_status(vecRODStatus);
221 for (
long unsigned int i{0};
i<vecRODStatusSize;
i++) {
222 const uint32_t statusWord{vecRODStatus[
i]};
225 const int timClockError{
static_cast<int>((statusWord >> 16) & 0
x1)};
226 const int bocClockError{
static_cast<int>((statusWord >> 17) & 0
x1)};
227 if (timClockError or bocClockError) {
228 ATH_MSG_DEBUG(
" Clock error in ROD status word: " << timClockError <<
" " << bocClockError);
231 sc=StatusCode::RECOVERABLE;
246 const unsigned long int vecROBDataSize{robFrag.rod_ndata()};
247 if (vecROBDataSize > robFrag.payload_size_word()) {
248 ATH_MSG_WARNING(
"The ROB data does not seem to fit in the payload. Rejecting fragment (ndata size " << vecROBDataSize <<
" !< payload size " << robFrag.payload_size_word()
249 <<
" header size: " << robFrag.rod_header_size_word()
250 <<
" trailer size: " << robFrag.rod_trailer_size_word()
251 <<
" fragment size: " << robFrag.rod_fragment_size_word()
253 return StatusCode::RECOVERABLE;
255 robFrag.rod_data(vecROBData);
258 for (
unsigned long int i{0};
i<vecROBDataSize;
i++) {
261 data16[0] = ((vecROBData[
i] >> 16) & 0xFFFF);
262 data16[1] = ( vecROBData[
i] & 0xFFFF);
264 for (
int n{0};
n<2;
n++) {
265 bool hasError{
false};
266 if (((data16[
n]>>13) & 0x7) == 0
x1) {
267 bool breakNow{
false};
269 if (hasError)
sc = StatusCode::RECOVERABLE;
273 else if (data16[
n] & 0x8000) {
274 if (not
data.foundHeader) {
275 ATH_MSG_INFO(
" Missing link header in ROD " << std::hex << robID << std::dec);
276 data.foundMissingLinkHeaderError =
true;
278 sc = StatusCode::RECOVERABLE;
282 if (superCondensedMode) {
284 if (hasError)
sc = StatusCode::RECOVERABLE;
287 else if (
data.condensedMode) {
289 if (hasError)
sc = StatusCode::RECOVERABLE;
294 if (hasError)
sc = StatusCode::RECOVERABLE;
298 else if (((data16[
n]>>13) & 0x7) == 0x0) {
300 if (hasError)
sc = StatusCode::RECOVERABLE;
303 else if (((data16[
n]>>13) & 0x7) == 0x3) {
305 if (hasError)
sc = StatusCode::RECOVERABLE;
308 else if (((data16[
n]>>13) & 0x7) == 0
x2) {
310 if (hasError)
sc = StatusCode::RECOVERABLE;
317 sc = StatusCode::RECOVERABLE;
323 if (
data.isStripValid()) {
324 if (not
data.isSaved(
false) and
data.isOldStripValid()) {
325 const int rdoMade{
makeRDO(
false,
data, cache, dataItemsPool)};
327 sc = StatusCode::RECOVERABLE;
331 data.setSaved(
false, rdoMade);
338 if (
data.foundMissingLinkHeaderError) {
342 for (
auto& [
hash, rdoColl] :
data.rdoCollMap) {
343 if (rdoColl==
nullptr)
continue;
345 if (rdoColl->empty()) {
347 errs.removeIfEmpty(
hash);
354 if (
sc.isFailure())
ATH_MSG_DEBUG(
"One or more ByteStream errors found ");
367 if (rdoColl==
nullptr)
return 0;
372 <<
" in collection " <<
data.linkIDHash <<
" out of range. Will not make RDO");
385 std::vector<IdentifierHash>::const_iterator hashIDIterator{
find(cache.
vecHash->begin(),
388 if (hashIDIterator == cache.
vecHash->end()) {
410 const unsigned int rawDataWord{
static_cast<unsigned int>(
data.groupSize | (
strip << 11) | (
data.timeBin <<22) | (
data.errors << 25))};
412 ATH_MSG_DEBUG(
"Output Raw Data " << std::hex <<
" Coll " <<
data.collID.getString()
421 rdoColl->push_back(sct_rdo);
423 rdoColl->push_back(std::make_unique<SCT3_RawData>(digitID, rawDataWord, &(
data.errorHit)));
432 const std::unordered_set<IdentifierHash>* foundHashes)
const
434 std::vector<IdentifierHash> hashIDs;
435 m_cabling->getHashesForRod(hashIDs, rodID);
439 if ((
error==SCT_ByteStreamErrors::MissingLinkHeaderError) and
440 foundHashes and foundHashes->count(
hash)) {
452 const bool result{
side==0 ? not link0Good : not link1Good};
457 return StatusCode::SUCCESS;
467 ATH_MSG_INFO(
"addSingleError hashID " << hashID <<
" is invalid.");
468 return StatusCode::SUCCESS;
473 if ((error<SCT_ByteStreamErrors::ABCDError_Chip0 || error>SCT_ByteStreamErrors::ABCDError_Chip5) and
474 (error<SCT_ByteStreamErrors::TempMaskedChip0 || error>SCT_ByteStreamErrors::TempMaskedChip5)) {
475 std::pair<bool, bool> badLinks{
m_configTool->badLinks(hashID)};
477 bool result{(
side==0 ? badLinks.first : badLinks.second) and (badLinks.first xor badLinks.second)};
484 ATH_MSG_DEBUG(
"Adding error to side " << 1-
side <<
" for module with RX redundancy " << otherSide);
488 return StatusCode::SUCCESS;
494 unsigned int firstTempMaskedChip,
498 ATH_MSG_INFO(
"setFirstTempMaskedChip hashID " << hashID <<
" is invalid.");
499 return StatusCode::RECOVERABLE;
501 if (firstTempMaskedChip==0) {
502 ATH_MSG_WARNING(
"setFirstTempMaskedChip: firstTempMaskedChip should be greater than 0. firstTempMaskedChip is "
503 << firstTempMaskedChip);
504 return StatusCode::RECOVERABLE;
514 unsigned int firstTempMaskedChipSide0{0};
515 if (hashID==hashSide0) firstTempMaskedChipSide0 = firstTempMaskedChip;
520 unsigned int firstTempMaskedChipSide1{0};
521 if (hashID==hashSide1) firstTempMaskedChipSide1 = firstTempMaskedChip;
525 const std::pair<bool, bool> badLinks{
m_configTool->badLinks(hashID)};
526 if (badLinks.first xor badLinks.second) {
528 if (badLinks.first and not badLinks.second) {
532 else if (badLinks.second and not badLinks.first) {
536 else if (badLinks.first and badLinks.second) {
538 ATH_MSG_WARNING(
"setFirstTempMaskedChip: Both link-0 and link-1 are working. But Rx redundancy is used... Why?");
539 return StatusCode::RECOVERABLE;
543 ATH_MSG_WARNING(
"setFirstTempMaskedChip: Both link-0 and link-1 are broken. But data are coming... Why?");
544 return StatusCode::RECOVERABLE;
553 const unsigned long long fullSerialNumber{
m_cabling->getSerialNumberFromHash(hashID).to_ulonglong()};
555 fullSerialNumber==20220170200183 or
556 fullSerialNumber==20220330200606 or
557 fullSerialNumber==20220330200693
559 if (
type!=1)
ATH_MSG_WARNING(
"Link-0 is broken but modified module readingout link-0, inconsistent");
568 fullSerialNumber==20220170200653 or
569 fullSerialNumber==20220330200117 or
570 fullSerialNumber==20220330200209 or
571 fullSerialNumber==20220330200505 or
572 fullSerialNumber==20220330200637 or
573 fullSerialNumber==20220330200701
575 if (
type!=2)
ATH_MSG_WARNING(
"Link-1 is broken but modified module readingout link-1, inconsistent");
588 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
590 {6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5},
592 {0, 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 6},
594 {6, 7, 8, 9, 10, 11, 1, 2, 3, 4, 5, 0}
611 ( 0<firstTempMaskedChipSide1 and firstTempMaskedChipSide1<=
N_CHIPS_PER_SIDE)) {
612 const unsigned int swapFirstTempMaskedChipSide0{firstTempMaskedChipSide0};
613 firstTempMaskedChipSide0 = firstTempMaskedChipSide1;
614 firstTempMaskedChipSide1 = swapFirstTempMaskedChipSide0;
617 if (firstTempMaskedChipSide0>0) {
618 for (
unsigned int iChip{firstTempMaskedChipSide0-1}; iChip<
N_CHIPS_PER_SIDE; iChip++) {
630 bool toBeMasked{
false};
632 int jChip{chipOrder[
type][iChip]};
633 if (jChip==
static_cast<int>(firstTempMaskedChip-1)) toBeMasked =
true;
646 <<
" SerialNumber " <<
m_cabling->getSerialNumberFromHash(hashID).str()
647 <<
" moduleID " << moduleID
653 <<
" firstTempMaskedChip " << firstTempMaskedChip);
654 return StatusCode::SUCCESS;
666 const EventContext& ctx)
const
670 data.foundHeader =
true;
674 if (
data.isStripValid()) {
675 if (not
data.isSaved(
false) and
data.isOldStripValid()) {
677 const int rdoMade{
makeRDO(
false,
data, cache, dataItemsPool)};
683 data.setSaved(
false, rdoMade);
692 const int rodlinkNumber{
static_cast<int>(inData & 0x7F)};
695 data.linkNumber = (((rodlinkNumber >>4)&0x7)*12+(rodlinkNumber &0xF));
696 const uint32_t onlineID{(robID & 0xFFFFFF) | (
data.linkNumber << 24)};
698 if ((onlineID ==0) or (
data.linkNumber > 95)) {
701 ATH_MSG_DEBUG(
"Header: xxx Link number out of range (skipping following data)"
702 << std::dec <<
data.linkNumber);
708 if (
hash.is_valid()) {
712 std::stringstream
msg;
713 msg <<std::hex << onlineID;
714 ATH_MSG_WARNING(
"Rob fragment (rob=" << robID <<
") with invalid onlineID " <<
msg.str() <<
" -> " <<
hash <<
".");
718 if ((inData >> 7) & 0
x1) {
723 if (inData & 0x800) {
730 if (inData & 0x1000) {
737 if (inData & 0x400) {
744 if (inData & 0x200) {
751 if ((inData & 0xF) > 11) {
757 if (!hasError and not
hash.is_valid()) {
758 std::stringstream
msg;
759 msg <<std::hex << onlineID;
760 ATH_MSG_WARNING(
"Rob fragment (rob=" << robID <<
") with invalid onlineID " <<
msg.str() <<
" -> " <<
hash <<
".");
764 data.condensedMode =
static_cast<bool>(inData & 0x100);
777 const EventContext& ctx)
const
786 const int chip{(inData>>11) & 0x7};
787 data.side = ((inData>>14) & 0
x1);
790 const int nStripsInWord{(inData & 0xF)+1};
793 << std::hex << inData);
801 bool secondSide{
false};
802 if ((
data.side==1) and ((
data.linkNumber%2)==0)) {
805 const int rdoMade{
makeRDO(
true,
data, cache, dataItemsPool)};
811 data.setSaved(
true, rdoMade);
818 else if ((
data.side==0) and ((
data.linkNumber%2)!=0)) {
821 const int rdoMade{
makeRDO(
true,
data, cache, dataItemsPool)};
827 data.setSaved(
true, rdoMade);
835 const uint32_t onlineID{(robID & 0xFFFFFF) | (
data.linkNumber << 24)};
841 data.setCollection(
m_sctID, id_hash, rdoIDCont, dataItemsPool, errs);
844 if (
data.groupSize == 0) {
850 const int rdoMade{
makeRDO(
true,
data, cache, dataItemsPool)};
856 data.setSaved(
true, rdoMade);
860 data.groupSize += nStripsInWord;
873 const EventContext& ctx)
const
877 const int chip{(inData>>11) & 0x7};
878 data.side = ((inData>>14) & 0
x1);
883 << std::hex << inData);
891 bool secondSide{
false};
892 if ((
data.side==1) and ((
data.linkNumber%2)==0)) {
895 const int rdoMade{
makeRDO(
true,
data, cache, dataItemsPool)};
901 data.setSaved(
true, rdoMade);
908 else if ((
data.side==0) and ((
data.linkNumber%2)!=0)) {
911 const int rdoMade{
makeRDO(
true,
data, cache, dataItemsPool)};
917 data.setSaved(
true, rdoMade);
925 const uint32_t onlineID{(robID & 0xFFFFFF) | (
data.linkNumber << 24)};
926 data.setCollection(
m_sctID,
m_cabling->getHashFromOnlineId(onlineID, ctx), rdoIDCont, dataItemsPool, errs);
929 if (
data.groupSize == 0) {
933 if (not (inData & 0
x1)) {
937 const int rdoMade{
makeRDO(
true,
data, cache, dataItemsPool)};
943 data.setSaved(
true, rdoMade);
949 ATH_MSG_DEBUG(
" Hit condensed : xxx ERROR in 1-hit " << std::hex << inData);
950 data.errorHit.push_back(
data.groupSize);
955 data.groupSize = (
data.groupSize>=2 ?
data.groupSize : 1);
969 const int rdoMade{
makeRDO(
true,
data, cache, dataItemsPool)};
975 data.setSaved(
true, rdoMade);
980 ATH_MSG_DEBUG(
" Hit condensed : xxx ERROR in 1st hit" << std::hex << inData);
981 data.errorHit.push_back(
data.groupSize);
987 ATH_MSG_DEBUG(
" Hit condensed : xxx ERROR in 2nd hit" << std::hex << inData);
988 data.errorHit.push_back(
data.groupSize);
1007 const EventContext& ctx)
const
1012 if (not (inData & 0x8)) {
1014 chip = ((inData>>11) & 0x7);
1015 data.side = ((inData>>14) & 0
x1);
1017 data.timeBin = (inData & 0x7);
1027 bool secondSide{
false};
1028 if ((
data.side==1) and ((
data.linkNumber%2)==0)) {
1032 else if ((
data.side==0) and ((
data.linkNumber%2)!=0)) {
1037 const uint32_t onlineID{(robID & 0xFFFFFF) | (
data.linkNumber << 24)};
1038 data.setCollection(
m_sctID,
m_cabling->getHashFromOnlineId(onlineID, ctx), rdoIDCont, dataItemsPool, errs);
1041 const int rdoMade{
makeRDO(
false,
data, cache, dataItemsPool)};
1042 if (rdoMade == -1) {
1047 data.setSaved(
false, rdoMade);
1052 if (inData & 0x80) {
1062 data.timeBin = (inData & 0x7);
1064 const int rdoMade1{
makeRDO(
false,
data, cache, dataItemsPool)};
1065 if (rdoMade1 == -1) {
1070 data.setSaved(
false, rdoMade1);
1074 data.timeBin = ((inData >> 4) & 0x7);
1075 const int rdoMade2{
makeRDO(
false,
data, cache, dataItemsPool)};
1076 if (rdoMade2 == -1) {
1081 data.setSaved(
false, rdoMade2);
1094 data.timeBin = (inData & 0x7);
1096 const int rdoMade{
makeRDO(
false,
data, cache, dataItemsPool)};
1097 if (rdoMade == -1) {
1102 data.setSaved(
false, rdoMade);
1115 bool& hasError)
const
1119 if (not
data.foundHeader) {
1120 ATH_MSG_INFO(
" Missing link header in ROD " << std::hex << robID << std::dec);
1121 data.foundMissingLinkHeaderError =
true;
1127 const int chip{(inData>>3) & 0xF};
1128 const int abcError{inData & 0x7};
1130 <<
" Error code abcError " << abcError <<
" Link Number (or Stream) " <<
data.linkNumber);
1133 if (abcError!=0
x1 and abcError!=0
x2 and abcError!=0x4 and abcError!=0x7) {
1134 ATH_MSG_DEBUG(
"ABCD error has an invalid error code " << abcError
1135 <<
" the 16-bit word is 0x" << std::hex << inData << std::dec
1136 <<
" for hash " <<
data.linkIDHash);
1141 const unsigned int sideABCDError{
static_cast<unsigned int>(chip/8)};
1142 if (
data.linkIDHash.value()%2!=sideABCDError) {
1146 ATH_MSG_DEBUG(
"ABCD error and online ID have different side information for hash " <<
data.linkIDHash <<
". "
1147 << sideABCDError <<
" from ABCD error and " <<
data.linkIDHash.value()%2 <<
" from online ID");
1148 data.linkIDHash = (
data.linkIDHash.value()/2)*2+sideABCDError;
1153 ATH_MSG_DEBUG(
"ABCD error has an invalid chip 0x" << std::hex << chip << std::dec
1154 <<
" the 16-bit word is 0x" << std::hex << inData << std::dec
1155 <<
" for hash " <<
data.linkIDHash.value());
1181 bool& hasError)
const
1185 if (not
data.foundHeader) {
1186 ATH_MSG_INFO(
" Missing link header in ROD " << std::hex << robID << std::dec);
1187 data.foundMissingLinkHeaderError =
true;
1193 ATH_MSG_DEBUG(
" xxx Raw Data Mode " << std::hex << inData << std::dec <<
": Config Data Mode ");
1206 bool& hasError)
const
1218 data.foundHeader =
false;
1222 if (inData & 0x1000) {
1223 ATH_MSG_DEBUG(
" Trailer: xxx Trailer ERROR " << std::hex << inData);
1229 if (inData & 0x800) {
1233 ATH_MSG_DEBUG(
" Trailer: xxx Header-Trailer limit ERROR " << std::hex << inData);
1239 if (inData & 0x400) {
1241 ATH_MSG_DEBUG(
" Trailer: xxx Data Overflow ERROR " << std::hex << inData);