LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
TriggerNamesService_service.cc
Go to the documentation of this file.
11 
12 // vim: set sw=2 expandtab :
13 
14 #include <algorithm>
15 #include <cassert>
16 #include <cstddef>
17 #include <limits>
18 #include <optional>
19 #include <string>
20 #include <vector>
21 
23 using namespace fhicl;
24 using namespace std;
25 
27 
28 namespace {
29  constexpr auto invalid_entry = numeric_limits<size_t>::max();
31  for_(art::PathID const id)
32  {
33  return [id](art::PathSpec const& spec) { return spec.path_id == id; };
34  }
36  for_(string const& name)
37  {
38  return [&name](art::PathSpec const& spec) { return spec.name == name; };
39  }
40 
41  auto
42  lookup_exception(string const& process_name)
43  {
44  return art::Exception{
46  "An error occurred while retrieving the trigger paths for process '" +
47  process_name + "'.\n"};
48  }
49 
51  data_for_process(ParameterSet const& trigger_paths_pset,
52  ParameterSet const physics_pset)
53  {
54  auto const spec_strs =
55  trigger_paths_pset.get<vector<string>>("trigger_paths");
56  auto specs = art::path_specs(spec_strs);
57 
58  vector<string> trigger_path_names;
59  vector<vector<string>> module_names;
60  for (auto const& spec_str : specs) {
61  trigger_path_names.push_back(spec_str.name);
62  module_names.push_back(physics_pset.get<vector<string>>(spec_str.name));
63  }
64  return {
65  std::move(specs), std::move(trigger_path_names), std::move(module_names)};
66  }
67 }
68 
69 namespace art {
70 
71  TriggerNamesService::TriggerNamesService(
72  ParameterSet const& trigger_paths_pset,
73  ParameterSet const& physics_pset)
74  {
75  dataPerProcess_.try_emplace(
76  getProcessName(), data_for_process(trigger_paths_pset, physics_pset));
77  }
78 
79  DataPerProcess const&
80  TriggerNamesService::currentData_() const
81  {
82  return dataPerProcess_.at(getProcessName());
83  }
84 
85  // =================================================================================
86  // All processes
87  TriggerResults const&
88  TriggerNamesService::triggerResults(Event const& e,
89  string const& process_name) const
90  {
91  auto h = e.getHandle<TriggerResults>({"TriggerResults", "", process_name});
92  if (h) {
93  return *h;
94  }
95  throw lookup_exception(process_name) << *h.whyFailed();
96  }
97 
98  map<string, HLTPathStatus>
99  TriggerNamesService::pathResults(Event const& e,
100  string const& process_name) const
101  {
102  auto const& tr = triggerResults(e, process_name);
103  auto const& pname =
104  process_name == "current_process" ? getProcessName() : process_name;
105 
106  auto it = dataPerProcess_.find(process_name);
107  if (it == cend(dataPerProcess_)) {
108  auto config = e.processHistory().getConfigurationForProcess(pname);
109  if (not config) {
110  throw lookup_exception(pname)
111  << "Could not locate process configuration for the process '" << pname
112  << "'\n"
113  << "This can happen if the ParameterSets were dropped on input.\n"
114  << "Please contact artists@fnal.gov for guidance.\n";
115  }
116 
117  auto const& trigger_pset = ParameterSetRegistry::get(tr.parameterSetID());
118  auto const& pset = ParameterSetRegistry::get(config->parameterSetID());
119  auto data =
120  data_for_process(trigger_pset, pset.get<ParameterSet>("physics"));
121  it = dataPerProcess_.try_emplace(process_name, std::move(data)).first;
122  }
123 
124  auto const& names = it->second.triggerPathNames;
125  assert(size(names) == tr.size());
126 
127  map<string, HLTPathStatus> result;
128  for (size_t i = 0, n = tr.size(); i != n; ++i) {
129  result.try_emplace(names[i], tr.at(i));
130  }
131  return result;
132  }
133 
134  // =================================================================================
135  // Current process only
136  string const&
137  TriggerNamesService::getProcessName() const
138  {
139  return Globals::instance()->processName();
140  }
141 
142  vector<string> const&
143  TriggerNamesService::getTrigPaths() const
144  {
145  return currentData_().triggerPathNames;
146  }
147 
148  string const&
149  TriggerNamesService::getTrigPath(PathID const id) const
150  {
151  auto const i = index_for(id);
152  if (i == invalid_entry) {
154  << "A path name could not be found corresponding to path ID "
155  << to_string(id) << '\n';
156  }
157  return currentData_().triggerPathSpecs[i].name;
158  }
159 
160  vector<string> const&
161  TriggerNamesService::getTrigPathModules(string const& name) const
162  {
163  auto const& modules = currentData_().moduleNames;
164  return modules.at(index_(for_(name)));
165  }
166 
167  vector<string> const&
168  TriggerNamesService::getTrigPathModules(PathID const id) const
169  {
170  auto const& modules = currentData_().moduleNames;
171  return modules.at(index_for(id));
172  }
173 
174  size_t
175  TriggerNamesService::index_for(PathID const id) const
176  {
177  return index_(for_(id));
178  }
179 
180  size_t
181  TriggerNamesService::index_(entry_selector_t matched_entry) const
182  {
183  auto const& path_specs = currentData_().triggerPathSpecs;
184 
185  auto const b = begin(path_specs);
186  auto const e = end(path_specs);
187  auto it = find_if(b, e, matched_entry);
188  if (it == e) {
189  return invalid_entry;
190  }
191  return distance(b, it);
192  }
193 
194 } // namespace art
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
Definition: StdUtils.h:93
static collection_type const & get() noexcept
const std::string instance
ProcessHistory const & processHistory() const
Definition: Event.cc:71
STL namespace.
std::string to_string(Protection p)
Definition: Protection.cc:4
std::function< bool(PathSpec const &)> entry_selector_t
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
std::vector< PathSpec > path_specs(std::vector< std::string > const &path_spec_strs)
Definition: PathSpec.cc:34
parameter set interface
T get(std::string const &key) const
Definition: ParameterSet.h:314
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::optional< ProcessConfiguration > getConfigurationForProcess(std::string const &name) const
Handle< PROD > getHandle(SelectorBase const &) const
art::TriggerNamesService::DataPerProcess DataPerProcess
Definition: MVAAlg.h:12
Char_t n[5]
std::vector< art::PathSpec > path_specs(std::vector< ModuleSpec > const &selection_override_entries, std::string const &path_selection_override)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
Float_t e
Definition: plot.C:35