10 #include "boost/filesystem.hpp" 11 #include "boost/program_options.hpp" 13 #include "cetlib/HorizontalRule.h" 14 #include "cetlib/container_algorithms.h" 15 #include "cetlib/ostream_handle.h" 16 #include "cetlib_except/exception.h" 31 #include <type_traits> 34 namespace bpo = boost::program_options;
38 make_ostream_handle(std::string
const& filename)
40 if (filename.empty()) {
41 return cet::ostream_handle{std::cerr};
43 auto os = cet::ostream_handle{filename};
46 <<
"Unable to write post-processed configuration to specified file " 54 get_print_mode(std::string
const& mode)
58 }
else if (mode ==
"annotate") {
60 }
else if (mode ==
"prefix-annotate") {
64 <<
"Unrecognized ParameterSet printing mode: " << mode <<
'\n';
68 banner(std::string
const& filename)
70 std::string result =
"** Config output ";
72 filename.empty() ?
"follows" : std::string(
"to file '" + filename +
"'");
88 std::underlying_type_t<debug_processing> i{};
89 for (
auto const debugProcessing :
90 {
"configOut",
"debugConfig",
"validateConfig"}) {
92 if (!scheduler_pset.
has_key(debugProcessing))
98 assert(std::strcmp(debugProcessing,
"configOut") == 0);
99 auto const filename = scheduler_pset.
get<std::string>(
"configOut");
100 std::cerr << banner(filename);
101 auto os = make_ostream_handle(filename);
103 return debug_processing::config_out;
106 auto const& debug_table =
108 auto const filename = debug_table.
get<std::string>(
"fileName");
109 auto const mode = debug_table.get<std::string>(
"printMode");
110 std::cerr << banner(filename);
111 auto os = make_ostream_handle(filename);
115 return debug_processing::none;
125 bpo::options_description& in_desc,
126 cet::filepath_maker& lookupPolicy,
129 std::ostringstream descstr;
130 descstr <<
"\nUsage: " 131 << boost::filesystem::path(argv[0]).filename().native()
132 <<
" <-c <config-file>> <other-options> [<source-file>]+\n\n" 134 bpo::options_description all_desc{descstr.str()};
135 all_desc.add(in_desc);
137 handlers.emplace(handlers.begin(),
142 bpo::positional_options_description pd;
144 pd.add(
"source", -1);
146 bpo::variables_map vm;
148 bpo::store(bpo::command_line_parser(argc, argv)
156 std::cerr <<
"Exception from command line processing in " << argv[0]
157 <<
": " << e.what() <<
"\n";
161 for (
auto& handler : handlers) {
162 auto result = handler->checkOptions(vm);
169 for (
auto& handler : handlers) {
170 auto result = handler->processOptions(vm, raw_config);
183 constexpr cet::HorizontalRule rule{36};
184 std::cerr <<
"ERROR: Failed to create a parameter set from parsed " 185 "configuration with exception " 186 << e.what() <<
".\n";
187 std::cerr <<
" Intermediate configuration state follows:\n" 189 << rule(
'-') <<
'\n';
190 for (
auto const& item : raw_config) {
191 std::cerr << item.first <<
": " << item.second.to_string() <<
'\n';
193 std::cerr << rule(
'-') <<
'\n' << rule(
'-') <<
'\n';
202 std::cerr <<
"Uncaught exception while inserting main parameter set into " 221 bpo::variables_map vm;
228 constexpr cet::HorizontalRule rule{36};
229 std::cerr <<
"ERROR: Failed to create a parameter set from an input " 230 "configuration string with exception " 231 << e.what() <<
".\n";
232 std::cerr <<
" Input configuration string follows:\n" 233 << rule(
'-') << rule(
'-') <<
"\n";
234 std::cerr << config_string <<
"\n";
235 std::cerr << rule(
'-') << rule(
'-') <<
'\n';
243 std::cerr <<
"Uncaught exception while inserting main parameter set into " 253 auto const& services_pset =
255 auto const& scheduler_pset =
259 auto const debug_processing_mode =
260 maybe_output_config(main_pset, scheduler_pset);
261 if (debug_processing_mode == debug_processing::debug_config) {
274 std::cerr << e.what() <<
'\n';
278 std::cerr << e.what() <<
'\n';
282 std::cerr <<
"Caught unknown exception while initializing the message " 287 mf::LogInfo(
"MF_INIT_OK") <<
"Messagelogger initialization complete.";
301 if (debug_processing_mode == debug_processing::validate_config) {
304 if (scheduler_pset.
has_key(
"dataDependencyGraph")) {
307 if (ep.runToCompletion() == EventProcessor::epSignal) {
309 if (scheduler_pset.
get<
bool>(
"errorOnSIGINT")) {
322 catch (std::bad_alloc
const& bda) {
void SetIteration(string const &val)
static ParameterSetID const & put(ParameterSet const &ps)
int run_art(int argc, char **argv, bpo::options_description &in_desc, cet::filepath_maker &lookupPolicy, OptionsHandlers &&handlers)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::atomic< int > shutdown_flag
void make_ParameterSet(intermediate_table const &tbl, ParameterSet &ps)
void printStdException(std::exception const &e, char const *prog)
void printUnknownException(char const *prog)
void StartMessageFacility(fhicl::ParameterSet const &pset, string const &applicationName)
int run_art_string_config(std::string const &config_string)
T get(std::string const &key) const
std::string to_indented_string() const
std::vector< std::unique_ptr< art::OptionsHandler >> OptionsHandlers
bool has_key(std::string const &key) const
void setupSignals(bool want_sigint_enabled)
int processOptions(bpo::variables_map const &vm, fhicl::intermediate_table &raw_config)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
int run_art_common_(fhicl::ParameterSet const &main_pset)
void printArtException(cet::exception const &e, char const *prog)
bool is_key_to_atom(std::string const &key) const
constexpr int info_success()
void printBadAllocException(char const *prog)
cet::coded_exception< error, detail::translate > exception
void parse_document(std::string const &filename, cet::filepath_maker &maker, intermediate_table &result)