ROOT logo
// @(#)root/eve:$Id: alice_esd_html_summary.C 27536 2009-02-19 20:19:57Z matevz $

// Html table and event summary for alice_esd.C

//==============================================================================

class HtmlObjTable : public TObject
{
public:                     // make them public for shorter code

   TString   fName;
   Int_t     fNValues;      // number of values
   Int_t     fNFields;      // number of fields
   TArrayF  *fValues;
   TString  *fLabels;
   Bool_t    fExpand;

   TString   fHtml;         // HTML output code

   void Build();
   void BuildTitle();
   void BuildLabels();
   void BuildTable();

public:
   HtmlObjTable(const char *name, Int_t nfields, Int_t nvals, Bool_t exp=kTRUE);
   virtual ~HtmlObjTable();

   void     SetLabel(Int_t col, const char *label) { fLabels[col] = label; }
   void     SetValue(Int_t col, Int_t row, Float_t val) { fValues[col].SetAt(val, row); }
   TString  Html() const { return fHtml; }

   ClassDef(HtmlObjTable, 0);
};

//==============================================================================

class HtmlSummary
{
public:                           // make them public for shorter code
   Int_t           fNTables;
   TOrdCollection *fObjTables;    // ->array of object tables
   TString         fHtml;         // output HTML string
   TString         fTitle;        // page title
   TString         fHeader;       // HTML header
   TString         fFooter;       // HTML footer

   void     MakeHeader();
   void     MakeFooter();

public:
   HtmlSummary(const char *title);
   virtual ~HtmlSummary();

   HtmlObjTable  *AddTable(const char *name, Int_t nfields, Int_t nvals, 
                           Bool_t exp=kTRUE, Option_t *opt="");
   HtmlObjTable  *GetTable(Int_t at) const { return (HtmlObjTable *)fObjTables->At(at); }
   void           Build();
   void           Clear(Option_t *option="");
   void           Reset(Option_t *option="");
   TString        Html() const { return fHtml; }

   ClassDef(HtmlSummary, 0);
};

//==============================================================================

HtmlSummary *fgHtmlSummary = 0;
TGHtml      *fgHtml        = 0;

//==============================================================================

//______________________________________________________________________________
HtmlObjTable::HtmlObjTable(const char *name, Int_t nfields, Int_t nvals, Bool_t exp) : 
   fName(name), fNValues(nvals), fNFields(nfields), fExpand(exp)
{
   // Constructor.

   fValues = new TArrayF[fNFields];
   for (int i=0;i<fNFields;i++)
      fValues[i].Set(nvals);
   fLabels = new TString[fNFields];
}

//______________________________________________________________________________
HtmlObjTable::~HtmlObjTable()
{
   // Destructor.

   delete [] fValues;
   delete [] fLabels;
}

//______________________________________________________________________________
void HtmlObjTable::Build()
{
   // Build HTML code.

   fHtml = "<table width=100% border=1 cellspacing=0 cellpadding=0 bgcolor=f0f0f0> ",

   BuildTitle();
   if (fExpand && (fNFields > 0) && (fNValues > 0)) {
      BuildLabels();
      BuildTable();
   }

   fHtml += "</table>";
}

//______________________________________________________________________________
void HtmlObjTable::BuildTitle()
{
   // Build table title.
   
   fHtml += "<tr><td colspan=";
   fHtml += Form("%d>", fNFields+1);
   fHtml += "<table width=100% border=0 cellspacing=2 cellpadding=0 bgcolor=6e6ea0>";
   fHtml += "<tr><td align=left>";
   fHtml += "<font face=Verdana size=3 color=ffffff><b><i>";
   fHtml += fName;
   fHtml += "</i></b></font></td>";
   fHtml += "<td>";
   fHtml += "<td align=right> ";
   fHtml += "<font face=Verdana size=3 color=ffffff><b><i>";
   fHtml += Form("Size = %d", fNValues);
   fHtml += "</i></b></font></td></tr>";
   fHtml += "</table>";
   fHtml += "</td></tr>";
}

//______________________________________________________________________________
void HtmlObjTable::BuildLabels()
{
   // Build table labels.

   Int_t i;
   fHtml += "<tr bgcolor=c0c0ff>";
   fHtml += "<th> </th>"; // for the check boxes
   for (i=0;i<fNFields;i++) {
      fHtml += "<th> ";
      fHtml += fLabels[i];
      fHtml += " </th>"; // for the check boxes
   }
   fHtml += "</tr>";
}

//______________________________________________________________________________
void HtmlObjTable::BuildTable()
{
   // Build part of table with values.

   for (int i = 0; i < fNValues; i++) {
      if (i%2)
         fHtml += "<tr bgcolor=e0e0ff>";
      else
         fHtml += "<tr bgcolor=ffffff>";
      
      TString name = fName;
      name.ReplaceAll(" ", "_");
      // checkboxes
      fHtml += "<td bgcolor=d0d0ff align=\"center\">";
      fHtml += "<input type=\"checkbox\" name=\"";
      fHtml += name;
      fHtml += Form("[%d]\">",i);
      fHtml += "</td>";

      for (int j = 0; j < fNFields; j++) {
         fHtml += "<td width=";
         fHtml += Form("%d%%", 100/fNFields);
         fHtml += " align=\"center\"";
         fHtml += ">";
         fHtml += Form("%1.4f", fValues[j][i]);
         fHtml += "</td>";
      }
      fHtml += "</tr> ";
   }
}

//______________________________________________________________________________
HtmlSummary::HtmlSummary(const char *title) : fNTables(0), fTitle(title)
{
   // Constructor.

   fObjTables = new TOrdCollection();
}

//______________________________________________________________________________
HtmlSummary::~HtmlSummary()
{
   // Destructor.

   Reset();
}

//______________________________________________________________________________
HtmlObjTable *HtmlSummary::AddTable(const char *name, Int_t nfields, Int_t nvals,
                                    Bool_t exp, Option_t *option)
{
   // Add a new table in our list of tables.

   TString opt = option;
   opt.ToLower();
   HtmlObjTable *table = new HtmlObjTable(name, nfields, nvals, exp);
   fNTables++;
   if (opt.Contains("first"))
      fObjTables->AddFirst(table);
   else
      fObjTables->Add(table);
   return table;
}

//______________________________________________________________________________
void HtmlSummary::Clear(Option_t *option)
{
   // Clear the table list.

   if (option && option[0] == 'D')
      fObjTables->Delete(option);
   else
      fObjTables->Clear(option);
   fNTables = 0;
}

//______________________________________________________________________________
void HtmlSummary::Reset(Option_t *)
{
   // Reset (delete) the table list;

   delete fObjTables; fObjTables = 0;
   fNTables = 0;
}

//______________________________________________________________________________
void HtmlSummary::Build()
{
   // Build the summary.

   MakeHeader();
   for (int i=0;i<fNTables;i++) {
      GetTable(i)->Build();
      fHtml += GetTable(i)->Html();
   }
   MakeFooter();
}

//______________________________________________________________________________
void HtmlSummary::MakeHeader()
{
   // Make HTML header.

   fHeader  = "<html><head><title>";
   fHeader += fTitle;
   fHeader += "</title></head><body>";
   fHeader += "<center><h2><font color=#2222ee><i>";
   fHeader += fTitle;
   fHeader += "</i></font></h2></center>";
   fHtml    = fHeader;
}

//______________________________________________________________________________
void HtmlSummary::MakeFooter()
{
   // Make HTML footer.

   fFooter  = "<br><p><br><center><strong><font size=2 color=#2222ee>";
   fFooter += "Example of using Html widget to display tabular data";
   fFooter += "<br>";
   fFooter += "© 2007-2008 Bertrand Bellenot";
   fFooter += "</font></strong></center></body></html>";  
   fHtml   += fFooter;
}

//==============================================================================

//______________________________________________________________________________
void update_html_summary()
{
   // Update summary of current event.

   TEveElement::List_i i;
   TEveElement::List_i j;
   Int_t k;
   TEveElement *el;
   HtmlObjTable *table;
   TEveEventManager *mgr = gEve ? gEve->GetCurrentEvent() : 0;
   if (mgr) {
      fgHtmlSummary->Clear("D");
      for (i=mgr->BeginChildren(); i!=mgr->EndChildren(); ++i) {
         el = ((TEveElement*)(*i));
         if (el->IsA() == TEvePointSet::Class()) {
            TEvePointSet *ps = (TEvePointSet *)el;
            TString ename  = ps->GetElementName();
            TString etitle = ps->GetElementTitle();
            if (ename.First('\'') != kNPOS)
               ename.Remove(ename.First('\''));
            etitle.Remove(0, 2);
            Int_t nel = atoi(etitle.Data());
            table = fgHtmlSummary->AddTable(ename, 0, nel);
         }
         else if (el->IsA() == TEveTrackList::Class()) {
            TEveTrackList *tracks = (TEveTrackList *)el;
            TString ename  = tracks->GetElementName();
            if (ename.First('\'') != kNPOS)
               ename.Remove(ename.First('\''));
            table = fgHtmlSummary->AddTable(ename.Data(), 5, 
                     tracks->NumChildren(), kTRUE, "first");
            table->SetLabel(0, "Momentum");
            table->SetLabel(1, "P_t");
            table->SetLabel(2, "Phi");
            table->SetLabel(3, "Theta");
            table->SetLabel(4, "Eta");
            k=0;
            for (j=tracks->BeginChildren(); j!=tracks->EndChildren(); ++j) {
               Float_t p     = ((TEveTrack*)(*j))->GetMomentum().Mag();
               table->SetValue(0, k, p);
               Float_t pt    = ((TEveTrack*)(*j))->GetMomentum().Perp();
               table->SetValue(1, k, pt);
               Float_t phi   = ((TEveTrack*)(*j))->GetMomentum().Phi();
               table->SetValue(2, k, phi);
               Float_t theta = ((TEveTrack*)(*j))->GetMomentum().Theta();
               table->SetValue(3, k, theta);
               Float_t eta   = ((TEveTrack*)(*j))->GetMomentum().Eta();
               table->SetValue(4, k, eta);
               ++k;
            }
         }
      }
      fgHtmlSummary->Build();
      fgHtml->Clear();
      fgHtml->ParseText((char*)fgHtmlSummary->Html().Data());
      fgHtml->Layout();
   }
}
 alice_esd_html_summary.C:1
 alice_esd_html_summary.C:2
 alice_esd_html_summary.C:3
 alice_esd_html_summary.C:4
 alice_esd_html_summary.C:5
 alice_esd_html_summary.C:6
 alice_esd_html_summary.C:7
 alice_esd_html_summary.C:8
 alice_esd_html_summary.C:9
 alice_esd_html_summary.C:10
 alice_esd_html_summary.C:11
 alice_esd_html_summary.C:12
 alice_esd_html_summary.C:13
 alice_esd_html_summary.C:14
 alice_esd_html_summary.C:15
 alice_esd_html_summary.C:16
 alice_esd_html_summary.C:17
 alice_esd_html_summary.C:18
 alice_esd_html_summary.C:19
 alice_esd_html_summary.C:20
 alice_esd_html_summary.C:21
 alice_esd_html_summary.C:22
 alice_esd_html_summary.C:23
 alice_esd_html_summary.C:24
 alice_esd_html_summary.C:25
 alice_esd_html_summary.C:26
 alice_esd_html_summary.C:27
 alice_esd_html_summary.C:28
 alice_esd_html_summary.C:29
 alice_esd_html_summary.C:30
 alice_esd_html_summary.C:31
 alice_esd_html_summary.C:32
 alice_esd_html_summary.C:33
 alice_esd_html_summary.C:34
 alice_esd_html_summary.C:35
 alice_esd_html_summary.C:36
 alice_esd_html_summary.C:37
 alice_esd_html_summary.C:38
 alice_esd_html_summary.C:39
 alice_esd_html_summary.C:40
 alice_esd_html_summary.C:41
 alice_esd_html_summary.C:42
 alice_esd_html_summary.C:43
 alice_esd_html_summary.C:44
 alice_esd_html_summary.C:45
 alice_esd_html_summary.C:46
 alice_esd_html_summary.C:47
 alice_esd_html_summary.C:48
 alice_esd_html_summary.C:49
 alice_esd_html_summary.C:50
 alice_esd_html_summary.C:51
 alice_esd_html_summary.C:52
 alice_esd_html_summary.C:53
 alice_esd_html_summary.C:54
 alice_esd_html_summary.C:55
 alice_esd_html_summary.C:56
 alice_esd_html_summary.C:57
 alice_esd_html_summary.C:58
 alice_esd_html_summary.C:59
 alice_esd_html_summary.C:60
 alice_esd_html_summary.C:61
 alice_esd_html_summary.C:62
 alice_esd_html_summary.C:63
 alice_esd_html_summary.C:64
 alice_esd_html_summary.C:65
 alice_esd_html_summary.C:66
 alice_esd_html_summary.C:67
 alice_esd_html_summary.C:68
 alice_esd_html_summary.C:69
 alice_esd_html_summary.C:70
 alice_esd_html_summary.C:71
 alice_esd_html_summary.C:72
 alice_esd_html_summary.C:73
 alice_esd_html_summary.C:74
 alice_esd_html_summary.C:75
 alice_esd_html_summary.C:76
 alice_esd_html_summary.C:77
 alice_esd_html_summary.C:78
 alice_esd_html_summary.C:79
 alice_esd_html_summary.C:80
 alice_esd_html_summary.C:81
 alice_esd_html_summary.C:82
 alice_esd_html_summary.C:83
 alice_esd_html_summary.C:84
 alice_esd_html_summary.C:85
 alice_esd_html_summary.C:86
 alice_esd_html_summary.C:87
 alice_esd_html_summary.C:88
 alice_esd_html_summary.C:89
 alice_esd_html_summary.C:90
 alice_esd_html_summary.C:91
 alice_esd_html_summary.C:92
 alice_esd_html_summary.C:93
 alice_esd_html_summary.C:94
 alice_esd_html_summary.C:95
 alice_esd_html_summary.C:96
 alice_esd_html_summary.C:97
 alice_esd_html_summary.C:98
 alice_esd_html_summary.C:99
 alice_esd_html_summary.C:100
 alice_esd_html_summary.C:101
 alice_esd_html_summary.C:102
 alice_esd_html_summary.C:103
 alice_esd_html_summary.C:104
 alice_esd_html_summary.C:105
 alice_esd_html_summary.C:106
 alice_esd_html_summary.C:107
 alice_esd_html_summary.C:108
 alice_esd_html_summary.C:109
 alice_esd_html_summary.C:110
 alice_esd_html_summary.C:111
 alice_esd_html_summary.C:112
 alice_esd_html_summary.C:113
 alice_esd_html_summary.C:114
 alice_esd_html_summary.C:115
 alice_esd_html_summary.C:116
 alice_esd_html_summary.C:117
 alice_esd_html_summary.C:118
 alice_esd_html_summary.C:119
 alice_esd_html_summary.C:120
 alice_esd_html_summary.C:121
 alice_esd_html_summary.C:122
 alice_esd_html_summary.C:123
 alice_esd_html_summary.C:124
 alice_esd_html_summary.C:125
 alice_esd_html_summary.C:126
 alice_esd_html_summary.C:127
 alice_esd_html_summary.C:128
 alice_esd_html_summary.C:129
 alice_esd_html_summary.C:130
 alice_esd_html_summary.C:131
 alice_esd_html_summary.C:132
 alice_esd_html_summary.C:133
 alice_esd_html_summary.C:134
 alice_esd_html_summary.C:135
 alice_esd_html_summary.C:136
 alice_esd_html_summary.C:137
 alice_esd_html_summary.C:138
 alice_esd_html_summary.C:139
 alice_esd_html_summary.C:140
 alice_esd_html_summary.C:141
 alice_esd_html_summary.C:142
 alice_esd_html_summary.C:143
 alice_esd_html_summary.C:144
 alice_esd_html_summary.C:145
 alice_esd_html_summary.C:146
 alice_esd_html_summary.C:147
 alice_esd_html_summary.C:148
 alice_esd_html_summary.C:149
 alice_esd_html_summary.C:150
 alice_esd_html_summary.C:151
 alice_esd_html_summary.C:152
 alice_esd_html_summary.C:153
 alice_esd_html_summary.C:154
 alice_esd_html_summary.C:155
 alice_esd_html_summary.C:156
 alice_esd_html_summary.C:157
 alice_esd_html_summary.C:158
 alice_esd_html_summary.C:159
 alice_esd_html_summary.C:160
 alice_esd_html_summary.C:161
 alice_esd_html_summary.C:162
 alice_esd_html_summary.C:163
 alice_esd_html_summary.C:164
 alice_esd_html_summary.C:165
 alice_esd_html_summary.C:166
 alice_esd_html_summary.C:167
 alice_esd_html_summary.C:168
 alice_esd_html_summary.C:169
 alice_esd_html_summary.C:170
 alice_esd_html_summary.C:171
 alice_esd_html_summary.C:172
 alice_esd_html_summary.C:173
 alice_esd_html_summary.C:174
 alice_esd_html_summary.C:175
 alice_esd_html_summary.C:176
 alice_esd_html_summary.C:177
 alice_esd_html_summary.C:178
 alice_esd_html_summary.C:179
 alice_esd_html_summary.C:180
 alice_esd_html_summary.C:181
 alice_esd_html_summary.C:182
 alice_esd_html_summary.C:183
 alice_esd_html_summary.C:184
 alice_esd_html_summary.C:185
 alice_esd_html_summary.C:186
 alice_esd_html_summary.C:187
 alice_esd_html_summary.C:188
 alice_esd_html_summary.C:189
 alice_esd_html_summary.C:190
 alice_esd_html_summary.C:191
 alice_esd_html_summary.C:192
 alice_esd_html_summary.C:193
 alice_esd_html_summary.C:194
 alice_esd_html_summary.C:195
 alice_esd_html_summary.C:196
 alice_esd_html_summary.C:197
 alice_esd_html_summary.C:198
 alice_esd_html_summary.C:199
 alice_esd_html_summary.C:200
 alice_esd_html_summary.C:201
 alice_esd_html_summary.C:202
 alice_esd_html_summary.C:203
 alice_esd_html_summary.C:204
 alice_esd_html_summary.C:205
 alice_esd_html_summary.C:206
 alice_esd_html_summary.C:207
 alice_esd_html_summary.C:208
 alice_esd_html_summary.C:209
 alice_esd_html_summary.C:210
 alice_esd_html_summary.C:211
 alice_esd_html_summary.C:212
 alice_esd_html_summary.C:213
 alice_esd_html_summary.C:214
 alice_esd_html_summary.C:215
 alice_esd_html_summary.C:216
 alice_esd_html_summary.C:217
 alice_esd_html_summary.C:218
 alice_esd_html_summary.C:219
 alice_esd_html_summary.C:220
 alice_esd_html_summary.C:221
 alice_esd_html_summary.C:222
 alice_esd_html_summary.C:223
 alice_esd_html_summary.C:224
 alice_esd_html_summary.C:225
 alice_esd_html_summary.C:226
 alice_esd_html_summary.C:227
 alice_esd_html_summary.C:228
 alice_esd_html_summary.C:229
 alice_esd_html_summary.C:230
 alice_esd_html_summary.C:231
 alice_esd_html_summary.C:232
 alice_esd_html_summary.C:233
 alice_esd_html_summary.C:234
 alice_esd_html_summary.C:235
 alice_esd_html_summary.C:236
 alice_esd_html_summary.C:237
 alice_esd_html_summary.C:238
 alice_esd_html_summary.C:239
 alice_esd_html_summary.C:240
 alice_esd_html_summary.C:241
 alice_esd_html_summary.C:242
 alice_esd_html_summary.C:243
 alice_esd_html_summary.C:244
 alice_esd_html_summary.C:245
 alice_esd_html_summary.C:246
 alice_esd_html_summary.C:247
 alice_esd_html_summary.C:248
 alice_esd_html_summary.C:249
 alice_esd_html_summary.C:250
 alice_esd_html_summary.C:251
 alice_esd_html_summary.C:252
 alice_esd_html_summary.C:253
 alice_esd_html_summary.C:254
 alice_esd_html_summary.C:255
 alice_esd_html_summary.C:256
 alice_esd_html_summary.C:257
 alice_esd_html_summary.C:258
 alice_esd_html_summary.C:259
 alice_esd_html_summary.C:260
 alice_esd_html_summary.C:261
 alice_esd_html_summary.C:262
 alice_esd_html_summary.C:263
 alice_esd_html_summary.C:264
 alice_esd_html_summary.C:265
 alice_esd_html_summary.C:266
 alice_esd_html_summary.C:267
 alice_esd_html_summary.C:268
 alice_esd_html_summary.C:269
 alice_esd_html_summary.C:270
 alice_esd_html_summary.C:271
 alice_esd_html_summary.C:272
 alice_esd_html_summary.C:273
 alice_esd_html_summary.C:274
 alice_esd_html_summary.C:275
 alice_esd_html_summary.C:276
 alice_esd_html_summary.C:277
 alice_esd_html_summary.C:278
 alice_esd_html_summary.C:279
 alice_esd_html_summary.C:280
 alice_esd_html_summary.C:281
 alice_esd_html_summary.C:282
 alice_esd_html_summary.C:283
 alice_esd_html_summary.C:284
 alice_esd_html_summary.C:285
 alice_esd_html_summary.C:286
 alice_esd_html_summary.C:287
 alice_esd_html_summary.C:288
 alice_esd_html_summary.C:289
 alice_esd_html_summary.C:290
 alice_esd_html_summary.C:291
 alice_esd_html_summary.C:292
 alice_esd_html_summary.C:293
 alice_esd_html_summary.C:294
 alice_esd_html_summary.C:295
 alice_esd_html_summary.C:296
 alice_esd_html_summary.C:297
 alice_esd_html_summary.C:298
 alice_esd_html_summary.C:299
 alice_esd_html_summary.C:300
 alice_esd_html_summary.C:301
 alice_esd_html_summary.C:302
 alice_esd_html_summary.C:303
 alice_esd_html_summary.C:304
 alice_esd_html_summary.C:305
 alice_esd_html_summary.C:306
 alice_esd_html_summary.C:307
 alice_esd_html_summary.C:308
 alice_esd_html_summary.C:309
 alice_esd_html_summary.C:310
 alice_esd_html_summary.C:311
 alice_esd_html_summary.C:312
 alice_esd_html_summary.C:313
 alice_esd_html_summary.C:314
 alice_esd_html_summary.C:315
 alice_esd_html_summary.C:316
 alice_esd_html_summary.C:317
 alice_esd_html_summary.C:318
 alice_esd_html_summary.C:319
 alice_esd_html_summary.C:320
 alice_esd_html_summary.C:321
 alice_esd_html_summary.C:322
 alice_esd_html_summary.C:323
 alice_esd_html_summary.C:324
 alice_esd_html_summary.C:325
 alice_esd_html_summary.C:326
 alice_esd_html_summary.C:327
 alice_esd_html_summary.C:328
 alice_esd_html_summary.C:329
 alice_esd_html_summary.C:330
 alice_esd_html_summary.C:331
 alice_esd_html_summary.C:332
 alice_esd_html_summary.C:333
 alice_esd_html_summary.C:334