7 #include "tbb/task_arena.h" 33 fillTable(std::string
const& bpo_key,
35 bpo::variables_map
const& vm,
37 bool const default_value)
39 if (vm.count(bpo_key)) {
40 config.
put(fhicl_key, vm[bpo_key].as<bool>());
42 config.
put(fhicl_key, default_value);
49 bpo::options_description& desc)
51 bpo::options_description processing_options{
"Processing options"};
53 processing_options.add_options()
56 "Number of threads AND schedules to use for event processing " 57 "(default = 1, 0 = all cores).")
60 "Number of schedules to use for event processing (default = 1)")
64 "Number of threads to use for event processing (default = 1, 0 = all " 66 (
"default-exceptions",
67 "Some exceptions may be handled differently by default (e.g. " 69 (
"rethrow-default",
"All exceptions default to rethrow.")
71 "All exceptions overridden to rethrow (cf rethrow-default).")
72 (
"errorOnMissingConsumes",
73 bpo::value<bool>()->implicit_value(
true,
"true"),
74 "If 'true', then an exception will be thrown if any module attempts " 75 "to retrieve a product via the 'getBy*' interface without specifying " 76 "the appropriate 'consumes<T>(...)' statement in the module constructor.")
78 bpo::value<bool>()->implicit_value(
true,
"true"),
79 "If 'true', a signal received from the user yields an art return code " 80 "corresponding to an error; otherwise return 0.");
82 desc.add(processing_options);
88 if ((vm.count(
"rethrow-all") + vm.count(
"rethrow-default") +
89 vm.count(
"no-rethrow-default")) > 1) {
91 <<
"Options --default-exceptions, --rethrow-all, and --rethrow-default\n" 92 <<
"are mutually incompatible.\n";
97 if (vm.count(
"parallelism")) {
98 if (vm.count(
"nthreads") or vm.count(
"nschedules")) {
100 "cannot be used with either " 101 "--nthreads or --nschedules.\n";
105 if (vm.count(
"nthreads") and vm[
"nthreads"].as<
int>() < 0) {
107 <<
"Option --nthreads must greater than or equal to 0.";
109 if (vm.count(
"nschedules") and vm[
"nschedules"].as<
int>() < 1) {
111 <<
"Option --nschedules must be at least 1.\n";
118 bpo::variables_map
const& vm,
121 auto const scheduler_key =
fhicl_key(
"services",
"scheduler");
123 if (vm.count(
"rethrow-all") == 1 || vm.count(
"rethrow-default") == 1) {
124 raw_config.
put(
fhicl_key(scheduler_key,
"defaultExceptions"),
false);
125 if (vm.count(
"rethrow-all") == 1) {
133 fillTable(
"errorOnMissingConsumes",
134 fhicl_key(scheduler_key,
"errorOnMissingConsumes"),
138 fillTable(
"errorOnSIGINT",
139 fhicl_key(scheduler_key,
"errorOnSIGINT"),
144 auto const num_schedules_key =
fhicl_key(scheduler_key,
"num_schedules");
145 auto const num_threads_key =
fhicl_key(scheduler_key,
"num_threads");
146 if (vm.count(
"parallelism")) {
148 auto const j = vm[
"parallelism"].as<
int>();
149 auto const nthreads =
150 (j == 0) ? tbb::this_task_arena::max_concurrency() : j;
151 raw_config.
put(num_schedules_key, nthreads);
152 raw_config.
put(num_threads_key, nthreads);
156 if (vm.count(
"nschedules")) {
157 raw_config.
put(num_schedules_key, vm[
"nschedules"].as<int>());
159 if (vm.count(
"nthreads")) {
160 auto const nt = vm[
"nthreads"].as<
int>();
161 auto const nthreads =
162 (nt == 0) ? tbb::this_task_arena::max_concurrency() : nt;
163 raw_config.
put(num_threads_key, nthreads);
169 raw_config.
put(num_schedules_key, 1);
172 raw_config.
put(num_threads_key, 1);
int doCheckOptions(bpo::variables_map const &vm) override
ProcessingOptionsHandler(bpo::options_description &desc)
bool exists_outside_prolog(fhicl::intermediate_table const &config, std::string const &key)
std::enable_if_t< std::is_convertible_v< T, std::string >, std::string > fhicl_key(T const &name)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
int doProcessOptions(bpo::variables_map const &vm, fhicl::intermediate_table &raw_config) override