CbmRoot
Loading...
Searching...
No Matches
services/run_info/app/Application.cxx
Go to the documentation of this file.
1/* Copyright (C) 2025 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
10#include "Application.h"
11
12#include "CbmEnumArray.h"
14
15#include <Logger.h>
16
17#include <boost/program_options.hpp>
18
19#include <cstdlib>
20#include <exception>
21#include <iostream>
22#include <sstream>
23
26
27namespace po = boost::program_options;
28
29
30// ---------------------------------------------------------------------------------------------------------------------
31//
32std::optional<EInfo> Application::ParseOptions(int argc, char* argv[])
33{
35 bool verbose = false;
36
37 // ----- Define options
38 po::options_description opts(" Options");
39 auto optsAdd = opts.add_options();
40 // Default options
41 optsAdd("help,h", "display this help and exit");
42
43 // Required options
44 optsAdd("run,r", po::value<uint32_t>(&fRunId)->value_name("<runID>")->required(),
45 "standard CBM run identifier (required)");
46
47 // Info selection options
48 optsAdd("geotag,g", po::bool_switch(&vbSelected[EInfo::GeoTag])->default_value(false), "prints the geometry tag");
49 optsAdd("print,p", po::bool_switch(&vbSelected[EInfo::Print])->default_value(false),
50 "print available information on the run ID");
51 optsAdd("run-start", po::bool_switch(&vbSelected[EInfo::RunStart])->default_value(false),
52 "print a run starttime in nanoseconds since the epoch");
53 optsAdd("algo-config", po::bool_switch(&vbSelected[EInfo::AlgoConfig])->default_value(false),
54 "print path to the algo config");
55 optsAdd("tof-calibration-tag", po::bool_switch(&vbSelected[EInfo::TofCalibTag])->default_value(false),
56 "print TOF calibration tag");
57 optsAdd("bmon-calibration-tag", po::bool_switch(&vbSelected[EInfo::BmonCalibTag])->default_value(false),
58 "print BMON calibration tag");
59 optsAdd("alignment-tag", po::bool_switch(&vbSelected[EInfo::AlignmentTag])->default_value(false),
60 "print alignment tag");
61 optsAdd("reco-par-tag", po::bool_switch(&vbSelected[EInfo::RecoParTag])->default_value(false),
62 "print reconstruction parameters tag");
63 optsAdd("reco-par-dir", po::bool_switch(&vbSelected[EInfo::RecoParDir])->default_value(false),
64 "print reconstruction parameters directory");
65
66 // Optional
67 optsAdd("verbose,v", po::bool_switch(&verbose)->default_value(false),
68 "Switch logging printout ON (default: only FATAL)");
69
70
71 po::variables_map vars;
72 po::store(po::parse_command_line(argc, argv, opts), vars);
73
74 if (vars.count("help")) {
75 std::cout << opts << std::endl;
76 std::exit(EXIT_SUCCESS);
77 }
78
79 po::notify(vars);
80
81 int nSelectedInfos{0};
82 EInfo selectedInfo{EInfo::Print};
83 for (size_t iInfo = 0; iInfo < vbSelected.size(); ++iInfo) {
84 if (vbSelected[iInfo]) {
85 selectedInfo = static_cast<EInfo>(iInfo);
86 ++nSelectedInfos;
87 }
88 }
89 if (nSelectedInfos > 1) {
90 throw std::logic_error("More than one information items were requested. Please request only one item");
91 }
92
93 if (!verbose) {
94 fair::Logger::SetConsoleSeverity(fair::Severity::fatal);
95 }
96
97 return std::make_optional(selectedInfo);
98}
99
100// ---------------------------------------------------------------------------------------------------------------------
101//
102void Application::Print(EInfo info) const
103{
105 if (!db.LoadRun(fRunId)) {
106 std::cerr << "Failed to load info for run " << fRunId << " from the database (see error above)" << std::endl;
107 throw std::runtime_error("DB Info not available for this run");
108 }
109 std::string dir = std::getenv("VMCWORKDIR") != nullptr ? std::getenv("VMCWORKDIR") : "";
110 if (dir.empty()) {
111 throw std::runtime_error("VMCWORKDIR environmental variable not found. Please configure your CbmRoot");
112 }
113
114 switch (info) {
115 case EInfo::GeoTag: std::cout << db.GetGeoSetupTag() << std::endl; break;
116 case EInfo::TofCalibTag: std::cout << db.GetTofCalibrationTag() << std::endl; break;
117 case EInfo::BmonCalibTag: std::cout << db.GetBmonCalibrationTag() << std::endl; break;
118 case EInfo::AlignmentTag: std::cout << db.GetAlignmentTag() << std::endl; break;
119 case EInfo::RecoParTag: std::cout << db.GetRecoParTag() << std::endl; break;
120 case EInfo::RecoParDir: std::cout << dir << "/" << db.GetRecoParDir() << std::endl; break;
121 case EInfo::AlgoConfig: std::cout << dir << "/" << db.GetAlgoMainConfigPath() << std::endl; break;
122 case EInfo::RunStart: std::cout << db.GetRunStartTimeNs() << std::endl; break;
123 case EInfo::Print: std::cout << db.ToString() << std::endl; break;
124 case EInfo::END: break;
125 };
126}
A singleton helper class for keeping the CbmRunDatabase instance in ROOT environment.
static RunDatabaseContainer & Instance()
Instance access.
void Print(EInfo info) const
Gets and prints information to the stdout.
std::optional< EInfo > ParseOptions(int argc, char *argv[])
Parse command line arguments.
@ RecoParDir
Tag of reconstruction parameters.
@ RunStart
Path to algo main configuration file.
@ AlgoConfig
Directory with reconstruction parameters.
@ END
Prints run information into stdout.
The application class for the run_info service.