Logo ROOT  
Reference Guide
gtreeTableTest.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_gui
3/// This TableTest class is a simple example of how to use a TGTreeTable.
4/// TableTest inherits from TGMainFrame to create a top level frame to embed the TGTreeTable in.
5/// First, the staff.root file is opened to obtain a tree. A TGTreeTable is then created using the tree.
6/// 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.
7/// For more information about the use of TGTreeTable, see it's documentation.
8///
9/// \macro_code
10///
11/// \author Roel Aaij 13/07/2007
12
13#include <iostream>
14#include <TApplication.h>
15#include <TGClient.h>
16#include <TGButton.h>
17#include <TGFrame.h>
18#include <TGWindow.h>
19#include <TString.h>
20#include <TGTreeTable.h>
21#include <TFile.h>
22#include <TNtuple.h>
23#include <TTree.h>
24
25// A little class to automatically handle the generation of unique
26// widget ids.
27class IDList {
28private:
29 Int_t nID; // Generates unique widget IDs.
30public:
31 IDList() : nID(0) {}
32 ~IDList() {}
33 Int_t GetUnID(void) { return ++nID ; }
34};
35
36class TableTest : public TGMainFrame {
37
38private:
39 IDList fIDs; // Generator for unique widget IDs.
40 UInt_t fNTableRows;
41 UInt_t fNTableColumns;
42 TGTreeTable *fTreeTable;
43 TFile *fFile;
44
45public:
46 TableTest(const TGWindow *p, UInt_t ntrows, UInt_t ntcols,
47 UInt_t w = 100, UInt_t h = 100);
48 virtual ~TableTest() ;
49
50 void DoExit() ;
51
52 TGTreeTable *GetTable() { return fTreeTable; }
53
54 ClassDef(TableTest, 0)
55};
56
57TableTest::TableTest(const TGWindow *p, UInt_t ntrows, UInt_t ntcols,
58 UInt_t w, UInt_t h)
59 : TGMainFrame(p, w, h), fNTableRows(ntrows), fNTableColumns(ntcols),
60 fTreeTable(0)
61{
62 SetCleanup(kDeepCleanup) ;
63 Connect("CloseWindow()", "TableTest", this, "DoExit()") ;
64 DontCallClose() ;
65
66 // Open the root file
67 fFile = new TFile("cernstaff.root");
68
69 if (!fFile || fFile->IsZombie()) {
70 printf("Please run <ROOT location>/tutorials/tree/cernbuild.C first.");
71 return;
72 }
73
74 // Get the tree from the file.
75 TTree *tree = (TTree *)fFile->Get("T");
76
77 // Setup the expressions for the columns and the selection of the
78 // interface.
79 TString varexp = "px:py:pz:random:sin(px):log(px/py):log(pz)";
80 TString select = "px>0 && py>0 && pz>0";
81 TString options = "";
82
83 // Create the table and add it to the TableTest that is a TGMainFrame
84 fTreeTable = new TGTreeTable(this, fIDs.GetUnID(), tree);
85 AddFrame(fTreeTable, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
86
87 // Calls to layout and draw the TableTest that is a TGMainFrame.
88 SetWindowName("TGTreeTable Test") ;
89 MapSubwindows() ;
90 Layout();
91 Resize(GetDefaultWidth()+20, 600) ;
92 MapWindow() ;
93
94} ;
95
96TableTest::~TableTest()
97{
98 // Destructor
99 fFile->Close();
100 Cleanup() ;
101}
102
103 void TableTest::DoExit()
104{
105 // Exit this application via the Exit button or Window Manager.
106 // Use one of the both lines according to your needs.
107 // Please note to re-run this macro in the same ROOT session,
108 // you have to compile it to get signals/slots 'on place'.
109
110 DeleteWindow(); // to stay in the ROOT session
111 // gApplication->Terminate(); // to exit and close the ROOT session
112}
113
114TGTreeTable *gtreeTableTest(UInt_t ntrows = 50, UInt_t ntcols = 10) {
115 TableTest *test = new TableTest(0, ntrows, ntcols, 500, 200);
116 return test->GetTable();
117}
#define h(i)
Definition: RSha256.hxx:106
int Int_t
Definition: RtypesCore.h:43
unsigned int UInt_t
Definition: RtypesCore.h:44
#define ClassDef(name, id)
Definition: Rtypes.h:322
@ kDeepCleanup
Definition: TGFrame.h:51
@ kLHintsExpandY
Definition: TGLayout.h:38
@ kLHintsExpandX
Definition: TGLayout.h:37
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:53
TGTreeTable is a TGTable that owns it's own interface.
Definition: TGTreeTable.h:18
Basic string class.
Definition: TString.h:131
A TTree represents a columnar dataset.
Definition: TTree.h:78
RooCmdArg Layout(Double_t xmin, Double_t xmax=0.99, Double_t ymin=0.95)
Definition: test.py:1
Definition: tree.py:1