CbmRoot
Loading...
Searching...
No Matches
reco/offline/app/ProgramOptions.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese [committer] */
4
12#include "ProgramOptions.h"
13
14#include <Logger.h>
15
16#include <boost/program_options.hpp>
17
18#include <iostream>
19
20namespace po = boost::program_options;
21
22using std::string;
23
24namespace cbm::reco::offline
25{
26
27 // ----- Parse command line ---------------------------------------------
28 void ProgramOptions::ParseOptions(int argc, char* argv[])
29 {
30
31 // --- Define generic options
32 po::options_description generic("Generic options");
33 auto generic_add = generic.add_options();
34 generic_add("help,h", "display this help and exit");
35
36 // --- Define configuration options
37 string defconfig = std::getenv("VMCWORKDIR");
38 defconfig.append("/");
39 defconfig.append(DEFAULT_CONFIG);
40 po::options_description config("Configuration");
41 auto config_add = config.add_options();
42 config_add("output,o", po::value<string>(&fOutput)->value_name("<file name>"),
43 "name of the output ROOT file with reconstructed data");
44 config_add("digitization,d", po::value<string>(&fRaw)->value_name("<file name>"),
45 "name of the raw ROOT file containing digi data");
46 config_add("parameter,p", po::value<string>(&fPar)->value_name("<file name>"),
47 "name of a parameter ROOT file (FairRuntimeDb format)");
48 config_add("config,c", po::value<string>(&fConfig)->value_name("<file name>")->default_value(defconfig),
49 "name of a YAML file describing the configuration of reconstruction");
50 config_add("setup,s", po::value<string>(&fSetup)->value_name("<tag>")->default_value(DEFAULT_SETUP),
51 "geometry setup tag");
52 config_add("overwrite,w", po::bool_switch(&fOverwrite)->default_value(false),
53 "allow to overwite an existing output file");
54
55 // --- Allowed options
56 po::options_description cmdline_options("Allowed options");
57 cmdline_options.add(generic).add(config);
58
59 // --- Parse command line
60 po::variables_map vars;
61 po::store(po::parse_command_line(argc, argv, cmdline_options), vars);
62 po::notify(vars);
63
64 // --- Help: print help information and exit program
65 if (vars.count("help") != 0u) {
66 std::cout << cmdline_options << std::endl;
67 exit(EXIT_SUCCESS);
68 }
69
70 // --- Catch mandatory parameters not being specified
71 if (vars.count("output") == 0u) {
72 throw std::runtime_error("no output file name specified");
73 }
74 if (vars.count("digitization") == 0u) {
75 throw std::runtime_error("no digitization (raw) file name specified");
76 }
77 if (vars.count("parameter") == 0u) {
78 throw std::runtime_error("no parameter file name specified");
79 }
80 }
81 // --------------------------------------------------------------------------
82
83} // namespace cbm::reco::offline
std::string fRaw
Input raw (digi) file name (ROOT format)
std::string fPar
Parameter file name (ROOT format)
bool fOverwrite
Enable overwriting of existing output file.
std::string fConfig
Configuration file name (YAML format)
std::string fOutput
Output file name (ROOT format)
void ParseOptions(int argc, char *argv[])
Parse command line arguments using boost program_options.