CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/DQM/SiStripMonitorClient/src/SiStripWebInterface.cc

Go to the documentation of this file.
00001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00002 #include "DQM/SiStripMonitorClient/interface/SiStripWebInterface.h"
00003 #include "DQM/SiStripMonitorClient/interface/SiStripInformationExtractor.h"
00004 #include "DQMServices/Core/interface/DQMStore.h"
00005 #include "DQMServices/Core/interface/DQMScope.h"
00006 #include "DQM/TrackerCommon/interface/CgiWriter.h"
00007 #include "DQM/TrackerCommon/interface/CgiReader.h"
00008 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
00009 
00010 
00011 #include <map>
00012 #include <iostream>
00013 #include <sstream>
00014 
00015 #define BUF_SIZE 256
00016 //
00017 // -- Constructor
00018 // 
00019 SiStripWebInterface::SiStripWebInterface(DQMStore* dqm_store) : dqmStore_(dqm_store) {
00020   
00021   theActionFlag = NoAction;
00022   infoExtractor_  = 0;
00023   if (infoExtractor_ == 0) infoExtractor_ = new SiStripInformationExtractor();
00024   TkMapType = "QTestAlarm";
00025 }
00026 //
00027 // --  Destructor
00028 // 
00029 SiStripWebInterface::~SiStripWebInterface() {
00030   if (infoExtractor_) delete infoExtractor_;
00031   infoExtractor_ = 0; 
00032 }
00033 // 
00034 // -- Handles requests from WebElements submitting non-default requests 
00035 //
00036 void SiStripWebInterface::handleAnalyserRequest(xgi::Input* in,xgi::Output* out, const edm::ESHandle<SiStripDetCabling>& detcabling, int niter) {
00037   DQMScope enter;
00038   // put the request information in a multimap...
00039   //  std::multimap<std::string, std::string> requestMap_;
00040   CgiReader reader(in);
00041   reader.read_form(requestMap_);
00042   if (niter < 0) return;
00043   std::string requestID = get_from_multimap(requestMap_, "RequestID");
00044   // get the string that identifies the request:
00045   edm::LogInfo ("SiStripWebInterface") << "SiStripWebInterface::handleAnalyserRequest RequestID = " << requestID ;
00046   if (requestID == "IsReady") {
00047     theActionFlag = NoAction;    
00048     if (niter > 0) {
00049       infoExtractor_->readLayoutNames(dqmStore_, out);
00050     } else {
00051       returnReplyXml(out, "ReadyState", "wait");
00052     }
00053   }    
00054   else if (requestID == "CheckQTResults") {
00055     std::string infoType = get_from_multimap(requestMap_, "InfoType");
00056     infoExtractor_->readQTestSummary(dqmStore_, infoType, out);
00057     theActionFlag = NoAction;
00058   }
00059   else if (requestID == "SingleModuleHistoList") {
00060     theActionFlag = NoAction;
00061     std::string sname = get_from_multimap(requestMap_, "FolderName");    
00062     infoExtractor_->readModuleAndHistoList(dqmStore_, sname, detcabling, out);
00063   } 
00064   else if (requestID == "GlobalHistoList") {
00065     theActionFlag = NoAction;
00066     std::string gname = get_from_multimap(requestMap_, "GlobalFolder");    
00067     infoExtractor_->readGlobalHistoList(dqmStore_, gname, out);
00068   } 
00069   else if (requestID == "SummaryHistoList") {
00070     theActionFlag = NoAction;
00071     std::string sname = get_from_multimap(requestMap_, "StructureName");
00072     infoExtractor_->readSummaryHistoTree(dqmStore_, sname, out);
00073   } 
00074   else if (requestID == "AlarmList") {
00075     theActionFlag = NoAction;
00076     std::string sname = get_from_multimap(requestMap_, "StructureName");
00077     infoExtractor_->readAlarmTree(dqmStore_, sname, out);
00078   } 
00079   else if (requestID == "ReadQTestStatus") {
00080     theActionFlag = NoAction;
00081     infoExtractor_->readStatusMessage(dqmStore_, requestMap_, out);
00082   } 
00083    else if (requestID == "PlotAsModule") {
00084     theActionFlag = NoAction;  
00085     infoExtractor_->getSingleModuleHistos(dqmStore_, requestMap_, out);    
00086   }
00087   else if (requestID == "PlotGlobalHisto") {
00088     theActionFlag = NoAction;
00089     infoExtractor_->getGlobalHistos(dqmStore_, requestMap_, out);    
00090   }
00091   else if (requestID == "PlotHistogramFromPath") {
00092    theActionFlag = NoAction;
00093    infoExtractor_->getHistosFromPath(dqmStore_, requestMap_, out);    
00094   } 
00095   else if (requestID == "PlotTkMapHistogram") {
00096     theActionFlag = NoAction;
00097     requestMap_.insert(std::pair<std::string,std::string>("TkMapType", TkMapType));
00098     infoExtractor_->getTrackerMapHistos(dqmStore_, requestMap_, out);
00099   }
00100   else if (requestID == "PlotHistogramFromLayout") {
00101     theActionFlag = PlotHistogramFromLayout;
00102   } 
00103   else if (requestID == "GetImage") { 
00104    infoExtractor_->getImage(requestMap_, out);
00105   }
00106   else if (requestID == "GetTkMap") { 
00107     theActionFlag = NoAction;    
00108     
00109     ifstream fin("dqmtmapviewer.xhtml");
00110     char buf[BUF_SIZE];
00111     std::ostringstream html_out;
00112     if (!fin) {
00113       std::cerr << "Input File: dqmtmapviewer.xhtml "<< " could not be opened!" << std::endl;
00114       return;
00115     }
00116     while (fin.getline(buf, BUF_SIZE, '\n')) { // pops off the newline character 
00117       html_out << buf << std::endl;
00118     }
00119     fin.close();
00120     
00121     out->getHTTPResponseHeader().addHeader("Content-type","application/xhtml+xml");
00122     *out << html_out.str();
00123   }
00124   else if (requestID == "NonGeomHistoList") {
00125     theActionFlag = NoAction;
00126     std::string fname = get_from_multimap(requestMap_, "FolderName");
00127     infoExtractor_->readNonGeomHistoTree(dqmStore_, fname, out);
00128   }
00129   else if (requestID == "PlotModuleCondDBHistos") {    
00130     theActionFlag = NoAction;
00131     CondDBPlotParameter local_par;
00132     uint32_t detId = atoi(get_from_multimap(requestMap_,"ModId").c_str());
00133     local_par.detId   = detId;
00134     local_par.type    = "";
00135     local_par.side    = 999;
00136     local_par.layer   = 999;   
00137     bool create_plot;   
00138     infoExtractor_->getCondDBHistos(dqmStore_, create_plot, requestMap_, out);      
00139     if (create_plot)  condDBRequestList_.push_back(local_par);
00140   }
00141   else if (requestID == "PlotLayerCondDBHistos") {
00142 
00143     theActionFlag = NoAction;
00144     CondDBPlotParameter local_par;
00145     std::string sname = get_from_multimap(requestMap_,"StructureName");
00146     local_par.detId   = 999;
00147     local_par.type    = sname.substr(sname.find_first_of("/")+1,3);
00148     if (sname.find("side_")!=std::string::npos) 
00149             local_par.side = atoi((sname.substr(sname.find("side_")+5,1)).c_str());
00150     else local_par.side = 999;
00151     local_par.layer   = atoi((sname.substr(sname.find_last_of("_")+1)).c_str());
00152     bool create_plot;
00153     infoExtractor_->getCondDBHistos(dqmStore_, create_plot, requestMap_, out);      
00154     if (create_plot)  condDBRequestList_.push_back(local_par);
00155 
00156   }  else if (requestID == "UpdateTrackerMapOption") { 
00157     theActionFlag = NoAction;
00158     TkMapType = get_from_multimap(requestMap_,"Option");
00159     returnReplyXml(out, "TkMapOption", TkMapType);
00160   }
00161 
00162   performAction();
00163 }
00164 //
00165 // -- Perform action
00166 //
00167 void SiStripWebInterface::performAction() {
00168 
00169   switch (theActionFlag) {
00170   case SiStripWebInterface::Summary :
00171     {
00172       //      actionExecutor_->createSummary(dqmStore_);
00173       break;
00174     }
00175   case SiStripWebInterface::PlotSingleModuleHistos :
00176     {
00177 //      infoExtractor_->plotSingleModuleHistos(dqmStore_, requestMap_, out);
00178       break;
00179     }
00180   case SiStripWebInterface::PlotGlobalHistos :
00181     {
00182 //      infoExtractor_->plotGlobalHistos(dqmStore_, requestMap_, out);
00183       break;
00184     }
00185   case SiStripWebInterface::PlotTkMapHistogram :
00186     {
00187 //      infoExtractor_->plotTrackerMapHistos(dqmStore_, requestMap_, out);
00188       break;
00189     }
00190   case SiStripWebInterface::PlotHistogramFromPath :
00191     {
00192 //       infoExtractor_->plotHistosFromPath(dqmStore_, requestMap_, out);
00193       break;
00194     }
00195   case SiStripWebInterface::PlotHistogramFromLayout :
00196     {
00197       infoExtractor_->plotHistosFromLayout(dqmStore_);
00198       break;
00199     }
00200   case SiStripWebInterface::CreatePlots :
00201     {
00202       infoExtractor_->createImages(dqmStore_);
00203       break;
00204     }
00205   case SiStripWebInterface::NoAction :
00206     {
00207       break;
00208     }
00209   }
00210   setActionFlag(SiStripWebInterface::NoAction);
00211 }
00212 void SiStripWebInterface::returnReplyXml(xgi::Output * out, const std::string& name, const std::string& comment){
00213    out->getHTTPResponseHeader().addHeader("Content-Type", "text/xml");
00214   *out << "<?xml version=\"1.0\" ?>" << std::endl;
00215   *out << "<"<<name<<">" << std::endl;
00216   *out << " <Response>" << comment << "</Response>" << std::endl;
00217   *out << "</"<<name<<">" << std::endl;
00218 }
00219 //
00220 // Get the RequestId and tags 
00221 //
00222 std::string SiStripWebInterface::get_from_multimap(std::multimap<std::string, std::string> &mymap, std::string key)
00223 {
00224   std::multimap<std::string, std::string>::iterator it;
00225   it = mymap.find(key);
00226   if (it != mymap.end())
00227     {
00228       return (it->second);
00229     }
00230   return "";
00231 }
00232 //
00233 // -- Get CondDB Parameters
00234 //
00235 void SiStripWebInterface::getConDBPlotParameters(unsigned int ival, uint32_t &det_id, 
00236                    std::string& subdet_type, uint32_t& subdet_side, uint32_t& layer_number) {
00237   if (condDBRequestList_.size() > ival) {
00238     det_id       = condDBRequestList_[ival].detId;
00239     subdet_type  = condDBRequestList_[ival].type;
00240     subdet_side  = condDBRequestList_[ival].side;
00241     layer_number = condDBRequestList_[ival].layer;
00242   } else {
00243     det_id       = 999;
00244     subdet_type  = "";
00245     subdet_side  = 999;
00246     layer_number = 999;
00247   }
00248 
00249 }