Skip to content

Commit a138faf

Browse files
authored
ctpdev: dump raw on error (#11657)
* dev: raw data dump if error * clang * dev: dumping raw data * clang * dev: debugs removed, error output decreased. * clang * dev: option for max errors added * clang * fix: small * fix: in return vals
1 parent 9accb6b commit a138faf

File tree

4 files changed

+53
-23
lines changed

4 files changed

+53
-23
lines changed

Detectors/CTP/reconstruction/include/CTPReconstruction/RawDataDecoder.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class RawDataDecoder
4141
void setDoLumi(bool lumi) { mDoLumi = lumi; }
4242
void setDoDigits(bool digi) { mDoDigits = digi; }
4343
void setVerbose(bool v) { mVerbose = v; }
44+
void setMAXErrors(int m) { mErrorMax = m; }
4445
uint32_t getIRRejected() const { return mIRRejected; }
4546
uint32_t getTCRRejected() const { return mTCRRejected; }
4647
std::vector<uint32_t>& getTFOrbits() { return mTFOrbits; }
@@ -64,6 +65,10 @@ class RawDataDecoder
6465
bool mPadding = true;
6566
uint32_t mTFOrbit = 0;
6667
std::vector<uint32_t> mTFOrbits;
68+
// error verbosness
69+
int mErrorIR = 0;
70+
int mErrorTCR = 0;
71+
int mErrorMax = 3;
6772
};
6873
} // namespace ctp
6974
} // namespace o2

Detectors/CTP/reconstruction/src/RawDataDecoder.cxx

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
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
}
4040
int 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
//
108120
int 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
//
292313
int RawDataDecoder::init()

Detectors/CTP/workflow/src/RawDecoderSpec.cxx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ void RawDecoderSpec::init(framework::InitContext& ctx)
2525
{
2626
mNTFToIntegrate = ctx.options().get<int>("ntf-to-average");
2727
mVerbose = ctx.options().get<bool>("use-verbose-mode");
28+
int maxerrors = ctx.options().get<int>("print-errors-num");
2829
mDecoder.setVerbose(mVerbose);
2930
mDecoder.setDoLumi(mDoLumi);
3031
mDecoder.setDoDigits(mDoDigits);
31-
LOG(info) << "CTP reco init done. DoLumi:" << mDoLumi << " DoDigits:" << mDoDigits << " NTF:" << mNTFToIntegrate;
32+
mDecoder.setMAXErrors(maxerrors);
33+
LOG(info) << "CTP reco init done. DoLumi:" << mDoLumi << " DoDigits:" << mDoDigits << " NTF:" << mNTFToIntegrate << " Max errors:" << maxerrors;
3234
}
3335
void RawDecoderSpec::endOfStream(framework::EndOfStreamContext& ec)
3436
{
@@ -170,5 +172,6 @@ o2::framework::DataProcessorSpec o2::ctp::reco_workflow::getRawDecoderSpec(bool
170172
o2::framework::AlgorithmSpec{o2::framework::adaptFromTask<o2::ctp::reco_workflow::RawDecoderSpec>(digits, lumi)},
171173
o2::framework::Options{
172174
{"ntf-to-average", o2::framework::VariantType::Int, 90, {"Time interval for averaging luminosity in units of TF"}},
175+
{"print-errors-num", o2::framework::VariantType::Int, 3, {"Max number of errors to print"}},
173176
{"use-verbose-mode", o2::framework::VariantType::Bool, false, {"Verbose logging"}}}};
174177
}

Detectors/CTP/workflow/src/ctp-raw-decoder.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
3030
{"no-lumi", o2::framework::VariantType::Bool, false, {"do not produce luminosity output"}},
3131
{"no-digits", o2::framework::VariantType::Bool, false, {"do not produce digits output"}},
3232
{"disable-root-output", o2::framework::VariantType::Bool, false, {"disable root-files output writer"}},
33+
{"print-errors-number", o2::framework::VariantType::Int, 3, {"number of error to print by CTP raw decoder"}},
3334
{"configKeyValues", o2::framework::VariantType::String, "", {"Semicolon separated key=value strings ..."}}};
3435
std::swap(workflowOptions, options);
3536
}

0 commit comments

Comments
 (0)