Logo ROOT  
Reference Guide
alice_esd_html_summary.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve
3/// Html table and event summary for alice_esd.C
4///
5/// \macro_code
6///
7/// \author Bertrand Bellenot
8
9class HtmlObjTable : public TObject
10{
11public: // make them public for shorter code
12
13 TString fName;
14 Int_t fNValues; // number of values
15 Int_t fNFields; // number of fields
16 TArrayF *fValues;
17 TString *fLabels;
18 Bool_t fExpand;
19
20 TString fHtml; // HTML output code
21
22 void Build();
23 void BuildTitle();
24 void BuildLabels();
25 void BuildTable();
26
27public:
28 HtmlObjTable(const char *name, Int_t nfields, Int_t nvals, Bool_t exp=kTRUE);
29 virtual ~HtmlObjTable();
30
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; }
34
35 ClassDef(HtmlObjTable, 0);
36};
37
38//==============================================================================
39
40class HtmlSummary
41{
42public: // make them public for shorter code
43 Int_t fNTables;
44 TOrdCollection *fObjTables; // ->array of object tables
45 TString fHtml; // output HTML string
46 TString fTitle; // page title
47 TString fHeader; // HTML header
48 TString fFooter; // HTML footer
49
50 void MakeHeader();
51 void MakeFooter();
52
53public:
54 HtmlSummary(const char *title);
55 virtual ~HtmlSummary();
56
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); }
60 void Build();
61 void Clear(Option_t *option="");
62 void Reset(Option_t *option="");
63 TString Html() const { return fHtml; }
64
65 ClassDef(HtmlSummary, 0);
66};
67
68//==============================================================================
69
70HtmlSummary *fgHtmlSummary = 0;
71TGHtml *fgHtml = 0;
72
73//==============================================================================
74
75//______________________________________________________________________________
76HtmlObjTable::HtmlObjTable(const char *name, Int_t nfields, Int_t nvals, Bool_t exp) :
77 fName(name), fNValues(nvals), fNFields(nfields), fExpand(exp)
78{
79 // Constructor.
80
81 fValues = new TArrayF[fNFields];
82 for (int i=0;i<fNFields;i++)
83 fValues[i].Set(nvals);
84 fLabels = new TString[fNFields];
85}
86
87//______________________________________________________________________________
88HtmlObjTable::~HtmlObjTable()
89{
90 // Destructor.
91
92 delete [] fValues;
93 delete [] fLabels;
94}
95
96//______________________________________________________________________________
97void HtmlObjTable::Build()
98{
99 // Build HTML code.
100
101 fHtml = "<table width=100% border=1 cellspacing=0 cellpadding=0 bgcolor=f0f0f0> ",
102
103 BuildTitle();
104 if (fExpand && (fNFields > 0) && (fNValues > 0)) {
105 BuildLabels();
106 BuildTable();
107 }
108
109 fHtml += "</table>";
110}
111
112//______________________________________________________________________________
113void HtmlObjTable::BuildTitle()
114{
115 // Build table title.
116
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>";
122 fHtml += fName;
123 fHtml += "</i></b></font></td>";
124 fHtml += "<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>";
129 fHtml += "</table>";
130 fHtml += "</td></tr>";
131}
132
133//______________________________________________________________________________
134void HtmlObjTable::BuildLabels()
135{
136 // Build table labels.
137
138 Int_t i;
139 fHtml += "<tr bgcolor=c0c0ff>";
140 fHtml += "<th> </th>"; // for the check boxes
141 for (i=0;i<fNFields;i++) {
142 fHtml += "<th> ";
143 fHtml += fLabels[i];
144 fHtml += " </th>"; // for the check boxes
145 }
146 fHtml += "</tr>";
147}
148
149//______________________________________________________________________________
150void HtmlObjTable::BuildTable()
151{
152 // Build part of table with values.
153
154 for (int i = 0; i < fNValues; i++) {
155 if (i%2)
156 fHtml += "<tr bgcolor=e0e0ff>";
157 else
158 fHtml += "<tr bgcolor=ffffff>";
159
160 TString name = fName;
161 name.ReplaceAll(" ", "_");
162 // checkboxes
163 fHtml += "<td bgcolor=d0d0ff align=\"center\">";
164 fHtml += "<input type=\"checkbox\" name=\"";
165 fHtml += name;
166 fHtml += Form("[%d]\">",i);
167 fHtml += "</td>";
168
169 for (int j = 0; j < fNFields; j++) {
170 fHtml += "<td width=";
171 fHtml += Form("%d%%", 100/fNFields);
172 fHtml += " align=\"center\"";
173 fHtml += ">";
174 fHtml += Form("%1.4f", fValues[j][i]);
175 fHtml += "</td>";
176 }
177 fHtml += "</tr> ";
178 }
179}
180
181//______________________________________________________________________________
182HtmlSummary::HtmlSummary(const char *title) : fNTables(0), fTitle(title)
183{
184 // Constructor.
185
186 fObjTables = new TOrdCollection();
187}
188
189//______________________________________________________________________________
190HtmlSummary::~HtmlSummary()
191{
192 // Destructor.
193
194 Reset();
195}
196
197//______________________________________________________________________________
198HtmlObjTable *HtmlSummary::AddTable(const char *name, Int_t nfields, Int_t nvals,
199 Bool_t exp, Option_t *option)
200{
201 // Add a new table in our list of tables.
202
203 TString opt = option;
204 opt.ToLower();
205 HtmlObjTable *table = new HtmlObjTable(name, nfields, nvals, exp);
206 fNTables++;
207 if (opt.Contains("first"))
208 fObjTables->AddFirst(table);
209 else
210 fObjTables->Add(table);
211 return table;
212}
213
214//______________________________________________________________________________
215void HtmlSummary::Clear(Option_t *option)
216{
217 // Clear the table list.
218
219 if (option && option[0] == 'D')
220 fObjTables->Delete(option);
221 else
222 fObjTables->Clear(option);
223 fNTables = 0;
224}
225
226//______________________________________________________________________________
227void HtmlSummary::Reset(Option_t *)
228{
229 // Reset (delete) the table list;
230
231 delete fObjTables; fObjTables = 0;
232 fNTables = 0;
233}
234
235//______________________________________________________________________________
236void HtmlSummary::Build()
237{
238 // Build the summary.
239
240 MakeHeader();
241 for (int i=0;i<fNTables;i++) {
242 GetTable(i)->Build();
243 fHtml += GetTable(i)->Html();
244 }
245 MakeFooter();
246}
247
248//______________________________________________________________________________
249void HtmlSummary::MakeHeader()
250{
251 // Make HTML header.
252
253 fHeader = "<html><head><title>";
254 fHeader += fTitle;
255 fHeader += "</title></head><body>";
256 fHeader += "<center><h2><font color=#2222ee><i>";
257 fHeader += fTitle;
258 fHeader += "</i></font></h2></center>";
259 fHtml = fHeader;
260}
261
262//______________________________________________________________________________
263void HtmlSummary::MakeFooter()
264{
265 // Make HTML footer.
266
267 fFooter = "<br><p><br><center><strong><font size=2 color=#2222ee>";
268 fFooter += "Example of using Html widget to display tabular data";
269 fFooter += "<br>";
270 fFooter += "(c) 2007-2010 Bertrand Bellenot";
271 fFooter += "</font></strong></center></body></html>";
272 fHtml += fFooter;
273}
274
275//==============================================================================
276
277//______________________________________________________________________________
278void update_html_summary()
279{
280 // Update summary of current event.
281
284 Int_t k;
285 TEveElement *el;
286 HtmlObjTable *table;
288 if (mgr) {
289 fgHtmlSummary->Clear("D");
290 for (i=mgr->BeginChildren(); i!=mgr->EndChildren(); ++i) {
291 el = ((TEveElement*)(*i));
292 if (el->IsA() == TEvePointSet::Class()) {
294 TString ename = ps->GetElementName();
295 TString etitle = ps->GetElementTitle();
296 if (ename.First('\'') != kNPOS)
297 ename.Remove(ename.First('\''));
298 etitle.Remove(0, 2);
299 Int_t nel = atoi(etitle.Data());
300 table = fgHtmlSummary->AddTable(ename, 0, nel);
301 }
302 else if (el->IsA() == TEveTrackList::Class()) {
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");
314 k=0;
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);
326 ++k;
327 }
328 }
329 }
330 fgHtmlSummary->Build();
331 fgHtml->Clear();
332 fgHtml->ParseText((char*)fgHtmlSummary->Html().Data());
333 fgHtml->Layout();
334 }
335}
void Class()
Definition: Class.C:29
const Ssiz_t kNPOS
Definition: RtypesCore.h:113
int Int_t
Definition: RtypesCore.h:43
bool Bool_t
Definition: RtypesCore.h:61
float Float_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:89
const char Option_t
Definition: RtypesCore.h:64
#define ClassDef(name, id)
Definition: Rtypes.h:322
R__EXTERN TEveManager * gEve
Definition: TEveManager.h:243
char name[80]
Definition: TGX11.cxx:109
double exp(double)
char * Form(const char *fmt,...)
Array of floats (32 bits per element).
Definition: TArrayF.h:27
void SetAt(Double_t v, Int_t i)
Definition: TArrayF.h:51
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition: TEveElement.h:34
List_i EndChildren()
Definition: TEveElement.h:165
List_i BeginChildren()
Definition: TEveElement.h:164
List_t::iterator List_i
Definition: TEveElement.h:70
Base class for event management and navigation.
TEveEventManager * GetCurrentEvent() const
Definition: TEveManager.h:149
TEvePointSet is a render-element holding a collection of 3D points with optional per-point TRef and a...
Definition: TEvePointSet.h:36
A list of tracks supporting change of common attributes and selection based on track parameters.
Definition: TEveTrack.h:140
Visual representation of a track.
Definition: TEveTrack.h:33
Definition: TGHtml.h:872
virtual void Clear(Option_t *="")
Erase all HTML from this widget and clear the screen.
Definition: TGHtml.cxx:299
int ParseText(char *text, const char *index=0)
Appends (or insert at the specified position) the given HTML text to the end of any HTML text that ma...
Definition: TGHtml.cxx:314
virtual void Layout()
layout view
Definition: TGView.cxx:344
Mother of all ROOT objects.
Definition: TObject.h:37
Ordered collection.
void Clear(Option_t *option="")
Remove all objects from the collection.
TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
void AddFirst(TObject *obj)
Insert object at beginning of collection.
void Delete(Option_t *option="")
Remove all objects from the collection AND delete all heap based objects.
virtual void Add(TObject *obj)
Basic string class.
Definition: TString.h:131
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1125
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition: TString.cxx:499
const char * Data() const
Definition: TString.h:364
TString & Remove(Ssiz_t pos)
Definition: TString.h:668
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:619
TPaveText * pt
static constexpr double ps
void tracks()
Definition: tracks.C:49