CbmRoot
Loading...
Searching...
No Matches
services/histserv/tester/ProgramOptions.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023 Facility for Antiproton and Ion Research in Europe, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pierre-Alain Loizeau [committer] */
4
5#include "ProgramOptions.h"
6
7#include <Logger.h>
8
9#include <boost/program_options.hpp>
10
11#include <iostream>
12
13namespace po = boost::program_options;
14
15using std::string;
16
18{
19
20 // ----- Parse command line ---------------------------------------------
21 void ProgramOptions::ParseOptions(int argc, char* argv[])
22 {
23
24 // --- Define generic options
25 po::options_description generic(" Generic options");
26 auto generic_add = generic.add_options();
27 generic_add("help,h", "display this help and exit");
28
29 // --- Define configuration options: Mandatory
30 po::options_description config_req(" Configuration (required)");
31 auto config_req_add = config_req.add_options();
32 config_req_add("output,o", po::value<string>(&fsChanHistosIn)->required()->value_name("<protocol://xxxxxx>"),
33 "name or host:port or whatever is needed for output channel (histos/canvases config and data), "
34 "cf http://api.zeromq.org/2-1:zmq-connect");
35
36 // --- Define configuration options: Optional
37 po::options_description config(" Configuration (optional)");
38 auto config_add = config.add_options();
39 config_add("runtime,r", po::value<int64_t>(&fRunTime)->default_value(90),
40 "duration of test run in seconds ~ x4 entries in test histogram ");
41 config_add("pubint,p", po::value<int64_t>(&fPubInterval)->default_value(5),
42 "publication interval in seconds (accumulate statistics between message emissions)");
43
44 // --- Allowed options
45 po::options_description cmdline_options("Allowed options");
46 cmdline_options.add(generic).add(config_req).add(config);
47
48 // --- Parse command line
49 po::variables_map vars;
50 po::store(po::parse_command_line(argc, argv, cmdline_options), vars);
51
52 // --- Help: print help information and exit program
53 if (vars.count("help") != 0u) {
54 std::cout << cmdline_options << std::endl;
55 exit(EXIT_SUCCESS);
56 }
57
58 // --- Run notify after processing the help to avoid it being blocked by missing arguments
59 po::notify(vars);
60 }
61 // --------------------------------------------------------------------------
62
63} // namespace cbm::services::histserv_tester
void ParseOptions(int argc, char *argv[])
Get configuration file name (YAML format)