File indexing completed on 2023-03-17 10:57:25
0001 #include <cassert>
0002
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "FWCore/Common/interface/TriggerNames.h"
0005 #include "FWCore/Common/interface/TriggerResultsByName.h"
0006 #include "DQM/TrackingMonitorSource/interface/HLTPathSelector.h"
0007
0008 using namespace std;
0009 using namespace edm;
0010
0011 HLTPathSelector::HLTPathSelector(const edm::ParameterSet& ps)
0012 : verbose_(ps.getUntrackedParameter<bool>("verbose", false)),
0013 processName_(ps.getParameter<std::string>("processName")),
0014 hltPathsOfInterest_(ps.getParameter<std::vector<std::string> >("hltPathsOfInterest")),
0015 triggerResultsTag_(
0016 ps.getUntrackedParameter<edm::InputTag>("triggerResults", edm::InputTag("TriggerResults", "", "HLT"))),
0017 triggerEventTag_(
0018 ps.getUntrackedParameter<edm::InputTag>("triggerEvent", edm::InputTag("hltTriggerSummaryAOD", "", "HLT"))),
0019 triggerResultsToken_(consumes<edm::TriggerResults>(triggerResultsTag_)),
0020 triggerEventToken_(consumes<trigger::TriggerEvent>(triggerEventTag_)) {}
0021 void HLTPathSelector::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
0022 bool changed(true);
0023 if (hltConfig_.init(iRun, iSetup, processName_, changed)) {
0024 if (changed) {
0025 edm::LogInfo("HLTPathSelector") << "HLT initialised";
0026 hltConfig_.dump("PrescaleTable");
0027 }
0028 hltPathsMap_.clear();
0029 const unsigned int n(hltConfig_.size());
0030 const std::vector<std::string>& pathList = hltConfig_.triggerNames();
0031 for (const auto& path : pathList) {
0032 if (!hltPathsOfInterest_.empty()) {
0033 int nmatch = 0;
0034 for (const auto& kt : hltPathsOfInterest_)
0035 nmatch += TPRegexp(kt).Match(path);
0036 if (!nmatch)
0037 continue;
0038 }
0039 const unsigned int triggerIndex(hltConfig_.triggerIndex(path));
0040
0041 if (triggerIndex >= n) {
0042 edm::LogError("HLTPathSelector") << "path: " << path << " - not found!";
0043 continue;
0044 }
0045 hltPathsMap_[path] = triggerIndex;
0046 }
0047 } else
0048 edm::LogError("HLTPathSelector") << " config extraction failure with process name " << processName_;
0049 }
0050 bool HLTPathSelector::filter(edm::Event& iEvent, edm::EventSetup const& iSetup) {
0051
0052 edm::Handle<edm::TriggerResults> triggerResultsHandle_;
0053 iEvent.getByToken(triggerResultsToken_, triggerResultsHandle_);
0054 if (!triggerResultsHandle_.isValid()) {
0055 edm::LogError("HLTPathSelector") << "Error in getting TriggerResults product from Event!";
0056 return false;
0057 }
0058
0059 edm::Handle<trigger::TriggerEvent> triggerEventHandle_;
0060 iEvent.getByToken(triggerEventToken_, triggerEventHandle_);
0061 if (!triggerEventHandle_.isValid()) {
0062 edm::LogError("HLTPathSelector") << "Error in getting TriggerEvent product from Event!";
0063 return false;
0064 }
0065
0066 assert(triggerResultsHandle_->size() == hltConfig_.size());
0067
0068 int flag = 0;
0069 for (auto const& it : hltPathsMap_) {
0070 const std::string path(it.first);
0071 const unsigned int triggerIndex(it.second);
0072 assert(triggerIndex == iEvent.triggerNames(*triggerResultsHandle_).triggerIndex(path));
0073
0074
0075 if (verbose_)
0076 edm::LogInfo("HLTPathSelector") << " Trigger path <" << path << "> status:"
0077 << " WasRun=" << triggerResultsHandle_->wasrun(triggerIndex)
0078 << " Accept=" << triggerResultsHandle_->accept(triggerIndex)
0079 << " Error=" << triggerResultsHandle_->error(triggerIndex);
0080
0081 if (triggerResultsHandle_->wasrun(triggerIndex) && triggerResultsHandle_->accept(triggerIndex)) {
0082 ++flag;
0083 if (tmap_.find(path) == tmap_.end())
0084 tmap_[path] = 1;
0085 else
0086 tmap_[path]++;
0087 }
0088 }
0089 if (flag > 0)
0090 return true;
0091 return false;
0092 }
0093 void HLTPathSelector::endJob() {
0094 edm::LogInfo("HLTPathSelector") << setw(32) << "HLT Path" << setw(9) << "ACCEPT";
0095 for (auto const& jt : tmap_)
0096 edm::LogInfo("HLTPathSelector") << setw(9) << jt.second;
0097 }
0098
0099 #include "FWCore/Framework/interface/MakerMacros.h"
0100 DEFINE_FWK_MODULE(HLTPathSelector);