CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/DPGAnalysis/SiStripTools/plugins/SiStripQualityHistory.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    SiStripTools
00004 // Class:      SiStripQualityHistory
00005 // 
00013 //
00014 // Original Author:  Andrea Venturi
00015 //         Created:  Tue Sep 18 17:52:00 CEST 2009
00016 //
00017 //
00018 
00019 
00020 // system include files
00021 #include <memory>
00022 
00023 // user include files
00024 
00025 #include <vector>
00026 #include <map>
00027 
00028 //#include "TGraph.h"
00029 #include "TH1F.h"
00030 
00031 #include "FWCore/Framework/interface/Frameworkfwd.h"
00032 #include "FWCore/Framework/interface/EDAnalyzer.h"
00033 
00034 #include "FWCore/Framework/interface/Event.h"
00035 #include "FWCore/Framework/interface/MakerMacros.h"
00036 #include "FWCore/Framework/interface/Run.h"
00037 
00038 #include "FWCore/Framework/interface/ESHandle.h"
00039 
00040 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00041 
00042 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00043 
00044 #include "FWCore/ServiceRegistry/interface/Service.h"
00045 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00046 
00047 #include "FWCore/Utilities/interface/InputTag.h"
00048 
00049 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
00050 #include "CalibTracker/Records/interface/SiStripQualityRcd.h"
00051 
00052 //
00053 // class decleration
00054 //
00055 
00056 class SiStripQualityHistory : public edm::EDAnalyzer {
00057  public:
00058     explicit SiStripQualityHistory(const edm::ParameterSet&);
00059     ~SiStripQualityHistory();
00060 
00061   enum {Module,Fiber,APV};
00062 
00063    private:
00064       virtual void beginJob() ;
00065       virtual void beginRun(const edm::Run&, const edm::EventSetup&) ;
00066       virtual void endRun(const edm::Run&, const edm::EventSetup&) ;
00067       virtual void analyze(const edm::Event&, const edm::EventSetup&);
00068       virtual void endJob() ;
00069 
00070       // ----------member data ---------------------------
00071 
00072   const std::vector<edm::ParameterSet> _monitoredssq;
00073   const unsigned int _mode;
00074   //  std::map<std::string,TGraph*> _history;
00075   std::map<std::string,TH1F*> _history;
00076 
00077 
00078 };
00079 
00080 //
00081 // constants, enums and typedefs
00082 //
00083 
00084 //
00085 // static data member definitions
00086 //
00087 
00088 //
00089 // constructors and destructor
00090 //
00091 SiStripQualityHistory::SiStripQualityHistory(const edm::ParameterSet& iConfig):
00092   _monitoredssq(iConfig.getParameter<std::vector<edm::ParameterSet> >("monitoredSiStripQuality")),
00093   _mode(iConfig.getUntrackedParameter<unsigned int>("granularityMode",Module)),
00094   _history()
00095 {
00096    //now do what ever initialization is needed
00097 
00098   edm::Service<TFileService> tfserv;
00099 
00100   for(std::vector<edm::ParameterSet>::const_iterator ps=_monitoredssq.begin();ps!=_monitoredssq.end();++ps) {
00101     
00102     std::string name = ps->getParameter<std::string>("name");
00103     //    _history[name] = tfserv->make<TGraph>();
00104     //    _history[name]->SetName(name.c_str());     _history[name]->SetTitle(name.c_str()); 
00105 
00106     _history[name] = tfserv->make<TH1F>(name.c_str(),name.c_str(),10,0,10);
00107 
00108   }
00109 
00110 }
00111 
00112 
00113 SiStripQualityHistory::~SiStripQualityHistory()
00114 {
00115  
00116    // do anything here that needs to be done at desctruction time
00117    // (e.g. close files, deallocate resources etc.)
00118 
00119 }
00120 
00121 
00122 //
00123 // member functions
00124 //
00125 
00126 // ------------ method called to for each event  ------------
00127 void
00128 SiStripQualityHistory::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00129 {
00130   edm::LogInfo("EventProcessing") << "event being processed";
00131 }
00132 
00133 void 
00134 SiStripQualityHistory::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
00135 {
00136 
00137   // loop on all the SiStripQuality objects to be monitored
00138 
00139   for(std::vector<edm::ParameterSet>::const_iterator ps=_monitoredssq.begin();ps!=_monitoredssq.end();++ps) {
00140     
00141     std::string name = ps->getParameter<std::string>("name");
00142     std::string label = ps->getParameter<std::string>("ssqLabel");
00143 
00144     
00145     edm::ESHandle<SiStripQuality> ssq;
00146     iSetup.get<SiStripQualityRcd>().get(label,ssq);
00147 
00148     std::vector<SiStripQuality::BadComponent> bads = ssq->getBadComponentList();
00149 
00150     edm::LogInfo("Debug") << bads.size() << " bad components found";
00151 
00152     int nbad=0;
00153 
00154     for(std::vector<SiStripQuality::BadComponent>::const_iterator bc=bads.begin();bc!=bads.end();++bc) {
00155 
00156       if(_mode==Module) {
00157        if(bc->BadModule) ++nbad;
00158       }
00159       else if(_mode == Fiber) {
00160       for(int fiber=1;fiber<5;fiber*=2) {
00161         if((bc->BadFibers & fiber)>0) ++nbad;
00162       }
00163     }
00164     else if(_mode ==APV) {
00165       for(int apv=1;apv<33;apv*=2) {
00166         if((bc->BadApvs & apv)>0) ++nbad;
00167       }
00168     }
00169   }
00170 
00171 
00172     //    _history[name]->SetPoint(_history[name]->GetN(),iRun.run(),nbad);
00173     char runname[100];
00174     sprintf(runname,"%d",iRun.run());
00175     edm::LogInfo("Debug") << name << " " << runname << " " << nbad;
00176     _history[name]->Fill(runname,nbad);
00177 
00178   }
00179 
00180   
00181 
00182 }
00183 
00184 void 
00185 SiStripQualityHistory::endRun(const edm::Run& iRun, const edm::EventSetup&)
00186 {}
00187 
00188 
00189 // ------------ method called once each job just before starting event loop  ------------
00190 void 
00191 SiStripQualityHistory::beginJob()
00192 {}
00193 
00194 // ------------ method called once each job just after ending the event loop  ------------
00195 void 
00196 SiStripQualityHistory::endJob() 
00197 {
00198   /*
00199   for(std::vector<edm::ParameterSet>::const_iterator ps=_monitoredssq.begin();ps!=_monitoredssq.end();++ps) {
00200     
00201     std::string name = ps->getParameter<std::string>("name");
00202     _history[name]->Write();
00203 
00204   }
00205   */
00206 }
00207 
00208 
00209 //define this as a plug-in
00210 DEFINE_FWK_MODULE(SiStripQualityHistory);