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