9 class HtmlObjTable :
public TObject
28 HtmlObjTable(
const char *name, Int_t nfields, Int_t nvals, Bool_t exp=kTRUE);
29 virtual ~HtmlObjTable();
31 void SetLabel(Int_t col,
const char *label) { fLabels[col] = label; }
32 void SetValue(Int_t col, Int_t row, Float_t val) { fValues[col].SetAt(val, row); }
33 TString Html()
const {
return fHtml; }
35 ClassDef(HtmlObjTable, 0);
44 TOrdCollection *fObjTables;
54 HtmlSummary(
const char *title);
55 virtual ~HtmlSummary();
57 HtmlObjTable *AddTable(
const char *name, Int_t nfields, Int_t nvals,
58 Bool_t exp=kTRUE, Option_t *opt=
"");
59 HtmlObjTable *GetTable(Int_t at)
const {
return (HtmlObjTable *)fObjTables->At(at); }
61 void Clear(Option_t *option=
"");
62 void Reset(Option_t *option=
"");
63 TString Html()
const {
return fHtml; }
65 ClassDef(HtmlSummary, 0);
70 HtmlSummary *fgHtmlSummary = 0;
76 HtmlObjTable::HtmlObjTable(
const char *name, Int_t nfields, Int_t nvals, Bool_t exp) :
77 fName(name), fNValues(nvals), fNFields(nfields), fExpand(exp)
81 fValues =
new TArrayF[fNFields];
82 for (
int i=0;i<fNFields;i++)
83 fValues[i].Set(nvals);
84 fLabels =
new TString[fNFields];
88 HtmlObjTable::~HtmlObjTable()
97 void HtmlObjTable::Build()
101 fHtml =
"<table width=100% border=1 cellspacing=0 cellpadding=0 bgcolor=f0f0f0> ",
104 if (fExpand && (fNFields > 0) && (fNValues > 0)) {
113 void HtmlObjTable::BuildTitle()
117 fHtml +=
"<tr><td colspan=";
118 fHtml += Form(
"%d>", fNFields+1);
119 fHtml +=
"<table width=100% border=0 cellspacing=2 cellpadding=0 bgcolor=6e6ea0>";
120 fHtml +=
"<tr><td align=left>";
121 fHtml +=
"<font face=Verdana size=3 color=ffffff><b><i>";
123 fHtml +=
"</i></b></font></td>";
125 fHtml +=
"<td align=right> ";
126 fHtml +=
"<font face=Verdana size=3 color=ffffff><b><i>";
127 fHtml += Form(
"Size = %d", fNValues);
128 fHtml +=
"</i></b></font></td></tr>";
130 fHtml +=
"</td></tr>";
134 void HtmlObjTable::BuildLabels()
139 fHtml +=
"<tr bgcolor=c0c0ff>";
140 fHtml +=
"<th> </th>";
141 for (i=0;i<fNFields;i++) {
150 void HtmlObjTable::BuildTable()
154 for (
int i = 0; i < fNValues; i++) {
156 fHtml +=
"<tr bgcolor=e0e0ff>";
158 fHtml +=
"<tr bgcolor=ffffff>";
160 TString name = fName;
161 name.ReplaceAll(
" ",
"_");
163 fHtml +=
"<td bgcolor=d0d0ff align=\"center\">";
164 fHtml +=
"<input type=\"checkbox\" name=\"";
166 fHtml += Form(
"[%d]\">",i);
169 for (
int j = 0; j < fNFields; j++) {
170 fHtml +=
"<td width=";
171 fHtml += Form(
"%d%%", 100/fNFields);
172 fHtml +=
" align=\"center\"";
174 fHtml += Form(
"%1.4f", fValues[j][i]);
182 HtmlSummary::HtmlSummary(
const char *title) : fNTables(0), fTitle(title)
186 fObjTables =
new TOrdCollection();
190 HtmlSummary::~HtmlSummary()
198 HtmlObjTable *HtmlSummary::AddTable(
const char *name, Int_t nfields, Int_t nvals,
199 Bool_t exp, Option_t *option)
203 TString opt = option;
205 HtmlObjTable *table =
new HtmlObjTable(name, nfields, nvals, exp);
207 if (opt.Contains(
"first"))
208 fObjTables->AddFirst(table);
210 fObjTables->Add(table);
215 void HtmlSummary::Clear(Option_t *option)
219 if (option && option[0] ==
'D')
220 fObjTables->Delete(option);
222 fObjTables->Clear(option);
227 void HtmlSummary::Reset(Option_t *)
231 delete fObjTables; fObjTables = 0;
236 void HtmlSummary::Build()
241 for (
int i=0;i<fNTables;i++) {
242 GetTable(i)->Build();
243 fHtml += GetTable(i)->Html();
249 void HtmlSummary::MakeHeader()
253 fHeader =
"<html><head><title>";
255 fHeader +=
"</title></head><body>";
256 fHeader +=
"<center><h2><font color=#2222ee><i>";
258 fHeader +=
"</i></font></h2></center>";
263 void HtmlSummary::MakeFooter()
267 fFooter =
"<br><p><br><center><strong><font size=2 color=#2222ee>";
268 fFooter +=
"Example of using Html widget to display tabular data";
270 fFooter +=
"(c) 2007-2010 Bertrand Bellenot";
271 fFooter +=
"</font></strong></center></body></html>";
278 void update_html_summary()
282 TEveElement::List_i i;
283 TEveElement::List_i j;
287 TEveEventManager *mgr = gEve ? gEve->GetCurrentEvent() : 0;
289 fgHtmlSummary->Clear(
"D");
290 for (i=mgr->BeginChildren(); i!=mgr->EndChildren(); ++i) {
291 el = ((TEveElement*)(*i));
292 if (el->IsA() == TEvePointSet::Class()) {
293 TEvePointSet *ps = (TEvePointSet *)el;
294 TString ename = ps->GetElementName();
295 TString etitle = ps->GetElementTitle();
296 if (ename.First(
'\'') != kNPOS)
297 ename.Remove(ename.First(
'\''));
299 Int_t nel = atoi(etitle.Data());
300 table = fgHtmlSummary->AddTable(ename, 0, nel);
302 else if (el->IsA() == TEveTrackList::Class()) {
303 TEveTrackList *tracks = (TEveTrackList *)el;
304 TString ename = tracks->GetElementName();
305 if (ename.First(
'\'') != kNPOS)
306 ename.Remove(ename.First(
'\''));
307 table = fgHtmlSummary->AddTable(ename.Data(), 5,
308 tracks->NumChildren(), kTRUE,
"first");
309 table->SetLabel(0,
"Momentum");
310 table->SetLabel(1,
"P_t");
311 table->SetLabel(2,
"Phi");
312 table->SetLabel(3,
"Theta");
313 table->SetLabel(4,
"Eta");
315 for (j=tracks->BeginChildren(); j!=tracks->EndChildren(); ++j) {
316 Float_t p = ((TEveTrack*)(*j))->GetMomentum().Mag();
317 table->SetValue(0, k, p);
318 Float_t pt = ((TEveTrack*)(*j))->GetMomentum().Perp();
319 table->SetValue(1, k, pt);
320 Float_t phi = ((TEveTrack*)(*j))->GetMomentum().Phi();
321 table->SetValue(2, k, phi);
322 Float_t theta = ((TEveTrack*)(*j))->GetMomentum().Theta();
323 table->SetValue(3, k, theta);
324 Float_t eta = ((TEveTrack*)(*j))->GetMomentum().Eta();
325 table->SetValue(4, k, eta);
330 fgHtmlSummary->Build();
332 fgHtml->ParseText((
char*)fgHtmlSummary->Html().Data());