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