Line data Source code
1 : #include <iostream>
2 : #include "fhiclcpp/ParameterSet.h"
3 :
4 : #include <boost/program_options.hpp>
5 :
6 : using namespace fhicl;
7 : namespace bpo = boost::program_options;
8 :
9 0 : int main(int argc, char* argv[])
10 : try
11 : {
12 : // Get the input parameters via the boost::program_options library,
13 : // designed to make it relatively simple to define arguments and
14 : // issue errors if argument list is supplied incorrectly
15 :
16 0 : std::ostringstream descstr;
17 0 : descstr << *argv << " <-c <config-file>> <other-options>";
18 :
19 0 : bpo::options_description desc = descstr.str();
20 :
21 0 : desc.add_options()("config,c", bpo::value<std::string>(), "Configuration file.")("help,h",
22 : "produce help message");
23 :
24 0 : bpo::variables_map vm;
25 :
26 : try
27 : {
28 0 : bpo::store(bpo::command_line_parser(argc, argv).options(desc).run(), vm);
29 0 : bpo::notify(vm);
30 : }
31 0 : catch (bpo::error const& e)
32 : {
33 0 : std::cerr << "Exception from command line processing in " << *argv << ": " << e.what() << "\n";
34 0 : return -1;
35 0 : }
36 :
37 0 : if (vm.count("help") != 0u)
38 : {
39 0 : std::cout << desc << std::endl;
40 0 : return 1;
41 : }
42 0 : if (vm.count("config") == 0u)
43 : {
44 : std::cerr << "Exception from command line processing in " << *argv << ": no configuration file given.\n"
45 : << "For usage and an options list, please do '" << *argv << " --help"
46 0 : << "'.\n";
47 0 : return 2;
48 : }
49 :
50 : // Check the directories defined by the FHICL_FILE_PATH
51 : // environmental variable for the *.fcl file whose name was passed to
52 : // the command line. If not defined, look in the current directory.
53 :
54 0 : if (getenv("FHICL_FILE_PATH") == nullptr)
55 : {
56 0 : std::cerr << "INFO: environment variable FHICL_FILE_PATH was not set. Using \".\"\n";
57 0 : setenv("FHICL_FILE_PATH", ".", 0);
58 : }
59 :
60 0 : auto file_name = vm["config"].as<std::string>();
61 0 : auto filepath_maker = cet::filepath_lookup("FHICL_FILE_PATH");
62 :
63 0 : auto complete_pset = fhicl::ParameterSet::make(file_name, filepath_maker);
64 :
65 0 : std::cout << complete_pset.to_indented_string(0, false) << "\n";
66 :
67 0 : return 0;
68 0 : }
69 :
70 0 : catch (std::exception const& x)
71 : {
72 0 : std::cerr << "Exception (type std::exception) caught in driver: " << x.what() << "\n";
73 0 : return 1;
74 0 : }
75 0 : catch (...)
76 : {
77 0 : return -1;
78 0 : }
|