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"
13#include "CbmMcbmUtils.h"
14
15#include <boost/program_options.hpp>
16
17#include <exception>
18#include <iostream>
19#include <sstream>
20
23
24namespace po = boost::program_options;
25
26
27// ---------------------------------------------------------------------------------------------------------------------
28//
29std::optional<EInfo> Application::ParseOptions(int argc, char* argv[])
30{
32
33 // ----- Define options
34 po::options_description opts(" Options");
35 auto optsAdd = opts.add_options();
36 // Default options
37 optsAdd("help,h", "display this help and exit");
38
39 // Required options
40 optsAdd("r,run", po::value<uint32_t>(&fRunId)->required(), "standard CBM run identifier (required)");
41
42 // Info selection options
43 optsAdd("g,geotag", po::bool_switch(&vbSelected[EInfo::GeoTag])->default_value(false), "prints the geometry tag");
44 optsAdd("p,print", po::bool_switch(&vbSelected[EInfo::Print])->default_value(false),
45 "prints available information on the run ID");
46
47 po::variables_map vars;
48 po::store(po::parse_command_line(argc, argv, opts), vars);
49 po::notify(vars);
50
51 if (vars.count("help")) {
52 std::cout << opts << std::endl;
53 return std::nullopt;
54 }
55
56 int nSelectedInfos{0};
57 EInfo selectedInfo{EInfo::Print};
58 for (size_t iInfo = 0; iInfo < vbSelected.size(); ++iInfo) {
59 if (vbSelected[iInfo]) {
60 selectedInfo = static_cast<EInfo>(iInfo);
61 ++nSelectedInfos;
62 }
63 }
64 if (nSelectedInfos > 1) {
65 throw std::logic_error("More then one information items were requested");
66 }
67
68 return std::make_optional(selectedInfo);
69}
70
71// ---------------------------------------------------------------------------------------------------------------------
72//
73void Application::Print(EInfo info) const
74{
75 switch (info) {
76 case EInfo::GeoTag: std::cout << cbm::mcbm::GetSetupFromRunId(fRunId) << std::endl; break;
77 case EInfo::Print: std::cout << GetRunInfo() << std::endl;
78 case EInfo::END: break;
79 };
80}
81
82// ---------------------------------------------------------------------------------------------------------------------
83//
84std::string Application::GetRunInfo() const
85{
86 std::stringstream msg;
87 msg << "------ Run #" << fRunId << '\n';
88 msg << "geometry tag: " << cbm::mcbm::GetSetupFromRunId(fRunId);
89 return msg.str();
90}
std::string GetSetupFromRunId(uint64_t ulRunId)
The application class for the run_info service.