Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-06 23:49:39

0001 #include "EventFilter/SiPixelRawToDigi/interface/ErrorChecker.h"
0002 
0003 #include "CondFormats/SiPixelObjects/interface/SiPixelFrameConverter.h"
0004 
0005 #include "DataFormats/DetId/interface/DetId.h"
0006 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0007 #include "DataFormats/FEDRawData/interface/FEDHeader.h"
0008 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
0009 
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 
0012 #include <bitset>
0013 #include <sstream>
0014 #include <iostream>
0015 
0016 using namespace std;
0017 using namespace edm;
0018 using namespace sipixelobjects;
0019 using namespace sipixelconstants;
0020 
0021 ErrorChecker::ErrorChecker() : ErrorCheckerBase(){};
0022 
0023 bool ErrorChecker::checkROC(bool& errorsInEvent,
0024                             int fedId,
0025                             const SiPixelFrameConverter* converter,
0026                             const SiPixelFedCabling* theCablingTree,
0027                             Word32& errorWord,
0028                             SiPixelFormatterErrors& errors) const {
0029   int errorType = (errorWord >> ROC_shift) & ERROR_mask;
0030   if LIKELY (errorType < 25)
0031     return true;
0032 
0033   switch (errorType) {
0034     case (25): {
0035       CablingPathToDetUnit cablingPath = {unsigned(fedId), (errorWord >> LINK_shift) & LINK_mask, 1};
0036       if (!theCablingTree->findItem(cablingPath))
0037         return false;
0038       LogDebug("") << "  invalid ROC=25 found (errorType=25)";
0039       errorsInEvent = true;
0040       break;
0041     }
0042     case (26): {
0043       //LogDebug("")<<"  gap word found (errorType=26)";
0044       return false;
0045     }
0046     case (27): {
0047       //LogDebug("")<<"  dummy word found (errorType=27)";
0048       return false;
0049     }
0050     case (28): {
0051       LogDebug("") << "  error fifo nearly full (errorType=28)";
0052       errorsInEvent = true;
0053       break;
0054     }
0055     case (29): {
0056       LogDebug("") << "  timeout on a channel (errorType=29)";
0057       errorsInEvent = true;
0058       if ((errorWord >> OMIT_ERR_shift) & OMIT_ERR_mask) {
0059         LogDebug("") << "  ...first errorType=29 error, this gets masked out";
0060         return false;
0061       }
0062       break;
0063     }
0064     case (30): {
0065       LogDebug("") << "  TBM error trailer (errorType=30)";
0066       int StateMatch_bits = 4;
0067       int StateMatch_shift = 8;
0068       uint32_t StateMatch_mask = ~(~uint32_t(0) << StateMatch_bits);
0069       int StateMatch = (errorWord >> StateMatch_shift) & StateMatch_mask;
0070       if (StateMatch != 1 && StateMatch != 8) {
0071         LogDebug("") << " FED error 30 with unexpected State Bits (errorType=30)";
0072         return false;
0073       }
0074       if (StateMatch == 1)
0075         errorType = 40;  // 1=Overflow -> 40, 8=number of ROCs -> 30
0076       errorsInEvent = true;
0077       break;
0078     }
0079     case (31): {
0080       LogDebug("") << "  event number error (errorType=31)";
0081       errorsInEvent = true;
0082       break;
0083     }
0084     default:
0085       return true;
0086   };
0087 
0088   if (includeErrors_) {
0089     // store error
0090     SiPixelRawDataError error(errorWord, errorType, fedId);
0091     cms_uint32_t detId;
0092     detId = errorDetId(converter, errorType, errorWord);
0093     errors[detId].push_back(error);
0094   }
0095   return false;
0096 }
0097 
0098 // this function finds the detId for an error word that cannot be processed in word2digi
0099 cms_uint32_t ErrorChecker::errorDetId(const SiPixelFrameConverter* converter, int errorType, const Word32& word) const {
0100   if (!converter)
0101     return dummyDetId;
0102 
0103   ElectronicIndex cabling;
0104 
0105   switch (errorType) {
0106     case 25:
0107     case 30:
0108     case 31:
0109     case 36:
0110     case 40: {
0111       // set dummy values for cabling just to get detId from link
0112       cabling.dcol = 0;
0113       cabling.pxid = 2;
0114       cabling.roc = 1;
0115       cabling.link = (word >> LINK_shift) & LINK_mask;
0116 
0117       DetectorIndex detIdx;
0118       int status = converter->toDetector(cabling, detIdx);
0119       if (!status)
0120         return detIdx.rawId;
0121       break;
0122     }
0123     case 29: {
0124       int chanNmbr = 0;
0125       const int DB0_shift = 0;
0126       const int DB1_shift = DB0_shift + 1;
0127       const int DB2_shift = DB1_shift + 1;
0128       const int DB3_shift = DB2_shift + 1;
0129       const int DB4_shift = DB3_shift + 1;
0130       const cms_uint32_t DataBit_mask = ~(~cms_uint32_t(0) << 1);
0131 
0132       int CH1 = (word >> DB0_shift) & DataBit_mask;
0133       int CH2 = (word >> DB1_shift) & DataBit_mask;
0134       int CH3 = (word >> DB2_shift) & DataBit_mask;
0135       int CH4 = (word >> DB3_shift) & DataBit_mask;
0136       int CH5 = (word >> DB4_shift) & DataBit_mask;
0137       int BLOCK_bits = 3;
0138       int BLOCK_shift = 8;
0139       cms_uint32_t BLOCK_mask = ~(~cms_uint32_t(0) << BLOCK_bits);
0140       int BLOCK = (word >> BLOCK_shift) & BLOCK_mask;
0141       int localCH = 1 * CH1 + 2 * CH2 + 3 * CH3 + 4 * CH4 + 5 * CH5;
0142       if (BLOCK % 2 == 0)
0143         chanNmbr = (BLOCK / 2) * 9 + localCH;
0144       else
0145         chanNmbr = ((BLOCK - 1) / 2) * 9 + 4 + localCH;
0146       if ((chanNmbr < 1) || (chanNmbr > 36))
0147         break;  // signifies unexpected result
0148 
0149       // set dummy values for cabling just to get detId from link if in Barrel
0150       cabling.dcol = 0;
0151       cabling.pxid = 2;
0152       cabling.roc = 1;
0153       cabling.link = chanNmbr;
0154       DetectorIndex detIdx;
0155       int status = converter->toDetector(cabling, detIdx);
0156       if (!status)
0157         return detIdx.rawId;
0158       break;
0159     }
0160     case 37:
0161     case 38: {
0162       cabling.dcol = 0;
0163       cabling.pxid = 2;
0164       cabling.roc = (word >> ROC_shift) & ROC_mask;
0165       cabling.link = (word >> LINK_shift) & LINK_mask;
0166 
0167       DetectorIndex detIdx;
0168       int status = converter->toDetector(cabling, detIdx);
0169       if (status)
0170         break;
0171 
0172       return detIdx.rawId;
0173       break;
0174     }
0175     default:
0176       break;
0177   };
0178   return dummyDetId;
0179 }