1 #ifndef artdaq_proto_LoadParameterSet_hh
2 #define artdaq_proto_LoadParameterSet_hh 1
5 #include "fhiclcpp/make_ParameterSet.h"
6 #include <boost/program_options.hpp>
8 namespace bpo = boost::program_options;
10 fhicl::ParameterSet LoadParameterSet(std::string
const& psetOrFile)
12 fhicl::ParameterSet pset;
16 make_ParameterSet(psetOrFile, pset);
18 catch (fhicl::exception e)
20 if (getenv(
"FHICL_FILE_PATH") ==
nullptr)
21 setenv(
"FHICL_FILE_PATH",
".", 0);
22 cet::filepath_lookup_after1 lookup_policy(
"FHICL_FILE_PATH");
23 make_ParameterSet(psetOrFile, lookup_policy, pset);
29 fhicl::ParameterSet LoadParameterSet(
int argc,
char* argv[])
31 std::ostringstream descstr;
33 <<
" <-c <config>> <other-options> [<source-file>]+";
34 bpo::options_description desc(descstr.str());
36 (
"config,c", bpo::value<std::string>(),
"Configuration")
37 (
"help,h",
"produce help message");
38 bpo::variables_map vm;
41 bpo::store(bpo::command_line_parser(argc, argv).options(desc).run(), vm);
44 catch (bpo::error
const & e)
46 TLOG_ERROR(
"LoadParameterSet") <<
"Exception from command line processing in " << argv[0]
47 <<
": " << e.what() <<
"\n";
52 TLOG_INFO(
"LoadParameterSet") << desc << std::endl;
57 fhicl::ParameterSet pset;
59 if (vm.count(
"config"))
61 std::string config = vm[
"config"].as<std::string>();
63 if (config ==
"-" || config ==
"--")
65 TLOG_ERROR(
"LoadParameterSet") <<
"Reading configuration from standard input. Press Ctrl-D to end" << std::endl;
68 while (std::getline(std::cin, line))
70 ss << line << std::endl;
74 make_ParameterSet(ss.str(), pset);
78 TLOG_DEBUG(
"LoadParameterSet") << config << std::endl;
79 pset = LoadParameterSet(config);
84 TLOG_ERROR(
"LoadParameterSet") <<
"Exception from command line processing in " << argv[0]
85 <<
": no configuration given.\n"
86 <<
"For usage and an options list, please do '"
87 << argv[0] <<
" --help"
93 #endif //artdaq_proto_LoadParameterSet_hh