00001 #ifndef artdaq_proto_LoadParameterSet_hh 00002 #define artdaq_proto_LoadParameterSet_hh 1 00003 00004 #include "fhiclcpp/make_ParameterSet.h" 00005 #include <boost/program_options.hpp> 00006 #include <iostream> 00007 namespace bpo = boost::program_options; 00008 00009 inline fhicl::ParameterSet LoadParameterSet(int argc, char* argv[]) { 00010 std::ostringstream descstr; 00011 descstr << argv[0] 00012 << " <-c <config-file>> <other-options> [<source-file>]+"; 00013 bpo::options_description desc(descstr.str()); 00014 desc.add_options() 00015 ("config,c", bpo::value<std::string>(), "Configuration file.") 00016 ("help,h", "produce help message"); 00017 bpo::variables_map vm; 00018 try { 00019 bpo::store(bpo::command_line_parser(argc, argv).options(desc).run(), vm); 00020 bpo::notify(vm); 00021 } 00022 catch (bpo::error const & e) { 00023 std::cerr << "Exception from command line processing in " << argv[0] 00024 << ": " << e.what() << "\n"; 00025 exit(-1); 00026 } 00027 if (vm.count("help")) { 00028 std::cout << desc << std::endl; 00029 exit(1); 00030 } 00031 if (!vm.count("config")) { 00032 std::cerr << "Exception from command line processing in " << argv[0] 00033 << ": no configuration file given.\n" 00034 << "For usage and an options list, please do '" 00035 << argv[0] << " --help" 00036 << "'.\n"; 00037 exit(2); 00038 } 00039 fhicl::ParameterSet pset; 00040 if (getenv("FHICL_FILE_PATH") == nullptr) { 00041 std::cerr 00042 << "INFO: environment variable FHICL_FILE_PATH was not set. Using \".\"\n"; 00043 setenv("FHICL_FILE_PATH", ".", 0); 00044 } 00045 cet::filepath_lookup_after1 lookup_policy("FHICL_FILE_PATH"); 00046 make_ParameterSet(vm["config"].as<std::string>(), lookup_policy, pset); 00047 return pset; 00048 } 00049 #endif //artdaq_proto_LoadParameterSet_hh