CbmRoot
Loading...
Searching...
No Matches
algo/base/Options.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Felix Weiglhofer [committer] */
4#include "algo/base/Options.h"
5
8
9#include <boost/program_options.hpp>
10
11#include <iostream>
12#include <iterator>
13#include <unordered_map>
14
15using namespace cbm::algo;
16namespace po = boost::program_options;
17
18using fles::Subsystem;
19
20
21namespace std
22{
23 template<class T>
24 std::ostream& operator<<(std::ostream& os, const std::vector<T>& v)
25 {
26 copy(v.begin(), v.end(), std::ostream_iterator<T>(os, " "));
27 return os;
28 }
29} // namespace std
30
31#ifndef CBM_ONLINE_USE_FAIRLOGGER
32void validate(boost::any& v, const std::vector<std::string>& values, severity_level*, int)
33{
34
35 static const std::unordered_map<std::string, severity_level> levels{
36 {"trace", severity_level::trace}, {"debug", severity_level::debug}, {"status", severity_level::status},
37 {"info", severity_level::info}, {"warning", severity_level::warning}, {"error", severity_level::error},
38 {"fatal", severity_level::fatal}};
39
40 po::validators::check_first_occurrence(v);
41
42 const std::string& s = po::validators::get_single_string(values);
43
44 auto it = levels.find(s);
45
46 if (it == levels.end()) throw po::validation_error(po::validation_error::invalid_option_value);
47
48 v = it->second;
49}
50#endif // Not CBM_ONLINE_USE_FAIRLOGGER
51
52Options::Options(int argc, char** argv)
53{
54
55 po::options_description required("Required options");
56 // clang-format off
57 required.add_options()
58 ("config,p", po::value(&fMainConfigPath)->value_name("<file>")->required(),
59 "Path to the configuration file")
60 ("input-locator,i", po::value(&fInputLocator)->value_name("<locator>")->required(),
61 "URI specifying input timeslice source")
62 ;
63 // clang-format on
64
65 po::options_description generic("Other options");
66 // clang-format off
67 generic.add_options()
68 ("output,o", po::value(&fOutputFile)->default_value("")->value_name("<template>"), "write results to file(s)")
69 ("output-max-size", po::value(&fOutputMaxSize)->default_value(0)->value_name("<size>"), "max size of a single output file (bytes)")
70 ("output-max-items", po::value(&fOutputMaxItems)->default_value(0)->value_name("<num>"), "max number of output items in a single file")
71 ("batch-qa-output", po::value(&fBatchQaOutput)->default_value("")->value_name("<file>"), "writes QA histogram to <file>, IF THE HISTOGRAM SERVER IS NOT AVAILABLE")
72 ("device,d", po::value(&fDevice)->default_value("cpu")->value_name("<device>"),
73 "select device (cpu, cuda0, cuda1, hip0, ...)")
75 ("log-level,l", po::value(&fLogLevel)->default_value(info)->value_name("<level>"),
76 "set log level (debug, info, warning, error, fatal)")
77#endif // Not CBM_ONLINE_USE_FAIRLOGGER
78 ("monitor,m", po::value(&fMonitorUri)->value_name("<uri>")->implicit_value("file:cout"),
79 "URI specifying monitor output (e.g. file:/tmp/monitor.txt, influx1:login:8086:cbmreco_status). Prints to cout when no argument is given. Monitor is disabled when flag is not set.")
80 ("histogram", po::value(&fHistogramUri)->value_name("<uri>"), "URI to specify histogram server")
81 ("histoshwm", po::value(&fHistogramHwm)->default_value(1)->value_name("<num>"),
82 "High-Water Mark for ZMQ socket to histogram server in messages:\n"
83 " 0 = no buffering, num = nb updates kept in buffer if not pulled by server \n"
84 " Tune to avoid too high memory usage but also adapt to server load!")
85 ("aux-data", po::value(&fCollectAuxData)->implicit_value(true), "Enables collecting of auxiliary data from algorithms")
86 ("qa", po::value(&fQaSteps)->multitoken()->default_value({QaStep::UnpackSts, QaStep::EventBuilding, QaStep::Tracking})->value_name("<qa steps>"),
87 "space separated list of QA Steps to enable (BeamBmon, UnpackSts, EventBuilding, Tracking, ...)")
88#ifdef BOOST_IOS_HAS_ZSTD
89 ("hist-compr", po::bool_switch(&fCompressHistograms)->default_value(false),
90 "enables ZSTD compression of the outgoing histograms stream (decompression needed in target server!)")
91#endif
92 ("log-file,L", po::value(&fLogFile)->value_name("<file>"),
93 "write log messages to file")
94 ("output-types,O", po::value(&fOutputTypes)->multitoken()->value_name("<types>"),
95 "space separated list of reconstruction output types (Hit, Tracks, DigiTimeslice, DigiEvent, ...)")
96 ("compress-archive", po::bool_switch(&fCompressArchive)->default_value(false), "Enable compression for output archives")
97 ("steps", po::value(&fRecoSteps)->multitoken()->default_value({Step::Unpack, Step::DigiTrigger, Step::LocalReco, Step::Tracking})->value_name("<steps>"),
98 "space separated list of reconstruction steps (unpack, digitrigger, localreco, ...)")
99 ("event-reco", po::bool_switch(&fReconstructDigiEvents)->default_value(false), "runs digi event reconstruction (local reco, tracking, trigger)")
100 ("systems,s", po::value(&fDetectors)->multitoken()->default_value({Subsystem::STS, Subsystem::TOF, Subsystem::BMON, Subsystem::MUCH, Subsystem::RICH, Subsystem::TRD, Subsystem::TRD2D})->value_name("<detectors>"),
101 "space separated list of detectors to process (sts, mvd, ...)")
102 ("child-id,c", po::value(&fChildId)->default_value("00")->value_name("<id>"), "online process id on node")
103 ("run-id,r", po::value(&fRunId)->default_value(2391)->value_name("<RunId>"), "Run ID, for now flesctl run index, later run start time")
104 ("run-start", po::value(&fRunStartTime)->default_value(0)->value_name("<RunStart >"), "Run start time in ns, can be fles start or online start")
105 ("num-ts,n", po::value(&fNumTimeslices)->default_value(-1)->value_name("<num>"),
106 "Stop after <num> timeslices (-1 = all)")
107 ("skip-ts", po::value(&fSkipTimeslices)->default_value(0)->value_name("<num>"),
108 "Skip first <num> timeslices")
109 ("omp", po::value(&fNumOMPThreads)->default_value(-1)->value_name("<num>"),
110 "Set number of OpenMP threads (-1 = use OMP_NUM_THREADS environment variable)")
111 ("times,t", po::value(&fProfilingLevel)->default_value(ProfilingNone)->implicit_value(ProfilingPerTS),
112 "Print kernel times (Can opt. be given a value: Use none to disable or summary to only print aggregated times.)")
113 ("timings-file", po::value(&fTimingsFile)->value_name("<file>"),
114 "Write profiling times to yaml file (only when '-t' is set)")
115 ("dump-archive", po::bool_switch(&fDumpArchive)->default_value(false),
116 "Dump archive content to stdout and exit. Provide archive with '-i'. (This is a hack to quick check archive content until we have proper tooling.)")
117 ("release-mode,R",po::value<bool>(&fReleaseMode)->implicit_value(true),
118 "Copy and release each timeslice immediately after receiving it")
119 ("help,h",
120 "produce help message")
121 ;
122 // clang-format on
123
124 po::options_description cmdline_options;
125 cmdline_options.add(required).add(generic);
126
127 po::variables_map vm;
128 po::command_line_parser parser{argc, argv};
129 parser.options(cmdline_options);
130 try {
131 auto result = parser.run();
132 po::store(result, vm);
133 }
134 catch (const std::exception& e) {
135 std::cerr << "Error: " << e.what() << std::endl;
136 std::cerr << "Use '-h' to display all valid options." << std::endl;
137 std::exit(EXIT_FAILURE);
138 }
139
140 if (vm.count("help") > 0) {
141 std::cout << cmdline_options << std::endl;
142 std::exit(EXIT_SUCCESS);
143 }
144
145 try {
146 po::notify(vm);
147 }
148 catch (const po::required_option& e) {
149 std::cerr << "Error: " << e.what() << std::endl;
150 std::cerr << "Use '-h' to display all valid options." << std::endl;
151 std::exit(EXIT_FAILURE);
152 }
153
154 { // Make the path to the main config and to parameters directory absolute
155 auto dir = fs::absolute(fs::canonical(fMainConfigPath));
156 L_(info) << "!!! fMainConfigPath=" << fMainConfigPath;
157 L_(info) << "!!! dir(fMainConfigPath)=" << dir.string();
158
159 fMainConfigPath = dir.string();
160 fParamsDir = dir.parent_path().string();
161 L_(info) << " fMainConfigPath=" << fMainConfigPath;
162 L_(info) << " fParamsDir=" << fParamsDir;
163 }
164}
165
166bool Options::HasOutput(RecoData recoData) const { return Contains(fOutputTypes, recoData); }
167
168bool Options::Has(fles::Subsystem detector) const { return Contains(fDetectors, detector); }
169
170bool Options::Has(Step step) const { return Contains(fRecoSteps, step); }
171
172bool Options::Has(QaStep qastep) const { return Contains(fQaSteps, qastep); }
#define CBM_ONLINE_USE_FAIRLOGGER
#define L_(level)
fscal v[fmask::Size]
Definition KfSimdPseudo.h:4
This file contains utility functions for STL containers.
void validate(boost::any &v, const std::vector< std::string > &values, severity_level *, int)
std::vector< fles::Subsystem > fDetectors
std::size_t fOutputMaxItems
std::string fMainConfigPath
std::vector< RecoData > fOutputTypes
std::vector< Step > fRecoSteps
bool HasOutput(RecoData recoData) const
severity_level fLogLevel
bool Has(fles::Subsystem detector) const
ProfilingLevel fProfilingLevel
std::vector< QaStep > fQaSteps
bool Contains(const C &container, const T &value)
Definition StlUtils.h:21
Hash for CbmL1LinkKey.
std::ostream & operator<<(std::ostream &os, const std::vector< T > &v)