LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
ServiceDirector.cc
Go to the documentation of this file.
2 
6 
8 using ParameterSets = std::vector<ParameterSet>;
9 
10 namespace {
11 
12  void
13  addService(std::string const& name, ParameterSets& service_set)
14  {
16  tmp.put("service_type", name);
18  service_set.emplace_back(std::move(tmp));
19  }
20 
21  void
22  addService(std::string const& name,
23  ParameterSet const& source,
24  ParameterSets& service_set)
25  {
27  if (source.get_if_present(name, tmp)) {
28  service_set.emplace_back(std::move(tmp));
29  } else {
30  // Add a suitably simple parameter set.
31  addService(name, service_set);
32  }
33  }
34 
36  extractServices(ParameterSet&& services)
37  {
38  ParameterSets service_set;
39  bool const wantTracer{services.get<bool>("scheduler.wantTracer", false)};
40  services.erase("scheduler");
41 
42  // If we want the tracer and it's not explicitly configured, insert
43  // it, otherwise it'll get picked up automatically.
44  if (wantTracer && !services.has_key("Tracer")) {
45  addService("Tracer", service_set);
46  }
47 
48  // Force presence of FileCatalogMetadata service.
49  addService("FileCatalogMetadata", services, service_set);
50  services.erase("FileCatalogMetadata");
51 
52  // Force presence of DatabaseConnection service.
53  addService("DatabaseConnection", services, service_set);
54  services.erase("DatabaseConnection");
55 
56  // Extract all
57  for (auto const& key : services.get_pset_names()) {
58  addService(key, services, service_set);
59  }
60  return service_set;
61  }
62 }
63 
65  ActivityRegistry& areg,
66  ServiceToken& serviceToken)
67  : serviceToken_{serviceToken}
68 {
70  ServiceRegistry::createSet(extractServices(std::move(services)), areg);
71 }
static ParameterSetID const & put(ParameterSet const &ps)
Float_t tmp
Definition: plot.C:37
std::vector< ParameterSet > ParameterSets
bool get_if_present(std::string const &key, T &value) const
Definition: ParameterSet.h:208
ServiceDirector(fhicl::ParameterSet &&services, ActivityRegistry &areg, ServiceToken &token)
void put(std::string const &key)
static ServiceToken createSet(ParameterSets const &, ActivityRegistry &)
ServiceToken & serviceToken_