CMS 3D CMS Logo

TriggerResultsBasedEventSelector.cc
Go to the documentation of this file.
1 #include <algorithm>
2 
7 
9 
10 namespace {
11  //--------------------------------------------------------
12  // Remove whitespace (spaces and tabs) from a std::string.
13  void remove_whitespace(std::string& s) {
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  void test_remove_whitespace() {
19  std::string a("noblanks");
20  std::string b("\t no blanks \t");
21 
22  remove_whitespace(b);
23  assert(a == b);
24  }
25 
26  //--------------------------------------------------------
27  // Given a path-spec (std::string of the form "a:b", where the ":b" is
28  // optional), return a parsed_path_spec_t containing "a" and "b".
29 
30  typedef std::pair<std::string, std::string> parsed_path_spec_t;
31  void parse_path_spec(std::string const& path_spec, 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, trimmed_path_spec.size());
41  }
42  }
43 
44  void test_parse_path_spec() {
45  std::vector<std::string> paths;
46  paths.push_back("a:p1");
47  paths.push_back("b:p2");
48  paths.push_back(" c");
49  paths.push_back("ddd\t:p3");
50  paths.push_back("eee: p4 ");
51 
52  std::vector<parsed_path_spec_t> parsed(paths.size());
53  for (size_t i = 0; i < paths.size(); ++i) {
54  parse_path_spec(paths[i], parsed[i]);
55  }
56 
57  assert(parsed[0].first == "a");
58  assert(parsed[0].second == "p1");
59  assert(parsed[1].first == "b");
60  assert(parsed[1].second == "p2");
61  assert(parsed[2].first == "c");
62  assert(parsed[2].second.empty());
63  assert(parsed[3].first == "ddd");
64  assert(parsed[3].second == "p3");
65  assert(parsed[4].first == "eee");
66  assert(parsed[4].second == "p4");
67  }
68 } // namespace
69 
70 namespace edm {
71  namespace test {
73  test_remove_whitespace();
74  test_parse_path_spec();
75  }
76  } // namespace test
77 
78  namespace detail {
79 
81  std::string const& iProcessName,
82  std::vector<std::string> const& iAllTriggerNames,
85  // If selectevents is an emtpy ParameterSet, then we are to write
86  // all events, or one which contains a vstrig 'SelectEvents' that
87  // is empty, we are to write all events. We have no need for any
88  // EventSelectors.
89  if (iPSet.empty()) {
90  oSelector.setupDefault();
91  return true;
92  }
93 
94  std::vector<std::string> path_specs = iPSet.getParameter<std::vector<std::string> >("SelectEvents");
95 
96  if (path_specs.empty()) {
97  oSelector.setupDefault();
98  return true;
99  }
100 
101  // If we get here, we have the possibility of having to deal with
102  // path_specs that look at more than one process.
103  std::vector<parsed_path_spec_t> parsed_paths(path_specs.size());
104  for (size_t i = 0; i < path_specs.size(); ++i) {
105  parse_path_spec(path_specs[i], parsed_paths[i]);
106  }
107  oSelector.setup(parsed_paths, iAllTriggerNames, iProcessName, std::move(iC));
108 
109  return false;
110  }
111 
112  // typedef detail::NamedEventSelector NES;
113 
115 
117 
118  void TriggerResultsBasedEventSelector::setup(std::vector<parsed_path_spec_t> const& path_specs,
119  std::vector<std::string> const& triggernames,
120  std::string const& process_name,
121  ConsumesCollector&& iC) {
122  // paths_for_process maps each PROCESS names to a sequence of
123  // PATH names
124  std::map<std::string, std::vector<std::string> > paths_for_process;
125  for (auto const& path_spec : path_specs) {
126  // Default to current process if none specified
127  if (path_spec.second.empty()) {
128  paths_for_process[process_name].push_back(path_spec.first);
129  } else {
130  paths_for_process[path_spec.second].push_back(path_spec.first);
131  }
132  }
133  // Now go through all the PROCESS names, and create a
134  // NamedEventSelector for each.
135  for (auto const& path : paths_for_process) {
136  // For the current process we know the trigger names
137  // from the configuration file
138  if (path.first == process_name) {
139  selectors_.emplace_back(path.first, EventSelector(path.second, triggernames), std::move(iC));
140  } else {
141  // For previous processes we do not know the trigger
142  // names yet.
143  selectors_.emplace_back(path.first, EventSelector(path.second), std::move(iC));
144  }
145  }
146  }
147 
149  if (wantAllEvents_) {
150  return true;
151  }
152  for (auto& selector : selectors_) {
154  ev.getByToken<TriggerResults>(selector.token(), handle);
155  bool match = selector.match(*handle);
156  if (match) {
157  return true;
158  }
159  }
160  return false;
161  }
162 
164  edm::ParameterSet const& iInitial,
165  std::string const& iLabel,
166  std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
167  bool anyProductProduced) {
168  ParameterSet selectEventsInfo;
169  selectEventsInfo.copyForModify(iInitial);
170  selectEventsInfo.addParameter<bool>("InProcessHistory", anyProductProduced);
171  std::vector<std::string> endPaths;
172  std::vector<int> endPathPositions;
173 
174  // The label will be empty if and only if this is a SubProcess
175  // SubProcess's do not appear on any end path
176  if (!iLabel.empty()) {
177  std::map<std::string, std::vector<std::pair<std::string, int> > >::const_iterator iter =
178  outputModulePathPositions.find(iLabel);
179  assert(iter != outputModulePathPositions.end());
180  for (auto const& item : iter->second) {
181  endPaths.push_back(item.first);
182  endPathPositions.push_back(item.second);
183  }
184  }
185  selectEventsInfo.addParameter<std::vector<std::string> >("EndPaths", endPaths);
186  selectEventsInfo.addParameter<std::vector<int> >("EndPathPositions", endPathPositions);
187  if (!selectEventsInfo.exists("SelectEvents")) {
188  selectEventsInfo.addParameter<std::vector<std::string> >("SelectEvents", std::vector<std::string>());
189  }
190  selectEventsInfo.registerIt();
191 
192  return selectEventsInfo.id();
193  }
194 
195  } // namespace detail
196 } // namespace edm
edm::ParameterSet::registerIt
ParameterSet const & registerIt()
Definition: ParameterSet.cc:113
mps_fire.i
i
Definition: mps_fire.py:428
funct::false
false
Definition: Factorize.h:29
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
patZpeak.handle
handle
Definition: patZpeak.py:23
edm
HLT enums.
Definition: AlignableModifier.h:19
Algorithms.h
cms::cuda::assert
assert(be >=bs)
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
edm::ParameterSet::copyForModify
void copyForModify(ParameterSet const &other)
Definition: ParameterSet.cc:100
edm::ParameterSet::id
ParameterSetID id() const
Definition: ParameterSet.cc:189
edm::detail::TriggerResultsBasedEventSelector::wantAllEvents_
bool wantAllEvents_
Definition: TriggerResultsBasedEventSelector.h:68
EventForOutput.h
detail
Definition: ConvertingESProducerWithDependenciesT.h:23
edm::Handle
Definition: AssociativeIterator.h:50
edm::EventSelector
Definition: EventSelector.h:35
dqmdumpme.first
first
Definition: dqmdumpme.py:55
edm::detail::TriggerResultsBasedEventSelector::TriggerResultsBasedEventSelector
TriggerResultsBasedEventSelector()
Definition: TriggerResultsBasedEventSelector.cc:114
alignCSCRings.s
s
Definition: alignCSCRings.py:92
test
Definition: SmallWORMDict.h:13
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
edm::detail::TriggerResultsBasedEventSelector::selectors_
selectors_t selectors_
Definition: TriggerResultsBasedEventSelector.h:67
edm::detail::TriggerResultsBasedEventSelector::setupDefault
void setupDefault()
Definition: TriggerResultsBasedEventSelector.cc:116
s_TrigResultsType
static const edm::TypeID s_TrigResultsType(typeid(edm::TriggerResults))
edm::Hash
Definition: Hash.h:43
b
double b
Definition: hdecay.h:118
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet::exists
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: ParameterSet.cc:681
edm::ParameterSet
Definition: ParameterSet.h:47
a
double a
Definition: hdecay.h:119
edm::detail::TriggerResultsBasedEventSelector::wantEvent
bool wantEvent(EventForOutput const &e)
Definition: TriggerResultsBasedEventSelector.cc:148
edm::ParameterSet::addParameter
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:135
edm::detail::TriggerResultsBasedEventSelector
Definition: TriggerResultsBasedEventSelector.h:47
edm::test::run_all_output_module_tests
void run_all_output_module_tests()
Definition: TriggerResultsBasedEventSelector.cc:72
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
edm::detail::TriggerResultsBasedEventSelector::setup
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: TriggerResultsBasedEventSelector.cc:118
edm::detail::configureEventSelector
bool configureEventSelector(edm::ParameterSet const &iPSet, std::string const &iProcessName, std::vector< std::string > const &iAllTriggerNames, edm::detail::TriggerResultsBasedEventSelector &oSelector, ConsumesCollector &&iC)
Definition: TriggerResultsBasedEventSelector.cc:80
edm::EventForOutput
Definition: EventForOutput.h:50
edm::TypeID
Definition: TypeID.h:22
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::detail::registerProperSelectionInfo
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)
Definition: TriggerResultsBasedEventSelector.cc:163
edm::match
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)
Definition: BranchDescription.cc:351
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
MatrixUtil.remove
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:219
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Skims_PA_cff.paths
paths
Definition: Skims_PA_cff.py:18
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
genParticles_cff.map
map
Definition: genParticles_cff.py:11
ParameterSet.h
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
edm::TriggerResults
Definition: TriggerResults.h:35
edm::ParameterSet::empty
bool empty() const
Definition: ParameterSet.h:201
TriggerResultsBasedEventSelector.h