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 void HcalBaseDQClient::beginJob()
00034 {
00035 dqmStore_ = edm::Service<DQMStore>().operator->();
00036 if (debug_>0)
00037 {
00038 std::cout <<"<HcalBaseDQClient::beginJob()> Displaying dqmStore directory structure:"<<std::endl;
00039 dqmStore_->showDirStructure();
00040 }
00041 }
00042
00043 void HcalBaseDQClient::setStatusMap(std::map<HcalDetId, unsigned int>& map)
00044 {
00045
00046
00047
00048
00049
00050 if (debug_>1) std::cout <<"<HcalBaseDQClient::setStatusMap> Input map size = "<<map.size()<<std::endl;
00051 for (std::map<HcalDetId, unsigned int>::const_iterator iter = map.begin();
00052 iter!=map.end();++iter)
00053 {
00054 if ((iter->second & badChannelStatusMask_) == 0 ) continue;
00055 badstatusmap[iter->first]=iter->second;
00056 }
00057
00058 if (debug_>1) std::cout <<"<HcalBaseDQClient::setStatusMap> "<<name_<<" Output map size = "<<badstatusmap.size()<<std::endl;
00059 }
00060
00061
00062 bool HcalBaseDQClient::validHtmlOutput()
00063 {
00064 return validHtmlOutput_;
00065 }
00066
00067 void HcalBaseDQClient::htmlOutput(std::string htmlDir)
00068 {
00069 if (dqmStore_==0)
00070 {
00071 if (debug_>0) std::cout <<"<HcalBaseDQClient::htmlOutput> dqmStore object does not exist!"<<std::endl;
00072 return;
00073 }
00074
00075 if (debug_>2) std::cout <<"\t<HcalBaseDQClient::htmlOutput> Preparing html for task: "<<name_<<std::endl;
00076 int pcol_error[105];
00077 for( int i=0; i<105; ++i )
00078 {
00079
00080 TColor* color = gROOT->GetColor( 901+i );
00081 if( ! color ) color = new TColor( 901+i, 0, 0, 0, "" );
00082 if (i<5)
00083 color->SetRGB(i/5.,1.,0);
00084 else if (i>100)
00085 color->SetRGB(0,0,0);
00086 else
00087 color->SetRGB(1,1-0.01*i,0);
00088 pcol_error[i]=901+i;
00089 }
00090
00091 ofstream htmlFile;
00092 std::string outfile=htmlDir+name_+".html";
00093 htmlFile.open(outfile.c_str());
00094
00095
00096 htmlFile << "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"> " << std::endl;
00097 htmlFile << "<html> " << std::endl;
00098 htmlFile << "<head> " << std::endl;
00099 htmlFile << " <meta content=\"text/html; charset=ISO-8859-1\" " << std::endl;
00100 htmlFile << " http-equiv=\"content-type\"> " << std::endl;
00101 htmlFile << " <title>Monitor: Hcal "<<name_<<" output</title> " << std::endl;
00102 htmlFile << "</head> " << std::endl;
00103 htmlFile << "<style type=\"text/css\"> td { font-weight: bold } </style>" << std::endl;
00104 htmlFile << "<body> " << std::endl;
00105 htmlFile << "<br> " << std::endl;
00106 htmlFile << "<hr>" << std::endl;
00107
00108 gStyle->SetPalette(105,pcol_error);
00109 gStyle->SetNumberContours(105);
00110 gROOT->ForceStyle();
00111
00112 if (debug_>0) std::cout <<"<HcalBaseDQClient::htmlOutput> Writing html output for client "<<this->name()<<std::endl;
00113 if (ProblemCells!=0)
00114 {
00115 (ProblemCells->getTH2F())->SetMaximum(1.05);
00116 (ProblemCells->getTH2F())->SetMinimum(0.);
00117 htmlFile << "<table align=\"center\" border=\"1\" cellspacing=\"0\" " << std::endl;
00118 htmlFile << "cellpadding=\"10\"> " << std::endl;
00119 htmlFile<<"<tr align=\"center\">"<<std::endl;
00120 htmlAnyHisto(-1,ProblemCells->getTH2F(),"ieta","iphi",92, htmlFile,htmlDir,debug_);
00121 htmlFile<<"</tr>"<<std::endl;
00122 htmlFile<<"</table>"<<std::endl;
00123 }
00124 if (ProblemCellsByDepth!=0)
00125 {
00126 htmlFile << "<table align=\"center\" border=\"1\" cellspacing=\"0\" " << std::endl;
00127 htmlFile << "cellpadding=\"10\"> " << std::endl;
00128 for (unsigned int i=0;i<ProblemCellsByDepth->depth.size()/2;++i)
00129 {
00130 if (ProblemCellsByDepth->depth[2*i]==0) continue;
00131 if (ProblemCellsByDepth->depth[2*i+1]==0) continue;
00132 (ProblemCellsByDepth->depth[2*i]->getTH2F())->SetMaximum(1.05);
00133 (ProblemCellsByDepth->depth[2*i]->getTH2F())->SetMinimum(0.);
00134 (ProblemCellsByDepth->depth[2*i+1]->getTH2F())->SetMaximum(1.05);
00135 (ProblemCellsByDepth->depth[2*i+1]->getTH2F())->SetMinimum(0.);
00136 htmlFile<<"<tr align=\"center\">"<<std::endl;
00137 htmlAnyHisto(-1,ProblemCellsByDepth->depth[2*i]->getTH2F(),"ieta","iphi",92, htmlFile,htmlDir,debug_);
00138 htmlAnyHisto(-1,ProblemCellsByDepth->depth[2*i+1]->getTH2F(),"ieta","iphi",92, htmlFile,htmlDir,debug_);
00139
00140 htmlFile<<"</tr>"<<std::endl;
00141 }
00142 htmlFile<<"</table>"<<std::endl;
00143 }
00144
00145 htmlFile << "<table align=\"center\" border=\"1\" cellspacing=\"0\" " << std::endl;
00146 htmlFile << "cellpadding=\"10\"> " << std::endl;
00147
00148
00149 std::vector<MonitorElement*> hists = dqmStore_->getAllContents(subdir_);
00150 gStyle->SetPalette(1);
00151
00152 int counter=0;
00153 for (unsigned int i=0;i<hists.size();++i)
00154 {
00155 if (hists[i]->kind()==MonitorElement::DQM_KIND_TH1F)
00156 {
00157 ++counter;
00158 if (counter%2==1)
00159 htmlFile << "<tr align=\"center\">" << std::endl;
00160 htmlAnyHisto(-1,(hists[i]->getTH1F()),"","", 92, htmlFile, htmlDir,debug_);
00161 if (counter%2==2)
00162 htmlFile <<"</tr>"<<std::endl;
00163 }
00164
00165 else if (hists[i]->kind()==MonitorElement::DQM_KIND_TH2F)
00166 {
00167 std::string histname=hists[i]->getName();
00168 bool isproblem=false;
00169 for (unsigned int j=0;j<problemnames_.size();++j)
00170 {
00171 if (problemnames_[j]==histname)
00172 {
00173 isproblem=true;
00174 if (debug_>1) std::cout <<"<HcalBaseDQClient::htmlOutput> Found Problem Histogram '"<<histname<<"' in list of histograms"<<std::endl;
00175 break;
00176 }
00177 }
00178 if (isproblem) continue;
00179 ++counter;
00180 if (counter%2==1)
00181 htmlFile << "<tr align=\"center\">" << std::endl;
00182 htmlAnyHisto(-1,(hists[i]->getTH2F()),"","", 92, htmlFile, htmlDir,debug_);
00183 if (counter%2==2)
00184 htmlFile <<"</tr>"<<std::endl;
00185 }
00186
00187 else if (hists[i]->kind()==MonitorElement::DQM_KIND_TPROFILE)
00188 {
00189 ++counter;
00190 if (counter%2==1)
00191 htmlFile << "<tr align=\"center\">" << std::endl;
00192 htmlAnyHisto(-1,(hists[i]->getTProfile()),"","", 92, htmlFile, htmlDir,debug_);
00193 if (counter%2==2)
00194 htmlFile <<"</tr>"<<std::endl;
00195 }
00196 }
00197 htmlFile<<"</table>"<<std::endl;
00198 htmlFile << "</body> " << std::endl;
00199 htmlFile << "</html> " << std::endl;
00200 htmlFile.close();
00201 return;
00202 }