Skip to content

Commit f1fbd35

Browse files
lietavaRoman Lietava
andauthored
ctpdev: consistencycheck debug and ctpcfg config added (#14247)
* dev: checkConsistency and ctp.cfg * dev: consistency checker * dev:ctpcfg to CCDB * clang * dev:ctpcfg * clang * fix * fix --------- Co-authored-by: Roman Lietava <rl@eduroam-174258829-1.dyndns.cern.ch>
1 parent 9647d48 commit f1fbd35

File tree

11 files changed

+205
-69
lines changed

11 files changed

+205
-69
lines changed

DataFormats/Detectors/CTP/include/DataFormatsCTP/Configuration.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ class CTPConfiguration
173173
uint64_t getDecrtiptorInputsMask(const std::string& name) const;
174174
std::map<o2::detectors::DetID::ID, std::vector<CTPInput>> getDet2InputMap();
175175
uint64_t getTriggerClassMask() const;
176+
uint64_t getTriggerClassMaskWInputs() const;
177+
uint64_t getTriggerClassMaskWInputsNoTrgDets() const;
176178
std::vector<int> getTriggerClassList() const;
177179
uint32_t getRunNumber() { return mRunNumber; };
178180
std::vector<std::string> getDetectorList() const;
@@ -203,6 +205,17 @@ class CTPConfiguration
203205

204206
std::ostream& operator<<(std::ostream& in, const CTPConfiguration& conf);
205207

208+
struct CtpCfg {
209+
CtpCfg() = default;
210+
std::string filename = "ctp.cfg";
211+
int readAndSave(std::string& path);
212+
uint32_t TFOrbits = 0;
213+
int ccdb = -1; // -1 means def constructor was called
214+
uint32_t orbitShift = 0;
215+
uint32_t irInputs_1_24 = 0;
216+
uint32_t irInputs_25_48 = 0;
217+
ClassDefNV(CtpCfg, 1)
218+
};
206219
} // namespace ctp
207220
} // namespace o2
208221
#endif //_CTP_CONFIGURATION_H_

DataFormats/Detectors/CTP/src/Configuration.cxx

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,30 @@ uint64_t CTPConfiguration::getTriggerClassMask() const
905905
}
906906
return clsmask;
907907
}
908+
uint64_t CTPConfiguration::getTriggerClassMaskWInputs() const
909+
{
910+
uint64_t clsmask = 0;
911+
for (auto const& cls : mCTPClasses) {
912+
if (cls.name.find("TRUE") != std::string::npos) { // ignoring internal ctp generators
913+
continue;
914+
}
915+
clsmask |= cls.classMask;
916+
}
917+
return clsmask;
918+
}
919+
uint64_t CTPConfiguration::getTriggerClassMaskWInputsNoTrgDets() const
920+
{
921+
uint64_t clsmask = 0;
922+
for (auto const& cls : mCTPClasses) {
923+
bool exclude = cls.name.find("TRUE") != std::string::npos; // ignoring internal ctp generators
924+
exclude += cls.name.find("EMC") != std::string::npos;
925+
exclude += cls.name.find("TRD") != std::string::npos;
926+
exclude += cls.name.find("HMP") != std::string::npos;
927+
if (!exclude)
928+
clsmask |= cls.classMask;
929+
}
930+
return clsmask;
931+
}
908932
// Hardware positions of classes
909933
std::vector<int> CTPConfiguration::getTriggerClassList() const
910934
{
@@ -1153,6 +1177,47 @@ int CTPInputsConfiguration::getInputIndexFromName(std::string& name)
11531177
return 0xff;
11541178
}
11551179

1180+
int CtpCfg::readAndSave(std::string& path)
1181+
{
1182+
std::string file = path + filename;
1183+
std::ifstream ctpcfg(file);
1184+
if (ctpcfg.is_open()) {
1185+
std::string line;
1186+
while (std::getline(ctpcfg, line)) {
1187+
o2::utils::Str::trim(line);
1188+
if (line.size() == 0) {
1189+
continue;
1190+
}
1191+
if (line[0] == '#') {
1192+
continue;
1193+
}
1194+
std::vector<std::string> tokens = o2::utils::Str::tokenize(line, ' ');
1195+
size_t ntokens = tokens.size();
1196+
if (ntokens < 2) {
1197+
LOG(warn) << "Not enough tokens";
1198+
continue;
1199+
}
1200+
if (tokens[0].find("TForbits") != std::string::npos) {
1201+
TFOrbits = std::atol(tokens[1].c_str());
1202+
} else if (tokens[0].find("ccdb") != std::string::npos) {
1203+
ccdb = std::atoi(tokens[1].c_str());
1204+
} else if (tokens[0].find("orbitshift") != std::string::npos) {
1205+
orbitShift = std::atol(tokens[1].c_str());
1206+
} else if (tokens[0].find("ir_inputs") != std::string::npos) {
1207+
irInputs_1_24 = std::stoul(tokens[2].c_str(), nullptr, 16);
1208+
irInputs_25_48 = std::stoul(tokens[1].c_str(), nullptr, 16);
1209+
} else {
1210+
LOG(warn) << " Token not found:" << tokens[0];
1211+
}
1212+
}
1213+
LOG(warn) << "Open file success:" << file;
1214+
} else {
1215+
LOG(warn) << "Can not open file:" << file;
1216+
return 1;
1217+
}
1218+
return 0;
1219+
}
1220+
11561221
std::ostream& o2::ctp::operator<<(std::ostream& in, const o2::ctp::CTPConfiguration& conf)
11571222
{
11581223
conf.printStream(in);

DataFormats/Detectors/CTP/src/DataFormatsCTPLinkDef.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,6 @@
5555
#pragma link C++ class o2::ctp::TriggerOffsetsParam + ;
5656
#pragma link C++ class o2::conf::ConfigurableParamHelper < o2::ctp::TriggerOffsetsParam> + ;
5757

58+
#pragma link C++ class o2::ctp::CtpCfg + ;
59+
5860
#endif

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ class RawDataDecoder
5555
int init();
5656
static int shiftNew(const o2::InteractionRecord& irin, uint32_t TFOrbit, std::bitset<48>& inpmask, int64_t shift, int level, std::map<o2::InteractionRecord, CTPDigit>& digmap);
5757
static int shiftInputs(std::map<o2::InteractionRecord, CTPDigit>& digitsMap, o2::pmr::vector<CTPDigit>& digits, uint32_t TFOrbit, uint64_t trgclassmask = 0xffffffffffffffff);
58-
int checkReadoutConsistentncy(o2::pmr::vector<CTPDigit>& digits, uint64_t trgclassmask = 0xffffffffffffffff);
58+
int checkReadoutConsistentncy(o2::pmr::vector<CTPDigit>& digits, uint64_t trgclassmask = 0xffffffffffffffff, uint64_t trigclassmaskNoTrgDets = 0xffffffffffffffff);
59+
std::array<uint64_t, o2::ctp::CTP_NCLASSES> getClassErrorsA() { return mClassErrorsA; }
60+
std::array<uint64_t, o2::ctp::CTP_NCLASSES> getClassErrorsB() { return mClassErrorsB; }
61+
std::array<uint64_t, o2::ctp::CTP_NCLASSES> getClassCountersA() { return mClassCountersA; }
62+
std::array<uint64_t, o2::ctp::CTP_NCLASSES> getClassCountersB() { return mClassCountersB; }
63+
int getLostDueToShift() { return mLostDueToShift; }
5964

6065
private:
6166
static constexpr uint32_t TF_TRIGGERTYPE_MASK = 0x800;
@@ -83,8 +88,13 @@ class RawDataDecoder
8388
// error verbosness
8489
int mErrorIR = 0;
8590
int mErrorTCR = 0;
86-
int mErrorMax = 3;
91+
int mErrorMax = 5;
8792
bool mStickyError = false;
93+
std::array<uint64_t, o2::ctp::CTP_NCLASSES> mClassErrorsA{};
94+
std::array<uint64_t, o2::ctp::CTP_NCLASSES> mClassErrorsB{}; // from inputs
95+
std::array<uint64_t, o2::ctp::CTP_NCLASSES> mClassCountersA{};
96+
std::array<uint64_t, o2::ctp::CTP_NCLASSES> mClassCountersB{}; // from inputs
97+
int mLostDueToShift = 0;
8898
CTPConfiguration mCTPConfig;
8999
};
90100
} // namespace ctp

Detectors/CTP/reconstruction/src/RawDataDecoder.cxx

Lines changed: 48 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,17 @@ int RawDataDecoder::decodeRaw(o2::framework::InputRecord& inputs, std::vector<o2
294294
}
295295
if (mDoDigits & mDecodeInps) {
296296
uint64_t trgclassmask = 0xffffffffffffffff;
297+
uint64_t trgclassmaskNOTRGDet = 0xffffffffffffffff;
297298
if (mCTPConfig.getRunNumber() != 0) {
298-
trgclassmask = mCTPConfig.getTriggerClassMask();
299+
trgclassmask = mCTPConfig.getTriggerClassMaskWInputs();
300+
trgclassmaskNOTRGDet = mCTPConfig.getTriggerClassMaskWInputsNoTrgDets();
301+
// mCTPConfig.printStream(std::cout);
299302
}
300303
// std::cout << "trgclassmask:" << std::hex << trgclassmask << std::dec << std::endl;
301-
ret = shiftInputs(digitsMap, digits, mTFOrbit, trgclassmask);
302-
if (mCheckConsistency) {
303-
ret = checkReadoutConsistentncy(digits, trgclassmask);
304+
ret = shiftInputs(digitsMap, digits, mTFOrbit);
305+
// if (mCheckConsistency) {
306+
if (1) {
307+
ret = checkReadoutConsistentncy(digits, trgclassmask, trgclassmaskNOTRGDet);
304308
}
305309
}
306310
if (mDoDigits && !mDecodeInps) {
@@ -530,12 +534,6 @@ int RawDataDecoder::shiftNew(const o2::InteractionRecord& irin, uint32_t TFOrbit
530534
int RawDataDecoder::shiftInputs(std::map<o2::InteractionRecord, CTPDigit>& digitsMap, o2::pmr::vector<CTPDigit>& digits, uint32_t TFOrbit, uint64_t trgclassmask)
531535
{
532536
// int nClasswoInp = 0; // counting classes without input which should never happen
533-
int nLM = 0;
534-
int nL0 = 0;
535-
int nL1 = 0;
536-
int nTwI = 0;
537-
int nTwoI = 0;
538-
int nTwoIlost = 0;
539537
std::map<o2::InteractionRecord, CTPDigit> digitsMapShifted;
540538
auto L0shift = o2::ctp::TriggerOffsetsParam::Instance().LM_L0;
541539
auto L1shift = L0shift + o2::ctp::TriggerOffsetsParam::Instance().L0_L1;
@@ -593,86 +591,77 @@ int RawDataDecoder::shiftInputs(std::map<o2::InteractionRecord, CTPDigit>& digit
593591
}
594592
}
595593
for (auto const& dig : digitsMapShifted) {
596-
auto d = dig.second;
597-
if ((d.CTPInputMask & LMMASKInputs).count()) {
598-
nLM++;
599-
}
600-
if ((d.CTPInputMask & L0MASKInputs).count()) {
601-
nL0++;
602-
}
603-
if ((d.CTPInputMask & L1MASKInputs).count()) {
604-
nL1++;
605-
}
606-
if ((d.CTPClassMask).to_ulong() & trgclassmask) {
607-
if (d.CTPInputMask.count()) {
608-
nTwI++;
609-
} else {
610-
if (d.intRecord.bc == (o2::constants::lhc::LHCMaxBunches - L1shift)) { // input can be lost because latency class-l1input = 1
611-
nTwoIlost++;
612-
} else {
613-
// LOG(error) << d.intRecord << " " << d.CTPClassMask << " " << d.CTPInputMask;
614-
// std::cout << "ERROR:" << std::hex << d.CTPClassMask << " " << d.CTPInputMask << std::dec << std::endl;
615-
nTwoI++;
616-
}
617-
}
618-
}
619594
digits.push_back(dig.second);
620595
}
621-
int ret = 0;
622-
if (nTwoI) { // Trigger class wo Input
623-
LOG(error) << "LM:" << nLM << " L0:" << nL0 << " L1:" << nL1 << " TwI:" << nTwI << " Trigger classes wo input:" << nTwoI;
624-
ret = 64;
625-
}
626-
if (nTwoIlost) {
627-
LOG(warn) << " Trigger classes wo input from diff latency 1:" << nTwoIlost;
628-
}
629-
return ret;
596+
return 0;
630597
}
631598
//
632-
int RawDataDecoder::checkReadoutConsistentncy(o2::pmr::vector<CTPDigit>& digits, uint64_t trgclassmask)
599+
int RawDataDecoder::checkReadoutConsistentncy(o2::pmr::vector<CTPDigit>& digits, uint64_t trgclassmask, uint64_t trgclassmaskNoTrgDet)
633600
{
601+
LOG(debug) << "Checking readout";
634602
int ret = 0;
635-
int lost = 0;
603+
static int nerror = 0;
636604
for (auto const& digit : digits) {
637605
// if class mask => inps
638606
for (int i = 0; i < digit.CTPClassMask.size(); i++) {
639-
if (digit.CTPClassMask[i] & trgclassmask) {
607+
bool trgcls = trgclassmask & (1ull << i);
608+
if (digit.CTPClassMask[i] & trgcls) {
640609
const CTPClass* cls = mCTPConfig.getCTPClassFromHWIndex(i);
641610
if (cls == nullptr) {
642-
LOG(error) << "Class mask index not found in CTP config:" << i;
611+
if (nerror < mErrorMax) {
612+
LOG(error) << "Class mask index not found in CTP config:" << i;
613+
nerror++;
614+
}
643615
ret = 128;
644616
continue;
645617
}
618+
mClassCountersA[i]++;
619+
if (cls->descriptor == nullptr)
620+
continue;
646621
uint64_t clsinpmask = cls->descriptor->getInputsMask();
647622
uint64_t diginpmask = digit.CTPInputMask.to_ullong();
648623
if (!((clsinpmask & diginpmask) == clsinpmask)) {
649-
LOG(error) << "CTP class:" << cls->name << " inpmask:" << clsinpmask << " not compatible with inputs mask:" << diginpmask;
624+
if (nerror < mErrorMax) {
625+
LOG(error) << "Cls=>Inps: CTP class:" << cls->name << " inpmask:" << clsinpmask << " not compatible with inputs mask:" << diginpmask;
626+
nerror++;
627+
}
628+
mClassErrorsA[i]++;
650629
ret = 128;
651630
}
652631
}
653632
}
654633
// if inps => class mask
655634
for (auto const& cls : mCTPConfig.getCTPClasses()) {
656-
uint64_t clsinpmask = cls.descriptor->getInputsMask();
635+
// cls.printStream(std::cout);
636+
if (cls.descriptor == nullptr)
637+
continue;
638+
uint64_t clsinpmask = cls.descriptor->getInputsMask(); // class definition
657639
uint64_t diginpmask = digit.CTPInputMask.to_ullong();
658640
uint64_t digclsmask = digit.CTPClassMask.to_ullong();
659641
if ((clsinpmask & diginpmask) == clsinpmask) {
660-
if ((cls.classMask & digclsmask) == 0) {
661-
int32_t BCShiftCorrection = -o2::ctp::TriggerOffsetsParam::Instance().customOffset[o2::detectors::DetID::CTP];
662-
int32_t offset = BCShiftCorrection + o2::ctp::TriggerOffsetsParam::Instance().LM_L0 + o2::ctp::TriggerOffsetsParam::Instance().L0_L1_classes - 1;
663-
offset = o2::constants::lhc::LHCMaxBunches - offset;
664-
if (digit.intRecord.bc < offset) {
665-
LOG(error) << "CTP class:" << cls.name << " inpmask:" << clsinpmask << " cls mask:" << cls.classMask << " not found in digit:" << digit;
666-
ret = 256;
667-
} else {
668-
lost++;
642+
if (cls.classMask & trgclassmask) {
643+
mClassCountersB[cls.getIndex()]++;
644+
if ((cls.classMask & digclsmask) == 0) {
645+
int32_t BCShiftCorrection = -o2::ctp::TriggerOffsetsParam::Instance().customOffset[o2::detectors::DetID::CTP];
646+
int32_t offset = BCShiftCorrection + o2::ctp::TriggerOffsetsParam::Instance().LM_L0 + o2::ctp::TriggerOffsetsParam::Instance().L0_L1_classes - 1;
647+
offset = o2::constants::lhc::LHCMaxBunches - offset;
648+
if (digit.intRecord.bc < offset) {
649+
if ((nerror < mErrorMax) && (cls.classMask & ~trgclassmaskNoTrgDet)) {
650+
LOG(info) << "Inp=>Cls: CTP class:" << cls.name << " inpmask:" << clsinpmask << " cls mask:" << cls.classMask << " not found in digit:" << digit;
651+
nerror++;
652+
}
653+
mClassErrorsB[cls.getIndex()]++;
654+
ret = 256;
655+
} else {
656+
mLostDueToShift++;
657+
}
669658
}
670659
}
671660
}
672661
}
673662
}
674-
if (lost) {
675-
LOG(info) << "LOST classes because of shift:" << lost;
663+
if (mLostDueToShift) {
664+
LOG(debug) << "LOST classes because of shift:" << mLostDueToShift;
676665
}
677666
return ret;
678667
}

Detectors/CTP/workflow/src/RawDecoderSpec.cxx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,21 @@ void RawDecoderSpec::endOfStream(framework::EndOfStreamContext& ec)
6969
o0 = TFOrbits[i];
7070
}
7171
std::cout << std::endl;
72-
std::cout << "Number of missing TF:" << nmiss << std::endl;
73-
std::cout << "# of IR errors:" << mDecoder.getErrorIR() << " TCR errors:" << mDecoder.getErrorTCR() << std::endl;
72+
LOG(info) << " Lost due to the shift:" << mDecoder.getLostDueToShift();
73+
LOG(info) << "Number of missing TF:" << nmiss << std::endl;
74+
if (mDecoder.getErrorIR() || mDecoder.getErrorTCR())
75+
LOG(error) << "# of IR errors:" << mDecoder.getErrorIR() << " TCR errors:" << mDecoder.getErrorTCR() << std::endl;
76+
std::array<uint64_t, o2::ctp::CTP_NCLASSES> clsA = mDecoder.getClassCountersA();
77+
std::array<uint64_t, o2::ctp::CTP_NCLASSES> clsB = mDecoder.getClassCountersB();
78+
std::array<uint64_t, o2::ctp::CTP_NCLASSES> clsEA = mDecoder.getClassErrorsA();
79+
std::array<uint64_t, o2::ctp::CTP_NCLASSES> clsEB = mDecoder.getClassErrorsB();
80+
81+
for (int i = 0; i < o2::ctp::CTP_NCLASSES; i++) {
82+
bool print = clsA[i] > 0 || clsB[i] > 0 || clsEA[i] > 0 || clsEB[i] > 0;
83+
if (clsEA[i])
84+
LOG(error) << " Class without inputs:";
85+
LOG(important) << "CLASS:" << i << " Cls=>Inp:" << clsA[i] << " Inp=>Cls:" << clsB[i] << " ErrorsCls=>Inps:" << clsEA[i] << " MissingInps=>Cls:" << clsEB[i];
86+
}
7487
}
7588
void RawDecoderSpec::run(framework::ProcessingContext& ctx)
7689
{

Detectors/CTP/workflowScalers/include/CTPWorkflowScalers/RunManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class CTPRunManager : public ctpCCDBManager
7272
int mEOX = 0; // redundancy check
7373
int mNew = 1; // 1 - no CCDB: used for QC
7474
int mQCWritePeriod = 3; // Time in 10secs between two writes to QCCD
75-
ClassDefNV(CTPRunManager, 7);
75+
ClassDefNV(CTPRunManager, 8);
7676
};
7777
} // namespace ctp
7878
} // namespace o2

Detectors/CTP/workflowScalers/include/CTPWorkflowScalers/ctpCCDBManager.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ class ctpCCDBManager
2929
int saveRunConfigToCCDB(CTPConfiguration* cfg, long timeStart);
3030
int saveSoxOrbit(uint32_t runNumber, uint32_t soxOrbit, long timeStart);
3131
int saveOrbitReset(long timeStamp);
32+
int saveCtpCfg(uint32_t runNumber, long timeStamp);
3233
static CTPConfiguration getConfigFromCCDB(long timestamp, std::string run, bool& ok);
3334
static CTPConfiguration getConfigFromCCDB(long timestamp, std::string run);
3435
CTPRunScalers getScalersFromCCDB(long timestamp, std::string, bool& ok);
3536
static void setCCDBHost(std::string host) { mCCDBHost = host; };
3637
static void setQCDBHost(std::string host) { mQCDBHost = host; };
38+
void setCtpCfgDir(std::string& ctpcfgdir) { mCtpCfgDir = ctpcfgdir; };
3739

3840
protected:
3941
/// Database constants
@@ -46,7 +48,10 @@ class ctpCCDBManager
4648
const std::string mQCDBPathCTPScalers = "qc/CTP/Scalers";
4749
const std::string mCCDBPathSoxOrbit = "CTP/Calib/FirstRunOrbit";
4850
const std::string mCCDBPathOrbitReset = "CTP/Calib/OrbitReset";
49-
ClassDefNV(ctpCCDBManager, 1);
51+
const std::string mCCDBPathCtpCfg = "CTP/Config/CtpCfg";
52+
std::string mCtpCfgDir;
53+
54+
ClassDefNV(ctpCCDBManager, 2);
5055
};
5156
} // namespace ctp
5257
} // namespace o2

0 commit comments

Comments
 (0)