CMS 3D CMS Logo

SiStripWebInterface.cc

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

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