CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/PhysicsTools/RecoUtils/plugins/HLTEventSelector.cc

Go to the documentation of this file.
00001 #include "PhysicsTools/RecoUtils/plugins/HLTEventSelector.h"
00002 
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 
00005 #include "DataFormats/Common/interface/TriggerResults.h"
00006 #include "FWCore/Common/interface/TriggerNames.h"
00007 
00008 HLTEventSelector::HLTEventSelector (const edm::ParameterSet& pset){
00009   // input collection
00010   triggerResults_ = pset.getParameter<edm::InputTag>("triggerResults");
00011   // trigger path names
00012   pathNames_ = pset.getParameter< std::vector<std::string> >("pathNames");
00013 
00014   edm::LogInfo("HLTEventSelector") << "constructed with \n"
00015                                    << "  src = " << triggerResults_ << "\n"
00016                                    << "  #pathnames = " << pathNames_.size();
00017 }
00018 
00019 bool
00020 HLTEventSelector::select (const edm::Event& event) const
00021 {
00022   //
00023   // get the trigger results and check validity
00024   //
00025   edm::Handle<edm::TriggerResults> hltHandle;
00026   event.getByLabel(triggerResults_, hltHandle);
00027   if ( !hltHandle.isValid() ) {
00028     edm::LogWarning("HLTEventSelector") << "No trigger results for InputTag " << triggerResults_;
00029     return false;
00030   }
00031   //
00032   // get results
00033   //
00034   const edm::TriggerNames & trgNames = event.triggerNames(*hltHandle);
00035   unsigned int trgSize = trgNames.size();
00036 //   static int first(true);
00037 //   if ( first ) {
00038 //     first = false;
00039 //     std::cout << "Trigger menu" << std::endl;
00040 //     for ( unsigned int i=0; i<trgSize; ++i ) {
00041 //       std::cout << trgNames.triggerName(i) << std::endl;
00042 //     }
00043 //   }
00044 //
00045 // example for OR of all specified triggers
00046 //
00047   for ( std::vector<std::string>::const_iterator i=pathNames_.begin();
00048         i!=pathNames_.end(); ++i ) {
00049     // get index
00050     unsigned int index = trgNames.triggerIndex(*i);
00051     if ( index==trgSize ) {
00052       edm::LogWarning("HLTEventSelector") << "Unknown trigger name " << *i;
00053 //       return false;
00054       continue;
00055     }
00056 //     if ( !hltHandle->accept(index) )  return false;
00057     if ( hltHandle->accept(index) ) {
00058       LogDebug("HLTEventSelector") << "Event selected by " << *i;
00059       return true;
00060     }
00061   }
00062 //   return true;
00063   LogDebug("HLTEventSelector") << "Event rejected";
00064   return false;
00065 }