LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
RPManager.cc
Go to the documentation of this file.
4 #include "cetlib/PluginTypeDeducer.h"
5 
6 #include <memory>
7 #include <string>
8 
9 namespace {
10  std::size_t
11  countProducers(art::RPManager::RPMap_t const& rpmap)
12  {
13  std::size_t result = 0ul;
14  for (auto const& path : rpmap) {
15  result += path.second.size();
16  }
17  return result;
18  }
19 }
20 
22  : pf_(Suffixes::plugin(), "makeRP")
23  , rpmap_(makeRPs_(ps))
24  , size_(countProducers(rpmap_))
25 {}
26 
27 namespace {
28  std::unique_ptr<art::RPWorker>
29  pathLoader(cet::BasicPluginFactory& pf,
30  fhicl::ParameterSet const& producers,
31  std::string const& pkey,
32  std::string const& omLabel,
33  std::string& errMsg)
34  {
35  std::unique_ptr<art::RPWorker> result;
36  auto const& pconfig = producers.get<fhicl::ParameterSet>(pkey);
37  auto libspec = pconfig.get<std::string>("plugin_type");
38  auto const& ptype = pf.pluginType(libspec);
40  result = pf.makePlugin<std::unique_ptr<art::RPWorker>,
41  art::RPParams const&,
42  fhicl::ParameterSet const&>(
43  libspec, {pconfig.id(), libspec, pkey}, pconfig);
44  } else {
45  errMsg += +"Parameter set " + omLabel,
46  +".results." + pkey + " specifies a plugin " + libspec +
47  "\n which is not of required type ResultsProducer.\n";
48  }
49  return result;
50  }
51 }
52 
53 auto
55 {
56  using fhicl::ParameterSet;
57  decltype(rpmap_) result;
58  auto results = ps.get<ParameterSet>("results", {});
59  auto producers = results.get<ParameterSet>("producers", {});
60  auto results_keys = results.get_names();
61  auto producer_keys = producers.get_names();
62  std::map<std::string, std::vector<std::string>> paths;
63  std::string const omLabel(ps.get<std::string>("module_label"));
64  std::string errMsg;
65  if (producer_keys.empty()) {
66  if (!results.is_empty()) {
68  << "Parameter set " << omLabel
69  << ".results is non-empty, but does not contain\n"
70  << "a non-empty producers parameter set.\n";
71  }
72  } else {
73  auto const path_keys_end =
74  std::remove(results_keys.begin(), results_keys.end(), "producers");
75  auto const& all_labels = producers.get_names();
76  std::set<std::string> all_labels_set(all_labels.cbegin(),
77  all_labels.cend());
78  std::map<std::string, std::string> used_labels;
79  for (auto path_key = results_keys.begin(); path_key != path_keys_end;
80  ++path_key) {
81  if (!results.is_key_to_sequence(*path_key)) {
82  errMsg += +"Parameter " + omLabel + ".results." + *path_key +
83  " does not describe a sequence (i.e. a path).\n";
84  } else {
85  auto path = results.get<std::vector<std::string>>(*path_key);
86  std::size_t path_index = 0ull;
87  for (auto const& l : path) {
88  if (all_labels_set.find(l) == all_labels_set.end()) { // Bad label
89  errMsg += omLabel + ".results." + *path_key + '[' +
90  std::to_string(path_index) + "] (" + l + ')' +
91  " is not defined in " + omLabel + ".results.producers.\n";
92  } else {
93  auto const ans = used_labels.emplace(l, *path_key);
94  if (!ans.second) { // Duplicate
95  errMsg += omLabel + ".results." + *path_key + '[' +
96  std::to_string(path_index) + "] (" + l + ')' +
97  " is a duplicate: previously used in path " +
98  ans.first->second + ".\n";
99  }
100  }
101  ++path_index;
102  }
103  if (errMsg.empty()) {
104  paths.emplace(*path_key, std::move(path));
105  }
106  }
107  }
108  if (paths.empty() && (errMsg.empty())) {
109  paths.emplace("default_path", all_labels);
110  }
111  }
112  if (!errMsg.empty()) {
114  << "Errors encountered while configuring ResultsProducers:\n"
115  << errMsg;
116  }
117  for (auto const& path : paths) {
118  auto ins_res = rpmap_.emplace(path.first, decltype(rpmap_)::mapped_type{});
119  std::transform(path.second.cbegin(),
120  path.second.cend(),
121  std::back_inserter(ins_res.first->second),
122  std::bind(&pathLoader,
123  std::ref(pf_),
124  std::cref(producers),
125  std::placeholders::_1,
126  std::cref(omLabel),
127  std::ref(errMsg)));
128  }
129  if (!errMsg.empty()) {
131  << "Errors encountered while instantiating ResultsProducers:\n"
132  << errMsg;
133  }
134  return result;
135 }
cet::BasicPluginFactory pf_
Definition: RPManager.h:45
std::map< std::string, RPPath_t > RPMap_t
Definition: RPManager.h:27
RPManager(fhicl::ParameterSet const &ps)
Definition: RPManager.cc:21
T get(std::string const &key) const
Definition: ParameterSet.h:231
ParameterSetID id() const
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::string to_string(Flag_t< Storage > const flag)
Convert a flag into a stream (shows its index).
Definition: BitMask.h:187
RPMap_t rpmap_
Definition: RPManager.h:46
RPMap_t makeRPs_(fhicl::ParameterSet const &ps)
Definition: RPManager.cc:54