Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00008
00009
00010 #include "FWCore/Framework/interface/CurrentProcessingContext.h"
00011 #include "FWCore/Framework/interface/LuminosityBlock.h"
00012 #include "FWCore/ServiceRegistry/interface/Service.h"
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00015 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
00016 #include "HLTrigger/HLTcore/interface/HLTPrescaler.h"
00017
00019
00021
00022 const unsigned int HLTPrescaler::prescaleSeed_ = 65537;
00023
00025
00027
00028
00029 HLTPrescaler::HLTPrescaler(edm::ParameterSet const& iConfig) :
00030 prescaleSet_(0)
00031 , prescaleFactor_(1)
00032 , eventCount_(0)
00033 , acceptCount_(0)
00034 , offsetCount_(0)
00035 , offsetPhase_(iConfig.existsAs<unsigned int>("offset") ? iConfig.getParameter<unsigned int>("offset") : 0)
00036 , prescaleService_(0)
00037 , newLumi_(true)
00038 , gtDigi_ (iConfig.getParameter<edm::InputTag>("L1GtReadoutRecordTag"))
00039 {
00040 if(edm::Service<edm::service::PrescaleService>().isAvailable())
00041 prescaleService_ = edm::Service<edm::service::PrescaleService>().operator->();
00042 else
00043 LogDebug("NoPrescaleService")<<"PrescaleService unavailable, prescaleFactor=1!";
00044 }
00045
00046
00047 HLTPrescaler::~HLTPrescaler()
00048 {
00049
00050 }
00051
00052
00054
00056
00057
00058 bool HLTPrescaler::beginLuminosityBlock(edm::LuminosityBlock & lb,
00059 edm::EventSetup const& iSetup)
00060 {
00061 newLumi_ = true;
00062
00063 return true;
00064 }
00065
00066
00067
00068 bool HLTPrescaler::filter(edm::Event& iEvent, const edm::EventSetup&)
00069 {
00070
00071
00072 if (newLumi_) {
00073 newLumi_ = false;
00074
00075 bool needsInit (eventCount_==0);
00076
00077 if (prescaleService_) {
00078 std::string const & pathName = * currentContext()->pathName();
00079 const unsigned int oldSet(prescaleSet_);
00080 const unsigned int oldPrescale(prescaleFactor_);
00081
00082 edm::Handle<L1GlobalTriggerReadoutRecord> handle;
00083 iEvent.getByLabel(gtDigi_ , handle);
00084 if (handle.isValid()) {
00085 prescaleSet_ = handle->gtFdlWord().gtPrescaleFactorIndexAlgo();
00086
00087
00088 prescaleFactor_ = prescaleService_->getPrescale(prescaleSet_, pathName);
00089 } else {
00090 edm::LogWarning("HLT") << "Cannot read prescale column index from GT data: using default as defined by configuration or DAQ";
00091 prescaleFactor_ = prescaleService_->getPrescale(pathName);
00092 }
00093
00094 if (prescaleSet_ != oldSet) {
00095 edm::LogInfo("ChangedPrescale")
00096 << "lumiBlockNb = " << iEvent.getLuminosityBlock().id().luminosityBlock()
00097 << ", set = " << prescaleSet_ << " [" << oldSet <<"]"
00098 << ", path = "<< pathName
00099 << ": " << prescaleFactor_ << " [" <<oldPrescale<<"]";
00100
00101 needsInit = true;
00102 }
00103 }
00104
00105 if (needsInit && (prescaleFactor_ != 0)) {
00106
00107 offsetCount_ = ((uint64_t) (iEvent.id().event() + offsetPhase_) * prescaleSeed_) % prescaleFactor_;
00108 }
00109 }
00110
00111 const bool result ( (prescaleFactor_ == 0) ?
00112 false : ((eventCount_ + offsetCount_) % prescaleFactor_ == 0) );
00113
00114 ++eventCount_;
00115 if (result) ++acceptCount_;
00116 return result;
00117 }
00118
00119
00120
00121 void HLTPrescaler::endJob()
00122 {
00123 edm::LogInfo("PrescaleSummary")
00124 << acceptCount_<< "/" <<eventCount_
00125 << " ("
00126 << 100.*acceptCount_/static_cast<double>(std::max(1u,eventCount_))
00127 << "% of events accepted).";
00128 return;
00129 }