CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CachedProducts.cc
Go to the documentation of this file.
1 #include <algorithm>
2 
3 #include "boost/bind.hpp"
4 
7 
8 namespace edm
9 {
10  namespace detail
11  {
13 
14 
16  fillDone_(false),
17  numberFound_(0),
18  selectors_()
19  { }
20 
21  void
22  CachedProducts::setupDefault(std::vector<std::string> const& triggernames)
23  {
24 
25  // Set up one NamedEventSelector, with default configuration
26  std::vector<std::string> paths;
27  EventSelector es(paths, triggernames);
28  NES nes("", es);
29  selectors_.push_back(nes);
30  //selectors_.push_back(NES("", EventSelector("",triggernames)));
31  }
32 
33  void
34  CachedProducts::setup(std::vector<parsed_path_spec_t> const& path_specs,
35  std::vector<std::string> const& triggernames,
36  const std::string& process_name)
37  {
38  // paths_for_process maps each PROCESS names to a sequence of
39  // PATH names
40  std::map<std::string, std::vector<std::string> > paths_for_process;
41  for (std::vector<parsed_path_spec_t>::const_iterator
42  i = path_specs.begin(),
43  e = path_specs.end();
44  i != e;
45  ++i)
46  {
47  // Default to current process if none specified
48  if (i->second == "") {
49  paths_for_process[process_name].push_back(i->first);
50  }
51  else {
52  paths_for_process[i->second].push_back(i->first);
53  }
54  }
55  // Now go through all the PROCESS names, and create a
56  // NamedEventSelector for each.
57  for (std::map<std::string, std::vector<std::string> >::const_iterator
58  i = paths_for_process.begin(),
59  e = paths_for_process.end();
60  i != e;
61  ++i)
62  {
63  // For the current process we know the trigger names
64  // from the configuration file
65  if (i->first == process_name) {
66  selectors_.push_back(NES(i->first,
67  EventSelector(i->second,
68  triggernames)));
69  }
70  // For previous processes we do not know the trigger
71  // names yet.
72  else {
73  selectors_.push_back(NES(i->first,
74  EventSelector(i->second)));
75  }
76  }
77  }
78 
81  {
82  fill(ev);
83  return returnOneHandleOrThrow();
84  }
85 
86  bool
88  {
89  // We have to get all the TriggerResults objects before we test
90  // any for a match, because we have to deal with the possibility
91  // of multiple TriggerResults objects --- note that the presence
92  // of more than one TriggerResults object in the event is
93  // intended to lead to an exception throw *unless* either the
94  // configuration has been set to match all events, or the
95  // configuration is set to use specific process names.
96 
97  fill(ev);
98 
99  // Now we go through and see if anyone matches...
100  iter i = selectors_.begin();
101  iter e = selectors_.end();
102  bool match_found = false;
103  while (!match_found && (i!=e))
104  {
105  match_found = i->match();
106  ++i;
107  }
108  return match_found;
109  }
110 
113  {
114  switch (numberFound_)
115  {
116  case 0:
118  "TooFewProducts")
119  << "CachedProducts::returnOneHandleOrThrow: "
120  << " too few products found, "
121  << "exepcted one, got zero\n";
122  case 1:
123 
124  break;
125  default:
127  "TooManyMatches")
128  << "CachedProducts::returnOneHandleOrThrow: "
129  << "too many products found, "
130  << "expected one, got " << numberFound_ << '\n';
131  }
132  return selectors_[0].product();
133  }
134 
137  {
138  if (!fillDone_)
139  {
140  fillDone_ = true;
141  for (iter i = selectors_.begin(), e = selectors_.end();
142  i != e; ++i)
143  {
144  i->fill(ev); // fill might throw...
145  ++numberFound_ ; // so numberFound_ might be less than expected
146  }
147  }
148  return numberFound_;
149  }
150 
151  void
153  {
154  for_all(selectors_, boost::bind(&NamedEventSelector::clear, _1));
155  fillDone_ = false;
156  numberFound_ = 0;
157  }
158 
159 
160  } // namespace detail
161 } // namespace edm
int i
Definition: DBlmapReader.cc:9
handle_t getOneTriggerResults(Event const &e)
detail::NamedEventSelector NES
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
Definition: Algorithms.h:16
selectors_t::size_type size_type
size_type fill(Event const &ev)
void setup(std::vector< parsed_path_spec_t > const &path_specs, std::vector< std::string > const &triggernames, const std::string &process_name)
selectors_t::iterator iter
void setupDefault(std::vector< std::string > const &triggernames)
bool wantEvent(Event const &e)