CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HLTPathSelector.cc
Go to the documentation of this file.
1 #include <cassert>
2 
7 
8 using namespace std;
9 using namespace edm;
10 
12  : verbose_(ps.getUntrackedParameter<bool>("verbose", false)),
13  processName_(ps.getParameter<std::string>("processName")),
14  hltPathsOfInterest_(ps.getParameter<std::vector<std::string> >("hltPathsOfInterest")),
15  triggerResultsTag_(
16  ps.getUntrackedParameter<edm::InputTag>("triggerResults", edm::InputTag("TriggerResults", "", "HLT"))),
17  triggerEventTag_(
18  ps.getUntrackedParameter<edm::InputTag>("triggerEvent", edm::InputTag("hltTriggerSummaryAOD", "", "HLT"))),
19  triggerResultsToken_(consumes<edm::TriggerResults>(triggerResultsTag_)),
20  triggerEventToken_(consumes<trigger::TriggerEvent>(triggerEventTag_)) {}
21 void HLTPathSelector::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
22  bool changed(true);
23  if (hltConfig_.init(iRun, iSetup, processName_, changed)) {
24  if (changed) {
25  edm::LogInfo("HLTPathSelector") << "HLT initialised";
26  hltConfig_.dump("PrescaleTable");
27  }
28  hltPathsMap_.clear();
29  const unsigned int n(hltConfig_.size());
30  const std::vector<std::string>& pathList = hltConfig_.triggerNames();
31  for (const auto& path : pathList) {
32  if (!hltPathsOfInterest_.empty()) {
33  int nmatch = 0;
34  for (const auto& kt : hltPathsOfInterest_)
35  nmatch += TPRegexp(kt).Match(path);
36  if (!nmatch)
37  continue;
38  }
39  const unsigned int triggerIndex(hltConfig_.triggerIndex(path));
40  // abort on invalid trigger name
41  if (triggerIndex >= n) {
42  edm::LogError("HLTPathSelector") << "path: " << path << " - not found!";
43  continue;
44  }
45  hltPathsMap_[path] = triggerIndex;
46  }
47  } else
48  edm::LogError("HLTPathSelector") << " config extraction failure with process name " << processName_;
49 }
51  // get event products
52  edm::Handle<edm::TriggerResults> triggerResultsHandle_;
53  iEvent.getByToken(triggerResultsToken_, triggerResultsHandle_);
54  if (!triggerResultsHandle_.isValid()) {
55  edm::LogError("HLTPathSelector") << "Error in getting TriggerResults product from Event!";
56  return false;
57  }
58 
59  edm::Handle<trigger::TriggerEvent> triggerEventHandle_;
60  iEvent.getByToken(triggerEventToken_, triggerEventHandle_);
61  if (!triggerEventHandle_.isValid()) {
62  edm::LogError("HLTPathSelector") << "Error in getting TriggerEvent product from Event!";
63  return false;
64  }
65  // sanity check
66  assert(triggerResultsHandle_->size() == hltConfig_.size());
67 
68  int flag = 0;
69  for (auto const& it : hltPathsMap_) {
70  const std::string path(it.first);
71  const unsigned int triggerIndex(it.second);
72  assert(triggerIndex == iEvent.triggerNames(*triggerResultsHandle_).triggerIndex(path));
73 
74  // Results from TriggerResults product
75  if (verbose_)
76  edm::LogInfo("HLTPathSelector") << " Trigger path <" << path << "> status:"
77  << " WasRun=" << triggerResultsHandle_->wasrun(triggerIndex)
78  << " Accept=" << triggerResultsHandle_->accept(triggerIndex)
79  << " Error=" << triggerResultsHandle_->error(triggerIndex);
80 
81  if (triggerResultsHandle_->wasrun(triggerIndex) && triggerResultsHandle_->accept(triggerIndex)) {
82  ++flag;
83  if (tmap_.find(path) == tmap_.end())
84  tmap_[path] = 1;
85  else
86  tmap_[path]++;
87  }
88  }
89  if (flag > 0)
90  return true;
91  return false;
92 }
94  edm::LogInfo("HLTPathSelector") << setw(32) << "HLT Path" << setw(9) << "ACCEPT";
95  for (auto const& jt : tmap_)
96  edm::LogInfo("HLTPathSelector") << setw(9) << jt.second;
97 }
98 // Define this as a plug-in
unsigned int size() const
number of trigger paths in trigger table
void dump(const std::string &what) const
Dumping config info to cout.
HLTConfigProvider hltConfig_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
std::map< std::string, unsigned int > hltPathsMap_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const std::vector< std::string > & triggerNames() const
names of trigger paths
unsigned int triggerIndex(std::string_view name) const
Definition: TriggerNames.cc:52
bool filter(edm::Event &, edm::EventSetup const &) override
const edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
Log< level::Error, false > LogError
assert(be >=bs)
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:275
unsigned int triggerIndex(const std::string &triggerName) const
slot position of trigger path in trigger table (0 to size-1)
const std::vector< std::string > hltPathsOfInterest_
int iEvent
Definition: GenABIO.cc:224
void beginRun(edm::Run const &, edm::EventSetup const &) override
bool isValid() const
Definition: HandleBase.h:70
Log< level::Info, false > LogInfo
std::map< std::string, int > tmap_
const edm::EDGetTokenT< trigger::TriggerEvent > triggerEventToken_
std::string processName_
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
HLTPathSelector(const edm::ParameterSet &)
Definition: Run.h:45