ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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.
27 class IDList {
28 private:
29  Int_t nID; // Generates unique widget IDs.
30 public:
31  IDList() : nID(0) {}
32  ~IDList() {}
33  Int_t GetUnID(void) { return ++nID ; }
34 };
35 
36 class TableTest : public TGMainFrame {
37 
38 private:
39  IDList fIDs; // Generator for unique widget IDs.
40  UInt_t fNTableRows;
41  UInt_t fNTableColumns;
42  TGTreeTable *fTreeTable;
43  TFile *fFile;
44 
45 public:
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 
57 TableTest::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 
96 TableTest::~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 
114 TGTreeTable *gtreeTableTest(UInt_t ntrows = 50, UInt_t ntcols = 10) {
115  TableTest *test = new TableTest(0, ntrows, ntcols, 500, 200);
116  return test->GetTable();
117 }
TGTreeTable is a TGTable that owns it's own interface.
Definition: TGTreeTable.h:21
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
#define ClassDef(name, id)
Definition: Rtypes.h:254
unsigned int UInt_t
Definition: RtypesCore.h:42
tuple tree
Definition: tree.py:24
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
RooCmdArg Layout(Double_t xmin, Double_t xmax=0.99, Double_t ymin=0.95)
A TTree object has a header with a name and a title.
Definition: TTree.h:98