CMS 3D CMS Logo

EBStatusFlagsClient.cc

Go to the documentation of this file.
00001 /*
00002  * \file EBStatusFlagsClient.cc
00003  *
00004  * $Date: 2008/06/25 15:08:18 $
00005  * $Revision: 1.23 $
00006  * \author G. Della Ricca
00007  *
00008 */
00009 
00010 #include <memory>
00011 #include <iostream>
00012 #include <fstream>
00013 #include <iomanip>
00014 
00015 #include "TCanvas.h"
00016 #include "TStyle.h"
00017 
00018 #include "DQMServices/Core/interface/DQMStore.h"
00019 
00020 #include "DQM/EcalCommon/interface/UtilsClient.h"
00021 #include "DQM/EcalCommon/interface/Numbers.h"
00022 
00023 #include <DQM/EcalBarrelMonitorClient/interface/EBStatusFlagsClient.h>
00024 
00025 using namespace cms;
00026 using namespace edm;
00027 using namespace std;
00028 
00029 EBStatusFlagsClient::EBStatusFlagsClient(const ParameterSet& ps) {
00030 
00031   // cloneME switch
00032   cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00033 
00034   // verbose switch
00035   verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
00036 
00037   // debug switch
00038   debug_ = ps.getUntrackedParameter<bool>("debug", false);
00039 
00040   // prefixME path
00041   prefixME_ = ps.getUntrackedParameter<string>("prefixME", "");
00042 
00043   // enableCleanup_ switch
00044   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00045 
00046   // vector of selected Super Modules (Defaults to all 36).
00047   superModules_.reserve(36);
00048   for ( unsigned int i = 1; i <= 36; i++ ) superModules_.push_back(i);
00049   superModules_ = ps.getUntrackedParameter<vector<int> >("superModules", superModules_);
00050 
00051   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00052 
00053     int ism = superModules_[i];
00054 
00055     h01_[ism-1] = 0;
00056 
00057     meh01_[ism-1] = 0;
00058 
00059     h02_[ism-1] = 0;
00060 
00061     meh02_[ism-1] = 0;
00062 
00063   }
00064 
00065 }
00066 
00067 EBStatusFlagsClient::~EBStatusFlagsClient() {
00068 
00069 }
00070 
00071 void EBStatusFlagsClient::beginJob(DQMStore* dqmStore) {
00072 
00073   dqmStore_ = dqmStore;
00074 
00075   if ( debug_ ) cout << "EBStatusFlagsClient: beginJob" << endl;
00076 
00077   ievt_ = 0;
00078   jevt_ = 0;
00079 
00080 }
00081 
00082 void EBStatusFlagsClient::beginRun(void) {
00083 
00084   if ( debug_ ) cout << "EBStatusFlagsClient: beginRun" << endl;
00085 
00086   jevt_ = 0;
00087 
00088   this->setup();
00089 
00090 }
00091 
00092 void EBStatusFlagsClient::endJob(void) {
00093 
00094   if ( debug_ ) cout << "EBStatusFlagsClient: endJob, ievt = " << ievt_ << endl;
00095 
00096   this->cleanup();
00097 
00098 }
00099 
00100 void EBStatusFlagsClient::endRun(void) {
00101 
00102   if ( debug_ ) cout << "EBStatusFlagsClient: endRun, jevt = " << jevt_ << endl;
00103 
00104   this->cleanup();
00105 
00106 }
00107 
00108 void EBStatusFlagsClient::setup(void) {
00109 
00110   dqmStore_->setCurrentFolder( prefixME_ + "/EBStatusFlagsClient" );
00111 
00112 }
00113 
00114 void EBStatusFlagsClient::cleanup(void) {
00115 
00116   if ( ! enableCleanup_ ) return;
00117 
00118   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00119 
00120     int ism = superModules_[i];
00121 
00122     if ( cloneME_ ) {
00123       if ( h01_[ism-1] ) delete h01_[ism-1];
00124       if ( h02_[ism-1] ) delete h02_[ism-1];
00125     }
00126 
00127     h01_[ism-1] = 0;
00128     h02_[ism-1] = 0;
00129 
00130     meh01_[ism-1] = 0;
00131     meh02_[ism-1] = 0;
00132 
00133   }
00134 
00135   dqmStore_->setCurrentFolder( prefixME_ + "/EBStatusFlagsClient" );
00136 
00137 }
00138 
00139 bool EBStatusFlagsClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status, bool flag) {
00140 
00141   status = true;
00142 
00143   if ( ! flag ) return false;
00144 
00145   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00146 
00147     int ism = superModules_[i];
00148 
00149     if ( verbose_ ) {
00150       cout << " " << Numbers::sEB(ism) << " (ism=" << ism << ")" << endl;
00151       cout << endl;
00152       UtilsClient::printBadChannels(meh01_[ism-1], UtilsClient::getHisto<TH2F*>(meh01_[ism-1]), true);
00153     }
00154 
00155     if ( meh01_[ism-1] ) {
00156       if ( meh01_[ism-1]->getEntries() != 0 ) status = false;
00157     }
00158 
00159   }
00160 
00161   return true;
00162 
00163 }
00164 
00165 void EBStatusFlagsClient::analyze(void) {
00166 
00167   ievt_++;
00168   jevt_++;
00169   if ( ievt_ % 10 == 0 ) {
00170     if ( debug_ ) cout << "EBStatusFlagsClient: ievt/jevt = " << ievt_ << "/" << jevt_ << endl;
00171   }
00172 
00173   char histo[200];
00174 
00175   MonitorElement* me;
00176 
00177   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00178 
00179     int ism = superModules_[i];
00180 
00181     sprintf(histo, (prefixME_ + "/EBStatusFlagsTask/FEStatus/EBSFT front-end status %s").c_str(), Numbers::sEB(ism).c_str());
00182     me = dqmStore_->get(histo);
00183     h01_[ism-1] = UtilsClient::getHisto<TH2F*>( me, cloneME_, h01_[ism-1] );
00184     meh01_[ism-1] = me;
00185 
00186     sprintf(histo, (prefixME_ + "/EBStatusFlagsTask/FEStatus/EBSFT front-end status bits %s").c_str(), Numbers::sEB(ism).c_str());
00187     me = dqmStore_->get(histo);
00188     h02_[ism-1] = UtilsClient::getHisto<TH1F*>( me, cloneME_, h02_[ism-1] );
00189     meh02_[ism-1] = me;
00190 
00191   }
00192 
00193 }
00194 
00195 void EBStatusFlagsClient::softReset(bool flag) {
00196 
00197 }
00198 
00199 void EBStatusFlagsClient::htmlOutput(int run, string& htmlDir, string& htmlName) {
00200 
00201   if ( verbose_ ) cout << "Preparing EBStatusFlagsClient html output ..." << endl;
00202 
00203   ofstream htmlFile;
00204 
00205   htmlFile.open((htmlDir + htmlName).c_str());
00206 
00207   // html page header
00208   htmlFile << "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">  " << endl;
00209   htmlFile << "<html>  " << endl;
00210   htmlFile << "<head>  " << endl;
00211   htmlFile << "  <meta content=\"text/html; charset=ISO-8859-1\"  " << endl;
00212   htmlFile << " https-equiv=\"content-type\">  " << endl;
00213   htmlFile << "  <title>Monitor:StatusFlagsTask output</title> " << endl;
00214   htmlFile << "</head>  " << endl;
00215   htmlFile << "<style type=\"text/css\"> td { font-weight: bold } </style>" << endl;
00216   htmlFile << "<body>  " << endl;
00217   //htmlFile << "<br>  " << endl;
00218   htmlFile << "<a name=""top""></a>" << endl;
00219   htmlFile << "<h2>Run:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" << endl;
00220   htmlFile << "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span " << endl;
00221   htmlFile << " style=\"color: rgb(0, 0, 153);\">" << run << "</span></h2>" << endl;
00222   htmlFile << "<h2>Monitoring task:&nbsp;&nbsp;&nbsp;&nbsp; <span " << endl;
00223   htmlFile << " style=\"color: rgb(0, 0, 153);\">DATA FLAGS</span></h2> " << endl;
00224   htmlFile << "<hr>" << endl;
00225   htmlFile << "<table border=1><tr><td bgcolor=red>channel has problems in this task</td>" << endl;
00226   htmlFile << "<td bgcolor=lime>channel has NO problems</td>" << endl;
00227   htmlFile << "<td bgcolor=yellow>channel is missing</td></table>" << endl;
00228   htmlFile << "<br>" << endl;
00229   htmlFile << "<table border=1>" << std::endl;
00230   for ( unsigned int i=0; i<superModules_.size(); i ++ ) {
00231     htmlFile << "<td bgcolor=white><a href=""#"
00232              << Numbers::sEB(superModules_[i]) << ">"
00233              << setfill( '0' ) << setw(2) << superModules_[i] << "</a></td>";
00234   }
00235   htmlFile << std::endl << "</table>" << std::endl;
00236 
00237   // Produce the plots to be shown as .png files from existing histograms
00238 
00239   const int csize = 250;
00240 
00241   const double histMax = 1.e15;
00242 
00243   int pCol5[10];
00244   for ( int i = 0; i < 10; i++ ) pCol5[i] = 501+i;
00245 
00246   TH2C dummy( "dummy", "dummy for sm", 17, 0., 17., 4, 0., 4. );
00247   for ( int i = 0; i < 68; i++ ) {
00248     int a = ( i/4 );
00249     int b = ( i%4 );
00250     dummy.Fill( a, b, i+1 );
00251   }
00252   dummy.SetMarkerSize(2);
00253   dummy.SetMinimum(0.1);
00254 
00255   string imgNameQual, imgNameBits, imgName, meName;
00256 
00257   TCanvas* cStatus = new TCanvas("cStatus", "Temp", 3*csize, csize);
00258   TCanvas* cStatusBits = new TCanvas("cStatusBits", "Temp", 3*csize, csize);
00259 
00260   TH2F* obj2f;
00261   TH1F* obj1f;
00262 
00263   // Loop on barrel supermodules
00264 
00265   for ( unsigned int i=0; i<superModules_.size(); i ++ ) {
00266 
00267     int ism = superModules_[i];
00268 
00269     // Quality plots
00270 
00271     imgNameQual = "";
00272 
00273     obj2f = h01_[ism-1];
00274 
00275     if ( obj2f ) {
00276 
00277       meName = obj2f->GetName();
00278 
00279       replace(meName.begin(), meName.end(), ' ', '_');
00280       imgNameQual = meName + ".png";
00281       imgName = htmlDir + imgNameQual;
00282 
00283       cStatus->cd();
00284       gStyle->SetOptStat(" ");
00285       gStyle->SetPalette(10, pCol5);
00286       obj2f->GetXaxis()->SetNdivisions(17);
00287       obj2f->GetYaxis()->SetNdivisions(4);
00288       cStatus->SetGridx();
00289       cStatus->SetGridy();
00290       obj2f->SetMinimum(0.0);
00291       obj2f->Draw("colz");
00292       dummy.Draw("text,same");
00293       cStatus->Update();
00294       cStatus->SaveAs(imgName.c_str());
00295 
00296     }
00297 
00298     imgNameBits = "";
00299 
00300     obj1f = h02_[ism-1];
00301 
00302     if ( obj1f ) {
00303 
00304       meName = obj1f->GetName();
00305 
00306       replace(meName.begin(), meName.end(), ' ', '_');
00307       imgNameBits = meName + ".png";
00308       imgName = htmlDir + imgNameBits;
00309 
00310       cStatusBits->cd();
00311       gStyle->SetOptStat("e");
00312       obj1f->SetStats(kTRUE);
00313       if ( obj1f->GetMaximum(histMax) > 0. ) {
00314         gPad->SetLogy(kTRUE);
00315       } else {
00316         gPad->SetLogy(kFALSE);
00317       }
00318       gPad->SetBottomMargin(0.25);
00319       obj1f->GetXaxis()->LabelsOption("v");
00320       obj1f->GetXaxis()->SetLabelSize(0.05);
00321       obj1f->Draw();
00322       cStatusBits->Update();
00323       cStatusBits->SaveAs(imgName.c_str());
00324       gPad->SetLogy(kFALSE);
00325 
00326     }
00327 
00328     if( i>0 ) htmlFile << "<a href=""#top"">Top</a>" << std::endl;
00329     htmlFile << "<hr>" << std::endl;
00330     htmlFile << "<h3><a name="""
00331              << Numbers::sEB(ism) << """></a><strong>"
00332              << Numbers::sEB(ism) << "</strong></h3>" << endl;
00333     htmlFile << "<table border=\"0\" cellspacing=\"0\" " << endl;
00334     htmlFile << "cellpadding=\"10\" align=\"center\"> " << endl;
00335     htmlFile << "<tr align=\"center\">" << endl;
00336 
00337     if ( imgNameQual.size() != 0 )
00338       htmlFile << "<td colspan=\"2\"><img src=\"" << imgNameQual << "\"></td>" << endl;
00339     else
00340       htmlFile << "<td colspan=\"2\"><img src=\"" << " " << "\"></td>" << endl;
00341 
00342     htmlFile << "</tr>" << endl;
00343     htmlFile << "<tr>" << endl;
00344 
00345     if ( imgNameBits.size() != 0 )
00346       htmlFile << "<td colspan=\"2\"><img src=\"" << imgNameBits << "\"></td>" << endl;
00347     else
00348       htmlFile << "<td colspan=\"2\"><img src=\"" << " " << "\"></td>" << endl;
00349 
00350     htmlFile << "</tr>" << endl;
00351 
00352     htmlFile << "</table>" << endl;
00353     htmlFile << "<br>" << endl;
00354 
00355   }
00356 
00357   delete cStatus;
00358   delete cStatusBits;
00359 
00360   // html page footer
00361   htmlFile << "</body> " << endl;
00362   htmlFile << "</html> " << endl;
00363 
00364   htmlFile.close();
00365 
00366 }
00367 

Generated on Tue Jun 9 17:32:44 2009 for CMSSW by  doxygen 1.5.4