Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
staffTableTest.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 TGTable with a TTreeTableInterface.
4/// TableTest inherits from TGMainFrame to create a top level frame to embed the TGTable in.
5/// First, the staff.root file is opened to obtain a tree. This tree also contains strings as data.
6/// Then a TTreeTableInterface is created using this tree. A table is then created using the interface.
7/// In the end, the table is added to the TGMainFrame that is the TableTest and the necessary calls to correctly draw
8/// the window are made. For more information about the use of TTreeTableInterface and TGTable, see their documentation.
9///
10/// \macro_code
11///
12/// \author Roel Aaij 13/07/2007
13
14#include <iostream>
15#include <TApplication.h>
16#include <TGClient.h>
17#include <TGButton.h>
18#include <TGFrame.h>
19#include <TGWindow.h>
20#include <TString.h>
21#include <TGTable.h>
22#include <TTreeTableInterface.h>
23#include <TFile.h>
24#include <TNtuple.h>
25#include <TSelectorDraw.h>
26
27// A little class to automatically handle the generation of unique
28// widget ids.
29class IDList {
30private:
31 Int_t nID; // Generates unique widget IDs.
32public:
33 IDList() : nID(0) {}
34 ~IDList() {}
35 Int_t GetUnID(void) { return ++nID; }
36};
37
38class TableTest : public TGMainFrame {
39
40private:
41 IDList fIDs; // Generator for unique widget IDs.
42 UInt_t fNTableRows;
43 UInt_t fNTableColumns;
44 TGTable *fTable;
45 TFile *fFile;
46
47 TTreeTableInterface *fInterface;
48
49public:
50 TableTest(const TGWindow *p, UInt_t ntrows, UInt_t ntcols, UInt_t w = 100, UInt_t h = 100);
51 ~TableTest() override;
52
53 void DoExit();
54
55 TGTable *GetTable() { return fTable; }
56 TTreeTableInterface *GetInterface() { return fInterface; }
57
58 ClassDefOverride(TableTest, 0)
59};
60
61TableTest::TableTest(const TGWindow *p, UInt_t ntrows, UInt_t ntcols, UInt_t w, UInt_t h)
62 : TGMainFrame(p, w, h), fNTableRows(ntrows), fNTableColumns(ntcols), fTable(nullptr)
63{
64 SetCleanup(kDeepCleanup);
65 Connect("CloseWindow()", "TableTest", this, "DoExit()");
66 DontCallClose();
67
68 // Open root file for the tree
69 fFile = new TFile("cernstaff.root");
70
71 if (!fFile || fFile->IsZombie()) {
72 printf("Please run <ROOT location>/tutorials/io/tree/tree500_cernbuild.C first.");
73 return;
74 }
75
76 // Get the tree from the file.
77 TTree *tree = (TTree *)fFile->Get("T");
78
79 // Setup the expressions for the column and selection of the interface.
80 TString varexp = "*";
81 TString select = "";
82 TString options = "";
83 fInterface = new TTreeTableInterface(tree, varexp.Data(), select.Data(), options.Data());
84
85 // Create a table using the interface and add it to the TableTest
86 // that is a TGMainFrame.
87 fTable = new TGTable(this, fIDs.GetUnID(), fInterface, fNTableRows, fNTableColumns);
88 AddFrame(fTable, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
89
90 // Calls to layout and draw the TableTest that is a TGMainFrame.
91 SetWindowName("Tree Table Test");
93 Layout();
94 Resize(GetDefaultWidth() + 20, 600);
95 MapWindow();
96};
97
98TableTest::~TableTest()
99{
100 // Destructor
101 delete fInterface;
102 fFile->Close();
103 Cleanup();
104}
105
106void TableTest::DoExit()
107{
108 // Exit this application via the Exit button or Window Manager.
109 // Use one of the both lines according to your needs.
110 // Please note to re-run this macro in the same ROOT session,
111 // you have to compile it to get signals/slots 'on place'.
112
113 DeleteWindow(); // to stay in the ROOT session
114 // gApplication->Terminate(); // to exit and close the ROOT session
115}
116
117TGTable *staffTableTest(UInt_t ntrows = 50, UInt_t ntcols = 10)
118{
119 TableTest *test = new TableTest(nullptr, ntrows, ntcols, 500, 200);
120 return test->GetTable();
121}
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
@ kDeepCleanup
Definition TGFrame.h:42
@ kLHintsExpandY
Definition TGLayout.h:31
@ kLHintsExpandX
Definition TGLayout.h:30
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize MapSubwindows
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:397
Create an array to hold a bunch of numbers.
Definition TGTable.h:34
ROOT GUI Window base class.
Definition TGWindow.h:23
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376
TTreeTableInterface is used to interface to data that is stored in a TTree.
A TTree represents a columnar dataset.
Definition TTree.h:79
RooCmdArg Layout(double xmin, double xmax=0.99, double ymin=0.95)