CMS 3D CMS Logo

ErrorCheckerPhase0.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 ErrorCheckerPhase0::Word64 CRC_mask = ~(~ErrorCheckerPhase0::Word64(0) << CRC_bits);
40  constexpr ErrorCheckerPhase0::Word32 ERROR_mask = ~(~ErrorCheckerPhase0::Word32(0) << ROC_bits);
41  constexpr ErrorCheckerPhase0::Word32 LINK_mask = ~(~ErrorCheckerPhase0::Word32(0) << LINK_bits);
42  constexpr ErrorCheckerPhase0::Word32 ROC_mask = ~(~ErrorCheckerPhase0::Word32(0) << ROC_bits);
43  constexpr ErrorCheckerPhase0::Word32 OMIT_ERR_mask = ~(~ErrorCheckerPhase0::Word32(0) << OMIT_ERR_bits);
44 } // namespace
45 
46 ErrorCheckerPhase0::ErrorCheckerPhase0() { includeErrors = false; }
47 
48 void ErrorCheckerPhase0::setErrorStatus(bool ErrorStatus) { includeErrors = ErrorStatus; }
49 
50 bool ErrorCheckerPhase0::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 ErrorCheckerPhase0::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 ErrorCheckerPhase0::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  LogDebug("") << " invalid ROC=25 found (errorType=25)";
118  errorsInEvent = true;
119  break;
120  }
121  case (26): {
122  return false;
123  }
124  case (27): {
125  return false;
126  }
127  case (28): {
128  LogDebug("") << " error fifo nearly full (errorType=28)";
129  errorsInEvent = true;
130  break;
131  }
132  case (29): {
133  LogDebug("") << " timeout on a channel (errorType=29)";
134  errorsInEvent = true;
135  if ((errorWord >> OMIT_ERR_shift) & OMIT_ERR_mask) {
136  LogDebug("") << " ...first errorType=29 error, this gets masked out";
137  return false;
138  }
139  break;
140  }
141  case (30): {
142  LogDebug("") << " TBM error trailer (errorType=30)";
143  errorsInEvent = true;
144  break;
145  }
146  case (31): {
147  LogDebug("") << " event number error (errorType=31)";
148  errorsInEvent = true;
149  break;
150  }
151  default:
152  return true;
153  };
154 
155  if (includeErrors) {
156  // check to see if overflow error for type 30, change type to 40 if so
157  if (errorType == 30) {
158  int StateMach_bits = 4;
159  int StateMach_shift = 8;
160  uint32_t StateMach_mask = ~(~uint32_t(0) << StateMach_bits);
161  int StateMach = (errorWord >> StateMach_shift) & StateMach_mask;
162  if (StateMach == 4 || StateMach == 9)
163  errorType = 40;
164  }
165 
166  // store error
167  SiPixelRawDataError error(errorWord, errorType, fedId);
168  cms_uint32_t detId;
169  detId = errorDetId(converter, errorType, errorWord);
170  errors[detId].push_back(error);
171  }
172  return false;
173 }
174 
176  int fedId, const SiPixelFrameConverter* converter, int status, Word32& errorWord, Errors& errors) {
177  switch (status) {
178  case (1): {
179  LogDebug("ErrorCheckerPhase0::conversionError") << " Fed: " << fedId << " invalid channel Id (errorType=35)";
180  if (includeErrors) {
181  int errorType = 35;
182  SiPixelRawDataError error(errorWord, errorType, fedId);
183  cms_uint32_t detId = errorDetId(converter, errorType, errorWord);
184  errors[detId].push_back(error);
185  }
186  break;
187  }
188  case (2): {
189  LogDebug("ErrorCheckerPhase0::conversionError") << " Fed: " << fedId << " invalid ROC Id (errorType=36)";
190  if (includeErrors) {
191  int errorType = 36;
192  SiPixelRawDataError error(errorWord, errorType, fedId);
193  cms_uint32_t detId = errorDetId(converter, errorType, errorWord);
194  errors[detId].push_back(error);
195  }
196  break;
197  }
198  case (3): {
199  LogDebug("ErrorCheckerPhase0::conversionError")
200  << " Fed: " << fedId << " invalid dcol/pixel value (errorType=37)";
201  if (includeErrors) {
202  int errorType = 37;
203  SiPixelRawDataError error(errorWord, errorType, fedId);
204  cms_uint32_t detId = errorDetId(converter, errorType, errorWord);
205  errors[detId].push_back(error);
206  }
207  break;
208  }
209  case (4): {
210  LogDebug("ErrorCheckerPhase0::conversionError")
211  << " Fed: " << fedId << " dcol/pixel read out of order (errorType=38)";
212  if (includeErrors) {
213  int errorType = 38;
214  SiPixelRawDataError error(errorWord, errorType, fedId);
215  cms_uint32_t detId = errorDetId(converter, errorType, errorWord);
216  errors[detId].push_back(error);
217  }
218  break;
219  }
220  default:
221  LogDebug("ErrorCheckerPhase0::conversionError")
222  << " cabling check returned unexpected result, status = " << status;
223  };
224 }
225 
226 // this function finds the detId for an error word that cannot be processed in word2digi
228  int errorType,
229  const Word32& word) const {
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 if in Barrel
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  break;
251  if (DetId(detIdx.rawId).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel))
252  return detIdx.rawId;
253  break;
254  }
255  case 29: {
256  int chanNmbr = 0;
257  const int DB0_shift = 0;
258  const int DB1_shift = DB0_shift + 1;
259  const int DB2_shift = DB1_shift + 1;
260  const int DB3_shift = DB2_shift + 1;
261  const int DB4_shift = DB3_shift + 1;
262  const cms_uint32_t DataBit_mask = ~(~cms_uint32_t(0) << 1);
263 
264  int CH1 = (word >> DB0_shift) & DataBit_mask;
265  int CH2 = (word >> DB1_shift) & DataBit_mask;
266  int CH3 = (word >> DB2_shift) & DataBit_mask;
267  int CH4 = (word >> DB3_shift) & DataBit_mask;
268  int CH5 = (word >> DB4_shift) & DataBit_mask;
269  int BLOCK_bits = 3;
270  int BLOCK_shift = 8;
271  cms_uint32_t BLOCK_mask = ~(~cms_uint32_t(0) << BLOCK_bits);
272  int BLOCK = (word >> BLOCK_shift) & BLOCK_mask;
273  int localCH = 1 * CH1 + 2 * CH2 + 3 * CH3 + 4 * CH4 + 5 * CH5;
274  if (BLOCK % 2 == 0)
275  chanNmbr = (BLOCK / 2) * 9 + localCH;
276  else
277  chanNmbr = ((BLOCK - 1) / 2) * 9 + 4 + localCH;
278  if ((chanNmbr < 1) || (chanNmbr > 36))
279  break; // signifies unexpected result
280 
281  // set dummy values for cabling just to get detId from link if in Barrel
282  cabling.dcol = 0;
283  cabling.pxid = 2;
284  cabling.roc = 1;
285  cabling.link = chanNmbr;
286  DetectorIndex detIdx;
287  int status = converter->toDetector(cabling, detIdx);
288  if (status)
289  break;
290  if (DetId(detIdx.rawId).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel))
291  return detIdx.rawId;
292  break;
293  }
294  case 37:
295  case 38: {
296  cabling.dcol = 0;
297  cabling.pxid = 2;
298  cabling.roc = (word >> ROC_shift) & ROC_mask;
299  cabling.link = (word >> LINK_shift) & LINK_mask;
300 
301  DetectorIndex detIdx;
302  int status = converter->toDetector(cabling, detIdx);
303  if (status)
304  break;
305 
306  return detIdx.rawId;
307  break;
308  }
309  default:
310  break;
311  };
312  return dummyDetId;
313 }
cms_uint32_t
unsigned int cms_uint32_t
Definition: typedefs.h:15
ErrorCheckerPhase0
Definition: ErrorCheckerPhase0.h:11
PixelSubdetector.h
MessageLogger.h
PixelSubdetector::PixelBarrel
Definition: PixelSubdetector.h:11
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
ErrorCheckerPhase0::checkTrailer
bool checkTrailer(bool &errorsInEvent, int fedId, unsigned int nWords, const Word64 *trailer, Errors &errors) override
Definition: ErrorCheckerPhase0.cc:80
edm
HLT enums.
Definition: AlignableModifier.h:19
omtf::Word64
uint64_t Word64
Definition: OmtfDataWord64.h:11
sipixelobjects::ElectronicIndex::dcol
int dcol
Definition: ElectronicIndex.h:8
ErrorCheckerPhase0::conversionError
void conversionError(int fedId, const SiPixelFrameConverter *converter, int status, Word32 &errorWord, Errors &errors) override
Definition: ErrorCheckerPhase0.cc:175
SiPixelFedCabling
Definition: SiPixelFedCabling.h:10
relativeConstraints.error
error
Definition: relativeConstraints.py:53
ErrorCheckerBase::Word32
cms_uint32_t Word32
Definition: ErrorCheckerBase.h:18
FEDTrailer::check
bool check() const
Check that the trailer is OK.
Definition: FEDTrailer.cc:45
word
uint64_t word
Definition: CTPPSTotemDataFormatter.cc:29
DetId
Definition: DetId.h:17
ErrorCheckerPhase0::Word32
cms_uint32_t Word32
Definition: ErrorCheckerPhase0.h:13
errors
Definition: errors.py:1
sipixelobjects
Definition: CablingPathToDetUnit.h:4
sipixelobjects::ElectronicIndex::pxid
int pxid
Definition: ElectronicIndex.h:9
ErrorCheckerPhase0::ErrorCheckerPhase0
ErrorCheckerPhase0()
Definition: ErrorCheckerPhase0.cc:46
sipixelobjects::ElectronicIndex
Definition: ElectronicIndex.h:5
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
sipixelobjects::ElectronicIndex::link
int link
Definition: ElectronicIndex.h:6
ErrorCheckerPhase0::checkHeader
bool checkHeader(bool &errorsInEvent, int fedId, const Word64 *header, Errors &errors) override
Definition: ErrorCheckerPhase0.cc:63
SiPixelFrameConverter.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::LogError
Definition: MessageLogger.h:183
FEDTrailer
Definition: FEDTrailer.h:14
FEDTrailer::moreTrailers
bool moreTrailers() const
Definition: FEDTrailer.cc:21
SiPixelFrameConverter
Definition: SiPixelFrameConverter.h:15
l1tstage2_dqm_sourceclient-live_cfg.fedId
fedId
Definition: l1tstage2_dqm_sourceclient-live_cfg.py:88
ErrorCheckerPhase0::errorDetId
cms_uint32_t errorDetId(const SiPixelFrameConverter *converter, int errorType, const Word32 &word) const override
Definition: ErrorCheckerPhase0.cc:227
ErrorCheckerPhase0.h
std
Definition: JetResolutionObject.h:76
ErrorCheckerBase::Word64
cms_uint64_t Word64
Definition: ErrorCheckerBase.h:19
ErrorCheckerPhase0::checkCRC
bool checkCRC(bool &errorsInEvent, int fedId, const Word64 *trailer, Errors &errors) override
Definition: ErrorCheckerPhase0.cc:50
DetId.h
LIKELY
#define LIKELY(x)
Definition: Likely.h:20
ErrorCheckerPhase0::checkROC
bool checkROC(bool &errorsInEvent, int fedId, const SiPixelFrameConverter *converter, const SiPixelFedCabling *theCablingTree, Word32 &errorWord, Errors &errors) override
Definition: ErrorCheckerPhase0.cc:105
FEDHeader::check
bool check() const
Check that the header is OK.
Definition: FEDHeader.cc:44
ErrorCheckerBase::Errors
std::map< cms_uint32_t, DetErrors > Errors
Definition: ErrorCheckerBase.h:22
FEDHeader::sourceID
uint16_t sourceID() const
Identifier of the FED.
Definition: FEDHeader.cc:19
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:292
ErrorCheckerPhase0::setErrorStatus
void setErrorStatus(bool ErrorStatus) override
Definition: ErrorCheckerPhase0.cc:48
FEDHeader
Definition: FEDHeader.h:14
FEDHeader.h
ErrorCheckerPhase0::Word64
cms_uint64_t Word64
Definition: ErrorCheckerPhase0.h:14
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