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 "Options.h"
5
6#include "util/StlUtils.h"
7
8#include <boost/program_options.hpp>
9
10#include <iostream>
11#include <iterator>
12#include <unordered_map>
13
14using namespace cbm::algo;
15namespace po = boost::program_options;
16
17using fles::Subsystem;
18
19
20namespace std
21{
22 template<class T>
23 std::ostream& operator<<(std::ostream& os, const std::vector<T>& v)
24 {
25 copy(v.begin(), v.end(), std::ostream_iterator<T>(os, " "));
26 return os;
27 }
28} // namespace std
29
30#ifndef CBM_ONLINE_USE_FAIRLOGGER
31void validate(boost::any& v, const std::vector<std::string>& values, severity_level*, int)
32{
33
34 static const std::unordered_map<std::string, severity_level> levels{
35 {"trace", severity_level::trace}, {"debug", severity_level::debug}, {"status", severity_level::status},
36 {"info", severity_level::info}, {"warning", severity_level::warning}, {"error", severity_level::error},
37 {"fatal", severity_level::fatal}};
38
39 po::validators::check_first_occurrence(v);
40
41 const std::string& s = po::validators::get_single_string(values);
42
43 auto it = levels.find(s);
44
45 if (it == levels.end()) throw po::validation_error(po::validation_error::invalid_option_value);
46
47 v = it->second;
48}
49#endif // Not CBM_ONLINE_USE_FAIRLOGGER
50
51Options::Options(int argc, char** argv)
52{
53
54 po::options_description required("Required options");
55 // clang-format off
56 required.add_options()
57 ("param-dir,p", po::value(&fParamsDir)->value_name("<folder>")->required(),
58 "read program options from this folder")
59 ("input-locator,i", po::value(&fInputLocator)->value_name("<locator>")->required(),
60 "URI specifying input timeslice source")
61 ;
62 // clang-format on
63
64 po::options_description generic("Other options");
65 // clang-format off
66 generic.add_options()
67 ("output,o", po::value(&fOutputFile)->default_value("")->value_name("<file>"),
68 "write results to file")
69 ("device,d", po::value(&fDevice)->default_value("cpu")->value_name("<device>"),
70 "select device (cpu, cuda0, cuda1, hip0, ...)")
71#ifndef CBM_ONLINE_USE_FAIRLOGGER
72 ("log-level,l", po::value(&fLogLevel)->default_value(info)->value_name("<level>"),
73 "set log level (debug, info, warning, error, fatal)")
74#endif // Not CBM_ONLINE_USE_FAIRLOGGER
75 ("monitor,m", po::value(&fMonitorUri)->value_name("<uri>")->implicit_value("file:cout"),
76 "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.")
77 ("histogram", po::value(&fHistogramUri)->value_name("<uri>"), "URI to specify histogram server")
78 ("histoshwm", po::value(&fHistogramHwm)->default_value(1)->value_name("<num>"),
79 "High-Water Mark for ZMQ socket to histogram server in messages:\n"
80 " 0 = no buffering, num = nb updates kept in buffer if not pulled by server \n"
81 " Tune to avoid too high memory usage but also adapt to server load!")
82 ("aux-data", po::value(&fCollectAuxData)->implicit_value(true), "Enables collecting of auxiliary data from algorithms")
83 ("qa", po::value(&fQaSteps)->multitoken()->default_value({QaStep::UnpackSts, QaStep::EventBuilding, QaStep::Tracking})->value_name("<qa steps>"),
84 "space separated list of QA Steps to enable (BeamBmon, UnpackSts, EventBuilding, Tracking, ...)")
85#ifdef BOOST_IOS_HAS_ZSTD
86 ("hist-compr", po::bool_switch(&fCompressHistograms)->default_value(false),
87 "enables ZSTD compression of the outgoing histograms stream (decompression needed in target server!)")
88#endif
89 ("log-file,L", po::value(&fLogFile)->value_name("<file>"),
90 "write log messages to file")
91 ("output-types,O", po::value(&fOutputTypes)->multitoken()->value_name("<types>"),
92 "space separated list of reconstruction output types (Hit, Tracks, DigiTimeslice, DigiEvent, ...)")
93 ("compress-archive", po::bool_switch(&fCompressArchive)->default_value(false), "Enable compression for output archives")
94 ("steps", po::value(&fRecoSteps)->multitoken()->default_value({Step::Unpack, Step::DigiTrigger, Step::LocalReco, Step::Tracking})->value_name("<steps>"),
95 "space separated list of reconstruction steps (unpack, digitrigger, localreco, ...)")
96 ("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>"),
97 "space separated list of detectors to process (sts, mvd, ...)")
98 ("child-id,c", po::value(&fChildId)->default_value("00")->value_name("<id>"), "online process id on node")
99 ("run-id,r", po::value(&fRunId)->default_value(2391)->value_name("<RunId>"), "Run ID, for now flesctl run index, later run start time")
100 ("run-start", po::value(&fRunStartTime)->default_value(0)->value_name("<RunStart >"), "Run start time in ns, can be fles start or online start")
101 ("num-ts,n", po::value(&fNumTimeslices)->default_value(-1)->value_name("<num>"),
102 "Stop after <num> timeslices (-1 = all)")
103 ("skip-ts", po::value(&fSkipTimeslices)->default_value(0)->value_name("<num>"),
104 "Skip first <num> timeslices")
105 ("omp", po::value(&fNumOMPThreads)->default_value(-1)->value_name("<num>"),
106 "Set number of OpenMP threads (-1 = use OMP_NUM_THREADS environment variable)")
107 ("times,t", po::value(&fProfilingLevel)->default_value(ProfilingNone)->implicit_value(ProfilingPerTS),
108 "Print kernel times (Can opt. be given a value: Use none to disable or summary to only print aggregated times.)")
109 ("timings-file", po::value(&fTimingsFile)->value_name("<file>"),
110 "Write profiling times to yaml file (only when '-t' is set)")
111 ("dump-archive", po::bool_switch(&fDumpArchive)->default_value(false),
112 "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.)")
113 ("release-mode,R",po::value<bool>(&fReleaseMode)->implicit_value(true),
114 "Copy and release each timeslice immediately after receiving it")
115 ("help,h",
116 "produce help message")
117 ;
118 // clang-format on
119
120 po::options_description cmdline_options;
121 cmdline_options.add(required).add(generic);
122
123 po::variables_map vm;
124 po::command_line_parser parser{argc, argv};
125 parser.options(cmdline_options);
126 try {
127 auto result = parser.run();
128 po::store(result, vm);
129 }
130 catch (const std::exception& e) {
131 std::cerr << "Error: " << e.what() << std::endl;
132 std::cerr << "Use '-h' to display all valid options." << std::endl;
133 std::exit(EXIT_FAILURE);
134 }
135
136 if (vm.count("help") > 0) {
137 std::cout << cmdline_options << std::endl;
138 std::exit(EXIT_SUCCESS);
139 }
140
141 try {
142 po::notify(vm);
143 }
144 catch (const po::required_option& e) {
145 std::cerr << "Error: " << e.what() << std::endl;
146 std::cerr << "Use '-h' to display all valid options." << std::endl;
147 std::exit(EXIT_FAILURE);
148 }
149}
150
151bool Options::HasOutput(RecoData recoData) const { return Contains(fOutputTypes, recoData); }
152
153bool Options::Has(fles::Subsystem detector) const { return Contains(fDetectors, detector); }
154
155bool Options::Has(Step step) const { return Contains(fRecoSteps, step); }
156
157bool Options::Has(QaStep qastep) const { return Contains(fQaSteps, qastep); }
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::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)