CMS 3D CMS Logo

TriggerResultsBasedEventSelector.cc
Go to the documentation of this file.
1 #include <algorithm>
2 
7 
9 
11  //--------------------------------------------------------
12  // Remove whitespace (spaces and tabs) from a std::string.
14  s.erase(std::remove(s.begin(), s.end(), ' '), s.end());
15  s.erase(std::remove(s.begin(), s.end(), '\t'), s.end());
16  }
17 
18  //--------------------------------------------------------
19  // Given a path-spec (std::string of the form "a:b", where the ":b" is
20  // optional), return a parsed_path_spec_t containing "a" and "b".
21 
22  typedef std::pair<std::string, std::string> parsed_path_spec_t;
24  std::string trimmed_path_spec(path_spec);
25  remove_whitespace(trimmed_path_spec);
26 
27  std::string::size_type colon = trimmed_path_spec.find(':');
28  if (colon == std::string::npos) {
29  output.first = trimmed_path_spec;
30  } else {
31  output.first = trimmed_path_spec.substr(0, colon);
32  output.second = trimmed_path_spec.substr(colon + 1, trimmed_path_spec.size());
33  }
34  }
35 } // namespace trigger_results_based_event_selector_utils
36 
38 
39 namespace edm {
40 
41  namespace detail {
42 
44  std::string const& iProcessName,
45  std::vector<std::string> const& iAllTriggerNames,
48  // If selectevents is an emtpy ParameterSet, then we are to write
49  // all events, or one which contains a vstrig 'SelectEvents' that
50  // is empty, we are to write all events. We have no need for any
51  // EventSelectors.
52  if (iPSet.empty()) {
53  oSelector.setupDefault();
54  return true;
55  }
56 
57  std::vector<std::string> path_specs = iPSet.getParameter<std::vector<std::string> >("SelectEvents");
58 
59  if (path_specs.empty()) {
60  oSelector.setupDefault();
61  return true;
62  }
63 
64  // If we get here, we have the possibility of having to deal with
65  // path_specs that look at more than one process.
66  std::vector<parsed_path_spec_t> parsed_paths(path_specs.size());
67  for (size_t i = 0; i < path_specs.size(); ++i) {
68  parse_path_spec(path_specs[i], parsed_paths[i]);
69  }
70  oSelector.setup(parsed_paths, iAllTriggerNames, iProcessName, std::move(iC));
71 
72  return false;
73  }
74 
75  // typedef detail::NamedEventSelector NES;
76 
77  TriggerResultsBasedEventSelector::TriggerResultsBasedEventSelector() : selectors_(), wantAllEvents_(false) {}
78 
80 
81  void TriggerResultsBasedEventSelector::setup(std::vector<parsed_path_spec_t> const& path_specs,
82  std::vector<std::string> const& triggernames,
83  std::string const& process_name,
84  ConsumesCollector&& iC) {
85  // paths_for_process maps each PROCESS names to a sequence of
86  // PATH names
87  std::map<std::string, std::vector<std::string> > paths_for_process;
88  for (auto const& path_spec : path_specs) {
89  // Default to current process if none specified
90  if (path_spec.second.empty()) {
91  paths_for_process[process_name].push_back(path_spec.first);
92  } else {
93  paths_for_process[path_spec.second].push_back(path_spec.first);
94  }
95  }
96  // Now go through all the PROCESS names, and create a
97  // NamedEventSelector for each.
98  for (auto const& path : paths_for_process) {
99  // For the current process we know the trigger names
100  // from the configuration file
101  if (path.first == process_name) {
102  selectors_.emplace_back(path.first, EventSelector(path.second, triggernames), std::move(iC));
103  } else {
104  // For previous processes we do not know the trigger
105  // names yet.
106  selectors_.emplace_back(path.first, EventSelector(path.second), std::move(iC));
107  }
108  }
109  }
110 
112  if (wantAllEvents_) {
113  return true;
114  }
115  for (auto& selector : selectors_) {
117  ev.getByToken<TriggerResults>(selector.token(), handle);
118  bool match = selector.match(*handle);
119  if (match) {
120  return true;
121  }
122  }
123  return false;
124  }
125 
127  edm::ParameterSet const& iInitial,
128  std::string const& iLabel,
129  std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
130  bool anyProductProduced) {
131  ParameterSet selectEventsInfo;
132  selectEventsInfo.copyForModify(iInitial);
133  selectEventsInfo.addParameter<bool>("InProcessHistory", anyProductProduced);
134  std::vector<std::string> endPaths;
135  std::vector<int> endPathPositions;
136 
137  // The label will be empty if and only if this is a SubProcess
138  // SubProcess's do not appear on any end path
139  if (!iLabel.empty()) {
140  std::map<std::string, std::vector<std::pair<std::string, int> > >::const_iterator iter =
141  outputModulePathPositions.find(iLabel);
142  assert(iter != outputModulePathPositions.end());
143  for (auto const& item : iter->second) {
144  endPaths.push_back(item.first);
145  endPathPositions.push_back(item.second);
146  }
147  }
148  selectEventsInfo.addParameter<std::vector<std::string> >("EndPaths", endPaths);
149  selectEventsInfo.addParameter<std::vector<int> >("EndPathPositions", endPathPositions);
150  if (!selectEventsInfo.exists("SelectEvents")) {
151  selectEventsInfo.addParameter<std::vector<std::string> >("SelectEvents", std::vector<std::string>());
152  }
153  selectEventsInfo.registerIt();
154 
155  return selectEventsInfo.id();
156  }
157 
158  } // namespace detail
159 } // namespace edm
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
Definition: Hash.h:43
static const edm::TypeID s_TrigResultsType(typeid(edm::TriggerResults))
bool exists(std::string const &parameterName) const
checks if a parameter exists
assert(be >=bs)
uint16_t size_type
ParameterSetID id() const
ParameterSet const & registerIt()
bool empty() const
Definition: ParameterSet.h:202
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:136
bool configureEventSelector(edm::ParameterSet const &iPSet, std::string const &iProcessName, std::vector< std::string > const &iAllTriggerNames, edm::detail::TriggerResultsBasedEventSelector &oSelector, ConsumesCollector &&iC)
void copyForModify(ParameterSet const &other)
std::pair< std::string, std::string > parsed_path_spec_t
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:233
void parse_path_spec(std::string const &path_spec, parsed_path_spec_t &output)
HLT enums.
void setup(std::vector< parsed_path_spec_t > const &path_specs, std::vector< std::string > const &triggernames, std::string const &process_name, ConsumesCollector &&iC)
Definition: output.py:1
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)
def move(src, dest)
Definition: eostools.py:511