Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:14:47

0001 #include "EventFilter/CTPPSRawToDigi/interface/RPixErrorChecker.h"
0002 
0003 #include "DataFormats/FEDRawData/interface/FEDHeader.h"
0004 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
0005 
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 
0008 using namespace edm;
0009 
0010 constexpr RPixErrorChecker::Word32 RPixErrorChecker::dummyDetId;
0011 
0012 RPixErrorChecker::RPixErrorChecker() { includeErrors_ = false; }
0013 
0014 void RPixErrorChecker::setErrorStatus(bool errorStatus) { includeErrors_ = errorStatus; }
0015 
0016 bool RPixErrorChecker::checkCRC(bool& errorsInEvent, int fedId, const Word64* trailer, Errors& errors) const {
0017   int CRC_BIT = (*trailer >> CRC_shift) & CRC_mask;
0018   if (CRC_BIT == 0)
0019     return true;
0020   errorsInEvent = true;
0021   LogDebug("CRCCheck") << "CRC check failed,  errorType = 39";
0022   if (includeErrors_) {
0023     int errorType = 39;
0024     errors[dummyDetId].emplace_back(*trailer, errorType, fedId);
0025   }
0026   return false;
0027 }
0028 
0029 bool RPixErrorChecker::checkHeader(bool& errorsInEvent, int fedId, const Word64* header, Errors& errors) const {
0030   FEDHeader fedHeader(reinterpret_cast<const unsigned char*>(header));
0031   if (!fedHeader.check())
0032     return false;
0033   if (fedHeader.sourceID() != fedId) {
0034     LogDebug("CTPPSPixelDataFormatter::interpretRawData, fedHeader.sourceID() != fedId")
0035         << ", sourceID = " << fedHeader.sourceID() << ", fedId = " << fedId << ", errorType = 32";
0036     errorsInEvent = true;
0037     if (includeErrors_) {
0038       int errorType = 32;
0039       errors[dummyDetId].emplace_back(*header, errorType, fedId);
0040     }
0041   }
0042   return fedHeader.moreHeaders();
0043 }
0044 
0045 bool RPixErrorChecker::checkTrailer(
0046     bool& errorsInEvent, int fedId, unsigned int nWords, const Word64* trailer, Errors& errors) const {
0047   FEDTrailer fedTrailer(reinterpret_cast<const unsigned char*>(trailer));
0048   if (!fedTrailer.check()) {
0049     if (includeErrors_) {
0050       int errorType = 33;
0051       errors[dummyDetId].emplace_back(*trailer, errorType, fedId);
0052     }
0053     errorsInEvent = true;
0054     LogDebug("FedTrailerCheck") << "fedTrailer.check failed, Fed: " << fedId << ", errorType = 33";
0055     return false;
0056   }
0057   if (fedTrailer.fragmentLength() != nWords) {
0058     LogDebug("FedTrailerLenght") << "fedTrailer.fragmentLength()!= nWords !! Fed: " << fedId << ", errorType = 34";
0059     errorsInEvent = true;
0060     if (includeErrors_) {
0061       int errorType = 34;
0062       errors[dummyDetId].emplace_back(*trailer, errorType, fedId);
0063     }
0064   }
0065   return fedTrailer.moreTrailers();
0066 }
0067 
0068 bool RPixErrorChecker::checkROC(
0069     bool& errorsInEvent, int fedId, uint32_t iD, const Word32& errorWord, Errors& errors) const {
0070   int errorType = (errorWord >> ROC_shift) & ERROR_mask;
0071   if LIKELY (errorType < 25)
0072     return true;
0073 
0074   switch (errorType) {
0075     case (25): {
0076       LogDebug("") << "  invalid ROC=25 found (errorType=25)";
0077       errorsInEvent = true;
0078       break;
0079     }
0080     case (26): {
0081       LogDebug("") << "  gap word found (errorType=26)";
0082       return false;
0083     }
0084     case (27): {
0085       LogDebug("") << "  dummy word found (errorType=27)";
0086       return false;
0087     }
0088     case (28): {
0089       LogDebug("") << "  error fifo nearly full (errorType=28)";
0090       errorsInEvent = true;
0091       break;
0092     }
0093     case (29): {
0094       LogDebug("") << "  timeout on a channel (errorType=29)";
0095       errorsInEvent = true;
0096       if ((errorWord >> OMIT_ERR_shift) & OMIT_ERR_mask) {
0097         LogDebug("") << "  ...first errorType=29 error, this gets masked out";
0098         return false;
0099       }
0100       break;
0101     }
0102     case (30): {
0103       LogDebug("") << "  TBM error trailer (errorType=30)";
0104       errorsInEvent = true;
0105       break;
0106     }
0107     case (31): {
0108       LogDebug("") << "  event number error (errorType=31)";
0109       errorsInEvent = true;
0110       break;
0111     }
0112     default:
0113       return true;
0114   };
0115 
0116   if (includeErrors_) {
0117     /// check to see if overflow error for type 30, change type to 40 if so
0118     if (errorType == 30) {
0119       uint32_t stateMach_bits = 4;
0120       uint32_t stateMach_shift = 8;
0121       uint32_t stateMach_mask = ~(~uint32_t(0) << stateMach_bits);
0122       uint32_t stateMach = (errorWord >> stateMach_shift) & stateMach_mask;
0123       if (stateMach == 4 || stateMach == 9)
0124         errorType = 40;
0125     }
0126 
0127     /// store error
0128     errors[iD].emplace_back(errorWord, errorType, fedId);
0129   }
0130 
0131   return false;
0132 }
0133 
0134 void RPixErrorChecker::conversionError(
0135     int fedId, uint32_t iD, const State& state, const Word32& errorWord, Errors& errors) const {
0136   int errorType = 0;
0137 
0138   switch (state) {
0139     case (InvalidLinkId): {
0140       LogDebug("ErrorChecker::conversionError") << " Fed: " << fedId << "  invalid channel Id (errorType=35)";
0141       errorType = 35;
0142       break;
0143     }
0144     case (InvalidROCId): {
0145       LogDebug("ErrorChecker::conversionError") << " Fed: " << fedId << "  invalid ROC Id (errorType=36)";
0146       errorType = 36;
0147       break;
0148     }
0149     case (InvalidPixelId): {
0150       LogDebug("ErrorChecker::conversionError") << " Fed: " << fedId << "  invalid dcol/pixel value (errorType=37)";
0151       errorType = 37;
0152       break;
0153     }
0154 
0155     default:
0156       LogDebug("ErrorChecker::conversionError") << "  cabling check returned unexpected result, status = " << state;
0157   };
0158 
0159   if (includeErrors_ && errorType > 0)
0160     errors[iD].emplace_back(errorWord, errorType, fedId);
0161 }