CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/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   string currDir = bei->pwd();
00406   string dname = currDir.substr(currDir.find_last_of("/")+1);
00407   str_val << " <li>\n"
00408           << "  <a href=\"#\" id=\"" << currDir << "\">\n   " 
00409           <<     dname << "\n"
00410           << "  </a>\n"
00411           << endl << endl;
00412 
00413   vector<string> meVec     = bei->getMEs(); 
00414   
00415   vector<string> subDirVec = bei->getSubdirs();
00416   if ( meVec.size()== 0  && subDirVec.size() == 0 ) {
00417     str_val << " </li>" << endl;    
00418     return;
00419   }
00420   str_val << "\n   <ul>" << endl; 
00421   for (vector<string>::const_iterator it  = meVec.begin();
00422                                       it != meVec.end(); it++) {
00423     if ((*it).find("_siPixel")!=string::npos || 
00424         (*it).find("_ctfWithMaterialTracks")!=string::npos) {
00425       string qit = (*it) ;
00426       string temp_s;
00427       if(qit.find("siPixel")!=string::npos || qit.find("ctfWithMaterialTracks")!=string::npos) { temp_s = qit.substr(0,qit.find_first_of("_")); }
00428       str_val << "    <li class=\"dhtmlgoodies_sheet.gif\">\n"
00429               << "     <input id      = \"selectedME\""
00430               << "            folder  = \"" << currDir << "\""
00431               << "            type    = \"checkbox\""
00432               << "            name    = \"selected\""
00433               << "            class   = \"smallCheckBox\""
00434               << "            value   = \"" << (*it) << "\""
00435               << "            onclick = \"javascript:IMGC.selectedIMGCItems()\" />\n"
00436 //            << "     <a href=\"javascript:IMGC.updateIMGC('" << currDir << "')\">\n       " 
00437               << "     <a href=\"javascript:IMGC.plotFromPath('" << currDir << "')\">\n       " 
00438 //            <<        temp_s << "\n"
00439               <<        (*it) << "\n"
00440               << "     </a>\n"
00441               << "    </li>" 
00442               << endl;
00443     }
00444   }
00445   for (vector<string>::const_iterator ic  = subDirVec.begin();
00446                                       ic != subDirVec.end(); ic++) {
00447     bei->cd(*ic);
00448     printModuleHistoList(bei, str_val);
00449     bei->goUp();
00450   }
00451   str_val << "   </ul>" << endl;  
00452   str_val << "  </li>"  << endl;  
00453 //cout<<"leaving SiPixelInformationExtractor::printModuleHistoList"<<endl;
00454 }
00455 
00456 //------------------------------------------------------------------------------
00461 void SiPixelInformationExtractor::readSummaryHistoTree(DQMStore* bei, 
00462                                                        string& str_name, 
00463                                                        xgi::Output * out) {
00464 //cout<<"entering  SiPixelInformationExtractor::readSummaryHistoTree"<<endl;
00465   ostringstream sumtree;
00466   if (goToDir(bei, str_name)) {
00467     sumtree << "<ul id=\"dhtmlgoodies_tree\" class=\"dhtmlgoodies_tree\">" << endl;
00468     printSummaryHistoList(bei,sumtree);
00469     sumtree <<"</ul>" << endl;   
00470   } else {
00471     sumtree << "Desired Directory does not exist";
00472   }
00473   cout << ACYellow << ACBold
00474        << "[SiPixelInformationExtractor::readSummaryHistoTree()]"
00475        << ACPlain << endl ;
00476   //     << "html string follows: " << endl ;
00477   //cout << sumtree.str() << endl ;
00478   //cout << ACYellow << ACBold
00479   //     << "[SiPixelInformationExtractor::readSummaryHistoTree()]"
00480   //     << ACPlain
00481   //     << "String complete " << endl ;
00482   out->getHTTPResponseHeader().addHeader("Content-Type", "text/plain");
00483   *out << sumtree.str();
00484    bei->cd();
00485 //cout<<"leaving  SiPixelInformationExtractor::readSummaryHistoTree"<<endl;
00486 }
00487 //------------------------------------------------------------------------------
00494 void SiPixelInformationExtractor::printSummaryHistoList(DQMStore * bei, 
00495                                                         ostringstream& str_val){
00496 //cout<<"entering SiPixelInformationExtractor::printSummaryHistoList"<<endl;
00497   string currDir = bei->pwd();
00498   string dname = currDir.substr(currDir.find_last_of("/")+1);
00499   if (dname.find("Module_") ==0 || dname.find("FED_")==0) return;
00500   str_val << " <li>\n"
00501           << "  <a href=\"#\" id=\"" << currDir << "\">\n   " 
00502           <<     dname 
00503           << "  </a>" 
00504           << endl;
00505 
00506   vector<string> meVec     = bei->getMEs(); 
00507   
00508   vector<string> subDirVec = bei->getSubdirs();
00509   if ( meVec.size()== 0  && subDirVec.size() == 0 ) {
00510     str_val << " </li> "<< endl;    
00511     return;
00512   }
00513   str_val << "\n   <ul>" << endl;      
00514   for (vector<string>::const_iterator it = meVec.begin();
00515        it != meVec.end(); it++) {
00516     if ((*it).find("SUM") == 0) {
00517       str_val << "    <li class=\"dhtmlgoodies_sheet.gif\">\n"
00518               << "     <input id      = \"selectedME\""
00519               << "            folder  = \"" << currDir << "\""
00520               << "            type    = \"checkbox\""
00521               << "            name    = \"selected\""
00522               << "            class   = \"smallCheckBox\""
00523               << "            value   = \"" << (*it) << "\""
00524               << "            onclick = \"javascript:IMGC.selectedIMGCItems()\" />\n"
00525 //              << "     <a href=\"javascript:IMGC.updateIMGC('" << currDir << "')\">\n       " 
00526               << "     <a href=\"javascript:IMGC.plotFromPath('" << currDir << "')\">\n       " 
00527               <<       (*it) << "\n"
00528               << "     </a>\n"
00529               << "    </li>" 
00530               << endl;
00531     }
00532   }
00533 
00534   for (vector<string>::const_iterator ic = subDirVec.begin();
00535        ic != subDirVec.end(); ic++) {
00536     bei->cd(*ic);
00537     printSummaryHistoList(bei, str_val);
00538     bei->goUp();
00539   }
00540   str_val << "   </ul> "<< endl;  
00541   str_val << "  </li> "<< endl;  
00542 //cout<<"leaving SiPixelInformationExtractor::printSummaryHistoList"<<endl;
00543 }
00544 
00545 
00546 //------------------------------------------------------------------------------
00551 void SiPixelInformationExtractor::readAlarmTree(DQMStore* bei, 
00552                                                 string& str_name, 
00553                                                 xgi::Output * out){
00554 //cout<<"entering SiPixelInformationExtractor::readAlarmTree"<<endl;
00555   ostringstream alarmtree;
00556   if (goToDir(bei, str_name)) {
00557     alarmtree << "<ul id=\"dhtmlgoodies_tree\" class=\"dhtmlgoodies_tree\">" << endl;
00558     alarmCounter_=0;
00559     printAlarmList(bei,alarmtree);
00560     if(alarmCounter_==0) alarmtree <<"<li>No problematic modules found, all ok!</li>" << endl;
00561     alarmtree <<"</ul>" << endl; 
00562   } else {
00563     alarmtree << "Desired Directory does not exist";
00564   }
00565   cout << ACYellow << ACBold
00566        << "[SiPixelInformationExtractor::readAlarmTree()]"
00567        << ACPlain << endl ;
00568   //     << "html string follows: " << endl ;
00569   //cout << alarmtree.str() << endl ;
00570   //cout << ACYellow << ACBold
00571   //     << "[SiPixelInformationExtractor::readAlarmTree()]"
00572   //     << ACPlain
00573   //     << "String complete " << endl ;
00574   out->getHTTPResponseHeader().addHeader("Content-Type", "text/plain");
00575  *out << alarmtree.str();
00576   bei->cd();
00577   cout << ACYellow << ACBold
00578        << "[SiPixelInformationExtractor::readAlarmTree()]"
00579        << ACPlain 
00580        << " Done!"
00581        << endl ;
00582 //cout<<"leaving SiPixelInformationExtractor::readAlarmTree"<<endl;
00583 }
00584 //------------------------------------------------------------------------------
00591 void SiPixelInformationExtractor::printAlarmList(DQMStore * bei, 
00592                                                  ostringstream& str_val){
00593 //cout<<"entering SiPixelInformationExtractor::printAlarmList"<<endl;
00594 //   cout << ACRed << ACBold
00595 //        << "[SiPixelInformationExtractor::printAlarmList()]"
00596 //        << ACPlain
00597 //        << " Enter" 
00598 //        << endl ;
00599   string currDir = bei->pwd();
00600   string dname = currDir.substr(currDir.find_last_of("/")+1);
00601   string image_name;
00602   selectImage(image_name,bei->getStatus(currDir));
00603   if(image_name!="images/LI_green.gif")
00604     str_val << " <li>\n"
00605             << "  <a href=\"#\" id=\"" << currDir << "\">\n   " 
00606             <<     dname 
00607             << "  </a>\n"
00608             << "  <img src=\"" 
00609             <<     image_name 
00610             << "\">" << endl;
00611   vector<string> subDirVec = bei->getSubdirs();
00612 
00613   vector<string> meVec = bei->getMEs();
00614    
00615   if (subDirVec.size() == 0 && meVec.size() == 0) {
00616     str_val <<  "</li> "<< endl;    
00617     return;
00618   }
00619   str_val << "<ul>" << endl;
00620   for (vector<string>::const_iterator it = meVec.begin();
00621            it != meVec.end(); it++) {
00622     string full_path = currDir + "/" + (*it);
00623 
00624     MonitorElement * me = bei->get(full_path);
00625     
00626     if (!me) continue;
00627     std::vector<QReport *> my_map = me->getQReports();
00628     if (my_map.size() > 0) {
00629       string image_name1;
00630       selectImage(image_name1,my_map);
00631       if(image_name1!="images/LI_green.gif") {
00632         alarmCounter_++;
00633         str_val << "    <li class=\"dhtmlgoodies_sheet.gif\">\n"
00634                 << "     <input id      = \"selectedME\""
00635                 << "            folder  = \"" << currDir << "\""
00636                 << "            type    = \"checkbox\""
00637                 << "            name    = \"selected\""
00638                 << "            class   = \"smallCheckBox\""
00639                 << "            value   = \"" << (*it) << "\""
00640                 << "            onclick = \"javascript:IMGC.selectedIMGCItems()\" />\n"
00641 //              << "     <a href=\"javascript:IMGC.updateIMGC('" << currDir << "')\">\n       " 
00642                 << "     <a href=\"javascript:IMGC.plotFromPath('" << currDir << "')\">\n       " 
00643                 <<        (*it) << "\n"
00644                 << "     </a>\n"
00645                 << "     <img src=\""
00646                 <<        image_name1 
00647                 << "\">"
00648                 << "    </li>" 
00649                 << endl;
00650         }       
00651     }
00652   }
00653   for (vector<string>::const_iterator ic = subDirVec.begin();
00654        ic != subDirVec.end(); ic++) {
00655     bei->cd(*ic);
00656     printAlarmList(bei, str_val);
00657     bei->goUp();
00658   }
00659   str_val << "</ul> "<< endl;  
00660   str_val << "</li> "<< endl;  
00661 //   cout << ACGreen << ACBold
00662 //        << "[SiPixelInformationExtractor::printAlarmList()]"
00663 //        << ACPlain
00664 //        << " Done" 
00665 //        << endl ;
00666 //cout<<"leaving SiPixelInformationExtractor::printAlarmList"<<endl;
00667 }
00668 
00669 
00670 //------------------------------------------------------------------------------
00675 void SiPixelInformationExtractor::getItemList(const multimap<string, string>& req_map, 
00676                                               string item_name,
00677                                               vector<string>& items) {
00678 //cout<<"entering SiPixelInformationExtractor::getItemList"<<endl;
00679   items.clear();
00680   for (multimap<string, string>::const_iterator it = req_map.begin();
00681        it != req_map.end(); it++) {
00682     if (it->first == item_name) {
00683       items.push_back(it->second);
00684     }
00685   }
00686 //cout<<"leaving SiPixelInformationExtractor::getItemList"<<endl;
00687 }
00688 
00689 //------------------------------------------------------------------------------
00694 bool SiPixelInformationExtractor::hasItem(multimap<string,string>& req_map,
00695                                           string item_name){
00696 //cout<<"entering SiPixelInformationExtractor::hasItem"<<endl;
00697   multimap<string,string>::iterator pos = req_map.find(item_name);
00698   if (pos != req_map.end()) return true;
00699   return false;  
00700 //cout<<"leaving SiPixelInformationExtractor::hasItem"<<endl;
00701 }
00702 
00703 //------------------------------------------------------------------------------
00708 std::string SiPixelInformationExtractor::getItemValue(const std::multimap<std::string,std::string>& req_map,
00709                                                  std::string item_name){
00710 //cout<<"entering SiPixelInformationExtractor::getItemValue for item: "<<item_name<<endl;
00711   std::multimap<std::string,std::string>::const_iterator pos = req_map.find(item_name);
00712   std::string value = " ";
00713   if (pos != req_map.end()) {
00714     value = pos->second;
00715   }
00716 //  cout<<"value = "<<value<<endl;
00717   return value;
00718 //cout<<"leaving SiPixelInformationExtractor::getItemValue"<<endl;
00719 }
00720 std::string SiPixelInformationExtractor::getItemValue(std::multimap<std::string,std::string>& req_map,
00721                                                  std::string item_name){
00722 //cout<<"entering SiPixelInformationExtractor::getItemValue for item: "<<item_name<<endl;
00723   std::multimap<std::string,std::string>::iterator pos = req_map.find(item_name);
00724   std::string value = " ";
00725   if (pos != req_map.end()) {
00726 //  cout<<"item found!"<<endl;
00727     value = pos->second;
00728   }
00729 //  cout<<"value = "<<value<<endl;
00730   return value;
00731 //cout<<"leaving SiPixelInformationExtractor::getItemValue"<<endl;
00732 }
00733 
00734 //
00735 // -- Get color  name from status
00736 //
00737 void SiPixelInformationExtractor::selectColor(string& col, int status){
00738   if (status == dqm::qstatus::STATUS_OK)    col = "#00ff00";
00739   else if (status == dqm::qstatus::WARNING) col = "#ffff00";
00740   else if (status == dqm::qstatus::ERROR)   col = "#ff0000";
00741   else if (status == dqm::qstatus::OTHER)   col = "#ffa500";
00742   else  col = "#0000ff";
00743 }
00744 //
00745 // -- Get Image name from ME
00746 //
00747 void SiPixelInformationExtractor::selectColor(string& col, vector<QReport*>& reports){
00748   int istat = 999;
00749   int status = 0;
00750   for (vector<QReport*>::const_iterator it = reports.begin(); it != reports.end();
00751        it++) {
00752     status = (*it)->getStatus();
00753     if (status > istat) istat = status;
00754   }
00755   selectColor(col, status);
00756 }
00757 //
00758 // -- Get Image name from status
00759 //
00760 void SiPixelInformationExtractor::selectImage(string& name, int status){
00761   if (status == dqm::qstatus::STATUS_OK) name="images/LI_green.gif";
00762   else if (status == dqm::qstatus::WARNING) name="images/LI_yellow.gif";
00763   else if (status == dqm::qstatus::ERROR) name="images/LI_red.gif";
00764   else if (status == dqm::qstatus::OTHER) name="images/LI_orange.gif";
00765   else  name="images/LI_blue.gif";
00766 }
00767 //
00768 // -- Get Image name from ME
00769 //
00770 void SiPixelInformationExtractor::selectImage(string& name, vector<QReport*>& reports){
00771   int istat = 999;
00772   int status = 0;
00773   for (vector<QReport*>::const_iterator it = reports.begin(); it != reports.end();
00774        it++) {
00775     status = (*it)->getStatus();
00776     if (status > istat) istat = status;
00777   }
00778   selectImage(name, status);
00779 }
00780 
00781 //
00782 // -- Get a tagged image 
00783 //
00784 void SiPixelInformationExtractor::getIMGCImage(const multimap<string, string>& req_map, 
00785                                                xgi::Output * out){
00786   string path = getItemValue(req_map,"Path");
00787   string image;
00788   histoPlotter_->getNamedImageBuffer(path, image);
00789 
00790   out->getHTTPResponseHeader().addHeader("Content-Type", "image/png");
00791   out->getHTTPResponseHeader().addHeader("Pragma", "no-cache");   
00792   out->getHTTPResponseHeader().addHeader("Cache-Control", "no-store, no-cache, must-revalidate,max-age=0");
00793   out->getHTTPResponseHeader().addHeader("Expires","Mon, 26 Jul 1997 05:00:00 GMT");
00794   *out << image;
00795 }
00796 
00797 void SiPixelInformationExtractor::getIMGCImage(multimap<string, string>& req_map, 
00798                                                xgi::Output * out){
00799   
00800   string path = getItemValue(req_map,"Path");
00801   string image;
00802   histoPlotter_->getNamedImageBuffer(path, image);
00803 
00804   out->getHTTPResponseHeader().addHeader("Content-Type", "image/png");
00805   out->getHTTPResponseHeader().addHeader("Pragma", "no-cache");   
00806   out->getHTTPResponseHeader().addHeader("Cache-Control", "no-store, no-cache, must-revalidate,max-age=0");
00807   out->getHTTPResponseHeader().addHeader("Expires","Mon, 26 Jul 1997 05:00:00 GMT");
00808   *out << image;
00809 
00810 }
00811 
00812 
00813 //------------------------------------------------------------------------------
00818 bool SiPixelInformationExtractor::goToDir(DQMStore* bei, 
00819                                           string& sname){ 
00820 //cout<<"entering SiPixelInformationExtractor::goToDir"<<endl;
00821   bei->cd();
00822   //if(flg) bei->cd("Collector/Collated");
00823   bei->cd(sname);
00824   string dirName = bei->pwd();
00825   if (dirName.find(sname) != string::npos) return true;
00826   else return false;  
00827 //cout<<"leaving SiPixelInformationExtractor::goToDir"<<endl;
00828 }
00829 
00830 //
00831 // -- Get Warning/Error Messages
00832 //
00833 void SiPixelInformationExtractor::readStatusMessage(DQMStore* bei, 
00834                                                     std::multimap<std::string, std::string>& req_map, 
00835                                                     xgi::Output * out){
00836 
00837   string path = getItemValue(req_map,"Path");
00838 
00839   int width  = atoi(getItemValue(req_map, "width").c_str());
00840   int height = atoi(getItemValue(req_map, "height").c_str());
00841 
00842   string opt =" ";
00843 
00844   ostringstream test_status;
00845   
00846   setXMLHeader(out);
00847   *out << "<StatusAndPath>" << endl;
00848   *out << "<PathList>" << endl;
00849   if (path.size() == 0) {
00850     *out << "<HPath>" << "NONE" << "</HPath>" << endl;     
00851     test_status << " ME Does not exist ! " << endl;
00852   } else {
00853     vector<MonitorElement*> all_mes = bei->getContents(path);
00854     *out << "<HPath>" << path << "</HPath>" << endl;     
00855     for(vector<MonitorElement*>::iterator it=all_mes.begin(); it!=all_mes.end(); it++){
00856       MonitorElement* me = (*it);
00857       if (!me) continue;
00858       string name = me->getName();  
00859 
00860       vector<QReport*> q_reports = me->getQReports();
00861       if (q_reports.size() == 0) continue;
00862       string full_path = path + "/" + name;
00863       histoPlotter_->setNewPlot(full_path, opt, width, height);
00864 
00865       if (q_reports.size() != 0) {
00866         test_status << " QTest Status for " << name << " : " << endl;
00867         test_status << " ======================================================== " << endl; 
00868         for (vector<QReport*>::const_iterator it = q_reports.begin(); it != q_reports.end();
00869              it++) {
00870           int status = (*it)->getStatus();
00871           if (status == dqm::qstatus::WARNING) test_status << " Warning ";
00872           else if (status == dqm::qstatus::ERROR) test_status << " Error  ";
00873           else if (status == dqm::qstatus::STATUS_OK) test_status << " Ok  ";
00874           else if (status == dqm::qstatus::OTHER) test_status << " Other(" << status << ") ";
00875           string mess_str = (*it)->getMessage();
00876           test_status <<  "&lt;br/&gt;";
00877           mess_str = mess_str.substr(mess_str.find(" Test")+5);
00878           test_status <<  " QTest Name  : " << mess_str.substr(0, mess_str.find(")")+1) << endl;
00879           test_status << "&lt;br/&gt;";
00880           test_status <<  " QTest Detail  : " << mess_str.substr(mess_str.find(")")+2) << endl;
00881         } 
00882         test_status << " ======================================================== " << endl;
00883       }
00884       *out << "<HPath>" << name << "</HPath>" << endl;         
00885     }    
00886   }
00887   *out << "</PathList>" << endl;
00888   *out << "<StatusList>" << endl;
00889   *out << "<Status>" << test_status.str() << "</Status>" << endl;      
00890   *out << "</StatusList>" << endl;
00891   *out << "</StatusAndPath>" << endl;
00892 }
00893 
00894 //------------------------------------------------------------------------------
00898 void SiPixelInformationExtractor::computeStatus(MonitorElement      * theME,
00899                                                 double              & colorValue,
00900                                                 pair<double,double> & norm) 
00901 {
00902   double normalizationX = 1 ;
00903   double normalizationY = 1 ;
00904   double meanX          = 0 ;
00905   double meanY          = 0 ;
00906   
00907   colorValue = 0 ;
00908 
00909   pair<double,double> normX ;
00910   pair<double,double> normY ;
00911 
00912   string theMEType = getMEType(theME) ;
00913 
00914 //   cout << ACRed << ACReverse
00915 //        << "[SiPixelInformationExtractor::computeStatus()]"
00916 //        << ACPlain
00917 //        << " Computing average for "
00918 //        << theME->getName()
00919 //        << endl ;
00920 
00921   if( theMEType.find("TH1") != string::npos)
00922   {
00923    meanX = (double)theME->getMean();
00924    getNormalization(theME, normX, "TH1") ;
00925    normalizationX = fabs( normX.second - normX.first) ;
00926    if( normalizationX == 0 ) {normalizationX=1.E-20;}
00927    colorValue  = meanX / normalizationX ;
00928    norm.first  = normX.first ;
00929    norm.second = normX.second ;
00930   }
00931   
00932   if( theMEType.find("TH2") != string::npos)
00933   {
00934    meanX = (double)theME->getMean(1);
00935    meanY = (double)theME->getMean(2);
00936    getNormalization2D(theME, normX, normY, "TH2") ;
00937    normalizationX = fabs( normX.second - normX.first) ;
00938    normalizationY = fabs( normY.second - normY.first) ;
00939    if( normalizationX == 0 ) {normalizationX=1.E-20;}
00940    if( normalizationY == 0 ) {normalizationY=1.E-20;}
00941    double cVX = meanX / normalizationX ;
00942    double cVY = meanY / normalizationY ;
00943    colorValue = sqrt(cVX*cVX + cVY*cVY) ;
00944    if( normalizationX >= normalizationY )
00945    { 
00946     norm.first  = normX.first;
00947     norm.second = normX.second ;
00948    } else { 
00949     norm.first  = normY.first;
00950     norm.second = normY.second ;
00951    }
00952 //   cout << ACBlue << ACBold << ACReverse
00953 //        << "[SiPixelInformationExtractor::computeStatus()]"
00954 //      << ACPlain << "    "
00955 //      << theME->getName()
00956 //      << " meanX:Y "
00957 //      << meanX << ":" << meanY
00958 //      << " normX:Y " 
00959 //      << norm.first << ":" << norm.second
00960 //      << endl ;
00961   } 
00962  
00963   return ;
00964 }
00965 
00966 //------------------------------------------------------------------------------
00970 void SiPixelInformationExtractor::getNormalization(MonitorElement     * theME, 
00971                                                    pair<double,double>& norm,
00972                                                    std::string          theMEType) 
00973 {
00974   double normLow  = 0 ;
00975   double normHigh = 0 ;
00976 
00977   if( theMEType.find("TH1") != string::npos)
00978   {
00979    normHigh    = (double)theME->getNbinsX() ;
00980    norm.first  = normLow  ;
00981    norm.second = normHigh ;
00982   }
00983 }
00984 
00985 //------------------------------------------------------------------------------
00989 void SiPixelInformationExtractor::getNormalization2D(MonitorElement     * theME, 
00990                                                      pair<double,double>& normX,
00991                                                      pair<double,double>& normY,
00992                                                      std::string          theMEType) 
00993 {
00994   double normLow  = 0 ;
00995   double normHigh = 0 ;
00996 
00997   if( theMEType.find("TH2") != string::npos )
00998   {
00999    normHigh    = (double)theME->getNbinsX() ;
01000    normX.first  = normLow  ;
01001    normX.second = normHigh ;
01002    normHigh    = (double)theME->getNbinsY() ;
01003    normY.first  = normLow  ;
01004    normY.second = normHigh ;
01005 //   cout << ACCyan << ACBold << ACReverse
01006 //        << "[SiPixelInformationExtractor::getNormalization2D()]"
01007 //      << ACPlain << " "
01008 //      << theME->getName()
01009 //      << " normX: " 
01010 //      << normX.first << ":" << normX.second
01011 //      << " normY: " 
01012 //      << normY.first << ":" << normY.second
01013 //      << endl ;
01014   }
01015 }
01016 
01017 //------------------------------------------------------------------------------
01022 void SiPixelInformationExtractor::selectMEList(DQMStore   * bei,  
01023                                                string                  & theMEName,
01024                                                vector<MonitorElement*> & mes) 
01025 {  
01026 //  cout<<"In SiPixelInformationExtractor::selectMEList: "<<endl;
01027   string currDir = bei->pwd();
01028    
01029   string theME ;
01030    
01031   // Get ME from Collector/FU0/Tracker/PixelEndcap/HalfCylinder_pX/Disk_X/Blade_XX/Panel_XX/Module_XX
01032   if (currDir.find("Module_") != string::npos ||
01033       currDir.find("FED_") != string::npos)  
01034   {
01035     vector<string> contents = bei->getMEs(); 
01036        
01037     for (vector<string>::const_iterator it = contents.begin(); it != contents.end(); it++) 
01038     {
01039       theME = (*it) ;
01040       if(theME.find("siPixel")==string::npos && theME.find("ctfWithMaterialTracks")==string::npos) {continue ;} // If the ME is not a siPixel or ctfWithMaterialTrack one, skip
01041       string temp_s = theME.substr(0,theME.find_first_of("_"));
01042       //cout<<"should be the variable name: temp_s= "<<temp_s<<endl;
01043       if (temp_s == theMEName)  
01044       {
01045         string full_path = currDir + "/" + (*it);
01046 
01047         MonitorElement * me = bei->get(full_path.c_str());
01048         
01049         if (me) {mes.push_back(me);}
01050       }
01051     }
01052     return;
01053   } else {  // If not yet reached the desired level in the directory tree, recursively go down one level more
01054     vector<string> subdirs = bei->getSubdirs();
01055     for (vector<string>::const_iterator it = subdirs.begin(); it != subdirs.end(); it++) 
01056     {
01057       bei->cd(*it);
01058       selectMEList(bei, theMEName, mes);
01059       bei->goUp();
01060     }
01061   }
01062 }
01063 
01064 //------------------------------------------------------------------------------
01068 void SiPixelInformationExtractor::sendTkUpdatedStatus(DQMStore  * bei, 
01069                                                       xgi::Output            * out,
01070                                                       std::string            & theMEName,
01071                                                       std::string            & theTKType) 
01072 {
01073 //  cout<<"In SiPixelInformationExtractor::sendTkUpdatedStatus: "<<endl;
01074   int rval, gval, bval;
01075   vector<string>          colorMap ;
01076   vector<MonitorElement*> me_list;
01077   pair<double,double>     norm ;
01078   double sts ;
01079     
01080   bei->cd();
01081   selectMEList(bei, theMEName, me_list) ;
01082   bei->cd();
01083 
01084   string detId = "undefined";
01085 
01086 /*   cout << ACYellow << ACBold
01087         << "[SiPixelInformationExtractor::sendTkUpdatedStatus()] "
01088         << ACPlain
01089         << "Preparing color map update for " 
01090         << theMEName
01091         << " type "
01092         << theTKType
01093         << " - List size: "
01094         << me_list.size() 
01095         << endl ;
01096 */  
01097   int maxEntries = 0 ;
01098   if( theTKType == "Entries") // In this case find the ME with the highest number of entries
01099   {                           // first and use that as a vertical scale normalization
01100    for(vector<MonitorElement*>::iterator it=me_list.begin(); it!=me_list.end(); it++)
01101    {
01102     int entries = (int)(*it)->getEntries() ;
01103     if( entries > maxEntries ) maxEntries = entries ;
01104    }
01105   }
01106   
01107   int entries = 0 ;
01108   stringstream jsSnippet ;
01109   for(vector<MonitorElement*>::iterator it=me_list.begin(); it!=me_list.end(); it++)
01110   {
01111     string meName    = (*it)->getName();
01112     string theMEType = getMEType(*it);
01113     if( meName.find("_3") != string::npos ) 
01114     {
01115      string detIdString = meName.substr(meName.find_last_of("_")+1,9);
01116      std::istringstream isst;
01117      isst.str(detIdString);
01118      isst>>detId;
01119      entries = (int)(*it)->getEntries() ;
01120      if( theTKType == "Averages") 
01121      {
01122       computeStatus(*it, sts, norm) ;
01123       SiPixelUtility::getStatusColor(sts, rval, gval, bval);
01124      } else if( theTKType == "Entries") {
01125       sts = (double)entries / (double)maxEntries ;
01126       SiPixelUtility::getStatusColor(sts, rval, gval, bval);
01127       if( entries > maxEntries ) maxEntries = entries ;
01128       norm.first  = 0 ;
01129       norm.second = maxEntries ;
01130      } else {
01131       int status  =  SiPixelUtility::getStatus((*it));
01132       if(        status == dqm::qstatus::ERROR ) 
01133       {
01134        rval = 255; gval =   0; bval =   0;
01135       } else if (status == dqm::qstatus::WARNING )  {
01136        rval = 255; gval = 255; bval =   0; 
01137       } else if (status == dqm::qstatus::OTHER)     {
01138        rval =   0; gval =   0; bval = 255;
01139       } else if (status == dqm::qstatus::STATUS_OK) {
01140        rval =   0; gval = 255; bval =   0;
01141       } else {  
01142        rval = 255; gval = 255; bval = 255;
01143       }
01144      }
01145      jsSnippet.str("") ;
01146      jsSnippet << " <DetInfo DetId='"
01147                << detId
01148                << "' red='"
01149                << rval
01150                << "' green='"
01151                << gval
01152                << "' blue='"
01153                << bval
01154                << "' entries='"
01155                << entries
01156                << "'/>" ;
01157      colorMap.push_back(jsSnippet.str()) ;
01158 //      if( it == me_list.begin()) // The first should be equal to all others...
01159 //      {
01160 //       getNormalization((*it), norm, theMEType.latin1()) ;
01161 //      }
01162     }
01163   }
01164 
01165 //  delete random ;
01166   
01167 /*   cout << ACYellow << ACBold
01168         << "[SiPixelInformationExtractor::sendTkUpdatedStatus()] "
01169         << ACPlain
01170         << "Color map consists of "
01171         << colorMap.size()
01172         << " snippets: start shipping back"
01173         << endl ;
01174 */
01175   out->getHTTPResponseHeader().addHeader("Content-Type", "text/xml");
01176   *out << "<?xml version=\"1.0\" ?>" << endl;
01177   *out << "<TrackerMapUpdate>"       << endl;
01178 
01179   for(vector<string>::iterator it=colorMap.begin(); it!=colorMap.end(); it++)
01180   {
01181    *out << *it << endl;
01182   }
01183  
01184   *out << " <theLimits id=\"normalizationLimits\" normLow=\"" 
01185        << norm.first 
01186        << "\" normHigh=\""
01187        << norm.second 
01188        << "\" />"
01189        << endl;
01190   *out << "</TrackerMapUpdate>"              
01191        << endl;
01192 
01193 /*   cout << ACYellow << ACBold
01194         << "[SiPixelInformationExtractor::sendTkUpdatedStatus()] "
01195         << ACPlain
01196         << "Color map updated within range " 
01197         << norm.first
01198         << "-"
01199         << norm.second
01200         << endl ;
01201 */
01202 }
01203 
01204 //------------------------------------------------------------------------------
01209 int SiPixelInformationExtractor::getDetId(MonitorElement * mE) 
01210 {
01211 //cout<<"In SiPixelInformationExtractor::getDetId: for ME= "<<mE->getName()<<endl;
01212  string mEName = mE->getName();
01213 
01214  int detId = 0;
01215  
01216  if( mEName.find("_3") != string::npos )
01217  {
01218   string detIdString = mEName.substr((mEName.find_last_of("_"))+1,9);
01219   //cout<<"string: "<<detIdString<<endl;
01220   std::istringstream isst;
01221   isst.str(detIdString);
01222   isst>>detId;
01223 // } else {
01224 //  cout << ACYellow << ACBold
01225 //       << "[SiPixelInformationExtractor::getDetId()] "
01226 //       << ACPlain
01227 //       << "Could not extract detId from "
01228 //       << mEName
01229 //       << endl ;
01230  }
01231   //cout<<"returning with: "<<detId<<endl;
01232   return detId ;
01233   
01234 }
01235 
01236 //------------------------------------------------------------------------------
01240 void SiPixelInformationExtractor::getMEList(DQMStore    * bei,  
01241                                             map<string, int>         & mEHash)
01242 {
01243   string currDir = bei->pwd();
01244    
01245 //   cout << ACRed << ACBold
01246 //        << "[SiPixelInformationExtractor::getMEList()]"
01247 //        << ACPlain
01248 //        << " Requesting ME list in " 
01249 //        << currDir
01250 //        << endl ;
01251        
01252   string theME ;
01253    
01254   // Get ME from Collector/FU0/Tracker/PixelEndcap/HalfCylinder_pX/Disk_X/Blade_XX/Panel_XX/Module_XX
01255   if (currDir.find("Module_") != string::npos ||
01256       currDir.find("FED_") != string::npos)  
01257   {
01258     vector<string> contents = bei->getMEs(); 
01259        
01260     for (vector<string>::const_iterator it = contents.begin(); it != contents.end(); it++) 
01261     {
01262       theME = (*it) ;
01263 //       cout << ACRed << ACReverse
01264 //            << "[SiPixelInformationExtractor::getMEList()]"
01265 //            << ACPlain
01266 //            << " ME: " 
01267 //            << (*it)
01268 //            << endl ;
01269       if(theME.find("siPixel")==string::npos && theME.find("ctfWithMaterialTracks")==string::npos) 
01270       {
01271        cout << ACRed << ACBold
01272             << "[SiPixelInformationExtractor::getMEList()]"
01273             << ACPlain
01274             << " ----> Skipping " 
01275             << (*it)
01276             << endl ;
01277        continue ;
01278       } // If the ME is not a Pixel one, skip
01279       string full_path = currDir + "/" + (*it);
01280       string mEName = theME.substr(0,theME.find_first_of("_"));
01281       mEHash[mEName]++ ;
01282     }
01283     
01284     return;
01285   } else {  // If not yet reached the desired level in the directory tree, recursively go down one level more
01286     vector<string> subdirs = bei->getSubdirs();
01287     for (vector<string>::const_iterator it = subdirs.begin(); it != subdirs.end(); it++) 
01288     {
01289       bei->cd(*it);
01290       getMEList(bei, mEHash);
01291       bei->goUp();
01292     }
01293   }
01294 }
01295 
01296 //
01297 // -- Get All histograms from a Path
01298 //
01299 void SiPixelInformationExtractor::getHistosFromPath(DQMStore * bei, 
01300                                                     const std::multimap<std::string, std::string>& req_map, 
01301                                                     xgi::Output * out){
01302 //cout<<"Entering SiPixelInformationExtractor::getHistosFromPath: "<<endl;
01303   string path = getItemValue(req_map,"Path");
01304 //cout<<"Path is: "<<path<<endl;
01305   if (path.size() == 0) return;
01306 
01307   int width  = atoi(getItemValue(req_map, "width").c_str());
01308   int height = atoi(getItemValue(req_map, "height").c_str());
01309 
01310   string opt =" ";
01311 
01312   setHTMLHeader(out);
01313   vector<MonitorElement*> all_mes = bei->getContents(path);
01314   *out << path << " " ;
01315   for(vector<MonitorElement*>::iterator it=all_mes.begin(); it!=all_mes.end(); it++){
01316     MonitorElement* me = (*it);
01317     //cout<<"I'm in the loop now..."<<endl;
01318     if (!me) continue;
01319     string name = me->getName();
01320     string full_path = path + "/" + name;
01321 //cout<<"Calling HP::setNewPlot now for "<<full_path<<endl;
01322     histoPlotter_->setNewPlot(full_path, opt, width, height);
01323     *out << name << " ";
01324   }
01325 //  cout<<"... leaving SiPixelInformationExtractor::getHistosFromPath!"<<endl;
01326 }
01327 
01329 
01330 void SiPixelInformationExtractor::bookNoisyPixels(DQMStore * bei, float noiseRate_,bool Tier0Flag) {
01331 //std::cout<<"BOOK NOISY PIXEL MEs!"<<std::endl;
01332   bei->cd();
01333   if(noiseRate_>=0.){
01334     bei->setCurrentFolder("Pixel/Barrel");
01335     EventRateBarrelPixels = bei->book1D("barrelEventRate","Digi event rate for all Barrel pixels",1000,0.,0.01);
01336     EventRateBarrelPixels->setAxisTitle("Event Rate",1);
01337     EventRateBarrelPixels->setAxisTitle("Number of Pixels",2);
01338     bei->cd();  
01339     bei->setCurrentFolder("Pixel/Endcap");
01340     EventRateEndcapPixels = bei->book1D("endcapEventRate","Digi event rate for all Endcap pixels",1000,0.,0.01);
01341     EventRateEndcapPixels->setAxisTitle("Event Rate",1);
01342     EventRateEndcapPixels->setAxisTitle("Number of Pixels",2);
01343   }
01344 }
01345 
01346           
01348 
01349 void SiPixelInformationExtractor::findNoisyPixels(DQMStore * bei, bool init, float noiseRate_, int noiseRateDenominator_, edm::EventSetup const& eSetup)
01350 {
01351 //cout<<"Entering SiPixelInformationExtractor::findNoisyPixels with noiseRate set to "<<noiseRate_<<endl;
01352 
01353   
01354   if(init){
01355     endOfModules_=false;
01356     nevents_=noiseRateDenominator_;
01357     if(nevents_ == -1){
01358       bei->cd();
01359       bei->setCurrentFolder("Pixel/EventInfo");
01360       nevents_ = (bei->get("Pixel/EventInfo/processedEvents"))->getIntValue();
01361     }
01362     bei->cd();  
01363     myfile_.open ("NoisyPixelList.txt", ios::app);
01364     myfile_ << "Noise summary, ran over " << nevents_ << " events, threshold was set to " << noiseRate_ <<  std::endl;
01365   }
01366   string currDir = bei->pwd();
01367   string dname = currDir.substr(currDir.find_last_of("/")+1);
01368 
01369 
01370   if(dname.find("Module_")!=string::npos){
01371     vector<string> meVec = bei->getMEs();
01372     for (vector<string>::const_iterator it = meVec.begin(); it != meVec.end(); it++) {
01373       string full_path = currDir + "/" + (*it);
01374       if(full_path.find("hitmap_siPixelDigis")!=string::npos){
01375         //broken HV bond:
01376         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_01/Panel_2/Module_2")!=string::npos) continue;
01377         //?noisy?
01378         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_12/Panel_1/Module_4")!=string::npos) continue;
01379         //ROG with HV problem (short?):
01380         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_10/Panel_1/Module_3")!=string::npos) continue;
01381         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_10/Panel_1/Module_4")!=string::npos) continue;
01382         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_10/Panel_2/Module_2")!=string::npos) continue;
01383         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_10/Panel_2/Module_3")!=string::npos) continue;
01384         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_11/Panel_1/Module_3")!=string::npos) continue;
01385         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_11/Panel_1/Module_4")!=string::npos) continue;
01386         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_11/Panel_2/Module_2")!=string::npos) continue;
01387         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_11/Panel_2/Module_3")!=string::npos) continue;
01388         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_12/Panel_1/Module_3")!=string::npos) continue;
01389         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_12/Panel_1/Module_4")!=string::npos) continue;
01390         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_12/Panel_2/Module_2")!=string::npos) continue;
01391         //if(currDir.find("HalfCylinder_mI/Disk_1/Blade_12/Panel_2/Module_3")!=string::npos) continue;
01392         MonitorElement * me = bei->get(full_path);
01393         if (!me) continue;
01394         int detid=getDetId(me); int pixcol=-1; int pixrow=-1; 
01395 
01396         //cout<<"detid= "<<detid<<endl;
01397         std::vector<std::pair<std::pair<int, int>, float> > noisyPixelsInModule;
01398         TH2F * hothisto = me->getTH2F();
01399         if(hothisto){
01400           for(int i=1; i!=hothisto->GetNbinsX()+1; i++){
01401             for(int j=1; j!=hothisto->GetNbinsY()+1; j++){
01402               float value = (hothisto->GetBinContent(i,j))/float(nevents_);
01403               if(me->getPathname().find("Barrel")!=string::npos){
01404                 EventRateBarrelPixels = bei->get("Pixel/Barrel/barrelEventRate");
01405                 if(EventRateBarrelPixels) EventRateBarrelPixels->Fill(value);
01406               }else if(me->getPathname().find("Endcap")!=string::npos){
01407                 EventRateEndcapPixels = bei->get("Pixel/Endcap/endcapEventRate");
01408                 if(EventRateEndcapPixels) EventRateEndcapPixels->Fill(value);
01409               }
01410               if(value > noiseRate_){
01411                 pixcol = i-1;
01412                 pixrow = j-1;
01413                 //cout<<"pixcol= "<<pixcol<<" , pixrow= "<<pixrow<<" , value= "<<value<<endl;
01414  
01415                 std::pair<int, int> address(pixcol, pixrow);
01416                 std::pair<std::pair<int, int>, float>  PixelStats(address, value);
01417                 noisyPixelsInModule.push_back(PixelStats);
01418               }
01419             }
01420           }
01421         }
01422         noisyDetIds_[detid] = noisyPixelsInModule;
01423         //if(noisyPixelsInModule.size()>=20) cout<<"This module has 20 or more hot pixels: "<<detid<<","<<bei->pwd()<<","<<noisyPixelsInModule.size()<<endl;
01424       }
01425     }
01426   }
01427   vector<string> subDirVec = bei->getSubdirs();  
01428   for (vector<string>::const_iterator ic = subDirVec.begin();
01429        ic != subDirVec.end(); ic++) {
01430     if((*ic).find("AdditionalPixelErrors")!=string::npos) continue;
01431     bei->cd(*ic);
01432     init=false;
01433     findNoisyPixels(bei,init,noiseRate_,noiseRateDenominator_,eSetup);
01434     bei->goUp();
01435   }
01436 
01437   if(bei->pwd().find("EventInfo")!=string::npos) endOfModules_ = true;
01438   
01439   if(!endOfModules_) return;
01440   // myfile_ <<"am in "<<bei->pwd()<<" now!"<<endl;
01441   if(currDir == "Pixel/EventInfo/reportSummaryContents"){
01442     eSetup.get<SiPixelFedCablingMapRcd>().get(theCablingMap);
01443     std::vector<std::pair<sipixelobjects::DetectorIndex,double> > pixelvec;
01444     std::map<uint32_t,int> myfedmap;
01445     std::map<uint32_t,std::string> mynamemap;
01446     int realfedID = -1;
01447     //int Nnoisies = noisyDetIds_.size();
01448     //cout<<"Number of noisy modules: "<<Nnoisies<<endl;
01449     int counter = 0;
01450     int n_noisyrocs_all = 0;
01451     int n_noisyrocs_barrel = 0;
01452     int n_noisyrocs_endcap = 0;
01453     int n_verynoisyrocs_all = 0;
01454     int n_verynoisyrocs_barrel = 0;
01455     int n_verynoisyrocs_endcap = 0;
01456 
01457     for(int fid = 0; fid < 40; fid++){
01458     for(std::map<uint32_t, std::vector< std::pair<std::pair<int, int>, float> > >::const_iterator it = noisyDetIds_.begin(); 
01459         it != noisyDetIds_.end(); it++){
01460       uint32_t detid = (*it).first;
01461       std::vector< std::pair<std::pair<int, int>, float> > noisyPixels = (*it).second;
01462       //cout<<noisyPixels.size()<<" noisy pixels in a module: "<<detid<<endl;
01463       // now convert into online conventions:
01464       for(int fedid=0; fedid<=40; ++fedid){
01465         SiPixelFrameConverter converter(theCablingMap.product(),fedid);
01466         uint32_t newDetId = detid;
01467         if(converter.hasDetUnit(newDetId)){
01468           realfedID=fedid;
01469           break;   
01470         }
01471       }
01472       if(fid == realfedID){
01473       //cout<<"FED ID is = "<<realfedID<<endl;
01474       if(realfedID==-1) continue; 
01475       DetId detId(detid);
01476       uint32_t detSubId = detId.subdetId();
01477       std::string outputname;
01478       bool HalfModule = false;
01479       if (detSubId == 2){   //FPIX
01480         PixelEndcapName nameworker(detid);
01481         outputname = nameworker.name();
01482       } else if(detSubId == 1){   //BPIX
01483         PixelBarrelName nameworker(detid);
01484         outputname = nameworker.name();
01485         HalfModule = nameworker.isHalfModule();
01486 
01487       } else{
01488         continue;
01489       } 
01490       std::map<int,int> myrocmap;
01491       myfedmap[detid]=realfedID;
01492       mynamemap[detid]=outputname;
01493       
01494       for(std::vector< std::pair< std::pair<int,int>, float> >::const_iterator pxl = noisyPixels.begin(); 
01495           pxl != noisyPixels.end(); pxl++){
01496         std::pair<int,int> offlineaddress = (*pxl).first;
01497         float Noise_frac = (*pxl).second;
01498         int offlineColumn = offlineaddress.first;
01499         int offlineRow = offlineaddress.second;
01500         counter++;
01501         //cout<<"noisy pixel counter: "<<counter<<endl;
01502 
01503         sipixelobjects::ElectronicIndex cabling; 
01504         SiPixelFrameConverter formatter(theCablingMap.product(),realfedID);
01505         sipixelobjects::DetectorIndex detector = {detid, offlineRow, offlineColumn};      
01506         formatter.toCabling(cabling,detector);
01507         // cabling should now contain cabling.roc and cabling.dcol  and cabling.pxid
01508         // however, the coordinates now need to be converted from dcl,pxid to the row,col coordinates used in the calibration info 
01509         sipixelobjects::LocalPixel::DcolPxid loc;
01510         loc.dcol = cabling.dcol;
01511         loc.pxid = cabling.pxid;
01512         
01513         
01514         // OLD version, not 31X compatible:
01515 //        const sipixelobjects::PixelFEDCabling *theFed= theCablingMap.product()->fed(realfedID);
01516 //      const sipixelobjects::PixelFEDLink * link = theFed->link(cabling.link);
01517 //      const sipixelobjects::PixelROC *theRoc = link->roc(cabling.roc);
01518 //      sipixelobjects::LocalPixel locpixel(loc);
01519         
01520         
01521         // FIX to adhere to new cabling map. To be replaced with CalibTracker/SiPixelTools detid - > hardware id classes ASAP.
01522         //        const sipixelobjects::PixelFEDCabling *theFed= theCablingMap.product()->fed(realfedID);
01523         //        const sipixelobjects::PixelFEDLink * link = theFed->link(cabling.link);
01524         //        const sipixelobjects::PixelROC *theRoc = link->roc(cabling.roc);
01525         sipixelobjects::LocalPixel locpixel(loc);
01526         assert(realfedID >= 0);
01527         assert(cabling.link >= 0);
01528         assert(cabling.roc >= 0);
01529         sipixelobjects::CablingPathToDetUnit path = {static_cast<unsigned int>(realfedID), 
01530                                                      static_cast<unsigned int>(cabling.link),
01531                                                      static_cast<unsigned int>(cabling.roc)};  
01532         const sipixelobjects::PixelROC *theRoc = theCablingMap->findItem(path);
01533         // END of FIX
01534         
01535         int onlineColumn = locpixel.rocCol();
01536         int onlineRow= locpixel.rocRow();
01537         myrocmap[(theRoc->idInDetUnit())]++;
01538 
01539         // ROC numbers in the barrel go from 8 to 15 instead of 0 to 7 in half modules.  This is a 
01540         // fix to get the roc number, and add 8 to it if:
01541         // it's a Barrel module AND on the minus side AND a Half module
01542 
01543         int rocnumber = -1;
01544 
01545         if((detSubId == 1) && (outputname.find("mO")!=string::npos || outputname.find("mI")!=string::npos) && (HalfModule)){
01546           rocnumber = theRoc->idInDetUnit() + 8;
01547         }
01548         else{
01549           rocnumber = theRoc->idInDetUnit();
01550         }
01551 
01552         //cout<<counter<<" : \t detid= "<<detid<<" , OFF col,row= "<<offlineColumn<<","<<offlineRow<<" , ON roc,col,row= "<<theRoc->idInDetUnit()<<","<<onlineColumn<<","<<onlineRow<<endl;
01553         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;
01554       }
01555       for(std::map<int, int>::const_iterator nrc = myrocmap.begin(); nrc != myrocmap.end(); nrc++){
01556         if((*nrc).second > 0){
01557           n_noisyrocs_all++;
01558           if(detSubId == 2){
01559             n_noisyrocs_endcap++;
01560           } else if(detSubId == 1){
01561             n_noisyrocs_barrel++;}
01562         }
01563         if((*nrc).second > 40){
01564           n_verynoisyrocs_all++;
01565           if(detSubId == 2){
01566             n_verynoisyrocs_endcap++;
01567           } else if(detSubId == 1){
01568             n_verynoisyrocs_barrel++;}
01569         }
01570       }
01571       }
01572 
01573     }
01574     }
01575     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;
01576     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;
01577 
01578   }
01579   myfile_.close();
01580 //cout<<"...leaving SiPixelInformationExtractor::findNoisyPixels!"<<endl;
01581   return;
01582 }
01583 
01584 
01585 //
01586 // -- Create Images 
01587 //
01588 void SiPixelInformationExtractor::createImages(DQMStore* bei){
01589   histoPlotter_->createPlots(bei);
01590 }
01591 
01592 //
01593 // -- Set HTML Header in xgi output
01594 //
01595 void SiPixelInformationExtractor::setHTMLHeader(xgi::Output * out) {
01596   out->getHTTPResponseHeader().addHeader("Content-Type", "text/html");
01597   out->getHTTPResponseHeader().addHeader("Pragma", "no-cache");   
01598   out->getHTTPResponseHeader().addHeader("Cache-Control", "no-store, no-cache, must-revalidate,max-age=0");
01599   out->getHTTPResponseHeader().addHeader("Expires","Mon, 26 Jul 1997 05:00:00 GMT");
01600 }
01601 //
01602 // -- Set XML Header in xgi output
01603 //
01604 void SiPixelInformationExtractor::setXMLHeader(xgi::Output * out) {
01605   out->getHTTPResponseHeader().addHeader("Content-Type", "text/xml");
01606   out->getHTTPResponseHeader().addHeader("Pragma", "no-cache");   
01607   out->getHTTPResponseHeader().addHeader("Cache-Control", "no-store, no-cache, must-revalidate,max-age=0");
01608   out->getHTTPResponseHeader().addHeader("Expires","Mon, 26 Jul 1997 05:00:00 GMT");
01609   *out << "<?xml version=\"1.0\" ?>" << std::endl;
01610 
01611 }
01612 //
01613 // -- Set Plain Header in xgi output
01614 //
01615 void SiPixelInformationExtractor::setPlainHeader(xgi::Output * out) {
01616   out->getHTTPResponseHeader().addHeader("Content-Type", "text/plain");
01617   out->getHTTPResponseHeader().addHeader("Pragma", "no-cache");   
01618   out->getHTTPResponseHeader().addHeader("Cache-Control", "no-store, no-cache, must-revalidate,max-age=0");
01619   out->getHTTPResponseHeader().addHeader("Expires","Mon, 26 Jul 1997 05:00:00 GMT");
01620 
01621 }