CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DQM/SiPixelMonitorClient/src/SiPixelInformationExtractor.cc

Go to the documentation of this file.
00001 
00007 #include "DQM/SiPixelMonitorClient/interface/SiPixelInformationExtractor.h"
00008 #include "DQM/SiPixelMonitorClient/interface/SiPixelUtility.h"
00009 #include "DQM/SiPixelMonitorClient/interface/SiPixelEDAClient.h"
00010 #include "DQM/SiPixelMonitorClient/interface/ANSIColors.h"
00011 #include "DQM/SiPixelMonitorClient/interface/SiPixelHistoPlotter.h"
00012 #include "DQM/SiPixelCommon/interface/SiPixelFolderOrganizer.h"
00013 
00014 #include "DQMServices/Core/interface/DQMStore.h"
00015 #include "DQMServices/Core/interface/MonitorElement.h"
00016 #include "DQM/TrackerCommon/interface/CgiReader.h"
00017 
00018 #include "FWCore/ParameterSet/interface/FileInPath.h"
00019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00020 
00021 #include "DataFormats/DetId/interface/DetId.h"
00022 #include "DataFormats/GeometrySurface/interface/Surface.h"
00023 #include "DataFormats/SiPixelDetId/interface/PixelBarrelName.h"
00024 #include "DataFormats/SiPixelDetId/interface/PixelEndcapName.h"
00025 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00026 
00027 #include "CondFormats/SiPixelObjects/interface/DetectorIndex.h"
00028 #include "CondFormats/SiPixelObjects/interface/SiPixelFrameConverter.h"
00029 
00030 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
00031 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00032 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00033 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00034 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
00035 
00036 #include "TClass.h"
00037 #include "TText.h"
00038 #include "TROOT.h"
00039 #include "TPad.h"
00040 #include "TStyle.h"
00041 #include "TSystem.h"
00042 #include "TString.h"
00043 #include "TImage.h"
00044 #include "TPaveText.h"
00045 #include "TImageDump.h"
00046 #include "TRandom.h"
00047 #include "TStopwatch.h"
00048 #include "TAxis.h"
00049 #include "TPaveLabel.h"
00050 #include "Rtypes.h"
00051 #include "TH1F.h"
00052 #include "TH2F.h"
00053 #include "TProfile.h"
00054 
00055 #include <iostream>
00056 #include <math.h>
00057 #include <map>
00058 
00059 #include <cstdlib> // for free() - Root can allocate with malloc() - sigh...
00060  
00061 using namespace std;
00062 using namespace edm;
00063 
00064 //------------------------------------------------------------------------------
00068 SiPixelInformationExtractor::SiPixelInformationExtractor(bool offlineXMLfile) : offlineXMLfile_(offlineXMLfile) {
00069   edm::LogInfo("SiPixelInformationExtractor") << 
00070     " Creating SiPixelInformationExtractor " << "\n" ;
00071   
00072   readReference_ = false;
00073   histoPlotter_=0;
00074   histoPlotter_ = new SiPixelHistoPlotter();
00075 }
00076 
00077 //------------------------------------------------------------------------------
00081 SiPixelInformationExtractor::~SiPixelInformationExtractor() {
00082   edm::LogInfo("SiPixelInformationExtractor") << 
00083     " Deleting SiPixelInformationExtractor " << "\n" ;
00084   
00085   if (histoPlotter_) delete histoPlotter_;
00086 }
00087 
00088 //------------------------------------------------------------------------------
00092 void SiPixelInformationExtractor::readConfiguration() { }
00093 
00094 //
00095 // -- Select Histograms for a given module
00096 //
00097 void SiPixelInformationExtractor::getSingleModuleHistos(DQMStore * bei, 
00098                                                         const multimap<string, string>& req_map, 
00099                                                         xgi::Output * out){
00100 //cout<<"In SiPixelInformationExtractor::getSingleModuleHistos: "<<endl;
00101   vector<string> hlist;
00102   getItemList(req_map,"histo", hlist);
00103 
00104   uint32_t detId = atoi(getItemValue(req_map,"ModId").c_str());
00105  
00106   int width  = atoi(getItemValue(req_map, "width").c_str());
00107   int height = atoi(getItemValue(req_map, "height").c_str());
00108 
00109   string opt =" ";
00110   
00111   SiPixelFolderOrganizer folder_organizer;
00112   string path;
00113   folder_organizer.getModuleFolder(detId,path);   
00114 
00115   if((bei->pwd()).find("Module_") == string::npos &&
00116      (bei->pwd()).find("FED_") == string::npos){
00117     cout<<"This is not a pixel module or FED!"<<endl;
00118     return;
00119   }
00120  
00121   vector<MonitorElement*> all_mes = bei->getContents(path);
00122   setHTMLHeader(out);
00123   *out << path << " ";
00124 
00125   string theME ;
00126   for (vector<string>::const_iterator ih = hlist.begin();
00127        ih != hlist.end(); ih++) {
00128     for (vector<MonitorElement *>::const_iterator it = all_mes.begin();
00129          it!= all_mes.end(); it++) {
00130       MonitorElement * me = (*it);
00131       if (!me) continue;
00132       theME = me->getName();
00133       string temp_s ; 
00134       if(theME.find("siPixel")!=string::npos || theME.find("ctfWithMaterialTracks")!=string::npos) { temp_s = theME.substr(0,theME.find_first_of("_")); }
00135       //cout<<"should be the variable name: temp_s= "<<temp_s<<endl;
00136       if (temp_s == (*ih)) {
00137         string full_path = path + "/" + me->getName();
00138         histoPlotter_->setNewPlot(full_path, opt, width, height);
00139         *out << me->getName() << " " ;
00140       }
00141     }
00142   }
00143 }
00144 
00145 //
00146 // -- Plot Tracker Map MEs
00147 //
00148 void SiPixelInformationExtractor::getTrackerMapHistos(DQMStore* bei, 
00149                                                       const std::multimap<std::string, std::string>& req_map, 
00150                                                       xgi::Output * out) {
00151 
00152 //  cout << __LINE__ << ACYellow << ACBold 
00153 //       << "[SiPixelInformationExtractor::getTrackerMapHistos] " << ACPlain << endl ;
00154 //  cout<<"I am in this dir: "<<bei->pwd()<<endl;
00155   vector<string> hlist;
00156   string tkmap_name;
00157   SiPixelConfigParser config_parser;
00158   string localPath;
00159   if(offlineXMLfile_) localPath = string("DQM/SiPixelMonitorClient/test/sipixel_tier0_config.xml");
00160   else localPath = string("DQM/SiPixelMonitorClient/test/sipixel_monitorelement_config.xml");
00161   config_parser.getDocument(edm::FileInPath(localPath).fullPath());
00162 //  if (!config_parser.getMENamesForTrackerMap(tkmap_name, hlist)) return;
00163 //  if (hlist.size() == 0) return;
00164   if (!config_parser.getMENamesForTrackerMap(tkmap_name, hlist)) 
00165   {
00166    cout << __LINE__ << ACYellow << ACBold 
00167         << "[SiPixelInformationExtractor::getTrackerMapHistos] " 
00168         << ACPlain << ACRed << ACPlain 
00169         << "getMENamesForTrackerMap return false " 
00170         << ACPlain << endl ; assert(0) ;
00171    return;
00172   }
00173   if (hlist.size() == 0) 
00174   {
00175    cout << __LINE__ << ACYellow << ACBold 
00176         << "[SiPixelInformationExtractor::getTrackerMapHistos] " 
00177         << ACPlain << ACRed << ACPlain 
00178         << "hlist.size() == 0 " 
00179         << ACPlain << endl ;  assert(0) ;
00180    return;
00181   }
00182 
00183 
00184   uint32_t detId = atoi(getItemValue(req_map,"ModId").c_str());
00185  
00186   int width  = atoi(getItemValue(req_map, "width").c_str());
00187   int height = atoi(getItemValue(req_map, "height").c_str());
00188 
00189   string opt =" ";
00190   
00191   SiPixelFolderOrganizer folder_organizer;
00192   string path;
00193   
00194   folder_organizer.getModuleFolder(detId,path);
00195   string currDir = bei->pwd();   
00196 //  cout<<"detId= "<<detId<<" , path= "<<path<<" , and now I am in "<<currDir<<endl;
00197   
00198 /*
00199   if((bei->pwd()).find("Module_") == string::npos &&
00200      (bei->pwd()).find("FED_") == string::npos){
00201     cout<<"This is not a pixel module or FED!"<<endl;
00202    cout << __LINE__ << ACYellow << ACBold 
00203         << "[SiPixelInformationExtractor::getTrackerMapHistos] " 
00204         << ACPlain << ACRed << ACPlain 
00205         << "This is not a pixel module or FED!" 
00206         << ACPlain << endl ; assert(0) ;
00207     return;
00208   }
00209 */ 
00210   vector<MonitorElement*> all_mes = bei->getContents(path);
00211   setXMLHeader(out);
00212 
00213 /*  cout << __LINE__ << ACCyan << ACBold 
00214        << " [SiPixelInformationExtractor::getTrackerMapHistos()] path "
00215        << ACPlain << path << endl ; 
00216   cout << __LINE__ << ACCyan << ACBold 
00217        << " [SiPixelInformationExtractor::getTrackerMapHistos()] all_mes.size() "
00218        << ACPlain << all_mes.size() << endl ; 
00219 */
00220   string theME ;
00221   *out << "<pathList>" << endl ;
00222   for (vector<string>::iterator ih = hlist.begin();
00223        ih != hlist.end(); ih++) {
00224        //cout<<"ih iterator (hlist): "<<(*ih)<<endl;
00225     for (vector<MonitorElement *>::const_iterator it = all_mes.begin();
00226          it!= all_mes.end(); it++) {
00227       MonitorElement * me = (*it);
00228       if (!me) 
00229       { 
00230        cout << __LINE__ << ACCyan << ACBold 
00231             << " [SiPixelInformationExtractor::getTrackerMapHistos()] skipping "
00232                        << ACPlain << *ih << endl ; 
00233        continue;
00234       }
00235       theME = me->getName();
00236       //cout<<"ME iterator (all_mes): "<<theME<<endl; 
00237       string temp_s ; 
00238       if(theME.find("siPixel")!=string::npos || theME.find("ctfWithMaterialTracks")!=string::npos) { temp_s = theME.substr(0,theME.find_first_of("_")); }
00239       //cout << __LINE__ << ACCyan << ACBold 
00240       //     << " [SiPixelInformationExtractor::getTrackerMapHistos()] temp_s "
00241       //     << ACPlain << temp_s << " <--> " << *ih << " |" << theME << "|" << endl ; 
00242       if (temp_s == (*ih)) {
00243         string full_path = path + "/" + me->getName();
00244         histoPlotter_->setNewPlot(full_path, opt, width, height);
00245 //cout << __LINE__ << ACRed << ACBold 
00246 //     << " [SiPixelInformationExtractor::getTrackerMapHistos()] fullPath: "
00247 //     << ACPlain << full_path << endl ; 
00248         *out << " <pathElement path='" << full_path << "' />" << endl ;
00249       }      
00250     }
00251   }   
00252   *out << "</pathList>" << endl ;
00253 //cout << __LINE__ << " [SiPixelInformationExtractor::getTrackerMapHistos()] endlist: " << endl ;
00254 }
00255 
00256 //============================================================================================================
00257 // --  Return type of ME
00258 //
00259 std::string  SiPixelInformationExtractor::getMEType(MonitorElement * theMe)
00260 {
00261   string qtype = theMe->getRootObject()->IsA()->GetName() ;
00262   if(         qtype.find("TH1") != string::npos )
00263   {
00264     return "TH1" ;
00265   } else if ( qtype.find("TH2") != string::npos  ) {
00266     return "TH2" ;
00267   } else if ( qtype.find("TH3") != string::npos ) {
00268     return "TH3" ;
00269   }
00270   return "TH1" ;
00271 }
00272 
00273 //------------------------------------------------------------------------------
00278 void SiPixelInformationExtractor::readModuleAndHistoList(DQMStore* bei, 
00279                                                          xgi::Output * out) {
00280 //cout<<"entering SiPixelInformationExtractor::readModuleAndHistoList"<<endl;
00281    bei->cd("Pixel");
00282    std::map<std::string,std::string> hnames;
00283    std::vector<std::string> mod_names;
00284    fillModuleAndHistoList(bei, mod_names, hnames);
00285    out->getHTTPResponseHeader().addHeader("Content-Type", "text/xml");
00286   *out << "<?xml version=\"1.0\" ?>" << std::endl;
00287   *out << "<ModuleAndHistoList>" << endl;
00288   *out << "<ModuleList>" << endl;
00289    for (std::vector<std::string>::iterator im = mod_names.begin();
00290         im != mod_names.end(); im++) {
00291      *out << "<ModuleNum>" << *im << "</ModuleNum>" << endl;     
00292    }
00293    *out << "</ModuleList>" << endl;
00294    *out << "<HistoList>" << endl;
00295 
00296    for (std::map<std::string,std::string>::iterator ih = hnames.begin();
00297         ih != hnames.end(); ih++) {
00298      *out << "<Histo type=\"" 
00299           << ih->second
00300           << "\">" 
00301           << ih->first 
00302           << "</Histo>" 
00303           << endl;     
00304    }
00305    *out << "</HistoList>" << endl;
00306    *out << "</ModuleAndHistoList>" << endl;
00307 //cout<<"leaving SiPixelInformationExtractor::readModuleAndHistoList"<<endl;
00308 }
00309 
00310 //------------------------------------------------------------------------------
00315 void SiPixelInformationExtractor::fillModuleAndHistoList(DQMStore * bei, 
00316                                                          vector<string>        & modules,
00317                                                          map<string,string>    & histos) {
00318 //cout<<"entering SiPixelInformationExtractor::fillModuleAndHistoList"<<endl;
00319   string currDir = bei->pwd();
00320   //cout<<"currDir= "<<currDir<<endl;
00321   if(currDir.find("Module_") != string::npos){
00322     if(histos.size() == 0){
00323       vector<string> contents = bei->getMEs();
00324       for (vector<string>::const_iterator it = contents.begin(); it != contents.end(); it++) {
00325         string hname          = (*it).substr(0, (*it).find("_siPixel"));
00326         if(hname==" ") hname = (*it).substr(0, (*it).find("_generalTracks"));
00327         string fullpathname   = bei->pwd() + "/" + (*it); 
00328        // cout<<"fullpathname="<<fullpathname<<endl;
00329         MonitorElement * me   = bei->get(fullpathname);
00330         string htype          = "undefined" ;
00331         if(me) htype = me->getRootObject()->IsA()->GetName() ;
00332         //cout<<"hname="<<hname<<endl;
00333         //if(htype=="TH1F" || htype=="TH1D"){
00334         histos[hname] = htype ;
00335         string mId=" ";
00336         if(hname.find("ndigis")                !=string::npos) mId = (*it).substr((*it).find("ndigis_siPixelDigis_")+20, 9);
00337         if(mId==" " && hname.find("nclusters") !=string::npos) mId = (*it).substr((*it).find("nclusters_siPixelClusters_")+26, 9);
00338         if(mId==" " && hname.find("residualX") !=string::npos) mId = (*it).substr((*it).find("residualX_ctfWithMaterialTracks_")+32, 9);
00339         if(mId==" " && hname.find("NErrors") !=string::npos) mId = (*it).substr((*it).find("NErrors_siPixelDigis_")+21, 9);
00340         if(mId==" " && hname.find("ClustX") !=string::npos) mId = (*it).substr((*it).find("ClustX_siPixelRecHit_")+21, 9);
00341         if(mId==" " && hname.find("pixelAlive") !=string::npos) mId = (*it).substr((*it).find("pixelAlive_siPixelCalibDigis_")+29, 9);
00342         if(mId==" " && hname.find("Gain1d") !=string::npos) mId = (*it).substr((*it).find("Gain1d_siPixelCalibDigis_")+25, 9);
00343         if(mId!=" ") modules.push_back(mId);
00344         //cout<<"mId="<<mId<<endl;
00345         //}
00346       }    
00347     }
00348   } else {  
00349     vector<string> subdirs = bei->getSubdirs();
00350     for (vector<string>::const_iterator it = subdirs.begin(); it != subdirs.end(); it++) {
00351       if((bei->pwd()).find("Barrel")==string::npos && (bei->pwd()).find("Endcap")==string::npos) bei->goUp();
00352       bei->cd(*it);
00353       fillModuleAndHistoList(bei, modules, histos);
00354       bei->goUp();
00355     }
00356   }
00357 //  fillBarrelList(bei, modules, histos);
00358 //cout<<"leaving SiPixelInformationExtractor::fillModuleAndHistoList"<<endl;
00359 }
00360 
00361 //------------------------------------------------------------------------------
00366 void SiPixelInformationExtractor::readModuleHistoTree(DQMStore* bei, 
00367                                                       string& str_name, 
00368                                                       xgi::Output * out) {
00369 //cout<<"entering  SiPixelInformationExtractor::readModuleHistoTree"<<endl;
00370   ostringstream modtree;
00371   if (goToDir(bei, str_name)) {
00372     modtree << "<form name=\"IMGCanvasItemsSelection\" "
00373             << "action=\"javascript:void%200\">" 
00374             << endl ;
00375     modtree << "<ul id=\"dhtmlgoodies_tree\" class=\"dhtmlgoodies_tree\">" << endl;
00376     printModuleHistoList(bei,modtree);
00377     modtree <<"</ul>" << endl;   
00378     modtree <<"</form>" << endl;   
00379   } else {
00380     modtree << "Desired Directory does not exist";
00381   }
00382   cout << ACYellow << ACBold
00383        << "[SiPixelInformationExtractor::readModuleHistoTree()]"
00384        << ACPlain << endl ;
00385   //     << "html string follows: " << endl ;
00386   //cout << modtree.str() << endl ;
00387   //cout << ACYellow << ACBold
00388   //     << "[SiPixelInformationExtractor::readModuleHistoTree()]"
00389   //     << ACPlain
00390   //     << "String complete " << endl ;
00391   out->getHTTPResponseHeader().addHeader("Content-Type", "text/plain");
00392   *out << modtree.str();
00393    bei->cd();
00394 //cout<<"leaving  SiPixelInformationExtractor::readModuleHistoTree"<<endl;
00395 }
00396 
00397 //------------------------------------------------------------------------------
00402 void SiPixelInformationExtractor::printModuleHistoList(DQMStore * bei, 
00403                                                        ostringstream& str_val){
00404 //cout<<"entering SiPixelInformationExtractor::printModuleHistoList"<<endl;
00405   static string indent_str = "";
00406   string currDir = bei->pwd();
00407   string dname = currDir.substr(currDir.find_last_of("/")+1);
00408   str_val << " <li>\n"
00409           << "  <a href=\"#\" id=\"" << currDir << "\">\n   " 
00410           <<     dname << "\n"
00411           << "  </a>\n"
00412           << endl << endl;
00413 
00414   vector<string> meVec     = bei->getMEs(); 
00415   
00416   vector<string> subDirVec = bei->getSubdirs();
00417   if ( meVec.size()== 0  && subDirVec.size() == 0 ) {
00418     str_val << " </li>" << endl;    
00419     return;
00420   }
00421   str_val << "\n   <ul>" << endl; 
00422   for (vector<string>::const_iterator it  = meVec.begin();
00423                                       it != meVec.end(); it++) {
00424     if ((*it).find("_siPixel")!=string::npos || 
00425         (*it).find("_ctfWithMaterialTracks")!=string::npos) {
00426       string qit = (*it) ;
00427       string temp_s;
00428       if(qit.find("siPixel")!=string::npos || qit.find("ctfWithMaterialTracks")!=string::npos) { temp_s = qit.substr(0,qit.find_first_of("_")); }
00429       str_val << "    <li class=\"dhtmlgoodies_sheet.gif\">\n"
00430               << "     <input id      = \"selectedME\""
00431               << "            folder  = \"" << currDir << "\""
00432               << "            type    = \"checkbox\""
00433               << "            name    = \"selected\""
00434               << "            class   = \"smallCheckBox\""
00435               << "            value   = \"" << (*it) << "\""
00436               << "            onclick = \"javascript:IMGC.selectedIMGCItems()\" />\n"
00437 //            << "     <a href=\"javascript:IMGC.updateIMGC('" << currDir << "')\">\n       " 
00438               << "     <a href=\"javascript:IMGC.plotFromPath('" << currDir << "')\">\n       " 
00439 //            <<        temp_s << "\n"
00440               <<        (*it) << "\n"
00441               << "     </a>\n"
00442               << "    </li>" 
00443               << endl;
00444     }
00445   }
00446   for (vector<string>::const_iterator ic  = subDirVec.begin();
00447                                       ic != subDirVec.end(); ic++) {
00448     bei->cd(*ic);
00449     printModuleHistoList(bei, str_val);
00450     bei->goUp();
00451   }
00452   str_val << "   </ul>" << endl;  
00453   str_val << "  </li>"  << endl;  
00454 //cout<<"leaving SiPixelInformationExtractor::printModuleHistoList"<<endl;
00455 }
00456 
00457 //------------------------------------------------------------------------------
00462 void SiPixelInformationExtractor::readSummaryHistoTree(DQMStore* bei, 
00463                                                        string& str_name, 
00464                                                        xgi::Output * out) {
00465 //cout<<"entering  SiPixelInformationExtractor::readSummaryHistoTree"<<endl;
00466   ostringstream sumtree;
00467   if (goToDir(bei, str_name)) {
00468     sumtree << "<ul id=\"dhtmlgoodies_tree\" class=\"dhtmlgoodies_tree\">" << endl;
00469     printSummaryHistoList(bei,sumtree);
00470     sumtree <<"</ul>" << endl;   
00471   } else {
00472     sumtree << "Desired Directory does not exist";
00473   }
00474   cout << ACYellow << ACBold
00475        << "[SiPixelInformationExtractor::readSummaryHistoTree()]"
00476        << ACPlain << endl ;
00477   //     << "html string follows: " << endl ;
00478   //cout << sumtree.str() << endl ;
00479   //cout << ACYellow << ACBold
00480   //     << "[SiPixelInformationExtractor::readSummaryHistoTree()]"
00481   //     << ACPlain
00482   //     << "String complete " << endl ;
00483   out->getHTTPResponseHeader().addHeader("Content-Type", "text/plain");
00484   *out << sumtree.str();
00485    bei->cd();
00486 //cout<<"leaving  SiPixelInformationExtractor::readSummaryHistoTree"<<endl;
00487 }
00488 //------------------------------------------------------------------------------
00495 void SiPixelInformationExtractor::printSummaryHistoList(DQMStore * bei, 
00496                                                         ostringstream& str_val){
00497 //cout<<"entering SiPixelInformationExtractor::printSummaryHistoList"<<endl;
00498   static string indent_str = "";
00499   string currDir = bei->pwd();
00500   string dname = currDir.substr(currDir.find_last_of("/")+1);
00501   if (dname.find("Module_") ==0 || dname.find("FED_")==0) return;
00502   str_val << " <li>\n"
00503           << "  <a href=\"#\" id=\"" << currDir << "\">\n   " 
00504           <<     dname 
00505           << "  </a>" 
00506           << endl;
00507 
00508   vector<string> meVec     = bei->getMEs(); 
00509   
00510   vector<string> subDirVec = bei->getSubdirs();
00511   if ( meVec.size()== 0  && subDirVec.size() == 0 ) {
00512     str_val << " </li> "<< endl;    
00513     return;
00514   }
00515   str_val << "\n   <ul>" << endl;      
00516   for (vector<string>::const_iterator it = meVec.begin();
00517        it != meVec.end(); it++) {
00518     if ((*it).find("SUM") == 0) {
00519       str_val << "    <li class=\"dhtmlgoodies_sheet.gif\">\n"
00520               << "     <input id      = \"selectedME\""
00521               << "            folder  = \"" << currDir << "\""
00522               << "            type    = \"checkbox\""
00523               << "            name    = \"selected\""
00524               << "            class   = \"smallCheckBox\""
00525               << "            value   = \"" << (*it) << "\""
00526               << "            onclick = \"javascript:IMGC.selectedIMGCItems()\" />\n"
00527 //              << "     <a href=\"javascript:IMGC.updateIMGC('" << currDir << "')\">\n       " 
00528               << "     <a href=\"javascript:IMGC.plotFromPath('" << currDir << "')\">\n       " 
00529               <<       (*it) << "\n"
00530               << "     </a>\n"
00531               << "    </li>" 
00532               << endl;
00533     }
00534   }
00535 
00536   for (vector<string>::const_iterator ic = subDirVec.begin();
00537        ic != subDirVec.end(); ic++) {
00538     bei->cd(*ic);
00539     printSummaryHistoList(bei, str_val);
00540     bei->goUp();
00541   }
00542   str_val << "   </ul> "<< endl;  
00543   str_val << "  </li> "<< endl;  
00544 //cout<<"leaving SiPixelInformationExtractor::printSummaryHistoList"<<endl;
00545 }
00546 
00547 
00548 //------------------------------------------------------------------------------
00553 void SiPixelInformationExtractor::readAlarmTree(DQMStore* bei, 
00554                                                 string& str_name, 
00555                                                 xgi::Output * out){
00556 //cout<<"entering SiPixelInformationExtractor::readAlarmTree"<<endl;
00557   ostringstream alarmtree;
00558   if (goToDir(bei, str_name)) {
00559     alarmtree << "<ul id=\"dhtmlgoodies_tree\" class=\"dhtmlgoodies_tree\">" << endl;
00560     alarmCounter_=0;
00561     printAlarmList(bei,alarmtree);
00562     if(alarmCounter_==0) alarmtree <<"<li>No problematic modules found, all ok!</li>" << endl;
00563     alarmtree <<"</ul>" << endl; 
00564   } else {
00565     alarmtree << "Desired Directory does not exist";
00566   }
00567   cout << ACYellow << ACBold
00568        << "[SiPixelInformationExtractor::readAlarmTree()]"
00569        << ACPlain << endl ;
00570   //     << "html string follows: " << endl ;
00571   //cout << alarmtree.str() << endl ;
00572   //cout << ACYellow << ACBold
00573   //     << "[SiPixelInformationExtractor::readAlarmTree()]"
00574   //     << ACPlain
00575   //     << "String complete " << endl ;
00576   out->getHTTPResponseHeader().addHeader("Content-Type", "text/plain");
00577  *out << alarmtree.str();
00578   bei->cd();
00579   cout << ACYellow << ACBold
00580        << "[SiPixelInformationExtractor::readAlarmTree()]"
00581        << ACPlain 
00582        << " Done!"
00583        << endl ;
00584 //cout<<"leaving SiPixelInformationExtractor::readAlarmTree"<<endl;
00585 }
00586 //------------------------------------------------------------------------------
00593 void SiPixelInformationExtractor::printAlarmList(DQMStore * bei, 
00594                                                  ostringstream& str_val){
00595 //cout<<"entering SiPixelInformationExtractor::printAlarmList"<<endl;
00596 //   cout << ACRed << ACBold
00597 //        << "[SiPixelInformationExtractor::printAlarmList()]"
00598 //        << ACPlain
00599 //        << " Enter" 
00600 //        << endl ;
00601   static string indent_str = "";
00602   string currDir = bei->pwd();
00603   string dname = currDir.substr(currDir.find_last_of("/")+1);
00604   string image_name;
00605   selectImage(image_name,bei->getStatus(currDir));
00606   if(image_name!="images/LI_green.gif")
00607     str_val << " <li>\n"
00608             << "  <a href=\"#\" id=\"" << currDir << "\">\n   " 
00609             <<     dname 
00610             << "  </a>\n"
00611             << "  <img src=\"" 
00612             <<     image_name 
00613             << "\">" << endl;
00614   vector<string> subDirVec = bei->getSubdirs();
00615 
00616   vector<string> meVec = bei->getMEs();
00617    
00618   if (subDirVec.size() == 0 && meVec.size() == 0) {
00619     str_val <<  "</li> "<< endl;    
00620     return;
00621   }
00622   str_val << "<ul>" << endl;
00623   for (vector<string>::const_iterator it = meVec.begin();
00624            it != meVec.end(); it++) {
00625     string full_path = currDir + "/" + (*it);
00626 
00627     MonitorElement * me = bei->get(full_path);
00628     
00629     if (!me) continue;
00630     std::vector<QReport *> my_map = me->getQReports();
00631     if (my_map.size() > 0) {
00632       string image_name1;
00633       selectImage(image_name1,my_map);
00634       if(image_name1!="images/LI_green.gif") {
00635         alarmCounter_++;
00636         str_val << "    <li class=\"dhtmlgoodies_sheet.gif\">\n"
00637                 << "     <input id      = \"selectedME\""
00638                 << "            folder  = \"" << currDir << "\""
00639                 << "            type    = \"checkbox\""
00640                 << "            name    = \"selected\""
00641                 << "            class   = \"smallCheckBox\""
00642                 << "            value   = \"" << (*it) << "\""
00643                 << "            onclick = \"javascript:IMGC.selectedIMGCItems()\" />\n"
00644 //              << "     <a href=\"javascript:IMGC.updateIMGC('" << currDir << "')\">\n       " 
00645                 << "     <a href=\"javascript:IMGC.plotFromPath('" << currDir << "')\">\n       " 
00646                 <<        (*it) << "\n"
00647                 << "     </a>\n"
00648                 << "     <img src=\""
00649                 <<        image_name1 
00650                 << "\">"
00651                 << "    </li>" 
00652                 << endl;
00653         }       
00654     }
00655   }
00656   for (vector<string>::const_iterator ic = subDirVec.begin();
00657        ic != subDirVec.end(); ic++) {
00658     bei->cd(*ic);
00659     printAlarmList(bei, str_val);
00660     bei->goUp();
00661   }
00662   str_val << "</ul> "<< endl;  
00663   str_val << "</li> "<< endl;  
00664 //   cout << ACGreen << ACBold
00665 //        << "[SiPixelInformationExtractor::printAlarmList()]"
00666 //        << ACPlain
00667 //        << " Done" 
00668 //        << endl ;
00669 //cout<<"leaving SiPixelInformationExtractor::printAlarmList"<<endl;
00670 }
00671 
00672 
00673 //------------------------------------------------------------------------------
00678 void SiPixelInformationExtractor::getItemList(const multimap<string, string>& req_map, 
00679                                               string item_name,
00680                                               vector<string>& items) {
00681 //cout<<"entering SiPixelInformationExtractor::getItemList"<<endl;
00682   items.clear();
00683   for (multimap<string, string>::const_iterator it = req_map.begin();
00684        it != req_map.end(); it++) {
00685     if (it->first == item_name) {
00686       items.push_back(it->second);
00687     }
00688   }
00689 //cout<<"leaving SiPixelInformationExtractor::getItemList"<<endl;
00690 }
00691 
00692 //------------------------------------------------------------------------------
00697 bool SiPixelInformationExtractor::hasItem(multimap<string,string>& req_map,
00698                                           string item_name){
00699 //cout<<"entering SiPixelInformationExtractor::hasItem"<<endl;
00700   multimap<string,string>::iterator pos = req_map.find(item_name);
00701   if (pos != req_map.end()) return true;
00702   return false;  
00703 //cout<<"leaving SiPixelInformationExtractor::hasItem"<<endl;
00704 }
00705 
00706 //------------------------------------------------------------------------------
00711 std::string SiPixelInformationExtractor::getItemValue(const std::multimap<std::string,std::string>& req_map,
00712                                                  std::string item_name){
00713 //cout<<"entering SiPixelInformationExtractor::getItemValue for item: "<<item_name<<endl;
00714   std::multimap<std::string,std::string>::const_iterator pos = req_map.find(item_name);
00715   std::string value = " ";
00716   if (pos != req_map.end()) {
00717     value = pos->second;
00718   }
00719 //  cout<<"value = "<<value<<endl;
00720   return value;
00721 //cout<<"leaving SiPixelInformationExtractor::getItemValue"<<endl;
00722 }
00723 std::string SiPixelInformationExtractor::getItemValue(std::multimap<std::string,std::string>& req_map,
00724                                                  std::string item_name){
00725 //cout<<"entering SiPixelInformationExtractor::getItemValue for item: "<<item_name<<endl;
00726   std::multimap<std::string,std::string>::iterator pos = req_map.find(item_name);
00727   std::string value = " ";
00728   if (pos != req_map.end()) {
00729 //  cout<<"item found!"<<endl;
00730     value = pos->second;
00731   }
00732 //  cout<<"value = "<<value<<endl;
00733   return value;
00734 //cout<<"leaving SiPixelInformationExtractor::getItemValue"<<endl;
00735 }
00736 
00737 //
00738 // -- Get color  name from status
00739 //
00740 void SiPixelInformationExtractor::selectColor(string& col, int status){
00741   if (status == dqm::qstatus::STATUS_OK)    col = "#00ff00";
00742   else if (status == dqm::qstatus::WARNING) col = "#ffff00";
00743   else if (status == dqm::qstatus::ERROR)   col = "#ff0000";
00744   else if (status == dqm::qstatus::OTHER)   col = "#ffa500";
00745   else  col = "#0000ff";
00746 }
00747 //
00748 // -- Get Image name from ME
00749 //
00750 void SiPixelInformationExtractor::selectColor(string& col, vector<QReport*>& reports){
00751   int istat = 999;
00752   int status = 0;
00753   for (vector<QReport*>::const_iterator it = reports.begin(); it != reports.end();
00754        it++) {
00755     status = (*it)->getStatus();
00756     if (status > istat) istat = status;
00757   }
00758   selectColor(col, status);
00759 }
00760 //
00761 // -- Get Image name from status
00762 //
00763 void SiPixelInformationExtractor::selectImage(string& name, int status){
00764   if (status == dqm::qstatus::STATUS_OK) name="images/LI_green.gif";
00765   else if (status == dqm::qstatus::WARNING) name="images/LI_yellow.gif";
00766   else if (status == dqm::qstatus::ERROR) name="images/LI_red.gif";
00767   else if (status == dqm::qstatus::OTHER) name="images/LI_orange.gif";
00768   else  name="images/LI_blue.gif";
00769 }
00770 //
00771 // -- Get Image name from ME
00772 //
00773 void SiPixelInformationExtractor::selectImage(string& name, vector<QReport*>& reports){
00774   int istat = 999;
00775   int status = 0;
00776   for (vector<QReport*>::const_iterator it = reports.begin(); it != reports.end();
00777        it++) {
00778     status = (*it)->getStatus();
00779     if (status > istat) istat = status;
00780   }
00781   selectImage(name, status);
00782 }
00783 
00784 //
00785 // -- Get a tagged image 
00786 //
00787 void SiPixelInformationExtractor::getIMGCImage(const multimap<string, string>& req_map, 
00788                                                xgi::Output * out){
00789   string path = getItemValue(req_map,"Path");
00790   string image;
00791   histoPlotter_->getNamedImageBuffer(path, image);
00792 
00793   out->getHTTPResponseHeader().addHeader("Content-Type", "image/png");
00794   out->getHTTPResponseHeader().addHeader("Pragma", "no-cache");   
00795   out->getHTTPResponseHeader().addHeader("Cache-Control", "no-store, no-cache, must-revalidate,max-age=0");
00796   out->getHTTPResponseHeader().addHeader("Expires","Mon, 26 Jul 1997 05:00:00 GMT");
00797   *out << image;
00798 }
00799 
00800 void SiPixelInformationExtractor::getIMGCImage(multimap<string, string>& req_map, 
00801                                                xgi::Output * out){
00802   
00803   string path = getItemValue(req_map,"Path");
00804   string image;
00805   histoPlotter_->getNamedImageBuffer(path, image);
00806 
00807   out->getHTTPResponseHeader().addHeader("Content-Type", "image/png");
00808   out->getHTTPResponseHeader().addHeader("Pragma", "no-cache");   
00809   out->getHTTPResponseHeader().addHeader("Cache-Control", "no-store, no-cache, must-revalidate,max-age=0");
00810   out->getHTTPResponseHeader().addHeader("Expires","Mon, 26 Jul 1997 05:00:00 GMT");
00811   *out << image;
00812 
00813 }
00814 
00815 
00816 //------------------------------------------------------------------------------
00821 bool SiPixelInformationExtractor::goToDir(DQMStore* bei, 
00822                                           string& sname){ 
00823 //cout<<"entering SiPixelInformationExtractor::goToDir"<<endl;
00824   bei->cd();
00825   //if(flg) bei->cd("Collector/Collated");
00826   bei->cd(sname);
00827   string dirName = bei->pwd();
00828   if (dirName.find(sname) != string::npos) return true;
00829   else return false;  
00830 //cout<<"leaving SiPixelInformationExtractor::goToDir"<<endl;
00831 }
00832 
00833 //
00834 // -- Get Warning/Error Messages
00835 //
00836 void SiPixelInformationExtractor::readStatusMessage(DQMStore* bei, 
00837                                                     std::multimap<std::string, std::string>& req_map, 
00838                                                     xgi::Output * out){
00839 
00840   string path = getItemValue(req_map,"Path");
00841 
00842   int width  = atoi(getItemValue(req_map, "width").c_str());
00843   int height = atoi(getItemValue(req_map, "height").c_str());
00844 
00845   string opt =" ";
00846 
00847   ostringstream test_status;
00848   
00849   setXMLHeader(out);
00850   *out << "<StatusAndPath>" << endl;
00851   *out << "<PathList>" << endl;
00852   if (path.size() == 0) {
00853     *out << "<HPath>" << "NONE" << "</HPath>" << endl;     
00854     test_status << " ME Does not exist ! " << endl;
00855   } else {
00856     vector<MonitorElement*> all_mes = bei->getContents(path);
00857     *out << "<HPath>" << path << "</HPath>" << endl;     
00858     for(vector<MonitorElement*>::iterator it=all_mes.begin(); it!=all_mes.end(); it++){
00859       MonitorElement* me = (*it);
00860       if (!me) continue;
00861       string name = me->getName();  
00862 
00863       vector<QReport*> q_reports = me->getQReports();
00864       if (q_reports.size() == 0) continue;
00865       string full_path = path + "/" + name;
00866       histoPlotter_->setNewPlot(full_path, opt, width, height);
00867 
00868       if (q_reports.size() != 0) {
00869         test_status << " QTest Status for " << name << " : " << endl;
00870         test_status << " ======================================================== " << endl; 
00871         for (vector<QReport*>::const_iterator it = q_reports.begin(); it != q_reports.end();
00872              it++) {
00873           int status = (*it)->getStatus();
00874           if (status == dqm::qstatus::WARNING) test_status << " Warning ";
00875           else if (status == dqm::qstatus::ERROR) test_status << " Error  ";
00876           else if (status == dqm::qstatus::STATUS_OK) test_status << " Ok  ";
00877           else if (status == dqm::qstatus::OTHER) test_status << " Other(" << status << ") ";
00878           string mess_str = (*it)->getMessage();
00879           test_status <<  "&lt;br/&gt;";
00880           mess_str = mess_str.substr(mess_str.find(" Test")+5);
00881           test_status <<  " QTest Name  : " << mess_str.substr(0, mess_str.find(")")+1) << endl;
00882           test_status << "&lt;br/&gt;";
00883           test_status <<  " QTest Detail  : " << mess_str.substr(mess_str.find(")")+2) << endl;
00884         } 
00885         test_status << " ======================================================== " << endl;
00886       }
00887       *out << "<HPath>" << name << "</HPath>" << endl;         
00888     }    
00889   }
00890   *out << "</PathList>" << endl;
00891   *out << "<StatusList>" << endl;
00892   *out << "<Status>" << test_status.str() << "</Status>" << endl;      
00893   *out << "</StatusList>" << endl;
00894   *out << "</StatusAndPath>" << endl;
00895 }
00896 
00897 //------------------------------------------------------------------------------
00901 void SiPixelInformationExtractor::computeStatus(MonitorElement      * theME,
00902                                                 double              & colorValue,
00903                                                 pair<double,double> & norm) 
00904 {
00905   double normalizationX = 1 ;
00906   double normalizationY = 1 ;
00907   double meanX          = 0 ;
00908   double meanY          = 0 ;
00909   
00910   colorValue = 0 ;
00911 
00912   pair<double,double> normX ;
00913   pair<double,double> normY ;
00914 
00915   string theMEType = getMEType(theME) ;
00916 
00917 //   cout << ACRed << ACReverse
00918 //        << "[SiPixelInformationExtractor::computeStatus()]"
00919 //        << ACPlain
00920 //        << " Computing average for "
00921 //        << theME->getName()
00922 //        << endl ;
00923 
00924   if( theMEType.find("TH1") != string::npos)
00925   {
00926    meanX = (double)theME->getMean();
00927    getNormalization(theME, normX, "TH1") ;
00928    normalizationX = fabs( normX.second - normX.first) ;
00929    if( normalizationX == 0 ) {normalizationX=1.E-20;}
00930    colorValue  = meanX / normalizationX ;
00931    norm.first  = normX.first ;
00932    norm.second = normX.second ;
00933   }
00934   
00935   if( theMEType.find("TH2") != string::npos)
00936   {
00937    meanX = (double)theME->getMean(1);
00938    meanY = (double)theME->getMean(2);
00939    getNormalization2D(theME, normX, normY, "TH2") ;
00940    normalizationX = fabs( normX.second - normX.first) ;
00941    normalizationY = fabs( normY.second - normY.first) ;
00942    if( normalizationX == 0 ) {normalizationX=1.E-20;}
00943    if( normalizationY == 0 ) {normalizationY=1.E-20;}
00944    double cVX = meanX / normalizationX ;
00945    double cVY = meanY / normalizationY ;
00946    colorValue = sqrt(cVX*cVX + cVY*cVY) ;
00947    if( normalizationX >= normalizationY )
00948    { 
00949     norm.first  = normX.first;
00950     norm.second = normX.second ;
00951    } else { 
00952     norm.first  = normY.first;
00953     norm.second = normY.second ;
00954    }
00955 //   cout << ACBlue << ACBold << ACReverse
00956 //        << "[SiPixelInformationExtractor::computeStatus()]"
00957 //      << ACPlain << "    "
00958 //      << theME->getName()
00959 //      << " meanX:Y "
00960 //      << meanX << ":" << meanY
00961 //      << " normX:Y " 
00962 //      << norm.first << ":" << norm.second
00963 //      << endl ;
00964   } 
00965  
00966   return ;
00967 }
00968 
00969 //------------------------------------------------------------------------------
00973 void SiPixelInformationExtractor::getNormalization(MonitorElement     * theME, 
00974                                                    pair<double,double>& norm,
00975                                                    std::string          theMEType) 
00976 {
00977   double normLow  = 0 ;
00978   double normHigh = 0 ;
00979 
00980   if( theMEType.find("TH1") != string::npos)
00981   {
00982    normHigh    = (double)theME->getNbinsX() ;
00983    norm.first  = normLow  ;
00984    norm.second = normHigh ;
00985   }
00986 }
00987 
00988 //------------------------------------------------------------------------------
00992 void SiPixelInformationExtractor::getNormalization2D(MonitorElement     * theME, 
00993                                                      pair<double,double>& normX,
00994                                                      pair<double,double>& normY,
00995                                                      std::string          theMEType) 
00996 {
00997   double normLow  = 0 ;
00998   double normHigh = 0 ;
00999 
01000   if( theMEType.find("TH2") != string::npos )
01001   {
01002    normHigh    = (double)theME->getNbinsX() ;
01003    normX.first  = normLow  ;
01004    normX.second = normHigh ;
01005    normHigh    = (double)theME->getNbinsY() ;
01006    normY.first  = normLow  ;
01007    normY.second = normHigh ;
01008 //   cout << ACCyan << ACBold << ACReverse
01009 //        << "[SiPixelInformationExtractor::getNormalization2D()]"
01010 //      << ACPlain << " "
01011 //      << theME->getName()
01012 //      << " normX: " 
01013 //      << normX.first << ":" << normX.second
01014 //      << " normY: " 
01015 //      << normY.first << ":" << normY.second
01016 //      << endl ;
01017   }
01018 }
01019 
01020 //------------------------------------------------------------------------------
01025 void SiPixelInformationExtractor::selectMEList(DQMStore   * bei,  
01026                                                string                  & theMEName,
01027                                                vector<MonitorElement*> & mes) 
01028 {  
01029 //  cout<<"In SiPixelInformationExtractor::selectMEList: "<<endl;
01030   string currDir = bei->pwd();
01031    
01032   string theME ;
01033    
01034   // Get ME from Collector/FU0/Tracker/PixelEndcap/HalfCylinder_pX/Disk_X/Blade_XX/Panel_XX/Module_XX
01035   if (currDir.find("Module_") != string::npos ||
01036       currDir.find("FED_") != string::npos)  
01037   {
01038     vector<string> contents = bei->getMEs(); 
01039        
01040     for (vector<string>::const_iterator it = contents.begin(); it != contents.end(); it++) 
01041     {
01042       theME = (*it) ;
01043       if(theME.find("siPixel")==string::npos && theME.find("ctfWithMaterialTracks")==string::npos) {continue ;} // If the ME is not a siPixel or ctfWithMaterialTrack one, skip
01044       string temp_s = theME.substr(0,theME.find_first_of("_"));
01045       //cout<<"should be the variable name: temp_s= "<<temp_s<<endl;
01046       if (temp_s == theMEName)  
01047       {
01048         string full_path = currDir + "/" + (*it);
01049 
01050         MonitorElement * me = bei->get(full_path.c_str());
01051         
01052         if (me) {mes.push_back(me);}
01053       }
01054     }
01055     return;
01056   } else {  // If not yet reached the desired level in the directory tree, recursively go down one level more
01057     vector<string> subdirs = bei->getSubdirs();
01058     for (vector<string>::const_iterator it = subdirs.begin(); it != subdirs.end(); it++) 
01059     {
01060       bei->cd(*it);
01061       selectMEList(bei, theMEName, mes);
01062       bei->goUp();
01063     }
01064   }
01065 }
01066 
01067 //------------------------------------------------------------------------------
01071 void SiPixelInformationExtractor::sendTkUpdatedStatus(DQMStore  * bei, 
01072                                                       xgi::Output            * out,
01073                                                       std::string            & theMEName,
01074                                                       std::string            & theTKType) 
01075 {
01076 //  cout<<"In SiPixelInformationExtractor::sendTkUpdatedStatus: "<<endl;
01077   int rval, gval, bval;
01078   vector<string>          colorMap ;
01079   vector<MonitorElement*> me_list;
01080   pair<double,double>     norm ;
01081   double sts ;
01082     
01083   bei->cd();
01084   selectMEList(bei, theMEName, me_list) ;
01085   bei->cd();
01086 
01087   string detId = "undefined";
01088 
01089 /*   cout << ACYellow << ACBold
01090         << "[SiPixelInformationExtractor::sendTkUpdatedStatus()] "
01091         << ACPlain
01092         << "Preparing color map update for " 
01093         << theMEName
01094         << " type "
01095         << theTKType
01096         << " - List size: "
01097         << me_list.size() 
01098         << endl ;
01099 */  
01100   int maxEntries = 0 ;
01101   if( theTKType == "Entries") // In this case find the ME with the highest number of entries
01102   {                           // first and use that as a vertical scale normalization
01103    for(vector<MonitorElement*>::iterator it=me_list.begin(); it!=me_list.end(); it++)
01104    {
01105     int entries = (int)(*it)->getEntries() ;
01106     if( entries > maxEntries ) maxEntries = entries ;
01107    }
01108   }
01109   
01110   int entries = 0 ;
01111   stringstream jsSnippet ;
01112   for(vector<MonitorElement*>::iterator it=me_list.begin(); it!=me_list.end(); it++)
01113   {
01114     string meName    = (*it)->getName();
01115     string theMEType = getMEType(*it);
01116     if( meName.find("_3") != string::npos ) 
01117     {
01118      string detIdString = meName.substr(meName.find_last_of("_")+1,9);
01119      std::istringstream isst;
01120      isst.str(detIdString);
01121      isst>>detId;
01122      entries = (int)(*it)->getEntries() ;
01123      if( theTKType == "Averages") 
01124      {
01125       computeStatus(*it, sts, norm) ;
01126       SiPixelUtility::getStatusColor(sts, rval, gval, bval);
01127      } else if( theTKType == "Entries") {
01128       sts = (double)entries / (double)maxEntries ;
01129       SiPixelUtility::getStatusColor(sts, rval, gval, bval);
01130       if( entries > maxEntries ) maxEntries = entries ;
01131       norm.first  = 0 ;
01132       norm.second = maxEntries ;
01133      } else {
01134       int status  =  SiPixelUtility::getStatus((*it));
01135       if(        status == dqm::qstatus::ERROR ) 
01136       {
01137        rval = 255; gval =   0; bval =   0;
01138       } else if (status == dqm::qstatus::WARNING )  {
01139        rval = 255; gval = 255; bval =   0; 
01140       } else if (status == dqm::qstatus::OTHER)     {
01141        rval =   0; gval =   0; bval = 255;
01142       } else if (status == dqm::qstatus::STATUS_OK) {
01143        rval =   0; gval = 255; bval =   0;
01144       } else {  
01145        rval = 255; gval = 255; bval = 255;
01146       }
01147      }
01148      jsSnippet.str("") ;
01149      jsSnippet << " <DetInfo DetId='"
01150                << detId
01151                << "' red='"
01152                << rval
01153                << "' green='"
01154                << gval
01155                << "' blue='"
01156                << bval
01157                << "' entries='"
01158                << entries
01159                << "'/>" ;
01160      colorMap.push_back(jsSnippet.str()) ;
01161 //      if( it == me_list.begin()) // The first should be equal to all others...
01162 //      {
01163 //       getNormalization((*it), norm, theMEType.latin1()) ;
01164 //      }
01165     }
01166   }
01167 
01168 //  delete random ;
01169   
01170 /*   cout << ACYellow << ACBold
01171         << "[SiPixelInformationExtractor::sendTkUpdatedStatus()] "
01172         << ACPlain
01173         << "Color map consists of "
01174         << colorMap.size()
01175         << " snippets: start shipping back"
01176         << endl ;
01177 */
01178   out->getHTTPResponseHeader().addHeader("Content-Type", "text/xml");
01179   *out << "<?xml version=\"1.0\" ?>" << endl;
01180   *out << "<TrackerMapUpdate>"       << endl;
01181 
01182   for(vector<string>::iterator it=colorMap.begin(); it!=colorMap.end(); it++)
01183   {
01184    *out << *it << endl;
01185   }
01186  
01187   *out << " <theLimits id=\"normalizationLimits\" normLow=\"" 
01188        << norm.first 
01189        << "\" normHigh=\""
01190        << norm.second 
01191        << "\" />"
01192        << endl;
01193   *out << "</TrackerMapUpdate>"              
01194        << endl;
01195 
01196 /*   cout << ACYellow << ACBold
01197         << "[SiPixelInformationExtractor::sendTkUpdatedStatus()] "
01198         << ACPlain
01199         << "Color map updated within range " 
01200         << norm.first
01201         << "-"
01202         << norm.second
01203         << endl ;
01204 */
01205 }
01206 
01207 //------------------------------------------------------------------------------
01212 int SiPixelInformationExtractor::getDetId(MonitorElement * mE) 
01213 {
01214 //cout<<"In SiPixelInformationExtractor::getDetId: for ME= "<<mE->getName()<<endl;
01215  string mEName = mE->getName();
01216 
01217  int detId = 0;
01218  
01219  if( mEName.find("_3") != string::npos )
01220  {
01221   string detIdString = mEName.substr((mEName.find_last_of("_"))+1,9);
01222   //cout<<"string: "<<detIdString<<endl;
01223   std::istringstream isst;
01224   isst.str(detIdString);
01225   isst>>detId;
01226 // } else {
01227 //  cout << ACYellow << ACBold
01228 //       << "[SiPixelInformationExtractor::getDetId()] "
01229 //       << ACPlain
01230 //       << "Could not extract detId from "
01231 //       << mEName
01232 //       << endl ;
01233  }
01234   //cout<<"returning with: "<<detId<<endl;
01235   return detId ;
01236   
01237 }
01238 
01239 //------------------------------------------------------------------------------
01243 void SiPixelInformationExtractor::getMEList(DQMStore    * bei,  
01244                                             map<string, int>         & mEHash)
01245 {
01246   string currDir = bei->pwd();
01247    
01248 //   cout << ACRed << ACBold
01249 //        << "[SiPixelInformationExtractor::getMEList()]"
01250 //        << ACPlain
01251 //        << " Requesting ME list in " 
01252 //        << currDir
01253 //        << endl ;
01254        
01255   string theME ;
01256    
01257   // Get ME from Collector/FU0/Tracker/PixelEndcap/HalfCylinder_pX/Disk_X/Blade_XX/Panel_XX/Module_XX
01258   if (currDir.find("Module_") != string::npos ||
01259       currDir.find("FED_") != string::npos)  
01260   {
01261     vector<string> contents = bei->getMEs(); 
01262        
01263     for (vector<string>::const_iterator it = contents.begin(); it != contents.end(); it++) 
01264     {
01265       theME = (*it) ;
01266 //       cout << ACRed << ACReverse
01267 //            << "[SiPixelInformationExtractor::getMEList()]"
01268 //            << ACPlain
01269 //            << " ME: " 
01270 //            << (*it)
01271 //            << endl ;
01272       if(theME.find("siPixel")==string::npos && theME.find("ctfWithMaterialTracks")==string::npos) 
01273       {
01274        cout << ACRed << ACBold
01275             << "[SiPixelInformationExtractor::getMEList()]"
01276             << ACPlain
01277             << " ----> Skipping " 
01278             << (*it)
01279             << endl ;
01280        continue ;
01281       } // If the ME is not a Pixel one, skip
01282       string full_path = currDir + "/" + (*it);
01283       string mEName = theME.substr(0,theME.find_first_of("_"));
01284       mEHash[mEName]++ ;
01285     }
01286     
01287     return;
01288   } else {  // If not yet reached the desired level in the directory tree, recursively go down one level more
01289     vector<string> subdirs = bei->getSubdirs();
01290     for (vector<string>::const_iterator it = subdirs.begin(); it != subdirs.end(); it++) 
01291     {
01292       bei->cd(*it);
01293       getMEList(bei, mEHash);
01294       bei->goUp();
01295     }
01296   }
01297 }
01298 
01299 //
01300 // -- Get All histograms from a Path
01301 //
01302 void SiPixelInformationExtractor::getHistosFromPath(DQMStore * bei, 
01303                                                     const std::multimap<std::string, std::string>& req_map, 
01304                                                     xgi::Output * out){
01305 //cout<<"Entering SiPixelInformationExtractor::getHistosFromPath: "<<endl;
01306   string path = getItemValue(req_map,"Path");
01307 //cout<<"Path is: "<<path<<endl;
01308   if (path.size() == 0) return;
01309 
01310   int width  = atoi(getItemValue(req_map, "width").c_str());
01311   int height = atoi(getItemValue(req_map, "height").c_str());
01312 
01313   string opt =" ";
01314 
01315   setHTMLHeader(out);
01316   vector<MonitorElement*> all_mes = bei->getContents(path);
01317   *out << path << " " ;
01318   for(vector<MonitorElement*>::iterator it=all_mes.begin(); it!=all_mes.end(); it++){
01319     MonitorElement* me = (*it);
01320     //cout<<"I'm in the loop now..."<<endl;
01321     if (!me) continue;
01322     string name = me->getName();
01323     string full_path = path + "/" + name;
01324 //cout<<"Calling HP::setNewPlot now for "<<full_path<<endl;
01325     histoPlotter_->setNewPlot(full_path, opt, width, height);
01326     *out << name << " ";
01327   }
01328 //  cout<<"... leaving SiPixelInformationExtractor::getHistosFromPath!"<<endl;
01329 }
01330 
01332 
01333 void SiPixelInformationExtractor::bookNoisyPixels(DQMStore * bei, float noiseRate_,bool Tier0Flag) {
01334 //std::cout<<"BOOK NOISY PIXEL MEs!"<<std::endl;
01335   bei->cd();
01336   if(noiseRate_>=0.){
01337     bei->setCurrentFolder("Pixel/Barrel");
01338     EventRateBarrelPixels = bei->book1D("barrelEventRate","Digi event rate for all Barrel pixels",1000,0.,0.01);
01339     EventRateBarrelPixels->setAxisTitle("Event Rate",1);
01340     EventRateBarrelPixels->setAxisTitle("Number of Pixels",2);
01341     bei->cd();  
01342     bei->setCurrentFolder("Pixel/Endcap");
01343     EventRateEndcapPixels = bei->book1D("endcapEventRate","Digi event rate for all Endcap pixels",1000,0.,0.01);
01344     EventRateEndcapPixels->setAxisTitle("Event Rate",1);
01345     EventRateEndcapPixels->setAxisTitle("Number of Pixels",2);
01346   }
01347 }
01348 
01349           
01351 
01352 void SiPixelInformationExtractor::findNoisyPixels(DQMStore * bei, bool init, float noiseRate_, int noiseRateDenominator_, edm::EventSetup const& eSetup)
01353 {
01354 //cout<<"Entering SiPixelInformationExtractor::findNoisyPixels with noiseRate set to "<<noiseRate_<<endl;
01355 
01356   
01357   if(init){
01358     endOfModules_=false;
01359     nevents_=noiseRateDenominator_;
01360     if(nevents_ == -1){
01361       bei->cd();
01362       bei->setCurrentFolder("Pixel/EventInfo");
01363       nevents_ = (bei->get("Pixel/EventInfo/processedEvents"))->getIntValue();
01364     }
01365     bei->cd();  
01366     myfile_.open ("NoisyPixelList.txt", ios::app);
01367     myfile_ << "Noise summary, ran over " << nevents_ << " events, threshold was set to " << noiseRate_ <<  std::endl;
01368   }
01369   string currDir = bei->pwd();
01370   string dname = currDir.substr(currDir.find_last_of("/")+1);
01371 
01372 
01373   if(dname.find("Module_")!=string::npos){
01374     vector<string> meVec = bei->getMEs();
01375     for (vector<string>::const_iterator it = meVec.begin(); it != meVec.end(); it++) {
01376       string full_path = currDir + "/" + (*it);
01377       if(full_path.find("hitmap_siPixelDigis")!=string::npos){
01378         //broken HV bond:
01379         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_01/Panel_2/Module_2")!=string::npos) continue;
01380         //?noisy?
01381         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_12/Panel_1/Module_4")!=string::npos) continue;
01382         //ROG with HV problem (short?):
01383         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_10/Panel_1/Module_3")!=string::npos) continue;
01384         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_10/Panel_1/Module_4")!=string::npos) continue;
01385         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_10/Panel_2/Module_2")!=string::npos) continue;
01386         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_10/Panel_2/Module_3")!=string::npos) continue;
01387         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_11/Panel_1/Module_3")!=string::npos) continue;
01388         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_11/Panel_1/Module_4")!=string::npos) continue;
01389         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_11/Panel_2/Module_2")!=string::npos) continue;
01390         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_11/Panel_2/Module_3")!=string::npos) continue;
01391         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_12/Panel_1/Module_3")!=string::npos) continue;
01392         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_12/Panel_1/Module_4")!=string::npos) continue;
01393         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_12/Panel_2/Module_2")!=string::npos) continue;
01394         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_12/Panel_2/Module_3")!=string::npos) continue;
01395         MonitorElement * me = bei->get(full_path);
01396         if (!me) continue;
01397         int detid=getDetId(me); int pixcol=-1; int pixrow=-1; 
01398 
01399         //cout<<"detid= "<<detid<<endl;
01400         std::vector<std::pair<std::pair<int, int>, float> > noisyPixelsInModule;
01401         TH2F * hothisto = me->getTH2F();
01402         if(hothisto){
01403           for(int i=1; i!=hothisto->GetNbinsX()+1; i++){
01404             for(int j=1; j!=hothisto->GetNbinsY()+1; j++){
01405               float value = (hothisto->GetBinContent(i,j))/float(nevents_);
01406               if(me->getPathname().find("Barrel")!=string::npos){
01407                 EventRateBarrelPixels = bei->get("Pixel/Barrel/barrelEventRate");
01408                 if(EventRateBarrelPixels) EventRateBarrelPixels->Fill(value);
01409               }else if(me->getPathname().find("Endcap")!=string::npos){
01410                 EventRateEndcapPixels = bei->get("Pixel/Endcap/endcapEventRate");
01411                 if(EventRateEndcapPixels) EventRateEndcapPixels->Fill(value);
01412               }
01413               if(value > noiseRate_){
01414                 pixcol = i-1;
01415                 pixrow = j-1;
01416                 //cout<<"pixcol= "<<pixcol<<" , pixrow= "<<pixrow<<" , value= "<<value<<endl;
01417  
01418                 std::pair<int, int> address(pixcol, pixrow);
01419                 std::pair<std::pair<int, int>, float>  PixelStats(address, value);
01420                 noisyPixelsInModule.push_back(PixelStats);
01421               }
01422             }
01423           }
01424         }
01425         noisyDetIds_[detid] = noisyPixelsInModule;
01426         //if(noisyPixelsInModule.size()>=20) cout<<"This module has 20 or more hot pixels: "<<detid<<","<<bei->pwd()<<","<<noisyPixelsInModule.size()<<endl;
01427       }
01428     }
01429   }
01430   vector<string> subDirVec = bei->getSubdirs();  
01431   for (vector<string>::const_iterator ic = subDirVec.begin();
01432        ic != subDirVec.end(); ic++) {
01433     if((*ic).find("AdditionalPixelErrors")!=string::npos) continue;
01434     bei->cd(*ic);
01435     init=false;
01436     findNoisyPixels(bei,init,noiseRate_,noiseRateDenominator_,eSetup);
01437     bei->goUp();
01438   }
01439 
01440   if(bei->pwd().find("EventInfo")!=string::npos) endOfModules_ = true;
01441   
01442   if(!endOfModules_) return;
01443   // myfile_ <<"am in "<<bei->pwd()<<" now!"<<endl;
01444   if(currDir == "Pixel/EventInfo/reportSummaryContents"){
01445     eSetup.get<SiPixelFedCablingMapRcd>().get(theCablingMap);
01446     std::vector<std::pair<sipixelobjects::DetectorIndex,double> > pixelvec;
01447     std::map<uint32_t,int> myfedmap;
01448     std::map<uint32_t,std::string> mynamemap;
01449     int realfedID = -1;
01450     //int Nnoisies = noisyDetIds_.size();
01451     //cout<<"Number of noisy modules: "<<Nnoisies<<endl;
01452     int counter = 0;
01453     int n_noisyrocs_all = 0;
01454     int n_noisyrocs_barrel = 0;
01455     int n_noisyrocs_endcap = 0;
01456     int n_verynoisyrocs_all = 0;
01457     int n_verynoisyrocs_barrel = 0;
01458     int n_verynoisyrocs_endcap = 0;
01459 
01460     for(int fid = 0; fid < 40; fid++){
01461     for(std::map<uint32_t, std::vector< std::pair<std::pair<int, int>, float> > >::const_iterator it = noisyDetIds_.begin(); 
01462         it != noisyDetIds_.end(); it++){
01463       uint32_t detid = (*it).first;
01464       std::vector< std::pair<std::pair<int, int>, float> > noisyPixels = (*it).second;
01465       //cout<<noisyPixels.size()<<" noisy pixels in a module: "<<detid<<endl;
01466       // now convert into online conventions:
01467       for(int fedid=0; fedid<=40; ++fedid){
01468         SiPixelFrameConverter converter(theCablingMap.product(),fedid);
01469         uint32_t newDetId = detid;
01470         if(converter.hasDetUnit(newDetId)){
01471           realfedID=fedid;
01472           break;   
01473         }
01474       }
01475       if(fid == realfedID){
01476       //cout<<"FED ID is = "<<realfedID<<endl;
01477       if(realfedID==-1) continue; 
01478       DetId detId(detid);
01479       uint32_t detSubId = detId.subdetId();
01480       std::string outputname;
01481       bool HalfModule = false;
01482       if (detSubId == 2){   //FPIX
01483         PixelEndcapName nameworker(detid);
01484         outputname = nameworker.name();
01485       } else if(detSubId == 1){   //BPIX
01486         PixelBarrelName nameworker(detid);
01487         outputname = nameworker.name();
01488         HalfModule = nameworker.isHalfModule();
01489 
01490       } else{
01491         continue;
01492       } 
01493       std::map<int,int> myrocmap;
01494       myfedmap[detid]=realfedID;
01495       mynamemap[detid]=outputname;
01496       
01497       for(std::vector< std::pair< std::pair<int,int>, float> >::const_iterator pxl = noisyPixels.begin(); 
01498           pxl != noisyPixels.end(); pxl++){
01499         std::pair<int,int> offlineaddress = (*pxl).first;
01500         float Noise_frac = (*pxl).second;
01501         int offlineColumn = offlineaddress.first;
01502         int offlineRow = offlineaddress.second;
01503         counter++;
01504         //cout<<"noisy pixel counter: "<<counter<<endl;
01505 
01506         sipixelobjects::ElectronicIndex cabling; 
01507         SiPixelFrameConverter formatter(theCablingMap.product(),realfedID);
01508         sipixelobjects::DetectorIndex detector = {detid, offlineRow, offlineColumn};      
01509         formatter.toCabling(cabling,detector);
01510         // cabling should now contain cabling.roc and cabling.dcol  and cabling.pxid
01511         // however, the coordinates now need to be converted from dcl,pxid to the row,col coordinates used in the calibration info 
01512         sipixelobjects::LocalPixel::DcolPxid loc;
01513         loc.dcol = cabling.dcol;
01514         loc.pxid = cabling.pxid;
01515         
01516         
01517         // OLD version, not 31X compatible:
01518 //        const sipixelobjects::PixelFEDCabling *theFed= theCablingMap.product()->fed(realfedID);
01519 //      const sipixelobjects::PixelFEDLink * link = theFed->link(cabling.link);
01520 //      const sipixelobjects::PixelROC *theRoc = link->roc(cabling.roc);
01521 //      sipixelobjects::LocalPixel locpixel(loc);
01522         
01523         
01524         // FIX to adhere to new cabling map. To be replaced with CalibTracker/SiPixelTools detid - > hardware id classes ASAP.
01525         //        const sipixelobjects::PixelFEDCabling *theFed= theCablingMap.product()->fed(realfedID);
01526         //        const sipixelobjects::PixelFEDLink * link = theFed->link(cabling.link);
01527         //        const sipixelobjects::PixelROC *theRoc = link->roc(cabling.roc);
01528         sipixelobjects::LocalPixel locpixel(loc);
01529         sipixelobjects::CablingPathToDetUnit path = {realfedID, cabling.link, cabling.roc};  
01530         const sipixelobjects::PixelROC *theRoc = theCablingMap->findItem(path);
01531         // END of FIX
01532         
01533         int onlineColumn = locpixel.rocCol();
01534         int onlineRow= locpixel.rocRow();
01535         myrocmap[(theRoc->idInDetUnit())]++;
01536 
01537         // ROC numbers in the barrel go from 8 to 15 instead of 0 to 7 in half modules.  This is a 
01538         // fix to get the roc number, and add 8 to it if:
01539         // it's a Barrel module AND on the minus side AND a Half module
01540 
01541         int rocnumber = -1;
01542 
01543         if((detSubId == 1) && (outputname.find("mO")!=string::npos || outputname.find("mI")!=string::npos) && (HalfModule)){
01544           rocnumber = theRoc->idInDetUnit() + 8;
01545         }
01546         else{
01547           rocnumber = theRoc->idInDetUnit();
01548         }
01549 
01550         //cout<<counter<<" : \t detid= "<<detid<<" , OFF col,row= "<<offlineColumn<<","<<offlineRow<<" , ON roc,col,row= "<<theRoc->idInDetUnit()<<","<<onlineColumn<<","<<onlineRow<<endl;
01551         myfile_ <<"NAME: "<<outputname<<" , DETID: "<<detid<<" , OFFLINE: col,row: "<<offlineColumn<<","<<offlineRow<<"  \t , ONLINE: roc,col,row: "<<rocnumber<<","<<onlineColumn<<","<<onlineRow<< "  \t , fed,dcol,pixid,link: "<<realfedID<<","<<loc.dcol<<","<<loc.pxid<<","<<cabling.link << ", Noise fraction: " << Noise_frac << std::endl;
01552       }
01553       for(std::map<int, int>::const_iterator nrc = myrocmap.begin(); nrc != myrocmap.end(); nrc++){
01554         if((*nrc).second > 0){
01555           n_noisyrocs_all++;
01556           if(detSubId == 2){
01557             n_noisyrocs_endcap++;
01558           } else if(detSubId == 1){
01559             n_noisyrocs_barrel++;}
01560         }
01561         if((*nrc).second > 40){
01562           n_verynoisyrocs_all++;
01563           if(detSubId == 2){
01564             n_verynoisyrocs_endcap++;
01565           } else if(detSubId == 1){
01566             n_verynoisyrocs_barrel++;}
01567         }
01568       }
01569       }
01570 
01571     }
01572     }
01573     myfile_ << "There are " << n_noisyrocs_all << " noisy ROCs (ROCs with at least 1 noisy pixel) in the entire detector. " << n_noisyrocs_endcap << " are in the FPIX and " << n_noisyrocs_barrel << " are in the BPIX. " << endl;
01574     myfile_ << "There are " << n_verynoisyrocs_all << " highly noisy ROCs (ROCs with at least 10% of all pixels passing the noise threshold) in the entire detector. " << n_verynoisyrocs_endcap << " are in the FPIX and " << n_verynoisyrocs_barrel << " are in the BPIX. " << endl;
01575 
01576   }
01577   myfile_.close();
01578 //cout<<"...leaving SiPixelInformationExtractor::findNoisyPixels!"<<endl;
01579   return;
01580 }
01581 
01582 
01583 //
01584 // -- Create Images 
01585 //
01586 void SiPixelInformationExtractor::createImages(DQMStore* bei){
01587   histoPlotter_->createPlots(bei);
01588 }
01589 
01590 //
01591 // -- Set HTML Header in xgi output
01592 //
01593 void SiPixelInformationExtractor::setHTMLHeader(xgi::Output * out) {
01594   out->getHTTPResponseHeader().addHeader("Content-Type", "text/html");
01595   out->getHTTPResponseHeader().addHeader("Pragma", "no-cache");   
01596   out->getHTTPResponseHeader().addHeader("Cache-Control", "no-store, no-cache, must-revalidate,max-age=0");
01597   out->getHTTPResponseHeader().addHeader("Expires","Mon, 26 Jul 1997 05:00:00 GMT");
01598 }
01599 //
01600 // -- Set XML Header in xgi output
01601 //
01602 void SiPixelInformationExtractor::setXMLHeader(xgi::Output * out) {
01603   out->getHTTPResponseHeader().addHeader("Content-Type", "text/xml");
01604   out->getHTTPResponseHeader().addHeader("Pragma", "no-cache");   
01605   out->getHTTPResponseHeader().addHeader("Cache-Control", "no-store, no-cache, must-revalidate,max-age=0");
01606   out->getHTTPResponseHeader().addHeader("Expires","Mon, 26 Jul 1997 05:00:00 GMT");
01607   *out << "<?xml version=\"1.0\" ?>" << std::endl;
01608 
01609 }
01610 //
01611 // -- Set Plain Header in xgi output
01612 //
01613 void SiPixelInformationExtractor::setPlainHeader(xgi::Output * out) {
01614   out->getHTTPResponseHeader().addHeader("Content-Type", "text/plain");
01615   out->getHTTPResponseHeader().addHeader("Pragma", "no-cache");   
01616   out->getHTTPResponseHeader().addHeader("Cache-Control", "no-store, no-cache, must-revalidate,max-age=0");
01617   out->getHTTPResponseHeader().addHeader("Expires","Mon, 26 Jul 1997 05:00:00 GMT");
01618 
01619 }