Skip to content

Commit

Permalink
ctpdev: dump raw on error (#11657)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lietava authored Jul 17, 2023
1 parent 9accb6b commit a138faf
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class RawDataDecoder
void setDoLumi(bool lumi) { mDoLumi = lumi; }
void setDoDigits(bool digi) { mDoDigits = digi; }
void setVerbose(bool v) { mVerbose = v; }
void setMAXErrors(int m) { mErrorMax = m; }
uint32_t getIRRejected() const { return mIRRejected; }
uint32_t getTCRRejected() const { return mTCRRejected; }
std::vector<uint32_t>& getTFOrbits() { return mTFOrbits; }
Expand All @@ -64,6 +65,10 @@ class RawDataDecoder
bool mPadding = true;
uint32_t mTFOrbit = 0;
std::vector<uint32_t> mTFOrbits;
// error verbosness
int mErrorIR = 0;
int mErrorTCR = 0;
int mErrorMax = 3;
};
} // namespace ctp
} // namespace o2
Expand Down
65 changes: 43 additions & 22 deletions Detectors/CTP/reconstruction/src/RawDataDecoder.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

/// \file RawDataDecoder.cxx
/// \author Roman Lietava

#include <fstream>
#include "DetectorsRaw/RDHUtils.h"
#include "CTPReconstruction/RawDataDecoder.h"

Expand Down Expand Up @@ -39,6 +39,7 @@ void RawDataDecoder::makeGBTWordInverse(std::vector<gbtword80_t>& diglets, gbtwo
}
int RawDataDecoder::addCTPDigit(uint32_t linkCRU, uint32_t orbit, gbtword80_t& diglet, gbtword80_t& pldmask, std::map<o2::InteractionRecord, CTPDigit>& digits)
{
int ret = 0;
gbtword80_t pld = (diglet & pldmask);
if (pld.count() == 0) {
return 0;
Expand Down Expand Up @@ -70,10 +71,15 @@ int RawDataDecoder::addCTPDigit(uint32_t linkCRU, uint32_t orbit, gbtword80_t& d
digits[ir].setInputMask(pld);
LOG(debug) << bcid << " inputs bcid vase 1 orbit " << orbit << " pld:" << pld;
} else {
LOG(error) << "Two CTP IRs with the same timestamp:" << ir.bc << " " << ir.orbit << " pld:" << pld << " dig:" << digits[ir];
if (mErrorIR < mErrorMax) {
LOG(error) << "Two CTP IRs with the same timestamp:" << ir.bc << " " << ir.orbit << " pld:" << pld << " dig:" << digits[ir];
}
ret = 2;
mErrorIR++;
}
} else {
LOG(error) << "Two digits with the same rimestamp:" << ir.bc << " " << ir.orbit;
ret = 2;
}
} else if (linkCRU == o2::ctp::GBTLinkIDClassRec) {
int32_t offset = BCShiftCorrection + o2::ctp::TriggerOffsetsParam::Instance().LM_L0 + o2::ctp::TriggerOffsetsParam::Instance().L0_L1 - 1;
Expand All @@ -95,18 +101,26 @@ int RawDataDecoder::addCTPDigit(uint32_t linkCRU, uint32_t orbit, gbtword80_t& d
digits[ir].setClassMask(pld);
LOG(debug) << bcid << " class bcid case 1 orbit " << orbit << " pld:" << pld;
} else {
LOG(error) << "Two CTP Class masks for same timestamp";
if (mErrorTCR < mErrorMax) {
LOG(error) << "Two CTP Class masks for same timestamp";
}
mErrorTCR++;
ret = 3;
}
} else {
LOG(error) << "Two digits with the same timestamp:" << ir.bc << " " << ir.orbit;
ret = 3;
}
} else {
LOG(error) << "Unxpected CTP CRU link:" << linkCRU;
}
return 0;
return ret;
}
//
int RawDataDecoder::decodeRaw(o2::framework::InputRecord& inputs, std::vector<o2::framework::InputSpec>& filter, std::vector<CTPDigit>& digits, std::vector<LumiInfo>& lumiPointsHBF1)
{
int ret = 0;
static int nwrites = 0;
uint64_t countsMBT = 0;
uint64_t countsMBV = 0;
std::map<o2::InteractionRecord, CTPDigit> digitsMap;
Expand Down Expand Up @@ -193,6 +207,7 @@ int RawDataDecoder::decodeRaw(o2::framework::InputRecord& inputs, std::vector<o2
if (mPadding == 1) {
wordSize = 16;
}
// LOG(info) << ii << " payload size:" << payload.size();
/* if (payload.size()) {
//LOG(info) << "payload size:" << payload.size();
// LOG(info) << "RDH FEEid: " << feeID << " CTP CRU link:" << linkCRU << " Orbit:" << triggerOrbit << " stopbit:" << stopBit << " packet:" << packetCounter;
Expand All @@ -206,14 +221,6 @@ int RawDataDecoder::decodeRaw(o2::framework::InputRecord& inputs, std::vector<o2
if ((wc == 0) && (wordCount != 0)) {
if (gbtWord80.count() != 80) {
gbtwords80.push_back(gbtWord80);
/* uint64_t bcid = (gbtWord80 & bcmask).to_ullong();
if (bcid < 279)
bcid += 3564 - 279;
else
bcid += -279;
std::string ss = fmt::format("{:x}", bcid);
LOG(info) << "w80:" << gbtWord80 << " " << ss;
// LOGP(info,"w80: {} bcid:{%x}", gbtWord80,bcid); */
}
gbtWord80.set();
}
Expand All @@ -226,13 +233,6 @@ int RawDataDecoder::decodeRaw(o2::framework::InputRecord& inputs, std::vector<o2
}
if ((gbtWord80.count() != 80) && (gbtWord80.count() > 0)) {
gbtwords80.push_back(gbtWord80);
/*uint64_t bcid = (gbtWord80 & bcmask).to_ullong();
if (bcid < 279)
bcid += 3564 - 279;
else
bcid += -279;
std::string ss = fmt::format("{:x}", bcid);
LOG(info) << "w80l:" << gbtWord80 << " " << ss; */
}
// decode 80 bits payload
for (auto word : gbtwords80) {
Expand All @@ -254,7 +254,7 @@ int RawDataDecoder::decodeRaw(o2::framework::InputRecord& inputs, std::vector<o2
continue;
}
LOG(debug) << "diglet:" << diglet << " " << (diglet & bcmask).to_ullong();
addCTPDigit(linkCRU, rdhOrbit, diglet, pldmask, digitsMap);
ret = addCTPDigit(linkCRU, rdhOrbit, diglet, pldmask, digitsMap);
}
}
// if ((remnant.count() > 0) && stopBit) {
Expand All @@ -272,7 +272,7 @@ int RawDataDecoder::decodeRaw(o2::framework::InputRecord& inputs, std::vector<o2
if (!mDoDigits) {
continue;
}
addCTPDigit(linkCRU, rdhOrbit, remnant, pldmask, digitsMap);
ret = addCTPDigit(linkCRU, rdhOrbit, remnant, pldmask, digitsMap);
LOG(debug) << "diglet:" << remnant << " " << (remnant & bcmask).to_ullong();
remnant = 0;
}
Expand All @@ -286,7 +286,28 @@ int RawDataDecoder::decodeRaw(o2::framework::InputRecord& inputs, std::vector<o2
digits.push_back(dig.second);
}
}
return 0;
// ret = 1;
if (ret) {
if (nwrites < mErrorMax) {
std::string file = "/tmp/dumpCTP" + std::to_string(nwrites) + ".bin";
std::ofstream dumpctp(file.c_str(), std::ios::out | std::ios::binary);
if (!dumpctp.good()) {
LOGP(error, "Failed to open file {}", file);
} else {
LOGP(info, "CTP dump file open {}", file);
for (auto it = parser.begin(); it != parser.end(); ++it) {
char* dataout = (char*)(it.raw());
dumpctp.write(dataout, it.size());
}
dumpctp.close();
}
nwrites++;
}
}
if (mErrorIR || mErrorTCR) {
LOG(error) << "CTP decoding IR errors:" << mErrorIR << " TCR errors:" << mErrorTCR;
}
return ret;
}
//
int RawDataDecoder::init()
Expand Down
5 changes: 4 additions & 1 deletion Detectors/CTP/workflow/src/RawDecoderSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ void RawDecoderSpec::init(framework::InitContext& ctx)
{
mNTFToIntegrate = ctx.options().get<int>("ntf-to-average");
mVerbose = ctx.options().get<bool>("use-verbose-mode");
int maxerrors = ctx.options().get<int>("print-errors-num");
mDecoder.setVerbose(mVerbose);
mDecoder.setDoLumi(mDoLumi);
mDecoder.setDoDigits(mDoDigits);
LOG(info) << "CTP reco init done. DoLumi:" << mDoLumi << " DoDigits:" << mDoDigits << " NTF:" << mNTFToIntegrate;
mDecoder.setMAXErrors(maxerrors);
LOG(info) << "CTP reco init done. DoLumi:" << mDoLumi << " DoDigits:" << mDoDigits << " NTF:" << mNTFToIntegrate << " Max errors:" << maxerrors;
}
void RawDecoderSpec::endOfStream(framework::EndOfStreamContext& ec)
{
Expand Down Expand Up @@ -170,5 +172,6 @@ o2::framework::DataProcessorSpec o2::ctp::reco_workflow::getRawDecoderSpec(bool
o2::framework::AlgorithmSpec{o2::framework::adaptFromTask<o2::ctp::reco_workflow::RawDecoderSpec>(digits, lumi)},
o2::framework::Options{
{"ntf-to-average", o2::framework::VariantType::Int, 90, {"Time interval for averaging luminosity in units of TF"}},
{"print-errors-num", o2::framework::VariantType::Int, 3, {"Max number of errors to print"}},
{"use-verbose-mode", o2::framework::VariantType::Bool, false, {"Verbose logging"}}}};
}
1 change: 1 addition & 0 deletions Detectors/CTP/workflow/src/ctp-raw-decoder.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
{"no-lumi", o2::framework::VariantType::Bool, false, {"do not produce luminosity output"}},
{"no-digits", o2::framework::VariantType::Bool, false, {"do not produce digits output"}},
{"disable-root-output", o2::framework::VariantType::Bool, false, {"disable root-files output writer"}},
{"print-errors-number", o2::framework::VariantType::Int, 3, {"number of error to print by CTP raw decoder"}},
{"configKeyValues", o2::framework::VariantType::String, "", {"Semicolon separated key=value strings ..."}}};
std::swap(workflowOptions, options);
}
Expand Down

0 comments on commit a138faf

Please sign in to comment.