LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
BasicPostProcessor.cc
Go to the documentation of this file.
2 
6 #include "cetlib/filepath_maker.h"
9 
10 #include <iostream>
11 #include <string>
12 
13 namespace {
14 
18 
19  void
20  verifyProcessName(fhicl::intermediate_table& raw_config)
21  {
22  if (exists_outside_prolog(raw_config, "process_name")) {
23  auto const& process_name = raw_config.get<std::string>("process_name");
24  if (process_name.empty()) {
25  throw cet::exception("BAD_PROCESS_NAME")
26  << "Empty process_name not permitted.";
27  } else if (process_name.find('_') != std::string::npos) {
28  throw cet::exception("BAD_PROCESS_NAME")
29  << "Underscores not permitted in process_name: illegal value \""
30  << process_name << "\"";
31  }
32  } else {
33  std::cerr << "INFO: using default process_name of \"DUMMY\".\n";
34  raw_config.put("process_name", "DUMMY");
35  }
36  }
37 
38  void
39  verifyInterfaces(fhicl::intermediate_table& raw_config)
40  {
41  std::string const services{"services"};
42  std::string const service_provider{"service_provider"};
43  auto const ciProvider =
44  fhicl_key(services, "CatalogInterface", service_provider);
45  auto const ftProvider =
46  fhicl_key(services, "FileTransfer", service_provider);
47  if (!exists_outside_prolog(raw_config, ciProvider)) {
48  raw_config.put(ciProvider, "TrivialFileDelivery");
49  }
50  if (!exists_outside_prolog(raw_config, ftProvider)) {
51  raw_config.put(ftProvider, "TrivialFileTransfer");
52  }
53  }
54 
55  void
56  verifySourceConfig(fhicl::intermediate_table& raw_config)
57  {
58  if (exists_outside_prolog(raw_config, "source.fileNames")) {
59  if (exists_outside_prolog(raw_config, "source.module_type")) {
60  if (raw_config.get<std::string>("source.module_type") == "EmptyEvent") {
62  << "Error: source files specified for EmptyEvent source.";
63  }
64  } else {
65  raw_config.put("source.module_type", "RootInput");
66  }
67  } else if (!exists_outside_prolog(raw_config, "source.module_type")) {
68  raw_config.put("source.module_type", "EmptyEvent");
69  }
70  if (raw_config.get<std::string>("source.module_type") == "EmptyEvent" &&
71  !exists_outside_prolog(raw_config, "source.maxEvents") &&
72  !exists_outside_prolog(raw_config, "source.maxTime")) {
73  // Default 1 event.
74  raw_config.put("source.maxEvents", 1);
75  }
76  }
77 
78  void
79  injectModuleLabels(fhicl::intermediate_table& int_table,
80  std::string const& table_spec)
81  {
82  if (!int_table.exists(table_spec)) {
83  return;
84  }
85  auto& top_table_val = int_table.update(table_spec);
86  if (!top_table_val.is_a(fhicl::TABLE)) {
88  << "Unexpected non-table " << table_spec << ".\n";
89  }
90  auto& table = int_table.get<table_t&>(table_spec);
91  for (auto const& tval : table) {
92  if (tval.first.find('_') != std::string::npos) {
94  << "Module parameter set label \"" << tval.first << "\" is illegal: "
95  << "underscores are not permitted in module names.";
96  }
97  auto& table_val = int_table.update(table_spec + '.' + tval.first);
98  if (!table_val.is_a(fhicl::TABLE)) {
100  << "Unexpected non-table " << tval.first << " found in " << table_spec
101  << ".\n";
102  };
103  int_table.put(table_spec + '.' + tval.first + ".module_label",
104  tval.first);
105  }
106  }
107 
108  void
109  addModuleLabels(fhicl::intermediate_table& raw_config)
110  {
111  if (exists_outside_prolog(raw_config, "source")) {
112  raw_config.put("source.module_label", "source");
113  }
114  injectModuleLabels(raw_config, "outputs");
115  injectModuleLabels(raw_config, "physics.producers");
116  injectModuleLabels(raw_config, "physics.filters");
117  injectModuleLabels(raw_config, "physics.analyzers");
118  }
119 
120  void
121  injectServiceType(fhicl::intermediate_table& raw_config,
122  std::string const& table_spec,
123  std::vector<std::string> const& excluded = {})
124  {
125  if (!exists_outside_prolog(raw_config, table_spec)) {
126  return;
127  }
128  auto& top_table_val = raw_config.update(table_spec);
129  if (!top_table_val.is_a(fhicl::TABLE)) {
131  << "Unexpected non-table " << table_spec << ".\n";
132  }
133  auto& table = raw_config.get<table_t&>(table_spec);
134  for (auto const& tval : table) {
135  auto& table_val = raw_config.update(table_spec + '.' + tval.first);
136  if (!table_val.is_a(fhicl::TABLE)) {
138  << "Unexpected non-table " << tval.first << " found in " << table_spec
139  << ".\n";
140  };
141  if (std::find(excluded.cbegin(), excluded.cend(), tval.first) ==
142  excluded.end()) {
143  raw_config.put(table_spec + '.' + tval.first + ".service_type",
144  tval.first);
145  }
146  }
147  }
148 
149  void
150  addServiceType(fhicl::intermediate_table& raw_config)
151  {
152  std::vector<std::string> const excluded{"message", "scheduler"};
153  injectServiceType(raw_config, "services", excluded);
154  }
155 } // namespace
156 
157 int
158 art::BasicPostProcessor::doCheckOptions(bpo::variables_map const&)
159 {
160  return 0; // NOP
161 }
162 
163 int
165  fhicl::intermediate_table& raw_config)
166 {
167  verifyProcessName(raw_config);
168  verifyInterfaces(raw_config);
169  verifySourceConfig(raw_config);
170  // module_labels and service_type.
171  addModuleLabels(raw_config);
172  addServiceType(raw_config);
173  return 0; // If anything had gone wrong, we would have thrown.
174 }
int doCheckOptions(bpo::variables_map const &vm) override
bool exists_outside_prolog(fhicl::intermediate_table const &config, std::string const &key)
int doProcessOptions(bpo::variables_map const &vm, fhicl::intermediate_table &raw_config) override
std::enable_if_t< std::is_convertible_v< T, std::string >, std::string > fhicl_key(T const &name)
Definition: fhicl_key.h:12
shims::map< std::string, extended_value > table_t
bool put(std::string const &name, std::string const &value, bool in_prolog=false)
bool exists(std::string const &key) const
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
extended_value & update(std::string const &key)
T get(std::string const &name)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33