Skip to content

Commit 35647e6

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 6c1671d commit 35647e6

File tree

2 files changed

+59
-6
lines changed

2 files changed

+59
-6
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: 58 additions & 6 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,
@@ -44,13 +47,14 @@ int createGRPECSObject(const std::string& dataPeriod,
4447
long marginAtSOR,
4548
long marginAtEOR,
4649
const std::string& ccdbServer = "",
50+
std::string ccdbServerInp = "",
4751
const std::string& metaDataStr = "",
4852
CCDBRefreshMode refresh = CCDBRefreshMode::NONE)
4953
{
5054
int retValGLO = 0;
5155
int retValRCT = 0;
5256
int retValGLOmd = 0;
53-
57+
int retValCTP = 0;
5458
// substitute TRG by CTP
5559
std::regex regCTP(R"((^\s*|,\s*)(TRG)(\s*,|\s*$))");
5660
std::string detsReadout{std::regex_replace(_detsReadout, regCTP, "$1CTP$3")};
@@ -78,6 +82,8 @@ int createGRPECSObject(const std::string& dataPeriod,
7882
tendVal = tend + marginAtEOR;
7983
}
8084
GRPECSObject grpecs;
85+
o2::ctp::CTPConfiguration* ctpConfig = nullptr;
86+
o2::ctp::CTPConfiguration ctpConfigNew;
8187
grpecs.setTimeStart(tstart);
8288
grpecs.setTimeEnd(tend);
8389
grpecs.setTimeStartCTP(tstartCTP);
@@ -119,10 +125,32 @@ int createGRPECSObject(const std::string& dataPeriod,
119125
}
120126
};
121127

128+
if (ccdbServerInp.empty()) {
129+
ccdbServerInp = ccdbServer;
130+
}
131+
if (runOrig > 0 && runOrig != run && tend <= tstart && !ccdbServerInp.empty()) { // create CTP config
132+
try {
133+
auto& bcm = o2::ccdb::BasicCCDBManager::instance();
134+
bcm.setURL(ccdbServerInp);
135+
bcm.setFatalWhenNull(false);
136+
ctpConfig = bcm.getForRun<o2::ctp::CTPConfiguration>("CTP/Config/Config", runOrig);
137+
if (!ctpConfig) {
138+
throw std::runtime_error(fmt::format("Failed to access CTP/Config/Config for original run {}", runOrig));
139+
}
140+
std::string cfstr = ctpConfig->getConfigString(), srun{fmt::format("run {}", run)}, srunOrig{fmt::format("run {}", runOrig)};
141+
o2::utils::Str::replaceAll(cfstr, srunOrig, srun);
142+
ctpConfigNew.loadConfigurationRun3(cfstr);
143+
ctpConfigNew.setRunNumber(run);
144+
} catch (std::exception e) {
145+
LOGP(error, "Failed to create CTP/Config/Config from the original run {}, reason: {}", runOrig, e.what());
146+
}
147+
}
148+
122149
toKeyValPairs(metaDataStr);
123150

124151
if (!ccdbServer.empty()) {
125152
CcdbApi api;
153+
126154
const std::string objPath{"GLO/Config/GRPECS"};
127155
api.init(ccdbServer);
128156
metadata["responsible"] = "ECS";
@@ -181,21 +209,41 @@ int createGRPECSObject(const std::string& dataPeriod,
181209
}
182210
}
183211
}
212+
213+
if (ctpConfig && ctpConfigNew.getRunNumber() == run) { // create CTP config
214+
std::map<std::string, std::string> metadataCTP;
215+
metadataCTP["runNumber"] = fmt::format("{}", run);
216+
metadataCTP["comment"] = fmt::format("cloned from run {}", runOrig);
217+
retValCTP = api.storeAsTFileAny(&ctpConfigNew, "CTP/Config/Config", metadataCTP, tstart, tendVal);
218+
if (retValCTP == 0) {
219+
LOGP(info, "Uploaded to {}/{} with validity {}:{} for SOR:{}/EOR:{}, cloned from run {}", ccdbServer, "CTP/Config/Config", tstart, tendVal, tstart, tend, runOrig);
220+
} else {
221+
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);
222+
}
223+
}
184224
} else { // write a local file
185225
auto fname = o2::base::NameConf::getGRPECSFileName();
186226
TFile grpF(fname.c_str(), "recreate");
187227
grpF.WriteObjectAny(&grpecs, grpecs.Class(), o2::base::NameConf::CCDBOBJECT.data());
188-
LOG(info) << "Stored to local file " << fname;
228+
grpF.Close();
229+
LOGP(info, "Stored GRPECS to local file {}", fname);
230+
if (ctpConfig && ctpConfigNew.getRunNumber() == run) {
231+
std::string ctnpfname = fmt::format("CTPConfig_{}_from_{}.root", run, runOrig);
232+
TFile ctpF(ctnpfname.c_str(), "recreate");
233+
ctpF.WriteObjectAny(&ctpConfigNew, ctpConfigNew.Class(), o2::base::NameConf::CCDBOBJECT.data());
234+
ctpF.Close();
235+
LOGP(info, "Stored CTPConfig to local file {}", ctnpfname);
236+
}
189237
}
190-
//
238+
191239
if (refresh != CCDBRefreshMode::NONE && !ccdbServer.empty()) {
192240
auto cmd = fmt::format("curl -I -i -s \"{}{}latest/%5Cw%7B3%7D/.*/`date +%s000`/?prepare={}\"", ccdbServer, ccdbServer.back() == '/' ? "" : "/", refresh == CCDBRefreshMode::SYNC ? "sync" : "true");
193241
auto t0 = std::chrono::high_resolution_clock::now();
194242
auto res = gSystem->Exec(cmd.c_str());
195243
auto t1 = std::chrono::high_resolution_clock::now();
196244
LOGP(info, "Executed [{}] -> {} in {:.3f} s", cmd, res, std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0).count() / 1000.f);
197245
}
198-
if (retValGLO != 0 || retValRCT != 0 || retValGLOmd != 0) {
246+
if (retValGLO != 0 || retValRCT != 0 || retValGLOmd != 0 || retValCTP != 0) {
199247
return 4;
200248
}
201249
return 0;
@@ -229,10 +277,12 @@ int main(int argc, char** argv)
229277
add_option("start-time-ctp", bpo::value<long>()->default_value(0), "run start CTP time in ms, same as ECS if not set or 0");
230278
add_option("end-time-ctp", bpo::value<long>()->default_value(0), "run end CTP time in ms, same as ECS if not set or 0");
231279
add_option("ccdb-server", bpo::value<std::string>()->default_value("http://alice-ccdb.cern.ch"), "CCDB server for upload, local file if empty");
280+
add_option("ccdb-server-input", bpo::value<std::string>()->default_value(""), "CCDB server for inputs (if needed, e.g. CTPConfig), dy default ccdb-server is used");
232281
add_option("meta-data,m", bpo::value<std::string>()->default_value("")->implicit_value(""), "metadata as key1=value1;key2=value2;..");
233282
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))");
234283
add_option("marginSOR", bpo::value<long>()->default_value(4 * o2::ccdb::CcdbObjectInfo::DAY), "validity at SOR");
235284
add_option("marginEOR", bpo::value<long>()->default_value(10 * o2::ccdb::CcdbObjectInfo::MINUTE), "validity margin to add after EOR");
285+
add_option("original-run,o", bpo::value<int>()->default_value(0), "if >0, use as the source run to create CTP/Config/Config object");
236286
opt_all.add(opt_general).add(opt_hidden);
237287
bpo::store(bpo::command_line_parser(argc, argv).options(opt_all).positional(opt_pos).run(), vm);
238288

@@ -253,13 +303,13 @@ int main(int argc, char** argv)
253303
}
254304
if (vm.count("run") == 0) {
255305
std::cerr << "ERROR: "
256-
<< "obligator run number is missing" << std::endl;
306+
<< "obligatory run number is missing" << std::endl;
257307
std::cerr << opt_general << std::endl;
258308
exit(3);
259309
}
260310
if (vm.count("period") == 0) {
261311
std::cerr << "ERROR: "
262-
<< "obligator data taking period name is missing" << std::endl;
312+
<< "obligatory data taking period name is missing" << std::endl;
263313
std::cerr << opt_general << std::endl;
264314
exit(3);
265315
}
@@ -278,6 +328,7 @@ int main(int argc, char** argv)
278328
int retVal = createGRPECSObject(
279329
vm["period"].as<std::string>(),
280330
vm["run"].as<int>(),
331+
vm["original-run"].as<int>(),
281332
vm["run-type"].as<int>(),
282333
vm["hbf-per-tf"].as<int>(),
283334
vm["detectors"].as<std::string>(),
@@ -291,6 +342,7 @@ int main(int argc, char** argv)
291342
vm["marginSOR"].as<long>(),
292343
vm["marginEOR"].as<long>(),
293344
vm["ccdb-server"].as<std::string>(),
345+
vm["ccdb-server-input"].as<std::string>(),
294346
vm["meta-data"].as<std::string>(),
295347
refresh);
296348

0 commit comments

Comments
 (0)