CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/DQM/SiPixelMonitorClient/src/SiPixelWebInterface.cc

Go to the documentation of this file.
00001 #include "DQM/SiPixelMonitorClient/interface/SiPixelWebInterface.h"
00002 #include "DQM/SiPixelMonitorClient/interface/SiPixelActionExecutor.h"
00003 #include "DQM/SiPixelMonitorClient/interface/SiPixelInformationExtractor.h"
00004 #include "DQM/SiPixelMonitorClient/interface/ANSIColors.h"
00005 #include "DQMServices/Core/interface/DQMStore.h"
00006 #include "DQMServices/Core/interface/DQMScope.h"
00007 #include "DQM/TrackerCommon/interface/CgiWriter.h"
00008 #include "DQM/TrackerCommon/interface/CgiReader.h"
00009 
00010 #include <map>
00011 #include <iostream>
00012 #include <sstream>
00013 
00014 #define BUF_SIZE 256
00015 
00016 using namespace std ;
00017 
00018 
00019 //____________________________________________________________________________________________________
00020 SiPixelWebInterface::SiPixelWebInterface(DQMStore* bei, 
00021                                          bool offlineXMLfile, 
00022                                          bool Tier0Flag) : 
00023                                          bei_(bei), 
00024                                          offlineXMLfile_(offlineXMLfile), 
00025                                          Tier0Flag_(Tier0Flag) {
00026   
00027   theActionFlag = NoAction;
00028   actionExecutor_ = 0;
00029   infoExtractor_  = 0;
00030   tkMapOptions_.push_back("Persistant");
00031   tkMapOptions_.push_back("Temporary");
00032   tkMapCreated = false;
00033   if (actionExecutor_ == 0) actionExecutor_ = new SiPixelActionExecutor(offlineXMLfile_, Tier0Flag_);
00034   if (infoExtractor_ == 0) infoExtractor_ = new SiPixelInformationExtractor(offlineXMLfile_);
00035 }
00036 
00037 //____________________________________________________________________________________________________
00038 //
00039 // --  Destructor
00040 // 
00041 SiPixelWebInterface::~SiPixelWebInterface() {
00042   if (actionExecutor_) delete actionExecutor_;
00043   actionExecutor_ = 0;
00044   if (infoExtractor_)  delete infoExtractor_;
00045   infoExtractor_  = 0; 
00046 }
00047 
00048 //____________________________________________________________________________________________________
00049 // 
00050 // -- Handles requests from WebElements submitting non-default requests 
00051 //
00052 void SiPixelWebInterface::handleEDARequest(xgi::Input* in,xgi::Output* out, int niter) {
00053   DQMScope enter;
00054   //DQMStore* bei = (*mui_p)->getBEInterface();
00055   CgiReader reader(in);
00056   reader.read_form(requestMap_);
00057   // get the string that identifies the request:
00058   std::string requestID = get_from_multimap(requestMap_, "RequestID");
00059   cout << ACGreen << ACBold << ACReverse 
00060        << "[SiPixelWebInterface::handleEDARequest]"
00061        << ACCyan 
00062        << " requestID " 
00063        << ACPlain
00064        << requestID << endl;
00065 
00066   if (requestID == "IsReady") {
00067     theActionFlag = NoAction;    
00068     returnReplyXml(out, "ReadyState", "wait");
00069   } else if (requestID == "CheckQTResults") {
00070    theActionFlag = QTestResult;
00071   } else if (requestID == "updateIMGCPlots") {    // <-----------------
00072     theActionFlag = NoAction;    
00073     std::string MEFolder = get_from_multimap(requestMap_, "MEFolder");
00074     //cout << ACYellow << ACBold
00075     //     << "[SiPixelWebInterface::handleEDARequest] "
00076     //   << ACPlain
00077     //   << "Collecting ME from folder " 
00078     //   << MEFolder
00079     //   << endl ;
00080     out->getHTTPResponseHeader().addHeader("Content-Type", "text/html");
00081     out->getHTTPResponseHeader().addHeader("Pragma", "no-cache");   
00082     out->getHTTPResponseHeader().addHeader("Cache-Control", "no-store, no-cache, must-revalidate,max-age=0");
00083     out->getHTTPResponseHeader().addHeader("Expires","Mon, 26 Jul 1997 05:00:00 GMT");
00084     bei_->cd() ;
00085     bei_->cd(MEFolder) ;
00086 
00087     vector<std::string> meList = bei_->getMEs() ;
00088     
00089     *out << MEFolder << " " ;
00090     bei_->cd() ;
00091     for(vector<std::string>::iterator it=meList.begin(); it!=meList.end(); it++)
00092     {
00093      *out << *it << " " ;
00094     }
00095 
00096   } else if (requestID == "getIMGCPlot") {        // <-----------------
00097    infoExtractor_->getIMGCImage(requestMap_, out);
00098 
00099   } else if (requestID == "SetupQTest") {         // <-----------------
00100     theActionFlag = setupQTest;
00101 
00102   } else if (requestID == "CreateSummary") {      // <-----------------
00103     theActionFlag = Summary;
00104 
00105   } else if (requestID == "CreateTkMap") {
00106     std::string name = "TkMap";
00107     std::string comment;
00108     if (tkMapCreated) comment = "Successful";
00109     else  comment = "Failed";
00110     returnReplyXml(out, name, comment);
00111     theActionFlag = CreateTkMap;    
00112   } else if (requestID == "SingleModuleHistoList") {
00113     theActionFlag = NoAction;
00114     infoExtractor_->readModuleAndHistoList(bei_, out);    
00115   } else if (requestID == "ModuleHistoList") {
00116     theActionFlag = NoAction;
00117     string sname = get_from_multimap(requestMap_, "StructureName");
00118     //cout<<"in EDARequest: structure name= "<<sname<<endl;
00119     infoExtractor_->readModuleHistoTree(bei_, sname, out);    
00120   } else if (requestID == "SummaryHistoList") {
00121     theActionFlag = NoAction;
00122     string sname = get_from_multimap(requestMap_, "StructureName");
00123     infoExtractor_->readSummaryHistoTree(bei_, sname, out);    
00124   } else if (requestID == "AlarmList") {
00125     theActionFlag = NoAction;
00126     string sname = get_from_multimap(requestMap_, "StructureName");
00127     infoExtractor_->readAlarmTree(bei_, sname, out);    
00128   } else if (requestID == "ReadQTestStatus") {
00129     theActionFlag = NoAction;
00130     //string path = get_from_multimap(requestMap_, "Path");
00131     //infoExtractor_->readStatusMessage(bei_, path, out);
00132     infoExtractor_->readStatusMessage(bei_, requestMap_, out);
00133   } else if (requestID == "PlotAsModule") {
00134     //theActionFlag = PlotSingleModuleHistos;    
00135     theActionFlag = NoAction;  
00136     infoExtractor_->getSingleModuleHistos(bei_, requestMap_, out);    
00137   } else if (requestID == "PlotHistogramFromPath") {
00138    //theActionFlag = PlotHistogramFromPath;
00139    theActionFlag = NoAction;
00140    infoExtractor_->getHistosFromPath(bei_, requestMap_, out);    
00141   //} else if (requestID == "PlotSingleHistogram") {
00142   //  theActionFlag = PlotSingleHistogram;
00143 
00144   } else if (requestID == "PlotTkMapHistogram") {
00145     //string theMEName = get_from_multimap(requestMap_, "MEName");
00146     //string theModId  = get_from_multimap(requestMap_, "ModId");
00147     //infoExtractor_->plotTkMapHisto(bei, theModId, theMEName);
00148     //out->getHTTPResponseHeader().addHeader("Content-Type", "image/png");
00149     //out->getHTTPResponseHeader().addHeader("Pragma", "no-cache");   
00150     //out->getHTTPResponseHeader().addHeader("Cache-Control", "no-store, no-cache, must-revalidate,max-age=0");
00151     //out->getHTTPResponseHeader().addHeader("Expires","Mon, 26 Jul 1997 05:00:00 GMT");
00152     //*out << infoExtractor_->getNamedImage(theMEName).str();
00153     theActionFlag = NoAction;    
00154     infoExtractor_->getTrackerMapHistos(bei_, requestMap_, out);
00155   //} else if (requestID == "UpdatePlot") {
00156   //  string theMEName = get_from_multimap(requestMap_, "MEName");
00157   //  out->getHTTPResponseHeader().addHeader("Content-Type", "image/png");
00158   //  out->getHTTPResponseHeader().addHeader("Pragma", "no-cache");   
00159   //  out->getHTTPResponseHeader().addHeader("Cache-Control", "no-store, no-cache, must-revalidate,max-age=0");
00160  //   out->getHTTPResponseHeader().addHeader("Expires","Mon, 26 Jul 1997 05:00:00 GMT");
00161   //  *out << infoExtractor_->getImage().str();
00162   //  theActionFlag = NoAction;    
00163  // } else if (requestID == "UpdateTkMapPlot") {
00164  //   string theMEName = get_from_multimap(requestMap_, "MEName");
00165  //   out->getHTTPResponseHeader().addHeader("Content-Type", "image/png");
00166  //   out->getHTTPResponseHeader().addHeader("Pragma", "no-cache");   
00167  //   out->getHTTPResponseHeader().addHeader("Cache-Control", "no-store, no-cache, must-revalidate,max-age=0");
00168  //   out->getHTTPResponseHeader().addHeader("Expires","Mon, 26 Jul 1997 05:00:00 GMT");
00169  //   *out << infoExtractor_->getNamedImage(theMEName).str();
00170  //    theActionFlag = NoAction;    
00171 
00172   } else if (requestID == "GetMEList") {
00173     theActionFlag = NoAction;
00174     infoExtractor_->readModuleAndHistoList(bei_, out);    
00175 
00176   } else if (requestID == "GetTkMap") { 
00177     theActionFlag = NoAction;    
00178     
00179     ifstream fin("dqmtmapviewer.xhtml");
00180     char buf[BUF_SIZE];
00181     std::ostringstream html_out;
00182     if (!fin) {
00183       std::cerr << "Input File: dqmtmapviewer.xhtml "<< " could not be opened!" << std::endl;
00184       return;
00185     }
00186     while (fin.getline(buf, BUF_SIZE, '\n')) { // pops off the newline character 
00187       html_out << buf << std::endl;
00188     }
00189     fin.close();
00190     
00191     out->getHTTPResponseHeader().addHeader("Content-type","application/xhtml+xml");
00192     *out << html_out.str();
00193   } else if (requestID == "periodicTrackerMapUpdate") {
00194    theActionFlag = NoAction;
00195    periodicTkMapUpdate(out) ;
00196 
00197   } else if  (requestID == "globalQFlag") {
00198     //cout << ACYellow << ACBold << "[SiPixelWebInterface::handleEDARequest]  " 
00199     //     << ACPlain << "Compute global Pixel quality flag" << endl;
00200     theActionFlag = ComputeGlobalQualityFlag;
00201   } else if (requestID == "dumpModIds") {
00202     theActionFlag = dumpModIds;
00203   }
00204     
00205   performAction();
00206 }
00207 
00208 //____________________________________________________________________________________________________
00209 // -- Perform action
00210 //
00211 void SiPixelWebInterface::performAction() {
00212 //cout<<"entering performAction..."<<endl;
00213   //DQMStore * bei_ = (*mui_p)->getBEInterface();
00214   switch (theActionFlag) {
00215   case SiPixelWebInterface::CreateTkMap :
00216     {
00217      if (createTkMap()) {
00218 //     cout<<"calling the dtor before this?"<<endl;
00219        tkMapCreated = true;
00220 //       theOut->getHTTPResponseHeader().addHeader("Content-Type", "text/xml");
00221 //      *theOut << "<?xml version=\"1.0\" ?>"        << endl;
00222 //      *theOut << "<TkMap>"                         << endl;
00223 //      *theOut << " <Response>Successfull</Response>" << endl;
00224 //      *theOut << "</TkMap>"                        << endl;
00225 //cout<<"Done creating the TkMap in WI::performAction, what now?!"<<endl;
00226      }
00227       break;
00228     }
00229   case SiPixelWebInterface::Summary :
00230     {
00231       actionExecutor_->createSummary(bei_);
00232       break;
00233     }
00234   case SiPixelWebInterface::Occupancy :
00235     {
00236       actionExecutor_->createOccupancy(bei_);
00237       break;
00238     }
00239   case SiPixelWebInterface::setupQTest :
00240     {
00241       actionExecutor_->setupQTests(bei_);
00242       break;
00243     }
00244   case SiPixelWebInterface::QTestResult :
00245     {
00246       actionExecutor_->checkQTestResults(bei_);
00247       break;
00248     }
00249   case SiPixelWebInterface::PlotSingleModuleHistos :
00250     {
00251 //      infoExtractor_->plotSingleModuleHistos(bei_, requestMap_);
00252       break;
00253     }
00254   case SiPixelWebInterface::PlotTkMapHistogram :
00255     {
00256 //      string theMEName = get_from_multimap(requestMap_, "MEName");
00257 //      string theModId  = get_from_multimap(requestMap_, "ModId");
00258 //      infoExtractor_->plotTkMapHisto(bei_, theModId, theMEName);
00259 //
00260 //      cout << ACYellow << ACBold 
00261 //           << "[SiPixelWebInterface::PlotTkMapHistogram()]"
00262 //           << ACPlain
00263 //           << " Buffer for "
00264 //         <<  theMEName
00265 //         << " stored away: shipping back header (" << theOut << ")" 
00266 //           << endl ;
00279       break;
00280     }
00281   case SiPixelWebInterface::PlotSingleHistogram :
00282     {
00283 //      infoExtractor_->plotSingleHistogram(bei_, requestMap_);
00284       break;
00285     }
00286   case SiPixelWebInterface::periodicTrackerMapUpdate :
00287     {
00288       break;
00289     }
00290   case SiPixelWebInterface::PlotHistogramFromPath :
00291     {
00292 //      infoExtractor_->getHistosFromPath(bei_, requestMap_);
00293       break;
00294     }
00295   case SiPixelWebInterface::CreatePlots :
00296     {
00297       infoExtractor_->createImages(bei_);
00298       break;
00299     }
00300   case SiPixelWebInterface::dumpModIds  :
00301     {
00302       break;
00303     }
00304   case SiPixelWebInterface::ComputeGlobalQualityFlag :
00305     {
00306       break;
00307     }
00308   case SiPixelWebInterface::NoAction :
00309     {
00310       break;
00311     }
00312   }
00313   setActionFlag(SiPixelWebInterface::NoAction);
00314 //  cout<<"leaving performAction..."<<endl;
00315 }
00316 
00317 
00318 //____________________________________________________________________________________________________
00319 void SiPixelWebInterface::returnReplyXml(xgi::Output * out, 
00320                                          const std::string& name, 
00321                                          const std::string& comment){
00322    out->getHTTPResponseHeader().addHeader("Content-Type", "text/xml");
00323   *out << "<?xml version=\"1.0\" ?>" << std::endl;
00324   *out << "<TkMap>" << endl;
00325   *out << " <Response>" << comment << "</Response>" << endl;
00326   *out << "</TkMap>" << endl;
00327 
00328 }
00329 
00330 
00331 //____________________________________________________________________________________________________
00332 bool SiPixelWebInterface::createTkMap() {
00333   //DQMStore * bei = (*mui_p)->getBEInterface();
00334   if (theActionFlag == SiPixelWebInterface::CreateTkMap) {
00335     string sname     = get_from_multimap(requestMap_, "MEName");
00336     string theTKType = get_from_multimap(requestMap_, "TKMapType");
00337     actionExecutor_->createTkMap(bei_, sname, theTKType);
00338     return true;
00339   } else {
00340     return false;
00341   }
00342 }
00343 
00344 
00345 //____________________________________________________________________________________________________
00346 void SiPixelWebInterface::periodicTkMapUpdate(xgi::Output * out)
00347 {
00348   //DQMStore * bei = (*mui_p)->getBEInterface();
00349   string sname     = get_from_multimap(requestMap_, "MEName");
00350   string theTKType = get_from_multimap(requestMap_, "TKMapType");
00351   infoExtractor_->sendTkUpdatedStatus(bei_, out, sname, theTKType) ;
00352 }
00353 
00354 //____________________________________________________________________________________________________
00355 bool SiPixelWebInterface::readConfiguration(int& tkmap_freq,int& summary_freq){
00356   bool success=false;
00357   tkmap_freq = -1;
00358   summary_freq = -1;
00359   if (actionExecutor_)  {
00360     actionExecutor_->readConfiguration(tkmap_freq,summary_freq);
00361     if(tkmap_freq!=-1 && summary_freq!=-1) success=true;
00362   }
00363   return success;
00364 }
00365 
00366 //
00367 // Get the RequestId and tags 
00368 //
00369 std::string SiPixelWebInterface::get_from_multimap(std::multimap<std::string, std::string> &mymap, std::string key)
00370 {
00371   std::multimap<std::string, std::string>::iterator it;
00372   it = mymap.find(key);
00373   if (it != mymap.end())
00374     {
00375       return (it->second);
00376     }
00377   return "";
00378 }