1 #ifndef artdaq_proto_LoadParameterSet_hh
2 #define artdaq_proto_LoadParameterSet_hh 1
6 #include "fhiclcpp/make_ParameterSet.h"
7 #include "fhiclcpp/types/Table.h"
8 #include <boost/program_options.hpp>
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 (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());
46 (
"config,c", bpo::value<std::string>(),
"Configuration")
47 (
"help,h",
"produce help message");
48 bpo::variables_map vm;
51 bpo::store(bpo::command_line_parser(argc, argv).options(desc).run(), vm);
54 catch (bpo::error
const & e)
56 TLOG_ERROR(
"LoadParameterSet") <<
"Exception from command line processing in " << argv[0]
57 <<
": " << e.what() <<
"\n";
62 std::cout << desc << std::endl;
63 std::cout << description << std::endl;
64 std::cout <<
"Sample FHiCL configuration for this application: " << std::endl;
65 fhicl::Table<C> config_description(fhicl::Name{ name });
66 config_description.print_allowed_configuration(std::cout);
71 fhicl::ParameterSet pset;
73 if (vm.count(
"config"))
75 std::string config = vm[
"config"].as<std::string>();
77 if (config ==
"-" || config ==
"--")
79 TLOG_ERROR(
"LoadParameterSet") <<
"Reading configuration from standard input. Press Ctrl-D to end" << std::endl;
82 while (std::getline(std::cin, line))
84 ss << line << std::endl;
88 make_ParameterSet(ss.str(), pset);
92 TLOG_DEBUG(
"LoadParameterSet") << config << std::endl;
93 pset = LoadParameterSet(config);
98 TLOG_ERROR(
"LoadParameterSet") <<
"Exception from command line processing in " << argv[0]
99 <<
": no configuration given.\n"
100 <<
"For usage and an options list, please do '"
101 << argv[0] <<
" --help"
107 #endif //artdaq_proto_LoadParameterSet_hh