CbmRoot
Loading...
Searching...
No Matches
services/archive_explorer/app/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 <boost/program_options.hpp>
7
8#include <iostream>
9
10namespace po = boost::program_options;
11
12using namespace cbm::explore;
13
14Options::Options(int argc, char** argv)
15{
16 po::options_description options("Options");
17
18 // clang-format off
19 options.add_options()
20 ("input,i", po::value(&fInput)->value_name("<input>")->required(),
21 "input archive")
22 ("input2,j", po::value(&fInput2)->value_name("<input2>"),
23 "second input archive, used for comparison (optional)")
24 ("port,p", po::value(&fPort)->value_name("<port>")->default_value(8080),
25 "port to listen on")
26 ("sensor", po::value(&fSensor)->value_name("<sensor>"),
27 "sensor to filter on")
28 ("help,h",
29 "produce help message")
30 ;
31 // clang-format on
32
33 po::variables_map vm;
34 po::command_line_parser parser {argc, argv};
35 parser.options(options);
36 try {
37 auto result = parser.run();
38 po::store(result, vm);
39 }
40 catch (const std::exception& e) {
41 std::cerr << "Error: " << e.what() << std::endl;
42 std::cerr << "Use '-h' to display all valid options." << std::endl;
43 std::exit(EXIT_FAILURE);
44 }
45
46 if (vm.count("help") > 0) {
47 std::cout << options << std::endl;
48 std::exit(EXIT_SUCCESS);
49 }
50
51 fFilterSensor = vm.count("sensor") > 0;
52
53 try {
54 po::notify(vm);
55 }
56 catch (const po::required_option& e) {
57 std::cerr << "Error: " << e.what() << std::endl;
58 std::cerr << "Use '-h' to display all valid options." << std::endl;
59 std::exit(EXIT_FAILURE);
60 }
61}