LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
BasicPostProcessor.cc
Go to the documentation of this file.
2 
6 #include "cetlib/container_algorithms.h"
7 #include "cetlib/filepath_maker.h"
8 #include "fhiclcpp/coding.h"
11 #include "fhiclcpp/parse.h"
12 
13 #include <iostream>
14 #include <string>
15 
16 namespace {
17 
21 
22  void
23  verifyProcessName(fhicl::intermediate_table& raw_config)
24  {
25  if (exists_outside_prolog(raw_config, "process_name")) {
26  auto const& process_name = raw_config.get<std::string>("process_name");
27  if (process_name.empty()) {
28  throw cet::exception("BAD_PROCESS_NAME")
29  << "Empty process_name not permitted.";
30  } else if (process_name.find('_') != std::string::npos) {
31  throw cet::exception("BAD_PROCESS_NAME")
32  << "Underscores not permitted in process_name: illegal value \""
33  << process_name << "\"";
34  }
35  } else {
36  std::cerr << "INFO: using default process_name of \"DUMMY\".\n";
37  raw_config.put("process_name", "DUMMY");
38  }
39  }
40 
41  void
42  verifyInterfaces(fhicl::intermediate_table& raw_config)
43  {
44  std::string const services{"services"};
45  std::string const service_provider{"service_provider"};
46  auto ciProvider = fhicl_key(services, "CatalogInterface", service_provider);
47  auto ftProvider = fhicl_key(services, "FileTransfer", service_provider);
48  if (!exists_outside_prolog(raw_config, ciProvider)) {
49  raw_config.put(ciProvider, "TrivialFileDelivery");
50  }
51  if (!exists_outside_prolog(raw_config, ftProvider)) {
52  raw_config.put(ftProvider, "TrivialFileTransfer");
53  }
54  }
55 
56  void
57  verifySourceConfig(fhicl::intermediate_table& raw_config)
58  {
59  if (exists_outside_prolog(raw_config, "source.fileNames")) {
60  if (exists_outside_prolog(raw_config, "source.module_type")) {
61  if (raw_config.get<std::string>("source.module_type") == "EmptyEvent") {
63  << "Error: source files specified for EmptyEvent source.";
64  }
65  } else {
66  raw_config.put("source.module_type", "RootInput");
67  }
68  } else if (!exists_outside_prolog(raw_config, "source.module_type")) {
69  raw_config.put("source.module_type", "EmptyEvent");
70  }
71  if (raw_config.get<std::string>("source.module_type") == "EmptyEvent" &&
72  !exists_outside_prolog(raw_config, "source.maxEvents")) {
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  // trigger_paths
171  if (exists_outside_prolog(raw_config, "physics.trigger_paths")) {
172  raw_config.update("trigger_paths.trigger_paths") =
173  raw_config.find("physics.trigger_paths");
174  }
175  // module_labels and service_type.
176  addModuleLabels(raw_config);
177  addServiceType(raw_config);
178  return 0; // If anything had gone wrong, we would have thrown.
179 }
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
shims::map< std::string, extended_value > table_t
extended_value const & find(std::string const &name) const
bool put(std::string const &name, std::string const &value, bool in_prolog=false)
std::enable_if_t< std::is_convertible< T, std::string >::value, std::string > fhicl_key(T const &name)
Definition: fhicl_key.h:13
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
extended_value & update(std::string const &name)
T get(std::string const &name)
bool exists(std::string const &name) const
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33