Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DecodingStat.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DecodingStat.h
1 // @file DecodingStat.h
2 // @brief Alpide Chip and GBT link decoding statistics
3 // @sa <O2/Detectors/ITSMFT/common/reconstruction/include/ITSMFTReconstruction/DecodingStat.h>
4 // <5ca140c87>
5 
6 #ifndef MVTXDECODER_DECODINGSTAT_H
7 #define MVTXDECODER_DECODINGSTAT_H
8 
9 #define CXX_17 201703L
10 
11 #include <string>
12 #include <array>
13 #include <cstring>
14 
15 namespace mvtx
16 {
17 class ChipPixelData;
18 
19 struct ChipStat {
20  enum ActionOnError : int {
21  ErrActNone = 0x0, // do nothing
22  ErrActPropagate = 0x1, // propagate to decoded data
23  ErrActDump = 0x2 // produce raw data dump
24  };
25 
26  enum DecErrors : int {
27  BusyViolation, // Busy violation
28  DataOverrun, // Data overrun
29  Fatal, // Fatal (?)
30  BusyOn, // Busy On
31  BusyOff, // Busy Off
32  TruncatedChipEmpty, // Data was truncated after ChipEmpty
33  TruncatedChipHeader, // Data was truncated after ChipHeader
34  TruncatedRegion, // Data was truncated after Region record
35  TruncatedLondData, // Data was truncated in the LongData record
36  WrongDataLongPattern, // LongData pattern has highest bit set
37  NoDataFound, // Region is not followed by Short or Long data
38  UnknownWord, // Unknown word was seen
39  RepeatingPixel, // Same pixel fired more than once
40  WrongRow, // Non-existing row decoded
41  APE_STRIP, // lane data stripped for this chip event (behaviour changed with RU FW v1.16.0, for general APE behaviour see https://alice.its.cern.ch/jira/browse/O2-1717)
42  APE_RESERVED_F3, // reserved F3
43  APE_DET_TIMEOUT, // detector timeout (FATAL)
44  APE_OOT_START, // 8b10b OOT (FATAL, start)
45  APE_PROTOCOL_ERROR, // event protocol error marker (FATAL, start)
46  APE_LANE_FIFO_OVERFLOW_ERROR, // lane FIFO overflow error (FATAL)
47  APE_FSM_ERROR, // FSM error (FATAL, SEU error, reached an unknown state)
48  APE_OCCUPANCY_RATE_LIMIT, // pending detector events limit (FATAL)
49  APE_OCCUPANCY_RATE_LIMIT_2, // pending detector events limit in packager(FATAL)
50  APE_LANE_PROTOCOL_ERROR, // lane protocol error
51  APE_RESERVED_FC, // reserved FC
52  APE_ERROR_NON_CRITICAL_BYTE, // Error in non critical byte
53  APE_OOT_NON_CRITICAL, // OOT non-critical
54  WrongDColOrder, // DColumns non increasing
55  InterleavedChipData, // Chip data interleaved on the cable
56  TruncatedBuffer, // truncated buffer, 0 padding
57  TrailerAfterHeader, // trailer seen after header w/o FE of FD set
59  };
60 
61 #if ( __cplusplus >= CXX_17 )
62  static constexpr std::array<std::string_view, NErrorsDefined> ErrNames = {
63 #else
64  const std::array<const std::string, NErrorsDefined> ErrNames = {
65 #endif
66  "BusyViolation flag ON", // BusyViolation
67  "DataOverrun flag ON", // DataOverrun
68  "Fatal flag ON", // Fatal
69  "BusyON", // BusyOn
70  "BusyOFF", // BusyOff
71  "Data truncated after ChipEmpty", // TruncatedChipEmpty
72  "Data truncated after ChipHeader", // TruncatedChipHeader
73  "Data truncated after Region", // TruncatedRegion
74  "Data truncated after LongData", // TruncatedLondData
75  "LongData pattern has highest bit set", // WrongDataLongPattern
76  "Region is not followed by Short or Long data", // NoDataFound
77  "Unknown word", // UnknownWord
78  "Same pixel fired multiple times", // RepeatingPixel
79  "Non-existing row decoded", // WrongRow
80  "APE_STRIP", // lane data stripped for this chip event (behaviour changed with RU FW v1.16.0, for general APE behaviour see https://alice.its.cern.ch/jira/browse/O2-1717)
81  "APE_RESERVED_F3", // reserved F3
82  "APE_DET_TIMEOUT", // detector timeout (FATAL)
83  "APE_OOT_START", // 8b10b OOT (FATAL, start)
84  "APE_PROTOCOL_ERROR", // event event protocol error marker (FATAL, start)
85  "APE_LANE_FIFO_OVERFLOW_ERROR", // lane FIFO overflow error (FATAL)
86  "APE_FSM_ERROR", // FSM error (FATAL, SEU error, reached an unknown state)
87  "APE_OCCUPANCY_RATE_LIMIT", // pending detector events limit (FATAL)
88  "APE_OCCUPANCY_RATE_LIMIT_2", // pending detector events limit in packager(FATAL)
89  "APE_LANE_PROTOCOL_ERROR", // lane protocol error
90  "APE_RESERVED_FC", // reserved
91  "APE_ERROR_IN_NON_CRITICAL_BYTE", // Error in non critical byte
92  "APE_OOT_NON_CRITICAL", // OOT non-critical
93  "DColumns non-increasing", // DColumns non increasing
94  "Chip data interleaved on the cable", // Chip data interleaved on the cable
95  "TruncatedBuffer", // truncated buffer, 0 padding
96  "TrailerAfterHeader" // trailer seen after header w/o FE of FD set
97  };
98 
99  static constexpr std::array<uint32_t, NErrorsDefined> ErrActions = {
100  ErrActPropagate | ErrActDump, // Busy violation
101  ErrActPropagate | ErrActDump, // Data overrun
102  ErrActPropagate | ErrActDump, // Fatal (?)
103  ErrActNone, // Busy On
104  ErrActNone, // Busy Off
105  ErrActPropagate | ErrActDump, // Data was truncated after ChipEmpty
106  ErrActPropagate | ErrActDump, // Data was truncated after ChipHeader
107  ErrActPropagate | ErrActDump, // Data was truncated after Region record
108  ErrActPropagate | ErrActDump, // Data was truncated in the LongData record
109  ErrActPropagate | ErrActDump, // LongData pattern has highest bit set
110  ErrActPropagate | ErrActDump, // Region is not followed by Short or Long data
111  ErrActPropagate | ErrActDump, // Unknown word was seen
112  ErrActPropagate, // Same pixel fired more than once
113  ErrActPropagate | ErrActDump, // Non-existing row decoded
114  ErrActPropagate | ErrActDump, // lane data stripped for this chip event (behaviour changed with RU FW v1.16.0, for general APE behaviour see https://alice.its.cern.ch/jira/browse/O2-1717)
115  ErrActPropagate | ErrActDump, // reserved F3
116  ErrActPropagate | ErrActDump, // detector timeout (FATAL)
117  ErrActPropagate | ErrActDump, // 8b10b OOT (FATAL, start)
118  ErrActPropagate | ErrActDump, // event protocol error marker (FATAL, start)
119  ErrActPropagate | ErrActDump, // lane FIFO overflow error (FATAL)
120  ErrActPropagate | ErrActDump, // FSM error (FATAL, SEU error, reached an unknown state)
121  ErrActPropagate | ErrActDump, // pending detector events limit (FATAL)
122  ErrActPropagate | ErrActDump, // pending detector events limit in packager(FATAL)
123  ErrActPropagate | ErrActDump, // lane protocol error
124  ErrActPropagate | ErrActDump, // reserved FC
125  ErrActPropagate | ErrActDump, // Error in non critical byte
126  ErrActPropagate | ErrActDump, // OOT non-critical
127  ErrActPropagate | ErrActDump, // DColumns non increasing
128  ErrActPropagate | ErrActDump, // Chip data interleaved on the cable
129  ErrActPropagate | ErrActDump, // Truncated buffer while something was expected
130  ErrActPropagate | ErrActDump // trailer seen after header w/o FE of FD set
131  };
132  uint16_t feeID = -1;
133  size_t nHits = 0;
134  std::array<uint32_t, NErrorsDefined> errorCounts = {};
135  ChipStat() = default;
136  ChipStat(uint16_t _feeID) : feeID(_feeID) {}
137 
138  void clear()
139  {
140  memset(errorCounts.data(), 0, sizeof(uint32_t) * errorCounts.size());
141  nHits = 0;
142  }
143 
144  static int getAPENonCritical(uint8_t c)
145  {
146  if (c == 0xfd || c == 0xfe) {
147  return APE_STRIP + c - 0xf2;
148  }
149  return -1;
150  }
151 
152  // return APE DecErrors code or -1 if not APE error, set fatal flag if needd
153  static int getAPECode(uint8_t c, bool& ft)
154  {
155  if (c < 0xf2 || c > 0xfe) {
156  ft = false;
157  return -1;
158  }
159  ft = c >= 0xf2 && c <= 0xfe;
160  return APE_STRIP + c - 0xf2;
161  }
162  uint32_t getNErrors() const;
163  uint32_t addErrors(uint32_t mask, uint16_t chID, int verbosity);
164  uint32_t addErrors(const ChipPixelData& d, int verbosity);
165  void print(bool skipNoErr = true, const std::string& pref = "FEEID") const;
166 
167 // ClassDefNV(ChipStat, 1);
168 };
169 
170 struct ChipError {
171  uint32_t id = -1;
172  uint32_t nerrors = 0;
173  uint32_t errors = 0;
174 
175  int16_t getChipID() const { return int16_t(id & 0xffff); }
176  uint16_t getFEEID() const { return uint16_t(id >> 16); }
177  static uint32_t composeID(uint16_t feeID, int16_t chipID) { return uint32_t(feeID) << 16 | uint16_t(chipID); }
178 // ClassDefNV(ChipError, 1);
179 };
180 
184 
185  enum DecErrors : int {
186  ErrNoRDHAtStart, // page does not start with RDH
187  ErrPageNotStopped, // RDH is stopped, but the time is not matching the ~stop packet
188  ErrStopPageNotEmpty, // Page with RDH.stop is not empty
189  ErrPageCounterDiscontinuity, // RDH page counters for the same RU/trigger are not continuous
190  ErrRDHvsGBTHPageCnt, // RDH and GBT header page counters are not consistent
191  ErrMissingGBTTrigger, // GBT trigger word was expected but not found
192  ErrMissingGBTHeader, // GBT payload header was expected but not found
193  ErrMissingGBTTrailer, // GBT payload trailer was expected but not found
194  ErrNonZeroPageAfterStop, // all lanes were stopped but the page counter in not 0
195  ErrUnstoppedLanes, // end of FEE data reached while not all lanes received stop
196  ErrDataForStoppedLane, // data was received for stopped lane
197  ErrNoDataForActiveLane, // no data was seen for lane (which was not in timeout)
198  ErrIBChipLaneMismatch, // chipID (on module) was different from the lane ID on the IB stave
199  ErrCableDataHeadWrong, // cable data does not start with chip header or empty chip
200  ErrInvalidActiveLanes, // active lanes pattern conflicts with expected for given RU type
201  ErrPacketCounterJump, // jump in RDH.packetCounter
202  ErrPacketDoneMissing, // packet done is missing in the trailer while CRU page is not over
203  ErrMissingDiagnosticWord, // missing diagnostic word after RDH with stop
204  ErrGBTWordNotRecognized, // GBT word not recognized
205  ErrWrongeCableID, // Invalid cable ID
206  ErrWrongAlignmentWord, // unexpected alignment word
207  ErrMissingROF, // missing ROF (desync?)
208  ErrOldROF, // old ROF (desync?)
210  };
211 
212 #if ( __cplusplus >= CXX_17 )
213  static constexpr std::array<std::string_view, NErrorsDefined> ErrNames = {
214 #else
215  const std::array<std::string, NErrorsDefined> ErrNames = {
216 #endif
217  "Page data not start with expected RDH", // ErrNoRDHAtStart
218  "RDH is stopped, but the time is not matching the stop packet", // ErrPageNotStopped
219  "Page with RDH.stop does not contain diagnostic word only", // ErrStopPageNotEmpty
220  "RDH page counters for the same RU/trigger are not continuous", // ErrPageCounterDiscontinuity
221  "RDH and GBT header page counters are not consistent", // ErrRDHvsGBTHPageCnt
222  "GBT trigger word was expected but not found", // ErrMissingGBTTrigger
223  "GBT payload header was expected but not found", // ErrMissingGBTHeader
224  "GBT payload trailer was expected but not found", // ErrMissingGBTTrailer
225  "All lanes were stopped but the page counter in not 0", // ErrNonZeroPageAfterStop
226  "End of FEE data reached while not all lanes received stop", // ErrUnstoppedLanes
227  "Data was received for stopped lane", // ErrDataForStoppedLane
228  "No data was seen for lane (which was not in timeout)", // ErrNoDataForActiveLane
229  "ChipID (on module) was different from the lane ID on the IB stave", // ErrIBChipLaneMismatch
230  "Cable data does not start with chip header or empty chip", // ErrCableDataHeadWrong
231  "Active lanes pattern conflicts with expected for given RU type", // ErrInvalidActiveLanes
232  "Jump in RDH_packetCounter", // ErrPacketCounterJump
233  "Packet done is missing in the trailer while CRU page is not over", // ErrPacketDoneMissing
234  "Missing diagnostic GBT word after RDH with stop", // ErrMissingDiagnosticWord
235  "GBT word not recognized", // ErrGBTWordNotRecognized
236  "Wrong cable ID" // ErrWrongeCableID
237  "Unexpected CRU page alignment padding word", // ErrWrongAlignmentWord
238  "ROF in future, pause decoding to synchronize", // ErrMissingROF
239  "Old ROF, discarding", // ErrOldROF
240  };
241 
242  enum BitMaps : int {
243  ORBIT = 0,
244  HB = 1,
245  HBr = 2,
246  HC = 3,
247  PHYSICS = 4,
248  PP = 5,
249  CAL = 6,
250  SOT = 7,
251  EOT = 8,
252  SOC = 9,
253  EOC = 10,
254  TF = 11,
255  FE_RST = 12,
256  RT = 13,
257  RS = 14,
258  nBitMap = 15
259  };
260 
261 #if ( __cplusplus >= CXX_17 )
262  static constexpr std::array<std::string_view, nBitMap> BitMapName = {
263 #else
264  const std::array<std::string, nBitMap> BitMapName = {
265 #endif
266  "ORBIT",
267  "HB",
268  "HBr",
269  "HC",
270  "PHYSICS",
271  "PP",
272  "CAL",
273  "SOT",
274  "EOT",
275  "SOC",
276  "EOC",
277  "TF",
278  "FE_RST",
279  "RT",
280  "RS"
281  };
282 
283  uint16_t feeID = 0; // FeeID
284  std::array<uint32_t, NErrorsDefined> errorCounts = {}; // error counters
285  std::array<uint32_t, nBitMap> trgBitCounts = {};
286 
287  void clear()
288  {
289  errorCounts.fill(0);
290  trgBitCounts.fill(0);
291  }
292 
293  void print(bool skipNoErr = true) const;
294 
295 // ClassDefNV(GBTLinkDecodingStat, 2);
296 };
297 
298 } // namespace mvtx
299 #endif