LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
CachedProducts.cc
Go to the documentation of this file.
2 
3 #include "cetlib/container_algorithms.h"
4 
5 #include <map>
6 #include <string>
7 #include <vector>
8 
9 using namespace cet;
10 using namespace std;
11 
12 void
13 art::detail::CachedProducts::setupDefault(vector<string> const& triggernames)
14 {
15  // Setup to accept everything.
16  vector<string> paths;
17  EventSelector ES(paths, triggernames);
18  p_and_e_selectors_.emplace_back("", ES);
19 }
20 
21 void
23  vector<pair<string, string>> const& path_specs,
24  vector<string> const& triggernames,
25  string const& process_name)
26 {
27  // Turn the passed path specs into a map of process name to
28  // a vector of trigger names.
29  map<string, vector<string>> paths_for_process;
30  for (auto const& pr : path_specs) {
31  auto const& pname = pr.first.empty() ? process_name : pr.first;
32  paths_for_process[pname].push_back(pr.second);
33  }
34 
35  // Now go through all the process names found, and create an event
36  // selector for each one.
37  for (auto const& pr : paths_for_process) {
38  auto const& pname = pr.first;
39  auto const& paths = pr.second;
40  if (pname == process_name) {
41  // For the passed process name we have been given the trigger names.
42  p_and_e_selectors_.emplace_back(pname,
43  EventSelector{paths, triggernames});
44  continue;
45  }
46  // For other process names we do not know the trigger names.
47  p_and_e_selectors_.emplace_back(pname, EventSelector{paths});
48  }
49 }
50 
51 bool
53 {
54  // Get all the TriggerResults objects before we test any for a
55  // match, because we have to deal with the possibility there may be
56  // more than one. Note that the existence of more than one object
57  // in the event is intended to lead to an exception throw *unless*
58  // either the configuration has been set to match all events, or the
59  // configuration is set to use specific process names.
60  loadTriggerResults(ev);
61 
62  return any_of(begin(p_and_e_selectors_),
63  end(p_and_e_selectors_),
64  [](auto& s) { return s.match(); });
65 }
66 
69 {
70  const_cast<CachedProducts*>(this)->loadTriggerResults(ev);
71  if (numberFound_ == 1) {
72  return p_and_e_selectors_[0].triggerResults();
73  }
74  if (numberFound_ == 0) {
75  throw art::Exception(art::errors::ProductNotFound, "TooFewProducts")
76  << "CachedProducts::getOneTriggerResults: "
77  << "too few products found, exepcted one, got zero\n";
78  }
79  throw art::Exception(art::errors::ProductNotFound, "TooManyMatches")
80  << "CachedProducts::getOneTriggerResults: "
81  << "too many products found, expected one, got " << numberFound_ << '\n';
82 }
83 
84 void
86 {
87  for_all(p_and_e_selectors_, [](auto& p) { p.clearTriggerResults(); });
88  loadDone_ = false;
89  numberFound_ = 0;
90 }
91 
92 void
94 {
95  // Get all the TriggerResults objects for the process names we are
96  // interested in.
97  if (loadDone_) {
98  return;
99  }
100  loadDone_ = true;
101  // Note: The loadTriggerResults call might throw, so numberFound_
102  // may be less than expected.
103  for_all(p_and_e_selectors_, [&, this](auto& s) {
104  s.loadTriggerResults(ev);
105  ++numberFound_;
106  });
107 }
Float_t s
Definition: plot.C:23
art::Handle< art::TriggerResults > getOneTriggerResults(Event const &) const
STL namespace.
void setup(std::vector< std::pair< std::string, std::string >> const &path_specs, std::vector< std::string > const &trigger_names, std::string const &process_name)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void loadTriggerResults(Event const &)
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
void setupDefault(std::vector< std::string > const &trigger_names)
bool wantEvent(Event const &)