43int main(
int argc,
char** argv)
45 const std::string testCCDB =
"http://ccdb-test.cern.ch:8080";
47 const std::string aliceCCDB =
"http://alice-ccdb.cern.ch";
48 bpo::variables_map vm;
49 bpo::options_description opt_general(
"Usage:\n " + std::string(argv[0]) +
50 " Write ctp config or scalers to BK\n");
51 bpo::options_description opt_hidden(
"");
52 bpo::options_description opt_all;
53 bpo::positional_options_description opt_pos;
55 auto add_option = opt_general.add_options();
56 add_option(
"help,h",
"Print this help message");
57 add_option(
"input-file,f", bpo::value<std::string>()->default_value(
"none"),
"input file name, none - do not read file");
58 add_option(
"bkhost,b", bpo::value<std::string>()->default_value(
"none"),
"bk web address");
59 add_option(
"ccdb", bpo::value<std::string>()->default_value(
"alice"),
"choose databse: test- test ccdb; prod - production ccdb; alice - alice ccdb; else ccdb parameter");
60 add_option(
"run-number,r", bpo::value<uint32_t>()->default_value(0),
"run number");
61 add_option(
"timestamp,t", bpo::value<uint64_t>()->default_value(0),
"timestamp; if 0 timestamp is calulated inside this code");
62 add_option(
"cfg,c", bpo::value<bool>()->default_value(0),
"Do cfg");
63 add_option(
"scalers,s", bpo::value<bool>()->default_value(0),
"Do scalers");
65 opt_all.add(opt_general).add(opt_hidden);
66 bpo::store(bpo::command_line_parser(argc, argv).options(opt_all).positional(opt_pos).run(), vm);
67 if (vm.count(
"help")) {
68 std::cout << opt_general << std::endl;
72 }
catch (bpo::error& e) {
73 std::cerr <<
"ERROR: " << e.what() << std::endl
75 std::cerr << opt_general << std::endl;
77 }
catch (std::exception& e) {
78 std::cerr << e.what() <<
", application will now exit" << std::endl;
81 uint64_t timestamp = vm[
"timestamp"].as<uint64_t>();
84 std::vector<std::string> runs;
85 int32_t run = vm[
"run-number"].as<uint32_t>();
86 std::cout <<
"run:" << run << std::endl;
88 std::cout <<
"pushing" << std::endl;
92 std::string
filename = vm[
"input-file"].as<std::string>();
95 if (!
file.is_open()) {
96 LOG(fatal) <<
"Cannot open file:" <<
filename << std::endl;
99 while (std::getline(
file, line)) {
100 std::cout << line <<
"\n";
103 runs.push_back(tokens[0]);
107 bool cfg = vm[
"cfg"].as<
bool>();
108 bool scalers = vm[
"scalers"].as<
bool>();
109 std::cout <<
"Doing: cfg:" << cfg <<
" scal:" << scalers << std::endl;
110 if (cfg || scalers) {
111 std::string bkhost = vm[
"bkhost"].as<std::string>();
112 std::unique_ptr<o2::bkp::api::BkpClient> mBKClient = o2::bkp::api::BkpClientFactory::create(bkhost);
114 std::string ccdbAddress;
115 if (vm[
"ccdb"].as<std::string>() ==
"prod") {
117 }
else if (vm[
"ccdb"].as<std::string>() ==
"test") {
118 ccdbAddress = testCCDB;
119 }
else if (vm[
"ccdb"].as<std::string>() ==
"alice") {
120 ccdbAddress = aliceCCDB;
122 ccdbAddress = vm[
"ccdb"].as<std::string>();
125 std::cout <<
"CCDB: " << vm[
"ccdb"].as<std::string>() <<
" " << ccdbAddress << std::endl;
126 std::map<std::string, std::string> metadata;
127 for (
auto const& run : runs) {
128 metadata[
"runNumber"] = run;
130 int runNumber = std::stoi(run);
134 std::string ctpcfgstr = ctpcfg.getConfigString();
136 mBKClient->run()->setRawCtpTriggerConfiguration(runNumber, ctpcfgstr);
137 }
catch (std::runtime_error& error) {
138 std::cerr <<
"An error occurred: " << error.what() << std::endl;
141 LOG(info) <<
"Run BK:" << run <<
" CFG:" << cfg;
145 ctpcnts.convertRawToO2();
146 std::vector<uint32_t> clsinds = ctpcnts.getClassIndexes();
147 long ts = ctpcnts.getTimeLimit().second;
149 for (
auto const& ind : clsinds) {
150 std::array<uint64_t, 7> cntsbk = ctpcnts.getIntegralForClass(
i);
151 std::string clsname = ctpcfg.getClassNameFromHWIndex(cntsbk[0]);
153 mBKClient->ctpTriggerCounters()->createOrUpdateForRun(runNumber, clsname, ts, cntsbk[1], cntsbk[2], cntsbk[3], cntsbk[4], cntsbk[5], cntsbk[6]);
154 std::cout << runNumber <<
" clsname: " << cntsbk[0] <<
" " << clsname <<
" t:" << ts <<
" cnts:" << cntsbk[1] <<
" " << cntsbk[2] <<
" " << cntsbk[3] <<
" " << cntsbk[4] <<
" " << cntsbk[5] <<
" " << cntsbk[6] << std::endl;
157 }
catch (std::runtime_error& error) {
158 std::cerr <<
"An error occurred: " << error.what() << std::endl;
168 std::cout <<
"o2-ctp-bk-write done" << std::endl;