CMS 3D CMS Logo

SiPixelHistoricInfoEDAClient.cc

Go to the documentation of this file.
00001 #include <memory>
00002 #include <iostream>
00003 #include <sstream>
00004 #include <string>
00005 #include <stdio.h>
00006 #include <sys/time.h>
00007 
00008 #include "TNamed.h"
00009 #include "TH1F.h"
00010 
00011 #include "FWCore/Framework/interface/Frameworkfwd.h"
00012 #include "FWCore/Framework/interface/EDAnalyzer.h"
00013 #include "FWCore/Framework/interface/Event.h"
00014 #include "FWCore/Framework/interface/MakerMacros.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00018 
00019 #include "DataFormats/Provenance/interface/EventID.h"
00020 #include "DataFormats/Provenance/interface/RunID.h"
00021 #include "DataFormats/Provenance/interface/Timestamp.h"
00022 
00023 #include "DataFormats/Common/interface/Handle.h"
00024 #include "DataFormats/TrackCandidate/interface/TrackCandidateCollection.h"
00025 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00026 #include "RecoTracker/TransientTrackingRecHit/interface/TkTransientTrackingRecHitBuilder.h"
00027 #include "TrackingTools/PatternTools/interface/TrajectoryFitter.h"
00028 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
00029 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
00030 #include "TrackingTools/TrackFitters/interface/TrajectoryStateCombiner.h"
00031 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00032 
00033 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00034 #include "CondFormats/SiPixelObjects/interface/SiPixelPerformanceSummary.h"
00035 
00036 #include "DQMServices/Core/interface/DQMStore.h"
00037 #include "DQMServices/Core/interface/MonitorElement.h"
00038 
00039 #include "DQM/SiPixelCommon/interface/SiPixelHistogramId.h"
00040 #include "DQM/SiPixelHistoricInfoClient/interface/SiPixelHistoricInfoEDAClient.h"
00041 
00042 
00043 using namespace std;
00044 using namespace cgicc;
00045 using namespace xcept;
00046 
00047 
00048 SiPixelHistoricInfoEDAClient::SiPixelHistoricInfoEDAClient(const edm::ParameterSet& parameterSet) { 
00049   parameterSet_ = parameterSet;  
00050   dbe_ = edm::Service<DQMStore>().operator->(); 
00051   dbe_->setVerbose(0); 
00052 }
00053 
00054 
00055 /*// mui_ = new DQMOldReceiver();
00056   // // sipixelWebInterface_ = new SiPixelWebInterface("dummy","dummy",&mui_); 
00057   // webInterface_ = new SiPixelHistoricInfoWebInterface(getContextURL(), getApplicationURL(), &mui_);
00058   // defaultWebPageCreated_ = false; 
00059 
00060 void SiPixelHistoricInfoEDAClient::defaultWebPage(xgi::Input* in, xgi::Output* out) {
00061   if (!defaultPageCreated_) {
00062     static const int BUF_SIZE = 256; 
00063     ifstream fin("loader.html", ios::in);
00064     if (!fin) {
00065       cerr << "loader.html could not be opened!" << endl;
00066       return;
00067     }
00068     char buf[BUF_SIZE];
00069     ostringstream html_dump;
00070     while (fin.getline(buf, BUF_SIZE,'\n')) html_dump << buf << std::endl; 
00071     fin.close();
00072    *out << html_dump.str() << std::endl;
00073    
00074     defaultWebPageCreated_ = true;
00075   }  
00076   webInterface_->handleEDARequest(in, out);
00077 } */
00078 
00079 
00080 SiPixelHistoricInfoEDAClient::~SiPixelHistoricInfoEDAClient() {}
00081 
00082 
00083 void SiPixelHistoricInfoEDAClient::beginJob(const edm::EventSetup& eventSetup) {
00084   nEvents = 0; 
00085 }
00086 
00087 
00088 void SiPixelHistoricInfoEDAClient::beginRun(const edm::Run& run, const edm::EventSetup& eventSetup) {
00089   performanceSummary_ = new SiPixelPerformanceSummary();
00090   performanceSummary_->clear(); 
00091   performanceSummary_->setRunNumber(run.run());
00092   firstEventInRun = true;
00093 }
00094 
00095 
00096 void SiPixelHistoricInfoEDAClient::analyze(const edm::Event& event, const edm::EventSetup& eventSetup) {
00097   if (firstEventInRun) {
00098     firstEventInRun = false;
00099     performanceSummary_->setTimeValue(event.time().value());
00100   }
00101   nEvents++;
00102 }
00103 
00104 
00105 void SiPixelHistoricInfoEDAClient::endRun(const edm::Run& run, const edm::EventSetup& eventSetup) {
00106   firstEventInRun = false;
00107   std::cout << "SiPixelHistoricInfoEDAClient::endRun() number of events = "<< nEvents << std::endl;
00108 
00109   retrievePointersToModuleMEs(eventSetup);
00110   fillSummaryObjects(run);
00111   performanceSummary_->print();
00112   writetoDB(run); 
00113   
00114   if (parameterSet_.getUntrackedParameter<bool>("writeHisto", true)) {
00115     std::string outputDir = parameterSet_.getUntrackedParameter<std::string>("outputDir",".");
00116     std::ostringstream endRunOutputFile; 
00117     endRunOutputFile << outputDir << "/SiPixelHistoricInfoEDAClient_" << run.run() <<".root"; 
00118     dbe_->save(endRunOutputFile.str()); 
00119   }
00120 }
00121 
00122 
00123 void SiPixelHistoricInfoEDAClient::endJob() {
00124   if (parameterSet_.getUntrackedParameter<bool>("writeHisto", true)) {
00125     std::string outputDir = parameterSet_.getUntrackedParameter<std::string>("outputDir",".");
00126     std::ostringstream endJobOutputFile; 
00127     endJobOutputFile << outputDir << "/SiPixelHistoricInfoEDAClient_endJob.root"; 
00128     dbe_->save(endJobOutputFile.str());
00129   }
00130 }
00131 
00132 
00133 void SiPixelHistoricInfoEDAClient::retrievePointersToModuleMEs(const edm::EventSetup& eventSetup) {
00134   std::vector<string> listOfMEsWithFullPath;
00135   dbe_->getContents(listOfMEsWithFullPath);
00136     
00137   for (std::vector<string>::const_iterator ime=listOfMEsWithFullPath.begin(); 
00138        ime!=listOfMEsWithFullPath.end(); ime++) {
00139     uint32_t pathLength = (*ime).find(":",0);     
00140     string thePath = (*ime).substr(0, pathLength); 
00141     string allHists = (*ime).substr(pathLength+1); 
00142     
00143     if (thePath.find("Pixel",0)!=string::npos && thePath.find("Module",0)!=string::npos) {
00144       uint histnameLength; 
00145       do {
00146         histnameLength = allHists.find(",",0);
00147         string theHist;
00148         if (histnameLength!=string::npos) {
00149           theHist = allHists.substr(0, histnameLength);
00150           allHists.erase(0, histnameLength+1);
00151         }
00152         else theHist = allHists; 
00153 
00154         string fullPathHist = thePath + "/" + theHist;
00155         MonitorElement* theMEpointer = dbe_->get(fullPathHist);
00156 
00157         SiPixelHistogramId hisIDmanager;
00158         string hisID;
00159         uint32_t localMEdetID;
00160         if (theMEpointer) {
00161           hisID = theMEpointer->getName();
00162           localMEdetID = hisIDmanager.getRawId(hisID);
00163 
00164           if (ClientPointersToModuleMEs.find(localMEdetID)==ClientPointersToModuleMEs.end()) {
00165             std::vector<MonitorElement*> newMEvector;
00166             newMEvector.push_back(theMEpointer);
00167             ClientPointersToModuleMEs.insert(std::make_pair(localMEdetID, newMEvector));
00168           }
00169           else ((ClientPointersToModuleMEs.find(localMEdetID))->second).push_back(theMEpointer);
00170         }
00171       } 
00172       while (histnameLength!=string::npos); 
00173     } 
00174   } 
00175 }
00176 
00177 
00178 void SiPixelHistoricInfoEDAClient::fillSummaryObjects(const edm::Run& run) const {
00179   for (std::map< uint32_t, std::vector<MonitorElement*> >::const_iterator iMEvec=ClientPointersToModuleMEs.begin(); 
00180        iMEvec!=ClientPointersToModuleMEs.end(); iMEvec++) {
00181     uint32_t localMEdetID = iMEvec->first;
00182     std::vector<MonitorElement*> theMEvector = iMEvec->second;
00183     
00184     for (std::vector<MonitorElement*>::const_iterator iMEpntr = theMEvector.begin(); 
00185          iMEpntr!=theMEvector.end(); iMEpntr++) {
00186       std::string theMEname = (*iMEpntr)->getName();
00187       // if (parameterSet_.getUntrackedParameter<bool>("debug", true)) std::cout << theMEname << std::endl; 
00188       
00189       if (theMEname.find("ndigis_siPixelDigis")!=std::string::npos) { 
00190         performanceSummary_->setNumberOfDigis(localMEdetID, (*iMEpntr)->getMean(), (*iMEpntr)->getRMS());
00191         if (parameterSet_.getUntrackedParameter<bool>("debug", true)) { 
00192           std::cout << "sipixel performance summary table set with the number of digi's "<< (*iMEpntr)->getMean() 
00193                                                                                 << " +- "<< (*iMEpntr)->getRMS() 
00194                     <<" for det ID "<< localMEdetID << std::endl; 
00195         }
00196       } 
00197       /* if (theMEname.find("size_siPixelClusters")!=std::string::npos) {
00198         performanceSummary_->setClusterSize(localMEdetID, (*iMEpntr)->getMean(), (*iMEpntr)->getRMS());
00199       } */
00200     }
00201   }
00202 }
00203 
00204 
00205 void SiPixelHistoricInfoEDAClient::writetoDB(const edm::Run& run) const {
00206   unsigned int thisRun = run.run();
00207   std::cout << std::endl << "SiPixelHistoricInfoEDAClient::writetoDB() run = "<< thisRun << std::endl; 
00208 
00209   edm::Service<cond::service::PoolDBOutputService> mydbservice; 
00210   if (mydbservice.isAvailable()) {
00211     if (mydbservice->isNewTagRequest("SiPixelPerformanceSummaryRcd")) {
00212       mydbservice->createNewIOV<SiPixelPerformanceSummary>(performanceSummary_, 
00213                                                            mydbservice->beginOfTime(), 
00214                                                            mydbservice->endOfTime(), 
00215                                                           "SiPixelPerformanceSummaryRcd"); 
00216     } 
00217     else {
00218       mydbservice->appendSinceTime<SiPixelPerformanceSummary>(performanceSummary_, 
00219                                                               mydbservice->currentTime(), 
00220                                                              "SiPixelPerformanceSummaryRcd"); 
00221     }
00222   }
00223   else  edm::LogError("writetoDB") << "service unavailable" << std::endl; 
00224 
00225   std::cout << "SiPixelHistoricInfoEDAClient::writetoDB() finished. "<< std::endl; 
00226 }
00227 
00228 
00229 void SiPixelHistoricInfoEDAClient::writetoDB(edm::EventID eventID, edm::Timestamp EventTime) const {
00230   unsigned int thisRun        = eventID.run();
00231   unsigned int thisEvent      = eventID.event();
00232   unsigned long long thisTime = EventTime.value();
00233   std::cout << std::endl << "SiPixelHistoricInfoEDAClient::writetoDB() run = "<< thisRun 
00234                                                                  <<" event = "<< thisEvent 
00235                                                                   <<" time = "<< thisTime << std::endl;
00236 
00237   edm::Service<cond::service::PoolDBOutputService> mydbservice;
00238   if (mydbservice.isAvailable()) {
00239     if (mydbservice->isNewTagRequest("SiPixelPerformanceSummaryRcd")) {
00240       mydbservice->createNewIOV<SiPixelPerformanceSummary>(performanceSummary_, 
00241                                                            mydbservice->beginOfTime(), 
00242                                                            mydbservice->endOfTime(), 
00243                                                           "SiPixelPerformanceSummaryRcd");     
00244     } 
00245     else {
00246       mydbservice->appendSinceTime<SiPixelPerformanceSummary>(performanceSummary_, 
00247                                                               mydbservice->currentTime(), 
00248                                                              "SiPixelPerformanceSummaryRcd");
00249     }
00250   } 
00251   else edm::LogError("writetoDB") << "service unavailable" << std::endl;
00252 }
00253 
00254 
00255 void SiPixelHistoricInfoEDAClient::savetoFile(std::string filename) const {
00256   dbe_->save(filename); 
00257 }
00258 
00259 
00260 float SiPixelHistoricInfoEDAClient::calculatePercentOver(MonitorElement* me) const {
00261   TH1F* hist = me->getTH1F();
00262   unsigned int nBins = hist->GetNbinsX();
00263   unsigned int upperBin = hist->FindBin(hist->GetMean()+3*hist->GetRMS()); 
00264   float percentage=0.0;
00265   if ((upperBin-nBins)<1) {
00266     percentage = hist->Integral(upperBin,nBins)/hist->Integral(); 
00267     return percentage;
00268   }
00269   return -99.9; 
00270 }
00271 
00272 /*
00273   edm::ESHandle<TrackerGeometry> pDD;
00274   eventSetup.get<TrackerDigiGeometryRecord>().get(pDD);
00275 
00276   ClientPointersToModuleMEs.clear(); 
00277   for (TrackerGeometry::DetContainer::const_iterator it=pDD->dets().begin(); 
00278        it!=pDD->dets().end(); it++) {
00279     if (dynamic_cast<PixelGeomDetUnit*>((*it))!=0) {
00280       DetId detId = (*it)->geographicalId();
00281 
00282       if (detId.subdetId()==static_cast<int>(PixelSubdetector::PixelBarrel)) {
00283         std::vector<MonitorElement*> local_mes = dbe_->get(detId()); 
00284         ClientPointersToModuleMEs.insert(std::make_pair(detId(), local_mes));
00285       } 
00286       else if (detId.subdetId()==static_cast<int>(PixelSubdetector::PixelEndcap)) {
00287         std::vector<MonitorElement*> local_mes = dbe_->get(detId()); 
00288         ClientPointersToModuleMEs.insert(std::make_pair(detId(), local_mes));
00289       }
00290     }
00291   }
00292   std::cout << "SiPixelHistoricInfoEDAClient::retrievePointersToModuleMEs() ClientPointersToModuleMEs.size() = "
00293             <<  ClientPointersToModuleMEs.size() << std::endl;
00294 
00295 
00296   float percentage = calculatePercentOver(*iMEpntr);
00297   if (percentage>-99.9) performanceSummary_->setNoisePercentage(localMEdetID, calculatePercentOver(*iMEpntr)); 
00298 
00299 
00300 void SiPixelHistoricInfoEDAClient::printMEs() const {
00301   std::cout << "SiPixelHistoricInfoEDAClient::printMEs ClientPointersToModuleMEs.size() = "
00302             << ClientPointersToModuleMEs.size() << std::endl;
00303 
00304   for (std::map< uint32_t, std::vector<MonitorElement*> >::iterator imapmes=ClientPointersToModuleMEs.begin();
00305        imapmes!=ClientPointersToModuleMEs.end(); imapmes++) {
00306     std::cout << "Det ID = "<< imapmes->first << std::endl;
00307 
00308     std::vector<MonitorElement*> locvec = imapmes->second;
00309     for (std::vector<MonitorElement*>::const_iterator imep=locvec.begin();
00310          imep!=locvec.end(); imep++) {
00311       std::cout << (*imep)->getName() << " entries/mean/rms: "
00312                 << (*imep)->getEntries() <<" / "   
00313                 << (*imep)->getMean() <<" / "      
00314                 << (*imep)->getRMS() << std::endl; 
00315     }
00316     std::vector<MonitorElement*> tagged_mes = dbe_->get(imapmes->first);
00317     for (std::vector<MonitorElement*>::const_iterator imep=tagged_mes.begin();
00318          imep!=tagged_mes.end(); imep++) {
00319       std::cout << "(tagged ME) "<< (*imep)->getName() <<" entries/mean/rms: "
00320                                  << (*imep)->getEntries() <<" / "
00321                                  << (*imep)->getMean() <<" / "
00322                                  << (*imep)->getRMS() << std::endl;
00323     }
00324   }
00325 }
00326 */
00327 

Generated on Tue Jun 9 17:33:19 2009 for CMSSW by  doxygen 1.5.4