CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/HLTrigger/HLTcore/plugins/HLTPrescaler.cc

Go to the documentation of this file.
00001 
00002 //
00003 // HLTPrescaler
00004 // ------------
00005 //
00006 //           04/25/2008 Philipp Schieferdecker <philipp.schieferdecker@cern.ch>
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 // initialize static member variables
00021 
00022 const unsigned int HLTPrescaler::prescaleSeed_ = 65537;
00023 
00025 // construction/destruction
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 // implementation of member functions
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   // during the first event of a LumiSection, read from the GT the prescale index for this
00071   // LumiSection and get the corresponding prescale factor from the PrescaleService
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         // gtPrescaleFactorIndexTech() is also available
00087         // by construction, they should always return the same index
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         // reset the prescale counter
00101         needsInit = true;
00102       }
00103     }
00104 
00105     if (needsInit && (prescaleFactor_ != 0)) {
00106       // initialize the prescale counter to the first event number multiplied by a big "seed"
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 }