00001 #include "EventFilter/SiPixelRawToDigi/interface/ErrorChecker.h"
00002
00003 #include "CondFormats/SiPixelObjects/interface/SiPixelFrameConverter.h"
00004
00005 #include "DataFormats/DetId/interface/DetId.h"
00006 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00007 #include "DataFormats/FEDRawData/interface/FEDHeader.h"
00008 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
00009
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011
00012 #include <bitset>
00013 #include <sstream>
00014 #include <iostream>
00015
00016 using namespace std;
00017 using namespace edm;
00018 using namespace sipixelobjects;
00019
00020 const int CRC_bits = 1;
00021 const int LINK_bits = 6;
00022 const int ROC_bits = 5;
00023 const int DCOL_bits = 5;
00024 const int PXID_bits = 8;
00025 const int ADC_bits = 8;
00026
00027 const int CRC_shift = 2;
00028 const int ADC_shift = 0;
00029 const int PXID_shift = ADC_shift + ADC_bits;
00030 const int DCOL_shift = PXID_shift + PXID_bits;
00031 const int ROC_shift = DCOL_shift + DCOL_bits;
00032 const int LINK_shift = ROC_shift + ROC_bits;
00033
00034 const uint32_t dummyDetId = 0xffffffff;
00035
00036 const ErrorChecker::Word64 CRC_mask = ~(~ErrorChecker::Word64(0) << CRC_bits);
00037 const ErrorChecker::Word32 ERROR_mask = ~(~ErrorChecker::Word32(0) << ROC_bits);
00038 const ErrorChecker::Word32 LINK_mask = ~(~ErrorChecker::Word32(0) << LINK_bits);
00039 const ErrorChecker::Word32 ROC_mask = ~(~ErrorChecker::Word32(0) << ROC_bits);
00040 const ErrorChecker::Word32 DCOL_mask = ~(~ErrorChecker::Word32(0) << DCOL_bits);
00041 const ErrorChecker::Word32 PXID_mask = ~(~ErrorChecker::Word32(0) << PXID_bits);
00042
00043
00044 ErrorChecker::ErrorChecker() {
00045
00046 includeErrors = false;
00047 }
00048
00049 void ErrorChecker::setErrorStatus(bool ErrorStatus)
00050 {
00051 includeErrors = ErrorStatus;
00052 }
00053
00054 bool ErrorChecker::checkCRC(bool& errorsInEvent, int fedId, const Word64* trailer, Errors& errors)
00055 {
00056 int CRC_BIT = (*trailer >> CRC_shift) & CRC_mask;
00057 if (CRC_BIT == 0) return true;
00058 errorsInEvent = true;
00059 if (includeErrors) {
00060 int errorType = 39;
00061 SiPixelRawDataError error(*trailer, errorType, fedId);
00062 errors[dummyDetId].push_back(error);
00063 }
00064 return false;
00065 }
00066
00067 bool ErrorChecker::checkHeader(bool& errorsInEvent, int fedId, const Word64* header, Errors& errors)
00068 {
00069 FEDHeader fedHeader( reinterpret_cast<const unsigned char*>(header));
00070 if ( !fedHeader.check() ) return false;
00071 if ( fedHeader.sourceID() != fedId) {
00072 LogDebug("PixelDataFormatter::interpretRawData, fedHeader.sourceID() != fedId")
00073 <<", sourceID = " <<fedHeader.sourceID()
00074 <<", fedId = "<<fedId<<", errorType = 32";
00075 errorsInEvent = true;
00076 if (includeErrors) {
00077 int errorType = 32;
00078 SiPixelRawDataError error(*header, errorType, fedId);
00079 errors[dummyDetId].push_back(error);
00080 }
00081 }
00082 return fedHeader.moreHeaders();
00083 }
00084
00085 bool ErrorChecker::checkTrailer(bool& errorsInEvent, int fedId, int nWords, const Word64* trailer, Errors& errors)
00086 {
00087 FEDTrailer fedTrailer(reinterpret_cast<const unsigned char*>(trailer));
00088 if ( !fedTrailer.check()) {
00089 if(includeErrors) {
00090 int errorType = 33;
00091 SiPixelRawDataError error(*trailer, errorType, fedId);
00092 errors[dummyDetId].push_back(error);
00093 }
00094 errorsInEvent = true;
00095 LogError("PixelDataFormatter::interpretRawData, fedTrailer.check: ")
00096 <<"fedTrailer.check failed, Fed: " << fedId << ", errorType = 33";
00097 return false;
00098 }
00099 if ( fedTrailer.lenght()!= nWords) {
00100 LogError("PROBLEM in PixelDataFormatter, fedTrailer.lenght()!= nWords !!")<< " Fed: " << fedId << ", errorType = 34";
00101 errorsInEvent = true;
00102 if(includeErrors) {
00103 int errorType = 34;
00104 SiPixelRawDataError error(*trailer, errorType, fedId);
00105 errors[dummyDetId].push_back(error);
00106 }
00107 }
00108 return fedTrailer.moreTrailers();
00109 }
00110
00111 bool ErrorChecker::checkROC(bool& errorsInEvent, int fedId, const SiPixelFrameConverter* converter, Word32& errorWord, Errors& errors)
00112 {
00113 int errorType = (errorWord >> ROC_shift) & ERROR_mask;
00114
00115 switch (errorType) {
00116 case(25) : {
00117 LogDebug("")<<" invalid ROC=25 found (errorType=25)";
00118 errorsInEvent = true;
00119 break;
00120 }
00121 case(26) : {
00122
00123 return false;
00124 }
00125 case(27) : {
00126
00127 return false;
00128 }
00129 case(28) : {
00130 LogDebug("")<<" error fifo nearly full (errorType=28)";
00131 errorsInEvent = true;
00132 break;
00133 }
00134 case(29) : {
00135 LogDebug("")<<" timeout on a channel (errorType=29)";
00136 errorsInEvent = true;
00137 break;
00138 }
00139 case(30) : {
00140 LogDebug("")<<" TBM error trailer (errorType=30)";
00141 errorsInEvent = true;
00142 break;
00143 }
00144 case(31) : {
00145 LogDebug("")<<" event number error (errorType=31)";
00146 errorsInEvent = true;
00147 break;
00148 }
00149 default: return true;
00150 };
00151
00152 if(includeErrors) {
00153 SiPixelRawDataError error(errorWord, errorType, fedId);
00154 uint32_t detId;
00155 detId = errorDetId(converter, errorType, errorWord);
00156 errors[detId].push_back(error);
00157 }
00158 return false;
00159 }
00160
00161 void ErrorChecker::conversionError(int fedId, const SiPixelFrameConverter* converter, int status, Word32& errorWord, Errors& errors)
00162 {
00163 switch (status) {
00164 case(1) : {
00165 LogDebug("ErrorChecker::conversionError") << " Fed: " << fedId << " invalid channel Id (errorType=35)";
00166 if(includeErrors) {
00167 int errorType = 35;
00168 SiPixelRawDataError error(errorWord, errorType, fedId);
00169 uint32_t detId = errorDetId(converter, errorType, errorWord);
00170 errors[detId].push_back(error);
00171 }
00172 break;
00173 }
00174 case(2) : {
00175 LogDebug("ErrorChecker::conversionError")<< " Fed: " << fedId << " invalid ROC Id (errorType=36)";
00176 if(includeErrors) {
00177 int errorType = 36;
00178 SiPixelRawDataError error(errorWord, errorType, fedId);
00179 uint32_t detId = errorDetId(converter, errorType, errorWord);
00180 errors[detId].push_back(error);
00181 }
00182 break;
00183 }
00184 case(3) : {
00185 LogDebug("ErrorChecker::conversionError")<< " Fed: " << fedId << " invalid dcol/pixel value (errorType=37)";
00186 if(includeErrors) {
00187 int errorType = 37;
00188 SiPixelRawDataError error(errorWord, errorType, fedId);
00189 uint32_t detId = errorDetId(converter, errorType, errorWord);
00190 errors[detId].push_back(error);
00191 }
00192 break;
00193 }
00194 case(4) : {
00195 LogDebug("ErrorChecker::conversionError")<< " Fed: " << fedId << " dcol/pixel read out of order (errorType=38)";
00196 if(includeErrors) {
00197 int errorType = 38;
00198 SiPixelRawDataError error(errorWord, errorType, fedId);
00199 uint32_t detId = errorDetId(converter, errorType, errorWord);
00200 errors[detId].push_back(error);
00201 }
00202 break;
00203 }
00204 default: LogDebug("ErrorChecker::conversionError")<<" cabling check returned unexpected result, status = "<< status;
00205 };
00206 }
00207
00208
00209 uint32_t ErrorChecker::errorDetId(const SiPixelFrameConverter* converter,
00210 int errorType, const Word32 & word) const
00211 {
00212 if (!converter) return dummyDetId;
00213
00214 ElectronicIndex cabling;
00215
00216 switch (errorType) {
00217 case 30 : case 31: case 36: {
00218
00219 cabling.dcol = 0;
00220 cabling.pxid = 2;
00221 cabling.roc = 1;
00222 cabling.link = (word >> LINK_shift) & LINK_mask;
00223
00224 DetectorIndex detIdx;
00225 int status = converter->toDetector(cabling, detIdx);
00226 if (status) break;
00227
00228 if(DetId(detIdx.rawId).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) return detIdx.rawId;
00229 break;
00230 }
00231 case 37 : case 38: {
00232 cabling.dcol = 0;
00233 cabling.pxid = 2;
00234 cabling.roc = (word >> ROC_shift) & ROC_mask;
00235 cabling.link = (word >> LINK_shift) & LINK_mask;
00236
00237 DetectorIndex detIdx;
00238 int status = converter->toDetector(cabling, detIdx);
00239 if (status) break;
00240
00241 return detIdx.rawId;
00242 break;
00243 }
00244 default : break;
00245 };
00246 return dummyDetId;
00247 }