15 #include "boost/program_options.hpp" 17 #include "cetlib/HorizontalRule.h" 18 #include "cetlib/container_algorithms.h" 19 #include "cetlib/ostream_handle.h" 20 #include "cetlib_except/exception.h" 38 using namespace string_literals;
45 make_ostream_handle(std::string
const& filename)
47 assert(!filename.empty());
49 return cet::ostream_handle{std::cerr};
51 return cet::ostream_handle{std::cout};
53 auto os = cet::ostream_handle{filename};
56 <<
"Unable to write post-processed configuration to specified file " 64 get_print_mode(std::string
const& mode)
68 }
else if (mode ==
"annotate") {
70 }
else if (mode ==
"prefix-annotate") {
74 <<
"Unrecognized ParameterSet printing mode: " << mode <<
'\n';
78 banner(std::string
const& filename)
80 std::string result =
"** Config output ";
84 to_terminal ?
"follows" : std::string(
"to file '" + filename +
"'");
91 std::string
const& output_file,
92 std::string
const& mode)
94 std::cerr << banner(output_file);
95 auto os = make_ostream_handle(output_file);
110 if (not scheduler_pset.
has_key(
"debug")) {
111 return debug_processing::none;
114 auto const processing_options = {
115 "config-summary",
"config-out",
"debug-config",
"validate-config"};
117 auto const option = scheduler_pset.
get<std::string>(
"debug.option");
118 auto pos = cet::find_in_all(processing_options, option);
119 if (pos ==
cend(processing_options)) {
122 "An error was encountered while processing debugging options"}
123 <<
"The debugging option '" << option <<
"' is not supported.\n" 124 <<
"If you did not explicitly provide this value in your configuration " 125 "file, please contact artists@fnal.gov and report this error. " 127 <<
"choose from 'configSummary', 'configOut', 'debugConfig', or " 128 "'validateConfig'.\n";
131 auto const index = std::distance(
cbegin(processing_options), pos);
137 namespace bpo = boost::program_options;
144 bpo::options_description& all_desc,
148 bpo::positional_options_description pd;
150 pd.add(
"source", -1);
152 bpo::variables_map vm;
154 bpo::store(bpo::command_line_parser(argc, argv)
156 .style(bpo::command_line_style::default_style &
157 ~bpo::command_line_style::allow_guessing)
164 cerr <<
"Exception from command line processing in " << argv[0] <<
": " 169 for (
auto& handler : handlers) {
170 auto const result = handler->checkOptions(vm);
177 for (
auto& handler : handlers) {
178 auto const result = handler->processOptions(vm, raw_config);
187 auto const scheduler_key =
fhicl_key(
"services",
"scheduler");
188 auto enabled_modules = detail::EnabledModules::none();
191 auto const pruneConfigKey =
fhicl_key(scheduler_key,
"pruneConfig");
192 auto const reportUnusedKey =
fhicl_key(scheduler_key,
"reportUnused");
195 bool const prune_config = raw_config.
get<
bool>(pruneConfigKey);
196 bool const report_unused = raw_config.
get<
bool>(reportUnusedKey);
198 prune_config, report_unused, raw_config);
202 return e.returnCode();
208 catch (std::bad_alloc
const& bda) {
229 constexpr cet::HorizontalRule rule{36};
230 cerr <<
"ERROR: Failed to create a parameter set from parsed " 231 "configuration with exception " 232 << e.what() <<
".\n";
233 cerr <<
" Intermediate configuration state follows:\n" 235 << rule(
'-') <<
'\n';
236 for (
auto const& [key,
value] : raw_config) {
237 cerr << key <<
": " <<
value.to_string() <<
'\n';
239 cerr << rule(
'-') <<
'\n' << rule(
'-') <<
'\n';
247 cerr <<
"Uncaught exception while inserting main parameter set into " 258 mallopt(M_ARENA_MAX, 1);
261 auto const services_pset =
263 auto const scheduler_pset =
267 auto const debug_mode = debug_processing_mode(scheduler_pset);
268 if (debug_mode != debug_processing::none) {
270 auto const filename = debug_pset.
get<std::string>(
"fileName");
271 auto const mode = debug_pset.get<std::string>(
"printMode");
273 switch (debug_mode) {
274 case debug_processing::validate_config: {
277 case debug_processing::config_out: {
278 print_config(main_pset, filename, mode);
281 case debug_processing::debug_config: {
282 print_config(main_pset, filename, mode);
285 case debug_processing::config_summary: {
289 case debug_processing::none:
302 cerr << e.what() <<
'\n';
306 cerr << e.what() <<
'\n';
310 cerr <<
"Caught unknown exception while initializing the message " 314 mf::LogInfo(
"MF_INIT_OK") <<
"Messagelogger initialization complete.";
320 EventProcessor ep{std::move(main_pset), std::move(enabled_modules)};
326 if (debug_mode == debug_processing::validate_config) {
329 if (scheduler_pset.
has_key(
"dataDependencyGraph")) {
332 auto ep_rc = ep.runToCompletion();
333 if (ep_rc == EventProcessor::epSignal) {
335 if (scheduler_pset.
get<
bool>(
"errorOnSIGINT")) {
352 std::string
const msg{e.
what()};
353 mf::LogSystem(
"ArtException") << msg.substr(0, msg.find_last_of(
"\n"));
355 catch (bad_alloc
const& bda) {
void SetIteration(string const &val)
static ParameterSetID const & put(ParameterSet const &ps)
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
bool exists_outside_prolog(fhicl::intermediate_table const &config, std::string const &key)
void print_config_summary(fhicl::ParameterSet const &pset, std::string const &verbosity, EnabledModules const &enabled_modules)
static ParameterSet make(intermediate_table const &tbl)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
char const * what() const noexcept override
void printStdException(std::exception const &e, char const *prog)
std::atomic< int > shutdown_flag
void printUnknownException(char const *prog)
EnabledModules prune_config_if_enabled(bool prune_config, bool report_enabled, fhicl::intermediate_table &config)
void StartMessageFacility(fhicl::ParameterSet const &pset, string const &applicationName)
T get(std::string const &key) const
std::enable_if_t< std::is_convertible_v< T, std::string >, std::string > fhicl_key(T const &name)
std::string to_indented_string() const
std::vector< std::unique_ptr< art::OptionsHandler >> OptionsHandlers
MaybeLogger_< ELseverityLevel::ELsev_severe, false > LogSystem
bool has_key(std::string const &key) const
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
bool output_to_stderr(std::string const &spec)
int run_art(int argc, char **argv, bpo::options_description &all_desc, OptionsHandlers &&handlers)
void printArtException(cet::exception const &e, char const *prog)
constexpr int info_success()
decltype(auto) constexpr cbegin(T &&obj)
ADL-aware version of std::cbegin.
void printBadAllocException(char const *prog)
bool output_to_stdout(std::string const &spec)
cet::coded_exception< error, detail::translate > exception