CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/DQM/HcalMonitorClient/src/HcalClientUtils.cc

Go to the documentation of this file.
00001 #include "DQM/HcalMonitorClient/interface/HcalClientUtils.h"
00002 #include "DQMServices/Core/interface/DQMStore.h"
00003 #include "DQMServices/Core/interface/MonitorElement.h"
00004 #include <cstdlib>
00005 
00006 
00007 void resetME(const char* name, DQMStore* dbe){
00008   if(dbe==NULL) return;
00009   MonitorElement* me= dbe->get(name);
00010   if(me) dbe->softReset(me);
00011   return;
00012 }
00013 
00014 bool isValidGeom(std::string type, int depth)
00015 {
00016   if (type=="HB" && (depth==1 || depth==2))
00017     return true;
00018   if (type=="HE" && (depth==1 || depth==2 || depth==3))
00019     return true;
00020   if (type=="HO" && (depth==4))
00021     return true;
00022   if (type=="HF" && (depth==1 || depth==2))
00023     return true;
00024   return false;
00025 }
00026 
00027 bool isValidGeom(int subdet, int iEta, int iPhi, int depth){
00028   
00029   if(subdet<0 || subdet>3) return false;
00030   
00031   int EtaMin[4]; int EtaMax[4];
00032   int PhiMin[4]; int PhiMax[4];
00033   int DepMin[4]; int DepMax[4];
00034   
00035   //HB ieta/iphi/depths
00036   EtaMin[0]=1; EtaMax[0]=16;
00037   PhiMin[0]=1; PhiMax[0]=72;
00038   DepMin[0]=1; DepMax[0]=2;
00039   
00040   //HE ieta/iPhi/Depths
00041   EtaMin[1]=16; EtaMax[1]=29;
00042   PhiMin[1]=1; PhiMax[1]=72;
00043   DepMin[1]=1; DepMax[1]=3;
00044   
00045   //HF ieta/iphi/depths
00046   EtaMin[2]=29; EtaMax[2]=41;
00047   PhiMin[2]=1; PhiMax[2]=72;
00048   DepMin[2]=1; DepMax[2]=2;
00049   
00050   //HO ieta/iphi/depths
00051   EtaMin[3]=1; EtaMax[3]=15;
00052   PhiMin[3]=1; PhiMax[3]=72;
00053   DepMin[3]=4; DepMax[3]=4;
00054   
00055   if(iEta!=0) if(abs(iEta)<EtaMin[subdet] || abs(iEta)>EtaMax[subdet]) return false;
00056   if(iPhi!=0) if(abs(iPhi)<PhiMin[subdet] || abs(iPhi)>PhiMax[subdet]) return false;
00057   if(depth!=0) if(abs(depth)<DepMin[subdet] || abs(depth)>DepMax[subdet]) return false;
00058   
00059   
00060   if(subdet==0 && abs(depth)==2 && abs(iEta)<15) return false;
00061   else if(subdet==1){
00062     if(abs(iEta)>20 && (iPhi%2)==0) return false;    
00063     if(abs(iEta)>39 && (iPhi%4)!=3) return false;    
00064     if(abs(iEta)==16 && abs(depth)!=3) return false;
00065     if(abs(iEta)==17 && abs(depth)!=1) return false;
00066     if(abs(depth)==3){
00067       if(abs(iEta)!=27 && abs(iEta)!=28 &&abs(iEta)!=16) return false;
00068     }
00069   }
00070   else if(subdet==2 && (iPhi%2)==0) return false;   
00071   
00072   return true;
00073 }
00074 
00075 void dumpHisto(TH1F* hist, std::vector<std::string> &names, 
00076                std::vector<double> &meanX, std::vector<double> &meanY, 
00077                std::vector<double> &rmsX, std::vector<double> &rmsY){
00078   
00079   names.push_back((std::string)hist->GetName());
00080   meanX.push_back(hist->GetMean(1));
00081   meanY.push_back(-123e10);
00082   rmsX.push_back(hist->GetRMS(1));
00083   rmsY.push_back(-123e10);  
00084   return;
00085 }
00086 void dumpHisto2(TH2F* hist, std::vector<std::string> &names, 
00087                std::vector<double> &meanX, std::vector<double> &meanY, 
00088                std::vector<double> &rmsX, std::vector<double> &rmsY){
00089   
00090   names.push_back((std::string)hist->GetName());
00091   meanX.push_back(hist->GetMean(1));
00092   meanY.push_back(hist->GetMean(2));
00093   rmsX.push_back(hist->GetRMS(1));
00094   rmsY.push_back(hist->GetRMS(2));
00095   return;
00096 }
00097 
00098 void cleanString(std::string& title){
00099 
00100   for ( unsigned int i = 0; i < title.size(); i++ ) {
00101     if ( title.substr(i, 6) == " - Run" ){
00102       title.replace(i, title.size()-i, "");
00103     }
00104     if ( title.substr(i, 4) == "_Run" ){
00105       title.replace(i, title.size()-i, "");
00106     }
00107     if ( title.substr(i, 5) == "__Run" ){
00108       title.replace(i, title.size()-i, "");
00109     }
00110   }
00111 }
00112 
00113 void parseString(std::string& title){
00114   
00115   for ( unsigned int i = 0; i < title.size(); i++ ) {
00116     if ( title.substr(i, 1) == " " ){
00117       title.replace(i, 1, "_");
00118     }
00119     if ( title.substr(i, 1) == "#" ){
00120       title.replace(i, 1, "N");
00121     }
00122     if ( title.substr(i, 1) == "-" ){
00123       title.replace(i, 1, "_");
00124     }    
00125     if ( title.substr(i, 1) == "&" ){
00126       title.replace(i, 1, "_and_");
00127     }
00128     if ( title.substr(i, 1) == "(" 
00129          || title.substr(i, 1) == ")" 
00130          )  {
00131       title.replace(i, 1, "_");
00132     }
00133   }
00134   
00135   return;
00136 }
00137 
00138 std::string getIMG2(int runNo,TH2F* hist, int size, std::string htmlDir, const char* xlab, const char* ylab,bool color){
00139 
00140   if(hist==NULL) {
00141     printf("getIMG2:  This histo is NULL, %s, %s\n",xlab,ylab);
00142     return "";
00143   }
00144 
00145   std::string name = hist->GetTitle();
00146   cleanString(name);
00147   char dest[512];
00148   if(runNo>-1) sprintf(dest,"%s - Run %d",name.c_str(),runNo);
00149   else sprintf(dest,"%s",name.c_str());
00150   hist->SetTitle(dest);
00151   std::string title = dest;
00152 
00153   int xwid = 900; int ywid =540;
00154   if(size==1){
00155     title = title+"_tmb";
00156     xwid = 600; ywid = 360;
00157   }
00158   TCanvas* can = new TCanvas(dest,dest, xwid, ywid);
00159 
00160   // Put grids on all 2-D histograms
00161   can->SetGridx();
00162   can->SetGridy();
00163   
00164 
00165   parseString(title);
00166   std::string outName = title + ".gif";
00167   std::string saveName = htmlDir + outName;
00168   hist->SetXTitle(xlab);
00169   hist->SetYTitle(ylab);
00170   if(color) hist->Draw();
00171   else{
00172     hist->SetStats(false);
00173     hist->Draw("COLZ");
00174   }
00175   can->SaveAs(saveName.c_str());  
00176   delete can;
00177 
00178   return outName;
00179 }
00180 
00181 std::string getIMG(int runNo,TH1F* hist, int size, std::string htmlDir, const char* xlab, const char* ylab){
00182 
00183   if(hist==NULL) {
00184     printf("getIMG:  This histo is NULL, %s, %s\n",xlab,ylab);
00185     return "";
00186   }
00187 
00188   std::string name = hist->GetTitle();
00189   cleanString(name);
00190   char dest[512];
00191   if(runNo>-1) sprintf(dest,"%s - Run %d",name.c_str(),runNo);
00192   else sprintf(dest,"%s",name.c_str());
00193   hist->SetTitle(dest);
00194   std::string title = dest;
00195 
00196   int xwid = 900; int ywid =540;
00197   if(size==1){
00198     title = title+"_tmb";
00199     xwid = 600; ywid = 360;
00200   }
00201   TCanvas* can = new TCanvas(dest,dest, xwid, ywid);
00202 
00203   parseString(title);
00204   std::string outName = title + ".gif";
00205   std::string saveName = htmlDir + outName;
00206   hist->SetXTitle(xlab);
00207   hist->SetYTitle(ylab);
00208   hist->Draw();
00209 
00210   can->SaveAs(saveName.c_str());  
00211   delete can;
00212 
00213   return outName;
00214 }
00215 
00216 TH2F* getHisto2(std::string name, std::string process, DQMStore* dbe_, bool verb, bool clone){
00217 
00218   if(!dbe_) return NULL;
00219 
00220   TH2F* out = NULL;
00221   char title[150];  
00222   sprintf(title, "%sHcal/%s",process.c_str(),name.c_str());
00223 
00224   MonitorElement* me = dbe_->get(title);
00225 
00226   if ( me ) {      
00227     if ( verb) std::cout << "Found '" << title << "'" << std::endl;
00228     if ( clone) {
00229       char histo[150];
00230       sprintf(histo, "ME %s",name.c_str());
00231       out = dynamic_cast<TH2F*> (me->getTH2F()->Clone(histo));
00232     } else {
00233       out = me->getTH2F();
00234     }
00235   }
00236   return out;
00237 }
00238 
00239 TH1F* getHisto(std::string name, std::string process, DQMStore* dbe_, bool verb, bool clone){
00240   if(!dbe_) return NULL;
00241   
00242   char title[150];  
00243   sprintf(title, "%sHcal/%s",process.c_str(),name.c_str());
00244   TH1F* out = NULL;
00245 
00246   const MonitorElement* me = dbe_->get(title);
00247   if (me){      
00248     if ( verb ) std::cout << "Found '" << title << "'" << std::endl;
00249     if ( clone ) {
00250       char histo[150];
00251       sprintf(histo, "ME %s",name.c_str());
00252       out = dynamic_cast<TH1F*> (me->getTH1F()->Clone(histo));
00253     } else {
00254       out = me->getTH1F();
00255     }
00256   }
00257 
00258   return out;
00259 }
00260 
00261 
00262 TH2F* getHisto2(const MonitorElement* me, bool verb,bool clone){
00263   
00264   TH2F* out = NULL;
00265 
00266   if ( me ) {      
00267     if ( verb) std::cout << "Found '" << me->getName() << "'" << std::endl;
00268     //    MonitorElementT<TNamed>* ob = dynamic_cast<MonitorElementT<TNamed>*> (me);
00269     if ( clone ) {
00270       char histo[150];
00271       sprintf(histo, "ME %s", ((std::string)(me->getName())).c_str());
00272       out = dynamic_cast<TH2F*> (me->getTH2F()->Clone(histo));
00273     } else {
00274       out = me->getTH2F();
00275     }
00276   }
00277   return out;
00278 }
00279 
00280 TH1F* getHisto(const MonitorElement* me, bool verb,bool clone){
00281   TH1F* out = NULL;
00282 
00283   if ( me ) {      
00284     if ( verb ) std::cout << "Found '" << me->getName() << "'" << std::endl;
00285     if ( clone ) {
00286       char histo[150];
00287       sprintf(histo, "ME %s",((std::string)(me->getName())).c_str());
00288       out = dynamic_cast<TH1F*> (me->getTH1F()->Clone(histo));
00289     } else {
00290       out = me->getTH1F();
00291     }
00292  }
00293   return out;
00294 }
00295 
00296 
00297 void histoHTML(int runNo, TH1F* hist, const char* xlab, const char* ylab, int width, ofstream& htmlFile, std::string htmlDir){
00298   
00299   if(hist!=NULL){    
00300     std::string imgNameTMB = "";   
00301     imgNameTMB = getIMG(runNo,hist,1,htmlDir,xlab,ylab); 
00302     std::string imgName = "";   
00303     imgName = getIMG(runNo,hist,2,htmlDir,xlab,ylab);  
00304 
00305     if (imgName.size() != 0 )
00306       htmlFile << "<td><a href=\"" <<  imgName << "\"><img src=\"" <<  imgNameTMB << "\"></a></td>" << std::endl;
00307     else
00308       htmlFile << "<td><img src=\"" << " " << "\"></td>" << std::endl;
00309   }
00310   else htmlFile << "<td><img src=\"" << " " << "\"></td>" << std::endl;
00311   return;
00312 }
00313 
00314 void histoHTML2(int runNo, TH2F* hist, const char* xlab, const char* ylab, int width, ofstream& htmlFile, std::string htmlDir, bool color){
00315   if(hist!=NULL){
00316     std::string imgNameTMB = "";
00317     imgNameTMB = getIMG2(runNo,hist,1,htmlDir,xlab,ylab,color);  
00318     std::string imgName = "";
00319     imgName = getIMG2(runNo,hist,2,htmlDir,xlab,ylab,color);  
00320     if (imgName.size() != 0 )
00321       htmlFile << "<td><a href=\"" <<  imgName << "\"><img src=\"" <<  imgNameTMB << "\"></a></td>" << std::endl;
00322     else
00323       htmlFile << "<td><img src=\"" << " " << "\"></td>" << std::endl;
00324   }
00325   else htmlFile << "<td><img src=\"" << " " << "\"></td>" << std::endl;
00326   return;
00327 }
00328 
00329 void createXRangeTest(DQMStore* dbe, std::vector<std::string>& params){
00330   if (params.size() < 6) return;
00331   if(!dbe) return;
00332 
00333   QCriterion* qc = dbe->getQCriterion(params[1]);
00334   if(qc == NULL){
00335     qc = dbe->createQTest(ContentsXRange::getAlgoName(),params[1]);
00336     // Contents within [Xmin, Xmax]
00337     ContentsXRange* me_qc = (ContentsXRange*) qc;
00338     //set probability limit for test warning 
00339     me_qc->setWarningProb(atof(params[2].c_str()));
00340     //set probability limit for test error 
00341     me_qc->setErrorProb(atof(params[3].c_str()));
00342     // set allowed range in X-axis (default values: histogram's X-range)
00343     me_qc->setAllowedXRange(atof(params[4].c_str()), atof(params[5].c_str()));
00344   }
00345   // link it to the monitor element
00346   dbe->useQTest(params[0], params[1]);
00347   return;
00348 }
00349 
00350 void createYRangeTest(DQMStore* dbe, std::vector<std::string>& params){
00351   if (params.size() < 6) return;
00352   if(!dbe) return;
00353 
00354   QCriterion* qc = dbe->getQCriterion(params[1]);
00355   if(qc == NULL){
00356     qc = dbe->createQTest(ContentsYRange::getAlgoName(),params[1]);
00357     // Contents within [Xmin, Xmax]
00358     ContentsYRange* me_qc = (ContentsYRange*) qc;
00359     //set probability limit for test warning 
00360     me_qc->setWarningProb(atof(params[2].c_str()));
00361     //set probability limit for test error 
00362     me_qc->setErrorProb(atof(params[3].c_str()));
00363     // set allowed range in Y-axis (default values: histogram's Y-range)
00364     me_qc->setAllowedYRange(atof(params[4].c_str()), atof(params[5].c_str()));
00365   }
00366   // link it to the monitor element
00367   dbe->useQTest(params[0], params[1]);
00368   return;
00369 }
00370 
00371 void createMeanValueTest(DQMStore* dbe, std::vector<std::string>& params){
00372   if (params.size() < 7 ) return;
00373   if(!dbe) return;
00374 
00375   QCriterion* qc = dbe->getQCriterion(params[1]);
00376   if(qc == NULL){
00377     qc = dbe->createQTest("MeanWithinExpected",params[1]);
00378     // Contents within a mean value
00379     MeanWithinExpected* me_qc = (MeanWithinExpected*) qc;
00380     //set probability limit for test warning
00381     me_qc->setWarningProb(atof(params[2].c_str()));
00382     //set probability limit for test error
00383     me_qc->setErrorProb(atof(params[3].c_str()));
00384     // set Expected Mean
00385     me_qc->setExpectedMean(atof(params[4].c_str()));
00386     // set Test Type
00387     if (params[6] == "useRMS") me_qc->useRMS();
00388     else if (params[6] == "useSigma") me_qc->useSigma(atof(params[5].c_str()));
00389   }
00390   // link it to the monitor element
00391   dbe->useQTest(params[0], params[1]);
00392   return;
00393 }
00394 
00395 void createH2ContentTest(DQMStore* dbe, std::vector<std::string>& params){
00396   if (params.size() < 2 ) return;
00397   if(!dbe) return;
00398 
00399   QCriterion* qc = dbe->getQCriterion(params[1]);
00400   MonitorElement* me =  dbe->get(params[0]);
00401   if(me!=NULL && qc == NULL){
00402     /*  Time to get with 
00403   DQMServices/Core V03-00-12-qtest
00404   DQMServices/ClientConfig V03-00-04-qtest
00405     qc = dbe->createQTest(ContentsTH2FWithinRange::getAlgoName(),params[1]);
00406     // Contents within a mean value     
00407     ContentsTH2FWithinRangeROOT* me_qc = dynamic_cast<ContentsTH2FWithinRangeROOT*> (qc);
00408     me_qc->setMeanRange(0,1e-10);
00409     me_qc->setRMSRange(0,1e-10);
00410     // link it to the monitor element
00411     dbe->useQTest(params[0], params[1]);
00412     */
00413   }
00414   
00415   return;
00416 }
00417 
00418 void createH2CompTest(DQMStore* dbe, std::vector<std::string>& params, TH2F* ref){
00419   if (params.size() < 2 ) return;
00420   if(ref==NULL) return;
00421   if(!dbe) return;
00422 
00423   QCriterion* qc = dbe->getQCriterion(params[1]);
00424   MonitorElement* me =  dbe->get(params[0]);
00425   if(me!=NULL && qc == NULL){
00426     printf("\n\nDon't have this QC, but have the me!\n\n");
00427     const QReport* qr = me->getQReport(params[1]);
00428     if(qr) return;
00429     printf("\n\nThe ME doesn't have the QC!!\n\n");
00430     qc = dbe->createQTest("Comp2RefEqualH2",params[1]);
00431     /*  Time to get with 
00432   DQMServices/Core V03-00-12-qtest
00433   DQMServices/ClientConfig V03-00-04-qtest
00434     // Contents within a mean value     
00435     Comp2RefEqualH2ROOT* me_qc = dynamic_cast<Comp2RefEqualH2ROOT*> (qc);
00436     //set reference histogram
00437     me_qc->setReference(ref);
00438     // link it to the monitor element
00439     printf("\n\nGonna run it...\n\n");
00440     dbe->useQTest(params[0], params[1]);
00441     */
00442   }
00443   else printf("\n\nAlready had the QC or didn't have the ME!\n\n");
00444 
00445   return;
00446 }
00447 
00448 void htmlErrors(int runNo, std::string htmlDir, std::string client, std::string process, DQMStore* dbe, std::map<std::string, std::vector<QReport*> > mapE, std::map<std::string, std::vector<QReport*> > mapW, std::map<std::string, std::vector<QReport*> > mapO){
00449   if(!dbe) return;
00450 
00451   std::map<std::string, std::vector<QReport*> >::iterator mapIter;
00452 
00453   ofstream errorFile;
00454   errorFile.open((htmlDir + client+ "Errors.html").c_str());
00455   errorFile << "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">  " << std::endl;
00456   errorFile << "<html>  " << std::endl;
00457   errorFile << "<head>  " << std::endl;
00458   errorFile << "  <meta content=\"text/html; charset=ISO-8859-1\"  " << std::endl;
00459   errorFile << " https-equiv=\"content-type\">  " << std::endl;
00460   errorFile << "  <title>Monitor: Hcal " << client <<" Task Error Output</title> " << std::endl;
00461   errorFile << "</head>  " << std::endl;
00462   errorFile << "<style type=\"text/css\"> td { font-weight: bold } </style>" << std::endl;
00463   errorFile << "<body>  " << std::endl;
00464   errorFile << "<br>  " << std::endl;
00465   errorFile << "<h2>" << client <<" Errors</h2> " << std::endl;
00466 
00467   for (mapIter=mapE.begin(); mapIter!=mapE.end();mapIter++){
00468     std::string meName = mapIter->first;
00469     std::vector<QReport*> errors = mapIter->second;
00470     errorFile << "<br>" << std::endl;     
00471     errorFile << "<hr>" << std::endl;
00472     errorFile << "Monitorable '" << meName << "' has the following errors: <br>" << std::endl;
00473     for(std::vector<QReport*>::iterator report=errors.begin(); report!=errors.end(); report++){
00474       errorFile << "     "<< (*report)->getQRName() << ": "<< (*report)->getMessage() << std::endl;
00475     }
00476     MonitorElement* me = dbe->get(meName);
00477     errorFile << "<br>" << std::endl;
00478     errorFile << "<br>" << std::endl;
00479     const char * substr = strstr(meName.c_str(), client.c_str());
00480     if(me->getMeanError(2)==0){
00481       TH1F* obj1f = getHisto(substr, process.c_str(), dbe);
00482       std::string save = getIMG(runNo,obj1f,1,htmlDir,"X1a","Y1a");
00483       errorFile << "<img src=\"" <<  save << "\">" << std::endl;
00484     }
00485     else{
00486       TH2F* obj2f = getHisto2(substr, process.c_str(), dbe);
00487       std::string save = getIMG2(runNo,obj2f,1,htmlDir,"X2a","Y2a");
00488       errorFile << "<img src=\"" <<  save << "\">" << std::endl;
00489     }
00490     errorFile << "<br>" << std::endl;
00491     errorFile << std::endl;
00492   }
00493   errorFile << "<hr>" << std::endl;
00494   errorFile.close();
00495 
00496 
00497   errorFile.open((htmlDir + client+ "Warnings.html").c_str());
00498   errorFile << "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">  " << std::endl;
00499   errorFile << "<html>  " << std::endl;
00500   errorFile << "<head>  " << std::endl;
00501   errorFile << "  <meta content=\"text/html; charset=ISO-8859-1\"  " << std::endl;
00502   errorFile << " https-equiv=\"content-type\">  " << std::endl;
00503   errorFile << "  <title>Monitor: Hcal " << client <<" Task Warning Output</title> " << std::endl;
00504   errorFile << "</head>  " << std::endl;
00505   errorFile << "<style type=\"text/css\"> td { font-weight: bold } </style>" << std::endl;
00506   errorFile << "<body>  " << std::endl;
00507   errorFile << "<br>  " << std::endl;
00508   errorFile << "<h2>" << client <<" Warnings</h2> " << std::endl;
00509 
00510   for (mapIter=mapW.begin(); mapIter!=mapW.end();mapIter++){
00511     std::string meName = mapIter->first;
00512     std::vector<QReport*> errors = mapIter->second;
00513     errorFile << "<br>" << std::endl;     
00514     errorFile << "<hr>" << std::endl;
00515     errorFile << "Monitorable '" << meName << "' has the following warnings: <BR>" << std::endl;
00516     for(std::vector<QReport*>::iterator report=errors.begin(); report!=errors.end(); report++){
00517       errorFile << "     "<< (*report)->getQRName() << ": "<< (*report)->getMessage() << std::endl;
00518     }
00519     MonitorElement* me = dbe->get(meName);
00520     errorFile << "<br>" << std::endl;
00521     errorFile << "<br>" << std::endl;
00522     const char * substr = strstr(meName.c_str(), client.c_str());
00523     if(me->getMeanError(2)==0){
00524       TH1F* obj1f = getHisto(substr, process.c_str(), dbe);
00525       std::string save = getIMG(runNo,obj1f,1,htmlDir,"X1b","Y1b");
00526       errorFile << "<img src=\"" <<  save << "\">" << std::endl;
00527     }
00528     else{
00529       TH2F* obj2f = getHisto2(substr, process.c_str(), dbe);
00530       std::string save = getIMG2(runNo,obj2f,1,htmlDir,"X2b","Y2b");
00531       errorFile << "<img src=\"" <<  save << "\">" << std::endl;
00532     }
00533     errorFile << "<br>" << std::endl;
00534     errorFile << std::endl;  
00535   }
00536   errorFile << "<hr>" << std::endl;
00537   errorFile.close();
00538   
00539   errorFile.open((htmlDir + client+ "Messages.html").c_str());
00540   errorFile << "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">  " << std::endl;
00541   errorFile << "<html>  " << std::endl;
00542   errorFile << "<head>  " << std::endl;
00543   errorFile << "  <meta content=\"text/html; charset=ISO-8859-1\"  " << std::endl;
00544   errorFile << " https-equiv=\"content-type\">  " << std::endl;
00545   errorFile << "  <title>Monitor: Hcal " << client <<" Task Message Output</title> " << std::endl;
00546   errorFile << "</head>  " << std::endl;
00547   errorFile << "<style type=\"text/css\"> td { font-weight: bold } </style>" << std::endl;
00548   errorFile << "<body>  " << std::endl;
00549   errorFile << "<br>  " << std::endl;
00550   errorFile << "<h2>" << client <<" Messages</h2> " << std::endl;
00551 
00552   for (mapIter=mapO.begin(); mapIter!=mapO.end();mapIter++){
00553     std::string meName = mapIter->first;
00554     std::vector<QReport*> errors = mapIter->second;
00555     errorFile << "<br>" << std::endl;     
00556     errorFile << "<hr>" << std::endl;
00557     errorFile << "Monitorable '" << meName << "' has the following messages: <br>" << std::endl;
00558     for(std::vector<QReport*>::iterator report=errors.begin(); report!=errors.end(); report++){
00559       errorFile << "     "<< (*report)->getQRName() << ": "<< (*report)->getMessage() << std::endl;
00560     }
00561     errorFile << "<br>" << std::endl;
00562     errorFile << "<br>" << std::endl;
00563     MonitorElement* me = dbe->get(meName);
00564     const char * substr = strstr(meName.c_str(), client.c_str());
00565     if(me->getMeanError(2)==0){
00566       TH1F* obj1f = getHisto(substr, process.c_str(), dbe);
00567       std::string save = getIMG(runNo,obj1f,1,htmlDir,"X1c","Y1c");
00568       errorFile << "<img src=\"" <<  save << "\">" << std::endl;
00569     }
00570     else{
00571       TH2F* obj2f = getHisto2(substr, process.c_str(), dbe);
00572       std::string save = getIMG2(runNo,obj2f,1,htmlDir,"X2c","Y2c");
00573       errorFile << "<img src=\"" <<  save << "\">" << std::endl;
00574     }
00575     errorFile << "<br>" << std::endl;
00576     errorFile << std::endl;
00577   }
00578   errorFile << "<hr>" << std::endl;
00579   errorFile.close();
00580 
00581   return;
00582 
00583 }
00584 
00585 
00586 
00587 // TProfile histogram-related stuff
00588 
00589 TProfile* getHistoTProfile(std::string name, std::string process, DQMStore* dbe_, bool verb, bool clone){
00590   if(!dbe_) return NULL;
00591   
00592   char title[150];  
00593   sprintf(title, "%sHcal/%s",process.c_str(),name.c_str());
00594   TProfile* out = NULL;
00595 
00596   const MonitorElement* me = dbe_->get(title);
00597   if (me){      
00598     if ( verb ) std::cout << "Found '" << title << "'" << std::endl;
00599     if ( clone ) {
00600       char histo[150];
00601       sprintf(histo, "ME %s",name.c_str());
00602       out = dynamic_cast<TProfile*> (me->getTProfile()->Clone(histo));
00603     } else {
00604       out = me->getTProfile();
00605     }
00606   }
00607 
00608   return out;
00609 }
00610 
00611 TProfile* getHistoTProfile(const MonitorElement* me, bool verb,bool clone){
00612   TProfile* out = NULL;
00613   
00614   if ( me ) {      
00615     if ( verb ) std::cout << "Found '" << me->getName() << "'" << std::endl;
00616     if ( clone ) {
00617       char histo[150];
00618       sprintf(histo, "ME %s",((std::string)(me->getName())).c_str());
00619       out = dynamic_cast<TProfile*> (me->getTProfile()->Clone(histo));
00620     } else {
00621       out = me->getTProfile();
00622     }
00623  }
00624   return out;
00625 }
00626 
00627 std::string getIMGTProfile(int runNo,TProfile* hist, int size, std::string htmlDir, const char* xlab, const char* ylab, std::string opts){
00628 
00629   if(hist==NULL) {
00630     printf("getIMG:  This histo is NULL, %s, %s\n",xlab,ylab);
00631     return "";
00632   }
00633 
00634   std::string name = hist->GetTitle();
00635   cleanString(name);
00636   char dest[512];
00637   if(runNo>-1) sprintf(dest,"%s - Run %d",name.c_str(),runNo);
00638   else sprintf(dest,"%s",name.c_str());
00639   hist->SetTitle(dest);
00640   std::string title = dest;
00641 
00642   int xwid = 900; int ywid =540;
00643   if(size==1){
00644     title = title+"_tmb";
00645     xwid = 600; ywid = 360;
00646   }
00647   TCanvas* can = new TCanvas(dest,dest, xwid, ywid);
00648 
00649   parseString(title);
00650   std::string outName = title + ".gif";
00651   std::string saveName = htmlDir + outName;
00652   hist->SetXTitle(xlab);
00653   hist->SetYTitle(ylab);
00654   if (opts!="NONE")
00655     hist->SetOption(opts.c_str());
00656   hist->Draw();
00657 
00658   can->SaveAs(saveName.c_str());  
00659   delete can;
00660 
00661   return outName;
00662 }
00663 
00664 void histoHTMLTProfile(int runNo, TProfile* hist, const char* xlab, const char* ylab, int width, ofstream& htmlFile, std::string htmlDir, std::string opts){
00665   
00666   if(hist!=NULL){    
00667     std::string imgNameTMB = "";   
00668     imgNameTMB = getIMGTProfile(runNo,hist,1,htmlDir,xlab,ylab,opts); 
00669     std::string imgName = "";   
00670     imgName = getIMGTProfile(runNo,hist,2,htmlDir,xlab,ylab,opts);  
00671 
00672     if (imgName.size() != 0 )
00673       htmlFile << "<td><a href=\"" <<  imgName << "\"><img src=\"" <<  imgNameTMB << "\"></a></td>" << std::endl;
00674     else
00675       htmlFile << "<td><img src=\"" << " " << "\"></td>" << std::endl;
00676   }
00677   else htmlFile << "<td><img src=\"" << " " << "\"></td>" << std::endl;
00678   return;
00679 }
00680 
00681 
00682 // Get Histograms for TProfile2D
00683 
00684 TProfile2D* getHistoTProfile2D(std::string name, std::string process, DQMStore* dbe_, bool verb, bool clone){
00685   if(!dbe_) return NULL;
00686   
00687   char title[150];  
00688   sprintf(title, "%sHcal/%s",process.c_str(),name.c_str());
00689   TProfile2D* out = NULL;
00690 
00691   const MonitorElement* me = dbe_->get(title);
00692   if (me){      
00693     if ( verb ) std::cout << "Found '" << title << "'" << std::endl;
00694     if ( clone ) {
00695       char histo[150];
00696       sprintf(histo, "ME %s",name.c_str());
00697       out = dynamic_cast<TProfile2D*> (me->getTProfile2D()->Clone(histo));
00698     } else {
00699       out = me->getTProfile2D();
00700     }
00701   }
00702 
00703   return out;
00704 }
00705 
00706 TProfile2D* getHistoTProfile2D(const MonitorElement* me, bool verb,bool clone){
00707   TProfile2D* out = NULL;
00708   
00709   if ( me ) {      
00710     if ( verb ) std::cout << "Found '" << me->getName() << "'" << std::endl;
00711     if ( clone ) {
00712       char histo[150];
00713       sprintf(histo, "ME %s",((std::string)(me->getName())).c_str());
00714       out = dynamic_cast<TProfile2D*> (me->getTProfile2D()->Clone(histo));
00715     } else {
00716       out = me->getTProfile2D();
00717     }
00718  }
00719   return out;
00720 }
00721 
00722 // Get histograms for TH3F
00723 TH3F* getHistoTH3F(std::string name, std::string process, DQMStore* dbe_, bool verb, bool clone){
00724   if(!dbe_) return NULL;
00725   
00726   char title[150];  
00727   sprintf(title, "%sHcal/%s",process.c_str(),name.c_str());
00728   TH3F* out = NULL;
00729 
00730   const MonitorElement* me = dbe_->get(title);
00731   if (me){      
00732     if ( verb ) std::cout << "Found '" << title << "'" << std::endl;
00733     if ( clone ) {
00734       char histo[150];
00735       sprintf(histo, "ME %s",name.c_str());
00736       out = dynamic_cast<TH3F*> (me->getTH3F()->Clone(histo));
00737     } else {
00738       out = me->getTH3F();
00739     }
00740   }
00741 
00742   return out;
00743 }
00744 
00745 TH3F* getHistoTH3F(const MonitorElement* me, bool verb,bool clone){
00746   TH3F* out = NULL;
00747   
00748   if ( me ) {      
00749     if ( verb ) std::cout << "Found '" << me->getName() << "'" << std::endl;
00750     if ( clone ) {
00751       char histo[150];
00752       sprintf(histo, "ME %s",((std::string)(me->getName())).c_str());
00753       out = dynamic_cast<TH3F*> (me->getTH3F()->Clone(histo));
00754     } else {
00755       out = me->getTH3F();
00756     }
00757  }
00758   return out;
00759 }