Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GBTLink.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GBTLink.cxx
1 // @file GBTLink.cxx
2 // @brief Definitions of GBTLink class used for the ITS/MFT raw data decoding
3 // @sa <O2/Detectors/ITSMFT/common/reconstruction/src/GBTLink.cxx>
4 // <e5b583efa>
5 
6 #include "mvtx_decoder/GBTLink.h"
7 
8 #include <bitset>
9 
10 using namespace mvtx;
11 
12 //using RDHUtils = mvtx::RDHUtils;
13 //using RDH = mvtx::RAWDataHeader;
14 
18 
21 GBTLink::GBTLink(uint16_t _flx, uint16_t _fee) : flxId(_flx), feeId(_fee)
22 {
23 // chipStat.feeID = _fee;
24 // statistics.feeID = _fee;
26 }
27 
30 //std::string GBTLink::describe() const
31 //{
32 // std::string ss = fmt::format("link cruID:{:#06x}/lID{} feeID:{:#06x}", cruID, int(idInCRU), feeID);
33 // if (lanes) {
34 // ss += fmt::format(" lanes {}", std::bitset<28>(lanes).to_string());
35 // }
36 // return ss;
37 //}
38 
41 void GBTLink::clear(bool resetStat, bool resetTFRaw)
42 {
43  if ( data.isEmpty() )
44  {
45  data.clear();
46  }
47  else
48  {
50 // std::cout << "Link: " << feeID << " buffer Size: " << data.getSize() << std::endl;
51  }
52 
53  if (resetTFRaw)
54  {
55  rawData.clear();
56  mL1TrgTime.clear();
57  mTrgData.clear();
58  for ( auto&& hit : hit_vector )
59  {
60  delete hit;
61  }
62  hit_vector.clear();
63  dataOffset = 0;
64  hbf_count = 0;
65  }
66 
67  if (resetStat)
68  {
69  statistics.clear();
70  }
71  hbfEntry = 0;
72  status = None;
73 }
74 
77 int GBTLink::readFlxWord( GBTWord* gbtwords, uint16_t &w16 )
78 {
79  for ( uint8_t k = 0; k < 3; k++ )
80  {
81  gbtwords[k] = *(reinterpret_cast<GBTWord*>(data.getPtr() + dataOffset));
82  dataOffset +=10;
83  }
84 
85  w16 = *(reinterpret_cast<uint16_t*>(data.getPtr() + dataOffset));
86  dataOffset += 2;
87  return 0;
88 }
89 
90 //
92 //void GBTLink::printTrigger(const GBTTrigger* gbtTrg, int offs)
93 //{
94 // std::bitset<12> trb(gbtTrg->triggerType);
95 // LOG(info) << "Offs: " << offs << " Trigger : Orbit " << gbtTrg->orbit << " BC: " << gbtTrg->bc << " Trigger: " << trb << " noData:"
96 // << gbtTrg->noData << " internal:" << gbtTrg->internal << " continuation:" << gbtTrg->continuation << " on " << describe();
97 // gbtTrg->printX();
98 //}
99 //
101 //void GBTLink::printCalibrationWord(const GBTCalibration* gbtCal, int offs)
102 //{
103 // LOGP(info, "Offs: {} Calibration word {:5} | user_data {:#08x} on {}", offs, gbtCal->calibCounter, gbtCal->calibUserField, describe());
104 // gbtCal->printX();
105 //}
106 //
108 //void GBTLink::printHeader(const GBTDataHeader* gbtH, int offs)
109 //{
110 // std::bitset<28> LA(gbtH->activeLanes);
111 // LOG(info) << "Offs: " << offs << " Header : Active Lanes " << LA << " on " << describe();
112 // gbtH->printX();
113 //}
114 //
122 //
124 //void GBTLink::printTrailer(const GBTDataTrailer* gbtT, int offs)
125 //{
126 // std::bitset<28> LT(gbtT->lanesTimeout), LS(gbtT->lanesStops); // RSTODO
127 // LOG(info) << "Offs: " << offs << " Trailer: Done=" << gbtT->packetDone << " Lanes TO: " << LT << " | Lanes ST: " << LS << " on " << describe();
128 // gbtT->printX();
129 //}
130 //
132 //void GBTLink::printDiagnostic(const GBTDiagnostic* gbtD, int offs)
133 //{
134 // LOG(info) << "Offs: " << offs << " Diagnostic word on " << describe();
135 // gbtD->printX();
136 //}
137 //
139 //void GBTLink::printCableDiagnostic(const GBTCableDiagnostic* gbtD)
140 //{
141 // LOGP(info, "Diagnostic for {} Lane {} | errorID: {} data {:#018x} on {}", "IB", gbtD->getCableID(), gbtD->laneErrorID, gbtD->diagnosticData, describe());
142 // gbtD->printX();
143 //}
144 //
146 //void GBTLink::printCableStatus(const GBTCableStatus* gbtS)
147 //{
148 // LOGP(info, "Status data, not processed at the moment, on {}", describe());
149 // gbtS->printX();
150 //}
151 //
153 
154 #ifdef _RAW_READER_ERROR_CHECKS_
155 
158 //uint8_t GBTLink::checkErrorsRDH(const RDH& rdh)
159 //{
160 // uint8_t err = uint8_t(NoError);
161 // if (!RDHUtils::checkRDH(rdh, true)) {
162 // statistics.errorCounts[GBTLinkDecodingStat::ErrNoRDHAtStart]++;
163 // gbtErrStatUpadated = true;
164 // if (needToPrintError(statistics.errorCounts[GBTLinkDecodingStat::ErrNoRDHAtStart])) {
165 // err |= uint8_t(ErrorPrinted);
166 // LOG(info) << describe() << ' ' << irHBF << ' ' << statistics.ErrNames[GBTLinkDecodingStat::ErrNoRDHAtStart];
167 // }
168 // errorBits |= 0x1 << int(GBTLinkDecodingStat::ErrNoRDHAtStart);
169 // err |= uint8_t(Abort);
170 // return err; // fatal error
171 // }
172 // /*
173 // if ((RDHUtils::getPacketCounter(rdh) > packetCounter + 1) && packetCounter >= 0) {
174 // if (irHBF.isDummy()) {
175 // irHBF = RDHUtils::getHeartBeatIR(rdh);
176 // }
177 // statistics.errorCounts[GBTLinkDecodingStat::ErrPacketCounterJump]++;
178 // gbtErrStatUpadated = true;
179 // if (needToPrintError(statistics.errorCounts[GBTLinkDecodingStat::ErrPacketCounterJump])) {
180 // LOG(info) << describe() << ' ' << irHBF << ' ' << statistics.ErrNames[GBTLinkDecodingStat::ErrPacketCounterJump]
181 // << " : jump from " << int(packetCounter) << " to " << int(RDHUtils::getPacketCounter(rdh));
182 // err |= uint8_t(ErrorPrinted);
183 // }
184 // errorBits |= 0x1 << int(GBTLinkDecodingStat::ErrPacketCounterJump);
185 // err |= uint8_t(Warning);
186 // }
187 // packetCounter = RDHUtils::getPacketCounter(rdh);
188 // */
189 // return err;
190 //}
191 //
193 //uint8_t GBTLink::checkErrorsAlignmentPadding()
194 //{
207 // return err;
208 //}
209 //
212 //uint8_t GBTLink::checkErrorsRDHStop(const RDH& rdh)
213 //{
214 // uint8_t err = uint8_t(NoError);
215 // if (lastRDH && RDHUtils::getLHCBC(*lastRDH) != RDHUtils::getLHCBC(rdh)
216 // && !RDHUtils::getStopBit(*lastRDH)) {
217 // statistics.errorCounts[GBTLinkDecodingStat::ErrPageNotStopped]++;
218 // gbtErrStatUpadated = true;
219 // if (needToPrintError(statistics.errorCounts[GBTLinkDecodingStat::ErrPageNotStopped])) {
220 // LOG(info) << describe() << ' ' << irHBF << ' ' << statistics.ErrNames[GBTLinkDecodingStat::ErrPageNotStopped];
221 // RDHUtils::printRDH(*lastRDH);
222 // RDHUtils::printRDH(rdh);
223 // err |= uint8_t(ErrorPrinted);
224 // }
225 // errorBits |= 0x1 << int(GBTLinkDecodingStat::ErrPageNotStopped);
226 // err |= uint8_t(Warning);
227 // }
228 // return err;
229 //}
230 //
233 //uint8_t GBTLink::checkErrorsRDHStopPageEmpty(const RDH& rdh)
234 //{
235 // uint8_t err = uint8_t(NoError);
236 // if (RDHUtils::getStopBit(rdh) && RDHUtils::getPacketSize(rdh) != sizeof(RDH) + sizeof(FLXWord)) { // there could be only 1 diagnostic GBTWord after stop
237 // statistics.errorCounts[GBTLinkDecodingStat::ErrStopPageNotEmpty]++;
238 // gbtErrStatUpadated = true;
239 // if (needToPrintError(statistics.errorCounts[GBTLinkDecodingStat::ErrStopPageNotEmpty])) {
240 // LOG(info) << describe() << ' ' << irHBF << ' ' << statistics.ErrNames[GBTLinkDecodingStat::ErrStopPageNotEmpty];
241 // RDHUtils::printRDH(rdh);
242 // err |= uint8_t(ErrorPrinted);
243 // }
244 // errorBits |= 0x1 << int(GBTLinkDecodingStat::ErrStopPageNotEmpty);
245 // err |= uint8_t(Warning);
246 // }
247 // return err;
248 //}
249 //
252 //uint8_t GBTLink::checkErrorsTriggerWord(const GBTTrigger* gbtTrg)
253 //{
254 // uint8_t err = uint8_t(NoError);
255 // if (!gbtTrg->isTriggerWord()) { // check trigger word
256 // statistics.errorCounts[GBTLinkDecodingStat::ErrMissingGBTTrigger]++;
257 // gbtErrStatUpadated = true;
258 // if (needToPrintError(statistics.errorCounts[GBTLinkDecodingStat::ErrMissingGBTTrigger])) {
259 // gbtTrg->printX();
260 // LOG(info) << describe() << ' ' << irHBF << ' ' << statistics.ErrNames[GBTLinkDecodingStat::ErrMissingGBTTrigger];
261 // err |= uint8_t(ErrorPrinted);
262 // }
263 // errorBits |= 0x1 << int(GBTLinkDecodingStat::ErrMissingGBTTrigger);
264 // err |= uint8_t(Abort);
265 // }
266 // return err;
267 //}
268 //
271 //uint8_t GBTLink::checkErrorsCalibrationWord(const GBTCalibration* gbtCal)
272 //{
273 // // at the moment do nothing
274 // return uint8_t(NoError);
275 //}
276 //
279 //uint8_t GBTLink::checkErrorsHeaderWord(const GBTDataHeader* gbtH)
280 //{
281 // uint8_t err = uint8_t(NoError);
282 // if (!gbtH->isDataHeader()) { // check header word
283 // statistics.errorCounts[GBTLinkDecodingStat::ErrMissingGBTHeader]++;
284 // gbtErrStatUpadated = true;
285 // if (needToPrintError(statistics.errorCounts[GBTLinkDecodingStat::ErrMissingGBTHeader])) {
286 // gbtH->printX();
287 // LOG(info) << describe() << ' ' << irHBF << ' ' << statistics.ErrNames[GBTLinkDecodingStat::ErrMissingGBTHeader];
288 // err |= uint8_t(ErrorPrinted);
289 // }
290 // errorBits |= 0x1 << int(GBTLinkDecodingStat::ErrMissingGBTHeader);
291 // err |= uint8_t(Abort);
292 // }
293 // return err;
294 //}
295 //
298 //uint8_t GBTLink::checkErrorsActiveLanes(int cbl)
299 //{
300 // uint8_t err = uint8_t(NoError);
301 // if (~cbl & lanesActive) { // are there wrong lanes?
302 // statistics.errorCounts[GBTLinkDecodingStat::ErrInvalidActiveLanes]++;
303 // gbtErrStatUpadated = true;
304 // if (needToPrintError(statistics.errorCounts[GBTLinkDecodingStat::ErrInvalidActiveLanes])) {
305 // std::bitset<32> expectL(cbl), gotL(lanesActive);
306 // LOG(info) << describe() << ' ' << irHBF << ' ' << statistics.ErrNames[GBTLinkDecodingStat::ErrInvalidActiveLanes] << ' '
307 // << gotL << " vs " << expectL << " skip page";
308 // err |= uint8_t(ErrorPrinted);
309 // }
310 // errorBits |= 0x1 << int(GBTLinkDecodingStat::ErrInvalidActiveLanes);
311 // err |= uint8_t(Warning);
312 // }
313 // return err;
314 //}
315 //
318 //uint8_t GBTLink::checkErrorsGBTData(int cablePos)
319 //{
320 // uint8_t err = uint8_t(NoError);
321 // lanesWithData |= 0x1 << cablePos; // flag that the data was seen on this lane
322 // if (lanesStop & (0x1 << cablePos)) { // make sure stopped lanes do not transmit the data
323 // statistics.errorCounts[GBTLinkDecodingStat::ErrDataForStoppedLane]++;
324 // gbtErrStatUpadated = true;
325 // if (needToPrintError(statistics.errorCounts[GBTLinkDecodingStat::ErrDataForStoppedLane])) {
326 // LOG(info) << describe() << ' ' << irHBF << ' ' << statistics.ErrNames[GBTLinkDecodingStat::ErrDataForStoppedLane] << cablePos;
327 // err |= uint8_t(ErrorPrinted);
328 // }
329 // errorBits |= 0x1 << int(GBTLinkDecodingStat::ErrDataForStoppedLane);
330 // err |= uint8_t(Warning);
331 // }
332 //
333 // return err;
334 //}
335 //
338 //uint8_t GBTLink::checkErrorsGBTDataID(const GBTData* gbtD)
339 //{
340 // if (gbtD->isData()) {
341 // return uint8_t(NoError);
342 // }
343 // uint8_t err = uint8_t(NoError);
344 // statistics.errorCounts[GBTLinkDecodingStat::ErrGBTWordNotRecognized]++;
345 // gbtErrStatUpadated = true;
346 // if (needToPrintError(statistics.errorCounts[GBTLinkDecodingStat::ErrGBTWordNotRecognized])) {
347 // if (gbtD->isCableDiagnostic()) {
348 // printCableDiagnostic((GBTCableDiagnostic*)gbtD);
349 // } else if (gbtD->isStatus()) {
350 // printCableStatus((GBTCableStatus*)gbtD);
351 // }
352 // gbtD->printX();
353 // LOG(info) << describe() << ' ' << irHBF << ' ' << statistics.ErrNames[GBTLinkDecodingStat::ErrGBTWordNotRecognized];
354 // err |= uint8_t(ErrorPrinted);
355 // }
356 // err |= uint8_t(Skip);
357 // return err;
358 //}
359 //
362 //uint8_t GBTLink::checkErrorsTrailerWord(const GBTDataTrailer* gbtT)
363 //{
364 // uint8_t err = uint8_t(NoError);
365 // if (!gbtT->isDataTrailer()) {
366 // gbtT->printX();
367 // statistics.errorCounts[GBTLinkDecodingStat::ErrMissingGBTTrailer]++;
368 // gbtErrStatUpadated = true;
369 // if (needToPrintError(statistics.errorCounts[GBTLinkDecodingStat::ErrMissingGBTTrailer])) {
370 // LOG(info) << describe() << ' ' << irHBF << ' ' << statistics.ErrNames[GBTLinkDecodingStat::ErrMissingGBTTrailer];
371 // err |= uint8_t(ErrorPrinted);
372 // }
373 // errorBits |= 0x1 << int(GBTLinkDecodingStat::ErrMissingGBTTrailer);
374 // err |= uint8_t(Abort);
375 // return err;
376 // }
377 // lanesStatus |= gbtT->lanesStatus; // register timeouts
378 // return err;
379 //}
380 //
383 //uint8_t GBTLink::checkErrorsPacketDoneMissing(const GBTDataTrailer* gbtT, bool notEnd)
384 //{
385 // uint8_t err = uint8_t(NoError);
386 // if (!gbtT || (!gbtT->packetDone && notEnd)) { // Done may be missing only in case of carry-over to new CRU page
387 // statistics.errorCounts[GBTLinkDecodingStat::ErrPacketDoneMissing]++;
388 // gbtErrStatUpadated = true;
389 // if (needToPrintError(statistics.errorCounts[GBTLinkDecodingStat::ErrPacketDoneMissing])) {
390 // LOG(info) << describe() << ' ' << irHBF << ' ' << statistics.ErrNames[GBTLinkDecodingStat::ErrPacketDoneMissing];
391 // err |= uint8_t(ErrorPrinted);
392 // }
393 // errorBits |= 0x1 << int(GBTLinkDecodingStat::ErrPacketDoneMissing);
394 // err |= uint8_t(Warning);
395 // }
396 // return err;
397 //}
398 //
401 //uint8_t GBTLink::checkErrorsLanesStops()
402 //{
403 // // make sure all lane stops for finished page are received
404 // uint8_t err = uint8_t(NoError);
405 // if ((lanesActive & ~lanesStop)) {
406 // if (RDHUtils::getTrgType(*lastRDH) != mvtx::TrgBitMap::SOT) { // only SOT trigger allows unstopped lanes?
407 // statistics.errorCounts[GBTLinkDecodingStat::ErrUnstoppedLanes]++;
408 // gbtErrStatUpadated = true;
409 // if (needToPrintError(statistics.errorCounts[GBTLinkDecodingStat::ErrUnstoppedLanes])) {
410 // std::bitset<32> active(lanesActive), stopped(lanesStop);
411 // LOG(info) << describe() << ' ' << irHBF << ' ' << statistics.ErrNames[GBTLinkDecodingStat::ErrUnstoppedLanes]
412 // << " | active: " << active << " stopped: " << stopped;
413 // err |= uint8_t(ErrorPrinted);
414 // }
415 // errorBits |= 0x1 << int(GBTLinkDecodingStat::ErrUnstoppedLanes);
416 // }
417 // err |= uint8_t(Warning);
418 // }
419 // // make sure all active lanes (except those in time-out) have sent some data
420 // if ((~lanesWithData & lanesActive) != lanesTimeOut) {
421 // statistics.errorCounts[GBTLinkDecodingStat::ErrNoDataForActiveLane]++;
422 // gbtErrStatUpadated = true;
423 // if (needToPrintError(statistics.errorCounts[GBTLinkDecodingStat::ErrNoDataForActiveLane])) {
424 // std::bitset<32> withData(lanesWithData), active(lanesActive), timeOut(lanesTimeOut);
425 // LOG(info) << describe() << ' ' << irHBF << ' ' << statistics.ErrNames[GBTLinkDecodingStat::ErrNoDataForActiveLane]
426 // << " | with data: " << withData << " active: " << active << " timeOut: " << timeOut;
427 // err |= uint8_t(ErrorPrinted);
428 // }
429 // errorBits |= 0x1 << int(GBTLinkDecodingStat::ErrNoDataForActiveLane);
430 // err |= uint8_t(Warning);
431 // }
432 // return err;
433 //}
434 //
437 //uint8_t GBTLink::checkErrorsDiagnosticWord(const GBTDiagnostic* gbtD)
438 //{
439 // uint8_t err = uint8_t(NoError);
440 // if (RDHUtils::getPacketSize(lastRDH) != sizeof(RDH) + sizeof(FLXWord) || !gbtD->isDiagnosticWord()) { //
441 // statistics.errorCounts[GBTLinkDecodingStat::ErrMissingDiagnosticWord]++;
442 // gbtErrStatUpadated = true;
443 // if (needToPrintError(statistics.errorCounts[GBTLinkDecodingStat::ErrMissingDiagnosticWord])) {
444 // gbtD->printX();
445 // LOG(info) << describe() << ' ' << irHBF << ' ' << statistics.ErrNames[GBTLinkDecodingStat::ErrMissingDiagnosticWord];
446 // err |= uint8_t(ErrorPrinted);
447 // }
448 // errorBits |= 0x1 << int(GBTLinkDecodingStat::ErrMissingDiagnosticWord);
449 // err |= uint8_t(Abort);
450 // }
451 // return err;
452 //}
453 //
456 //uint8_t GBTLink::checkErrorsCableID(const GBTData* gbtD, uint8_t cableSW)
457 //{
458 // uint8_t err = uint8_t(NoError);
459 // if (cableSW == 0xff) {
460 // statistics.errorCounts[GBTLinkDecodingStat::ErrWrongeCableID]++;
461 // gbtErrStatUpadated = true;
462 // if (needToPrintError(statistics.errorCounts[GBTLinkDecodingStat::ErrWrongeCableID])) {
463 // gbtD->printX();
464 // LOG(info) << describe() << ' ' << irHBF << ' ' << statistics.ErrNames[GBTLinkDecodingStat::ErrWrongeCableID] << ' ' << gbtD->getCableID();
465 // err |= uint8_t(ErrorPrinted);
466 // }
467 // errorBits |= 0x1 << int(GBTLinkDecodingStat::ErrWrongeCableID);
468 // err |= uint8_t(Skip);
469 // }
470 // return err;
471 //}
472 
473 #endif