ROOT logo
// This TableTest class is a simple example of how to use a TGTreeTable. 
// TableTest inherits from TGMainFrame to create a top
// level frame to embed the TGTreeTable in. First, the staff.root file
// is opened to obtain a tree. A TGTreeTable is then created using the
// tree. In the end, the table is added to the TGMainFrame that is the
// TableTest and the necessary calls to correctly draw the window are
// made. For more information about the use of TGTreeTable, see it's
// documentation.

// author, Roel Aaij 13/07/2007

#include <iostream>
#include <TApplication.h>
#include <TGClient.h>
#include <TGButton.h>
#include <TGFrame.h>
#include <TGWindow.h>
#include <TString.h>
#include <TGTreeTable.h>
#include <TFile.h>
#include <TNtuple.h>
#include <TTree.h>

// A little class to automatically handle the generation of unique
// widget ids.
class IDList {
private:
   Int_t nID;               // Generates unique widget IDs.
public:
   IDList() : nID(0) {}
   ~IDList() {}
   Int_t GetUnID(void) { return ++nID ; }
};

class TableTest : public TGMainFrame {

private:
   IDList        fIDs;      // Generator for unique widget IDs.
   UInt_t        fNTableRows;
   UInt_t        fNTableColumns;
   TGTreeTable  *fTreeTable;
   TFile        *fFile;
   
public:
   TableTest(const TGWindow *p, UInt_t ntrows, UInt_t ntcols, 
             UInt_t w = 100, UInt_t h = 100);
   virtual ~TableTest() ;

   void DoExit() ;

   TGTreeTable *GetTable() { return fTreeTable; }

   ClassDef(TableTest, 0)
};
                          
TableTest::TableTest(const TGWindow *p, UInt_t ntrows, UInt_t ntcols, 
                     UInt_t w, UInt_t h) 
   : TGMainFrame(p, w, h), fNTableRows(ntrows), fNTableColumns(ntcols), 
     fTreeTable(0)
{
   SetCleanup(kDeepCleanup) ;   
   Connect("CloseWindow()", "TableTest", this, "DoExit()") ;
   DontCallClose() ;
   
   // Open the root file
   fFile = new TFile("$ROOTSYS/tutorials/tree/staff.root");

   if (!fFile || fFile->IsZombie()) {
      printf("Please run <ROOT location>/tutorials/tree/staff.C first.");
      return;
   }

   // Get the tree from the file.
   TTree *tree = (TTree *)fFile->Get("T");

   // Setup the expressions for the columns and the selection of the
   // interface.
   TString varexp = "px:py:pz:random:sin(px):log(px/py):log(pz)";
   TString select = "px>0 && py>0 && pz>0";
   TString options = "";

   // Create the table and add it to the TableTest that is a TGMainFrame
   fTreeTable = new TGTreeTable(this, fIDs.GetUnID(), tree);
   AddFrame(fTreeTable, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));

   // Calls to layout and draw the TableTest that is a TGMainFrame.
   SetWindowName("TGTreeTable Test") ;
   MapSubwindows() ;
   Layout();
   Resize() ;
   MapWindow() ;
   
} ;

TableTest::~TableTest()
{
   // Destructor
   fFile->Close();
   Cleanup() ;
}
 
 void TableTest::DoExit()
{
   // Exit this application via the Exit button or Window Manager.
   // Use one of the both lines according to your needs.
   // Please note to re-run this macro in the same ROOT session,
   // you have to compile it to get signals/slots 'on place'.
   
   DeleteWindow();            // to stay in the ROOT session
   //   gApplication->Terminate();   // to exit and close the ROOT session   
}

TGTreeTable *gtreeTableTest(UInt_t ntrows = 50, UInt_t ntcols = 10) {
   TableTest *test = new TableTest(0, ntrows, ntcols, 500, 200);
   return test->GetTable();
}
 gtreeTableTest.C:1
 gtreeTableTest.C:2
 gtreeTableTest.C:3
 gtreeTableTest.C:4
 gtreeTableTest.C:5
 gtreeTableTest.C:6
 gtreeTableTest.C:7
 gtreeTableTest.C:8
 gtreeTableTest.C:9
 gtreeTableTest.C:10
 gtreeTableTest.C:11
 gtreeTableTest.C:12
 gtreeTableTest.C:13
 gtreeTableTest.C:14
 gtreeTableTest.C:15
 gtreeTableTest.C:16
 gtreeTableTest.C:17
 gtreeTableTest.C:18
 gtreeTableTest.C:19
 gtreeTableTest.C:20
 gtreeTableTest.C:21
 gtreeTableTest.C:22
 gtreeTableTest.C:23
 gtreeTableTest.C:24
 gtreeTableTest.C:25
 gtreeTableTest.C:26
 gtreeTableTest.C:27
 gtreeTableTest.C:28
 gtreeTableTest.C:29
 gtreeTableTest.C:30
 gtreeTableTest.C:31
 gtreeTableTest.C:32
 gtreeTableTest.C:33
 gtreeTableTest.C:34
 gtreeTableTest.C:35
 gtreeTableTest.C:36
 gtreeTableTest.C:37
 gtreeTableTest.C:38
 gtreeTableTest.C:39
 gtreeTableTest.C:40
 gtreeTableTest.C:41
 gtreeTableTest.C:42
 gtreeTableTest.C:43
 gtreeTableTest.C:44
 gtreeTableTest.C:45
 gtreeTableTest.C:46
 gtreeTableTest.C:47
 gtreeTableTest.C:48
 gtreeTableTest.C:49
 gtreeTableTest.C:50
 gtreeTableTest.C:51
 gtreeTableTest.C:52
 gtreeTableTest.C:53
 gtreeTableTest.C:54
 gtreeTableTest.C:55
 gtreeTableTest.C:56
 gtreeTableTest.C:57
 gtreeTableTest.C:58
 gtreeTableTest.C:59
 gtreeTableTest.C:60
 gtreeTableTest.C:61
 gtreeTableTest.C:62
 gtreeTableTest.C:63
 gtreeTableTest.C:64
 gtreeTableTest.C:65
 gtreeTableTest.C:66
 gtreeTableTest.C:67
 gtreeTableTest.C:68
 gtreeTableTest.C:69
 gtreeTableTest.C:70
 gtreeTableTest.C:71
 gtreeTableTest.C:72
 gtreeTableTest.C:73
 gtreeTableTest.C:74
 gtreeTableTest.C:75
 gtreeTableTest.C:76
 gtreeTableTest.C:77
 gtreeTableTest.C:78
 gtreeTableTest.C:79
 gtreeTableTest.C:80
 gtreeTableTest.C:81
 gtreeTableTest.C:82
 gtreeTableTest.C:83
 gtreeTableTest.C:84
 gtreeTableTest.C:85
 gtreeTableTest.C:86
 gtreeTableTest.C:87
 gtreeTableTest.C:88
 gtreeTableTest.C:89
 gtreeTableTest.C:90
 gtreeTableTest.C:91
 gtreeTableTest.C:92
 gtreeTableTest.C:93
 gtreeTableTest.C:94
 gtreeTableTest.C:95
 gtreeTableTest.C:96
 gtreeTableTest.C:97
 gtreeTableTest.C:98
 gtreeTableTest.C:99
 gtreeTableTest.C:100
 gtreeTableTest.C:101
 gtreeTableTest.C:102
 gtreeTableTest.C:103
 gtreeTableTest.C:104
 gtreeTableTest.C:105
 gtreeTableTest.C:106
 gtreeTableTest.C:107
 gtreeTableTest.C:108
 gtreeTableTest.C:109
 gtreeTableTest.C:110
 gtreeTableTest.C:111
 gtreeTableTest.C:112
 gtreeTableTest.C:113
 gtreeTableTest.C:114
 gtreeTableTest.C:115
 gtreeTableTest.C:116
 gtreeTableTest.C:117