CbmRoot
Loading...
Searching...
No Matches
sim/response/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: Frederic Linz [committer], Volker Friese */
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;
23using std::vector;
24
26{
27
28 // ----- Parse command line ---------------------------------------------
29 void ProgramOptions::ParseOptions(int argc, char* argv[])
30 {
31
32 // --- Define generic options
33 po::options_description generic("Generic options");
34 auto generic_add = generic.add_options();
35 generic_add("help,h", "display this help and exit");
36
37 // --- Define configuration options
38 string defconfig = std::getenv("VMCWORKDIR");
39 defconfig.append("/");
40 defconfig.append(DEFAULT_CONFIG);
41 po::options_description config("Configuration");
42 auto config_add = config.add_options();
43 config_add("output,o", po::value<string>(&fOutput)->value_name("<file name>"),
44 "name of the output ROOT file with digi data");
45 config_add("transport,t", po::value<vector<string>>(&fTra)->value_name("<file names>")->multitoken(),
46 "names of a transport input sources (ROOT files)");
47 config_add("parameter,p", po::value<string>(&fPar)->value_name("<file name>"),
48 "name of a parameter ROOT file (FairRuntimeDb format)");
49 config_add("config,c", po::value<string>(&fConfig)->value_name("<file name>")->default_value(defconfig),
50 "name of a YAML file describing the configuration of reconstruction");
51 config_add("setup,s", po::value<string>(&fSetup)->value_name("<tag>")->default_value(DEFAULT_SETUP),
52 "geometry setup tag");
53 config_add("overwrite,w", po::bool_switch(&fOverwrite)->default_value(false),
54 "allow to overwite an existing output file");
55
56 // --- Allowed options
57 po::options_description cmdline_options("Allowed options");
58 cmdline_options.add(generic).add(config);
59
60 // --- Parse command line
61 po::variables_map vars;
62 po::store(po::parse_command_line(argc, argv, cmdline_options), vars);
63 po::notify(vars);
64
65 // --- Help: print help information and exit program
66 if (vars.count("help") != 0u) {
67 std::cout << cmdline_options << std::endl;
68 exit(EXIT_SUCCESS);
69 }
70
71 // --- Catch mandatory parameters not being specified
72 if (vars.count("output") == 0u) {
73 throw std::runtime_error("no output file name specified");
74 }
75 if (vars.count("transport") == 0u) {
76 throw std::runtime_error("no transport file name specified");
77 }
78 if (vars.count("parameter") == 0u) {
79 throw std::runtime_error("no parameter file name specified");
80 }
81 }
82 // --------------------------------------------------------------------------
83
84} // namespace cbm::sim::digitization
bool fOverwrite
Enable overwriting of existing output file.
std::vector< std::string > fTra
List of transport input sources (ROOT format)
std::string fConfig
Configuration file name (YAML format)
std::string fOutput
Output file name (ROOT format)
std::string fPar
Parameter file name (ROOT format)
void ParseOptions(int argc, char *argv[])
Parse command line arguments using boost program_options.