00001 #include "DQM/TrackerCommon/interface/WebInterface.h"
00002 #include "DQM/TrackerCommon/interface/CgiReader.h"
00003 #include "DQM/TrackerCommon/interface/CgiWriter.h"
00004 #include "DQM/TrackerCommon/interface/ContentReader.h"
00005 #include "FWCore/ServiceRegistry/interface/Service.h"
00006 #include "DQMServices/Core/interface/DQMStore.h"
00007
00008
00009 WebInterface::WebInterface(std::string _exeURL, std::string _appURL)
00010 {
00011 exeURL = _exeURL;
00012 appURL = _appURL;
00013
00014 std::cout << "created a WebInterface for the DQMClient, the url = " << appURL << std::endl;
00015 std::cout << "within context = " << exeURL << std::endl;
00016
00017 dqmStore_ = edm::Service<DQMStore>().operator->();
00018 }
00019
00020
00021 std::string WebInterface::get_from_multimap(std::multimap<std::string, std::string> &mymap, std::string key)
00022 {
00023 std::multimap<std::string, std::string>::iterator it;
00024 it = mymap.find(key);
00025 if (it != mymap.end())
00026 {
00027 return (it->second);
00028 }
00029 return "";
00030 }
00031
00032 void WebInterface::handleRequest(xgi::Input * in, xgi::Output * out ) throw (xgi::exception::Exception)
00033 {
00034 handleStandardRequest(in, out);
00035 handleCustomRequest(in, out);
00036
00037
00038 if (msg_dispatcher.hasAnyMessages()) msg_dispatcher.dispatchMessages(out);
00039 }
00040
00041 void WebInterface::Default(xgi::Input * in, xgi::Output * out ) throw (xgi::exception::Exception)
00042 {
00043 CgiWriter writer(out, getContextURL());
00044 writer.output_preamble();
00045 writer.output_head();
00046 page_p->printHTML(out);
00047 writer.output_finish();
00048 }
00049
00050 void WebInterface::add(std::string name, WebElement * element_p)
00051 {
00052 page_p->add(name, element_p);
00053 }
00054
00055 void WebInterface::handleStandardRequest(xgi::Input * in, xgi::Output * out ) throw (xgi::exception::Exception)
00056 {
00057 std::multimap<std::string, std::string> request_multimap;
00058 CgiReader reader(in);
00059 reader.read_form(request_multimap);
00060
00061
00062 std::string requestID = get_from_multimap(request_multimap, "RequestID");
00063
00064 if (requestID == "Configure") Configure(in, out);
00065 if (requestID == "Open") Open(in, out);
00066
00067
00068 if (requestID == "ContentsOpen") ContentsOpen(in, out);
00069 if (requestID == "Draw") DrawGif(in, out);
00070 }
00071
00072 void WebInterface::Configure(xgi::Input * in, xgi::Output * out) throw (xgi::exception::Exception)
00073 {
00074 CgiReader reader(in);
00075 reader.read_form(conf_map);
00076
00077 std::string host = get_from_multimap(conf_map, "Hostname");
00078 std::string port = get_from_multimap(conf_map, "Port");
00079 std::string clientname = get_from_multimap(conf_map, "Clientname");
00080
00081 }
00082
00083 void WebInterface::Open(xgi::Input * in, xgi::Output * out) throw (xgi::exception::Exception)
00084 {
00085 std::multimap<std::string, std::string> nav_map;
00086
00087 CgiReader reader(in);
00088 reader.read_form(nav_map);
00089
00090 std::string to_open = get_from_multimap(nav_map, "Open");
00091 std::string current = get_from_multimap(nav_map, "Current");
00092
00093
00094 if (to_open != "top")
00095 {
00096
00097 if (current != "top")
00098 {
00099
00100 if (to_open != "..")
00101 {
00102
00103 to_open = current + "/" + to_open;
00104 }
00105 }
00106 }
00107
00108
00109 std::cout << "will try to open " << to_open << std::endl;
00110 if (dqmStore_)
00111 {
00112 if (to_open == "top")
00113 {
00114 dqmStore_->setCurrentFolder("/");
00115 }
00116 else if (to_open == "..")
00117 {
00118 dqmStore_->goUp();
00119 }
00120 else
00121 {
00122 dqmStore_->setCurrentFolder(to_open);
00123 }
00124 printNavigatorXML(dqmStore_->pwd(), out);
00125 }
00126 else
00127 {
00128 std::cout << "no DQMStore object, subscription to " << to_open << " failed!" << std::endl;
00129 }
00130
00131 }
00132
00133 void WebInterface::printNavigatorXML(std::string current, xgi::Output * out)
00134 {
00135 if (!dqmStore_)
00136 {
00137 std::cout << "NO GUI!!!" << std::endl;
00138 return;
00139 }
00140
00141 out->getHTTPResponseHeader().addHeader("Content-Type", "text/xml");
00142
00143 *out << "<?xml version=\"1.0\" ?>" << std::endl;
00144
00145 *out << "<navigator>" << std::endl;
00146
00147 *out << "<current>" << current << "</current>" << std::endl;
00148
00149 ContentReader reader(dqmStore_);
00150
00151 std::list<std::string>::iterator it;
00152
00153 std::list<std::string> open_l;
00154 reader.give_subdirs(current, open_l, "SuperUser");
00155 for (it = open_l.begin(); it != open_l.end(); it++)
00156 *out << "<open>" << *it << "</open>" << std::endl;
00157
00158 std::list<std::string> subscribe_l;
00159 reader.give_files(current, subscribe_l, false);
00160 for (it = subscribe_l.begin(); it != subscribe_l.end(); it++)
00161 *out << "<subscribe>" << *it << "</subscribe>" << std::endl;
00162
00163 std::list<std::string> unsubscribe_l;
00164 reader.give_files(current, unsubscribe_l, true);
00165 for (it = unsubscribe_l.begin(); it != unsubscribe_l.end(); it++)
00166 *out << "<unsubscribe>" << *it << "</unsubscribe>" << std::endl;
00167
00168 *out << "</navigator>" << std::endl;
00169
00170
00171 std::cout << "<?xml version=\"1.0\" ?>" << std::endl;
00172
00173 std::cout << "<navigator>" << std::endl;
00174
00175 std::cout << "<current>" << current << "</current>" << std::endl;
00176
00177 for (it = open_l.begin(); it != open_l.end(); it++)
00178 std::cout << "<open>" << *it << "</open>" << std::endl;
00179
00180 for (it = subscribe_l.begin(); it != subscribe_l.end(); it++)
00181 std::cout << "<subscribe>" << *it << "</subscribe>" << std::endl;
00182
00183 for (it = unsubscribe_l.begin(); it != unsubscribe_l.end(); it++)
00184 std::cout << "<unsubscribe>" << *it << "</unsubscribe>" << std::endl;
00185
00186 std::cout << "</navigator>" << std::endl;
00187
00188 }
00189
00190 void WebInterface::ContentsOpen(xgi::Input * in, xgi::Output * out) throw (xgi::exception::Exception)
00191 {
00192 std::multimap<std::string, std::string> nav_map;
00193
00194 CgiReader reader(in);
00195 reader.read_form(nav_map);
00196
00197 std::string to_open = get_from_multimap(nav_map, "Open");
00198 std::string current = get_from_multimap(nav_map, "Current");
00199
00200
00201 if (to_open != "top")
00202 {
00203
00204 if (current != "top")
00205 {
00206
00207 if (to_open != "..")
00208 {
00209
00210 to_open = current + "/" + to_open;
00211 }
00212 }
00213 }
00214
00215
00216 std::cout << "will try to open " << to_open << std::endl;
00217 if (dqmStore_)
00218 {
00219 if (to_open == "top")
00220 {
00221 dqmStore_->cd();
00222 }
00223 else if (to_open == "..")
00224 {
00225 dqmStore_->goUp();
00226 }
00227 else
00228 {
00229 dqmStore_->setCurrentFolder(to_open);
00230 }
00231 printContentViewerXML(dqmStore_->pwd(), out);
00232 }
00233 else
00234 {
00235 std::cout << "no DQMStore object, subscription to " << to_open << " failed!" << std::endl;
00236 }
00237 }
00238
00239 void WebInterface::printContentViewerXML(std::string current, xgi::Output * out)
00240 {
00241 if (!(dqmStore_))
00242 {
00243 std::cout << "NO GUI!!!" << std::endl;
00244 return;
00245 }
00246
00247 out->getHTTPResponseHeader().addHeader("Content-Type", "text/xml");
00248
00249 *out << "<?xml version=\"1.0\" ?>" << std::endl;
00250
00251 *out << "<contentViewer>" << std::endl;
00252
00253 *out << "<current>" << current << "</current>" << std::endl;
00254
00255 ContentReader reader(dqmStore_);
00256
00257 std::list<std::string>::iterator it;
00258
00259 std::list<std::string> open_l;
00260 reader.give_subdirs(current, open_l, "SuperUser");
00261 for (it = open_l.begin(); it != open_l.end(); it++)
00262 *out << "<open>" << *it << "</open>" << std::endl;
00263
00264 std::list<std::string> view_l;
00265 reader.give_files(current, view_l, true);
00266 for (it = view_l.begin(); it != view_l.end(); it++)
00267 *out << "<view>" << *it << "</view>" << std::endl;
00268
00269 *out << "</contentViewer>" << std::endl;
00270 }
00271
00272
00273 void WebInterface::DrawGif(xgi::Input * in, xgi::Output * out) throw (xgi::exception::Exception)
00274 {
00275 std::multimap<std::string, std::string> view_multimap;
00276 ME_MAP view_map;
00277
00278 CgiReader cgi_reader(in);
00279 cgi_reader.read_form(view_multimap);
00280
00281 std::string current = get_from_multimap(view_multimap, "Current");
00282
00283
00284 if (dqmStore_)
00285 {
00286 std::cout << "The DQMStore pointer is empty!" << std::endl;
00287 return;
00288 }
00289
00290 ContentReader con_reader(dqmStore_);
00291 std::multimap<std::string,std::string>::iterator lower = view_multimap.lower_bound("View");
00292 std::multimap<std::string,std::string>::iterator upper = view_multimap.upper_bound("View");
00293 std::multimap<std::string,std::string>::iterator it;
00294 for (it = lower; it != upper; it++)
00295 {
00296 std::string name = it->second;
00297 MonitorElement *pointer = con_reader.give_ME(name);
00298 if (pointer != 0)
00299 {
00300 view_map.add(name, pointer);
00301 std::cout << "ADDING " << name << " TO view_map!!!" << std::endl;
00302 }
00303 }
00304
00305
00306 std::string id = get_from_multimap(view_multimap, "DisplayFrameName");
00307 std::cout << "will try to print " << id << std::endl;
00308
00309
00310 out->getHTTPResponseHeader().addHeader("Content-Type", "text/xml");
00311 *out << "<?xml version=\"1.0\" ?>" << std::endl;
00312 *out << "<fileURL>" << std::endl;
00313 *out << getContextURL() + "/temporary/" + id + ".gif" << std::endl;
00314 *out << "</fileURL>" << std::endl;
00315
00316 }
00317
00318 void WebInterface::printMap(ME_MAP view_map, std::string id)
00319 {
00320 view_map.print(id);
00321 }
00322
00323 void WebInterface::sendMessage(std::string title, std::string text, MessageType type)
00324 {
00325 Message * msg = new Message(title, text, type);
00326 msg_dispatcher.add(msg);
00327 }