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

#include "RPManager.h"

Public Types

template<typename RET , typename... ARGS>
using invoke_function_t = RET(ResultsProducer::*)(ARGS...)
 
using on_rpworker_t = std::function< void(RPWorker &)>
 

Public Member Functions

 RPManager (fhicl::ParameterSet const &ps)
 
template<typename... ARGS>
void invoke (invoke_function_t< void, ARGS... > mfunc, ARGS &&...args)
 
void for_each_RPWorker (on_rpworker_t wfunc)
 

Private Attributes

std::map< std::string, std::vector< std::unique_ptr< RPWorker > > > rpmap_
 

Detailed Description

Definition at line 19 of file RPManager.h.

Member Typedef Documentation

template<typename RET , typename... ARGS>
using art::RPManager::invoke_function_t = RET (ResultsProducer::*)(ARGS...)

Definition at line 22 of file RPManager.h.

using art::RPManager::on_rpworker_t = std::function<void(RPWorker&)>

Definition at line 24 of file RPManager.h.

Constructor & Destructor Documentation

art::RPManager::RPManager ( fhicl::ParameterSet const &  ps)

Definition at line 21 of file RPManager.cc.

References art::errors::Configuration, fhicl::ParameterSet::get(), fhicl::ParameterSet::get_names(), fhicl::ParameterSet::id(), art::Suffixes::plugin(), rpmap_, util::to_string(), value, and lar::dump::vector().

21  : rpmap_{}
22  {
23  string const omLabel(ps.get<string>("module_label"));
24  auto results = ps.get<ParameterSet>("results", {});
25  auto producers = results.get<ParameterSet>("producers", {});
26  auto results_keys = results.get_names();
27  auto producer_keys = producers.get_names();
28  map<string, vector<string>> paths;
29  string errMsg;
30  if (producer_keys.empty() && !results.is_empty()) {
32  << "Parameter set " << omLabel
33  << ".results is non-empty, but does not contain\n"
34  << "a non-empty producers parameter set.\n";
35  }
36  auto const path_keys_end =
37  remove(results_keys.begin(), results_keys.end(), "producers");
38  auto const& all_labels = producers.get_names();
39  set<string> all_labels_set(all_labels.cbegin(), all_labels.cend());
40  map<string, string> used_labels;
41  for (auto path_key = results_keys.begin(); path_key != path_keys_end;
42  ++path_key) {
43  if (!results.is_key_to_sequence(*path_key)) {
44  errMsg += "Parameter " + omLabel + ".results." + *path_key +
45  " does not describe a sequence (i.e. a path).\n";
46  continue;
47  }
48  auto path = results.get<vector<string>>(*path_key);
49  int idx = 0;
50  for (auto const& l : path) {
51  if (all_labels_set.find(l) == all_labels_set.end()) {
52  // Bad label
53  errMsg += omLabel + ".results."s + *path_key + '[' +
54  std::to_string(idx) + "] ("s + l + ')' +
55  " is not defined in "s + omLabel + ".results.producers.\n"s;
56  ++idx;
57  continue;
58  }
59  auto const ans = used_labels.emplace(l, *path_key);
60  if (!ans.second) {
61  // Duplicate
62  errMsg += omLabel + ".results." + *path_key + '[' +
63  std::to_string(idx) + "] (" + l + ')' +
64  " is a duplicate: previously used in path " +
65  ans.first->second + ".\n";
66  }
67  ++idx;
68  }
69  if (errMsg.empty()) {
70  paths.emplace(*path_key, std::move(path));
71  }
72  }
73  if (paths.empty() && (errMsg.empty())) {
74  paths.emplace("default_path", all_labels);
75  }
76  if (!errMsg.empty()) {
78  << "Errors encountered while configuring ResultsProducers:\n"
79  << errMsg;
80  }
81  cet::BasicPluginFactory pf{Suffixes::plugin(), "makeRP"};
82  for (auto const& [path_name, module_names] : paths) {
83  auto ins_res = rpmap_.emplace(path_name, vector<unique_ptr<RPWorker>>{});
84  transform(module_names.cbegin(),
85  module_names.cend(),
86  back_inserter(ins_res.first->second),
87  [&pf, &producers, &omLabel, &errMsg](string const& pkey) {
88  unique_ptr<RPWorker> result;
89  auto const& pconfig = producers.get<ParameterSet>(pkey);
90  auto libspec = pconfig.get<string>("plugin_type");
91  auto const& ptype = pf.pluginType(libspec);
93  result = pf.makePlugin<unique_ptr<RPWorker>,
94  RPParams const&,
95  ParameterSet const&>(
96  libspec, {pconfig.id(), libspec, pkey}, pconfig);
97  } else {
98  errMsg +=
99  "Parameter set " + omLabel + ".results." + pkey +
100  " specifies a plugin " + libspec +
101  "\n which is not of required type ResultsProducer.\n";
102  }
103  return result;
104  });
105  }
106  if (!errMsg.empty()) {
108  << "Errors encountered while instantiating ResultsProducers:\n"
109  << errMsg;
110  }
111  }
std::map< std::string, std::vector< std::unique_ptr< RPWorker > > > rpmap_
Definition: RPManager.h:35
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
T get(std::string const &key) const
Definition: ParameterSet.h:314
static std::string const & plugin()
double value
Definition: spectrum.C:18
ParameterSetID id() const
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::vector< std::string > get_names() const

Member Function Documentation

void art::RPManager::for_each_RPWorker ( on_rpworker_t  wfunc)

Definition at line 114 of file RPManager.cc.

References rpmap_, and w.

115  {
116  for (auto& path : rpmap_) {
117  for (auto& w : path.second) {
118  wfunc(*w);
119  }
120  }
121  }
std::map< std::string, std::vector< std::unique_ptr< RPWorker > > > rpmap_
Definition: RPManager.h:35
Float_t w
Definition: plot.C:20
template<typename... ARGS>
void art::RPManager::invoke ( invoke_function_t< void, ARGS... >  mfunc,
ARGS &&...  args 
)

Definition at line 40 of file RPManager.h.

References rpmap_, and w.

41  {
42  for (auto& path : rpmap_) {
43  for (auto& w : path.second) {
44  (w->rp().*mfunc)(std::forward<ARGS>(args)...);
45  }
46  }
47  }
std::map< std::string, std::vector< std::unique_ptr< RPWorker > > > rpmap_
Definition: RPManager.h:35
Float_t w
Definition: plot.C:20

Member Data Documentation

std::map<std::string, std::vector<std::unique_ptr<RPWorker> > > art::RPManager::rpmap_
private

Definition at line 35 of file RPManager.h.

Referenced by for_each_RPWorker(), invoke(), and RPManager().


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