CMS 3D CMS Logo

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

Generated on Tue Jun 9 17:33:21 2009 for CMSSW by  doxygen 1.5.4