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  pset}
47  {}
48 
49  Observer::Observer(vector<string> const& select_paths,
50  vector<string> const& reject_paths,
51  fhicl::ParameterSet const& pset)
52  : wantAllEvents_{empty(select_paths) and empty(reject_paths)}
54  , selectors_{make_selectors(select_paths, process_name_)}
55  , rejectors_{make_selectors(reject_paths, process_name_)}
56  , selector_config_id_{pset.id()}
57  {}
58 
59  void
61  {}
62 
63  void
65  {}
66 
67  string const&
69  {
70  return process_name_;
71  }
72 
73  bool
74  Observer::wantEvent(ScheduleID const id, Event const& e) const
75  {
76  if (wantAllEvents_) {
77  return true;
78  }
79  bool const select_event = selectors_ ? selectors_->matchEvent(id, e) : true;
80  bool const reject_event =
81  rejectors_ ? rejectors_->matchEvent(id, e) : false;
82  return select_event and not reject_event;
83  }
84 
87  {
88  return selector_config_id_;
89  }
90 
93  {
94  if (selectors_) {
95  return selectors_->getOneTriggerResults(e);
96  }
97 
98  // The following applies for cases where no SelectEvents entries
99  // exist.
101  if (e.get(empty_process_name, h)) {
102  return h;
103  }
104  return Handle<TriggerResults>{};
105  }
106 
107 } // namespace art
std::string const & processName() const
Definition: Observer.cc:68
Handle< TriggerResults > getTriggerResults(Event const &e) const
Definition: Observer.cc:92
std::string string
Definition: nybbler.cc:12
bool wantAllEvents_
Definition: Observer.h:82
void registerProducts(ProductDescriptions &, ModuleDescription const &)
Definition: Observer.cc:60
bool get(SelectorBase const &, Handle< PROD > &result) const
Definition: DataViewImpl.h:606
STL namespace.
std::string process_name_
Definition: Observer.h:83
std::vector< BranchDescription > ProductDescriptions
const double e
bool wantEvent(ScheduleID id, Event const &e) const
Definition: Observer.cc:74
void fillDescriptions(ModuleDescription const &)
Definition: Observer.cc:64
fhicl::ParameterSetID selector_config_id_
Definition: Observer.h:90
std::string const & processName() const
Definition: Globals.cc:48
std::optional< detail::ProcessAndEventSelectors > rejectors_
Definition: Observer.h:87
static Globals * instance()
Definition: Globals.cc:17
std::optional< detail::ProcessAndEventSelectors > selectors_
Definition: Observer.h:86
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:97
fhicl::ParameterSetID selectorConfig() const
Definition: Observer.cc:86
std::pair< std::string, std::string > split_process_and_path_names(std::string path_spec)
Definition: PathSpec.cc:11