Skip to content

Commit 9066928

Browse files
author
Roman Lietava
committed
dev: checkConsistency and ctp.cfg
1 parent 3eadf36 commit 9066928

File tree

10 files changed

+122
-49
lines changed

10 files changed

+122
-49
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ 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 getTriggerClassMaskOnlywInputs() const;
176177
std::vector<int> getTriggerClassList() const;
177178
uint32_t getRunNumber() { return mRunNumber; };
178179
std::vector<std::string> getDetectorList() const;
@@ -203,6 +204,17 @@ class CTPConfiguration
203204

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

207+
struct CtpCfg
208+
{
209+
CtpCfg() = default;
210+
std::string filename = "/home/alice/trigger/DBCTP/ctp.cfg";
211+
CtpCfg readAndSave();
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+
};
206218
} // namespace ctp
207219
} // namespace o2
208220
#endif //_CTP_CONFIGURATION_H_

DataFormats/Detectors/CTP/src/Configuration.cxx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,17 @@ uint64_t CTPConfiguration::getTriggerClassMask() const
905905
}
906906
return clsmask;
907907
}
908+
uint64_t CTPConfiguration::getTriggerClassMaskOnlywInputs() 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+
}
908919
// Hardware positions of classes
909920
std::vector<int> CTPConfiguration::getTriggerClassList() const
910921
{
@@ -1153,6 +1164,44 @@ int CTPInputsConfiguration::getInputIndexFromName(std::string& name)
11531164
return 0xff;
11541165
}
11551166

1167+
CtpCfg CtpCfg::readAndSave()
1168+
{
1169+
std::ifstream ctpcfg(filename);
1170+
if (ctpcfg.is_open()) {
1171+
std::string line;
1172+
while (std::getline(ctpcfg, line)) {
1173+
o2::utils::Str::trim(line);
1174+
if (line.size() == 0) {
1175+
continue;
1176+
}
1177+
if (line[0] == '#') {
1178+
continue;
1179+
}
1180+
std::vector<std::string> tokens = o2::utils::Str::tokenize(line, ' ');
1181+
size_t ntokens = tokens.size();
1182+
if(ntokens < 2) {
1183+
LOG(warn) << "Not enough tokens";
1184+
return *this;
1185+
}
1186+
if(tokens[0].find("TForbits") != std::string::npos) {
1187+
TFOrbits = std::atol(tokens[1].c_str());
1188+
} else if(tokens[0].find("ccdb") != std::string::npos) {
1189+
ccdb = std::atoi(tokens[1].c_str());
1190+
} else if(tokens[0].find("orbitshift") != std::string::npos) {
1191+
orbitShift = std::atol(tokens[1].c_str());
1192+
} else if(tokens[0].find("ir_inputs") != std::string::npos){
1193+
irInputs_1_24 = std::stoul(tokens[1].c_str(), nullptr, 16);
1194+
irInputs_25_48 = std::stoul(tokens[2].c_str(), nullptr, 16);
1195+
} else {
1196+
LOG(warn) << " Token not found:" << tokens[0];
1197+
}
1198+
}
1199+
} else {
1200+
LOG(warn) << "Can not open file:" << filename;
1201+
}
1202+
return *this;
1203+
}
1204+
11561205
std::ostream& o2::ctp::operator<<(std::ostream& in, const o2::ctp::CTPConfiguration& conf)
11571206
{
11581207
conf.printStream(in);

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class RawDataDecoder
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);
5858
int checkReadoutConsistentncy(o2::pmr::vector<CTPDigit>& digits, uint64_t trgclassmask = 0xffffffffffffffff);
59-
59+
std::map<int,int> getClassErrors() {return mClassErrors; }
60+
std::map<uint64_t,int> getInpError() { return mInpErrors; }
6061
private:
6162
static constexpr uint32_t TF_TRIGGERTYPE_MASK = 0x800;
6263
static constexpr uint32_t HB_TRIGGERTYPE_MASK = 0x2;
@@ -83,8 +84,10 @@ class RawDataDecoder
8384
// error verbosness
8485
int mErrorIR = 0;
8586
int mErrorTCR = 0;
86-
int mErrorMax = 3;
87+
int mErrorMax = 5;
8788
bool mStickyError = false;
89+
std::map<int,int> mClassErrors;
90+
std::map<uint64_t,int> mInpErrors;
8891
CTPConfiguration mCTPConfig;
8992
};
9093
} // namespace ctp

Detectors/CTP/reconstruction/src/RawDataDecoder.cxx

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ int RawDataDecoder::decodeRaw(o2::framework::InputRecord& inputs, std::vector<o2
295295
if (mDoDigits & mDecodeInps) {
296296
uint64_t trgclassmask = 0xffffffffffffffff;
297297
if (mCTPConfig.getRunNumber() != 0) {
298-
trgclassmask = mCTPConfig.getTriggerClassMask();
298+
trgclassmask = mCTPConfig.getTriggerClassMaskOnlywInputs();
299299
}
300300
// std::cout << "trgclassmask:" << std::hex << trgclassmask << std::dec << std::endl;
301301
ret = shiftInputs(digitsMap, digits, mTFOrbit, trgclassmask);
@@ -530,12 +530,6 @@ int RawDataDecoder::shiftNew(const o2::InteractionRecord& irin, uint32_t TFOrbit
530530
int RawDataDecoder::shiftInputs(std::map<o2::InteractionRecord, CTPDigit>& digitsMap, o2::pmr::vector<CTPDigit>& digits, uint32_t TFOrbit, uint64_t trgclassmask)
531531
{
532532
// 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;
539533
std::map<o2::InteractionRecord, CTPDigit> digitsMapShifted;
540534
auto L0shift = o2::ctp::TriggerOffsetsParam::Instance().LM_L0;
541535
auto L1shift = L0shift + o2::ctp::TriggerOffsetsParam::Instance().L0_L1;
@@ -593,60 +587,35 @@ int RawDataDecoder::shiftInputs(std::map<o2::InteractionRecord, CTPDigit>& digit
593587
}
594588
}
595589
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-
}
619590
digits.push_back(dig.second);
620591
}
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;
592+
return 0;
630593
}
631594
//
632595
int RawDataDecoder::checkReadoutConsistentncy(o2::pmr::vector<CTPDigit>& digits, uint64_t trgclassmask)
633596
{
634597
int ret = 0;
635598
int lost = 0;
599+
static int nerror = 0;
636600
for (auto const& digit : digits) {
637601
// if class mask => inps
638602
for (int i = 0; i < digit.CTPClassMask.size(); i++) {
639603
if (digit.CTPClassMask[i] & trgclassmask) {
640604
const CTPClass* cls = mCTPConfig.getCTPClassFromHWIndex(i);
641605
if (cls == nullptr) {
642-
LOG(error) << "Class mask index not found in CTP config:" << i;
606+
if(nerror < mErrorMax)
607+
LOG(error) << "Class mask index not found in CTP config:" << i;
643608
ret = 128;
644609
continue;
645610
}
646611
uint64_t clsinpmask = cls->descriptor->getInputsMask();
647612
uint64_t diginpmask = digit.CTPInputMask.to_ullong();
648613
if (!((clsinpmask & diginpmask) == clsinpmask)) {
649-
LOG(error) << "CTP class:" << cls->name << " inpmask:" << clsinpmask << " not compatible with inputs mask:" << diginpmask;
614+
if(nerror < mErrorMax)
615+
LOG(error) << "CTP class:" << cls->name << " inpmask:" << clsinpmask << " not compatible with inputs mask:" << diginpmask;
616+
auto result = mClassErrors.insert({cls->getIndex(),1});
617+
if(!result.second)
618+
mClassErrors[cls->getIndex()]++;
650619
ret = 128;
651620
}
652621
}
@@ -662,7 +631,11 @@ int RawDataDecoder::checkReadoutConsistentncy(o2::pmr::vector<CTPDigit>& digits,
662631
int32_t offset = BCShiftCorrection + o2::ctp::TriggerOffsetsParam::Instance().LM_L0 + o2::ctp::TriggerOffsetsParam::Instance().L0_L1_classes - 1;
663632
offset = o2::constants::lhc::LHCMaxBunches - offset;
664633
if (digit.intRecord.bc < offset) {
665-
LOG(error) << "CTP class:" << cls.name << " inpmask:" << clsinpmask << " cls mask:" << cls.classMask << " not found in digit:" << digit;
634+
if(nerror < mErrorMax)
635+
LOG(error) << "CTP class:" << cls.name << " inpmask:" << clsinpmask << " cls mask:" << cls.classMask << " not found in digit:" << digit;
636+
auto result = mInpErrors.insert({diginpmask,1});
637+
if(!result.second)
638+
mInpErrors[diginpmask]++;
666639
ret = 256;
667640
} else {
668641
lost++;

Detectors/CTP/workflow/src/RawDecoderSpec.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ 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) << "Number of missing TF:" << nmiss << std::endl;
73+
LOG(info) << "# of IR errors:" << mDecoder.getErrorIR() << " TCR errors:" << mDecoder.getErrorTCR() << std::endl;
7474
}
7575
void RawDecoderSpec::run(framework::ProcessingContext& ctx)
7676
{

Detectors/CTP/workflowScalers/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ o2_add_library(CTPWorkflowScalers
1313
SOURCES src/RunManager.cxx
1414
PUBLIC_LINK_LIBRARIES O2::Framework
1515
O2::DataFormatsCTP
16-
AliceO2::BookkeepingApi)
16+
AliceO2::BookkeepingApi
17+
AliceO2::InfoLogger)
1718
o2_target_root_dictionary(CTPWorkflowScalers HEADERS
1819
include/CTPWorkflowScalers/ctpCCDBManager.h)
1920
o2_add_executable(

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "DataFormatsCTP/Configuration.h"
1919
#include "BookkeepingApi/BkpClientFactory.h"
2020
#include "BookkeepingApi/BkpClient.h"
21+
#include <InfoLogger/InfoLogger.hxx>
2122

2223
using namespace o2::bkp::api;
2324
namespace o2
@@ -72,6 +73,7 @@ class CTPRunManager : public ctpCCDBManager
7273
int mEOX = 0; // redundancy check
7374
int mNew = 1; // 1 - no CCDB: used for QC
7475
int mQCWritePeriod = 3; // Time in 10secs between two writes to QCCD
76+
AliceO2::InfoLogger::InfoLogger mInfoLogger;
7577
ClassDefNV(CTPRunManager, 7);
7678
};
7779
} // namespace ctp

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ 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);
@@ -46,7 +47,8 @@ class ctpCCDBManager
4647
const std::string mQCDBPathCTPScalers = "qc/CTP/Scalers";
4748
const std::string mCCDBPathSoxOrbit = "CTP/Calib/FirstRunOrbit";
4849
const std::string mCCDBPathOrbitReset = "CTP/Calib/OrbitReset";
49-
ClassDefNV(ctpCCDBManager, 1);
50+
const std::string mCCDBPathCtpCfg = "CTP/Config/CtpCfg";
51+
ClassDefNV(ctpCCDBManager, 2);
5052
};
5153
} // namespace ctp
5254
} // namespace o2

Detectors/CTP/workflowScalers/src/RunManager.cxx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ int CTPRunManager::loadRun(const std::string& cfg)
122122
//
123123
mRunsLoaded[runnumber] = activerun;
124124
saveRunConfigToCCDB(&activerun->cfg, timeStamp);
125-
125+
saveCtpCfg(runnumber, timeStamp);
126126
return 0;
127127
}
128128
int CTPRunManager::setRunConfigBK(uint32_t runNumber, const std::string& cfg)
@@ -221,6 +221,9 @@ int CTPRunManager::addScalers(uint32_t irun, std::time_t time, bool start)
221221
int CTPRunManager::processMessage(std::string& topic, const std::string& message)
222222
{
223223
LOG(info) << "Processing message with topic:" << topic;
224+
std::string ahoj = "ahoj kniznica";
225+
mInfoLogger.logInfo(ahoj);
226+
LOG(important) << " ahoj important";
224227
std::string firstcounters;
225228
if (topic.find("clear") != std::string::npos) {
226229
mRunsLoaded.clear();

Detectors/CTP/workflowScalers/src/ctpCCDBManager.cxx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,34 @@ int ctpCCDBManager::saveOrbitReset(long timeStamp)
167167
}
168168
return 0;
169169
}
170+
int ctpCCDBManager::saveCtpCfg(uint32_t runNumber, long timeStart)
171+
{
172+
if (mCCDBHost == "none") {
173+
LOG(info) << "CtpCfg not written to CCDB none";
174+
return 0;
175+
}
176+
CtpCfg ctpcfg;
177+
ctpcfg.readAndSave();
178+
using namespace std::chrono_literals;
179+
std::chrono::seconds days3 = 259200s;
180+
std::chrono::seconds min10 = 600s;
181+
long time3days = std::chrono::duration_cast<std::chrono::milliseconds>(days3).count();
182+
long time10min = std::chrono::duration_cast<std::chrono::milliseconds>(min10).count();
183+
long tmin = timeStart - time10min;
184+
long tmax = timeStart + time3days;
185+
o2::ccdb::CcdbApi api;
186+
map<string, string> metadata; // can be empty
187+
metadata["runNumber"] = std::to_string(runNumber);
188+
api.init(mCCDBHost.c_str()); // or http://localhost:8080 for a local installation
189+
// store abitrary user object in strongly typed manner
190+
int ret = 0; //api.storeAsTFileAny(&vect, mCCDBPathCtpCfg, metadata, tmin, tmax);
191+
if (ret == 0) {
192+
LOG(info) << "CtpCfg saved in ccdb:" << mCCDBHost << " tmin:" << tmin << " tmax:" << tmax;
193+
} else {
194+
LOG(error) << "CtpCfg Problem writing to database ret:" << ret;
195+
}
196+
return 0;
197+
}
170198
CTPConfiguration ctpCCDBManager::getConfigFromCCDB(long timestamp, std::string run, bool& ok)
171199
{
172200
auto& mgr = o2::ccdb::BasicCCDBManager::instance();

0 commit comments

Comments
 (0)