CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
WebGUI.cc
Go to the documentation of this file.
1 //
3 // WebGUI
4 // ------
5 //
6 // 10/19/2006 Philipp Schieferdecker <philipp.schieferdecker@cern.ch>
8 
9 
11 
12 #include "xcept/Exception.h"
13 #include "xcept/tools.h"
14 
15 #include "cgicc/CgiDefs.h"
16 #include "cgicc/Cgicc.h"
17 #include "cgicc/HTMLClasses.h"
18 
19 #include <sstream>
20 
21 
22 using namespace std;
23 using namespace evf;
24 using namespace cgicc;
25 
26 
28 // construction/destruction
30 
31 //______________________________________________________________________________
32 WebGUI::WebGUI(xdaq::Application* app,StateMachine* fsm)
33  : app_(app)
34  , fsm_(fsm)
35  , log_(app->getApplicationContext()->getLogger())
36  , appInfoSpace_(0)
37  , monInfoSpace_(0)
38  , itemGroupListener_(0)
39  , parametersExported_(false)
40  , countersAddedToParams_(false)
41  , largeAppIcon_("/evf/images/rbicon.jpg")
42  , smallAppIcon_("/evf/images/rbicon.jpg")
43  , smallDbgIcon_("/evf/images/bugicon.jpg")
44  , smallCtmIcon_("/evf/images/spoticon.jpg")
45  , hyperDAQIcon_("/hyperdaq/images/HyperDAQ.jpg")
46 {
47  // initialize application information
48  string appClass=app_->getApplicationDescriptor()->getClassName();
49  unsigned int instance=app_->getApplicationDescriptor()->getInstance();
50  stringstream oss;
51  oss<<appClass<<instance;
52 
53  sourceId_=oss.str();
54  urn_ ="/"+app_->getApplicationDescriptor()->getURN();
55 
56  std::stringstream oss2;
57  oss2<<"urn:xdaq-monitorable-"<<appClass;
58  string monInfoSpaceName=oss2.str();
59  toolbox::net::URN urn = app_->createQualifiedInfoSpace(monInfoSpaceName);
60 
61  appInfoSpace_=app_->getApplicationInfoSpace();
62  monInfoSpace_=xdata::getInfoSpaceFactory()->get(urn.toString());
63  app_->getApplicationDescriptor()->setAttribute("icon",largeAppIcon_);
64 
65  // bind xgi callbacks
66  xgi::bind(this,&WebGUI::defaultWebPage,"defaultWebPage");
67  xgi::bind(this,&WebGUI::debugWebPage, "debugWebPage");
68  xgi::bind(this,&WebGUI::css, "styles.css");
69 
70  // set itemGroupListener
71  itemGroupListener_ = dynamic_cast<xdata::ActionListener*>(app_);
72  if (0!=itemGroupListener_) {
73  appInfoSpace()->addGroupRetrieveListener(itemGroupListener_);
74  monInfoSpace()->addGroupRetrieveListener(itemGroupListener_);
75  }
76 }
77 
78 
79 //______________________________________________________________________________
81 {
82 
83 }
84 
85 
87 // implementation of public member functions
89 
90 //______________________________________________________________________________
92 {
93  updateParams();
94 
95  *out<<"<html>"<<endl;
96  htmlHead(in,out,sourceId_);
97  *out<<body()<<endl;
98  htmlHeadline(in,out);
99  *out<<"<table cellpadding=\"25\"><tr valign=\"top\"><td>"<<endl;
100  htmlTable(in,out,"Standard Parameters",standardParams_);
101  *out<<"</td><td>"<<endl;
102  htmlTable(in,out,"Monitored Parameters",monitorParams_);
103  *out<<"</td></tr></table>"<<endl;
104  *out<<body()<<endl<<"</html>"<<endl;
105  return;
106 }
107 
108 
109 //______________________________________________________________________________
111 {
112  updateParams();
113 
114  *out<<"<html>"<<endl;
115  htmlHead(in,out,sourceId_+" [DEBUG]");
116  *out<<body()<<endl;
117  htmlHeadline(in,out);
118  *out<<"<table cellpadding=\"25\"><tr valign=\"top\"><td>"<<endl;
119  htmlTable(in,out,"Debug Parameters",debugParams_);
120  *out<<"</td></tr></table>"<<endl;
121  *out<<body()<<endl<<"</html>"<<endl;
122  return;
123 }
124 
125 
126 //______________________________________________________________________________
128 {
129  css_.css(in,out);
130 }
131 
132 
133 //______________________________________________________________________________
135 {
136  if (parametersExported_) {
137  LOG4CPLUS_ERROR(log_,"Failed to add standard parameter '"<<name<<"'.");
138  return;
139  }
140  standardParams_.push_back(make_pair(name,param));
141 }
142 
143 
144 //______________________________________________________________________________
146 {
147  if (parametersExported_) {
148  LOG4CPLUS_ERROR(log_,"Failed to add monitor parameter '"<<name<<"'.");
149  return;
150  }
151  monitorParams_.push_back(make_pair(name,param));
152 }
153 
154 
155 //______________________________________________________________________________
157 {
158  if (parametersExported_) {
159  LOG4CPLUS_ERROR(log_,"Failed to add debug parameter '"<<name<<"'.");
160  return;
161  }
162  debugParams_.push_back(make_pair(name,param));
163 }
164 
165 
166 //______________________________________________________________________________
168 {
170  LOG4CPLUS_ERROR(log_,"can't add standard counter '"<<name
171  <<"' to WebGUI of "<<sourceId_);
172  }
173  standardCounters_.push_back(make_pair(name,counter));
174 }
175 
176 
177 //______________________________________________________________________________
179 {
181  LOG4CPLUS_ERROR(log_,"can't add monitor counter '"<<name
182  <<"' to WebGUI of "<<sourceId_);
183  }
184  monitorCounters_.push_back(make_pair(name,counter));
185 }
186 
187 
188 //______________________________________________________________________________
190 {
192  LOG4CPLUS_ERROR(log_,"can't add debug counter '"<<name
193  <<"' to WebGUI of "<<sourceId_);
194  }
195  debugCounters_.push_back(make_pair(name,counter));
196 }
197 
198 
199 //______________________________________________________________________________
201 {
202  if (parametersExported_) return;
203 
205 
209 
211 
212  parametersExported_=true;
213 }
214 
215 
216 //______________________________________________________________________________
218 {
219  // standard counters
220  for (unsigned int i=0;i<standardCounters_.size();i++) {
221  Counter_t* counter=standardCounters_[i].second;
222  *counter=0;
223  }
224  // monitor counters
225  for (unsigned int i=0;i<monitorCounters_.size();i++) {
226  Counter_t* counter=monitorCounters_[i].second;
227  *counter=0;
228  }
229  // debug counters
230  for (unsigned int i=0;i<debugCounters_.size();i++) {
231  Counter_t* counter=debugCounters_[i].second;
232  *counter=0;
233  }
234 }
235 
236 
237 //______________________________________________________________________________
238 void WebGUI::addItemChangedListener(CString_t& name,xdata::ActionListener* l)
239 {
240  if (!parametersExported_) {
241  LOG4CPLUS_ERROR(log_,"Can't add ItemChangedListener for parameter '"<<name
242  <<"' before WebGUI::exportParameters() is called.");
243  return;
244  }
245 
246  try {
247  appInfoSpace()->addItemChangedListener(name,l);
248  }
249  catch (xcept::Exception) {
250  LOG4CPLUS_ERROR(log_,"failed to add ItemChangedListener to "
251  <<"application infospace for parameter '"<<name<<"'.");
252  }
253 
254  if (isMonitorParam(name)) {
255  try {
256  monInfoSpace()->addItemChangedListener(name,l);
257  }
258  catch (xcept::Exception) {
259  LOG4CPLUS_ERROR(log_,"failed to add ItemChangedListener to "
260  <<"monitor infospace for parameter '"<<name<<"'.");
261  }
262  }
263 
264 }
265 
266 
268 // implementation of private member functions
270 
271 //______________________________________________________________________________
273  xdata::InfoSpace* infoSpace)
274 {
275  for (unsigned int i=0;i<params.size();i++) {
276  string name =params[i].first;
277  Param_t* value=params[i].second;
278  try {
279  infoSpace->fireItemAvailable(name,value);
280  }
281  catch (xcept::Exception &e) {
282  LOG4CPLUS_ERROR(log_,"Can't add parameter '"<<name<<"' to info space '"
283  <<infoSpace->name()<<"': "
284  <<xcept::stdformat_exception_history(e));
285  }
286  }
287 }
288 
289 
290 //______________________________________________________________________________
292 {
293  if (countersAddedToParams_) return;
294 
295  // standard counters
296  for (unsigned int i=0;i<standardCounters_.size();i++) {
297  standardParams_.push_back(make_pair(standardCounters_[i].first,
299  }
300  // monitor counters
301  for (unsigned int i=0;i<monitorCounters_.size();i++) {
302  monitorParams_.push_back(make_pair(monitorCounters_[i].first,
304  }
305  // debug counters
306  for (unsigned int i=0;i<debugCounters_.size();i++) {
307  debugParams_.push_back(make_pair(debugCounters_[i].first,
309  }
311 }
312 
313 
314 //______________________________________________________________________________
316 {
317  ParamVec_t::const_iterator it;
318  for (it=monitorParams_.begin();it!=monitorParams_.end();++it)
319  if (it->first==name) return true;
320  return false;
321 }
322 
323 
324 //______________________________________________________________________________
326 {
327  if (0!=itemGroupListener_) {
328  std::list<std::string> emptyList;
329  appInfoSpace()->fireItemGroupRetrieve(emptyList,itemGroupListener_);
330  }
331 }
332 
333 
334 //______________________________________________________________________________
336  CString_t& title,const ParamVec_t& params)
337 {
338  *out<<table().set("frame","void").set("rules","rows")
339  .set("class","modules").set("width","300")<<endl
340  <<tr()<<th(title).set("colspan","2")<<tr()<<endl
341  <<tr()
342  <<th("Parameter").set("align","left")
343  <<th("Value").set("align","right")
344  <<tr()
345  <<endl;
346 
347  for (unsigned int i=0;i<params.size();i++) {
348  string valueAsString;
349  try {
350  valueAsString = params[i].second->toString();
351  }
352  catch (xcept::Exception& e) {
353  valueAsString = e.what();
354  }
355  *out<<tr()
356  <<td(params[i].first).set("align","left")
357  <<td(valueAsString).set("align","right")
358  <<tr()<<endl;
359  }
360  *out<<table()<<endl;
361 }
362 
363 
364 //______________________________________________________________________________
366 {
367  *out<<head()<<endl<<cgicc::link().set("type","text/css")
368  .set("rel","stylesheet")
369  .set("href",urn_+"/styles.css")
370  <<endl<<title(pageTitle.c_str())<<endl<<head()<<endl;
371 }
372 
373 
374 //______________________________________________________________________________
376 {
377  string stateName=fsm_->stateName()->toString();
378 
379  *out<<table().set("border","0").set("width","100%")<<endl
380  <<tr()<<td().set("align","left")<<endl
381  <<img().set("align","middle").set("src",largeAppIcon_)
382  .set("alt","main") .set("width","64")
383  .set("height","64") .set("border","")
384  <<endl
385  <<b()<<sourceId_<<" "<<stateName<<b()<<endl
386  <<td()<<endl
387  <<td().set("width","32")<<endl
388  <<a().set("href","/urn:xdaq-application:lid=3")
389  <<img().set("align","middle").set("src",hyperDAQIcon_)
390  .set("alt","HyperDAQ").set("width","32")
391  .set("height","32") .set("border","")
392  <<a()
393  <<td()<<endl
394  <<td().set("width","32")<<td()
395  <<td().set("width","32")
396  <<a().set("href",urn_+"/defaultWebPage")
397  <<img().set("align","middle").set("src",smallAppIcon_)
398  .set("alt","Debug") .set("width","32")
399  .set("height","32") .set("border","")
400  <<a()
401  <<td()<<endl
402  <<td().set("width","32")<<td()
403  <<td().set("width","32")
404  <<a().set("href",urn_+"/debugWebPage")
405  <<img().set("align","middle").set("src",smallDbgIcon_)
406  .set("alt","Debug") .set("width","32")
407  .set("height","32") .set("border","")
408  <<a()
409  <<td()<<endl
410  <<td().set("width","32")<<td()
411  <<td().set("width","32")
412  <<a().set("href",urn_+"/customWebPage")
413  <<img().set("align","middle").set("src",smallCtmIcon_)
414  .set("alt","Debug") .set("width","32")
415  .set("height","32") .set("border","")
416  <<a()
417  <<td()<<tr()<<table()<<endl;
418  *out<<hr()<<endl;
419 }
xdata::UnsignedInteger32 Counter_t
Definition: WebGUI.h:34
list table
Definition: asciidump.py:386
void addDebugCounter(CString_t &name, Counter_t *counter)
Definition: WebGUI.cc:189
int i
Definition: DBlmapReader.cc:9
StateMachine * fsm_
Definition: WebGUI.h:102
void resetCounters()
Definition: WebGUI.cc:217
void htmlTable(Input_t *in, Output_t *out, CString_t &title, const ParamVec_t &params)
Definition: WebGUI.cc:335
void updateParams()
Definition: WebGUI.cc:325
bool parametersExported_
Definition: WebGUI.h:121
CounterVec_t standardCounters_
Definition: WebGUI.h:117
void addStandardParam(CString_t &name, Param_t *param)
Definition: WebGUI.cc:134
void exportParameters()
Definition: WebGUI.cc:200
static PFTauRenderPlugin instance
void addCountersToParams()
Definition: WebGUI.cc:291
const std::string CString_t
Definition: WebGUI.h:40
xdata::Serializable Param_t
Definition: WebGUI.h:33
xgi::exception::Exception XgiException_t
Definition: WebGUI.h:41
void htmlHead(Input_t *in, Output_t *out, CString_t &pageTitle)
Definition: WebGUI.cc:365
std::string smallAppIcon_
Definition: WebGUI.h:125
CounterVec_t monitorCounters_
Definition: WebGUI.h:118
bool countersAddedToParams_
Definition: WebGUI.h:122
std::vector< std::pair< std::string, Param_t * > > ParamVec_t
Definition: WebGUI.h:35
xgi::Input Input_t
Definition: WebGUI.h:38
void addMonitorParam(CString_t &name, Param_t *param)
Definition: WebGUI.cc:145
void addItemChangedListener(CString_t &name, xdata::ActionListener *l)
Definition: WebGUI.cc:238
ParamVec_t standardParams_
Definition: WebGUI.h:114
xgi::Output Output_t
Definition: WebGUI.h:39
U second(std::pair< T, U > const &p)
std::string link(std::string &nm, std::string &ns)
Definition: hierarchy.cc:24
void addDebugParam(CString_t &name, Param_t *param)
Definition: WebGUI.cc:156
xdata::InfoSpace * appInfoSpace_
Definition: WebGUI.h:109
std::string sourceId_
Definition: WebGUI.h:106
xdaq::Application * app_
Definition: WebGUI.h:101
xdata::InfoSpace * monInfoSpace_
Definition: WebGUI.h:110
bool first
Definition: L1TdeRCT.cc:94
ParamVec_t monitorParams_
Definition: WebGUI.h:115
xdata::InfoSpace * appInfoSpace()
Definition: WebGUI.h:71
tuple out
Definition: dbtoconf.py:99
xdata::String * stateName()
Definition: StateMachine.h:69
xdata::InfoSpace * monInfoSpace()
Definition: WebGUI.h:72
virtual ~WebGUI()
Definition: WebGUI.cc:80
double b
Definition: hdecay.h:120
void htmlHeadline(Input_t *in, Output_t *out)
Definition: WebGUI.cc:375
Logger log_
Definition: WebGUI.h:104
void debugWebPage(Input_t *in, Output_t *out)
Definition: WebGUI.cc:110
void addParamsToInfoSpace(const ParamVec_t &params, xdata::InfoSpace *infoSpace)
Definition: WebGUI.cc:272
double a
Definition: hdecay.h:121
void addStandardCounter(CString_t &name, Counter_t *counter)
Definition: WebGUI.cc:167
std::string urn_
Definition: WebGUI.h:107
void addMonitorCounter(CString_t &name, Counter_t *counter)
Definition: WebGUI.cc:178
void defaultWebPage(Input_t *in, Output_t *out)
Definition: WebGUI.cc:91
std::string largeAppIcon_
Definition: WebGUI.h:124
bool isMonitorParam(CString_t &name)
Definition: WebGUI.cc:315
std::string smallCtmIcon_
Definition: WebGUI.h:127
CounterVec_t debugCounters_
Definition: WebGUI.h:119
std::string hyperDAQIcon_
Definition: WebGUI.h:128
ParamVec_t debugParams_
Definition: WebGUI.h:116
xdata::ActionListener * itemGroupListener_
Definition: WebGUI.h:112
std::string smallDbgIcon_
Definition: WebGUI.h:126
void css(Input_t *in, Output_t *out)
Definition: WebGUI.cc:127