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 = std::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_(std::string const& name)
37  {
38  return [&name](art::PathSpec const& spec) { return spec.name == name; };
39  }
40 
41  auto
42  lookup_exception(std::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<std::vector<std::string>>("trigger_paths");
56  auto specs = art::path_specs(spec_strs);
57 
58  std::vector<std::string> trigger_path_names;
59  std::vector<std::vector<std::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 {move(specs), move(trigger_path_names), move(module_names)};
65  }
66 }
67 
68 namespace art {
69 
70  TriggerNamesService::TriggerNamesService(
71  ParameterSet const& trigger_paths_pset,
72  ParameterSet const& physics_pset)
73  {
74  dataPerProcess_.try_emplace(
75  getProcessName(), data_for_process(trigger_paths_pset, physics_pset));
76  }
77 
78  DataPerProcess const&
79  TriggerNamesService::currentData_() const
80  {
81  return dataPerProcess_.at(getProcessName());
82  }
83 
84  // =================================================================================
85  // All processes
86  TriggerResults const&
87  TriggerNamesService::triggerResults(Event const& e,
88  std::string const& process_name) const
89  {
91  if (not e.getByLabel("TriggerResults", "", process_name, h)) {
92  throw lookup_exception(process_name) << *h.whyFailed();
93  }
94  return *h;
95  }
96 
97  std::map<std::string, HLTPathStatus>
98  TriggerNamesService::pathResults(Event const& e,
99  std::string const& process_name) const
100  {
101  auto const& tr = triggerResults(e, process_name);
102  auto const& pname =
103  process_name == "current_process" ? getProcessName() : process_name;
104 
105  auto it = dataPerProcess_.find(process_name);
106  if (it == cend(dataPerProcess_)) {
108  if (not config) {
109  throw lookup_exception(pname)
110  << "Could not locate process configuration for the process '" << pname
111  << "'\n"
112  << "This can happen if the ParameterSets were dropped on input.\n"
113  << "Please contact artists@fnal.gov for guidance.\n";
114  }
115 
116  auto const& trigger_pset = ParameterSetRegistry::get(tr.parameterSetID());
117  auto const& pset = ParameterSetRegistry::get(config->parameterSetID());
118  auto data = data_for_process(trigger_pset,
119  pset.get<fhicl::ParameterSet>("physics"));
120  it = dataPerProcess_.try_emplace(process_name, std::move(data)).first;
121  }
122 
123  auto const& names = it->second.triggerPathNames;
124  assert(size(names) == tr.size());
125 
126  std::map<std::string, HLTPathStatus> result;
127  for (size_t i = 0, n = tr.size(); i != n; ++i) {
128  result.try_emplace(names[i], tr.at(i));
129  }
130  return result;
131  }
132 
133  // =================================================================================
134  // Current process only
135  string const&
136  TriggerNamesService::getProcessName() const
137  {
139  }
140 
141  vector<string> const&
142  TriggerNamesService::getTrigPaths() const
143  {
144  return currentData_().triggerPathNames;
145  }
146 
147  string const&
148  TriggerNamesService::getTrigPath(PathID const id) const
149  {
150  auto const i = index_for(id);
151  if (i == invalid_entry) {
153  << "A path name could not be found corresponding to path ID "
154  << to_string(id) << '\n';
155  }
156  return currentData_().triggerPathSpecs[i].name;
157  }
158 
159  vector<string> const&
160  TriggerNamesService::getTrigPathModules(string const& name) const
161  {
162  auto const& modules = currentData_().moduleNames;
163  return modules.at(index_(for_(name)));
164  }
165 
166  vector<string> const&
167  TriggerNamesService::getTrigPathModules(PathID const id) const
168  {
169  auto const& modules = currentData_().moduleNames;
170  return modules.at(index_for(id));
171  }
172 
173  size_t
174  TriggerNamesService::index_for(PathID const id) const
175  {
176  return index_(for_(id));
177  }
178 
179  size_t
180  TriggerNamesService::index_(entry_selector_t matched_entry) const
181  {
182  auto const& path_specs = currentData_().triggerPathSpecs;
183 
184  auto const b = begin(path_specs);
185  auto const e = end(path_specs);
186  auto it = std::find_if(b, e, matched_entry);
187  if (it == e) {
188  return invalid_entry;
189  }
190  return std::distance(b, it);
191  }
192 
193 } // namespace art
static QCString name
Definition: declinfo.cpp:673
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
Definition: StdUtils.h:87
static QCString result
std::string string
Definition: nybbler.cc:12
ProcessHistory const & processHistory() const
static collection_type const & get() noexcept
STL namespace.
std::string to_string(Protection p)
Definition: Protection.cc:4
std::function< bool(PathSpec const &)> entry_selector_t
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
const double e
std::vector< PathSpec > path_specs(std::vector< std::string > const &path_spec_strs)
Definition: PathSpec.cc:34
static Config * config
Definition: config.cpp:1054
std::void_t< T > n
def move(depos, offset)
Definition: depos.py:107
T get(std::string const &key) const
Definition: ParameterSet.h:271
Strings const trigger_path_names
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
static int max(int a, int b)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::optional< ProcessConfiguration > getConfigurationForProcess(std::string const &name) const
std::string const & processName() const
Definition: Globals.cc:48
art::TriggerNamesService::DataPerProcess DataPerProcess
static bool * b
Definition: config.cpp:1043
std::shared_ptr< art::Exception const > whyFailed() const
Definition: Handle.h:219
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:72
static Globals * instance()
Definition: Globals.cc:17
static std::vector< std::string > const names
Definition: FragmentType.hh:8