CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TriggerResultsBasedEventSelector.cc
Go to the documentation of this file.
1 #include <algorithm>
2 
6 
8 
9 namespace {
10  //--------------------------------------------------------
11  // Remove whitespace (spaces and tabs) from a std::string.
12  void remove_whitespace(std::string& s) {
13  s.erase(std::remove(s.begin(), s.end(), ' '), s.end());
14  s.erase(std::remove(s.begin(), s.end(), '\t'), s.end());
15  }
16 
17  void test_remove_whitespace() {
18  std::string a("noblanks");
19  std::string b("\t no blanks \t");
20 
21  remove_whitespace(b);
22  assert(a == b);
23  }
24 
25  //--------------------------------------------------------
26  // Given a path-spec (std::string of the form "a:b", where the ":b" is
27  // optional), return a parsed_path_spec_t containing "a" and "b".
28 
29  typedef std::pair<std::string, std::string> parsed_path_spec_t;
30  void parse_path_spec(std::string const& path_spec,
31  parsed_path_spec_t& output) {
32  std::string trimmed_path_spec(path_spec);
33  remove_whitespace(trimmed_path_spec);
34 
35  std::string::size_type colon = trimmed_path_spec.find(":");
36  if(colon == std::string::npos) {
37  output.first = trimmed_path_spec;
38  } else {
39  output.first = trimmed_path_spec.substr(0, colon);
40  output.second = trimmed_path_spec.substr(colon + 1,
41  trimmed_path_spec.size());
42  }
43  }
44 
45  void test_parse_path_spec() {
46  std::vector<std::string> paths;
47  paths.push_back("a:p1");
48  paths.push_back("b:p2");
49  paths.push_back(" c");
50  paths.push_back("ddd\t:p3");
51  paths.push_back("eee: p4 ");
52 
53  std::vector<parsed_path_spec_t> parsed(paths.size());
54  for(size_t i = 0; i < paths.size(); ++i) {
55  parse_path_spec(paths[i], parsed[i]);
56  }
57 
58  assert(parsed[0].first == "a");
59  assert(parsed[0].second == "p1");
60  assert(parsed[1].first == "b");
61  assert(parsed[1].second == "p2");
62  assert(parsed[2].first == "c");
63  assert(parsed[2].second == "");
64  assert(parsed[3].first == "ddd");
65  assert(parsed[3].second == "p3");
66  assert(parsed[4].first == "eee");
67  assert(parsed[4].second == "p4");
68  }
69 }
70 
71 namespace edm
72 {
73  namespace test {
75  test_remove_whitespace();
76  test_parse_path_spec();
77  }
78  }
79 
80  namespace detail
81  {
82 
84  std::string const& iProcessName,
85  std::vector<std::string> const& iAllTriggerNames,
87  // If selectevents is an emtpy ParameterSet, then we are to write
88  // all events, or one which contains a vstrig 'SelectEvents' that
89  // is empty, we are to write all events. We have no need for any
90  // EventSelectors.
91  if(iPSet.empty()) {
92  oSelector.setupDefault(iAllTriggerNames);
93  return true;
94  }
95 
96  std::vector<std::string> path_specs =
97  iPSet.getParameter<std::vector<std::string> >("SelectEvents");
98 
99  if(path_specs.empty()) {
100  oSelector.setupDefault(iAllTriggerNames);
101  return true;
102  }
103 
104  // If we get here, we have the possibility of having to deal with
105  // path_specs that look at more than one process.
106  std::vector<parsed_path_spec_t> parsed_paths(path_specs.size());
107  for(size_t i = 0; i < path_specs.size(); ++i) {
108  parse_path_spec(path_specs[i], parsed_paths[i]);
109  }
110  oSelector.setup(parsed_paths, iAllTriggerNames, iProcessName);
111 
112  return false;
113  }
114 
115 
119  inputTag_,
120  nullptr,
121  mcc);
123  }
124 
126 
127 
129  fillDone_(false),
130  numberFound_(0),
131  selectors_()
132  { }
133 
134  void
135  TriggerResultsBasedEventSelector::setupDefault(std::vector<std::string> const& triggernames)
136  {
137 
138  // Set up one NamedEventSelector, with default configuration
139  std::vector<std::string> paths;
140  EventSelector es(paths, triggernames);
141  selectors_.emplace_back("", es);
142  //selectors_.push_back(NES("", EventSelector("",triggernames)));
143  }
144 
145  void
146  TriggerResultsBasedEventSelector::setup(std::vector<parsed_path_spec_t> const& path_specs,
147  std::vector<std::string> const& triggernames,
148  const std::string& process_name)
149  {
150  // paths_for_process maps each PROCESS names to a sequence of
151  // PATH names
152  std::map<std::string, std::vector<std::string> > paths_for_process;
153  for (std::vector<parsed_path_spec_t>::const_iterator
154  i = path_specs.begin(),
155  e = path_specs.end();
156  i != e;
157  ++i)
158  {
159  // Default to current process if none specified
160  if (i->second == "") {
161  paths_for_process[process_name].push_back(i->first);
162  }
163  else {
164  paths_for_process[i->second].push_back(i->first);
165  }
166  }
167  // Now go through all the PROCESS names, and create a
168  // NamedEventSelector for each.
169  for (std::map<std::string, std::vector<std::string> >::const_iterator
170  i = paths_for_process.begin(),
171  e = paths_for_process.end();
172  i != e;
173  ++i)
174  {
175  // For the current process we know the trigger names
176  // from the configuration file
177  if (i->first == process_name) {
178  selectors_.emplace_back(i->first,
179  EventSelector(i->second,
180  triggernames));
181  }
182  // For previous processes we do not know the trigger
183  // names yet.
184  else {
185  selectors_.emplace_back(i->first, EventSelector(i->second));
186  }
187  }
188  }
189 
192  {
193  fill(ev, mcc);
194  return returnOneHandleOrThrow();
195  }
196 
197  bool
199  {
200  // We have to get all the TriggerResults objects before we test
201  // any for a match, because we have to deal with the possibility
202  // of multiple TriggerResults objects --- note that the presence
203  // of more than one TriggerResults object in the event is
204  // intended to lead to an exception throw *unless* either the
205  // configuration has been set to match all events, or the
206  // configuration is set to use specific process names.
207 
208  fill(ev, mcc);
209 
210  // Now we go through and see if anyone matches...
211  iter i = selectors_.begin();
212  iter e = selectors_.end();
213  bool match_found = false;
214  while (!match_found && (i!=e))
215  {
216  match_found = i->match();
217  ++i;
218  }
219  return match_found;
220  }
221 
224  {
225  switch (numberFound_)
226  {
227  case 0:
229  "TooFewProducts")
230  << "TriggerResultsBasedEventSelector::returnOneHandleOrThrow: "
231  << " too few products found, "
232  << "exepcted one, got zero\n";
233  case 1:
234 
235  break;
236  default:
238  "TooManyMatches")
239  << "TriggerResultsBasedEventSelector::returnOneHandleOrThrow: "
240  << "too many products found, "
241  << "expected one, got " << numberFound_ << '\n';
242  }
243  return selectors_[0].product();
244  }
245 
248  {
249  if (!fillDone_)
250  {
251  fillDone_ = true;
252  for (iter i = selectors_.begin(), e = selectors_.end();
253  i != e; ++i)
254  {
255  i->fill(ev, mcc); // fill might throw...
256  ++numberFound_ ; // so numberFound_ might be less than expected
257  }
258  }
259  return numberFound_;
260  }
261 
262  void
264  {
265  for_all(selectors_, std::bind(&NamedEventSelector::clear, std::placeholders::_1));
266  fillDone_ = false;
267  numberFound_ = 0;
268  }
269 
270 
271 
274  std::string const& iLabel,
275  std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
276  bool anyProductProduced) {
277  ParameterSet selectEventsInfo;
278  selectEventsInfo.copyForModify(iInitial);
279  selectEventsInfo.addParameter<bool>("InProcessHistory", anyProductProduced);
280  std::vector<std::string> endPaths;
281  std::vector<int> endPathPositions;
282 
283  // The label will be empty if and only if this is a SubProcess
284  // SubProcess's do not appear on any end path
285  if (!iLabel.empty()) {
286  std::map<std::string, std::vector<std::pair<std::string, int> > >::const_iterator iter = outputModulePathPositions.find(iLabel);
287  assert(iter != outputModulePathPositions.end());
288  for (std::vector<std::pair<std::string, int> >::const_iterator i = iter->second.begin(), e = iter->second.end();
289  i != e; ++i) {
290  endPaths.push_back(i->first);
291  endPathPositions.push_back(i->second);
292  }
293  }
294  selectEventsInfo.addParameter<std::vector<std::string> >("EndPaths", endPaths);
295  selectEventsInfo.addParameter<std::vector<int> >("EndPathPositions", endPathPositions);
296  if (!selectEventsInfo.exists("SelectEvents")) {
297  selectEventsInfo.addParameter<std::vector<std::string> >("SelectEvents", std::vector<std::string>());
298  }
299  selectEventsInfo.registerIt();
300 
301  return selectEventsInfo.id();
302  }
303 
304 
305  } // namespace detail
306 } // namespace edm
T getParameter(std::string const &) const
bool empty() const
Definition: ParameterSet.h:217
int i
Definition: DBlmapReader.cc:9
ParameterSetID id() const
static const edm::TypeID s_TrigResultsType(typeid(edm::TriggerResults))
void fill(EventPrincipal const &e, ModuleCallingContext const *mcc)
assert(m_qm.get())
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool ev
detail::NamedEventSelector NES
size_type fill(EventPrincipal const &ev, ModuleCallingContext const *)
uint16_t size_type
void setupDefault(std::vector< std::string > const &triggernames)
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
Definition: Algorithms.h:16
U second(std::pair< T, U > const &p)
void setup(std::vector< parsed_path_spec_t > const &path_specs, std::vector< std::string > const &triggernames, const std::string &process_name)
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:143
def move
Definition: eostools.py:508
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
void copyForModify(ParameterSet const &other)
void convert_handle(BasicHandle &&bh, Handle< T > &result)
Definition: ConvertHandle.h:20
double b
Definition: hdecay.h:120
handle_t getOneTriggerResults(EventPrincipal const &e, ModuleCallingContext const *)
bool wantEvent(EventPrincipal const &e, ModuleCallingContext const *)
double a
Definition: hdecay.h:121
BasicHandle getByLabel(KindOfType kindOfType, TypeID const &typeID, InputTag const &inputTag, EDConsumerBase const *consumes, ModuleCallingContext const *mcc) const
Definition: Principal.cc:455
volatile std::atomic< bool > shutdown_flag false
ParameterSetID registerProperSelectionInfo(edm::ParameterSet const &iInitial, std::string const &iLabel, std::map< std::string, std::vector< std::pair< std::string, int > > > const &outputModulePathPositions, bool anyProductProduced)
bool configureEventSelector(edm::ParameterSet const &iPSet, std::string const &iProcessName, std::vector< std::string > const &iAllTriggerNames, edm::detail::TriggerResultsBasedEventSelector &oSelector)
ParameterSet const & registerIt()