CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/DPGAnalysis/SiStripTools/plugins/SiStripDetWithSomething.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    SiStripTools
00004 // Class:      SiStripDetWithSomething
00005 // 
00013 //
00014 // Original Author:  Andrea Venturi
00015 //         Created:  Wed Oct 22 17:54:30 CEST 2008
00016 //
00017 //
00018 
00019 
00020 // system include files
00021 #include <memory>
00022 
00023 // user include files
00024 #include "FWCore/Framework/interface/Frameworkfwd.h"
00025 #include "FWCore/Framework/interface/EDFilter.h"
00026 
00027 #include "FWCore/Framework/interface/Event.h"
00028 #include "FWCore/Framework/interface/MakerMacros.h"
00029 
00030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00031 
00032 #include <vector>
00033 
00034 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00035 
00036 #include "FWCore/Utilities/interface/InputTag.h"
00037 
00038 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
00039 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
00040 #include "DataFormats/Common/interface/DetSetVector.h"
00041 #include "DataFormats/Common/interface/DetSetVectorNew.h"
00042 
00043 //
00044 // class declaration
00045 //
00046 
00047 template <class T>
00048 class SiStripDetWithSomething : public edm::EDFilter {
00049    public:
00050       explicit SiStripDetWithSomething(const edm::ParameterSet&);
00051       ~SiStripDetWithSomething();
00052 
00053    private:
00054       virtual void beginJob() ;
00055       virtual bool filter(edm::Event&, const edm::EventSetup&);
00056       virtual void endJob() ;
00057       
00058       // ----------member data ---------------------------
00059 
00060   edm::InputTag _digicollection;
00061   std::vector<unsigned int> _wantedmod;
00062 
00063 };
00064 
00065 //
00066 // constants, enums and typedefs
00067 //
00068 
00069 //
00070 // static data member definitions
00071 //
00072 
00073 //
00074 // constructors and destructor
00075 //
00076 template <class T>
00077 SiStripDetWithSomething<T>::SiStripDetWithSomething(const edm::ParameterSet& iConfig):
00078   _digicollection(iConfig.getParameter<edm::InputTag>("collectionName")),
00079   _wantedmod(iConfig.getUntrackedParameter<std::vector<unsigned int> >("selectedModules"))
00080 
00081 {
00082    //now do what ever initialization is needed
00083 
00084   sort(_wantedmod.begin(),_wantedmod.end());
00085 
00086   edm::LogInfo("SelectedModules") << "Selected module list";
00087   for(std::vector<unsigned int>::const_iterator mod = _wantedmod.begin();mod!=_wantedmod.end();mod++) {
00088     edm::LogVerbatim("SelectedModules") << *mod ;
00089   }
00090 
00091 }
00092 
00093 
00094 template <class T>
00095 SiStripDetWithSomething<T>::~SiStripDetWithSomething()
00096 {
00097  
00098    // do anything here that needs to be done at desctruction time
00099    // (e.g. close files, deallocate resources etc.)
00100 
00101 }
00102 
00103 
00104 //
00105 // member functions
00106 //
00107 
00108 // ------------ method called on each new Event  ------------
00109 template <class T>
00110 bool
00111 SiStripDetWithSomething<T>::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00112 {
00113    using namespace edm;
00114 
00115    Handle<T> digis;
00116    iEvent.getByLabel(_digicollection,digis);
00117 
00118    for(typename T::const_iterator it = digis->begin();it!=digis->end();it++) {
00119 
00120      for(std::vector<unsigned int>::const_iterator mod=_wantedmod.begin();
00121          mod!=_wantedmod.end()&&it->detId()>=*mod;
00122          mod++) {
00123        if(*mod == it->detId()) {
00124          edm::LogInfo("ModuleFound") << " module " << *mod << " found with " 
00125                                      << it->size() << " digis/clusters";
00126          return true;
00127        }
00128      }
00129    }
00130 
00131    return false;
00132 }
00133 
00134 // ------------ method called once each job just before starting event loop  ------------
00135 template <class T>
00136 void 
00137 SiStripDetWithSomething<T>::beginJob()
00138 {
00139 }
00140 
00141 // ------------ method called once each job just after ending the event loop  ------------
00142 template <class T>
00143 void 
00144 SiStripDetWithSomething<T>::endJob() {
00145 }
00146 
00147 typedef SiStripDetWithSomething<edm::DetSetVector<SiStripDigi> > SiStripDetWithDigi;
00148 typedef SiStripDetWithSomething<edmNew::DetSetVector<SiStripCluster> > SiStripDetWithCluster;
00149 
00150 //define this as a plug-in
00151 DEFINE_FWK_MODULE(SiStripDetWithDigi);
00152 DEFINE_FWK_MODULE(SiStripDetWithCluster);