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 const int CRC_bits = 1;
21 const int LINK_bits = 6;
22 const int ROC_bits = 5;
23 const int DCOL_bits = 5;
24 const int PXID_bits = 8;
25 const int ADC_bits = 8;
26 
27 const int CRC_shift = 2;
28 const int ADC_shift = 0;
33 
34 const uint32_t dummyDetId = 0xffffffff;
35 
42 
43 
45 
46  includeErrors = false;
47 }
48 
49 void ErrorChecker::setErrorStatus(bool ErrorStatus)
50 {
51  includeErrors = ErrorStatus;
52 }
53 
54 bool ErrorChecker::checkCRC(bool& errorsInEvent, int fedId, const Word64* trailer, Errors& errors)
55 {
56  int CRC_BIT = (*trailer >> CRC_shift) & CRC_mask;
57  if (CRC_BIT == 0) return true;
58  errorsInEvent = true;
59  if (includeErrors) {
60  int errorType = 39;
61  SiPixelRawDataError error(*trailer, errorType, fedId);
62  errors[dummyDetId].push_back(error);
63  }
64  return false;
65 }
66 
67 bool ErrorChecker::checkHeader(bool& errorsInEvent, int fedId, const Word64* header, Errors& errors)
68 {
69  FEDHeader fedHeader( reinterpret_cast<const unsigned char*>(header));
70  if ( !fedHeader.check() ) return false; // throw exception?
71  if ( fedHeader.sourceID() != fedId) {
72  LogDebug("PixelDataFormatter::interpretRawData, fedHeader.sourceID() != fedId")
73  <<", sourceID = " <<fedHeader.sourceID()
74  <<", fedId = "<<fedId<<", errorType = 32";
75  errorsInEvent = true;
76  if (includeErrors) {
77  int errorType = 32;
78  SiPixelRawDataError error(*header, errorType, fedId);
79  errors[dummyDetId].push_back(error);
80  }
81  }
82  return fedHeader.moreHeaders();
83 }
84 
85 bool ErrorChecker::checkTrailer(bool& errorsInEvent, int fedId, int nWords, const Word64* trailer, Errors& errors)
86 {
87  FEDTrailer fedTrailer(reinterpret_cast<const unsigned char*>(trailer));
88  if ( !fedTrailer.check()) {
89  if(includeErrors) {
90  int errorType = 33;
91  SiPixelRawDataError error(*trailer, errorType, fedId);
92  errors[dummyDetId].push_back(error);
93  }
94  errorsInEvent = true;
95  LogError("PixelDataFormatter::interpretRawData, fedTrailer.check: ")
96  <<"fedTrailer.check failed, Fed: " << fedId << ", errorType = 33";
97  return false;
98  }
99  if ( fedTrailer.lenght()!= nWords) {
100  LogError("PROBLEM in PixelDataFormatter, fedTrailer.lenght()!= nWords !!")<< " Fed: " << fedId << ", errorType = 34";
101  errorsInEvent = true;
102  if(includeErrors) {
103  int errorType = 34;
104  SiPixelRawDataError error(*trailer, errorType, fedId);
105  errors[dummyDetId].push_back(error);
106  }
107  }
108  return fedTrailer.moreTrailers();
109 }
110 
111 bool ErrorChecker::checkROC(bool& errorsInEvent, int fedId, const SiPixelFrameConverter* converter, Word32& errorWord, Errors& errors)
112 {
113  int errorType = (errorWord >> ROC_shift) & ERROR_mask;
114 
115  switch (errorType) {
116  case(25) : {
117  LogDebug("")<<" invalid ROC=25 found (errorType=25)";
118  errorsInEvent = true;
119  break;
120  }
121  case(26) : {
122  //LogDebug("")<<" gap word found (errorType=26)";
123  return false;
124  }
125  case(27) : {
126  //LogDebug("")<<" dummy word found (errorType=27)";
127  return false;
128  }
129  case(28) : {
130  LogDebug("")<<" error fifo nearly full (errorType=28)";
131  errorsInEvent = true;
132  break;
133  }
134  case(29) : {
135  LogDebug("")<<" timeout on a channel (errorType=29)";
136  errorsInEvent = true;
137  break;
138  }
139  case(30) : {
140  LogDebug("")<<" TBM error trailer (errorType=30)";
141  errorsInEvent = true;
142  break;
143  }
144  case(31) : {
145  LogDebug("")<<" event number error (errorType=31)";
146  errorsInEvent = true;
147  break;
148  }
149  default: return true;
150  };
151 
152  if(includeErrors) {
153  SiPixelRawDataError error(errorWord, errorType, fedId);
154  uint32_t detId;
155  detId = errorDetId(converter, errorType, errorWord);
156  errors[detId].push_back(error);
157  }
158  return false;
159 }
160 
161 void ErrorChecker::conversionError(int fedId, const SiPixelFrameConverter* converter, int status, Word32& errorWord, Errors& errors)
162 {
163  switch (status) {
164  case(1) : {
165  LogDebug("ErrorChecker::conversionError") << " Fed: " << fedId << " invalid channel Id (errorType=35)";
166  if(includeErrors) {
167  int errorType = 35;
168  SiPixelRawDataError error(errorWord, errorType, fedId);
169  uint32_t detId = errorDetId(converter, errorType, errorWord);
170  errors[detId].push_back(error);
171  }
172  break;
173  }
174  case(2) : {
175  LogDebug("ErrorChecker::conversionError")<< " Fed: " << fedId << " invalid ROC Id (errorType=36)";
176  if(includeErrors) {
177  int errorType = 36;
178  SiPixelRawDataError error(errorWord, errorType, fedId);
179  uint32_t detId = errorDetId(converter, errorType, errorWord);
180  errors[detId].push_back(error);
181  }
182  break;
183  }
184  case(3) : {
185  LogDebug("ErrorChecker::conversionError")<< " Fed: " << fedId << " invalid dcol/pixel value (errorType=37)";
186  if(includeErrors) {
187  int errorType = 37;
188  SiPixelRawDataError error(errorWord, errorType, fedId);
189  uint32_t detId = errorDetId(converter, errorType, errorWord);
190  errors[detId].push_back(error);
191  }
192  break;
193  }
194  case(4) : {
195  LogDebug("ErrorChecker::conversionError")<< " Fed: " << fedId << " dcol/pixel read out of order (errorType=38)";
196  if(includeErrors) {
197  int errorType = 38;
198  SiPixelRawDataError error(errorWord, errorType, fedId);
199  uint32_t detId = errorDetId(converter, errorType, errorWord);
200  errors[detId].push_back(error);
201  }
202  break;
203  }
204  default: LogDebug("ErrorChecker::conversionError")<<" cabling check returned unexpected result, status = "<< status;
205  };
206 }
207 
208 // this function finds the detId for an error word, which cannot be processed in word2digi
210  int errorType, const Word32 & word) const
211 {
212  if (!converter) return dummyDetId;
213 
214  ElectronicIndex cabling;
215 
216  switch (errorType) {
217  case 30 : case 31: case 36: {
218  // set dummy values for cabling just to get detId from link if in Barrel
219  cabling.dcol = 0;
220  cabling.pxid = 2;
221  cabling.roc = 1;
222  cabling.link = (word >> LINK_shift) & LINK_mask;
223 
224  DetectorIndex detIdx;
225  int status = converter->toDetector(cabling, detIdx);
226  if (status) break;
227 
228  if(DetId(detIdx.rawId).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) return detIdx.rawId;
229  break;
230  }
231  case 37 : case 38: {
232  cabling.dcol = 0;
233  cabling.pxid = 2;
234  cabling.roc = (word >> ROC_shift) & ROC_mask;
235  cabling.link = (word >> LINK_shift) & LINK_mask;
236 
237  DetectorIndex detIdx;
238  int status = converter->toDetector(cabling, detIdx);
239  if (status) break;
240 
241  return detIdx.rawId;
242  break;
243  }
244  default : break;
245  };
246  return dummyDetId;
247 }
#define LogDebug(id)
uint32_t Word32
Definition: ErrorChecker.h:23
const int DCOL_bits
Definition: ErrorChecker.cc:23
bool check()
Definition: FEDTrailer.cc:66
bool checkTrailer(bool &errorsInEvent, int fedId, int nWords, const Word64 *trailer, Errors &errors)
Definition: ErrorChecker.cc:85
const int DCOL_shift
Definition: ErrorChecker.cc:30
bool moreTrailers()
Definition: FEDTrailer.cc:39
const int CRC_bits
Definition: ErrorChecker.cc:20
const ErrorChecker::Word32 DCOL_mask
Definition: ErrorChecker.cc:40
const int PXID_shift
Definition: ErrorChecker.cc:29
bool checkROC(bool &errorsInEvent, int fedId, const SiPixelFrameConverter *converter, Word32 &errorWord, Errors &errors)
int sourceID()
Identifier of the FED.
Definition: FEDHeader.cc:30
bool checkCRC(bool &errorsInEvent, int fedId, const Word64 *trailer, Errors &errors)
Definition: ErrorChecker.cc:54
bool moreHeaders()
Definition: FEDHeader.cc:38
const int LINK_shift
Definition: ErrorChecker.cc:32
const ErrorChecker::Word32 ROC_mask
Definition: ErrorChecker.cc:39
std::map< uint32_t, DetErrors > Errors
Definition: ErrorChecker.h:27
const int ADC_shift
Definition: ErrorChecker.cc:28
const int ROC_bits
Definition: ErrorChecker.cc:22
uint64_t Word64
const ErrorChecker::Word32 PXID_mask
Definition: ErrorChecker.cc:41
void setErrorStatus(bool ErrorStatus)
Definition: ErrorChecker.cc:49
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
const int ADC_bits
Definition: ErrorChecker.cc:25
Definition: DetId.h:20
bool check()
Check that the header is OK.
Definition: FEDHeader.cc:66
const int LINK_bits
Definition: ErrorChecker.cc:21
int lenght()
The length of the event fragment counted in 64-bit words including header and trailer.
Definition: FEDTrailer.cc:19
const int CRC_shift
Definition: ErrorChecker.cc:27
void conversionError(int fedId, const SiPixelFrameConverter *converter, int status, Word32 &errorWord, Errors &errors)
const int ROC_shift
Definition: ErrorChecker.cc:31
const ErrorChecker::Word64 CRC_mask
Definition: ErrorChecker.cc:36
const ErrorChecker::Word32 ERROR_mask
Definition: ErrorChecker.cc:37
const ErrorChecker::Word32 LINK_mask
Definition: ErrorChecker.cc:38
int toDetector(const sipixelobjects::ElectronicIndex &cabling, sipixelobjects::DetectorIndex &detector) const
tuple status
Definition: ntuplemaker.py:245
uint32_t errorDetId(const SiPixelFrameConverter *converter, int errorType, const Word32 &word) const
const int PXID_bits
Definition: ErrorChecker.cc:24
Pixel error – collection of errors and error information.
const uint32_t dummyDetId
Definition: ErrorChecker.cc:34
bool checkHeader(bool &errorsInEvent, int fedId, const Word64 *header, Errors &errors)
Definition: ErrorChecker.cc:67
uint64_t Word64
Definition: ErrorChecker.h:24