Skip to content

Commit a75a1a4

Browse files
committed
clang
1 parent 2bb8638 commit a75a1a4

File tree

2 files changed

+103
-102
lines changed

2 files changed

+103
-102
lines changed

Detectors/CTP/workflowScalers/src/ctp-bk-write.cxx

Lines changed: 100 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -40,128 +40,129 @@ namespace bpo = boost::program_options;
4040

4141
int main(int argc, char** argv)
4242
{
43-
const std::string testCCDB = "http://ccdb-test.cern.ch:8080";
44-
// std::string prodCCDB = "http://o2-ccdb.internal";
45-
const std::string aliceCCDB = "http://alice-ccdb.cern.ch";
46-
bpo::variables_map vm;
47-
bpo::options_description opt_general("Usage:\n " + std::string(argv[0]) +
48-
" Write ctp config or scalers to BK\n");
49-
bpo::options_description opt_hidden("");
50-
bpo::options_description opt_all;
51-
bpo::positional_options_description opt_pos;
52-
try {
43+
const std::string testCCDB = "http://ccdb-test.cern.ch:8080";
44+
// std::string prodCCDB = "http://o2-ccdb.internal";
45+
const std::string aliceCCDB = "http://alice-ccdb.cern.ch";
46+
bpo::variables_map vm;
47+
bpo::options_description opt_general("Usage:\n " + std::string(argv[0]) +
48+
" Write ctp config or scalers to BK\n");
49+
bpo::options_description opt_hidden("");
50+
bpo::options_description opt_all;
51+
bpo::positional_options_description opt_pos;
52+
try {
5353
auto add_option = opt_general.add_options();
5454
add_option("help,h", "Print this help message");
5555
add_option("input-file,f", bpo::value<std::string>()->default_value("none"), "input file name, none - do not read file");
5656
add_option("bkhost,b", bpo::value<std::string>()->default_value("none"), "bk web address");
5757
add_option("ccdb", bpo::value<std::string>()->default_value("alice"), "choose databse: test- test ccdb; prod - production ccdb; alice - alice ccdb; else ccdb parameter");
5858
add_option("run-number,r", bpo::value<uint32_t>()->default_value(0), "run number");
5959
add_option("timestamp,t", bpo::value<uint64_t>()->default_value(0), "timestamp; if 0 timestamp is calulated inside this code");
60-
add_option("cfg,c",bpo::value<bool>()->default_value(0),"Do cfg");
61-
add_option("scalers,s",bpo::value<bool>()->default_value(0),"Do scalers");
60+
add_option("cfg,c", bpo::value<bool>()->default_value(0), "Do cfg");
61+
add_option("scalers,s", bpo::value<bool>()->default_value(0), "Do scalers");
6262
//
6363
opt_all.add(opt_general).add(opt_hidden);
6464
bpo::store(bpo::command_line_parser(argc, argv).options(opt_all).positional(opt_pos).run(), vm);
6565
if (vm.count("help")) {
66-
std::cout << opt_general << std::endl;
67-
exit(0);
66+
std::cout << opt_general << std::endl;
67+
exit(0);
6868
}
6969
bpo::notify(vm);
70-
} catch (bpo::error& e) {
70+
} catch (bpo::error& e) {
7171
std::cerr << "ERROR: " << e.what() << std::endl
72-
<< std::endl;
72+
<< std::endl;
7373
std::cerr << opt_general << std::endl;
7474
exit(1);
75-
} catch (std::exception& e) {
75+
} catch (std::exception& e) {
7676
std::cerr << e.what() << ", application will now exit" << std::endl;
7777
exit(2);
78+
}
79+
uint64_t timestamp = vm["timestamp"].as<uint64_t>();
80+
//
81+
int ret = 0;
82+
std::vector<std::string> runs;
83+
int32_t run = vm["run-number"].as<uint32_t>();
84+
std::cout << "run:" << run << std::endl;
85+
if (run) {
86+
std::cout << "pushing" << std::endl;
87+
runs.push_back(std::to_string(run));
88+
}
89+
// read input file
90+
std::string filename = vm["input-file"].as<std::string>();
91+
std::ifstream file(filename);
92+
if (!file.is_open()) {
93+
std::cout << "Cannot open file! Using only run:" << run << std::endl;
94+
} else {
95+
std::string line;
96+
while (std::getline(file, line)) {
97+
std::cout << line << "\n";
98+
std::vector<std::string> tokens = o2::utils::Str::tokenize(line, ' ');
99+
// int run = std::stoi(tokens[0]);
100+
runs.push_back(tokens[0]);
78101
}
79-
uint64_t timestamp = vm["timestamp"].as<uint64_t>();
80-
//
81-
int ret = 0;
82-
std::vector<std::string> runs;
83-
int32_t run = vm["run-number"].as<uint32_t>();
84-
std::cout << "run:" << run << std::endl;
85-
if(run) {
86-
std::cout << "pushing" << std::endl;
87-
runs.push_back(std::to_string(run));
88-
}
89-
// read input file
90-
std::string filename = vm["input-file"].as<std::string>();
91-
std::ifstream file(filename);
92-
if (!file.is_open()) {
93-
std::cout << "Cannot open file! Using only run:" << run << std::endl;
102+
}
103+
bool cfg = vm["cfg"].as<bool>();
104+
bool scalers = vm["scalers"].as<bool>();
105+
std::cout << "Doing: cfg:" << cfg << " scal:" << scalers << std::endl;
106+
if (cfg || scalers) {
107+
std::string bkhost = vm["bkhost"].as<std::string>();
108+
std::unique_ptr<o2::bkp::api::BkpClient> mBKClient = o2::bkp::api::BkpClientFactory::create(bkhost);
109+
// get from ccdb
110+
std::string ccdbAddress;
111+
if (vm["ccdb"].as<std::string>() == "prod") {
112+
// ccdbAddress = prodCCDB;
113+
} else if (vm["ccdb"].as<std::string>() == "test") {
114+
ccdbAddress = testCCDB;
115+
} else if (vm["ccdb"].as<std::string>() == "alice") {
116+
ccdbAddress = aliceCCDB;
94117
} else {
95-
std::string line;
96-
while (std::getline(file, line)) {
97-
std::cout << line << "\n";
98-
std::vector<std::string> tokens = o2::utils::Str::tokenize(line, ' ');
99-
//int run = std::stoi(tokens[0]);
100-
runs.push_back(tokens[0]);
101-
}
118+
ccdbAddress = vm["ccdb"].as<std::string>();
102119
}
103-
bool cfg = vm["cfg"].as<bool>();
104-
bool scalers = vm["scalers"].as<bool>();
105-
std::cout << "Doing: cfg:" << cfg << " scal:" << scalers << std::endl;
106-
if(cfg || scalers){
107-
std::string bkhost = vm["bkhost"].as<std::string>();
108-
std::unique_ptr<o2::bkp::api::BkpClient> mBKClient = o2::bkp::api::BkpClientFactory::create(bkhost);
109-
//get from ccdb
110-
std::string ccdbAddress;
111-
if (vm["ccdb"].as<std::string>() == "prod") {
112-
//ccdbAddress = prodCCDB;
113-
} else if (vm["ccdb"].as<std::string>() == "test") {
114-
ccdbAddress = testCCDB;
115-
} else if (vm["ccdb"].as<std::string>() == "alice") {
116-
ccdbAddress = aliceCCDB;
117-
} else {
118-
ccdbAddress = vm["ccdb"].as<std::string>();
119-
}
120-
o2::ctp::ctpCCDBManager::setCCDBHost(ccdbAddress);
121-
std::cout << "CCDB: " << vm["ccdb"].as<std::string>() << " " << ccdbAddress << std::endl;
122-
//o2::ccdb::CcdbApi api;
123-
//api.init(ccdbAddress.c_str());
124-
std::map<std::string, std::string> metadata;
125-
for(auto const& run: runs) {
126-
metadata["runNumber"] = run;
127-
bool ok;
128-
int runNumber = std::stoi(run);
129-
auto ctpcfg = o2::ctp::ctpCCDBManager::getConfigFromCCDB(timestamp,run,ok);
120+
o2::ctp::ctpCCDBManager::setCCDBHost(ccdbAddress);
121+
std::cout << "CCDB: " << vm["ccdb"].as<std::string>() << " " << ccdbAddress << std::endl;
122+
// o2::ccdb::CcdbApi api;
123+
// api.init(ccdbAddress.c_str());
124+
std::map<std::string, std::string> metadata;
125+
for (auto const& run : runs) {
126+
metadata["runNumber"] = run;
127+
bool ok;
128+
int runNumber = std::stoi(run);
129+
auto ctpcfg = o2::ctp::ctpCCDBManager::getConfigFromCCDB(timestamp, run, ok);
130130

131-
if(cfg) {
132-
std::string ctpcfgstr = ctpcfg.getConfigString();
133-
try {
134-
mBKClient->run()->setRawCtpTriggerConfiguration(runNumber, ctpcfgstr);
135-
} catch (std::runtime_error& error) {
136-
std::cerr << "An error occurred: " << error.what() << std::endl;
137-
//return 1;
138-
}
139-
LOG(info) << "Run BK:" << run << " CFG:" << cfg;
140-
}
141-
if(scalers){
142-
auto ctpcnts = o2::ctp::ctpCCDBManager::getScalersFromCCDB(timestamp,run, "CTP/Calib/Scalers", ok);
143-
ctpcnts.convertRawToO2();
144-
std::vector<uint32_t> clsinds = ctpcnts.getClassIndexes();
145-
long ts = ctpcnts.getTimeLimit().second;
146-
int i = 0;
147-
for(auto const& ind: clsinds){
148-
std::array<uint64_t,7> cntsbk = ctpcnts.getIntegralForClass(i);
149-
std::string clsname = ctpcfg.getClassNameFromHWIndex(cntsbk[0]);
150-
try {
151-
mBKClient->ctpTriggerCounters()->createOrUpdateForRun(runNumber, clsname, ts, cntsbk[1], cntsbk[2], cntsbk[3], cntsbk[4], cntsbk[5], cntsbk[6]);
152-
std::cout << runNumber << " clsname: " << clsname << "t:" << ts << "cnts:" << cntsbk[1] << " " << cntsbk[2] << " " << cntsbk[3] << " " << cntsbk[4] << " " << cntsbk[5] << " " << cntsbk[6] << std::endl;;
131+
if (cfg) {
132+
std::string ctpcfgstr = ctpcfg.getConfigString();
133+
try {
134+
mBKClient->run()->setRawCtpTriggerConfiguration(runNumber, ctpcfgstr);
135+
} catch (std::runtime_error& error) {
136+
std::cerr << "An error occurred: " << error.what() << std::endl;
137+
// return 1;
138+
}
139+
LOG(info) << "Run BK:" << run << " CFG:" << cfg;
140+
}
141+
if (scalers) {
142+
auto ctpcnts = o2::ctp::ctpCCDBManager::getScalersFromCCDB(timestamp, run, "CTP/Calib/Scalers", ok);
143+
ctpcnts.convertRawToO2();
144+
std::vector<uint32_t> clsinds = ctpcnts.getClassIndexes();
145+
long ts = ctpcnts.getTimeLimit().second;
146+
int i = 0;
147+
for (auto const& ind : clsinds) {
148+
std::array<uint64_t, 7> cntsbk = ctpcnts.getIntegralForClass(i);
149+
std::string clsname = ctpcfg.getClassNameFromHWIndex(cntsbk[0]);
150+
try {
151+
mBKClient->ctpTriggerCounters()->createOrUpdateForRun(runNumber, clsname, ts, cntsbk[1], cntsbk[2], cntsbk[3], cntsbk[4], cntsbk[5], cntsbk[6]);
152+
std::cout << runNumber << " clsname: " << clsname << "t:" << ts << "cnts:" << cntsbk[1] << " " << cntsbk[2] << " " << cntsbk[3] << " " << cntsbk[4] << " " << cntsbk[5] << " " << cntsbk[6] << std::endl;
153+
;
153154

154-
} catch (std::runtime_error& error) {
155-
std::cerr << "An error occurred: " << error.what() << std::endl;
156-
//return 1;
157-
}
158-
LOG(info) << "Run BK scalers ok";
159-
i++;
160-
}
161-
}
155+
} catch (std::runtime_error& error) {
156+
std::cerr << "An error occurred: " << error.what() << std::endl;
157+
// return 1;
158+
}
159+
LOG(info) << "Run BK scalers ok";
160+
i++;
162161
}
163-
// add to bk
162+
}
164163
}
165-
std::cout << "o2-ctp-bk-write done" << std::endl;
166-
return ret;
164+
// add to bk
165+
}
166+
std::cout << "o2-ctp-bk-write done" << std::endl;
167+
return ret;
167168
}

Detectors/CTP/workflowScalers/src/ctpCCDBManager.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,12 @@ int ctpCCDBManager::saveCtpCfg(uint32_t runNumber, long timeStart)
204204
}
205205
CTPConfiguration ctpCCDBManager::getConfigFromCCDB(long timestamp, std::string run, bool& ok)
206206
{
207-
207+
208208
auto& mgr = o2::ccdb::BasicCCDBManager::instance();
209209
mgr.setURL(mCCDBHost);
210210
std::map<std::string, std::string> metadata; // can be empty
211211
metadata["runNumber"] = run;
212-
if(timestamp == 0) {
212+
if (timestamp == 0) {
213213
// Timestamp
214214
auto soreor = mgr.getRunDuration(std::stoi(run));
215215
timestamp = (soreor.second - soreor.first) / 2 + soreor.first;
@@ -257,7 +257,7 @@ CTPRunScalers ctpCCDBManager::getScalersFromCCDB(long timestamp, std::string run
257257
mgr.setURL(mCCDBHost);
258258
std::map<std::string, std::string> metadata; // can be empty
259259
metadata["runNumber"] = run;
260-
if(timestamp == 0) {
260+
if (timestamp == 0) {
261261
// Timestamp
262262
auto soreor = mgr.getRunDuration(std::stoi(run));
263263
timestamp = (soreor.second - soreor.first) / 2 + soreor.first;

0 commit comments

Comments
 (0)