Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions DataFormats/Detectors/CTP/include/DataFormatsCTP/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ class CTPConfiguration
uint64_t getDecrtiptorInputsMask(const std::string& name) const;
std::map<o2::detectors::DetID::ID, std::vector<CTPInput>> getDet2InputMap();
uint64_t getTriggerClassMask() const;
uint64_t getTriggerClassMaskWInputs() const;
uint64_t getTriggerClassMaskWInputsNoTrgDets() const;
std::vector<int> getTriggerClassList() const;
uint32_t getRunNumber() { return mRunNumber; };
std::vector<std::string> getDetectorList() const;
Expand Down Expand Up @@ -203,6 +205,17 @@ class CTPConfiguration

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

struct CtpCfg {
CtpCfg() = default;
std::string filename = "ctp.cfg";
int readAndSave(std::string& path);
uint32_t TFOrbits = 0;
int ccdb = -1; // -1 means def constructor was called
uint32_t orbitShift = 0;
uint32_t irInputs_1_24 = 0;
uint32_t irInputs_25_48 = 0;
ClassDefNV(CtpCfg, 1)
};
} // namespace ctp
} // namespace o2
#endif //_CTP_CONFIGURATION_H_
65 changes: 65 additions & 0 deletions DataFormats/Detectors/CTP/src/Configuration.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,30 @@ uint64_t CTPConfiguration::getTriggerClassMask() const
}
return clsmask;
}
uint64_t CTPConfiguration::getTriggerClassMaskWInputs() const
{
uint64_t clsmask = 0;
for (auto const& cls : mCTPClasses) {
if (cls.name.find("TRUE") != std::string::npos) { // ignoring internal ctp generators
continue;
}
clsmask |= cls.classMask;
}
return clsmask;
}
uint64_t CTPConfiguration::getTriggerClassMaskWInputsNoTrgDets() const
{
uint64_t clsmask = 0;
for (auto const& cls : mCTPClasses) {
bool exclude = cls.name.find("TRUE") != std::string::npos; // ignoring internal ctp generators
exclude += cls.name.find("EMC") != std::string::npos;
exclude += cls.name.find("TRD") != std::string::npos;
exclude += cls.name.find("HMP") != std::string::npos;
if (!exclude)
clsmask |= cls.classMask;
}
return clsmask;
}
// Hardware positions of classes
std::vector<int> CTPConfiguration::getTriggerClassList() const
{
Expand Down Expand Up @@ -1153,6 +1177,47 @@ int CTPInputsConfiguration::getInputIndexFromName(std::string& name)
return 0xff;
}

int CtpCfg::readAndSave(std::string& path)
{
std::string file = path + filename;
std::ifstream ctpcfg(file);
if (ctpcfg.is_open()) {
std::string line;
while (std::getline(ctpcfg, line)) {
o2::utils::Str::trim(line);
if (line.size() == 0) {
continue;
}
if (line[0] == '#') {
continue;
}
std::vector<std::string> tokens = o2::utils::Str::tokenize(line, ' ');
size_t ntokens = tokens.size();
if (ntokens < 2) {
LOG(warn) << "Not enough tokens";
continue;
}
if (tokens[0].find("TForbits") != std::string::npos) {
TFOrbits = std::atol(tokens[1].c_str());
} else if (tokens[0].find("ccdb") != std::string::npos) {
ccdb = std::atoi(tokens[1].c_str());
} else if (tokens[0].find("orbitshift") != std::string::npos) {
orbitShift = std::atol(tokens[1].c_str());
} else if (tokens[0].find("ir_inputs") != std::string::npos) {
irInputs_1_24 = std::stoul(tokens[2].c_str(), nullptr, 16);
irInputs_25_48 = std::stoul(tokens[1].c_str(), nullptr, 16);
} else {
LOG(warn) << " Token not found:" << tokens[0];
}
}
LOG(warn) << "Open file success:" << file;
} else {
LOG(warn) << "Can not open file:" << file;
return 1;
}
return 0;
}

std::ostream& o2::ctp::operator<<(std::ostream& in, const o2::ctp::CTPConfiguration& conf)
{
conf.printStream(in);
Expand Down
2 changes: 2 additions & 0 deletions DataFormats/Detectors/CTP/src/DataFormatsCTPLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@
#pragma link C++ class o2::ctp::TriggerOffsetsParam + ;
#pragma link C++ class o2::conf::ConfigurableParamHelper < o2::ctp::TriggerOffsetsParam> + ;

#pragma link C++ class o2::ctp::CtpCfg + ;

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ class RawDataDecoder
int init();
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);
static int shiftInputs(std::map<o2::InteractionRecord, CTPDigit>& digitsMap, o2::pmr::vector<CTPDigit>& digits, uint32_t TFOrbit, uint64_t trgclassmask = 0xffffffffffffffff);
int checkReadoutConsistentncy(o2::pmr::vector<CTPDigit>& digits, uint64_t trgclassmask = 0xffffffffffffffff);
int checkReadoutConsistentncy(o2::pmr::vector<CTPDigit>& digits, uint64_t trgclassmask = 0xffffffffffffffff, uint64_t trigclassmaskNoTrgDets = 0xffffffffffffffff);
std::array<uint64_t, o2::ctp::CTP_NCLASSES> getClassErrorsA() { return mClassErrorsA; }
std::array<uint64_t, o2::ctp::CTP_NCLASSES> getClassErrorsB() { return mClassErrorsB; }
std::array<uint64_t, o2::ctp::CTP_NCLASSES> getClassCountersA() { return mClassCountersA; }
std::array<uint64_t, o2::ctp::CTP_NCLASSES> getClassCountersB() { return mClassCountersB; }
int getLostDueToShift() { return mLostDueToShift; }

private:
static constexpr uint32_t TF_TRIGGERTYPE_MASK = 0x800;
Expand Down Expand Up @@ -83,8 +88,13 @@ class RawDataDecoder
// error verbosness
int mErrorIR = 0;
int mErrorTCR = 0;
int mErrorMax = 3;
int mErrorMax = 5;
bool mStickyError = false;
std::array<uint64_t, o2::ctp::CTP_NCLASSES> mClassErrorsA{};
std::array<uint64_t, o2::ctp::CTP_NCLASSES> mClassErrorsB{}; // from inputs
std::array<uint64_t, o2::ctp::CTP_NCLASSES> mClassCountersA{};
std::array<uint64_t, o2::ctp::CTP_NCLASSES> mClassCountersB{}; // from inputs
int mLostDueToShift = 0;
CTPConfiguration mCTPConfig;
};
} // namespace ctp
Expand Down
107 changes: 48 additions & 59 deletions Detectors/CTP/reconstruction/src/RawDataDecoder.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,17 @@ int RawDataDecoder::decodeRaw(o2::framework::InputRecord& inputs, std::vector<o2
}
if (mDoDigits & mDecodeInps) {
uint64_t trgclassmask = 0xffffffffffffffff;
uint64_t trgclassmaskNOTRGDet = 0xffffffffffffffff;
if (mCTPConfig.getRunNumber() != 0) {
trgclassmask = mCTPConfig.getTriggerClassMask();
trgclassmask = mCTPConfig.getTriggerClassMaskWInputs();
trgclassmaskNOTRGDet = mCTPConfig.getTriggerClassMaskWInputsNoTrgDets();
// mCTPConfig.printStream(std::cout);
}
// std::cout << "trgclassmask:" << std::hex << trgclassmask << std::dec << std::endl;
ret = shiftInputs(digitsMap, digits, mTFOrbit, trgclassmask);
if (mCheckConsistency) {
ret = checkReadoutConsistentncy(digits, trgclassmask);
ret = shiftInputs(digitsMap, digits, mTFOrbit);
// if (mCheckConsistency) {
if (1) {
ret = checkReadoutConsistentncy(digits, trgclassmask, trgclassmaskNOTRGDet);
}
}
if (mDoDigits && !mDecodeInps) {
Expand Down Expand Up @@ -530,12 +534,6 @@ int RawDataDecoder::shiftNew(const o2::InteractionRecord& irin, uint32_t TFOrbit
int RawDataDecoder::shiftInputs(std::map<o2::InteractionRecord, CTPDigit>& digitsMap, o2::pmr::vector<CTPDigit>& digits, uint32_t TFOrbit, uint64_t trgclassmask)
{
// int nClasswoInp = 0; // counting classes without input which should never happen
int nLM = 0;
int nL0 = 0;
int nL1 = 0;
int nTwI = 0;
int nTwoI = 0;
int nTwoIlost = 0;
std::map<o2::InteractionRecord, CTPDigit> digitsMapShifted;
auto L0shift = o2::ctp::TriggerOffsetsParam::Instance().LM_L0;
auto L1shift = L0shift + o2::ctp::TriggerOffsetsParam::Instance().L0_L1;
Expand Down Expand Up @@ -593,86 +591,77 @@ int RawDataDecoder::shiftInputs(std::map<o2::InteractionRecord, CTPDigit>& digit
}
}
for (auto const& dig : digitsMapShifted) {
auto d = dig.second;
if ((d.CTPInputMask & LMMASKInputs).count()) {
nLM++;
}
if ((d.CTPInputMask & L0MASKInputs).count()) {
nL0++;
}
if ((d.CTPInputMask & L1MASKInputs).count()) {
nL1++;
}
if ((d.CTPClassMask).to_ulong() & trgclassmask) {
if (d.CTPInputMask.count()) {
nTwI++;
} else {
if (d.intRecord.bc == (o2::constants::lhc::LHCMaxBunches - L1shift)) { // input can be lost because latency class-l1input = 1
nTwoIlost++;
} else {
// LOG(error) << d.intRecord << " " << d.CTPClassMask << " " << d.CTPInputMask;
// std::cout << "ERROR:" << std::hex << d.CTPClassMask << " " << d.CTPInputMask << std::dec << std::endl;
nTwoI++;
}
}
}
digits.push_back(dig.second);
}
int ret = 0;
if (nTwoI) { // Trigger class wo Input
LOG(error) << "LM:" << nLM << " L0:" << nL0 << " L1:" << nL1 << " TwI:" << nTwI << " Trigger classes wo input:" << nTwoI;
ret = 64;
}
if (nTwoIlost) {
LOG(warn) << " Trigger classes wo input from diff latency 1:" << nTwoIlost;
}
return ret;
return 0;
}
//
int RawDataDecoder::checkReadoutConsistentncy(o2::pmr::vector<CTPDigit>& digits, uint64_t trgclassmask)
int RawDataDecoder::checkReadoutConsistentncy(o2::pmr::vector<CTPDigit>& digits, uint64_t trgclassmask, uint64_t trgclassmaskNoTrgDet)
{
LOG(debug) << "Checking readout";
int ret = 0;
int lost = 0;
static int nerror = 0;
for (auto const& digit : digits) {
// if class mask => inps
for (int i = 0; i < digit.CTPClassMask.size(); i++) {
if (digit.CTPClassMask[i] & trgclassmask) {
bool trgcls = trgclassmask & (1ull << i);
if (digit.CTPClassMask[i] & trgcls) {
const CTPClass* cls = mCTPConfig.getCTPClassFromHWIndex(i);
if (cls == nullptr) {
LOG(error) << "Class mask index not found in CTP config:" << i;
if (nerror < mErrorMax) {
LOG(error) << "Class mask index not found in CTP config:" << i;
nerror++;
}
ret = 128;
continue;
}
mClassCountersA[i]++;
if (cls->descriptor == nullptr)
continue;
uint64_t clsinpmask = cls->descriptor->getInputsMask();
uint64_t diginpmask = digit.CTPInputMask.to_ullong();
if (!((clsinpmask & diginpmask) == clsinpmask)) {
LOG(error) << "CTP class:" << cls->name << " inpmask:" << clsinpmask << " not compatible with inputs mask:" << diginpmask;
if (nerror < mErrorMax) {
LOG(error) << "Cls=>Inps: CTP class:" << cls->name << " inpmask:" << clsinpmask << " not compatible with inputs mask:" << diginpmask;
nerror++;
}
mClassErrorsA[i]++;
ret = 128;
}
}
}
// if inps => class mask
for (auto const& cls : mCTPConfig.getCTPClasses()) {
uint64_t clsinpmask = cls.descriptor->getInputsMask();
// cls.printStream(std::cout);
if (cls.descriptor == nullptr)
continue;
uint64_t clsinpmask = cls.descriptor->getInputsMask(); // class definition
uint64_t diginpmask = digit.CTPInputMask.to_ullong();
uint64_t digclsmask = digit.CTPClassMask.to_ullong();
if ((clsinpmask & diginpmask) == clsinpmask) {
if ((cls.classMask & digclsmask) == 0) {
int32_t BCShiftCorrection = -o2::ctp::TriggerOffsetsParam::Instance().customOffset[o2::detectors::DetID::CTP];
int32_t offset = BCShiftCorrection + o2::ctp::TriggerOffsetsParam::Instance().LM_L0 + o2::ctp::TriggerOffsetsParam::Instance().L0_L1_classes - 1;
offset = o2::constants::lhc::LHCMaxBunches - offset;
if (digit.intRecord.bc < offset) {
LOG(error) << "CTP class:" << cls.name << " inpmask:" << clsinpmask << " cls mask:" << cls.classMask << " not found in digit:" << digit;
ret = 256;
} else {
lost++;
if (cls.classMask & trgclassmask) {
mClassCountersB[cls.getIndex()]++;
if ((cls.classMask & digclsmask) == 0) {
int32_t BCShiftCorrection = -o2::ctp::TriggerOffsetsParam::Instance().customOffset[o2::detectors::DetID::CTP];
int32_t offset = BCShiftCorrection + o2::ctp::TriggerOffsetsParam::Instance().LM_L0 + o2::ctp::TriggerOffsetsParam::Instance().L0_L1_classes - 1;
offset = o2::constants::lhc::LHCMaxBunches - offset;
if (digit.intRecord.bc < offset) {
if ((nerror < mErrorMax) && (cls.classMask & ~trgclassmaskNoTrgDet)) {
LOG(info) << "Inp=>Cls: CTP class:" << cls.name << " inpmask:" << clsinpmask << " cls mask:" << cls.classMask << " not found in digit:" << digit;
nerror++;
}
mClassErrorsB[cls.getIndex()]++;
ret = 256;
} else {
mLostDueToShift++;
}
}
}
}
}
}
if (lost) {
LOG(info) << "LOST classes because of shift:" << lost;
if (mLostDueToShift) {
LOG(debug) << "LOST classes because of shift:" << mLostDueToShift;
}
return ret;
}
Expand Down
17 changes: 15 additions & 2 deletions Detectors/CTP/workflow/src/RawDecoderSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,21 @@ void RawDecoderSpec::endOfStream(framework::EndOfStreamContext& ec)
o0 = TFOrbits[i];
}
std::cout << std::endl;
std::cout << "Number of missing TF:" << nmiss << std::endl;
std::cout << "# of IR errors:" << mDecoder.getErrorIR() << " TCR errors:" << mDecoder.getErrorTCR() << std::endl;
LOG(info) << " Lost due to the shift:" << mDecoder.getLostDueToShift();
LOG(info) << "Number of missing TF:" << nmiss << std::endl;
if (mDecoder.getErrorIR() || mDecoder.getErrorTCR())
LOG(error) << "# of IR errors:" << mDecoder.getErrorIR() << " TCR errors:" << mDecoder.getErrorTCR() << std::endl;
std::array<uint64_t, o2::ctp::CTP_NCLASSES> clsA = mDecoder.getClassCountersA();
std::array<uint64_t, o2::ctp::CTP_NCLASSES> clsB = mDecoder.getClassCountersB();
std::array<uint64_t, o2::ctp::CTP_NCLASSES> clsEA = mDecoder.getClassErrorsA();
std::array<uint64_t, o2::ctp::CTP_NCLASSES> clsEB = mDecoder.getClassErrorsB();

for (int i = 0; i < o2::ctp::CTP_NCLASSES; i++) {
bool print = clsA[i] > 0 || clsB[i] > 0 || clsEA[i] > 0 || clsEB[i] > 0;
if (clsEA[i])
LOG(error) << " Class without inputs:";
LOG(important) << "CLASS:" << i << " Cls=>Inp:" << clsA[i] << " Inp=>Cls:" << clsB[i] << " ErrorsCls=>Inps:" << clsEA[i] << " MissingInps=>Cls:" << clsEB[i];
}
}
void RawDecoderSpec::run(framework::ProcessingContext& ctx)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class CTPRunManager : public ctpCCDBManager
int mEOX = 0; // redundancy check
int mNew = 1; // 1 - no CCDB: used for QC
int mQCWritePeriod = 3; // Time in 10secs between two writes to QCCD
ClassDefNV(CTPRunManager, 7);
ClassDefNV(CTPRunManager, 8);
};
} // namespace ctp
} // namespace o2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ class ctpCCDBManager
int saveRunConfigToCCDB(CTPConfiguration* cfg, long timeStart);
int saveSoxOrbit(uint32_t runNumber, uint32_t soxOrbit, long timeStart);
int saveOrbitReset(long timeStamp);
int saveCtpCfg(uint32_t runNumber, long timeStamp);
static CTPConfiguration getConfigFromCCDB(long timestamp, std::string run, bool& ok);
static CTPConfiguration getConfigFromCCDB(long timestamp, std::string run);
CTPRunScalers getScalersFromCCDB(long timestamp, std::string, bool& ok);
static void setCCDBHost(std::string host) { mCCDBHost = host; };
static void setQCDBHost(std::string host) { mQCDBHost = host; };
void setCtpCfgDir(std::string& ctpcfgdir) { mCtpCfgDir = ctpcfgdir; };

protected:
/// Database constants
Expand All @@ -46,7 +48,10 @@ class ctpCCDBManager
const std::string mQCDBPathCTPScalers = "qc/CTP/Scalers";
const std::string mCCDBPathSoxOrbit = "CTP/Calib/FirstRunOrbit";
const std::string mCCDBPathOrbitReset = "CTP/Calib/OrbitReset";
ClassDefNV(ctpCCDBManager, 1);
const std::string mCCDBPathCtpCfg = "CTP/Config/CtpCfg";
std::string mCtpCfgDir;

ClassDefNV(ctpCCDBManager, 2);
};
} // namespace ctp
} // namespace o2
Expand Down
Loading