CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/DQMOffline/PFTau/plugins/PFDQMEventSelector.cc

Go to the documentation of this file.
00001 #include "DQMOffline/PFTau/plugins/PFDQMEventSelector.h" 
00002 
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 #include "FWCore/Framework/interface/Event.h"
00005 #include "DataFormats/Common/interface/Handle.h"
00006 
00007 #include "DQMServices/Core/interface/DQMStore.h"
00008 #include "DQMServices/Core/interface/MonitorElement.h"
00009 #include "FWCore/ServiceRegistry/interface/Service.h"
00010 
00011 #include <iostream>
00012  
00013 //
00014 // -- Constructor
00015 //
00016 PFDQMEventSelector::PFDQMEventSelector( const edm::ParameterSet & pset ) {
00017    verbose_       = pset.getParameter<bool>( "DebugOn" );
00018    inputFileName_ = pset.getParameter<std::string>("InputFileName");
00019    folderNames_   = pset.getParameter< std::vector<std::string> >("FolderNames");
00020 
00021    nEvents_         = 0;
00022    nSelectedEvents_ = 0;
00023    fileOpened_      = false;
00024 }
00025 //
00026 // -- Destructor
00027 //
00028 PFDQMEventSelector::~PFDQMEventSelector() {
00029 }
00030  
00031 //
00032 // -- BeginJob
00033 //
00034 void PFDQMEventSelector::beginJob() {
00035 
00036   dqmStore_ = edm::Service<DQMStore>().operator->();
00037   fileOpened_ = openInputFile();
00038 }
00039 //
00040 // -- Event Filtering
00041 //
00042 bool PFDQMEventSelector::filter( edm::Event & iEvent, edm::EventSetup const& iSetup) {
00043   
00044   nEvents_++;
00045   if (!fileOpened_) return false;
00046 
00047   unsigned int runNb  = iEvent.id().run();
00048   unsigned int evtNb  = iEvent.id().event();
00049   unsigned int lumiNb = iEvent.id().luminosityBlock();
00050   std::ostringstream eventid_str;
00051   eventid_str << runNb << "_"<< evtNb << "_" << lumiNb;
00052   
00053   for (std::vector<std::string>::const_iterator ifolder = folderNames_.begin();
00054                                     ifolder != folderNames_.end(); ifolder++) {
00055     std::string path  = "ParticleFlow/"+(*ifolder) + "/BadEvents";
00056     MonitorElement* me = dqmStore_->get(path + "/" + eventid_str.str());
00057     if (me) {
00058       nSelectedEvents_++;
00059       if ( verbose_ ) std::cout << " Total Events " << nEvents_ 
00060                                 << " Selected Events " << nSelectedEvents_ 
00061                                 << " Run # : " << runNb 
00062                                 << " Event # : " << evtNb
00063                                 << " Luminosity Block # : " << lumiNb
00064                                 <<  std::endl;           
00065       return true;
00066     }
00067   } 
00068   return false;
00069 }
00070 //
00071 // -- End Job
00072 //
00073 void PFDQMEventSelector::endJob() {
00074   if ( verbose_ ) std::cout << " Total Events " << nEvents_ 
00075                             << " Selected Events " << nSelectedEvents_ 
00076                             << std::endl; 
00077 }
00078 //
00079 // -- Open Input File
00080 //
00081 bool PFDQMEventSelector::openInputFile() { 
00082   if (inputFileName_.size() == 0) return false;
00083   edm::LogInfo("SiStripOfflineDQM") <<  "SiStripOfflineDQM::openInputFile: Accessing root File" << inputFileName_;
00084   dqmStore_->open(inputFileName_, false, "", "", DQMStore::StripRunDirs); 
00085   return true;
00086 }
00087 
00088 #include "FWCore/Framework/interface/MakerMacros.h"
00089 DEFINE_FWK_MODULE(PFDQMEventSelector);
00090 
00091