CbmRoot
Loading...
Searching...
No Matches
services/histserv/app/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("input,i", po::value<string>(&fsChanHistosIn)->required()->value_name("<protocol://xxxxxx>"),
33 "name or host:port or whatever is needed for input channel (histos/canvases config and data), "
34 "cf http://api.zeromq.org/2-1:zmq-bind");
35
36 // --- Define configuration options: Optional
37 po::options_description config(" Configuration (optional or with default)");
38 auto config_add = config.add_options();
39 config_add("highwater,hwm", po::value<int32_t>(&fiHistosInZmqHwm)->default_value(1),
40 "ZMQ input channel high-water mark in messages: 0 = no buffering, val = nb updates kept in buffer \n"
41 "Tune to match nb of update emitters but also to avoid extrem memory usage!");
42 config_add("timeout,zto", po::value<int32_t>(&fiHistosInZmqRcvToMs)->default_value(10),
43 "ZMQ input channel timeout in ms: -1 = block (term. handling!), 0 = instant (CPU load!), val = nb ms");
44 config_add("port,p", po::value<uint32_t>(&fuHttpServerPort)->default_value(8080),
45 "port on which the http ROOT server (JSroot) will be available (mind default value!)");
46 config_add("output,o", po::value<string>(&fsHistoFileName)->value_name("<file name>"),
47 "name of the output ROOT file with histograms backup");
48 config_add("overwrite,w", po::bool_switch(&fOverwrite)->default_value(false),
49 "allow to overwite an existing output file");
50 config_add("hideguicmds", po::bool_switch(&fHideGuiCommands)->default_value(false),
51 "allow to hides (disable) the GUI commands for Reset/Save/Close");
52#ifdef BOOST_IOS_HAS_ZSTD
53 config_add("compressed,c", po::bool_switch(&fCompressedInput)->default_value(false),
54 "enables ZSTD decompression of the input stream (compression needed in source!)");
55#endif
56
57 // --- Allowed options
58 po::options_description cmdline_options("Allowed options");
59 cmdline_options.add(generic).add(config_req).add(config);
60
61 // --- Parse command line
62 po::variables_map vars;
63 po::store(po::parse_command_line(argc, argv, cmdline_options), 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 // --- Run notify after processing the help to avoid it being blocked by missing arguments
72 po::notify(vars);
73 }
74 // --------------------------------------------------------------------------
75
76} // namespace cbm::services::histserv
int32_t fiHistosInZmqHwm
High-Water Mark, default keep only 1 update in buffer.
bool fOverwrite
Enable overwriting of existing output file.
uint32_t fuHttpServerPort
HTTP port of the ROOT web server.
bool fCompressedInput
Enables ZSTD stream decompression is available.
int32_t fiHistosInZmqRcvToMs
Timeout in ms: -1 = block, 0 = instant, val = nb ms.
bool fHideGuiCommands
Hides (disables) the GUI commands for Reset/Save/Close.
std::string fsHistoFileName
Output file name (ROOT format)
void ParseOptions(int argc, char *argv[])
Get configuration file name (YAML format)