test
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  // typedef detail::NamedEventSelector NES;
116 
118  selectors_()
119  { }
120 
121  void
122  TriggerResultsBasedEventSelector::setupDefault(std::vector<std::string> const& triggernames) {
123 
124  // Set up one NamedEventSelector, with default configuration
125  std::vector<std::string> paths;
126  EventSelector es(paths, triggernames);
127  selectors_.emplace_back("", es);
128  //selectors_.push_back(NES("", EventSelector("",triggernames)));
129  }
130 
131  void
132  TriggerResultsBasedEventSelector::setup(std::vector<parsed_path_spec_t> const& path_specs,
133  std::vector<std::string> const& triggernames,
134  const std::string& process_name) {
135  // paths_for_process maps each PROCESS names to a sequence of
136  // PATH names
137  std::map<std::string, std::vector<std::string> > paths_for_process;
138  for (auto const& path_spec : path_specs) {
139  // Default to current process if none specified
140  if (path_spec.second == "") {
141  paths_for_process[process_name].push_back(path_spec.first);
142  }
143  else {
144  paths_for_process[path_spec.second].push_back(path_spec.first);
145  }
146  }
147  // Now go through all the PROCESS names, and create a
148  // NamedEventSelector for each.
149  for (auto const& path : paths_for_process) {
150  // For the current process we know the trigger names
151  // from the configuration file
152  if (path.first == process_name) {
153  selectors_.emplace_back(path.first, EventSelector(path.second, triggernames));
154  } else {
155  // For previous processes we do not know the trigger
156  // names yet.
157  selectors_.emplace_back(path.first, EventSelector(path.second));
158  }
159  }
160  }
161 
162  bool
164  for(auto& selector : selectors_) {
167  selector.inputTag(),
168  nullptr,
169  nullptr,
170  mcc);
171  handle_t product;
172  convert_handle(std::move(h), product);
173  bool match = selector.match(*product);
174  if(match) {
175  return true;
176  }
177  }
178  return false;
179  }
180 
183  std::string const& iLabel,
184  std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
185  bool anyProductProduced) {
186  ParameterSet selectEventsInfo;
187  selectEventsInfo.copyForModify(iInitial);
188  selectEventsInfo.addParameter<bool>("InProcessHistory", anyProductProduced);
189  std::vector<std::string> endPaths;
190  std::vector<int> endPathPositions;
191 
192  // The label will be empty if and only if this is a SubProcess
193  // SubProcess's do not appear on any end path
194  if (!iLabel.empty()) {
195  std::map<std::string, std::vector<std::pair<std::string, int> > >::const_iterator iter = outputModulePathPositions.find(iLabel);
196  assert(iter != outputModulePathPositions.end());
197  for(auto const& item : iter->second) {
198  endPaths.push_back(item.first);
199  endPathPositions.push_back(item.second);
200  }
201  }
202  selectEventsInfo.addParameter<std::vector<std::string> >("EndPaths", endPaths);
203  selectEventsInfo.addParameter<std::vector<int> >("EndPathPositions", endPathPositions);
204  if (!selectEventsInfo.exists("SelectEvents")) {
205  selectEventsInfo.addParameter<std::vector<std::string> >("SelectEvents", std::vector<std::string>());
206  }
207  selectEventsInfo.registerIt();
208 
209  return selectEventsInfo.id();
210  }
211 
212  } // namespace detail
213 } // namespace edm
T getParameter(std::string const &) const
bool empty() const
Definition: ParameterSet.h:218
int i
Definition: DBlmapReader.cc:9
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
ParameterSetID id() const
static const edm::TypeID s_TrigResultsType(typeid(edm::TriggerResults))
assert(m_qm.get())
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool ev
uint16_t size_type
void setupDefault(std::vector< std::string > const &triggernames)
U second(std::pair< T, U > const &p)
BasicHandle getByLabel(KindOfType kindOfType, TypeID const &typeID, InputTag const &inputTag, EDConsumerBase const *consumes, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:476
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:144
def move
Definition: eostools.py:510
void copyForModify(ParameterSet const &other)
void convert_handle(BasicHandle &&bh, Handle< T > &result)
Definition: ConvertHandle.h:19
double b
Definition: hdecay.h:120
bool wantEvent(EventPrincipal const &e, ModuleCallingContext const *)
double a
Definition: hdecay.h:121
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()
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)