artdaq  v2_03_02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
LoadParameterSet.hh
1 #ifndef artdaq_proto_LoadParameterSet_hh
2 #define artdaq_proto_LoadParameterSet_hh 1
3 
4 #include "fhiclcpp/make_ParameterSet.h"
5 #include <boost/program_options.hpp>
6 #include <iostream>
7 namespace bpo = boost::program_options;
8 
9 inline fhicl::ParameterSet LoadParameterSet(int argc, char* argv[]) {
10  std::ostringstream descstr;
11  descstr << argv[0]
12  << " <-c <config-file>> <other-options> [<source-file>]+";
13  bpo::options_description desc(descstr.str());
14  desc.add_options()
15  ("config,c", bpo::value<std::string>(), "Configuration file.")
16  ("help,h", "produce help message");
17  bpo::variables_map vm;
18  try {
19  bpo::store(bpo::command_line_parser(argc, argv).options(desc).run(), vm);
20  bpo::notify(vm);
21  }
22  catch (bpo::error const & e) {
23  std::cerr << "Exception from command line processing in " << argv[0]
24  << ": " << e.what() << "\n";
25  exit(-1);
26  }
27  if (vm.count("help")) {
28  std::cout << desc << std::endl;
29  exit(1);
30  }
31  if (!vm.count("config")) {
32  std::cerr << "Exception from command line processing in " << argv[0]
33  << ": no configuration file given.\n"
34  << "For usage and an options list, please do '"
35  << argv[0] << " --help"
36  << "'.\n";
37  exit(2);
38  }
39  fhicl::ParameterSet pset;
40  if (getenv("FHICL_FILE_PATH") == nullptr) {
41  std::cerr
42  << "INFO: environment variable FHICL_FILE_PATH was not set. Using \".\"\n";
43  setenv("FHICL_FILE_PATH", ".", 0);
44  }
45  cet::filepath_lookup_after1 lookup_policy("FHICL_FILE_PATH");
46  make_ParameterSet(vm["config"].as<std::string>(), lookup_policy, pset);
47  return pset;
48 }
49 #endif //artdaq_proto_LoadParameterSet_hh