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
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
00051
00052 void SiPixelWebInterface::handleEDARequest(xgi::Input* in,xgi::Output* out, int niter) {
00053 DQMScope enter;
00054
00055 CgiReader reader(in);
00056 reader.read_form(requestMap_);
00057
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
00075
00076
00077
00078
00079
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
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
00131
00132 infoExtractor_->readStatusMessage(bei_, requestMap_, out);
00133 } else if (requestID == "PlotAsModule") {
00134
00135 theActionFlag = NoAction;
00136 infoExtractor_->getSingleModuleHistos(bei_, requestMap_, out);
00137 } else if (requestID == "PlotHistogramFromPath") {
00138
00139 theActionFlag = NoAction;
00140 infoExtractor_->getHistosFromPath(bei_, requestMap_, out);
00141
00142
00143
00144 } else if (requestID == "PlotTkMapHistogram") {
00145
00146
00147
00148
00149
00150
00151
00152
00153 theActionFlag = NoAction;
00154 infoExtractor_->getTrackerMapHistos(bei_, requestMap_, out);
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
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')) {
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
00199
00200 theActionFlag = ComputeGlobalQualityFlag;
00201 } else if (requestID == "dumpModIds") {
00202 theActionFlag = dumpModIds;
00203 }
00204
00205 performAction();
00206 }
00207
00208
00209
00210
00211 void SiPixelWebInterface::performAction() {
00212
00213
00214 switch (theActionFlag) {
00215 case SiPixelWebInterface::CreateTkMap :
00216 {
00217 if (createTkMap()) {
00218
00219 tkMapCreated = true;
00220
00221
00222
00223
00224
00225
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
00252 break;
00253 }
00254 case SiPixelWebInterface::PlotTkMapHistogram :
00255 {
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00279 break;
00280 }
00281 case SiPixelWebInterface::PlotSingleHistogram :
00282 {
00283
00284 break;
00285 }
00286 case SiPixelWebInterface::periodicTrackerMapUpdate :
00287 {
00288 break;
00289 }
00290 case SiPixelWebInterface::PlotHistogramFromPath :
00291 {
00292
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
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
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
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
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 }