CMS 3D CMS Logo

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