CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 }
45 
47 
48  includeErrors = false;
49 }
50 
51 void ErrorChecker::setErrorStatus(bool ErrorStatus)
52 {
53  includeErrors = ErrorStatus;
54 }
55 
56 bool ErrorChecker::checkCRC(bool& errorsInEvent, int fedId, const Word64* trailer, Errors& errors)
57 {
58  int CRC_BIT = (*trailer >> CRC_shift) & CRC_mask;
59  if (CRC_BIT == 0) return true;
60  errorsInEvent = true;
61  if (includeErrors) {
62  int errorType = 39;
63  SiPixelRawDataError error(*trailer, errorType, fedId);
64  errors[dummyDetId].push_back(error);
65  }
66  return false;
67 }
68 
69 bool ErrorChecker::checkHeader(bool& errorsInEvent, int fedId, const Word64* header, Errors& errors)
70 {
71  FEDHeader fedHeader( reinterpret_cast<const unsigned char*>(header));
72  if ( !fedHeader.check() ) return false; // throw exception?
73  if ( fedHeader.sourceID() != fedId) {
74  LogDebug("PixelDataFormatter::interpretRawData, fedHeader.sourceID() != fedId")
75  <<", sourceID = " <<fedHeader.sourceID()
76  <<", fedId = "<<fedId<<", errorType = 32";
77  errorsInEvent = true;
78  if (includeErrors) {
79  int errorType = 32;
80  SiPixelRawDataError error(*header, errorType, fedId);
81  errors[dummyDetId].push_back(error);
82  }
83  }
84  return fedHeader.moreHeaders();
85 }
86 
87 bool ErrorChecker::checkTrailer(bool& errorsInEvent, int fedId, int nWords, const Word64* trailer, Errors& errors)
88 {
89  FEDTrailer fedTrailer(reinterpret_cast<const unsigned char*>(trailer));
90  if ( !fedTrailer.check()) {
91  if(includeErrors) {
92  int errorType = 33;
93  SiPixelRawDataError error(*trailer, errorType, fedId);
94  errors[dummyDetId].push_back(error);
95  }
96  errorsInEvent = true;
97  LogError("FedTrailerCheck")
98  <<"fedTrailer.check failed, Fed: " << fedId << ", errorType = 33";
99  return false;
100  }
101  if ( fedTrailer.lenght()!= nWords) {
102  LogError("FedTrailerLenght")<< "fedTrailer.lenght()!= nWords !! Fed: " << fedId << ", errorType = 34";
103  errorsInEvent = true;
104  if(includeErrors) {
105  int errorType = 34;
106  SiPixelRawDataError error(*trailer, errorType, fedId);
107  errors[dummyDetId].push_back(error);
108  }
109  }
110  return fedTrailer.moreTrailers();
111 }
112 
113 bool ErrorChecker::checkROC(bool& errorsInEvent, int fedId, const SiPixelFrameConverter* converter, Word32& errorWord, Errors& errors)
114 {
115  int errorType = (errorWord >> ROC_shift) & ERROR_mask;
116  if likely(errorType<25) return true;
117 
118  switch (errorType) {
119  case(25) : {
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  errorsInEvent = true;
149  break;
150  }
151  case(31) : {
152  LogDebug("")<<" event number error (errorType=31)";
153  errorsInEvent = true;
154  break;
155  }
156  default: return true;
157  };
158 
159  if(includeErrors) {
160  // check to see if overflow error for type 30, change type to 40 if so
161  if(errorType==30) {
162  int StateMach_bits = 4;
163  int StateMach_shift = 8;
164  uint32_t StateMach_mask = ~(~uint32_t(0) << StateMach_bits);
165  int StateMach = (errorWord >> StateMach_shift) & StateMach_mask;
166  if( StateMach==4 || StateMach==9 ) errorType = 40;
167  }
168 
169  // store error
170  SiPixelRawDataError error(errorWord, errorType, fedId);
171  cms_uint32_t detId;
172  detId = errorDetId(converter, errorType, errorWord);
173  errors[detId].push_back(error);
174  }
175  return false;
176 }
177 
178 void ErrorChecker::conversionError(int fedId, const SiPixelFrameConverter* converter, int status, Word32& errorWord, Errors& errors)
179 {
180  switch (status) {
181  case(1) : {
182  LogDebug("ErrorChecker::conversionError") << " Fed: " << fedId << " invalid channel Id (errorType=35)";
183  if(includeErrors) {
184  int errorType = 35;
185  SiPixelRawDataError error(errorWord, errorType, fedId);
186  cms_uint32_t detId = errorDetId(converter, errorType, errorWord);
187  errors[detId].push_back(error);
188  }
189  break;
190  }
191  case(2) : {
192  LogDebug("ErrorChecker::conversionError")<< " Fed: " << fedId << " invalid ROC Id (errorType=36)";
193  if(includeErrors) {
194  int errorType = 36;
195  SiPixelRawDataError error(errorWord, errorType, fedId);
196  cms_uint32_t detId = errorDetId(converter, errorType, errorWord);
197  errors[detId].push_back(error);
198  }
199  break;
200  }
201  case(3) : {
202  LogDebug("ErrorChecker::conversionError")<< " Fed: " << fedId << " invalid dcol/pixel value (errorType=37)";
203  if(includeErrors) {
204  int errorType = 37;
205  SiPixelRawDataError error(errorWord, errorType, fedId);
206  cms_uint32_t detId = errorDetId(converter, errorType, errorWord);
207  errors[detId].push_back(error);
208  }
209  break;
210  }
211  case(4) : {
212  LogDebug("ErrorChecker::conversionError")<< " Fed: " << fedId << " dcol/pixel read out of order (errorType=38)";
213  if(includeErrors) {
214  int errorType = 38;
215  SiPixelRawDataError error(errorWord, errorType, fedId);
216  cms_uint32_t detId = errorDetId(converter, errorType, errorWord);
217  errors[detId].push_back(error);
218  }
219  break;
220  }
221  default: LogDebug("ErrorChecker::conversionError")<<" cabling check returned unexpected result, status = "<< status;
222  };
223 }
224 
225 // this function finds the detId for an error word that cannot be processed in word2digi
227  int errorType, const Word32 & word) const
228 {
229  if (!converter) return dummyDetId;
230 
231  ElectronicIndex cabling;
232 
233  switch (errorType) {
234  case 25 : case 30 : case 31 : case 36 : case 40 : {
235  // set dummy values for cabling just to get detId from link if in Barrel
236  cabling.dcol = 0;
237  cabling.pxid = 2;
238  cabling.roc = 1;
239  cabling.link = (word >> LINK_shift) & LINK_mask;
240 
241  DetectorIndex detIdx;
242  int status = converter->toDetector(cabling, detIdx);
243  if (status) break;
244  if(DetId(detIdx.rawId).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) return detIdx.rawId;
245  break;
246  }
247  case 29 : {
248  int chanNmbr = 0;
249  const int DB0_shift = 0;
250  const int DB1_shift = DB0_shift + 1;
251  const int DB2_shift = DB1_shift + 1;
252  const int DB3_shift = DB2_shift + 1;
253  const int DB4_shift = DB3_shift + 1;
254  const cms_uint32_t DataBit_mask = ~(~cms_uint32_t(0) << 1);
255 
256  int CH1 = (word >> DB0_shift) & DataBit_mask;
257  int CH2 = (word >> DB1_shift) & DataBit_mask;
258  int CH3 = (word >> DB2_shift) & DataBit_mask;
259  int CH4 = (word >> DB3_shift) & DataBit_mask;
260  int CH5 = (word >> DB4_shift) & DataBit_mask;
261  int BLOCK_bits = 3;
262  int BLOCK_shift = 8;
263  cms_uint32_t BLOCK_mask = ~(~cms_uint32_t(0) << BLOCK_bits);
264  int BLOCK = (word >> BLOCK_shift) & BLOCK_mask;
265  int localCH = 1*CH1+2*CH2+3*CH3+4*CH4+5*CH5;
266  if (BLOCK%2==0) chanNmbr=(BLOCK/2)*9+localCH;
267  else chanNmbr = ((BLOCK-1)/2)*9+4+localCH;
268  if ((chanNmbr<1)||(chanNmbr>36)) break; // signifies unexpected result
269 
270  // set dummy values for cabling just to get detId from link if in Barrel
271  cabling.dcol = 0;
272  cabling.pxid = 2;
273  cabling.roc = 1;
274  cabling.link = chanNmbr;
275  DetectorIndex detIdx;
276  int status = converter->toDetector(cabling, detIdx);
277  if (status) break;
278  if(DetId(detIdx.rawId).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) return detIdx.rawId;
279  break;
280  }
281  case 37 : case 38: {
282  cabling.dcol = 0;
283  cabling.pxid = 2;
284  cabling.roc = (word >> ROC_shift) & ROC_mask;
285  cabling.link = (word >> LINK_shift) & LINK_mask;
286 
287  DetectorIndex detIdx;
288  int status = converter->toDetector(cabling, detIdx);
289  if (status) break;
290 
291  return detIdx.rawId;
292  break;
293  }
294  default : break;
295  };
296  return dummyDetId;
297 }
#define LogDebug(id)
cms_uint32_t Word32
Definition: ErrorChecker.h:23
bool check()
Definition: FEDTrailer.cc:64
bool checkTrailer(bool &errorsInEvent, int fedId, int nWords, const Word64 *trailer, Errors &errors)
Definition: ErrorChecker.cc:87
bool moreTrailers()
Definition: FEDTrailer.cc:37
cms_uint64_t Word64
Definition: ErrorChecker.h:24
cms_uint32_t errorDetId(const SiPixelFrameConverter *converter, int errorType, const Word32 &word) const
bool checkROC(bool &errorsInEvent, int fedId, const SiPixelFrameConverter *converter, Word32 &errorWord, Errors &errors)
std::map< cms_uint32_t, DetErrors > Errors
Definition: ErrorChecker.h:27
int sourceID()
Identifier of the FED.
Definition: FEDHeader.cc:28
bool checkCRC(bool &errorsInEvent, int fedId, const Word64 *trailer, Errors &errors)
Definition: ErrorChecker.cc:56
bool moreHeaders()
Definition: FEDHeader.cc:36
uint64_t Word64
void setErrorStatus(bool ErrorStatus)
Definition: ErrorChecker.cc:51
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
unsigned int cms_uint32_t
Definition: typedefs.h:15
Definition: DetId.h:18
bool check()
Check that the header is OK.
Definition: FEDHeader.cc:64
int lenght()
The length of the event fragment counted in 64-bit words including header and trailer.
Definition: FEDTrailer.cc:17
void conversionError(int fedId, const SiPixelFrameConverter *converter, int status, Word32 &errorWord, Errors &errors)
#define likely(x)
Definition: Likely.h:20
int toDetector(const sipixelobjects::ElectronicIndex &cabling, sipixelobjects::DetectorIndex &detector) const
tuple status
Definition: ntuplemaker.py:245
#define constexpr
Pixel error – collection of errors and error information.
bool checkHeader(bool &errorsInEvent, int fedId, const Word64 *header, Errors &errors)
Definition: ErrorChecker.cc:69