CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTHighLevel.cc
Go to the documentation of this file.
1 
10 #include <vector>
11 #include <string>
12 #include <iostream>
13 #include <iomanip>
14 #include <boost/foreach.hpp>
15 
27 
28 // needed for trigger bits from EventSetup as in ALCARECO paths
31 
32 
35 
36 //
37 // constructors and destructor
38 //
40  inputTag_ (iConfig.getParameter<edm::InputTag> ("TriggerResultsTag")),
41  inputToken_ (consumes<edm::TriggerResults>(inputTag_)),
42  triggerNamesID_ (),
43  andOr_ (iConfig.getParameter<bool> ("andOr")),
44  throw_ (iConfig.getParameter<bool> ("throw")),
45  eventSetupPathsKey_(iConfig.getParameter<std::string>("eventSetupPathsKey")),
46  watchAlCaRecoTriggerBitsRcd_(0),
47  HLTPatterns_ (iConfig.getParameter<std::vector<std::string> >("HLTPaths")),
48  HLTPathsByName_(),
49  HLTPathsByIndex_()
50 {
51  // names and slot numbers are computed during the event loop,
52  // as they need to access the TriggerNames object via the TriggerResults
53 
54  if (eventSetupPathsKey_.size()) {
55  // If paths come from eventsetup, we must watch for IOV changes.
56  if (!HLTPatterns_.empty()) {
57  // We do not want double trigger path setting, so throw!
58  throw cms::Exception("Configuration")
59  << " HLTHighLevel instance: "<< iConfig.getParameter<std::string>("@module_label")
60  << "\n configured with " << HLTPatterns_.size() << " HLTPaths and\n"
61  << " eventSetupPathsKey " << eventSetupPathsKey_ << ", choose either of them.";
62  }
64  }
65 }
66 
68 {
69  delete watchAlCaRecoTriggerBitsRcd_; // safe on null pointer...
70 }
71 
72 //
73 // member functions
74 //
75 
76 void
79  desc.add<edm::InputTag>("TriggerResultsTag",edm::InputTag("TriggerResults","","HLT"));
80  std::vector<std::string> hltPaths(0);
81  // # provide list of HLT paths (or patterns) you want
82  desc.add<std::vector<std::string> >("HLTPaths",hltPaths);
83  // # not empty => use read paths from AlCaRecoTriggerBitsRcd via this key
84  desc.add<std::string>("eventSetupPathsKey","");
85  // # how to deal with multiple triggers: True (OR) accept if ANY is true, False (AND) accept if ALL are true
86  desc.add<bool>("andOr",true);
87  // # throw exception on unknown path names
88  desc.add<bool>("throw",true);
89  descriptions.add("hltHighLevel", desc);
90 }
91 
92 // Initialize the internal trigger path representation (names and indices) from the
93 // patterns specified in the configuration.
94 // This needs to be called once at startup, whenever the trigger table has changed
95 // or in case of paths from eventsetup and IOV changed
97  const edm::Event &event,
98  const edm::EventSetup& iSetup,
99  const edm::TriggerNames & triggerNames )
100 {
101  unsigned int n;
102 
103  // clean up old data
104  HLTPathsByName_.clear();
105  HLTPathsByIndex_.clear();
106 
107  // Overwrite paths from EventSetup via AlCaRecoTriggerBitsRcd if configured:
108  if (eventSetupPathsKey_.size()) {
109  HLTPatterns_ = this->pathsFromSetup(eventSetupPathsKey_, event, iSetup);
110  }
111 
112  if (HLTPatterns_.empty()) {
113  // for empty input vector, default to all HLT trigger paths
114  n = result.size();
115  HLTPathsByName_.resize(n);
116  HLTPathsByIndex_.resize(n);
117  for (unsigned int i = 0; i < n; ++i) {
118  HLTPathsByName_[i] = triggerNames.triggerName(i);
119  HLTPathsByIndex_[i] = i;
120  }
121  } else {
122  // otherwise, expand wildcards in trigger names...
123  BOOST_FOREACH(const std::string & pattern, HLTPatterns_) {
124  if (edm::is_glob(pattern)) {
125  // found a glob pattern, expand it
126  std::vector< std::vector<std::string>::const_iterator > matches = edm::regexMatch(triggerNames.triggerNames(), pattern);
127  if (matches.empty()) {
128  // pattern does not match any trigger paths
129  if (throw_)
130  throw cms::Exception("Configuration") << "requested pattern \"" << pattern << "\" does not match any HLT paths";
131  else
132  edm::LogInfo("Configuration") << "requested pattern \"" << pattern << "\" does not match any HLT paths";
133  } else {
134  // store the matching patterns
135  BOOST_FOREACH(std::vector<std::string>::const_iterator match, matches)
136  HLTPathsByName_.push_back(*match);
137  }
138  } else {
139  // found a trigger name, just copy it
140  HLTPathsByName_.push_back(pattern);
141  }
142  }
143  n = HLTPathsByName_.size();
144 
145  // ...and get hold of trigger indices
146  bool valid = false;
147  HLTPathsByIndex_.resize(n);
148  for (unsigned int i = 0; i < HLTPathsByName_.size(); i++) {
149  HLTPathsByIndex_[i] = triggerNames.triggerIndex(HLTPathsByName_[i]);
150  if (HLTPathsByIndex_[i] < result.size()) {
151  valid = true;
152  } else {
153  // trigger path not found
154  HLTPathsByIndex_[i] = (unsigned int) -1;
155  if (throw_)
156  throw cms::Exception("Configuration") << "requested HLT path \"" << HLTPathsByName_[i] << "\" does not exist";
157  else
158  edm::LogInfo("Configuration") << "requested HLT path \"" << HLTPathsByName_[i] << "\" does not exist";
159  }
160  }
161 
162  if (not valid) {
163  // no point in throwing - if requested, it should have already happened
164  edm::LogWarning("Configuration") << "none of the requested paths and pattern match any HLT path - no events will be selected";
165  }
166 
167  }
168 
169  // report on what is finally used
170  LogDebug("HLTHighLevel") << "HLT trigger paths: " + inputTag_.encode()
171  << " - Number of paths: " << n
172  << " - andOr mode: " << andOr_
173  << " - throw mode: " << throw_;
174 
175  LogTrace("HLTHighLevel") << "The HLT trigger paths (# index name):";
176  for (unsigned int i = 0; i < n; ++i)
177  if (HLTPathsByIndex_[i] == (unsigned int) -1)
178  LogTrace("HLTHighLevel") << " n/a " << HLTPathsByName_[i];
179  else
180  LogTrace("HLTHighLevel") << " " << std::setw(4) << HLTPathsByIndex_[i] << " " << HLTPathsByName_[i];
181 
182 }
183 
184 // ------------ getting paths from EventSetup ------------
185 std::vector<std::string>
187 {
188  // Get map of strings to concatenated list of names of HLT paths from EventSetup:
190  iSetup.get<AlCaRecoTriggerBitsRcd>().get(triggerBits);
191  typedef std::map<std::string, std::string> TriggerMap;
192  const TriggerMap &triggerMap = triggerBits->m_alcarecoToTrig;
193 
194  TriggerMap::const_iterator listIter = triggerMap.find(key);
195  if (listIter == triggerMap.end()) {
196  throw cms::Exception("Configuration")
197  << " HLTHighLevel [instance: " << moduleLabel() << " - path: " << pathName(event)
198  << "]: No triggerList with key " << key << " in AlCaRecoTriggerBitsRcd";
199  }
200 
201  // We must avoid a map<string,vector<string> > in DB for performance reason,
202  // so the paths are mapped into one string that we have to decompose:
203  return triggerBits->decompose(listIter->second);
204 }
205 
206 // ------------ method called to produce the data ------------
207  bool
209 {
210  using namespace std;
211  using namespace edm;
212 
213  // get hold of TriggerResults Object
215  iEvent.getByToken(inputToken_, trh);
216  if (trh.isValid()) {
217  LogDebug("HLTHighLevel") << "TriggerResults found, number of HLT paths: " << trh->size();
218  } else {
219  LogError("HLTHighLevel") << "TriggerResults product " << inputTag_.encode() << " not found - returning result=false!";
220  return false;
221  }
222 
223  // init the TriggerNames with the TriggerResults
224  const edm::TriggerNames & triggerNames = iEvent.triggerNames(*trh);
225  bool config_changed = false;
226  if (triggerNamesID_ != triggerNames.parameterSetID()) {
227  triggerNamesID_ = triggerNames.parameterSetID();
228  config_changed = true;
229  }
230 
231  // (re)run the initialization stuff if
232  // - this is the first event
233  // - or the HLT table has changed
234  // - or selected trigger bits come from AlCaRecoTriggerBitsRcd and these changed
235  if (config_changed or (watchAlCaRecoTriggerBitsRcd_ and watchAlCaRecoTriggerBitsRcd_->check(iSetup))) {
236  this->init(*trh, iEvent, iSetup, triggerNames);
237  }
238  unsigned int n = HLTPathsByName_.size();
239  unsigned int nbad = 0;
240  unsigned int fired = 0;
241 
242  // count invalid and fired triggers
243  for (unsigned int i = 0; i < n; i++)
244  if (HLTPathsByIndex_[i] == (unsigned int) -1)
245  ++nbad;
246  else if (trh->accept(HLTPathsByIndex_[i]))
247  ++fired;
248 
249  if ((nbad > 0) and (config_changed or throw_)) {
250  // only generate the error message if it's actually going to be used
252 
253  for (unsigned int i = 0; i < n; i++)
254  if (HLTPathsByIndex_[i] == (unsigned int) -1)
255  message += HLTPathsByName_[i] + " ";
256 
257  if (config_changed) {
258  LogTrace("HLTHighLevel")
259  << " HLTHighLevel [instance: " << moduleLabel()
260  << " - path: " << pathName(iEvent)
261  << "] configured with " << nbad
262  << "/" << n
263  << " unknown HLT path names: " << message;
264  }
265 
266  if (throw_) {
267  throw cms::Exception("Configuration")
268  << " HLTHighLevel [instance: " << moduleLabel()
269  << " - path: " << pathName(iEvent)
270  << "] configured with " << nbad
271  << "/" << n
272  << " unknown HLT path names: " << message;
273  }
274  }
275 
276  // Boolean filter result (always at least one trigger)
277  const bool accept( (fired > 0) and ( andOr_ or (fired == n-nbad) ) );
278  LogDebug("HLTHighLevel") << "Accept = " << std::boolalpha << accept;
279 
280  return accept;
281 }
282 
283 
285  return event.moduleCallingContext()->placeInPathContext()->pathContext()->pathName();
286 }
287 
289  return moduleDescription().moduleLabel();
290 }
#define LogDebug(id)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const
Definition: Event.cc:213
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
void init(const edm::TriggerResults &results, const edm::Event &, const edm::EventSetup &iSetup, const edm::TriggerNames &triggerNames)
initialize the trigger conditions (call this if the trigger paths have changed)
Definition: HLTHighLevel.cc:96
bool is_glob(std::string const &pattern)
Definition: RegexMatch.cc:18
list pattern
Definition: chain.py:104
bool andOr_
false = and-mode (all requested triggers), true = or-mode (at least one)
Definition: HLTHighLevel.h:68
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:25
std::string const & moduleLabel() const
Strings const & triggerNames() const
Definition: TriggerNames.cc:24
std::string encode() const
Definition: InputTag.cc:164
std::string const & moduleLabel() const
int iEvent
Definition: GenABIO.cc:230
unsigned int triggerIndex(std::string const &name) const
Definition: TriggerNames.cc:32
unsigned int size() const
Get number of paths stored.
tuple result
Definition: query.py:137
std::vector< unsigned int > HLTPathsByIndex_
list of required HLT triggers by HLT index
Definition: HLTHighLevel.h:89
edm::ParameterSetID triggerNamesID_
HLT trigger names.
Definition: HLTHighLevel.h:65
std::vector< std::vector< std::string >::const_iterator > regexMatch(std::vector< std::string > const &strings, boost::regex const &regexp)
Definition: RegexMatch.cc:30
ParameterDescriptionBase * add(U const &iLabel, T const &value)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
#define LogTrace(id)
edm::EDGetTokenT< edm::TriggerResults > inputToken_
Definition: HLTHighLevel.h:62
const std::string eventSetupPathsKey_
not empty =&gt; use read paths from AlCaRecoTriggerBitsRcd via this key
Definition: HLTHighLevel.h:78
std::string const & triggerName(unsigned int index) const
Definition: TriggerNames.cc:27
const T & get() const
Definition: EventSetup.h:55
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
virtual bool filter(edm::Event &, const edm::EventSetup &)
std::vector< std::string > pathsFromSetup(const std::string &key, const edm::Event &, const edm::EventSetup &iSetup) const
get HLTPaths with key &#39;key&#39; from EventSetup (AlCaRecoTriggerBitsRcd)
bool throw_
throw on any requested trigger being unknown
Definition: HLTHighLevel.h:71
HLTHighLevel(const edm::ParameterSet &)
Definition: HLTHighLevel.cc:39
ModuleDescription const & moduleDescription() const
Definition: EDFilter.h:52
std::string const & pathName(const edm::Event &) const
stolen from HLTFilter
std::vector< std::string > HLTPathsByName_
list of required HLT triggers by HLT name
Definition: HLTHighLevel.h:86
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: HLTHighLevel.cc:77
std::vector< std::string > HLTPatterns_
input patterns that will be expanded into trigger names
Definition: HLTHighLevel.h:83
edm::InputTag inputTag_
HLT TriggerResults EDProduct.
Definition: HLTHighLevel.h:61
edm::ESWatcher< AlCaRecoTriggerBitsRcd > * watchAlCaRecoTriggerBitsRcd_
Watcher to be created and used if &#39;eventSetupPathsKey_&#39; non empty:
Definition: HLTHighLevel.h:80