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