4 #include "boost/format.hpp"
5 #include "boost/lexical_cast.hpp"
6 #include "FWCore/Framework/interface/Event.h"
7 #include "FWCore/Framework/interface/EventSetup.h"
8 #include "FWCore/Framework/interface/MakerMacros.h"
9 #include "FWCore/ParameterSet/interface/ParameterSet.h"
10 #include "FWCore/Common/interface/TriggerNames.h"
11 #include "FWCore/Utilities/interface/InputTag.h"
12 #include "DataFormats/Common/interface/Handle.h"
13 #include "DataFormats/Common/interface/View.h"
14 #include "DataFormats/Common/interface/ValueMap.h"
15 #include "DataFormats/Common/interface/TriggerResults.h"
16 #include "DataFormats/PatCandidates/interface/TriggerEvent.h"
17 #include "PhysicsTools/PatUtils/interface/TriggerHelper.h"
25 #if CMSSW_MAJOR_VERSION >= 7
29 #include "DataFormats/PatCandidates/interface/PackedTriggerPrescales.h"
32 #if CMSSW_MAJOR_VERSION >= 8
33 #include "DataFormats/L1TGlobal/interface/GlobalAlgBlk.h"
38 : input_(config.getParameter<
edm::InputTag>(
"input")),
39 branch_(config.getParameter<
std::string>(
"branch")),
40 include_if_fired_(config.getParameter<bool>(
"includeAcceptedOnly")),
41 save_strings_(config.getParameter<bool>(
"saveStrings")),
42 split_version_(config.getParameter<bool>(
"splitVersion")),
43 input_is_standalone_(config.getParameter<bool>(
"inputIsStandAlone")),
44 input_prescales_(config.getParameter<
edm::InputTag>(
"inputPrescales")),
45 hlt_process_(config.getParameter<
std::string>(
"hltProcess")),
46 prescale_fallback_(config.getParameter<bool>(
"prescaleFallback"))
48 if(!input_is_standalone_){
49 consumes<pat::TriggerEvent>(input_);
51 consumes<edm::TriggerResults>(input_);
53 #if CMSSW_MAJOR_VERSION >= 7
54 consumes<pat::PackedTriggerPrescales>(input_prescales_);
56 #if CMSSW_MAJOR_VERSION >= 8
57 if (prescale_fallback_) {
58 consumes<BXVector<GlobalAlgBlk>>(edm::InputTag(
"gtStage2Digis"));
61 paths_ =
new std::vector<ic::TriggerPath>();
71 void ICTriggerPathProducer::produce(edm::Event& event,
72 const edm::EventSetup& setup) {
75 if (!input_is_standalone_) {
76 edm::Handle<pat::TriggerEvent> trig_handle;
77 event.getByLabel(input_, trig_handle);
78 std::vector<pat::TriggerPath>
const* paths = trig_handle->paths();
79 paths_->reserve(paths->size());
80 for (
unsigned i = 0; i < paths->size(); ++i) {
81 pat::TriggerPath
const& src = paths->at(i);
82 if (!src.wasAccept() && include_if_fired_)
continue;
87 std::string name = src.name();
88 SetNameInfo(name, &dest);
91 edm::Handle<edm::TriggerResults> trigres_handle;
92 event.getByLabel(input_, trigres_handle);
94 #if CMSSW_MAJOR_VERSION >= 7
95 edm::Handle<pat::PackedTriggerPrescales> prescales_handle;
96 event.getByLabel(input_prescales_, prescales_handle);
99 #if CMSSW_MAJOR_VERSION >= 8
100 edm::Handle<BXVector<GlobalAlgBlk>> l1algo_handle;
101 if (prescale_fallback_) {
102 event.getByLabel(edm::InputTag(
"gtStage2Digis"), l1algo_handle);
106 edm::TriggerNames
const& names =
event.triggerNames(*trigres_handle);
107 paths_->reserve(trigres_handle->size());
108 for (
unsigned int i = 0, n = trigres_handle->size(); i < n; ++i) {
109 if (!trigres_handle->accept(i) && include_if_fired_)
continue;
113 #if CMSSW_MAJOR_VERSION >= 7
114 dest.
set_prescale(prescales_handle->getPrescaleForIndex(i));
115 #if CMSSW_MAJOR_VERSION >= 8
116 if (prescale_fallback_) {
117 unsigned column = l1algo_handle->at(0, 0).getPreScColumn();
118 unsigned other_prescale = hlt_config_.prescaleValue(column, names.triggerName(i));
128 std::string name = names.triggerName(i);
129 SetNameInfo(name, &dest);
134 void ICTriggerPathProducer::SetNameInfo(std::string name,
136 if (split_version_) {
137 std::size_t v_pos = name.find_last_of(
'v');
138 if (v_pos != std::string::npos) {
139 std::string post_v = name.substr(v_pos+1);
140 std::string pre_v = name.substr(0, v_pos+1);
142 unsigned v = boost::lexical_cast<
unsigned>(post_v);
146 catch(boost::bad_lexical_cast
const&
e) {
154 if (!observed_paths_.count(name)) {
155 observed_paths_[name] = hash;
161 void ICTriggerPathProducer::beginRun(edm::Run
const& run,
162 edm::EventSetup
const& es) {
164 bool res = hlt_config_.init(run, es, hlt_process_, changed);
166 throw std::runtime_error(
167 "HLTConfigProvider did not initialise correctly");
170 void ICTriggerPathProducer::beginJob() {
174 void ICTriggerPathProducer::endJob() {
177 if (!save_strings_) {
178 std::cout << std::string(78,
'-') <<
"\n";
179 std::cout << boost::format(
"%-56s %20s\n")
180 %
"HLT Paths" % std::string(
"Hash Summmary");
181 std::map<std::string, std::size_t>::const_iterator iter;
182 for (iter = observed_paths_.begin(); iter != observed_paths_.end();
185 std::cout << boost::format(
"%-56s| %020i\n") % iter->first % iter->second;
void set_name(std::string const &name)
The trigger path name.
void set_prescale(unsigned const &prescale)
The trigger prescale.
uint64 CityHash64(const char *buf, size_t len)
Information on a trigger path, including accept, prescale and version information.
ICTriggerPathProducer(const edm::ParameterSet &)
void set_version(unsigned const &version)
The trigger version number.
DEFINE_FWK_MODULE(ICTriggerPathProducer)
void set_id(std::size_t const &id)
Unique identifier, usually a hash of the trigger name.
void set_accept(bool const &accept)
True if the trigger fired, false otherwise.
static void Add(std::size_t const &id, std::string const &str)