CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/DPGAnalysis/SiStripTools/plugins/LargeEvents.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    SiStripTools
00004 // Class:      LargeEvents
00005 // 
00013 //
00014 // Original Author:  Andrea Venturi
00015 //         Created:  Tue Oct 21 20:55:22 CEST 2008
00016 //
00017 //
00018 
00019 
00020 // system include files
00021 #include <memory>
00022 #include <string>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDFilter.h"
00027 
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 #include "FWCore/Framework/interface/ESHandle.h"
00031 #include "FWCore/Framework/interface/ESWatcher.h"
00032 
00033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00034 
00035 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00036 
00037 #include "FWCore/Utilities/interface/InputTag.h"
00038 
00039 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
00040 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
00041 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
00042 #include "DataFormats/Common/interface/DetSetVector.h"
00043 #include "DataFormats/Common/interface/DetSetVectorNew.h"
00044 #include "DataFormats/Common/interface/DetSet.h"
00045 
00046 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
00047 #include "CalibTracker/Records/interface/SiStripQualityRcd.h"
00048 
00049 //
00050 // class declaration
00051 //
00052 
00053 template <class T>
00054 class LargeEvents : public edm::EDFilter {
00055    public:
00056       explicit LargeEvents(const edm::ParameterSet&);
00057       ~LargeEvents();
00058 
00059    private:
00060       virtual void beginJob() ;
00061       virtual bool filter(edm::Event&, const edm::EventSetup&);
00062       virtual void endJob() ;
00063       
00064       // ----------member data ---------------------------
00065 
00066   edm::InputTag _collection;
00067   int _absthr;
00068   int _modthr;
00069   bool _useQuality;
00070   std::string _qualityLabel;
00071   edm::ESHandle<SiStripQuality> _qualityHandle;
00072   edm::ESWatcher<SiStripQualityRcd> _qualityWatcher;
00073 
00074 };
00075 
00076 //
00077 // constants, enums and typedefs
00078 //
00079 
00080 //
00081 // static data member definitions
00082 //
00083 
00084 //
00085 // constructors and destructor
00086 //
00087 template <class T>
00088 LargeEvents<T>::LargeEvents(const edm::ParameterSet& iConfig):
00089   _collection(iConfig.getParameter<edm::InputTag>("collectionName")),
00090   _absthr(iConfig.getUntrackedParameter<int>("absoluteThreshold")),
00091   _modthr(iConfig.getUntrackedParameter<int>("moduleThreshold")),
00092   _useQuality(iConfig.getUntrackedParameter<bool>("useQuality",false)),
00093   _qualityLabel(iConfig.getUntrackedParameter<std::string>("qualityLabel",""))
00094 {
00095    //now do what ever initialization is needed
00096 
00097 
00098 }
00099 
00100 template <class T>
00101 LargeEvents<T>::~LargeEvents()
00102 {
00103  
00104    // do anything here that needs to be done at desctruction time
00105    // (e.g. close files, deallocate resources etc.)
00106 
00107 }
00108 
00109 
00110 //
00111 // member functions
00112 //
00113 
00114 // ------------ method called on each new Event  ------------
00115 template <class T>
00116 bool
00117 LargeEvents<T>::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00118 {
00119    using namespace edm;
00120 
00121    if( _useQuality) {
00122      if(_qualityWatcher.check(iSetup)) {
00123        iSetup.get<SiStripQualityRcd>().get(_qualityLabel,_qualityHandle);
00124        LogDebug("SiStripQualityUpdated") << "SiStripQuality has changed and it will be updated";
00125      }
00126    }
00127 
00128    Handle<T> digis;
00129    iEvent.getByLabel(_collection,digis);
00130 
00131 
00132    int ndigitot = 0;
00133    for(typename T::const_iterator it = digis->begin();it!=digis->end();it++) {
00134 
00135      if(!_useQuality || !_qualityHandle->IsModuleBad(it->detId()) ) {
00136        if(_modthr < 0 || int(it->size()) < _modthr ) {
00137          ndigitot += it->size();
00138        }
00139      }
00140    }
00141 
00142    if(ndigitot > _absthr) {
00143      edm::LogInfo("LargeEventSelected") << "event with " << ndigitot << " digi/cluster selected";
00144      return true;
00145    }
00146 
00147    return false;
00148 }
00149 
00150 // ------------ method called once each job just before starting event loop  ------------
00151 template <class T>
00152 void 
00153 LargeEvents<T>::beginJob()
00154 {
00155 }
00156 
00157 // ------------ method called once each job just after ending the event loop  ------------
00158 template <class T>
00159 void 
00160 LargeEvents<T>::endJob() {
00161 }
00162 
00163 //define this as a plug-in
00164 typedef LargeEvents<edm::DetSetVector<SiStripDigi> > LargeSiStripDigiEvents;
00165 typedef LargeEvents<edmNew::DetSetVector<SiStripCluster> > LargeSiStripClusterEvents;
00166 typedef LargeEvents<edmNew::DetSetVector<SiPixelCluster> > LargeSiPixelClusterEvents;
00167 
00168 DEFINE_FWK_MODULE(LargeSiStripDigiEvents);
00169 DEFINE_FWK_MODULE(LargeSiStripClusterEvents);
00170 DEFINE_FWK_MODULE(LargeSiPixelClusterEvents);