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
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
00047
00048 void SiPixelWebInterface::handleEDARequest(xgi::Input* in,xgi::Output* out, int niter) {
00049 DQMScope enter;
00050
00051 CgiReader reader(in);
00052 reader.read_form(requestMap_);
00053
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
00071
00072
00073
00074
00075
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
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
00127
00128 infoExtractor_->readStatusMessage(bei_, requestMap_, out);
00129 } else if (requestID == "PlotAsModule") {
00130
00131 theActionFlag = NoAction;
00132 infoExtractor_->getSingleModuleHistos(bei_, requestMap_, out);
00133 } else if (requestID == "PlotHistogramFromPath") {
00134
00135 theActionFlag = NoAction;
00136 infoExtractor_->getHistosFromPath(bei_, requestMap_, out);
00137
00138
00139
00140 } else if (requestID == "PlotTkMapHistogram") {
00141
00142
00143
00144
00145
00146
00147
00148
00149 theActionFlag = NoAction;
00150 infoExtractor_->getTrackerMapHistos(bei_, requestMap_, out);
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
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
00178
00179 theActionFlag = ComputeGlobalQualityFlag;
00180 } else if (requestID == "dumpModIds") {
00181 theActionFlag = dumpModIds;
00182 }
00183
00184 performAction();
00185 }
00186
00187
00188
00189
00190 void SiPixelWebInterface::performAction() {
00191
00192
00193 switch (theActionFlag) {
00194 case SiPixelWebInterface::CreateTkMap :
00195 {
00196 if (createTkMap()) {
00197 tkMapCreated = true;
00198
00199
00200
00201
00202
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
00229 break;
00230 }
00231 case SiPixelWebInterface::PlotTkMapHistogram :
00232 {
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00256 break;
00257 }
00258 case SiPixelWebInterface::PlotSingleHistogram :
00259 {
00260
00261 break;
00262 }
00263 case SiPixelWebInterface::periodicTrackerMapUpdate :
00264 {
00265 break;
00266 }
00267 case SiPixelWebInterface::PlotHistogramFromPath :
00268 {
00269
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
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
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
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
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 }