File indexing completed on 2024-09-07 04:36:15
0001 #include "EventFilter/SiPixelRawToDigi/interface/ErrorCheckerPhase0.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 ErrorCheckerPhase0::ErrorCheckerPhase0() : ErrorCheckerBase() {}
0022
0023 bool ErrorCheckerPhase0::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 LogDebug("") << " invalid ROC=25 found (errorType=25)";
0036 errorsInEvent = true;
0037 break;
0038 }
0039 case (26): {
0040 return false;
0041 }
0042 case (27): {
0043 return false;
0044 }
0045 case (28): {
0046 LogDebug("") << " error fifo nearly full (errorType=28)";
0047 errorsInEvent = true;
0048 break;
0049 }
0050 case (29): {
0051 LogDebug("") << " timeout on a channel (errorType=29)";
0052 errorsInEvent = true;
0053 if ((errorWord >> OMIT_ERR_shift) & OMIT_ERR_mask) {
0054 LogDebug("") << " ...first errorType=29 error, this gets masked out";
0055 return false;
0056 }
0057 break;
0058 }
0059 case (30): {
0060 LogDebug("") << " TBM error trailer (errorType=30)";
0061 errorsInEvent = true;
0062 break;
0063 }
0064 case (31): {
0065 LogDebug("") << " event number error (errorType=31)";
0066 errorsInEvent = true;
0067 break;
0068 }
0069 default:
0070 return true;
0071 };
0072
0073 if (includeErrors_) {
0074
0075 if (errorType == 30) {
0076 int StateMach_bits = 4;
0077 int StateMach_shift = 8;
0078 uint32_t StateMach_mask = ~(~uint32_t(0) << StateMach_bits);
0079 int StateMach = (errorWord >> StateMach_shift) & StateMach_mask;
0080 if (StateMach == 4 || StateMach == 9)
0081 errorType = 40;
0082 }
0083
0084
0085 SiPixelRawDataError error(errorWord, errorType, fedId);
0086 cms_uint32_t detId;
0087 detId = errorDetId(converter, errorType, errorWord);
0088 errors[detId].push_back(error);
0089 }
0090 return false;
0091 }
0092
0093
0094 cms_uint32_t ErrorCheckerPhase0::errorDetId(const SiPixelFrameConverter* converter,
0095 int errorType,
0096 const Word32& word) const {
0097 if (!converter)
0098 return dummyDetId;
0099
0100 ElectronicIndex cabling;
0101
0102 switch (errorType) {
0103 case 25:
0104 case 30:
0105 case 31:
0106 case 36:
0107 case 40: {
0108
0109 cabling.dcol = 0;
0110 cabling.pxid = 2;
0111 cabling.roc = 1;
0112 cabling.link = (word >> LINK_shift) & LINK_mask;
0113
0114 DetectorIndex detIdx;
0115 int status = converter->toDetector(cabling, detIdx);
0116 if (status)
0117 break;
0118 if (DetId(detIdx.rawId).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel))
0119 return detIdx.rawId;
0120 break;
0121 }
0122 case 29: {
0123 int chanNmbr = 0;
0124 const int DB0_shift = 0;
0125 const int DB1_shift = DB0_shift + 1;
0126 const int DB2_shift = DB1_shift + 1;
0127 const int DB3_shift = DB2_shift + 1;
0128 const int DB4_shift = DB3_shift + 1;
0129 const cms_uint32_t DataBit_mask = ~(~cms_uint32_t(0) << 1);
0130
0131 int CH1 = (word >> DB0_shift) & DataBit_mask;
0132 int CH2 = (word >> DB1_shift) & DataBit_mask;
0133 int CH3 = (word >> DB2_shift) & DataBit_mask;
0134 int CH4 = (word >> DB3_shift) & DataBit_mask;
0135 int CH5 = (word >> DB4_shift) & DataBit_mask;
0136 int BLOCK_bits = 3;
0137 int BLOCK_shift = 8;
0138 cms_uint32_t BLOCK_mask = ~(~cms_uint32_t(0) << BLOCK_bits);
0139 int BLOCK = (word >> BLOCK_shift) & BLOCK_mask;
0140 int localCH = 1 * CH1 + 2 * CH2 + 3 * CH3 + 4 * CH4 + 5 * CH5;
0141 if (BLOCK % 2 == 0)
0142 chanNmbr = (BLOCK / 2) * 9 + localCH;
0143 else
0144 chanNmbr = ((BLOCK - 1) / 2) * 9 + 4 + localCH;
0145 if ((chanNmbr < 1) || (chanNmbr > 36))
0146 break;
0147
0148
0149 cabling.dcol = 0;
0150 cabling.pxid = 2;
0151 cabling.roc = 1;
0152 cabling.link = chanNmbr;
0153 DetectorIndex detIdx;
0154 int status = converter->toDetector(cabling, detIdx);
0155 if (status)
0156 break;
0157 if (DetId(detIdx.rawId).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel))
0158 return detIdx.rawId;
0159 break;
0160 }
0161 case 37:
0162 case 38: {
0163 cabling.dcol = 0;
0164 cabling.pxid = 2;
0165 cabling.roc = (word >> ROC_shift) & ROC_mask;
0166 cabling.link = (word >> LINK_shift) & LINK_mask;
0167
0168 DetectorIndex detIdx;
0169 int status = converter->toDetector(cabling, detIdx);
0170 if (status)
0171 break;
0172
0173 return detIdx.rawId;
0174 break;
0175 }
0176 default:
0177 break;
0178 };
0179 return dummyDetId;
0180 }