1111
1212// / \file RawDataDecoder.cxx
1313// / \author Roman Lietava
14-
14+ # include < fstream >
1515#include " DetectorsRaw/RDHUtils.h"
1616#include " CTPReconstruction/RawDataDecoder.h"
1717
@@ -39,6 +39,7 @@ void RawDataDecoder::makeGBTWordInverse(std::vector<gbtword80_t>& diglets, gbtwo
3939}
4040int RawDataDecoder::addCTPDigit (uint32_t linkCRU, uint32_t orbit, gbtword80_t & diglet, gbtword80_t & pldmask, std::map<o2::InteractionRecord, CTPDigit>& digits)
4141{
42+ int ret = 0 ;
4243 gbtword80_t pld = (diglet & pldmask);
4344 if (pld.count () == 0 ) {
4445 return 0 ;
@@ -70,10 +71,15 @@ int RawDataDecoder::addCTPDigit(uint32_t linkCRU, uint32_t orbit, gbtword80_t& d
7071 digits[ir].setInputMask (pld);
7172 LOG (debug) << bcid << " inputs bcid vase 1 orbit " << orbit << " pld:" << pld;
7273 } else {
73- LOG (error) << " Two CTP IRs with the same timestamp:" << ir.bc << " " << ir.orbit << " pld:" << pld << " dig:" << digits[ir];
74+ if (mErrorIR < mErrorMax ) {
75+ LOG (error) << " Two CTP IRs with the same timestamp:" << ir.bc << " " << ir.orbit << " pld:" << pld << " dig:" << digits[ir];
76+ }
77+ ret = 2 ;
78+ mErrorIR ++;
7479 }
7580 } else {
7681 LOG (error) << " Two digits with the same rimestamp:" << ir.bc << " " << ir.orbit ;
82+ ret = 2 ;
7783 }
7884 } else if (linkCRU == o2::ctp::GBTLinkIDClassRec) {
7985 int32_t offset = BCShiftCorrection + o2::ctp::TriggerOffsetsParam::Instance ().LM_L0 + o2::ctp::TriggerOffsetsParam::Instance ().L0_L1 - 1 ;
@@ -95,18 +101,26 @@ int RawDataDecoder::addCTPDigit(uint32_t linkCRU, uint32_t orbit, gbtword80_t& d
95101 digits[ir].setClassMask (pld);
96102 LOG (debug) << bcid << " class bcid case 1 orbit " << orbit << " pld:" << pld;
97103 } else {
98- LOG (error) << " Two CTP Class masks for same timestamp" ;
104+ if (mErrorTCR < mErrorMax ) {
105+ LOG (error) << " Two CTP Class masks for same timestamp" ;
106+ }
107+ mErrorTCR ++;
108+ ret = 3 ;
99109 }
100110 } else {
111+ LOG (error) << " Two digits with the same timestamp:" << ir.bc << " " << ir.orbit ;
112+ ret = 3 ;
101113 }
102114 } else {
103115 LOG (error) << " Unxpected CTP CRU link:" << linkCRU;
104116 }
105- return 0 ;
117+ return ret ;
106118}
107119//
108120int RawDataDecoder::decodeRaw (o2::framework::InputRecord& inputs, std::vector<o2::framework::InputSpec>& filter, std::vector<CTPDigit>& digits, std::vector<LumiInfo>& lumiPointsHBF1)
109121{
122+ int ret = 0 ;
123+ static int nwrites = 0 ;
110124 uint64_t countsMBT = 0 ;
111125 uint64_t countsMBV = 0 ;
112126 std::map<o2::InteractionRecord, CTPDigit> digitsMap;
@@ -193,6 +207,7 @@ int RawDataDecoder::decodeRaw(o2::framework::InputRecord& inputs, std::vector<o2
193207 if (mPadding == 1 ) {
194208 wordSize = 16 ;
195209 }
210+ // LOG(info) << ii << " payload size:" << payload.size();
196211 /* if (payload.size()) {
197212 //LOG(info) << "payload size:" << payload.size();
198213 // LOG(info) << "RDH FEEid: " << feeID << " CTP CRU link:" << linkCRU << " Orbit:" << triggerOrbit << " stopbit:" << stopBit << " packet:" << packetCounter;
@@ -206,14 +221,6 @@ int RawDataDecoder::decodeRaw(o2::framework::InputRecord& inputs, std::vector<o2
206221 if ((wc == 0 ) && (wordCount != 0 )) {
207222 if (gbtWord80.count () != 80 ) {
208223 gbtwords80.push_back (gbtWord80);
209- /* uint64_t bcid = (gbtWord80 & bcmask).to_ullong();
210- if (bcid < 279)
211- bcid += 3564 - 279;
212- else
213- bcid += -279;
214- std::string ss = fmt::format("{:x}", bcid);
215- LOG(info) << "w80:" << gbtWord80 << " " << ss;
216- // LOGP(info,"w80: {} bcid:{%x}", gbtWord80,bcid); */
217224 }
218225 gbtWord80.set ();
219226 }
@@ -226,13 +233,6 @@ int RawDataDecoder::decodeRaw(o2::framework::InputRecord& inputs, std::vector<o2
226233 }
227234 if ((gbtWord80.count () != 80 ) && (gbtWord80.count () > 0 )) {
228235 gbtwords80.push_back (gbtWord80);
229- /* uint64_t bcid = (gbtWord80 & bcmask).to_ullong();
230- if (bcid < 279)
231- bcid += 3564 - 279;
232- else
233- bcid += -279;
234- std::string ss = fmt::format("{:x}", bcid);
235- LOG(info) << "w80l:" << gbtWord80 << " " << ss; */
236236 }
237237 // decode 80 bits payload
238238 for (auto word : gbtwords80) {
@@ -254,7 +254,7 @@ int RawDataDecoder::decodeRaw(o2::framework::InputRecord& inputs, std::vector<o2
254254 continue ;
255255 }
256256 LOG (debug) << " diglet:" << diglet << " " << (diglet & bcmask).to_ullong ();
257- addCTPDigit (linkCRU, rdhOrbit, diglet, pldmask, digitsMap);
257+ ret = addCTPDigit (linkCRU, rdhOrbit, diglet, pldmask, digitsMap);
258258 }
259259 }
260260 // if ((remnant.count() > 0) && stopBit) {
@@ -272,7 +272,7 @@ int RawDataDecoder::decodeRaw(o2::framework::InputRecord& inputs, std::vector<o2
272272 if (!mDoDigits ) {
273273 continue ;
274274 }
275- addCTPDigit (linkCRU, rdhOrbit, remnant, pldmask, digitsMap);
275+ ret = addCTPDigit (linkCRU, rdhOrbit, remnant, pldmask, digitsMap);
276276 LOG (debug) << " diglet:" << remnant << " " << (remnant & bcmask).to_ullong ();
277277 remnant = 0 ;
278278 }
@@ -286,7 +286,28 @@ int RawDataDecoder::decodeRaw(o2::framework::InputRecord& inputs, std::vector<o2
286286 digits.push_back (dig.second );
287287 }
288288 }
289- return 0 ;
289+ // ret = 1;
290+ if (ret) {
291+ if (nwrites < mErrorMax ) {
292+ std::string file = " /tmp/dumpCTP" + std::to_string (nwrites) + " .bin" ;
293+ std::ofstream dumpctp (file.c_str (), std::ios::out | std::ios::binary);
294+ if (!dumpctp.good ()) {
295+ LOGP (error, " Failed to open file {}" , file);
296+ } else {
297+ LOGP (info, " CTP dump file open {}" , file);
298+ for (auto it = parser.begin (); it != parser.end (); ++it) {
299+ char * dataout = (char *)(it.raw ());
300+ dumpctp.write (dataout, it.size ());
301+ }
302+ dumpctp.close ();
303+ }
304+ nwrites++;
305+ }
306+ }
307+ if (mErrorIR || mErrorTCR ) {
308+ LOG (error) << " CTP decoding IR errors:" << mErrorIR << " TCR errors:" << mErrorTCR ;
309+ }
310+ return ret;
290311}
291312//
292313int RawDataDecoder::init ()
0 commit comments