CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/DQM/SiStripMonitorClient/src/SiStripInformationExtractor.cc

Go to the documentation of this file.
00001 #include "DQM/SiStripMonitorClient/interface/SiStripInformationExtractor.h"
00002 #include "DQMServices/Core/interface/DQMStore.h"
00003 #include "DQMServices/Core/interface/QTest.h"
00004 #include "DQMServices/Core/interface/QReport.h"
00005 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
00006 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00007 
00008 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
00009 #include "DQM/SiStripMonitorClient/interface/SiStripUtility.h"
00010 #include "DQM/SiStripMonitorClient/interface/SiStripLayoutParser.h"
00011 #include "DQM/SiStripMonitorClient/interface/SiStripConfigParser.h"
00012 #include "DQM/SiStripMonitorClient/interface/SiStripHistoPlotter.h"
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014 #include "FWCore/ParameterSet/interface/FileInPath.h"
00015 
00016 
00017 #include <iostream>
00018 
00019 //
00020 // -- Constructor
00021 // 
00022 SiStripInformationExtractor::SiStripInformationExtractor() {
00023   edm::LogInfo("SiStripInformationExtractor") << 
00024     " Creating SiStripInformationExtractor " << "\n" ;
00025   layoutParser_ = 0;
00026   layoutMap.clear();
00027   histoPlotter_=0;
00028   histoPlotter_ = new SiStripHistoPlotter();
00029   readConfiguration();
00030 }
00031 //
00032 // --  Destructor
00033 // 
00034 SiStripInformationExtractor::~SiStripInformationExtractor() {
00035   edm::LogInfo("SiStripInformationExtractor") << 
00036     " Deleting SiStripInformationExtractor " << "\n" ;
00037   if (layoutParser_) delete layoutParser_;
00038   if (histoPlotter_) delete histoPlotter_;
00039 
00040 }
00041 //
00042 // -- Read Configurationn File
00043 //
00044 void SiStripInformationExtractor::readConfiguration() {
00045   std::string localPath = std::string("DQM/SiStripMonitorClient/data/sistrip_plot_layout.xml");
00046   if (layoutParser_ == 0) {
00047     layoutParser_ = new SiStripLayoutParser();
00048     layoutParser_->getDocument(edm::FileInPath(localPath).fullPath());
00049   }
00050   if (layoutParser_->getAllLayouts(layoutMap)) {
00051      edm::LogInfo("SiStripInformationExtractor") << 
00052     " Layouts correctly readout " << "\n" ;
00053   } else  edm::LogInfo("SiStripInformationExtractor") << 
00054           " Problem in reading Layout " << "\n" ;
00055   if (layoutParser_) delete layoutParser_;
00056 
00057   subdetVec.push_back("SiStrip/MechanicalView/TIB");
00058   subdetVec.push_back("SiStrip/MechanicalView/TOB");
00059   subdetVec.push_back("SiStrip/MechanicalView/TID/side_2");
00060   subdetVec.push_back("SiStrip/MechanicalView/TID/side_1");
00061   subdetVec.push_back("SiStrip/MechanicalView/TEC/side_2");
00062   subdetVec.push_back("SiStrip/MechanicalView/TEC/side_1");
00063 
00064 }
00065 //
00066 // --  Fill Summary Histo List
00067 // 
00068 void SiStripInformationExtractor::printSummaryHistoList(DQMStore * dqm_store, std::ostringstream& str_val){
00069   static std::string indent_str = "";
00070 
00071   std::string currDir = dqm_store->pwd();
00072   std::string dname = currDir.substr(currDir.find_last_of("/")+1);
00073   if (dname.find("module_") ==0) return;
00074   //  str_val << "<li><a href=\"#\" id=\"" << currDir << "\">" << dname << "</a>" << std::endl;
00075   str_val << "<li><span class=\"folder\">" << dname << "</span>" << std::endl;
00076   std::vector<MonitorElement *> meVec = dqm_store->getContents(currDir);
00077   std::vector<std::string> subDirVec = dqm_store->getSubdirs();
00078   if ( meVec.size()== 0  && subDirVec.size() == 0 ) {
00079     str_val << "</li> "<< std::endl;    
00080     return;
00081   }
00082   str_val << "<ul>" << std::endl;      
00083   for (std::vector<MonitorElement *>::const_iterator it = meVec.begin();
00084          it != meVec.end(); it++) {
00085     MonitorElement* me = (*it);
00086     if (!me) continue;
00087     std::string name = (*it)->getName();
00088     str_val << "<li> <span class=\"file\"><a href=\"javascript:RequestHistos.DrawSummaryHistogram('" 
00089             << currDir
00090             << "')\">" << name << "</a></span></li>" << std::endl;
00091   }
00092 
00093   std::string mtag ="Modules: ";  
00094   for (std::vector<std::string>::const_iterator ic = subDirVec.begin();
00095        ic != subDirVec.end(); ic++) {
00096     dqm_store->cd(*ic);
00097     std::string titl = (*ic);
00098     if (titl.find("module_") == 0)  {
00099       titl = titl.substr(titl.find("module_")+7);
00100       mtag += titl + " ";
00101     }
00102     printSummaryHistoList(dqm_store, str_val);
00103     dqm_store->goUp();
00104   }
00105   if (mtag.size() > 10) {
00106     //    str_val << "<li class=\"note.gif\"><a href=\"#\">" << mtag << "</a></li>" << std::endl;
00107     str_val << "<li> <span class=\"file\"><a href=\"#\">" << mtag << "</a></span></li>" << std::endl;
00108   }
00109   str_val << "</ul> "<< std::endl;  
00110   str_val << "</li> "<< std::endl;  
00111 }
00112 //
00113 // --  Fill Alarm List
00114 // 
00115 void SiStripInformationExtractor::printAlarmList(DQMStore * dqm_store, std::ostringstream& str_val){
00116   static std::string indent_str = "";
00117 
00118   std::string currDir = dqm_store->pwd();
00119   std::string dname = currDir.substr(currDir.find_last_of("/")+1);
00120   std::string image_name;
00121   selectImage(image_name,dqm_store->getStatus(currDir));
00122   str_val << "<li><span class=\"folder\">" 
00123           << dname << "<img src=\""
00124           << image_name << "\"></span>" << std::endl;
00125   std::vector<std::string> subDirVec = dqm_store->getSubdirs();
00126   std::vector<MonitorElement *> meVec = dqm_store->getContents(currDir);
00127   
00128   if (subDirVec.size() == 0 && meVec.size() == 0) {
00129     str_val << "</li> "<< std::endl;    
00130     return;
00131   }
00132   str_val << "<ul>" << std::endl;
00133   if (dname.find("module_") != std::string::npos) {
00134     if (meVec.size() > 0) {
00135       for (std::vector<MonitorElement *>::const_iterator it = meVec.begin();
00136            it != meVec.end(); it++) {
00137         MonitorElement * me = (*it);
00138         if (!me) continue;
00139         std::vector<QReport*> q_reports = me->getQReports();
00140         if (q_reports.size() > 0) {
00141           std::string image_name1;
00142           selectImage(image_name1,q_reports);
00143           str_val << "<li><span class=\"file\"><a href=\"javascript:RequestHistos.ReadAlarmStatus('"
00144                   << currDir << "')\">"<<me->getName()
00145                   << "</a><img src=\""
00146                   << image_name1 << "\">" 
00147                   << "</span></li>" << std::endl;
00148         }
00149       }
00150     }
00151   }
00152   for (std::vector<std::string>::const_iterator ic = subDirVec.begin();
00153        ic != subDirVec.end(); ic++) {
00154     dqm_store->cd(*ic);
00155     printAlarmList(dqm_store, str_val);
00156     dqm_store->goUp();
00157   }
00158   str_val << "</ul> "<< std::endl;  
00159   str_val << "</li> "<< std::endl;  
00160 }
00161 //
00162 // -- Select Histograms for a given module
00163 //
00164 void SiStripInformationExtractor::getSingleModuleHistos(DQMStore * dqm_store, 
00165     const std::multimap<std::string, std::string>& req_map, xgi::Output * out){
00166 
00167   std::vector<std::string> hlist;
00168   getItemList(req_map,"histo", hlist);
00169 
00170   uint32_t detId = atoi(getItemValue(req_map,"ModId").c_str());
00171  
00172   int width  = atoi(getItemValue(req_map, "width").c_str());
00173   int height = atoi(getItemValue(req_map, "height").c_str());
00174 
00175   std::string opt =" ";
00176   
00177   SiStripFolderOrganizer folder_organizer;
00178   std::string path;
00179   folder_organizer.getFolderName(detId,path);   
00180 
00181   std::vector<MonitorElement*> all_mes = dqm_store->getContents(path);
00182   setXMLHeader(out);
00183   *out << "<HPathAndHNameList>" << std::endl;
00184   *out << "<HPath>" << path << "</HPath>" << std::endl;
00185 
00186   for (std::vector<std::string>::const_iterator ih = hlist.begin();
00187        ih != hlist.end(); ih++) {
00188     for (std::vector<MonitorElement *>::const_iterator it = all_mes.begin();
00189          it!= all_mes.end(); it++) {
00190       MonitorElement * me = (*it);
00191       if (!me) continue;
00192       std::string hname = me->getName();
00193       std::string name = hname.substr(0, hname.find("__det__"));
00194       if (name == (*ih)) {
00195         std::string full_path = path + "/" + hname;
00196         histoPlotter_->setNewPlot(full_path, opt, width, height);
00197         *out << "<HName>" << hname << "</HName>" << std::endl;
00198       }
00199     }
00200   }
00201   *out << "</HPathAndHNameList>" << std::endl;
00202 }
00203 //
00204 // -- Select Histograms from Global folder
00205 //
00206 void SiStripInformationExtractor::getGlobalHistos(DQMStore* dqm_store, const std::multimap<std::string, std::string>& req_map, xgi::Output * out) {
00207  
00208   std::vector<std::string> hlist;  
00209   getItemList(req_map,"histo", hlist);
00210 
00211   std::string path = getItemValue(req_map, "GlobalFolder");    
00212 
00213   int width  = atoi(getItemValue(req_map, "width").c_str());
00214   int height = atoi(getItemValue(req_map, "height").c_str());
00215 
00216   std::string opt =" ";
00217 
00218   std::vector<MonitorElement *> all_mes = dqm_store->getContents(path);
00219 
00220   setXMLHeader(out);
00221   *out << "<HPathAndHNameList>" << std::endl;
00222   *out << "<HPath>" << path << "</HPath>" << std::endl;
00223 
00224   for (std::vector<std::string>::const_iterator ih = hlist.begin();
00225        ih != hlist.end(); ih++) {      
00226     for (std::vector<MonitorElement *>::const_iterator it = all_mes.begin();
00227          it!= all_mes.end(); it++) {
00228       MonitorElement * me = (*it);
00229       if (!me) continue;
00230       std::string hname = me->getName();
00231       std::string name = hname.substr(0, hname.find("__det__"));
00232       if (name == (*ih)) {
00233         std::string full_path = path + "/" + hname;
00234         histoPlotter_->setNewPlot(full_path, opt, width, height);
00235         *out << "<HName>" << name << "</HName>" << std::endl;
00236       }
00237     }
00238   }
00239   *out << "</HPathAndHNameList>" << std::endl;
00240 }
00241 //
00242 // -- Get All histograms from a Path
00243 //
00244 void SiStripInformationExtractor::getHistosFromPath(DQMStore * dqm_store, const std::multimap<std::string, std::string>& req_map, xgi::Output * out){
00245 
00246   std::string path = getItemValue(req_map,"Path");
00247 
00248   if (path.size() == 0) return;
00249 
00250   int width  = atoi(getItemValue(req_map, "width").c_str());
00251   int height = atoi(getItemValue(req_map, "height").c_str());
00252 
00253   std::string opt =" ";
00254 
00255   setXMLHeader(out);
00256   *out << "<HPathAndHNameList>" << std::endl;
00257   *out << "<HPath>" << path << "</HPath>" << std::endl;
00258 
00259   std::vector<MonitorElement*> all_mes = dqm_store->getContents(path);
00260   for(std::vector<MonitorElement*>::iterator it=all_mes.begin(); it!=all_mes.end(); it++){
00261     MonitorElement* me = (*it);
00262     if (!me) continue;
00263     std::string name = me->getName();
00264     std::string full_path = path + "/" + name;
00265     histoPlotter_->setNewPlot(full_path, opt, width, height);
00266     *out << "<HName>" << name << "</HName>" << std::endl;
00267   }
00268   *out << "</HPathAndHNameList>" << std::endl;
00269 }
00270 //
00271 // plot Histograms from Layout
00272 //
00273 void SiStripInformationExtractor::plotHistosFromLayout(DQMStore * dqm_store){
00274   if (layoutMap.size() == 0) return;
00275 
00276   ofstream image_file;
00277   
00278   for (std::map<std::string, std::vector< std::string > >::iterator it = layoutMap.begin() ; it != layoutMap.end(); it++) {
00279     unsigned int ival = 0;
00280     std::string image_list = "images/" + it->first +".lis";
00281     image_file.open(image_list.c_str(), std::ios::out);
00282     if (!image_file) return;
00283 
00284     image_file << "[";
00285     for (std::vector<std::string>::iterator im = it->second.begin(); 
00286          im != it->second.end(); im++) {  
00287       std::string path_name = (*im);
00288       if (path_name.size() == 0) continue;
00289       MonitorElement* me = dqm_store->get(path_name);
00290       ival++;
00291       std::ostringstream  fname, ftitle;
00292       if (!me) {
00293         fname << "images/EmptyPlot.png";
00294         ftitle << "EmptyPlot";                 
00295       } else {
00296         fname << "images/" << it->first << "_" <<ival << ".png";
00297         ftitle << me->getName();
00298         histoPlotter_->createStaticPlot(me, fname.str());
00299       }
00300       image_file << "["<< "\"" << fname.str() << "\",\"" << path_name << "\"]";
00301       if (ival != it->second.size()) image_file << ","<< std::endl;
00302     }
00303     image_file << "]" << std::endl;
00304     image_file.close();
00305   }
00306 }
00307 //
00308 // -- Plot Tracker Map MEs
00309 //
00310 void SiStripInformationExtractor::getTrackerMapHistos(DQMStore* dqm_store, const std::multimap<std::string, std::string>& req_map, xgi::Output * out) {
00311 
00312   uint32_t detId = atoi(getItemValue(req_map,"ModId").c_str());
00313  
00314   int width  = atoi(getItemValue(req_map, "width").c_str());
00315   int height = atoi(getItemValue(req_map, "height").c_str());
00316 
00317   std::string opt =" ";
00318   
00319   SiStripFolderOrganizer folder_organizer;
00320   std::string path;
00321   folder_organizer.getFolderName(detId,path);   
00322 
00323   std::vector<MonitorElement*> all_mes = dqm_store->getContents(path);
00324   setXMLHeader(out);
00325   *out << "<HPathAndHNameList>" << std::endl;
00326   *out << "<HPath>" << path << "</HPath>" << std::endl;
00327   for (std::vector<MonitorElement *>::const_iterator it = all_mes.begin();
00328        it!= all_mes.end(); it++) {
00329     MonitorElement * me = (*it);
00330     if (!me) continue;
00331     std::string hname = me->getName(); 
00332     std::string full_path;
00333     full_path = path + "/" + hname;
00334     histoPlotter_->setNewPlot(full_path, opt, width, height);
00335     *out << "<HName>" << hname << "</HName>" << std::endl;
00336   }
00337   *out << "</HPathAndHNameList>" << std::endl;   
00338 
00339 }
00340 //
00341 // -- Select Histograms for a given module
00342 //
00343 void SiStripInformationExtractor::getCondDBHistos(DQMStore * dqm_store, bool& plot_flag, const std::multimap<std::string, std::string>& req_map,xgi::Output * out){
00344 
00345   plot_flag = true;
00346   std::string sname = getItemValue(req_map,"StructureName");
00347   int width  = atoi(getItemValue(req_map, "width").c_str());
00348   int height = atoi(getItemValue(req_map, "height").c_str());
00349 
00350   std::string path = "";
00351   uint32_t detId;
00352   if (hasItem(req_map,std::string("ModId"))) {
00353     detId = atoi(getItemValue(req_map,"ModId").c_str());
00354     if (detId != 0) {
00355       SiStripFolderOrganizer folder_organizer;
00356       folder_organizer.getFolderName(detId,path);
00357     }
00358   } else {
00359     if (sname.size() > 0) path = "SiStrip/" + sname;
00360   }
00361   if (path.size() == 0) path = "dummy_path";
00362 
00363   setXMLHeader(out);
00364   *out << "<HPathAndHNameList>" << std::endl;
00365   *out << "<HPath>" << path << "</HPath>" << std::endl;
00366   
00367   if (path == "dummy_path") {
00368     *out << "<HName>" << "Dummy" << "</HName>" << std::endl;
00369     plot_flag = false;
00370   } else {
00371     std::string opt = getItemValue(req_map,"option");
00372     std::vector<std::string> htypes;
00373     SiStripUtility::split(opt, htypes, ",");
00374     // Check if CondDB histograms already exists
00375     std::vector<MonitorElement*> all_mes = dqm_store->getContents(path);
00376     for (std::vector<std::string>::const_iterator ih = htypes.begin();
00377          ih!= htypes.end(); ih++) {
00378       std::string type = (*ih);
00379       if (type.size() == 0) continue;
00380       for (std::vector<MonitorElement *>::const_iterator it = all_mes.begin();
00381            it!= all_mes.end(); it++) {
00382         MonitorElement * me = (*it);
00383         if (!me) continue;
00384         std::string hname = me->getName();
00385         if (hname.find(type) != std::string::npos) {
00386           plot_flag = false;
00387           break;
00388         } 
00389       }  
00390       if (plot_flag == false) break;
00391     } 
00392     histoPlotter_->setNewCondDBPlot(path, opt, width, height);
00393     for (std::vector<std::string>::const_iterator ih = htypes.begin();
00394          ih != htypes.end(); ih++) {
00395       if ((*ih).size() > 0) {
00396         *out << "<HName>" << (*ih)  << "</HName>" << std::endl;
00397       }
00398     }
00399   }
00400   *out << "</HPathAndHNameList>" << std::endl;
00401 }
00402 //
00403 // -- Get a tagged image 
00404 //
00405 void SiStripInformationExtractor::getImage(const std::multimap<std::string, std::string>& req_map, xgi::Output * out){
00406   
00407   std::string path = getItemValue(req_map,"Path");
00408   std::string image;
00409   histoPlotter_->getNamedImageBuffer(path, image);
00410   out->getHTTPResponseHeader().addHeader("Content-Type", "image/png");
00411   out->getHTTPResponseHeader().addHeader("Pragma", "no-cache");   
00412   out->getHTTPResponseHeader().addHeader("Cache-Control", "no-store, no-cache, must-revalidate,max-age=0");
00413   out->getHTTPResponseHeader().addHeader("Expires","Mon, 26 Jul 1997 05:00:00 GMT");
00414   *out << image;
00415 
00416 }
00417 //
00418 // -- Read Layout Group names
00419 //
00420 void SiStripInformationExtractor::readLayoutNames(DQMStore* dqm_store, xgi::Output * out){
00421   setXMLHeader(out);
00422   *out << "<LayoutAndTKMapList>" << std::endl;
00423   if (layoutMap.size() > 0) {
00424     *out << "<LayoutList>" << std::endl;
00425     for (std::map<std::string, std::vector< std::string > >::iterator it = layoutMap.begin();
00426         it != layoutMap.end(); it++) {
00427      *out << "<LName>" << it->first << "</LName>" << std::endl;  
00428    }
00429    *out << "</LayoutList>" << std::endl;
00430   }
00431   dqm_store->cd();
00432   *out << "<TKMapOptionList>" << std::endl;
00433   *out << "<TkMapOption>" << "QTestAlarm" << "</TkMapOption>" << std::endl;
00434 
00435   for (std::vector<std::string>::const_iterator isubdet = subdetVec.begin(); isubdet != subdetVec.end(); isubdet++) {
00436     std::string dname = (*isubdet);
00437     if (!dqm_store->dirExists(dname)) continue;
00438     dqm_store->cd(dname);
00439     std::vector<std::string> subDirVec = dqm_store->getSubdirs();
00440     if (subDirVec.size() == 0) continue;
00441     for (std::vector<std::string>::const_iterator ilayer = subDirVec.begin(); ilayer != subDirVec.end(); ilayer++) {
00442       std::string lname = (*ilayer);
00443       if (lname.find("BadModuleList") != std::string::npos) continue; 
00444       dqm_store->cd(lname);
00445       break;
00446     }
00447     std::vector<std::string> meVec = dqm_store->getMEs();
00448     for (std::vector<std::string>::const_iterator it = meVec.begin();
00449          it != meVec.end(); it++) {
00450       std::string hname = (*it); 
00451       if (hname.find("TkHMap_") != std::string::npos) {
00452         std::string name = hname.substr(hname.find("TkHMap_")+7);
00453         name = name.substr(0,name.find_first_of("_")); 
00454         *out << "<TkMapOption>" << name << "</TkMapOption>" << std::endl;
00455       }
00456     }
00457     break;
00458   }
00459   *out << "</TKMapOptionList>" << std::endl;      
00460   *out << "</LayoutAndTKMapList>" << std::endl;
00461    dqm_store->cd();
00462 }
00463 //
00464 // read the Module And HistoList
00465 //
00466 void SiStripInformationExtractor::readModuleAndHistoList(DQMStore* dqm_store, std::string& sname, const edm::ESHandle<SiStripDetCabling>& detcabling,xgi::Output * out) {
00467 
00468   std::string dname = "SiStrip/" + sname;
00469   if (!dqm_store->dirExists(dname)) return;
00470 
00471   dqm_store->cd(dname);
00472   std::vector<std::string> mids; 
00473   SiStripUtility::getModuleFolderList(dqm_store, mids);
00474   dqm_store->cd();
00475 
00476   setXMLHeader(out);
00477   *out << "<ModuleAndHistoList>" << std::endl;
00478   
00479   // Fill Module List
00480   *out << "<ModuleList>" << std::endl;
00481   uint32_t aDetId  = 0;
00482   for (std::vector<std::string>::const_iterator it=mids.begin(); it != mids.end(); it++){    
00483     std::string moduleId = (*it);
00484     moduleId = moduleId.substr(moduleId.find("module_")+7); 
00485     *out << "<ModuleNum>" << moduleId << "</ModuleNum>" << std::endl;     
00486     if (aDetId == 0) aDetId = atoi(moduleId.c_str());
00487   }
00488   
00489   *out << "</ModuleList>" << std::endl;
00490   // Fill Histo list
00491   *out << "<HistoList>" << std::endl;
00492   
00493   std::vector<MonitorElement*> detector_mes = dqm_store->getContents(mids[0]);
00494   for (std::vector<MonitorElement *>::const_iterator it = detector_mes.begin();
00495          it!= detector_mes.end(); it++) {
00496     MonitorElement * me = (*it);     
00497     if (!me) continue;
00498     std::string hname_full = me->getName();
00499     std::string hname = hname_full.substr(0, hname_full.find("__det__"));
00500     *out << "<Histo>" << hname << "</Histo>" << std::endl;     
00501   }
00502   *out << "</HistoList>" << std::endl;
00503   *out << "</ModuleAndHistoList>" << std::endl;
00504 }
00505 //
00506 // Global Histogram List
00507 //
00508 void SiStripInformationExtractor::readGlobalHistoList(DQMStore* dqm_store, std::string& str_name,xgi::Output * out) {
00509    std::vector<std::string> hnames;
00510    std::string dname = str_name;
00511   
00512    setXMLHeader(out);
00513    *out << "<GlobalHistoList>" << std::endl;
00514    if (dqm_store->dirExists(dname)) {
00515      std::vector<MonitorElement*> meVec = dqm_store->getContents(dname);
00516      for (std::vector<MonitorElement *>::const_iterator it = meVec.begin();
00517           it != meVec.end(); it++) {
00518        MonitorElement* me = (*it);
00519        if (!me) continue;
00520        *out << "<GHisto>" << (*it)->getName() << "</GHisto>" << std::endl;           
00521      }
00522    } else {   
00523      *out << "<GHisto>" << " Desired directory : " << "</GHisto>" << std::endl;
00524      *out << "<GHisto>" <<       dname             << "</GHisto>" << std::endl;
00525      *out << "<GHisto>" << " does not exist!!!!  " << "</GHisto>" << std::endl;      
00526    }
00527    *out << "</GlobalHistoList>" << std::endl;
00528 }
00529 //
00530 // read the Structure And SummaryHistogram List
00531 //
00532 void SiStripInformationExtractor::readSummaryHistoTree(DQMStore* dqm_store, std::string& str_name, xgi::Output * out) {
00533   std::ostringstream sumtree;
00534   std::string dname = "SiStrip/" + str_name;
00535   if (dqm_store->dirExists(dname)) {    
00536     dqm_store->cd(dname);
00537     sumtree << "<ul id=\"summary_histo_tree\" class=\"filetree\">" << std::endl;
00538     printSummaryHistoList(dqm_store,sumtree);
00539     sumtree <<"</ul>" << std::endl;   
00540   } else {
00541     sumtree << " Desired Directory :  " << std::endl;
00542     sumtree <<       dname              << std::endl;
00543     sumtree <<  " does not exist !!!! " << std::endl;
00544   }
00545   setPlainHeader(out);
00546   *out << sumtree.str();
00547   dqm_store->cd();
00548 }
00549 //
00550 // read the Structure And Alarm Tree
00551 //
00552 void SiStripInformationExtractor::readAlarmTree(DQMStore* dqm_store, 
00553                   std::string& str_name, xgi::Output * out){
00554   std::ostringstream alarmtree;
00555   std::string dname = "SiStrip/" + str_name;
00556   if (dqm_store->dirExists(dname)) {    
00557     dqm_store->cd(dname);
00558     alarmtree << "<ul id=\"alarm_tree\" class=\"filetree\">" << std::endl;
00559     printAlarmList(dqm_store,alarmtree);
00560     alarmtree <<"</ul>" << std::endl; 
00561   } else {
00562     alarmtree << "Desired Directory :   " << std::endl;
00563     alarmtree <<       dname              << std::endl;
00564     alarmtree <<  " does not exist !!!! " << std::endl;
00565   }
00566   setPlainHeader(out);
00567   *out << alarmtree.str();
00568   dqm_store->cd();
00569 }
00570 //
00571 // Get elements from multi map
00572 //
00573 void SiStripInformationExtractor::getItemList(const std::multimap<std::string, std::string>& req_map, std::string item_name,std::vector<std::string>& items) {
00574   items.clear();
00575   for (std::multimap<std::string, std::string>::const_iterator it = req_map.begin();
00576        it != req_map.end(); it++) {
00577     
00578     if (it->first == item_name) {
00579       items.push_back(it->second);
00580     }
00581   }
00582 }
00583 //
00584 //  check a specific item in the map
00585 //
00586 bool SiStripInformationExtractor::hasItem(const std::multimap<std::string,std::string>& req_map,
00587                                           std::string item_name){
00588   std::multimap<std::string,std::string>::const_iterator pos = req_map.find(item_name);
00589   if (pos != req_map.end()) return true;
00590   return false;  
00591 }
00592 //
00593 // check the value of an item in the map
00594 //  
00595 std::string SiStripInformationExtractor::getItemValue(const std::multimap<std::string,std::string>& req_map,
00596                                                  std::string item_name){
00597   std::multimap<std::string,std::string>::const_iterator pos = req_map.find(item_name);
00598   std::string value = " ";
00599   if (pos != req_map.end()) {
00600     value = pos->second;
00601   }
00602   return value;
00603 }
00604 //
00605 // -- Get color  name from status
00606 //
00607 void SiStripInformationExtractor::selectColor(std::string& col, int status){
00608   if (status == dqm::qstatus::STATUS_OK)    col = "#00ff00";
00609   else if (status == dqm::qstatus::WARNING) col = "#ffff00";
00610   else if (status == dqm::qstatus::ERROR)   col = "#ff0000";
00611   else if (status == dqm::qstatus::OTHER)   col = "#ffa500";
00612   else  col = "#0000ff";
00613 }
00614 //
00615 // -- Get Image name from ME
00616 //
00617 void SiStripInformationExtractor::selectColor(std::string& col, std::vector<QReport*>& reports){
00618   int istat = 999;
00619   int status = 0;
00620   for (std::vector<QReport*>::const_iterator it = reports.begin(); it != reports.end();
00621        it++) {
00622     status = (*it)->getStatus();
00623     if (status > istat) istat = status;
00624   }
00625   selectColor(col, status);
00626 }
00627 //
00628 // -- Get Image name from status
00629 //
00630 void SiStripInformationExtractor::selectImage(std::string& name, int status){
00631   if (status == dqm::qstatus::STATUS_OK) name="images/LI_green.gif";
00632   else if (status == dqm::qstatus::WARNING) name="images/LI_yellow.gif";
00633   else if (status == dqm::qstatus::ERROR) name="images/LI_red.gif";
00634   else if (status == dqm::qstatus::OTHER) name="images/LI_orange.gif";
00635   else  name="images/LI_blue.gif";
00636 }
00637 //
00638 // -- Get Image name from ME
00639 //
00640 void SiStripInformationExtractor::selectImage(std::string& name, std::vector<QReport*>& reports){
00641   int istat = 999;
00642   int status = 0;
00643   for (std::vector<QReport*>::const_iterator it = reports.begin(); it != reports.end();
00644        it++) {
00645     status = (*it)->getStatus();
00646     if (status > istat) istat = status;
00647   }
00648   selectImage(name, status);
00649 }
00650 //
00651 // -- Get Warning/Error Messages
00652 //
00653 void SiStripInformationExtractor::readStatusMessage(DQMStore* dqm_store, std::multimap<std::string, std::string>& req_map, xgi::Output * out){
00654 
00655   std::string path = getItemValue(req_map,"Path");
00656 
00657   int width  = atoi(getItemValue(req_map, "width").c_str());
00658   int height = atoi(getItemValue(req_map, "height").c_str());
00659 
00660   std::string opt =" ";
00661 
00662   std::ostringstream test_status;
00663   
00664   setXMLHeader(out);
00665   *out << "<StatusAndPath>" << std::endl;
00666   *out << "<PathList>" << std::endl;
00667   if (path.size() == 0) {
00668     *out << "<HPath>" << "NONE" << "</HPath>" << std::endl;     
00669     test_status << " ME Does not exist ! " << std::endl;
00670   } else {
00671     std::vector<MonitorElement*> all_mes = dqm_store->getContents(path);
00672     *out << "<HPath>" << path << "</HPath>" << std::endl;     
00673     for(std::vector<MonitorElement*>::iterator it=all_mes.begin(); it!=all_mes.end(); it++){
00674       MonitorElement* me = (*it);
00675       if (!me) continue;
00676       std::string name = me->getName();  
00677 
00678       std::vector<QReport*> q_reports = me->getQReports();
00679       if (q_reports.size() == 0 && name.find("StripQualityFromCondDB") == std::string::npos) continue;
00680       std::string full_path = path + "/" + name;
00681       histoPlotter_->setNewPlot(full_path, opt, width, height);
00682 
00683       if (q_reports.size() != 0) {
00684         test_status << " QTest Status for " << name << " : " << std::endl;
00685         test_status << " ======================================================== " << std::endl; 
00686         for (std::vector<QReport*>::const_iterator it = q_reports.begin(); it != q_reports.end();
00687              it++) {
00688           int status = (*it)->getStatus();
00689           if (status == dqm::qstatus::WARNING) test_status << " Warning ";
00690           else if (status == dqm::qstatus::ERROR) test_status << " Error  ";
00691           else if (status == dqm::qstatus::STATUS_OK) test_status << " Ok  ";
00692           else if (status == dqm::qstatus::OTHER) test_status << " Other(" << status << ") ";
00693           std::string mess_str = (*it)->getMessage();
00694           test_status <<  " &lt;br/&gt;";
00695           mess_str = mess_str.substr(mess_str.find(" Test")+5);
00696           test_status <<  " QTest Name  : " << mess_str.substr(0, mess_str.find(")")+1) << std::endl;
00697           test_status << " &lt;br/&gt;";
00698           test_status <<  " QTest Detail  : " << mess_str.substr(mess_str.find(")")+2) << std::endl;
00699         } 
00700         test_status << " ======================================================== " << std::endl;
00701       }
00702       *out << "<HName>" << name << "</HName>" << std::endl;         
00703     }    
00704   }
00705   *out << "</PathList>" << std::endl;
00706   *out << "<StatusList>" << std::endl;
00707   *out << "<Status>" << test_status.str() << "</Status>" << std::endl;      
00708   *out << "</StatusList>" << std::endl;
00709   *out << "</StatusAndPath>" << std::endl;
00710 }
00711 //
00712 // -- Read the text Summary of QTest result
00713 //
00714 void SiStripInformationExtractor::readQTestSummary(DQMStore* dqm_store, std::string type, xgi::Output * out) {
00715 
00716   int nDetsWithError = 0;
00717   int nDetsTotal = 0;
00718   std::ostringstream qtest_summary, lite_summary;
00719   
00720   dqm_store->cd();
00721   SiStripFolderOrganizer folder_organizer;
00722   for (std::vector<std::string>::const_iterator isubdet = subdetVec.begin(); isubdet != subdetVec.end(); isubdet++) {
00723     std::string dname = (*isubdet);
00724     std::string bad_module_folder = dname + "/" + "BadModuleList";
00725     if (!dqm_store->dirExists(dname)) continue;
00726 
00727     dqm_store->cd(dname);
00728     std::vector<std::string> mids;
00729     SiStripUtility::getModuleFolderList(dqm_store, mids);
00730   
00731     int ndet    = mids.size();
00732     int errdet = 0;
00733     dqm_store->cd();
00734     dqm_store->cd(dname);
00735 
00736     qtest_summary << dname.substr(dname.find("View/")+5) << " : <br/>";
00737     qtest_summary << "=============================="<< "<br/>";
00738     if (dqm_store->dirExists(bad_module_folder)) {
00739 
00740       std::vector<MonitorElement *> meVec = dqm_store->getContents(bad_module_folder);
00741       for (std::vector<MonitorElement *>::const_iterator it = meVec.begin();
00742            it != meVec.end(); it++) {
00743         errdet++;
00744         int flag = (*it)->getIntValue();
00745         std::string message;
00746         SiStripUtility::getBadModuleStatus(flag, message);
00747         qtest_summary << " Module Id " << (*it)->getName() << " has "<< message << "<br/>";
00748       }
00749     }
00750     qtest_summary << "--------------------------------------------------------------------"<< "<br/>";
00751     qtest_summary << " Detectors :  Total "<< ndet
00752                   << " with Error " << errdet << "<br/>";
00753     qtest_summary << "--------------------------------------------------------------------"<< "<br/>";
00754     nDetsWithError += errdet;
00755     nDetsTotal     += ndet;
00756   }
00757   qtest_summary << "--------------------------------------------------------------------"<< "<br/>";
00758   qtest_summary << "--------------------------------------------------------------------"<< "<br/>";
00759   qtest_summary << " Total Detectors " << nDetsTotal;
00760   qtest_summary << " # of Detectors with Error " << nDetsWithError << "<br/>";
00761   qtest_summary << "--------------------------------------------------------------------"<< "<br/>";
00762   qtest_summary << "--------------------------------------------------------------------"<< "<br/>";
00763 
00764   lite_summary << " Total Detectors " << nDetsTotal << "<br/>";
00765   lite_summary << " # of Detectors with Error " << nDetsWithError << "<br/>";
00766 
00767   setHTMLHeader(out);
00768   if (type == "Lite") *out << lite_summary.str();
00769   else {
00770     *out << qtest_summary.str();
00771   }
00772   dqm_store->cd();
00773 }
00774 //
00775 // -- Create Images 
00776 //
00777 void SiStripInformationExtractor::createImages(DQMStore* dqm_store){
00778   if (histoPlotter_->plotsToMake())       histoPlotter_->createPlots(dqm_store);
00779   if (histoPlotter_->condDBPlotsToMake()) histoPlotter_->createCondDBPlots(dqm_store);
00780 }
00781 //
00782 // -- Set HTML Header in xgi output
00783 //
00784 void SiStripInformationExtractor::setHTMLHeader(xgi::Output * out) {
00785   out->getHTTPResponseHeader().addHeader("Content-Type", "text/html");
00786   out->getHTTPResponseHeader().addHeader("Pragma", "no-cache");   
00787   out->getHTTPResponseHeader().addHeader("Cache-Control", "no-store, no-cache, must-revalidate,max-age=0");
00788   out->getHTTPResponseHeader().addHeader("Expires","Mon, 26 Jul 1997 05:00:00 GMT");
00789 }
00790 //
00791 // -- Set XML Header in xgi output
00792 //
00793 void SiStripInformationExtractor::setXMLHeader(xgi::Output * out) {
00794   out->getHTTPResponseHeader().addHeader("Content-Type", "text/xml");
00795   out->getHTTPResponseHeader().addHeader("Pragma", "no-cache");   
00796   out->getHTTPResponseHeader().addHeader("Cache-Control", "no-store, no-cache, must-revalidate,max-age=0");
00797   out->getHTTPResponseHeader().addHeader("Expires","Mon, 26 Jul 1997 05:00:00 GMT");
00798   *out << "<?xml version=\"1.0\" ?>" << std::endl;
00799 
00800 }
00801 //
00802 // -- Set Plain Header in xgi output
00803 //
00804 void SiStripInformationExtractor::setPlainHeader(xgi::Output * out) {
00805   out->getHTTPResponseHeader().addHeader("Content-Type", "text/plain");
00806   out->getHTTPResponseHeader().addHeader("Pragma", "no-cache");   
00807   out->getHTTPResponseHeader().addHeader("Cache-Control", "no-store, no-cache, must-revalidate,max-age=0");
00808   out->getHTTPResponseHeader().addHeader("Expires","Mon, 26 Jul 1997 05:00:00 GMT");
00809 
00810 }
00811 //
00812 // read the Structure And Readout/Control Histogram List
00813 //
00814 void SiStripInformationExtractor::readNonGeomHistoTree(DQMStore* dqm_store, std::string& fld_name, xgi::Output * out) {
00815   std::ostringstream sumtree;
00816   std::string dname = "SiStrip/" + fld_name;
00817   if (dqm_store->dirExists(dname)) {    
00818     dqm_store->cd(dname);
00819     sumtree << "<ul id=\"non_geo_tree\" class=\"filetree\">" << std::endl;
00820     printNonGeomHistoList(dqm_store,sumtree);
00821     sumtree <<"</ul>" << std::endl;   
00822   } else {
00823     sumtree << " Desired Directory :  " << std::endl;
00824     sumtree <<       dname              << std::endl;
00825     sumtree <<  " does not exist !!!! " << std::endl;
00826   }
00827   setPlainHeader(out);
00828   *out << sumtree.str();
00829   dqm_store->cd();
00830 }
00831 //
00832 // --  Fill Readout/Control Histo List
00833 // 
00834 void SiStripInformationExtractor::printNonGeomHistoList(DQMStore * dqm_store, std::ostringstream& str_val){
00835   static std::string indent_str = "";
00836 
00837   std::string currDir = dqm_store->pwd();
00838   std::string dname = currDir.substr(currDir.find_last_of("/")+1);
00839   str_val << "<li><span class=\"folder\">" << dname << "</span>" << std::endl;
00840   std::vector<MonitorElement *> meVec = dqm_store->getContents(currDir);
00841   std::vector<std::string> subDirVec = dqm_store->getSubdirs();
00842   if ( meVec.size()== 0  && subDirVec.size() == 0 ) {
00843     str_val << "</li> "<< std::endl;    
00844     return;
00845   }
00846   str_val << "<ul>" << std::endl;      
00847   for (std::vector<MonitorElement *>::const_iterator it = meVec.begin();
00848          it != meVec.end(); it++) {
00849     MonitorElement* me = (*it);
00850     if (!me) continue;
00851     std::string name = (*it)->getName();
00852     str_val << "<li> <span class=\"file\"><a href=\"javascript:RequestHistos.DrawSummaryHistogram('" 
00853             << currDir
00854             << "')\">" << name << "</a></span></li>" << std::endl;
00855   }
00856   for (std::vector<std::string>::const_iterator ic = subDirVec.begin();
00857        ic != subDirVec.end(); ic++) {
00858     dqm_store->cd(*ic);
00859     printNonGeomHistoList(dqm_store, str_val);
00860     dqm_store->goUp();
00861   }
00862   str_val << "</ul> "<< std::endl;  
00863   str_val << "</li> "<< std::endl;  
00864 }