00001 #include <iostream>
00002 #include "fhiclcpp/ParameterSet.h"
00003 #include "fhiclcpp/make_ParameterSet.h"
00004
00005 #include <boost/program_options.hpp>
00006
00007 using namespace fhicl;
00008 namespace bpo = boost::program_options;
00009
00010
00011 int main(int argc, char* argv[]) try
00012 {
00013
00014
00015
00016
00017 std::ostringstream descstr;
00018 descstr << argv[0] << " <-c <config-file>> <other-options>";
00019
00020 bpo::options_description desc = descstr.str();
00021
00022 desc.add_options()
00023 ("config,c", bpo::value<std::string>(), "Configuration file.")
00024 ("help,h", "produce help message");
00025
00026 bpo::variables_map vm;
00027
00028 try
00029 {
00030 bpo::store(bpo::command_line_parser(argc, argv).options(desc).run(), vm);
00031 bpo::notify(vm);
00032 }
00033 catch (bpo::error const& e)
00034 {
00035 std::cerr << "Exception from command line processing in " << argv[0]
00036 << ": " << e.what() << "\n";
00037 return -1;
00038 }
00039
00040 if (vm.count("help"))
00041 {
00042 std::cout << desc << std::endl;
00043 return 1;
00044 }
00045 if (!vm.count("config"))
00046 {
00047 std::cerr << "Exception from command line processing in " << argv[0]
00048 << ": no configuration file given.\n"
00049 << "For usage and an options list, please do '"
00050 << argv[0] << " --help"
00051 << "'.\n";
00052 return 2;
00053 }
00054
00055
00056
00057
00058
00059
00060 ParameterSet complete_pset;
00061
00062
00063 if (getenv("FHICL_FILE_PATH") == nullptr)
00064 {
00065 std::cerr
00066 << "INFO: environment variable FHICL_FILE_PATH was not set. Using \".\"\n";
00067 setenv("FHICL_FILE_PATH", ".", 0);
00068 }
00069
00070 auto file_name = vm["config"].as<std::string>();
00071 auto filepath_maker = cet::filepath_lookup("FHICL_FILE_PATH");
00072
00073 make_ParameterSet(file_name, filepath_maker, complete_pset);
00074
00075 std::cout << complete_pset.to_indented_string(0, false) << "\n";
00076
00077 return 0;
00078 }
00079
00080 catch (std::string& x)
00081 {
00082 std::cerr << "Exception (type string) caught in driver: " << x << "\n";
00083 return 1;
00084 }
00085
00086 catch (char const* m)
00087 {
00088 std::cerr << "Exception (type char const*) caught in driver: " << std::endl;
00089 if (m)
00090 {
00091 std::cerr << m;
00092 }
00093 else
00094 {
00095 std::cerr << "[the value was a null pointer, so no message is available]";
00096 }
00097 std::cerr << '\n';
00098 }