#include <string>
#include <vector>
#include "boost/format.hpp"
#include "boost/lexical_cast.hpp"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Common/interface/TriggerNames.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/Common/interface/View.h"
#include "DataFormats/Common/interface/ValueMap.h"
#include "DataFormats/Common/interface/TriggerResults.h"
#include "DataFormats/PatCandidates/interface/TriggerEvent.h"
#include "PhysicsTools/PatUtils/interface/TriggerHelper.h"
#if CMSSW_MAJOR_VERSION >= 7
#include "DataFormats/PatCandidates/interface/PackedTriggerPrescales.h"
#endif
#if CMSSW_MAJOR_VERSION >= 8
#include "DataFormats/L1TGlobal/interface/GlobalAlgBlk.h"
#endif
: input_(config.getParameter<
edm::InputTag>(
"input")),
branch_(config.getParameter<
std::string>(
"branch")),
include_if_fired_(config.getParameter<bool>("includeAcceptedOnly")),
save_strings_(config.getParameter<bool>("saveStrings")),
split_version_(config.getParameter<bool>("splitVersion")),
input_is_standalone_(config.getParameter<bool>("inputIsStandAlone")),
input_prescales_(config.getParameter<
edm::InputTag>(
"inputPrescales")),
hlt_process_(config.getParameter<
std::string>(
"hltProcess")),
prescale_fallback_(config.getParameter<bool>("prescaleFallback"))
{
if(!input_is_standalone_){
consumes<pat::TriggerEvent>(input_);
} else {
consumes<edm::TriggerResults>(input_);
}
#if CMSSW_MAJOR_VERSION >= 7
consumes<pat::PackedTriggerPrescales>(input_prescales_);
#endif
#if CMSSW_MAJOR_VERSION >= 8
if (prescale_fallback_) {
consumes<BXVector<GlobalAlgBlk>>(edm::InputTag("gtStage2Digis"));
}
#endif
paths_ = new std::vector<ic::TriggerPath>();
}
void ICTriggerPathProducer::produce(edm::Event& event,
const edm::EventSetup& setup) {
paths_->clear();
if (!input_is_standalone_) {
edm::Handle<pat::TriggerEvent> trig_handle;
event.getByLabel(input_, trig_handle);
std::vector<pat::TriggerPath> const* paths = trig_handle->paths();
paths_->reserve(paths->size());
for (unsigned i = 0; i < paths->size(); ++i) {
pat::TriggerPath const& src = paths->at(i);
if (!src.wasAccept() && include_if_fired_) continue;
std::string name = src.name();
SetNameInfo(name, &dest);
}
} else {
edm::Handle<edm::TriggerResults> trigres_handle;
event.getByLabel(input_, trigres_handle);
#if CMSSW_MAJOR_VERSION >= 7
edm::Handle<pat::PackedTriggerPrescales> prescales_handle;
event.getByLabel(input_prescales_, prescales_handle);
#endif
#if CMSSW_MAJOR_VERSION >= 8
edm::Handle<BXVector<GlobalAlgBlk>> l1algo_handle;
if (prescale_fallback_) {
event.getByLabel(edm::InputTag("gtStage2Digis"), l1algo_handle);
}
#endif
edm::TriggerNames const& names = event.triggerNames(*trigres_handle);
paths_->reserve(trigres_handle->size());
for (unsigned int i = 0, n = trigres_handle->size(); i < n; ++i) {
if (!trigres_handle->accept(i) && include_if_fired_) continue;
#if CMSSW_MAJOR_VERSION >= 7
dest.
set_prescale(prescales_handle->getPrescaleForIndex(i));
#if CMSSW_MAJOR_VERSION >= 8
if (prescale_fallback_) {
unsigned column = l1algo_handle->at(0, 0).getPreScColumn();
unsigned other_prescale = hlt_config_.prescaleValue(column, names.triggerName(i));
}
#endif
#else
#endif
std::string name = names.triggerName(i);
SetNameInfo(name, &dest);
}
}
}
void ICTriggerPathProducer::SetNameInfo(std::string name,
if (split_version_) {
std::size_t v_pos = name.find_last_of('v');
if (v_pos != std::string::npos) {
std::string post_v = name.substr(v_pos+1);
std::string pre_v = name.substr(0, v_pos+1);
try {
unsigned v = boost::lexical_cast<unsigned>(post_v);
name = pre_v;
}
catch(boost::bad_lexical_cast
const&
e) {
}
}
}
if (save_strings_) {
} else {
if (!observed_paths_.count(name)) {
observed_paths_[name] = hash;
}
}
}
void ICTriggerPathProducer::beginRun(edm::Run const& run,
edm::EventSetup const& es) {
bool changed = true;
bool res = hlt_config_.init(run, es, hlt_process_, changed);
if (!res)
throw std::runtime_error(
"HLTConfigProvider did not initialise correctly");
}
void ICTriggerPathProducer::beginJob() {
}
void ICTriggerPathProducer::endJob() {
if (!save_strings_) {
std::cout << std::string(78, '-') << "\n";
std::cout << boost::format("%-56s %20s\n")
% "HLT Paths" % std::string("Hash Summmary");
std::map<std::string, std::size_t>::const_iterator iter;
for (iter = observed_paths_.begin(); iter != observed_paths_.end();
++iter) {
std::cout << boost::format("%-56s| %020i\n") % iter->first % iter->second;
}
}
}