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 
12 #include <vector>
13 #include <string>
14 #include <iostream>
15 #include <iomanip>
16 #include <boost/foreach.hpp>
17 
25 
26 // needed for trigger bits from EventSetup as in ALCARECO paths
29 
30 
32 
33 //
34 // constructors and destructor
35 //
37  inputTag_ (iConfig.getParameter<edm::InputTag> ("TriggerResultsTag")),
38  triggerNamesID_ (),
39  andOr_ (iConfig.getParameter<bool> ("andOr")),
40  throw_ (iConfig.getParameter<bool> ("throw")),
41  eventSetupPathsKey_(iConfig.getParameter<std::string>("eventSetupPathsKey")),
42  watchAlCaRecoTriggerBitsRcd_(0),
43  HLTPatterns_ (iConfig.getParameter<std::vector<std::string> >("HLTPaths")),
44  HLTPathsByName_(),
45  HLTPathsByIndex_()
46 {
47  // names and slot numbers are computed during the event loop,
48  // as they need to access the TriggerNames object via the TriggerResults
49 
50  if (eventSetupPathsKey_.size()) {
51  // If paths come from eventsetup, we must watch for IOV changes.
52  if (!HLTPatterns_.empty()) {
53  // We do not want double trigger path setting, so throw!
54  throw cms::Exception("Configuration")
55  << " HLTHighLevel instance: "<< iConfig.getParameter<std::string>("@module_label")
56  << "\n configured with " << HLTPatterns_.size() << " HLTPaths and\n"
57  << " eventSetupPathsKey " << eventSetupPathsKey_ << ", choose either of them.";
58  }
60  }
61 }
62 
64 {
65  delete watchAlCaRecoTriggerBitsRcd_; // safe on null pointer...
66 }
67 
68 //
69 // member functions
70 //
71 
72 // Initialize the internal trigger path representation (names and indices) from the
73 // patterns specified in the configuration.
74 // This needs to be called once at startup, whenever the trigger table has changed
75 // or in case of paths from eventsetup and IOV changed
77  const edm::EventSetup& iSetup,
78  const edm::TriggerNames & triggerNames )
79 {
80  unsigned int n;
81 
82  // clean up old data
83  HLTPathsByName_.clear();
84  HLTPathsByIndex_.clear();
85 
86  // Overwrite paths from EventSetup via AlCaRecoTriggerBitsRcd if configured:
87  if (eventSetupPathsKey_.size()) {
89  }
90 
91  if (HLTPatterns_.empty()) {
92  // for empty input vector, default to all HLT trigger paths
93  n = result.size();
94  HLTPathsByName_.resize(n);
95  HLTPathsByIndex_.resize(n);
96  for (unsigned int i = 0; i < n; ++i) {
97  HLTPathsByName_[i] = triggerNames.triggerName(i);
98  HLTPathsByIndex_[i] = i;
99  }
100  } else {
101  // otherwise, expand wildcards in trigger names...
102  BOOST_FOREACH(const std::string & pattern, HLTPatterns_) {
103  if (edm::is_glob(pattern)) {
104  // found a glob pattern, expand it
105  std::vector< std::vector<std::string>::const_iterator > matches = edm::regexMatch(triggerNames.triggerNames(), pattern);
106  if (matches.empty()) {
107  // pattern does not match any trigger paths
108  if (throw_)
109  throw cms::Exception("Configuration") << "requested pattern \"" << pattern << "\" does not match any HLT paths";
110  else
111  edm::LogInfo("Configuration") << "requested pattern \"" << pattern << "\" does not match any HLT paths";
112  } else {
113  // store the matching patterns
114  BOOST_FOREACH(std::vector<std::string>::const_iterator match, matches)
115  HLTPathsByName_.push_back(*match);
116  }
117  } else {
118  // found a trigger name, just copy it
119  HLTPathsByName_.push_back(pattern);
120  }
121  }
122  n = HLTPathsByName_.size();
123 
124  // ...and get hold of trigger indices
125  bool valid = false;
126  HLTPathsByIndex_.resize(n);
127  for (unsigned int i = 0; i < HLTPathsByName_.size(); i++) {
128  HLTPathsByIndex_[i] = triggerNames.triggerIndex(HLTPathsByName_[i]);
129  if (HLTPathsByIndex_[i] < result.size()) {
130  valid = true;
131  } else {
132  // trigger path not found
133  HLTPathsByIndex_[i] = (unsigned int) -1;
134  if (throw_)
135  throw cms::Exception("Configuration") << "requested HLT path \"" << HLTPathsByName_[i] << "\" does not exist";
136  else
137  edm::LogInfo("Configuration") << "requested HLT path \"" << HLTPathsByName_[i] << "\" does not exist";
138  }
139  }
140 
141  if (not valid) {
142  // no point in throwing - if requested, it should have already happened
143  edm::LogWarning("Configuration") << "none of the requested paths and pattern match any HLT path - no events will be selected";
144  }
145 
146  }
147 
148  // report on what is finally used
149  LogDebug("HLTHighLevel") << "HLT trigger paths: " + inputTag_.encode()
150  << " - Number of paths: " << n
151  << " - andOr mode: " << andOr_
152  << " - throw mode: " << throw_;
153 
154  LogTrace("HLTHighLevel") << "The HLT trigger paths (# index name):";
155  for (unsigned int i = 0; i < n; ++i)
156  if (HLTPathsByIndex_[i] == (unsigned int) -1)
157  LogTrace("HLTHighLevel") << " n/a " << HLTPathsByName_[i];
158  else
159  LogTrace("HLTHighLevel") << " " << std::setw(4) << HLTPathsByIndex_[i] << " " << HLTPathsByName_[i];
160 
161 }
162 
163 // ------------ getting paths from EventSetup ------------
164 std::vector<std::string>
165 HLTHighLevel::pathsFromSetup(const std::string &key, const edm::EventSetup &iSetup) const
166 {
167  // Get map of strings to concatenated list of names of HLT paths from EventSetup:
169  iSetup.get<AlCaRecoTriggerBitsRcd>().get(triggerBits);
170  typedef std::map<std::string, std::string> TriggerMap;
171  const TriggerMap &triggerMap = triggerBits->m_alcarecoToTrig;
172 
173  TriggerMap::const_iterator listIter = triggerMap.find(key);
174  if (listIter == triggerMap.end()) {
175  throw cms::Exception("Configuration")
176  << " HLTHighLevel [instance: " << moduleLabel() << " - path: " << pathName()
177  << "]: No triggerList with key " << key << " in AlCaRecoTriggerBitsRcd";
178  }
179 
180  // We must avoid a map<string,vector<string> > in DB for performance reason,
181  // so the paths are mapped into one string that we have to decompose:
182  return triggerBits->decompose(listIter->second);
183 }
184 
185 // ------------ method called to produce the data ------------
186  bool
188 {
189  using namespace std;
190  using namespace edm;
191 
192  // get hold of TriggerResults Object
194  iEvent.getByLabel(inputTag_, trh);
195  if (trh.isValid()) {
196  LogDebug("HLTHighLevel") << "TriggerResults found, number of HLT paths: " << trh->size();
197  } else {
198  LogError("HLTHighLevel") << "TriggerResults product " << inputTag_.encode() << " not found - returning result=false!";
199  return false;
200  }
201 
202  // init the TriggerNames with the TriggerResults
203  const edm::TriggerNames & triggerNames = iEvent.triggerNames(*trh);
204  bool config_changed = false;
205  if (triggerNamesID_ != triggerNames.parameterSetID()) {
206  triggerNamesID_ = triggerNames.parameterSetID();
207  config_changed = true;
208  }
209 
210  // (re)run the initialization stuff if
211  // - this is the first event
212  // - or the HLT table has changed
213  // - or selected trigger bits come from AlCaRecoTriggerBitsRcd and these changed
214  if (config_changed or (watchAlCaRecoTriggerBitsRcd_ and watchAlCaRecoTriggerBitsRcd_->check(iSetup))) {
215  this->init(*trh, iSetup, triggerNames);
216  }
217  unsigned int n = HLTPathsByName_.size();
218  unsigned int nbad = 0;
219  unsigned int fired = 0;
220 
221  // count invalid and fired triggers
222  for (unsigned int i = 0; i < n; i++)
223  if (HLTPathsByIndex_[i] == (unsigned int) -1)
224  ++nbad;
225  else if (trh->accept(HLTPathsByIndex_[i]))
226  ++fired;
227 
228  if ((nbad > 0) and (config_changed or throw_)) {
229  // only generate the error message if it's actually going to be used
230  std::string message;
231 
232  for (unsigned int i = 0; i < n; i++)
233  if (HLTPathsByIndex_[i] == (unsigned int) -1)
234  message += HLTPathsByName_[i] + " ";
235 
236  if (config_changed) {
237  LogTrace("HLTHighLevel")
238  << " HLTHighLevel [instance: " << moduleLabel()
239  << " - path: " << pathName()
240  << "] configured with " << nbad
241  << "/" << n
242  << " unknown HLT path names: " << message;
243  }
244 
245  if (throw_) {
246  throw cms::Exception("Configuration")
247  << " HLTHighLevel [instance: " << moduleLabel()
248  << " - path: " << pathName()
249  << "] configured with " << nbad
250  << "/" << n
251  << " unknown HLT path names: " << message;
252  }
253  }
254 
255  // Boolean filter result (always at least one trigger)
256  const bool accept( (fired > 0) and ( andOr_ or (fired == n-nbad) ) );
257  LogDebug("HLTHighLevel") << "Accept = " << std::boolalpha << accept;
258 
259  return accept;
260 }
261 
262 
263 std::string const & HLTHighLevel::pathName() const {
264  return * currentContext()->pathName();
265 }
266 
267 std::string const & HLTHighLevel::moduleLabel() const {
268  return * currentContext()->moduleLabel();
269 }
#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:199
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
std::string const * moduleLabel() const
bool is_glob(std::string const &pattern)
Definition: RegexMatch.cc:18
bool andOr_
false = and-mode (all requested triggers), true = or-mode (at least one)
Definition: HLTHighLevel.h:64
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:22
Strings const & triggerNames() const
Definition: TriggerNames.cc:24
std::string encode() const
Definition: InputTag.cc:72
std::string const & moduleLabel() const
std::vector< std::string > pathsFromSetup(const std::string &key, const edm::EventSetup &iSetup) const
get HLTPaths with key &#39;key&#39; from EventSetup (AlCaRecoTriggerBitsRcd)
int iEvent
Definition: GenABIO.cc:243
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:85
edm::ParameterSetID triggerNamesID_
HLT trigger names.
Definition: HLTHighLevel.h:61
void init(const edm::TriggerResults &results, const edm::EventSetup &iSetup, const edm::TriggerNames &triggerNames)
initialize the trigger conditions (call this if the trigger paths have changed)
Definition: HLTHighLevel.cc:76
std::vector< std::vector< std::string >::const_iterator > regexMatch(std::vector< std::string > const &strings, boost::regex const &regexp)
Definition: RegexMatch.cc:30
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
#define LogTrace(id)
const std::string eventSetupPathsKey_
not empty =&gt; use read paths from AlCaRecoTriggerBitsRcd via this key
Definition: HLTHighLevel.h:74
std::string const & triggerName(unsigned int index) const
Definition: TriggerNames.cc:27
const T & get() const
Definition: EventSetup.h:55
std::string const & pathName() const
stolen from HLTFilter
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:59
virtual bool filter(edm::Event &, const edm::EventSetup &)
bool throw_
throw on any requested trigger being unknown
Definition: HLTHighLevel.h:67
HLTHighLevel(const edm::ParameterSet &)
Definition: HLTHighLevel.cc:36
list key
Definition: combine.py:13
std::vector< std::string > HLTPathsByName_
list of required HLT triggers by HLT name
Definition: HLTHighLevel.h:82
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
std::vector< std::string > HLTPatterns_
input patterns that will be expanded into trigger names
Definition: HLTHighLevel.h:79
std::string const * pathName() const
edm::InputTag inputTag_
HLT TriggerResults EDProduct.
Definition: HLTHighLevel.h:58
edm::ESWatcher< AlCaRecoTriggerBitsRcd > * watchAlCaRecoTriggerBitsRcd_
Watcher to be created and used if &#39;eventSetupPathsKey_&#39; non empty:
Definition: HLTHighLevel.h:76
CurrentProcessingContext const * currentContext() const
Definition: EDFilter.cc:115