Skip to content

Commit 262ceb1

Browse files
authored
dev: ctp config saved at start of run (#9011)
1 parent ebccdf0 commit 262ceb1

2 files changed

Lines changed: 36 additions & 9 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ class CTPRunManager
166166
int addScalers(uint32_t irun, std::time_t time);
167167
int processMessage(std::string& topic, const std::string& message);
168168
void printActiveRuns() const;
169-
int saveRunToCCDB(int i);
169+
int saveRunScalersToCCDB(int i);
170+
int saveRunConfigToCCDB(CTPConfiguration* cfg, long timeStart);
170171
int getConfigFromCCDB();
171172
int getScalersFromCCDB();
172173
int loadScalerNames();
@@ -180,7 +181,8 @@ class CTPRunManager
180181
std::map<std::string, uint32_t> mScalerName2Position;
181182
CTPActiveRun* mRunInStart = nullptr;
182183
int mEOX = 0; // redundancy check
183-
ClassDefNV(CTPRunManager, 1);
184+
int mCtpcfg = 0;
185+
ClassDefNV(CTPRunManager, 2);
184186
};
185187
} // namespace ctp
186188
} // namespace o2

DataFormats/Detectors/CTP/src/Configuration.cxx

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ int CTPRunManager::startRun(const std::string& cfg)
579579
activerun->scalers.setClassMask(activerun->cfg.getTriggerClassMask());
580580
//
581581
mRunInStart = activerun;
582+
saveRunConfigToCCDB(&activerun->cfg, timeStamp);
582583
return 0;
583584
}
584585
int CTPRunManager::stopRun(uint32_t irun)
@@ -591,7 +592,7 @@ int CTPRunManager::stopRun(uint32_t irun)
591592
const auto now = std::chrono::system_clock::now();
592593
const long timeStamp = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
593594
mActiveRuns[irun]->timeStop = timeStamp;
594-
saveRunToCCDB(irun);
595+
saveRunScalersToCCDB(irun);
595596
delete mActiveRuns[irun];
596597
mActiveRuns[irun] = nullptr;
597598
return 0;
@@ -630,6 +631,11 @@ int CTPRunManager::processMessage(std::string& topic, const std::string& message
630631
{
631632
LOG(info) << "Processing message with topic:" << topic;
632633
std::string firstcounters;
634+
if (topic.find("ctpconfig") != std::string::npos) {
635+
LOG(info) << "ctpcfg received";
636+
startRun(message);
637+
mCtpcfg = 1;
638+
}
633639
if (topic.find("sox") != std::string::npos) {
634640
// get config
635641
size_t irun = message.find("run");
@@ -639,9 +645,13 @@ int CTPRunManager::processMessage(std::string& topic, const std::string& message
639645
return 1;
640646
}
641647
LOG(info) << "SOX received, Run:" << irun;
642-
std::string cfg = message.substr(irun, message.size() - irun);
643-
LOG(info) << "Config:" << cfg;
644-
startRun(cfg);
648+
if (mCtpcfg == 0) {
649+
std::string cfg = message.substr(irun, message.size() - irun);
650+
LOG(info) << "Config:" << cfg;
651+
startRun(cfg);
652+
} else {
653+
mCtpcfg = 0;
654+
}
645655
firstcounters = message.substr(0, irun);
646656
}
647657
if (topic.find("eox") != std::string::npos) {
@@ -711,7 +721,7 @@ void CTPRunManager::printActiveRuns() const
711721
}
712722
std::cout << std::endl;
713723
}
714-
int CTPRunManager::saveRunToCCDB(int i)
724+
int CTPRunManager::saveRunScalersToCCDB(int i)
715725
{
716726
// data base
717727
CTPActiveRun* run = mActiveRuns[i];
@@ -721,9 +731,24 @@ int CTPRunManager::saveRunToCCDB(int i)
721731
map<string, string> metadata; // can be empty
722732
api.init(mCcdbHost.c_str()); // or http://localhost:8080 for a local installation
723733
// store abitrary user object in strongly typed manner
724-
api.storeAsTFileAny(&(run->cfg), o2::ctp::CCDBPathCTPConfig, metadata, tmin, tmax);
725734
api.storeAsTFileAny(&(run->scalers), o2::ctp::CCDBPathCTPScalers, metadata, tmin, tmax);
726-
LOG(info) << "CTP config and scalers saved in ccdb, run:" << run->cfg.getRunNumber();
735+
LOG(info) << "CTP scalers saved in ccdb, run:" << run->cfg.getRunNumber();
736+
return 0;
737+
}
738+
int CTPRunManager::saveRunConfigToCCDB(CTPConfiguration* cfg, long timeStart)
739+
{
740+
// data base
741+
long tmin = timeStart;
742+
using namespace std::chrono_literals;
743+
std::chrono::seconds days3 = 259200s;
744+
long time3days = std::chrono::duration_cast<std::chrono::milliseconds>(days3).count();
745+
long tmax = timeStart + time3days;
746+
o2::ccdb::CcdbApi api;
747+
map<string, string> metadata; // can be empty
748+
api.init(mCcdbHost.c_str()); // or http://localhost:8080 for a local installation
749+
// store abitrary user object in strongly typed manner
750+
api.storeAsTFileAny(cfg, o2::ctp::CCDBPathCTPConfig, metadata, tmin, tmax);
751+
LOG(info) << "CTP config saved in ccdb, run:" << cfg->getRunNumber();
727752
return 0;
728753
}
729754
int CTPRunManager::getConfigFromCCDB()

0 commit comments

Comments
 (0)