Project
Loading...
Searching...
No Matches
GRPTool.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#include <boost/program_options.hpp>
13#include <cstdlib>
14#include <string>
19#include <fairlogger/Logger.h>
20#include <TFile.h>
24#include <SimConfig/SimConfig.h>
25#include <unordered_map>
26#include <filesystem>
30
31//
32// Created by Sandro Wenzel on 20.06.22.
33//
34
35// A utility to create/edit GRP objects for MC
36
37enum class GRPCommand {
38 kNONE,
39 kCREATE,
40 kANCHOR,
45};
46
47// options struct filled from command line
48struct Options {
49 std::vector<std::string> readout;
50 std::vector<std::string> skipreadout;
51 int run; // run number
52 int orbitsPerTF = 256; // number of orbits per timeframe --> used to calculate start orbit for collisions
54 std::string grpfilename = ""; // generic filename placeholder used by various commands
55 std::vector<std::string> continuous = {};
56 std::vector<std::string> triggered = {};
57 bool clearRO = false;
58 std::string outprefix = "";
59 std::string fieldstring = "";
60 std::string bcPatternFile = "";
61 bool print = false; // whether to print outcome of GRP operation
62 bool lhciffromccdb = false; // whether only to take GRPLHCIF from CCDB
63 std::string publishto = "";
64 std::string ccdbhost = o2::base::NameConf::getCCDBServer(); // honours ALICEO2_CCDB_*; see NameConf::getCCDBServer
65 bool isRun5 = false; // whether or not this is supposed to be a Run5 detector configuration
66 std::string vertex = "ccdb";
67 std::string configKeyValues = "";
68 uint64_t timestamp = 0;
69 std::string detectorList; // detector layout
70};
71
72namespace
73{
74class CCDBHelper
75{
76 public:
77 CCDBHelper(Options const& opts)
78 {
79 api.init(opts.ccdbhost);
80 auto soreor = o2::ccdb::BasicCCDBManager::getRunDuration(api, opts.run);
81 runStart = soreor.first;
82 runEnd = soreor.second;
83 if (opts.timestamp > 0) {
84 timestamp = opts.timestamp;
85 } else {
86 timestamp = runStart;
87 }
88 }
90 uint64_t runStart = -1;
91 uint64_t runEnd = -1;
92 uint64_t timestamp = -1;
93};
94} // namespace
95
96// a simple reusable CCDB wrapper; caching some info across functions
97std::unique_ptr<CCDBHelper> gCCDBWrapper;
98
99void print_globalHelp(int argc, char* argv[])
100{
101 std::cout << "** A GRP utility **\n\n";
102 std::cout << "Usage: " << argv[0] << " subcommand [sub-command-options]\n";
103 std::cout << "\n";
104 std::cout << "The following subcommands are available:\n";
105 std::cout << "\t createGRPs : Create baseline GRP objects/file\n";
106 std::cout << "\t anchorGRPs : Fetch GRP objects from CCDB based on run number\n";
107 std::cout << "\t print_GRPECS : print a GRPECS object/file\n";
108 std::cout << "\t print_GRPMAG : print a GRPMagField object/file\n";
109 std::cout << "\t print_GRPLHC : print a GRPLHCIF object/file\n";
110 std::cout << "\t setROMode : modify/set readoutMode in a GRPECS file\n";
111 std::cout << "\n";
112 std::cout << "Sub-command options can be seen with subcommand --help\n";
113}
114
115namespace
116{
117template <typename T>
118void printGRP(std::string const& filename, std::string const& objtype)
119{
120 std::cout << "\nPrinting " << objtype << " from file " << filename << "\n\n";
121 auto grp = T::loadFrom(filename);
122 if (grp) {
123 grp->print();
124 delete grp;
125 } else {
126 std::cerr << "Error loading " << objtype << " objects from file " << filename << "\n";
127 }
128}
129} // namespace
130
131void printGRPECS(std::string const& filename)
132{
133 printGRP<o2::parameters::GRPECSObject>(filename, "GRPECS");
134}
135
136void printGRPMAG(std::string const& filename)
137{
138 printGRP<o2::parameters::GRPMagField>(filename, "GRPMAG");
139}
140
141void printGRPLHC(std::string const& filename)
142{
143 printGRP<o2::parameters::GRPLHCIFData>(filename, "GRPLHCIF");
144}
145
146void setROMode(std::string const& filename, std::vector<std::string> const& continuous,
147 std::vector<std::string> const& triggered, bool clear = false)
148{
150
151 if (filename.size() == 0) {
152 std::cout << "no filename given\n";
153 return;
154 }
156 const std::string grpName{o2::base::NameConf::CCDBOBJECT};
157 TFile flGRP(filename.c_str(), "update");
158 if (flGRP.IsZombie()) {
159 LOG(error) << "Failed to open GRPECS file " << filename << " in update mode ";
160 return;
161 }
162 std::unique_ptr<GRPECSObject> grp(static_cast<GRPECSObject*>(flGRP.GetObjectChecked(grpName.c_str(), GRPECSObject::Class())));
163 if (grp.get()) {
164 // clear complete state (continuous state) first of all when asked
165 if (clear) {
166 for (auto id = DetID::First; id <= DetID::Last; ++id) {
167 if (grp->isDetReadOut(id)) {
168 grp->remDetContinuousReadOut(id);
169 }
170 }
171 }
172
173 //
174 for (auto& detstr : continuous) {
175 // convert to detID
176 o2::detectors::DetID id(detstr.c_str());
177 if (grp->isDetReadOut(id)) {
178 grp->addDetContinuousReadOut(id);
179 LOG(info) << "Setting det " << detstr << " to continuous RO mode";
180 }
181 }
182 //
183 for (auto& detstr : triggered) {
184 // convert to detID
185 o2::detectors::DetID id(detstr.c_str());
186 if (grp->isDetReadOut(id)) {
187 grp->addDetTrigger(id);
188 LOG(info) << "Setting det " << detstr << " to trigger CTP";
189 }
190 }
191 grp->print();
192 flGRP.WriteObjectAny(grp.get(), grp->Class(), grpName.c_str());
193 }
194 flGRP.Close();
195}
196
197// copies a file idendified by filename to a CCDB snapshot starting under path
198// and with the CCDBpath hierarchy
199bool publish(std::string const& filename, std::string const& path, std::string CCDBpath)
200{
201 if (!std::filesystem::exists(filename)) {
202 LOG(error) << "Input file " << filename << "does not exist\n";
203 return false;
204 }
205
206 std::string targetdir = path + CCDBpath;
207 try {
209 } catch (std::exception e) {
210 LOGP(error, "Could not create local snapshot cache directory {}, reason: {}", targetdir, e.what());
211 return false;
212 }
213
214 auto targetfile = std::filesystem::path(targetdir + "/snapshot.root");
215 auto opts = std::filesystem::copy_options::overwrite_existing;
216 std::filesystem::copy_file(filename, targetfile, opts);
217 if (std::filesystem::exists(targetfile)) {
218 LOG(info) << "file " << filename << " copied/published to " << targetfile;
219 }
220 return true;
221}
222
223// download a set of basic GRP files based on run number/time
224bool anchor_GRPs(Options const& opts, std::vector<std::string> const& paths = {"GLO/Config/GRPECS", "GLO/Config/GRPMagField", "GLO/Config/GRPLHCIF"})
225{
226 if (!gCCDBWrapper) {
227 gCCDBWrapper = std::move(std::make_unique<CCDBHelper>(opts));
228 }
229 // fix the timestamp early
230 uint64_t timestamp = gCCDBWrapper->timestamp;
231
232 const bool preserve_path = true;
233 const std::string filename("snapshot.root");
234 std::map<std::string, std::string> filter;
235 bool success = true;
236 for (auto& p : paths) {
237 LOG(info) << "Fetching " << p << " from CCDB";
238 success &= gCCDBWrapper->api.retrieveBlob(p, opts.publishto, filter, timestamp, preserve_path, filename);
239 }
240 return success;
241}
242
243// creates a mean vertex object for further use (CCDB queries) in the CCDB cache
245{
246 // either
247 const char* CCDBPATH = "/GLO/Calib/MeanVertex";
248 if (opts.vertex == "ccdb") {
249 anchor_GRPs(opts, {CCDBPATH});
250 } else {
251 LOG(info) << "Creating MeanVertex object on the fly using the InteractionDiamond params";
253 const auto& xyz = param.position;
254 const auto& sigma = param.width;
255 std::unique_ptr<o2::dataformats::MeanVertexObject> meanv(new o2::dataformats::MeanVertexObject(xyz[0], xyz[1], xyz[2], sigma[0], sigma[1], sigma[2], param.slopeX, param.slopeY));
257 api.init("file://" + opts.publishto);
258 std::map<std::string, std::string> meta;
259 meta["Created-by"] = "Monte Carlo GRPTool";
260 if (!gCCDBWrapper) {
261 gCCDBWrapper = std::move(std::make_unique<CCDBHelper>(opts));
262 }
263 api.storeAsTFileAny(meanv.get(), CCDBPATH, meta, gCCDBWrapper->runStart, gCCDBWrapper->runEnd);
264
265 // we created a file not called snapshot.root ---> still need to do this ... so that this object get's picked up later on
266 // we pick up the latest produced file and will rename it to snapshot.root (thanks ChatGPT)
267 std::filesystem::path directory_path = opts.publishto + CCDBPATH;
268 // Timepoint to hold the latest modification time
269 std::filesystem::file_time_type latest_time = std::filesystem::file_time_type::min();
270 // Path to hold the latest modified file
271 std::filesystem::path latest_file;
272 // Iterate over all files in the directory
273 for (const auto& file : std::filesystem::directory_iterator(directory_path)) {
274 // Check if the file is a regular file
275 if (file.is_regular_file()) {
276 // Get the last modification time of the file
277 std::filesystem::file_time_type mod_time = std::filesystem::last_write_time(file.path());
278 // Check if the modification time is later than the latest time found so far
279 if (mod_time > latest_time) {
280 latest_time = mod_time;
281 latest_file = file.path();
282 }
283 }
284 }
285 auto oldpath = latest_file;
286 auto newpath = latest_file.parent_path();
287 newpath.append(std::string("snapshot.root"));
288 std::filesystem::rename(oldpath, newpath);
289 }
290 return true;
291}
292
293// creates a set of basic GRP files (for simulation)
294bool create_GRPs(Options const& opts)
295{
296 // some code duplication from o2-sim --> remove it
297
298 uint64_t runStart = -1; // used in multiple GRPs
299
300 // MeanVertexObject
301 {
302 LOG(info) << "---- creating MeanVertex ----";
304 }
305
306 // GRPECS
307 {
308 LOG(info) << " --- creating GRP ECS -----";
310 grp.setRun(opts.run);
311 // if
312 auto& ccdbmgr = o2::ccdb::BasicCCDBManager::instance();
313 auto soreor = ccdbmgr.getRunDuration(opts.run);
314 runStart = soreor.first;
315 grp.setTimeStart(runStart);
316 grp.setTimeEnd(soreor.second);
317 grp.setNHBFPerTF(opts.orbitsPerTF);
318 std::vector<std::string> modules{};
319 if (!o2::conf::SimConfig::determineActiveModulesList(opts.detectorList, opts.readout, std::vector<std::string>(), modules)) {
320 return false;
321 }
322 std::vector<std::string> readout{};
323 o2::conf::SimConfig::determineReadoutDetectors(modules, std::vector<std::string>(), opts.skipreadout, readout);
324 for (auto& detstr : readout) {
325 o2::detectors::DetID id(detstr.c_str());
326 grp.addDetReadOut(id);
327 // set default RO modes
330 }
331 }
332 grp.setIsMC(true);
333 grp.setRunType(o2::parameters::GRPECSObject::RunType::PHYSICS);
334 // grp.setDataPeriod("mc"); // decide what to put here
335 std::string grpfilename = o2::base::NameConf::getGRPECSFileName(opts.outprefix);
336 TFile grpF(grpfilename.c_str(), "recreate");
337 grpF.WriteObjectAny(&grp, grp.Class(), o2::base::NameConf::CCDBOBJECT.data());
338 grpF.Close();
339 if (opts.print) {
340 grp.print();
341 }
342 if (opts.publishto.size() > 0) {
343 publish(grpfilename, opts.publishto, "/GLO/Config/GRPECS");
344 }
345 }
346
347 // GRPMagField
348 {
349 LOG(info) << " --- creating magfield GRP -----";
351 // parse the wanted field value
352 int fieldvalue = 0;
353 o2::conf::SimFieldMode fieldmode;
354 auto ok = o2::conf::SimConfig::parseFieldString(opts.fieldstring, fieldvalue, fieldmode);
355 if (!ok) {
356 LOG(error) << "Error parsing field string " << opts.fieldstring;
357 return false;
358 }
359
360 if (fieldmode == o2::conf::SimFieldMode::kCCDB) {
361 // we download the object from CCDB
362 LOG(info) << "Downloading mag field directly from CCDB";
363 if (!anchor_GRPs(opts, {"GLO/Config/GRPMagField"})) {
364 LOG(fatal) << "Downloading mag field failed";
365 }
366 if (opts.print) {
367 // print the object that was downloaded
368 printGRPMAG(std::string(opts.publishto) + std::string("/GLO/Config/GRPMagField/snapshot.root"));
369 }
370 } else {
371 // let's not create an actual mag field object for this
372 // we only need to lookup the currents from the possible
373 // values of mag field
374 // +-2,+-5,0 and uniform
375
376 const std::unordered_map<int, std::pair<int, int>> field_to_current = {{2, {12000, 6000}},
377 {5, {30000, 6000}},
378 {-2, {-12000, -6000}},
379 {-5, {-30000, -6000}},
380 {0, {0, 0}}};
381
382 auto currents_iter = field_to_current.find(fieldvalue);
383 if (currents_iter == field_to_current.end()) {
384 LOG(error) << " Could not lookup currents for fieldvalue " << fieldvalue;
385 return false;
386 }
387
388 o2::units::Current_t currDip = (*currents_iter).second.second;
389 o2::units::Current_t currL3 = (*currents_iter).second.first;
390 grp.setL3Current(currL3);
391 grp.setDipoleCurrent(currDip);
393 if (opts.print) {
394 grp.print();
395 }
396 std::string grpfilename = o2::base::NameConf::getGRPMagFieldFileName(opts.outprefix);
397 TFile grpF(grpfilename.c_str(), "recreate");
398 grpF.WriteObjectAny(&grp, grp.Class(), o2::base::NameConf::CCDBOBJECT.data());
399 grpF.Close();
400 if (opts.publishto.size() > 0) {
401 publish(grpfilename, opts.publishto, "/GLO/Config/GRPMagField");
402 }
403 }
404 }
405
406 // GRPLHCIF --> complete it later
407 {
408 LOG(info) << " --- creating GRP LHCIF -----";
409 if (opts.lhciffromccdb) { // if we take the whole object it directly from CCDB, we can just download it
410 LOG(info) << "Downloading complete GRPLHCIF object directly from CCDB";
411 anchor_GRPs(opts, {"GLO/Config/GRPLHCIF"});
412 } else {
414 // eventually we need to set the beam info from the generator, at the moment put some plausible values
415 grp.setFillNumberWithTime(runStart, 0); // RS FIXME
416 grp.setInjectionSchemeWithTime(runStart, ""); // RS FIXME
417 grp.setBeamEnergyPerZWithTime(runStart, 6.8e3); // RS FIXME
418 grp.setAtomicNumberB1WithTime(runStart, 1.); // RS FIXME
419 grp.setAtomicNumberB2WithTime(runStart, 1.); // RS FIXME
420 grp.setCrossingAngleWithTime(runStart, 0.); // RS FIXME
421 grp.setBeamAZ();
422
423 // set the BC pattern if necessary
424 if (opts.bcPatternFile.size() > 0) {
425 // load bunch filling from the file (with standard CCDB convention)
426 auto* bc = o2::BunchFilling::loadFrom(opts.bcPatternFile, "ccdb_object");
427 if (!bc) {
428 // if it failed, retry with default naming
430 }
431 if (!bc) {
432 LOG(fatal) << "Failed to load bunch filling from " << opts.bcPatternFile;
433 }
434 grp.setBunchFillingWithTime(grp.getBeamEnergyPerZTime(), *bc); // borrow the time from the existing entry
435 delete bc;
436 } else {
437 // we initialize with a default bunch filling scheme;
438 LOG(info) << "Initializing with default bunch filling";
440 bc.setDefault();
442 }
443
444 std::string grpfilename = o2::base::NameConf::getGRPLHCIFFileName(opts.outprefix);
445 if (opts.print) {
446 grp.print();
447 }
448 TFile grpF(grpfilename.c_str(), "recreate");
449 grpF.WriteObjectAny(&grp, grp.Class(), o2::base::NameConf::CCDBOBJECT.data());
450 grpF.Close();
451 if (opts.publishto.size() > 0) {
452 publish(grpfilename, opts.publishto, "/GLO/Config/GRPLHCIF");
453 }
454 }
455 }
456
457 return true;
458}
459
460void perform_Command(Options const& opts)
461{
462 switch (opts.command) {
463 case GRPCommand::kCREATE: {
464 create_GRPs(opts);
465 break;
466 }
467 case GRPCommand::kANCHOR: {
468 anchor_GRPs(opts);
469 break;
470 }
473 break;
474 }
477 break;
478 }
481 break;
482 }
484 setROMode(opts.grpfilename, opts.continuous, opts.triggered, opts.clearRO);
485 break;
486 }
487 default: {
488 }
489 }
490}
491
492bool parseOptions(int argc, char* argv[], Options& optvalues)
493{
494 namespace bpo = boost::program_options;
495 bpo::options_description global("Global options");
496 global.add_options()("command", bpo::value<std::string>(), "command to execute")("subargs", bpo::value<std::vector<std::string>>(), "Arguments for command");
497 global.add_options()("help,h", "Produce help message.");
498
499 bpo::positional_options_description pos;
500 pos.add("command", 1).add("subargs", -1);
501
502 bpo::variables_map vm;
503 bpo::parsed_options parsed{nullptr};
504 try {
505 parsed = bpo::command_line_parser(argc, argv).options(global).positional(pos).allow_unregistered().run();
506
507 bpo::store(parsed, vm);
508
509 // help
510 if (vm.count("help") > 0 && vm.count("command") == 0) {
511 print_globalHelp(argc, argv);
512 return false;
513 }
514 } catch (const bpo::error& e) {
515 std::cerr << e.what() << "\n\n";
516 std::cerr << "Error parsing global options; Available options:\n";
517 std::cerr << global << std::endl;
518 return false;
519 }
520
521 auto subparse = [&parsed](auto& desc, auto& vm, std::string const& command_name) {
522 try {
523 // Collect all the unrecognized options from the first pass. This will include the
524 // (positional) command name, so we need to erase that.
525 std::vector<std::string> opts = bpo::collect_unrecognized(parsed.options, bpo::include_positional);
526 // opts.erase(opts.begin());
527
528 // Parse again... and store to vm
529 bpo::store(bpo::command_line_parser(opts).options(desc).run(), vm);
530 bpo::notify(vm);
531
532 if (vm.count("help")) {
533 std::cout << desc << std::endl;
534 return false;
535 }
536 } catch (const bpo::error& e) {
537 std::cerr << e.what() << "\n\n";
538 std::cerr << "Error parsing options for " << command_name << " Available options:\n";
539 std::cerr << desc << std::endl;
540 return false;
541 }
542 return true;
543 };
544
545 std::string cmd = vm["command"].as<std::string>();
546
547 if (cmd == "anchorGRPs") {
548 optvalues.command = GRPCommand::kANCHOR;
549 // ls command has the following options:
550 bpo::options_description desc("anchor GRP options");
551
552 // ls command has the following options:
553 desc.add_options()("run", bpo::value<int>(&optvalues.run)->default_value(-1), "Run number");
554 desc.add_options()("print", "print resulting GRPs");
555 desc.add_options()("publishto", bpo::value<std::string>(&optvalues.publishto)->default_value("GRP"), "Base path under which GRP objects should be published on disc. This path can serve as lookup for CCDB queries of the GRP objects.");
556 if (!subparse(desc, vm, "anchorGRPs")) {
557 return false;
558 }
559 if (vm.count("print") > 0) {
560 optvalues.print = true;
561 }
562 } else if (cmd == "createGRPs") {
563 optvalues.command = GRPCommand::kCREATE;
564
565 // ls command has the following options:
566 bpo::options_description desc("create options");
567 desc.add_options()("detectorList", bpo::value<std::string>(&optvalues.detectorList)->default_value("ALICE2"), "Pick a specific version of ALICE, for specifics check the o2-sim description");
568 desc.add_options()("readoutDets", bpo::value<std::vector<std::string>>(&optvalues.readout)->multitoken()->default_value(std::vector<std::string>({"all"}), "all Run3 detectors"), "Detector list to be readout/active");
569 desc.add_options()("skipReadout", bpo::value<std::vector<std::string>>(&optvalues.skipreadout)->multitoken()->default_value(std::vector<std::string>(), "nothing skipped"), "list of inactive detectors (precendence over --readout)");
570 desc.add_options()("run", bpo::value<int>(&optvalues.run)->default_value(-1), "Run number");
571 desc.add_options()("hbfpertf", bpo::value<int>(&optvalues.orbitsPerTF)->default_value(128), "heart beat frames per timeframe (timeframelength)");
572 desc.add_options()("field", bpo::value<std::string>(&optvalues.fieldstring)->default_value("-5"), "L3 field rounded to kGauss, allowed values +-2,+-5 and 0; +-<intKGaus>U for uniform field");
573 desc.add_options()("outprefix,o", bpo::value<std::string>(&optvalues.outprefix)->default_value("o2sim"), "Prefix for GRP output files");
574 desc.add_options()("bcPatternFile", bpo::value<std::string>(&optvalues.bcPatternFile)->default_value(""), "Interacting BC pattern file (e.g. from CreateBCPattern.C)");
575 desc.add_options()("lhcif-CCDB", "take GRPLHCIF directly from CCDB");
576 desc.add_options()("print", "print resulting GRPs");
577 desc.add_options()("publishto", bpo::value<std::string>(&optvalues.publishto)->default_value(""), "Base path under which GRP objects should be published on disc. This path can serve as lookup for CCDB queries of the GRP objects.");
578 desc.add_options()("isRun5", bpo::bool_switch(&optvalues.isRun5), "Whether or not to expect a Run5 detector configuration. (deprecated, use detectorList option)");
579 desc.add_options()("vertex", bpo::value<std::string>(&optvalues.vertex)->default_value("ccdb"), "How the vertex is to be initialized. Default is CCDB. Alternative is \"Diamond\" which is constructing the mean vertex from the Diamond param via the configKeyValues path");
580 desc.add_options()("timestamp", bpo::value<uint64_t>(&optvalues.timestamp)->default_value(0), "Force timestamp to be used (useful when anchoring)");
581 desc.add_options()("configKeyValues", bpo::value<std::string>(&optvalues.configKeyValues)->default_value(""), "Semicolon separated key=value strings (e.g.: 'TPC.gasDensity=1;...')");
582 if (!subparse(desc, vm, "createGRPs")) {
583 return false;
584 }
585 if (vm.count("print") > 0) {
586 optvalues.print = true;
587 }
588 if (vm.count("lhcif-CCDB") > 0) {
589 optvalues.lhciffromccdb = true;
590 }
591 auto vertexmode = vm["vertex"].as<std::string>();
592 if (!(vertexmode == "ccdb" || vertexmode == "Diamond")) {
593 return false;
594 }
595 // init params
597
598 } else if (cmd == "setROMode") {
599 // set/modify the ROMode
601 bpo::options_description desc("setting detector readout modes");
602 desc.add_options()("file,f", bpo::value<std::string>(&optvalues.grpfilename)->default_value("o2sim_grpecs.root"), "Path to GRPECS file");
603 desc.add_options()("continuousRO", bpo::value<std::vector<std::string>>(&optvalues.continuous)->multitoken()->default_value(std::vector<std::string>({"all"}), "all active detectors"), "List of detectors to set to continuous mode");
604 desc.add_options()("triggerCTP", bpo::value<std::vector<std::string>>(&optvalues.triggered)->multitoken()->default_value(std::vector<std::string>({""}), "none"), "List of detectors to trigger CTP");
605 desc.add_options()("clear", "clears all RO modes (prio to applying other options)");
606 if (!subparse(desc, vm, "setROMode")) {
607 return false;
608 }
609 if (vm.count("clear") > 0) {
610 optvalues.clearRO = true;
611 }
612 } else if (cmd == "print_GRPECS") {
613 optvalues.command = GRPCommand::kPRINTECS;
614 // print the GRP
615 bpo::options_description desc("print options");
616 desc.add_options()("file,f", bpo::value<std::string>(&optvalues.grpfilename), "Path to GRP file");
617 if (!subparse(desc, vm, "print_GRPECS")) {
618 return false;
619 }
620 } else if (cmd == "print_GRPLHC") {
621 optvalues.command = GRPCommand::kPRINTLHC;
622 // print the GRP
623 bpo::options_description desc("print options");
624 desc.add_options()("file,f", bpo::value<std::string>(&optvalues.grpfilename), "Path to GRP file");
625 if (!subparse(desc, vm, "print_GRPECS")) {
626 return false;
627 }
628 } else if (cmd == "print_GRPMAG") {
629 optvalues.command = GRPCommand::kPRINTMAG;
630 // print the GRP
631 bpo::options_description desc("print options");
632 desc.add_options()("file,f", bpo::value<std::string>(&optvalues.grpfilename), "Path to GRP file");
633 if (!subparse(desc, vm, "print_GRPECS")) {
634 return false;
635 }
636 } else {
637 std::cerr << "Error: Unknown command " << cmd << std::endl;
638 return false;
639 }
640
641 return true;
642}
643
644int main(int argc, char* argv[])
645{
646 Options options;
647 if (parseOptions(argc, argv, options)) {
648 perform_Command(options);
649 } else {
650 std::cout << "Parse options failed\n";
651 return 1;
652 }
653 return 0;
654}
uint64_t bc
Definition RawEventData.h:5
Header of the AggregatedRunInfo struct.
container for the LHC InterFace data
Header of the General Run Parameters object for B field values.
bool publish(std::string const &filename, std::string const &path, std::string CCDBpath)
Definition GRPTool.cxx:199
bool create_MeanVertexObject(Options const &opts)
Definition GRPTool.cxx:244
void printGRPECS(std::string const &filename)
Definition GRPTool.cxx:131
std::unique_ptr< CCDBHelper > gCCDBWrapper
Definition GRPTool.cxx:97
void print_globalHelp(int argc, char *argv[])
Definition GRPTool.cxx:99
void setROMode(std::string const &filename, std::vector< std::string > const &continuous, std::vector< std::string > const &triggered, bool clear=false)
Definition GRPTool.cxx:146
GRPCommand
Definition GRPTool.cxx:37
bool anchor_GRPs(Options const &opts, std::vector< std::string > const &paths={"GLO/Config/GRPECS", "GLO/Config/GRPMagField", "GLO/Config/GRPLHCIF"})
Definition GRPTool.cxx:224
bool create_GRPs(Options const &opts)
Definition GRPTool.cxx:294
void perform_Command(Options const &opts)
Definition GRPTool.cxx:460
bool parseOptions(int argc, char *argv[], Options &optvalues)
Definition GRPTool.cxx:492
void printGRPMAG(std::string const &filename)
Definition GRPTool.cxx:136
void printGRPLHC(std::string const &filename)
Definition GRPTool.cxx:141
Definition of the Names Generator class.
uint16_t pos
Definition RawData.h:3
static BunchFilling * loadFrom(const std::string &fileName, const std::string &objName="")
static std::string getGRPECSFileName(const std::string_view prefix=STANDARDSIMPREFIX)
Definition NameConf.cxx:65
static std::string getGRPLHCIFFileName(const std::string_view prefix=STANDARDSIMPREFIX)
Definition NameConf.cxx:71
static constexpr std::string_view CCDBOBJECT
Definition NameConf.h:66
static std::string getCCDBServer()
Definition NameConf.cxx:123
static std::string getGRPMagFieldFileName(const std::string_view prefix=STANDARDSIMPREFIX)
Definition NameConf.cxx:77
static BasicCCDBManager & instance()
std::pair< int64_t, int64_t > getRunDuration(int runnumber, bool fatal=true)
int storeAsTFileAny(const T *obj, std::string const &path, std::map< std::string, std::string > const &metadata, long startValidityTimestamp=-1, long endValidityTimestamp=-1, std::vector< char >::size_type maxSize=0) const
Definition CcdbApi.h:163
void init(std::string const &hosts)
Definition CcdbApi.cxx:237
static void updateFromString(std::string const &)
static bool parseFieldString(std::string const &fieldstring, int &fieldvalue, o2::conf::SimFieldMode &mode)
static void determineReadoutDetectors(std::vector< std::string > const &active, std::vector< std::string > const &enabledRO, std::vector< std::string > const &skippedRO, std::vector< std::string > &finalRO)
static bool determineActiveModulesList(const std::string &version, std::vector< std::string > const &input, std::vector< std::string > const &skipped, std::vector< std::string > &active)
Static class with identifiers, bitmasks and names for ALICE detectors.
Definition DetID.h:60
static constexpr ID Last
if extra detectors added, update this !!!
Definition DetID.h:95
static constexpr bool alwaysTriggeredRO(DetID::ID det)
void setTimeEnd(timePoint t)
void setTimeStart(timePoint t)
void setNHBFPerTF(uint32_t n)
void addDetReadOut(DetID id)
add specific detector to the list of readout detectors
void addDetContinuousReadOut(DetID id)
add specific detector to the list of continuously readout detectors
void print() const
print itself
void setBeamAZ(int a, int z, beamDirection beam)
void setBunchFillingWithTime(std::pair< long, o2::BunchFilling > p)
void setBeamEnergyPerZWithTime(std::pair< long, int32_t > p)
void setCrossingAngleWithTime(std::pair< long, o2::units::AngleRad_t > p)
void setAtomicNumberB1WithTime(std::pair< long, int32_t > p)
void setFillNumberWithTime(std::pair< long, int32_t > p)
void setInjectionSchemeWithTime(std::pair< long, std::string > p)
void setAtomicNumberB2WithTime(std::pair< long, int32_t > p)
void setDipoleCurrent(o2::units::Current_t v)
Definition GRPMagField.h:52
void print() const
print itself
void setL3Current(o2::units::Current_t v)
Definition GRPMagField.h:51
void setFieldUniformity(bool v)
Definition GRPMagField.h:53
GLsizei const GLuint * paths
Definition glcorearb.h:5475
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition glcorearb.h:1308
GLsizei const GLchar *const * path
Definition glcorearb.h:3591
GLenum GLfloat param
Definition glcorearb.h:271
GLuint id
Definition glcorearb.h:650
std::string timestamp() noexcept
Definition Clock.h:84
void createDirectoriesIfAbsent(std::string const &path)
std::string filename()
std::string publishto
Definition GRPTool.cxx:63
std::vector< std::string > readout
Definition GRPTool.cxx:49
std::string outprefix
Definition GRPTool.cxx:58
bool print
Definition GRPTool.cxx:61
std::string configKeyValues
Definition GRPTool.cxx:67
std::vector< std::string > triggered
Definition GRPTool.cxx:56
std::string grpfilename
Definition GRPTool.cxx:54
std::string ccdbhost
Definition GRPTool.cxx:64
std::string fieldstring
Definition GRPTool.cxx:59
int run
Definition GRPTool.cxx:51
bool isRun5
Definition GRPTool.cxx:65
std::vector< std::string > skipreadout
Definition GRPTool.cxx:50
bool clearRO
Definition GRPTool.cxx:57
uint64_t timestamp
Definition GRPTool.cxx:68
std::string vertex
Definition GRPTool.cxx:66
std::vector< std::string > continuous
Definition GRPTool.cxx:55
std::string detectorList
Definition GRPTool.cxx:69
GRPCommand command
Definition GRPTool.cxx:53
bool lhciffromccdb
Definition GRPTool.cxx:62
std::string bcPatternFile
Definition GRPTool.cxx:60
int orbitsPerTF
Definition GRPTool.cxx:52
#define main
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
vec clear()