CbmRoot
Loading...
Searching...
No Matches
analysis/common/analysis_tree_converter/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
25namespace cbm::atconverter
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 analysistree data");
45 config_add("transport,t", po::value<vector<string>>(&fTra)->value_name("<file names>")->multitoken(),
46 "name of transport input sources (ROOT files)");
47 config_add("digitization,d", po::value<string>(&fRaw)->value_name("<file name>"),
48 "name of the raw ROOT file containing digi data");
49 config_add("parameter,p", po::value<string>(&fPar)->value_name("<file name>"),
50 "name of a parameter ROOT file (FairRuntimeDb format)");
51 config_add("reconstruction,r", po::value<string>(&fReco)->value_name("<file nams>"),
52 "name of a reconstruction ROOT file");
53 config_add("config,c", po::value<string>(&fConfig)->value_name("<file name>")->default_value(defconfig),
54 "name of a YAML file describing the configuration of reconstruction");
55 config_add("setup,s", po::value<string>(&fSetup)->value_name("<tag>")->default_value(DEFAULT_SETUP),
56 "geometry setup tag");
57 config_add("overwrite,w", po::bool_switch(&fOverwrite)->default_value(false),
58 "allow to overwite an existing output file");
59
60 // --- Allowed options
61 po::options_description cmdline_options("Allowed options");
62 cmdline_options.add(generic).add(config);
63
64 // --- Parse command line
65 po::variables_map vars;
66 po::store(po::parse_command_line(argc, argv, cmdline_options), vars);
67 po::notify(vars);
68
69 // --- Help: print help information and exit program
70 if (vars.count("help") != 0u) {
71 std::cout << cmdline_options << std::endl;
72 exit(EXIT_SUCCESS);
73 }
74
75 // --- Catch mandatory parameters not being specified
76 if (vars.count("output") == 0u) { throw std::runtime_error("no output file name specified"); }
77 if (vars.count("transport") == 0u) { throw std::runtime_error("no transport file name specified"); }
78 if (vars.count("digitization") == 0u) { throw std::runtime_error("no digitization (raw) file name specified"); }
79 if (vars.count("parameter") == 0u) { throw std::runtime_error("no parameter file name specified"); }
80 if (vars.count("reconstruction") == 0u) { throw std::runtime_error("no reconstruction file name specified"); }
81 }
82 // --------------------------------------------------------------------------
83
84} // namespace cbm::atconverter
std::vector< std::string > fTra
Vector of transport input file names.
void ParseOptions(int argc, char *argv[])
Parse command line arguments using boost program_options.