CbmRoot
Loading...
Searching...
No Matches
services/online_par_dump/ProgramOptions.cxx
Go to the documentation of this file.
1/* Copyright (C) 2024 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Felix Weiglhofer [committer] */
4
5#include "ProgramOptions.h"
6
7#include <boost/program_options.hpp>
8
9#include <iostream>
10
11namespace po = boost::program_options;
12
13ProgramOptions::ProgramOptions(int argc, char** argv)
14{
15 po::options_description required("Required options");
16 // clang-format off
17 required.add_options()
18 ("setup,s", po::value(&setup)->value_name("<setup>")->required(),
19 "Setup: mCBM2022, mCBM2024")
20 ("outdir,o", po::value(&outputDir)->value_name("<outputDir>")->required(),
21 "Output directory for the parameter files")
22 ;
23 // clang-format on
24
25 po::options_description optional{"Other options"};
26 // clang-format off
27 optional.add_options()
28 ("no-alignment", po::bool_switch(&skipAlignment),
29 "Do not do alignment")
30 ("help,h", "Print help message")
31 ;
32 // clang-format on
33
34
35 po::options_description cmdline_options;
36 cmdline_options.add(required).add(optional);
37
38 po::variables_map vm;
39 po::command_line_parser parser{argc, argv};
40 parser.options(cmdline_options);
41 try {
42 auto result = parser.run();
43 po::store(result, vm);
44 }
45 catch (const std::exception& e) {
46 std::cerr << "Error: " << e.what() << std::endl;
47 std::cerr << "Use '-h' to display all valid options." << std::endl;
48 std::exit(EXIT_FAILURE);
49 }
50
51 if (vm.count("help") > 0) {
52 std::cout << cmdline_options << std::endl;
53 std::exit(EXIT_SUCCESS);
54 }
55
56 try {
57 po::notify(vm);
58 }
59 catch (const po::required_option& e) {
60 std::cerr << "Error: " << e.what() << std::endl;
61 std::cerr << "Use '-h' to display all valid options." << std::endl;
62 std::exit(EXIT_FAILURE);
63 }
64}
ProgramOptions(int argc, char *argv[])
Standard constructor with command line arguments.