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