LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
art::FileCatalogOptionsHandler Class Reference

#include "FileCatalogOptionsHandler.h"

Inheritance diagram for art::FileCatalogOptionsHandler:
art::OptionsHandler

Public Member Functions

 FileCatalogOptionsHandler (bpo::options_description &desc)
 
int checkOptions (bpo::variables_map const &vm)
 
int processOptions (bpo::variables_map const &vm, fhicl::intermediate_table &raw_config)
 

Private Member Functions

int doCheckOptions (bpo::variables_map const &vm) override
 
int doProcessOptions (bpo::variables_map const &vm, fhicl::intermediate_table &raw_config) override
 

Private Attributes

std::string appFamily_ {}
 
std::string appVersion_ {}
 

Detailed Description

Definition at line 14 of file FileCatalogOptionsHandler.h.

Constructor & Destructor Documentation

art::FileCatalogOptionsHandler::FileCatalogOptionsHandler ( bpo::options_description &  desc)
explicit

Definition at line 174 of file FileCatalogOptionsHandler.cc.

References appFamily_, and appVersion_.

176 {
177  bpo::options_description sam_options{"SAM options"};
178  // clang-format off
179  sam_options.add_options()
180  ("sam-web-uri", bpo::value<string>(), "URI for SAM web service.")
181  ("sam-process-id", bpo::value<string>(), "SAM process ID.")
182  ("sam-application-family",
183  bpo::value<string>(&appFamily_), "SAM application family.")
184  ("sam-app-family",
185  bpo::value<string>(&appFamily_), "SAM application family.")
186  ("sam-application-version",
187  bpo::value<string>(&appVersion_), "SAM application version.")
188  ("sam-app-version",
189  bpo::value<string>(&appVersion_), "SAM application version.")
190  ("sam-group", bpo::value<string>(), "SAM group.")
191  ("sam-file-type", bpo::value<string>(), "File type for SAM metadata.")
192  ("sam-data-tier",
193  bpo::value<vector<string>>(),
194  "SAM data tier (<spec-label>:<tier-spec>).")
195  ("sam-run-type", bpo::value<string>(), "Global run-type for SAM metadata.")
196  ("sam-stream-name",
197  bpo::value<vector<string>>(),
198  "SAM stream name (<module-label>:<stream-name>).")
199  ("sam-inherit-metadata", "Input file provides the file type and run type.")
200  ("sam-inherit-file-type", "Input file provides the file type.")
201  ("sam-inherit-run-type", "Input file provides the run type.");
202  // clang-format on
203  desc.add(sam_options);
204 }

Member Function Documentation

int art::OptionsHandler::checkOptions ( bpo::variables_map const &  vm)
inherited

Definition at line 51 of file OptionsHandler.cc.

References art::OptionsHandler::doCheckOptions().

52 {
53  std::string const thisClass(cet::demangle_symbol(typeid(*this).name()));
54  return exceptionCatcher([&vm, this] { return doCheckOptions(vm); },
55  thisClass + "::doCheckOptions()",
56  89);
57 }
virtual int doCheckOptions(bpo::variables_map const &vm)=0
int art::FileCatalogOptionsHandler::doCheckOptions ( bpo::variables_map const &  vm)
overrideprivatevirtual

Implements art::OptionsHandler.

Definition at line 207 of file FileCatalogOptionsHandler.cc.

208 {
209  // Checks can't be done until after post-processing.
210  return 0;
211 }
int art::FileCatalogOptionsHandler::doProcessOptions ( bpo::variables_map const &  vm,
fhicl::intermediate_table raw_config 
)
overrideprivatevirtual

Implements art::OptionsHandler.

Definition at line 214 of file FileCatalogOptionsHandler.cc.

References appFamily_, appVersion_, art::errors::Configuration, art::ensureTable(), fhicl::intermediate_table::erase(), art::detail::exists_outside_prolog(), art::detail::fhicl_key(), fhicl::intermediate_table::get(), and fhicl::intermediate_table::put().

217 {
218  std::string const services{"services"};
219  auto const& ciLocation = fhicl_key(services, "CatalogInterface");
220  auto const& ftLocation = fhicl_key(services, "FileTransfer");
221  auto const& fcmdLocation = fhicl_key(services, "FileCatalogMetadata");
222 
224  // Load up the configuration with command-line options.
225  //
226  // sam-web-uri and sam-process-id.
227  if (vm.count("sam-web-uri") > 0) {
228  raw_config.put(fhicl_key(ciLocation, "webURI"),
229  vm["sam-web-uri"].as<string>());
230  }
231  if (vm.count("sam-process-id") > 0) {
232  // Sequence.
233  raw_config.put("source.fileNames",
234  vector<string>{vm["sam-process-id"].as<string>()});
235  // Atom.
236  raw_config.put(fhicl_key(fcmdLocation, "processID"),
237  vm["sam-process-id"].as<string>());
238  }
239  if (exists_outside_prolog(raw_config, fhicl_key(ciLocation, "webURI")) !=
241  raw_config, fhicl_key(fcmdLocation, "processID"))) { // Inconsistent.
243  << "configurations " << fhicl_key(ciLocation, "webURI")
244  << " (--sam-web-uri) and\n"
245  << fhicl_key(fcmdLocation, "processID")
246  << " (--sam-process-id) must be specified\n"
247  << "together or not at all.\n";
248  }
249  bool const wantSAMweb{
250  exists_outside_prolog(raw_config, fhicl_key(ciLocation, "webURI")) &&
251  exists_outside_prolog(raw_config, "source.fileNames")};
252  // Other metadata items.
253  if (!appFamily_.empty()) {
254  raw_config.put(fhicl_key(fcmdLocation, "applicationFamily"), appFamily_);
255  }
256  if (vm.count("sam-group") > 0) {
257  raw_config.put(fhicl_key(fcmdLocation, "group"),
258  vm["sam-group"].as<string>());
259  }
260  if (!appVersion_.empty()) {
261  raw_config.put(fhicl_key(fcmdLocation, "applicationVersion"), appVersion_);
262  }
263 
264  check_metadata_options(vm);
265 
266  string const mdFromInput{"metadataFromInput"};
267  bool specifyDataTier{false}; // The output module needs a
268  // 'dataTier' if "fileType" is
269  // provided either by the input file
270  // or as a configuration parameter.
271  if (vm.count("sam-inherit-metadata") > 0) {
272  raw_config.put(fhicl_key(fcmdLocation, mdFromInput),
273  vector<string>{"fileType", "runType"});
274  specifyDataTier = true;
275  raw_config.erase(fhicl_key(fcmdLocation, "fileType"));
276  raw_config.erase(fhicl_key(fcmdLocation, "runType"));
277  } else {
278  vector<string> md;
279  if (vm.count("sam-inherit-file-type") > 0) {
280  md.emplace_back("file_type");
281  specifyDataTier = true;
282  raw_config.erase(fhicl_key(fcmdLocation, "fileType"));
283  }
284  if (vm.count("sam-inherit-run-type") > 0) {
285  // 'run_type' is not supported by SAM as a top-level field; we
286  // thus preface it with 'art.'
287  md.emplace_back("art.run_type");
288  raw_config.erase(fhicl_key(fcmdLocation, "runType"));
289  }
290  if (!md.empty()) {
291  raw_config.put(fhicl_key(fcmdLocation, mdFromInput), md);
292  }
293  }
294 
295  if (vm.count("sam-run-type") > 0) {
296  raw_config.put(fhicl_key(fcmdLocation, "runType"),
297  vm["sam-run-type"].as<string>());
298  }
299  if (vm.count("sam-file-type") > 0) {
300  raw_config.put(fhicl_key(fcmdLocation, "fileType"),
301  vm["sam-file-type"].as<string>());
302  }
303  bool const requireMetadata =
304  have_outputs(raw_config) &&
305  (wantSAMweb ||
306  exists_outside_prolog(raw_config,
307  fhicl_key(fcmdLocation, "applicationFamily")) ||
308  exists_outside_prolog(raw_config,
309  fhicl_key(fcmdLocation, "applicationVersion")) ||
310  exists_outside_prolog(raw_config, fhicl_key(fcmdLocation, "group")) ||
311  exists_outside_prolog(raw_config, fhicl_key(fcmdLocation, "fileType")) ||
312  specifyDataTier);
313 
314  if (requireMetadata) {
315  fill_tiers_streams(vm, raw_config);
316  maybeThrowOnMissingMetadata(raw_config);
317  }
318 
319  string process_name;
320  if (exists_outside_prolog(raw_config, "process_name")) {
321  process_name = raw_config.get<string>("process_name");
322  }
323  if (requireMetadata && process_name.empty()) {
325  << "Non-empty / default process_name required for SAM metadata.\n";
326  }
327  if (wantSAMweb) {
328  raw_config.put(fhicl_key(ciLocation, "service_provider"),
329  "IFCatalogInterface");
330  raw_config.put(fhicl_key(ftLocation, "service_provider"), "IFFileTransfer");
331  art::ensureTable(raw_config, fhicl_key(services, "IFDH"));
332  }
333  return 0;
334 }
bool exists_outside_prolog(fhicl::intermediate_table const &config, std::string const &key)
void ensureTable(fhicl::intermediate_table &table, std::string const &fhicl_spec)
Definition: ensureTable.cc:6
std::enable_if_t< std::is_convertible_v< T, std::string >, std::string > fhicl_key(T const &name)
Definition: fhicl_key.h:12
bool put(std::string const &name, std::string const &value, bool in_prolog=false)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void erase(std::string const &key, bool in_prolog=false)
T get(std::string const &name)
int art::OptionsHandler::processOptions ( bpo::variables_map const &  vm,
fhicl::intermediate_table raw_config 
)
inherited

Definition at line 60 of file OptionsHandler.cc.

References art::OptionsHandler::doProcessOptions().

62 {
63  std::string const thisClass(cet::demangle_symbol(typeid(*this).name()));
64  return exceptionCatcher(
65  [&, this] { return doProcessOptions(vm, raw_config); },
66  thisClass + "::doProcessOptions()",
67  90);
68 }
virtual int doProcessOptions(bpo::variables_map const &vm, fhicl::intermediate_table &raw_config)=0

Member Data Documentation

std::string art::FileCatalogOptionsHandler::appFamily_ {}
private

Definition at line 25 of file FileCatalogOptionsHandler.h.

Referenced by doProcessOptions(), and FileCatalogOptionsHandler().

std::string art::FileCatalogOptionsHandler::appVersion_ {}
private

Definition at line 26 of file FileCatalogOptionsHandler.h.

Referenced by doProcessOptions(), and FileCatalogOptionsHandler().


The documentation for this class was generated from the following files: