1 #ifndef artdaq_proto_LoadParameterSet_hh
2 #define artdaq_proto_LoadParameterSet_hh 1
5 #include <boost/program_options.hpp>
7 #include "fhiclcpp/make_ParameterSet.h"
8 #include "fhiclcpp/types/Table.h"
10 namespace bpo = boost::program_options;
12 fhicl::ParameterSet LoadParameterSet(std::string
const& psetOrFile)
14 fhicl::ParameterSet pset;
18 make_ParameterSet(psetOrFile, pset);
20 catch (
const fhicl::exception& e)
22 if (getenv(
"FHICL_FILE_PATH") ==
nullptr)
23 setenv(
"FHICL_FILE_PATH",
".", 0);
24 cet::filepath_lookup_after1 lookup_policy(
"FHICL_FILE_PATH");
25 make_ParameterSet(psetOrFile, lookup_policy, pset);
32 void PrintConfigurationToConsole(std::string name)
34 fhicl::Table<C> config_description(fhicl::Name{name});
35 config_description.print_allowed_configuration(std::cout);
39 fhicl::ParameterSet LoadParameterSet(
int argc,
char* argv[], std::string name, std::string description)
41 std::ostringstream descstr;
43 <<
" <-c <config>> <other-options> [<source-file>]+";
44 bpo::options_description desc(descstr.str());
45 desc.add_options()(
"config,c", bpo::value<std::string>(),
"Configuration")(
"help,h",
"produce help message");
46 bpo::variables_map vm;
49 bpo::store(bpo::command_line_parser(argc, argv).options(desc).run(), vm);
52 catch (bpo::error
const& e)
54 TLOG_ERROR(
"LoadParameterSet") <<
"Exception from command line processing in " << argv[0]
55 <<
": " << e.what() <<
"\n";
60 std::cout << desc << std::endl;
61 std::cout << description << std::endl;
62 std::cout <<
"Sample FHiCL configuration for this application: " << std::endl;
63 fhicl::Table<C> config_description(fhicl::Name{name});
64 config_description.print_allowed_configuration(std::cout);
68 fhicl::ParameterSet pset;
70 if (vm.count(
"config"))
72 std::string config = vm[
"config"].as<std::string>();
74 if (config ==
"-" || config ==
"--")
76 TLOG_ERROR(
"LoadParameterSet") <<
"Reading configuration from standard input. Press Ctrl-D to end" << std::endl;
79 while (std::getline(std::cin, line))
81 ss << line << std::endl;
85 make_ParameterSet(ss.str(), pset);
89 TLOG_DEBUG(
"LoadParameterSet") << config << std::endl;
90 pset = LoadParameterSet(config);
95 TLOG_ERROR(
"LoadParameterSet") <<
"Exception from command line processing in " << argv[0]
96 <<
": no configuration given.\n"
97 <<
"For usage and an options list, please do '"
98 << argv[0] <<
" --help"
104 #endif //artdaq_proto_LoadParameterSet_hh