CMS 3D CMS Logo

ErrorChecker.cc
Go to the documentation of this file.
2 
4 
9 
11 
12 #include <bitset>
13 #include <sstream>
14 #include <iostream>
15 
16 using namespace std;
17 using namespace edm;
18 using namespace sipixelobjects;
19 
20 namespace {
21  constexpr int CRC_bits = 1;
22  constexpr int LINK_bits = 6;
23  constexpr int ROC_bits = 5;
24  constexpr int DCOL_bits = 5;
25  constexpr int PXID_bits = 8;
26  constexpr int ADC_bits = 8;
27  constexpr int OMIT_ERR_bits = 1;
28 
29  constexpr int CRC_shift = 2;
30  constexpr int ADC_shift = 0;
31  constexpr int PXID_shift = ADC_shift + ADC_bits;
32  constexpr int DCOL_shift = PXID_shift + PXID_bits;
33  constexpr int ROC_shift = DCOL_shift + DCOL_bits;
34  constexpr int LINK_shift = ROC_shift + ROC_bits;
35  constexpr int OMIT_ERR_shift = 20;
36 
37  constexpr cms_uint32_t dummyDetId = 0xffffffff;
38 
39  constexpr ErrorChecker::Word64 CRC_mask = ~(~ErrorChecker::Word64(0) << CRC_bits);
40  constexpr ErrorChecker::Word32 ERROR_mask = ~(~ErrorChecker::Word32(0) << ROC_bits);
41  constexpr ErrorChecker::Word32 LINK_mask = ~(~ErrorChecker::Word32(0) << LINK_bits);
42  constexpr ErrorChecker::Word32 ROC_mask = ~(~ErrorChecker::Word32(0) << ROC_bits);
43  constexpr ErrorChecker::Word32 OMIT_ERR_mask = ~(~ErrorChecker::Word32(0) << OMIT_ERR_bits);
44 } // namespace
45 
46 ErrorChecker::ErrorChecker() { includeErrors = false; }
47 
48 void ErrorChecker::setErrorStatus(bool ErrorStatus) { includeErrors = ErrorStatus; }
49 
50 bool ErrorChecker::checkCRC(bool& errorsInEvent, int fedId, const Word64* trailer, Errors& errors) {
51  int CRC_BIT = (*trailer >> CRC_shift) & CRC_mask;
52  if (CRC_BIT == 0)
53  return true;
54  errorsInEvent = true;
55  if (includeErrors) {
56  int errorType = 39;
57  SiPixelRawDataError error(*trailer, errorType, fedId);
58  errors[dummyDetId].push_back(error);
59  }
60  return false;
61 }
62 
63 bool ErrorChecker::checkHeader(bool& errorsInEvent, int fedId, const Word64* header, Errors& errors) {
64  FEDHeader fedHeader(reinterpret_cast<const unsigned char*>(header));
65  if (!fedHeader.check())
66  return false; // throw exception?
67  if (fedHeader.sourceID() != fedId) {
68  LogDebug("PixelDataFormatter::interpretRawData, fedHeader.sourceID() != fedId")
69  << ", sourceID = " << fedHeader.sourceID() << ", fedId = " << fedId << ", errorType = 32";
70  errorsInEvent = true;
71  if (includeErrors) {
72  int errorType = 32;
73  SiPixelRawDataError error(*header, errorType, fedId);
74  errors[dummyDetId].push_back(error);
75  }
76  }
77  return fedHeader.moreHeaders();
78 }
79 
81  bool& errorsInEvent, int fedId, unsigned int nWords, const Word64* trailer, Errors& errors) {
82  FEDTrailer fedTrailer(reinterpret_cast<const unsigned char*>(trailer));
83  if (!fedTrailer.check()) {
84  if (includeErrors) {
85  int errorType = 33;
86  SiPixelRawDataError error(*trailer, errorType, fedId);
87  errors[dummyDetId].push_back(error);
88  }
89  errorsInEvent = true;
90  LogError("FedTrailerCheck") << "fedTrailer.check failed, Fed: " << fedId << ", errorType = 33";
91  return false;
92  }
93  if (fedTrailer.fragmentLength() != nWords) {
94  LogError("FedTrailerLenght") << "fedTrailer.fragmentLength()!= nWords !! Fed: " << fedId << ", errorType = 34";
95  errorsInEvent = true;
96  if (includeErrors) {
97  int errorType = 34;
98  SiPixelRawDataError error(*trailer, errorType, fedId);
99  errors[dummyDetId].push_back(error);
100  }
101  }
102  return fedTrailer.moreTrailers();
103 }
104 
105 bool ErrorChecker::checkROC(bool& errorsInEvent,
106  int fedId,
108  const SiPixelFedCabling* theCablingTree,
109  Word32& errorWord,
110  Errors& errors) {
111  int errorType = (errorWord >> ROC_shift) & ERROR_mask;
112  if
113  LIKELY(errorType < 25) return true;
114 
115  switch (errorType) {
116  case (25): {
117  CablingPathToDetUnit cablingPath = {unsigned(fedId), (errorWord >> LINK_shift) & LINK_mask, 1};
118  if (!theCablingTree->findItem(cablingPath))
119  return false;
120  LogDebug("") << " invalid ROC=25 found (errorType=25)";
121  errorsInEvent = true;
122  break;
123  }
124  case (26): {
125  //LogDebug("")<<" gap word found (errorType=26)";
126  return false;
127  }
128  case (27): {
129  //LogDebug("")<<" dummy word found (errorType=27)";
130  return false;
131  }
132  case (28): {
133  LogDebug("") << " error fifo nearly full (errorType=28)";
134  errorsInEvent = true;
135  break;
136  }
137  case (29): {
138  LogDebug("") << " timeout on a channel (errorType=29)";
139  errorsInEvent = true;
140  if ((errorWord >> OMIT_ERR_shift) & OMIT_ERR_mask) {
141  LogDebug("") << " ...first errorType=29 error, this gets masked out";
142  return false;
143  }
144  break;
145  }
146  case (30): {
147  LogDebug("") << " TBM error trailer (errorType=30)";
148  int StateMatch_bits = 4;
149  int StateMatch_shift = 8;
150  uint32_t StateMatch_mask = ~(~uint32_t(0) << StateMatch_bits);
151  int StateMatch = (errorWord >> StateMatch_shift) & StateMatch_mask;
152  if (StateMatch != 1 && StateMatch != 8) {
153  LogDebug("") << " FED error 30 with unexpected State Bits (errorType=30)";
154  return false;
155  }
156  if (StateMatch == 1)
157  errorType = 40; // 1=Overflow -> 40, 8=number of ROCs -> 30
158  errorsInEvent = true;
159  break;
160  }
161  case (31): {
162  LogDebug("") << " event number error (errorType=31)";
163  errorsInEvent = true;
164  break;
165  }
166  default:
167  return true;
168  };
169 
170  if (includeErrors) {
171  // store error
172  SiPixelRawDataError error(errorWord, errorType, fedId);
173  cms_uint32_t detId;
174  detId = errorDetId(converter, errorType, errorWord);
175  errors[detId].push_back(error);
176  }
177  return false;
178 }
179 
181  int fedId, const SiPixelFrameConverter* converter, int status, Word32& errorWord, Errors& errors) {
182  switch (status) {
183  case (1): {
184  LogDebug("ErrorChecker::conversionError") << " Fed: " << fedId << " invalid channel Id (errorType=35)";
185  if (includeErrors) {
186  int errorType = 35;
187  SiPixelRawDataError error(errorWord, errorType, fedId);
188  cms_uint32_t detId = errorDetId(converter, errorType, errorWord);
189  errors[detId].push_back(error);
190  }
191  break;
192  }
193  case (2): {
194  LogDebug("ErrorChecker::conversionError") << " Fed: " << fedId << " invalid ROC Id (errorType=36)";
195  if (includeErrors) {
196  int errorType = 36;
197  SiPixelRawDataError error(errorWord, errorType, fedId);
198  cms_uint32_t detId = errorDetId(converter, errorType, errorWord);
199  errors[detId].push_back(error);
200  }
201  break;
202  }
203  case (3): {
204  LogDebug("ErrorChecker::conversionError") << " Fed: " << fedId << " invalid dcol/pixel value (errorType=37)";
205  if (includeErrors) {
206  int errorType = 37;
207  SiPixelRawDataError error(errorWord, errorType, fedId);
208  cms_uint32_t detId = errorDetId(converter, errorType, errorWord);
209  errors[detId].push_back(error);
210  }
211  break;
212  }
213  case (4): {
214  LogDebug("ErrorChecker::conversionError") << " Fed: " << fedId << " dcol/pixel read out of order (errorType=38)";
215  if (includeErrors) {
216  int errorType = 38;
217  SiPixelRawDataError error(errorWord, errorType, fedId);
218  cms_uint32_t detId = errorDetId(converter, errorType, errorWord);
219  errors[detId].push_back(error);
220  }
221  break;
222  }
223  default:
224  LogDebug("ErrorChecker::conversionError") << " cabling check returned unexpected result, status = " << status;
225  };
226 }
227 
228 // this function finds the detId for an error word that cannot be processed in word2digi
230  if (!converter)
231  return dummyDetId;
232 
233  ElectronicIndex cabling;
234 
235  switch (errorType) {
236  case 25:
237  case 30:
238  case 31:
239  case 36:
240  case 40: {
241  // set dummy values for cabling just to get detId from link
242  cabling.dcol = 0;
243  cabling.pxid = 2;
244  cabling.roc = 1;
245  cabling.link = (word >> LINK_shift) & LINK_mask;
246 
247  DetectorIndex detIdx;
248  int status = converter->toDetector(cabling, detIdx);
249  if (!status)
250  return detIdx.rawId;
251  break;
252  }
253  case 29: {
254  int chanNmbr = 0;
255  const int DB0_shift = 0;
256  const int DB1_shift = DB0_shift + 1;
257  const int DB2_shift = DB1_shift + 1;
258  const int DB3_shift = DB2_shift + 1;
259  const int DB4_shift = DB3_shift + 1;
260  const cms_uint32_t DataBit_mask = ~(~cms_uint32_t(0) << 1);
261 
262  int CH1 = (word >> DB0_shift) & DataBit_mask;
263  int CH2 = (word >> DB1_shift) & DataBit_mask;
264  int CH3 = (word >> DB2_shift) & DataBit_mask;
265  int CH4 = (word >> DB3_shift) & DataBit_mask;
266  int CH5 = (word >> DB4_shift) & DataBit_mask;
267  int BLOCK_bits = 3;
268  int BLOCK_shift = 8;
269  cms_uint32_t BLOCK_mask = ~(~cms_uint32_t(0) << BLOCK_bits);
270  int BLOCK = (word >> BLOCK_shift) & BLOCK_mask;
271  int localCH = 1 * CH1 + 2 * CH2 + 3 * CH3 + 4 * CH4 + 5 * CH5;
272  if (BLOCK % 2 == 0)
273  chanNmbr = (BLOCK / 2) * 9 + localCH;
274  else
275  chanNmbr = ((BLOCK - 1) / 2) * 9 + 4 + localCH;
276  if ((chanNmbr < 1) || (chanNmbr > 36))
277  break; // signifies unexpected result
278 
279  // set dummy values for cabling just to get detId from link if in Barrel
280  cabling.dcol = 0;
281  cabling.pxid = 2;
282  cabling.roc = 1;
283  cabling.link = chanNmbr;
284  DetectorIndex detIdx;
285  int status = converter->toDetector(cabling, detIdx);
286  if (!status)
287  return detIdx.rawId;
288  break;
289  }
290  case 37:
291  case 38: {
292  cabling.dcol = 0;
293  cabling.pxid = 2;
294  cabling.roc = (word >> ROC_shift) & ROC_mask;
295  cabling.link = (word >> LINK_shift) & LINK_mask;
296 
297  DetectorIndex detIdx;
298  int status = converter->toDetector(cabling, detIdx);
299  if (status)
300  break;
301 
302  return detIdx.rawId;
303  break;
304  }
305  default:
306  break;
307  };
308  return dummyDetId;
309 }
cms_uint32_t
unsigned int cms_uint32_t
Definition: typedefs.h:15
PixelSubdetector.h
ErrorChecker::ErrorChecker
ErrorChecker()
Definition: ErrorChecker.cc:46
MessageLogger.h
FEDHeader::moreHeaders
bool moreHeaders() const
Definition: FEDHeader.cc:23
SiPixelRawDataError
Pixel error – collection of errors and error information.
Definition: SiPixelRawDataError.h:19
mps_update.status
status
Definition: mps_update.py:69
converter
Definition: CandidateProducer.h:25
SiPixelFedCabling::findItem
virtual const sipixelobjects::PixelROC * findItem(const sipixelobjects::CablingPathToDetUnit &) const =0
edm
HLT enums.
Definition: AlignableModifier.h:19
pixelgpudetails::LINK_bits
const uint32_t LINK_bits
Definition: SiPixelRawToClusterGPUKernel.h:41
omtf::Word64
uint64_t Word64
Definition: OmtfDataWord64.h:11
ErrorChecker::checkTrailer
bool checkTrailer(bool &errorsInEvent, int fedId, unsigned int nWords, const Word64 *trailer, Errors &errors) override
Definition: ErrorChecker.cc:80
ErrorChecker::errorDetId
cms_uint32_t errorDetId(const SiPixelFrameConverter *converter, int errorType, const Word32 &word) const override
Definition: ErrorChecker.cc:229
sipixelobjects::ElectronicIndex::dcol
int dcol
Definition: ElectronicIndex.h:8
SiPixelFedCabling
Definition: SiPixelFedCabling.h:10
pixelgpudetails::DCOL_bits
const uint32_t DCOL_bits
Definition: SiPixelRawToClusterGPUKernel.h:43
ErrorChecker::checkHeader
bool checkHeader(bool &errorsInEvent, int fedId, const Word64 *header, Errors &errors) override
Definition: ErrorChecker.cc:63
relativeConstraints.error
error
Definition: relativeConstraints.py:53
ErrorChecker::Word32
cms_uint32_t Word32
Definition: ErrorChecker.h:13
ErrorChecker.h
pixelgpudetails::OMIT_ERR_mask
const uint32_t OMIT_ERR_mask
Definition: SiPixelRawToClusterGPUKernel.h:78
pixelgpudetails::OMIT_ERR_shift
const uint32_t OMIT_ERR_shift
Definition: SiPixelRawToClusterGPUKernel.h:68
pixelgpudetails::ROC_mask
const uint32_t ROC_mask
Definition: SiPixelRawToClusterGPUKernel.h:71
FEDTrailer::check
bool check() const
Check that the trailer is OK.
Definition: FEDTrailer.cc:45
word
uint64_t word
Definition: CTPPSTotemDataFormatter.cc:29
errors
Definition: errors.py:1
sipixelobjects
Definition: CablingPathToDetUnit.h:4
sipixelobjects::CablingPathToDetUnit
Definition: CablingPathToDetUnit.h:5
ErrorChecker::checkROC
bool checkROC(bool &errorsInEvent, int fedId, const SiPixelFrameConverter *converter, const SiPixelFedCabling *theCablingTree, Word32 &errorWord, Errors &errors) override
Definition: ErrorChecker.cc:105
pixelgpudetails::PXID_bits
const uint32_t PXID_bits
Definition: SiPixelRawToClusterGPUKernel.h:44
pixelgpudetails::OMIT_ERR_bits
const uint32_t OMIT_ERR_bits
Definition: SiPixelRawToClusterGPUKernel.h:52
sipixelobjects::ElectronicIndex::pxid
int pxid
Definition: ElectronicIndex.h:9
ErrorChecker::checkCRC
bool checkCRC(bool &errorsInEvent, int fedId, const Word64 *trailer, Errors &errors) override
Definition: ErrorChecker.cc:50
sipixelobjects::ElectronicIndex
Definition: ElectronicIndex.h:5
sipixelobjects::ElectronicIndex::link
int link
Definition: ElectronicIndex.h:6
pixelgpudetails::ADC_shift
const uint32_t ADC_shift
Definition: SiPixelRawToClusterGPUKernel.h:60
SiPixelFrameConverter.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
FEDTrailer
Definition: FEDTrailer.h:14
ErrorChecker::conversionError
void conversionError(int fedId, const SiPixelFrameConverter *converter, int status, Word32 &errorWord, Errors &errors) override
Definition: ErrorChecker.cc:180
pixelgpudetails::PXID_shift
const uint32_t PXID_shift
Definition: SiPixelRawToClusterGPUKernel.h:61
FEDTrailer::moreTrailers
bool moreTrailers() const
Definition: FEDTrailer.cc:21
pixelgpudetails::LINK_shift
const uint32_t LINK_shift
Definition: SiPixelRawToClusterGPUKernel.h:64
SiPixelFrameConverter
Definition: SiPixelFrameConverter.h:15
pixelgpudetails::ROC_bits
const uint32_t ROC_bits
Definition: SiPixelRawToClusterGPUKernel.h:42
ErrorChecker::Word64
cms_uint64_t Word64
Definition: ErrorChecker.h:14
l1tstage2_dqm_sourceclient-live_cfg.fedId
fedId
Definition: l1tstage2_dqm_sourceclient-live_cfg.py:88
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
ErrorChecker
Definition: ErrorChecker.h:11
ErrorChecker::setErrorStatus
void setErrorStatus(bool ErrorStatus) override
Definition: ErrorChecker.cc:48
std
Definition: JetResolutionObject.h:76
pixelgpudetails::LINK_mask
const uint32_t LINK_mask
Definition: SiPixelRawToClusterGPUKernel.h:70
DetId.h
LIKELY
#define LIKELY(x)
Definition: Likely.h:20
pixelgpudetails::ADC_bits
const uint32_t ADC_bits
Definition: SiPixelRawToClusterGPUKernel.h:45
pixelgpudetails::DCOL_shift
const uint32_t DCOL_shift
Definition: SiPixelRawToClusterGPUKernel.h:62
FEDHeader::check
bool check() const
Check that the header is OK.
Definition: FEDHeader.cc:44
FEDHeader::sourceID
uint16_t sourceID() const
Identifier of the FED.
Definition: FEDHeader.cc:19
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:292
ErrorChecker::Errors
std::map< cms_uint32_t, DetErrors > Errors
Definition: ErrorChecker.h:17
pixelgpudetails::ROC_shift
const uint32_t ROC_shift
Definition: SiPixelRawToClusterGPUKernel.h:63
FEDHeader
Definition: FEDHeader.h:14
FEDHeader.h
pixelgpudetails::ERROR_mask
const uint32_t ERROR_mask
Definition: SiPixelRawToClusterGPUKernel.h:77
sipixelobjects::DetectorIndex::rawId
uint32_t rawId
Definition: DetectorIndex.h:7
sipixelobjects::DetectorIndex
Definition: DetectorIndex.h:6
sipixelobjects::ElectronicIndex::roc
int roc
Definition: ElectronicIndex.h:7
FEDTrailer::fragmentLength
uint32_t fragmentLength() const
The length of the event fragment counted in 64-bit words including header and trailer.
Definition: FEDTrailer.cc:13
FEDTrailer.h