LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
Observer.cc
Go to the documentation of this file.
2 // vim: set sw=2 expandtab :
3 
9 
10 #include <string>
11 #include <vector>
12 
13 using namespace std;
14 
16 
17 using namespace art::detail;
18 
19 namespace {
20 
21  std::optional<ProcessAndEventSelectors>
22  make_selectors(vector<string> const& paths, std::string const& process_name)
23  {
24  if (empty(paths)) {
25  return std::nullopt;
26  }
27  // Parse the event selection criteria into (process, trigger name
28  // list) pairs.
29  vector<pair<string, string>> PPS(paths.size());
30  for (size_t i = 0; i < paths.size(); ++i) {
31  PPS[i] = art::split_process_and_path_names(paths[i]);
32  }
33  return std::make_optional<ProcessAndEventSelectors>(PPS, process_name);
34  }
35 
36  art::ProcessNameSelector const empty_process_name{""};
37 }
38 
39 namespace art {
40 
41  Observer::~Observer() noexcept = default;
42 
44  : Observer{pset.get<vector<string>>("SelectEvents", {}),
45  pset.get<vector<string>>("RejectEvents", {})}
46  {}
47 
48  Observer::Observer(vector<string> const& select_paths,
49  vector<string> const& reject_paths)
50  : wantAllEvents_{empty(select_paths) and empty(reject_paths)}
52  , selectors_{make_selectors(select_paths, process_name_)}
53  , rejectors_{make_selectors(reject_paths, process_name_)}
54  {}
55 
56  string const&
58  {
59  return process_name_;
60  }
61 
62  bool
63  Observer::wantEvent(ScheduleID const id, Event const& e) const
64  {
65  if (wantAllEvents_) {
66  return true;
67  }
68  bool const select_event = selectors_ ? selectors_->matchEvent(id, e) : true;
69  bool const reject_event =
70  rejectors_ ? rejectors_->matchEvent(id, e) : false;
71  return select_event and not reject_event;
72  }
73 
76  {
77  if (selectors_) {
78  return selectors_->getOneTriggerResults(e);
79  }
80 
81  // The following applies for cases where no SelectEvents entries
82  // exist.
84  if (e.get(empty_process_name, h)) {
85  return h;
86  }
87  return Handle<TriggerResults>{};
88  }
89 
90 } // namespace art
std::string const & processName() const
Definition: Observer.cc:57
bool get(SelectorBase const &, Handle< PROD > &result) const
Handle< TriggerResults > getTriggerResults(Event const &e) const
Definition: Observer.cc:75
bool wantAllEvents_
Definition: Observer.h:75
STL namespace.
std::string process_name_
Definition: Observer.h:76
bool wantEvent(ScheduleID id, Event const &e) const
Definition: Observer.cc:63
std::string const & processName() const
Definition: Globals.cc:48
Definition: MVAAlg.h:12
std::optional< detail::ProcessAndEventSelectors > rejectors_
Definition: Observer.h:80
static Globals * instance()
Definition: Globals.cc:17
Float_t e
Definition: plot.C:35
std::optional< detail::ProcessAndEventSelectors > selectors_
Definition: Observer.h:79
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:109
std::pair< std::string, std::string > split_process_and_path_names(std::string path_spec)
Definition: PathSpec.cc:11