7 #include "boost/program_options.hpp" 8 #include "cetlib_except/demangle.h" 19 using namespace fhicl;
24 std::string
const fhicl_env_var{
"FHICL_FILE_PATH"};
27 std::string
const help{
"Help"};
28 std::string
const processing{
"Processing"};
29 std::string
const config{
"Configuration"};
36 string output_filename;
37 string input_filename;
42 Options process_arguments(
int argc,
char* argv[]);
45 cet::filepath_maker& lookup_policy);
47 std::unique_ptr<cet::filepath_maker> get_policy(
int const lookup_policy,
48 string const& lookup_path);
54 main(
int argc,
char* argv[])
59 opts = process_arguments(argc, argv);
62 if (e.category() == help)
64 if (e.category() == processing) {
65 std::cerr << e.what() <<
'\n';
68 if (e.category() == config) {
69 std::cerr << e.what() <<
'\n';
74 auto const policy = get_policy(opts.lookup_policy, opts.lookup_path);
78 pset = form_pset(opts.input_filename, *policy);
81 std::cerr << e.what() <<
'\n';
85 std::cerr <<
"Unknown exception\n";
92 std::ofstream ofs{opts.output_filename};
93 std::ostream& os = opts.output_filename.empty() ? std::cout : ofs;
95 os <<
"# Produced from '" << argv[0] <<
"' using:\n" 96 <<
"# Input : " << opts.input_filename <<
'\n' 98 << cet::demangle_symbol(
typeid(decltype(*policy)).name()) <<
'\n' 99 <<
"# Path : \"" << opts.lookup_path <<
"\"\n\n" 108 process_arguments(
int argc,
char* argv[])
110 namespace bpo = boost::program_options;
117 bpo::options_description desc(
"fhicl-dump [-c] <file>\nOptions");
118 desc.add_options()(
"help,h",
"produce this help message")(
119 "config,c", bpo::value<std::string>(&opts.input_filename),
"input file")(
121 bpo::value<std::string>(&opts.output_filename),
122 "output file (default is STDOUT)")(
124 bpo::bool_switch(&
annotated)->default_value(
false,
"false"),
125 "include source location annotations")(
128 "include source location annotations on line preceding parameter " 129 "assignment (mutually exclusive with 'annotated' option)")(
130 "quiet,q",
"suppress output to STDOUT")(
132 bpo::value<int>(&opts.lookup_policy)->default_value(1),
133 "lookup policy code:" 134 "\n 0 => cet::filepath_maker" 135 "\n 1 => cet::filepath_lookup" 136 "\n 2 => cet::filepath_lookup_nonabsolute" 137 "\n 3 => cet::filepath_lookup_after1")(
139 bpo::value<std::string>(&opts.lookup_path)->default_value(fhicl_env_var),
140 "path or environment variable to be used by lookup-policy");
142 bpo::positional_options_description p;
145 bpo::variables_map vm;
148 bpo::command_line_parser(argc, argv).options(desc).positional(p).run(),
153 std::ostringstream err_stream;
154 err_stream <<
"Error processing command line in " << argv[0] <<
": " 155 << err.what() <<
'\n';
159 if (vm.count(
"help")) {
160 std::cout << desc <<
'\n';
164 if (vm.count(
"quiet")) {
166 throw cet::exception(config) <<
"Cannot specify both '--quiet' and " 167 "'--(prefix-)annotated' options.\n";
173 throw cet::exception(config) <<
"Cannot specify both '--annotated' and " 174 "'--prefix-annotated' options.\n";
182 if (!vm.count(
"config")) {
183 std::ostringstream err_stream;
184 err_stream <<
"\nMissing input configuration file.\n\n" << desc <<
'\n';
190 std::unique_ptr<cet::filepath_maker>
191 get_policy(
int const lookup_policy, std::string
const& lookup_path)
193 switch (lookup_policy) {
195 return std::make_unique<cet::filepath_maker>();
197 return std::make_unique<cet::filepath_lookup>(lookup_path);
199 return std::make_unique<cet::filepath_lookup_nonabsolute>(lookup_path);
201 return std::make_unique<cet::filepath_lookup_after1>(lookup_path);
203 std::ostringstream err_stream;
204 err_stream <<
"Error: command line lookup-policy " << lookup_policy
205 <<
" is unknown; choose 0, 1, 2, or 3\n";
206 throw std::runtime_error(err_stream.str());
211 form_pset(std::string
const& filename, cet::filepath_maker& lookup_policy)
void make_ParameterSet(intermediate_table const &tbl, ParameterSet &ps)
std::string to_indented_string() const
int main(int argc, char *argv[])
cet::coded_exception< error, detail::translate > exception
void parse_document(std::string const &filename, cet::filepath_maker &maker, intermediate_table &result)