Skip to content

Commit 1edf213

Browse files
committed
o2-ecs-grp-create creates CTP/Config if --original-run <run> passed at SOR
Will clone the CTP/Config/Config of (replayed) original-run with the credentials of the new synthetic run
1 parent 276c322 commit 1edf213

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

Detectors/GRP/workflows/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ o2_add_executable(grp-create
4545
SOURCES src/create-grp-ecs.cxx
4646
PUBLIC_LINK_LIBRARIES O2::DetectorsCommonDataFormats
4747
O2::DataFormatsParameters
48+
O2::DataFormatsCTP
4849
O2::CommonUtils
4950
O2::CCDB
5051
Boost::program_options)

Detectors/GRP/workflows/src/create-grp-ecs.cxx

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
#include <regex>
1616
#include <TSystem.h>
1717
#include "DataFormatsParameters/GRPECSObject.h"
18+
#include "DataFormatsCTP/Configuration.h"
1819
#include "DetectorsCommonDataFormats/DetID.h"
1920
#include "CCDB/CcdbApi.h"
21+
#include "CCDB/BasicCCDBManager.h"
2022
#include "CommonUtils/NameConf.h"
2123
#include "CommonUtils/StringUtils.h"
2224

@@ -31,6 +33,7 @@ enum CCDBRefreshMode { NONE,
3133

3234
int createGRPECSObject(const std::string& dataPeriod,
3335
int run,
36+
int runOrig, // in case of replay
3437
int runTypeI,
3538
int nHBPerTF,
3639
const std::string& _detsReadout,
@@ -50,6 +53,7 @@ int createGRPECSObject(const std::string& dataPeriod,
5053
int retValGLO = 0;
5154
int retValRCT = 0;
5255
int retValGLOmd = 0;
56+
int retValCTP = 0;
5357

5458
// substitute TRG by CTP
5559
std::regex regCTP(R"((^\s*|,\s*)(TRG)(\s*,|\s*$))");
@@ -120,9 +124,8 @@ int createGRPECSObject(const std::string& dataPeriod,
120124
};
121125

122126
toKeyValPairs(metaDataStr);
123-
127+
CcdbApi api;
124128
if (!ccdbServer.empty()) {
125-
CcdbApi api;
126129
const std::string objPath{"GLO/Config/GRPECS"};
127130
api.init(ccdbServer);
128131
metadata["responsible"] = "ECS";
@@ -181,21 +184,46 @@ int createGRPECSObject(const std::string& dataPeriod,
181184
}
182185
}
183186
}
187+
188+
if (runOrig > 0 && runOrig != run && tend < tstart) { // create CTP config
189+
try {
190+
auto& bcm = o2::ccdb::BasicCCDBManager::instance();
191+
bcm.setURL(ccdbServer);
192+
bcm.setFatalWhenNull(false);
193+
auto ctpConfOrig = bcm.getForRun<o2::ctp::CTPConfiguration>("CTP/Config/Config", runOrig);
194+
if (!ctpConfOrig) {
195+
throw std::runtime_error(fmt::format("Failed to access CTP/Config/Config for original run {}", runOrig));
196+
}
197+
ctpConfOrig->setRunNumber(run);
198+
std::map<std::string, std::string> metadataCTP;
199+
metadataCTP["runNumber"] = fmt::format("{}", run);
200+
metadataCTP["comment"] = fmt::format("cloned from run {}", runOrig);
201+
retValCTP = api.storeAsTFileAny(ctpConfOrig, "CTP/Config/Config", metadataCTP, tstart, tendVal);
202+
if (retValCTP == 0) {
203+
LOGP(info, "Uploaded to {}/{} with validity {}:{} for SOR:{}/EOR:{}, cloned from run {}", ccdbServer, "CTP/Config/Config", tstart, tendVal, tstart, tend, runOrig);
204+
} else {
205+
LOGP(alarm, "Upload to {}/{} with validity {}:{} for SOR:{}/EOR:{} (cloned from run {}) FAILED, returned with code {}", ccdbServer, "CTP/Config/Config", tstart, tendVal, tstart, tend, runOrig, retValCTP);
206+
}
207+
} catch (std::exception e) {
208+
LOGP(error, "Failed to create CTP/Config/Config from the original run {}, reason: {}", runOrig, e.what());
209+
return false;
210+
}
211+
}
184212
} else { // write a local file
185213
auto fname = o2::base::NameConf::getGRPECSFileName();
186214
TFile grpF(fname.c_str(), "recreate");
187215
grpF.WriteObjectAny(&grpecs, grpecs.Class(), o2::base::NameConf::CCDBOBJECT.data());
188216
LOG(info) << "Stored to local file " << fname;
189217
}
190-
//
218+
191219
if (refresh != CCDBRefreshMode::NONE && !ccdbServer.empty()) {
192220
auto cmd = fmt::format("curl -I -i -s \"{}{}latest/%5Cw%7B3%7D/.*/`date +%s000`/?prepare={}\"", ccdbServer, ccdbServer.back() == '/' ? "" : "/", refresh == CCDBRefreshMode::SYNC ? "sync" : "true");
193221
auto t0 = std::chrono::high_resolution_clock::now();
194222
auto res = gSystem->Exec(cmd.c_str());
195223
auto t1 = std::chrono::high_resolution_clock::now();
196224
LOGP(info, "Executed [{}] -> {} in {:.3f} s", cmd, res, std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0).count() / 1000.f);
197225
}
198-
if (retValGLO != 0 || retValRCT != 0 || retValGLOmd != 0) {
226+
if (retValGLO != 0 || retValRCT != 0 || retValGLOmd != 0 || retValCTP != 0) {
199227
return 4;
200228
}
201229
return 0;
@@ -233,6 +261,7 @@ int main(int argc, char** argv)
233261
add_option("refresh", bpo::value<string>()->default_value("")->implicit_value("async"), R"(refresh server cache after upload: "none" (or ""), "async" (non-blocking) and "sync" (blocking))");
234262
add_option("marginSOR", bpo::value<long>()->default_value(4 * o2::ccdb::CcdbObjectInfo::DAY), "validity at SOR");
235263
add_option("marginEOR", bpo::value<long>()->default_value(10 * o2::ccdb::CcdbObjectInfo::MINUTE), "validity margin to add after EOR");
264+
add_option("original-run,o", bpo::value<int>()->default_value(0), "if >0, use as the source run to create CTP/Config/Config object");
236265
opt_all.add(opt_general).add(opt_hidden);
237266
bpo::store(bpo::command_line_parser(argc, argv).options(opt_all).positional(opt_pos).run(), vm);
238267

@@ -278,6 +307,7 @@ int main(int argc, char** argv)
278307
int retVal = createGRPECSObject(
279308
vm["period"].as<std::string>(),
280309
vm["run"].as<int>(),
310+
vm["original-run"].as<int>(),
281311
vm["run-type"].as<int>(),
282312
vm["hbf-per-tf"].as<int>(),
283313
vm["detectors"].as<std::string>(),

0 commit comments

Comments
 (0)