CMS 3D CMS Logo

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_(ps.getUntrackedParameter<edm::InputTag>("triggerResults", edm::InputTag("TriggerResults","","HLT"))),
16  triggerEventTag_(ps.getUntrackedParameter<edm::InputTag>("triggerEvent", edm::InputTag("hltTriggerSummaryAOD","","HLT"))),
17  triggerResultsToken_(consumes<edm::TriggerResults>(triggerResultsTag_)),
18  triggerEventToken_(consumes<trigger::TriggerEvent>(triggerEventTag_))
19 {
20 }
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 (auto path: pathList) {
32  if (!hltPathsOfInterest_.empty()) {
33  int nmatch = 0;
34  for (auto kt: hltPathsOfInterest_)
35  nmatch += TPRegexp(kt).Match(path);
36  if (!nmatch) continue;
37  }
38  const unsigned int triggerIndex(hltConfig_.triggerIndex(path));
39  // abort on invalid trigger name
40  if (triggerIndex >= n) {
41  edm::LogError("HLTPathSelector") << "path: " << path << " - not found!";
42  continue;
43  }
44  hltPathsMap_[path] = triggerIndex;
45  }
46  }
47  else
48  edm::LogError("HLTPathSelector")
49  << " config extraction failure with process name "
50  << processName_;
51 }
53  // get event products
54  edm::Handle<edm::TriggerResults> triggerResultsHandle_;
55  iEvent.getByToken(triggerResultsToken_, triggerResultsHandle_);
56  if (!triggerResultsHandle_.isValid()) {
57  edm::LogError("HLTPathSelector") << "Error in getting TriggerResults product from Event!";
58  return false;
59  }
60 
61  edm::Handle<trigger::TriggerEvent> triggerEventHandle_;
62  iEvent.getByToken(triggerEventToken_, triggerEventHandle_);
63  if (!triggerEventHandle_.isValid()) {
64  edm::LogError("HLTPathSelector") << "Error in getting TriggerEvent product from Event!";
65  return false;
66  }
67  // sanity check
68  assert(triggerResultsHandle_->size() == hltConfig_.size());
69 
70  int flag = 0;
71  for (auto const& it: hltPathsMap_) {
72  const std::string path(it.first);
73  const unsigned int triggerIndex(it.second);
74  assert(triggerIndex == iEvent.triggerNames(*triggerResultsHandle_).triggerIndex(path));
75 
76  // Results from TriggerResults product
77  if (verbose_)
78  edm::LogInfo("HLTPathSelector")
79  << " Trigger path <" << path << "> status:"
80  << " WasRun=" << triggerResultsHandle_->wasrun(triggerIndex)
81  << " Accept=" << triggerResultsHandle_->accept(triggerIndex)
82  << " Error=" << triggerResultsHandle_->error(triggerIndex);
83 
84  if (triggerResultsHandle_->wasrun(triggerIndex) && triggerResultsHandle_->accept(triggerIndex)) {
85  ++flag;
86  if (tmap_.find(path) == tmap_.end())
87  tmap_[path] = 1;
88  else
89  tmap_[path]++;
90  }
91  }
92  if (flag > 0) return true;
93  return false;
94 }
96 
97  edm::LogInfo("HLTPathSelector")
98  << setw(32) << "HLT Path"
99  << setw(9) << "ACCEPT";
100  for (auto const& jt: tmap_)
101  edm::LogInfo("HLTPathSelector")
102  << setw(9) << jt.second;
103 }
104 // 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.
bool wasrun() const
Was at least one path run?
HLTConfigProvider hltConfig_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
std::map< std::string, unsigned int > hltPathsMap_
bool accept() const
Has at least one path accepted the event?
const std::vector< std::string > & triggerNames() const
names of trigger paths
bool filter(edm::Event &, edm::EventSetup const &) override
const edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
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
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
unsigned int triggerIndex(std::string const &name) const
Definition: TriggerNames.cc:24
unsigned int size() const
Get number of paths stored.
void beginRun(edm::Run const &, edm::EventSetup const &) override
bool error() const
Has any path encountered an error (exception)
bool isValid() const
Definition: HandleBase.h:74
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 &)
HLT enums.
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:256
Definition: Run.h:45