CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/DQM/HcalMonitorClient/src/HcalBaseDQClient.cc

Go to the documentation of this file.
00001 #include "DQM/HcalMonitorClient/interface/HcalBaseDQClient.h"
00002 #include "DQM/HcalMonitorClient/interface/HcalHistoUtils.h"
00003 #include "DQM/HcalMonitorClient/interface/HcalClientUtils.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00005 #include <iostream>
00006 #include <fstream>
00007 
00008 HcalBaseDQClient::HcalBaseDQClient(std::string s, const edm::ParameterSet& ps)
00009 {
00010   name_=s;
00011   enableCleanup_         = ps.getUntrackedParameter<bool>("enableCleanup",false);
00012   debug_                 = ps.getUntrackedParameter<int>("debug",0);
00013   prefixME_              = ps.getUntrackedParameter<std::string>("subSystemFolder","Hcal/");
00014   if (prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
00015     prefixME_.append("/");
00016 
00017   validHtmlOutput_       = ps.getUntrackedParameter<bool>("validHtmlOutput",true);
00018   Online_                = ps.getUntrackedParameter<bool>("online",false);
00019 
00020   subdir_="HcalInfo/";
00021   subdir_=prefixME_+subdir_;
00022 
00023   cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00024   badChannelStatusMask_   = 0;
00025   enoughevents_=true;
00026   minerrorrate_=0;
00027   minevents_=0;
00028 
00029   ProblemCells=0;
00030   ProblemCellsByDepth=0;
00031 }
00032 
00033 HcalBaseDQClient::~HcalBaseDQClient()
00034 {}
00035 
00036 void HcalBaseDQClient::beginJob()
00037 {
00038   dqmStore_ = edm::Service<DQMStore>().operator->();
00039   if (debug_>0) 
00040     {
00041       std::cout <<"<HcalBaseDQClient::beginJob()>  Displaying dqmStore directory structure:"<<std::endl;
00042       dqmStore_->showDirStructure();
00043     }
00044 }
00045 
00046 void HcalBaseDQClient::setStatusMap(std::map<HcalDetId, unsigned int>& map)
00047   {
00048     /* Get the list of all bad channels in the status map,
00049        and combine it with the bad cell requirements for the particular task
00050        to form a new map
00051     */
00052 
00053     if (debug_>1) std::cout <<"<HcalBaseDQClient::setStatusMap>  Input map size = "<<map.size()<<std::endl;
00054     for (std::map<HcalDetId, unsigned int>::const_iterator iter = map.begin(); 
00055          iter!=map.end();++iter)
00056       {
00057         if ((iter->second & badChannelStatusMask_) == 0 ) continue; // channel not marked as bad by this test
00058         badstatusmap[iter->first]=iter->second;
00059       }
00060     
00061     if (debug_>1) std::cout <<"<HcalBaseDQClient::setStatusMap>  "<<name_<<" Output map size = "<<badstatusmap.size()<<std::endl;
00062   } // void HcalBaseDQClient::getStatusMap
00063 
00064 
00065 bool HcalBaseDQClient::validHtmlOutput()
00066 {
00067   return validHtmlOutput_;
00068 }
00069 
00070 void HcalBaseDQClient::htmlOutput(std::string htmlDir)
00071 {
00072   if (dqmStore_==0) 
00073     {
00074       if (debug_>0) std::cout <<"<HcalBaseDQClient::htmlOutput> dqmStore object does not exist!"<<std::endl;
00075       return;
00076     }
00077 
00078   if (debug_>2) std::cout <<"\t<HcalBaseDQClient::htmlOutput>  Preparing html for task: "<<name_<<std::endl;
00079   int pcol_error[105];
00080  for( int i=0; i<105; ++i )
00081     {
00082       
00083       TColor* color = gROOT->GetColor( 901+i );
00084       if( ! color ) color = new TColor( 901+i, 0, 0, 0, "" );
00085       if (i<5)
00086         color->SetRGB(i/5.,1.,0);
00087       else if (i>100)
00088         color->SetRGB(0,0,0);
00089       else
00090         color->SetRGB(1,1-0.01*i,0);
00091       pcol_error[i]=901+i;
00092     } // for (int i=0;i<105;++i)
00093 
00094   ofstream htmlFile;
00095   std::string outfile=htmlDir+name_+".html";
00096   htmlFile.open(outfile.c_str());
00097 
00098   // html page header
00099   htmlFile << "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">  " << std::endl;
00100   htmlFile << "<html>  " << std::endl;
00101   htmlFile << "<head>  " << std::endl;
00102   htmlFile << "  <meta content=\"text/html; charset=ISO-8859-1\"  " << std::endl;
00103   htmlFile << " http-equiv=\"content-type\">  " << std::endl;
00104   htmlFile << "  <title>Monitor: Hcal "<<name_<<" output</title> " << std::endl;
00105   htmlFile << "</head>  " << std::endl;
00106   htmlFile << "<style type=\"text/css\"> td { font-weight: bold } </style>" << std::endl;
00107   htmlFile << "<body>  " << std::endl;
00108   htmlFile << "<br>  " << std::endl;
00109   htmlFile << "<hr>" << std::endl;
00110 
00111   gStyle->SetPalette(105,pcol_error);
00112   gStyle->SetNumberContours(105);
00113   gROOT->ForceStyle();
00114 
00115   if (debug_>0) std::cout <<"<HcalBaseDQClient::htmlOutput>  Writing html output for client "<<this->name()<<std::endl;
00116   if (ProblemCells!=0)
00117     {
00118       (ProblemCells->getTH2F())->SetMaximum(1.05);
00119       (ProblemCells->getTH2F())->SetMinimum(0.);
00120       htmlFile << "<table align=\"center\" border=\"1\" cellspacing=\"0\" " << std::endl;
00121       htmlFile << "cellpadding=\"10\"> " << std::endl;
00122       htmlFile<<"<tr align=\"center\">"<<std::endl;
00123       htmlAnyHisto(-1,ProblemCells->getTH2F(),"ieta","iphi",92, htmlFile,htmlDir,debug_);
00124       htmlFile<<"</tr>"<<std::endl;
00125       htmlFile<<"</table>"<<std::endl;
00126     }
00127   if (ProblemCellsByDepth!=0)
00128     {
00129       htmlFile << "<table align=\"center\" border=\"1\" cellspacing=\"0\" " << std::endl;
00130       htmlFile << "cellpadding=\"10\"> " << std::endl;
00131       for (unsigned int i=0;i<ProblemCellsByDepth->depth.size()/2;++i)
00132         {
00133           if (ProblemCellsByDepth->depth[2*i]==0) continue;
00134           if (ProblemCellsByDepth->depth[2*i+1]==0) continue;
00135           (ProblemCellsByDepth->depth[2*i]->getTH2F())->SetMaximum(1.05);
00136           (ProblemCellsByDepth->depth[2*i]->getTH2F())->SetMinimum(0.);
00137           (ProblemCellsByDepth->depth[2*i+1]->getTH2F())->SetMaximum(1.05);
00138           (ProblemCellsByDepth->depth[2*i+1]->getTH2F())->SetMinimum(0.);
00139           htmlFile<<"<tr align=\"center\">"<<std::endl;
00140           htmlAnyHisto(-1,ProblemCellsByDepth->depth[2*i]->getTH2F(),"ieta","iphi",92, htmlFile,htmlDir,debug_);
00141           htmlAnyHisto(-1,ProblemCellsByDepth->depth[2*i+1]->getTH2F(),"ieta","iphi",92, htmlFile,htmlDir,debug_);
00142           
00143           htmlFile<<"</tr>"<<std::endl;
00144         }
00145       htmlFile<<"</table>"<<std::endl;
00146    }
00147     
00148   htmlFile << "<table align=\"center\" border=\"1\" cellspacing=\"0\" " << std::endl;
00149   htmlFile << "cellpadding=\"10\"> " << std::endl;
00150   
00151 
00152   std::vector<MonitorElement*> hists = dqmStore_->getAllContents(subdir_);
00153   gStyle->SetPalette(1);
00154   
00155   int counter=0;
00156   for (unsigned int i=0;i<hists.size();++i)
00157     {
00158       if (hists[i]->kind()==MonitorElement::DQM_KIND_TH1F)
00159         {
00160           ++counter;
00161           if (counter%2==1) 
00162             htmlFile << "<tr align=\"center\">" << std::endl;
00163           htmlAnyHisto(-1,(hists[i]->getTH1F()),"","", 92, htmlFile, htmlDir,debug_);
00164           if (counter%2==2)
00165             htmlFile <<"</tr>"<<std::endl;
00166         }
00167 
00168       else if (hists[i]->kind()==MonitorElement::DQM_KIND_TH2F)
00169         {
00170           std::string histname=hists[i]->getName();
00171           bool isproblem=false;
00172           for (unsigned int j=0;j<problemnames_.size();++j)
00173             {
00174               if (problemnames_[j]==histname)
00175                 {
00176                   isproblem=true;
00177                   if (debug_>1) std::cout <<"<HcalBaseDQClient::htmlOutput>  Found Problem Histogram '"<<histname<<"' in list of histograms"<<std::endl;
00178                   break;
00179                 }       
00180             }
00181           if (isproblem) continue; // don't redraw problem histograms
00182           ++counter;
00183           if (counter%2==1) 
00184             htmlFile << "<tr align=\"center\">" << std::endl;
00185           htmlAnyHisto(-1,(hists[i]->getTH2F()),"","", 92, htmlFile, htmlDir,debug_);
00186           if (counter%2==2)
00187             htmlFile <<"</tr>"<<std::endl;
00188         }
00189 
00190       else if (hists[i]->kind()==MonitorElement::DQM_KIND_TPROFILE)
00191         {
00192           ++counter;
00193           if (counter%2==1) 
00194             htmlFile << "<tr align=\"center\">" << std::endl;
00195           htmlAnyHisto(-1,(hists[i]->getTProfile()),"","", 92, htmlFile, htmlDir,debug_);
00196           if (counter%2==2)
00197             htmlFile <<"</tr>"<<std::endl;
00198         }
00199     }
00200   htmlFile<<"</table>"<<std::endl;
00201   htmlFile << "</body> " << std::endl;
00202   htmlFile << "</html> " << std::endl;
00203   htmlFile.close();
00204   return;
00205 }