ROOT
Version master
v6.34
v6.32
v6.30
v6.28
v6.26
v6.24
v6.22
v6.20
v6.18
v6.16
v6.14
v6.12
v6.10
v6.08
v6.06
Reference Guide
►
ROOT
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
ntupleTableTest.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 hsimple.root file is opened to obtain an ntuple. Then a TTreeTableInterface is created using this ntuple.
6
/// 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.
29
class
IDList
{
30
private
:
31
Int_t
nID
;
// Generates unique widget IDs.
32
public
:
33
IDList
() :
nID
(0) {}
34
~IDList
() {}
35
Int_t
GetUnID
(
void
) {
return
++
nID
; }
36
};
37
38
class
TableTest
:
public
TGMainFrame
{
39
40
private
:
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
49
public
:
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
61
TableTest::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
(
"$ROOTSYS/tutorials/hsimple.root"
);
70
71
if
(!fFile || fFile->IsZombie()) {
72
printf
(
"Please run <ROOT location>/tutorials/hsimple.C first."
);
73
return
;
74
}
75
76
// Get the ntuple from the file.
77
TNtuple
*
ntuple
= (
TNtuple
*)fFile->Get(
"ntuple"
);
78
79
// Setup the expressions for the columns and the selection of the
80
// interface.
81
TString
varexp
=
"px:py:pz:random:sin(px):log(px/py):log(pz)"
;
82
TString
select
=
""
;
83
TString
options =
""
;
84
85
// Create the interface.
86
fInterface =
new
TTreeTableInterface
(
ntuple
,
varexp
.Data(),
select
.Data(), options.
Data
());
87
88
// Create the table and add it to the TableTest that is a TGMainFrame.
89
fTable =
new
TGTable
(
this
, fIDs.GetUnID(), fInterface,
fNTableRows
,
fNTableColumns
);
90
AddFrame(fTable,
new
TGLayoutHints
(
kLHintsExpandX
|
kLHintsExpandY
));
91
92
// Calls to layout and draw the TableTest that is a TGMainFrame.
93
SetWindowName(
"Tree Table Test"
);
94
MapSubwindows
();
95
Layout
();
96
Resize(GetDefaultWidth() + 20, 600);
97
MapWindow();
98
};
99
100
TableTest::~TableTest()
101
{
102
// Destructor
103
delete
fInterface;
104
fFile->Close();
105
Cleanup();
106
}
107
108
void
TableTest::DoExit()
109
{
110
// Exit this application via the Exit button or Window Manager.
111
// Use one of the both lines according to your needs.
112
// Please note to re-run this macro in the same ROOT session,
113
// you have to compile it to get signals/slots 'on place'.
114
115
DeleteWindow();
// to stay in the ROOT session
116
// gApplication->Terminate(); // to exit and close the ROOT session
117
}
118
119
TGTable
*
ntupleTableTest
(
UInt_t
ntrows
= 50,
UInt_t
ntcols
= 10)
120
{
121
TableTest
*
test
=
new
TableTest
(
nullptr
,
ntrows
,
ntcols
, 500, 200);
122
return
test
->GetTable();
123
}
h
#define h(i)
Definition
RSha256.hxx:106
Int_t
int Int_t
Definition
RtypesCore.h:45
UInt_t
unsigned int UInt_t
Definition
RtypesCore.h:46
ClassDefOverride
#define ClassDefOverride(name, id)
Definition
Rtypes.h:346
TApplication.h
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
TFile.h
TGButton.h
TGClient.h
TGFrame.h
kDeepCleanup
@ kDeepCleanup
Definition
TGFrame.h:42
kLHintsExpandY
@ kLHintsExpandY
Definition
TGLayout.h:31
kLHintsExpandX
@ kLHintsExpandX
Definition
TGLayout.h:30
TGTable.h
w
winID w
Definition
TGWin32VirtualGLProxy.cxx:39
p
winID h TVirtualViewer3D TVirtualGLPainter p
Definition
TGWin32VirtualGLProxy.cxx:51
MapSubwindows
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize MapSubwindows
Definition
TGWin32VirtualXProxy.cxx:94
TGWindow.h
TNtuple.h
TSelectorDraw.h
TString.h
TTreeTableInterface.h
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
TFile
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition
TFile.h:131
TGLayoutHints
This class describes layout hints used by the layout classes.
Definition
TGLayout.h:50
TGMainFrame
Defines top level windows that interact with the system Window Manager.
Definition
TGFrame.h:399
TGTable
Create an array to hold a bunch of numbers.
Definition
TGTable.h:34
TGWindow
ROOT GUI Window base class.
Definition
TGWindow.h:23
TNtuple
A simple TTree restricted to a list of float variables only.
Definition
TNtuple.h:28
TString
Basic string class.
Definition
TString.h:139
TString::Data
const char * Data() const
Definition
TString.h:376
TTreeTableInterface
TTreeTableInterface is used to interface to data that is stored in a TTree.
Definition
TTreeTableInterface.h:25
RooFit::Layout
RooCmdArg Layout(double xmin, double xmax=0.99, double ymin=0.95)
Definition
RooGlobalFunc.cxx:745
tutorials
visualisation
gui
ntupleTableTest.C
ROOT master - Reference Guide Generated on Tue Apr 8 2025 06:21:59 (GVA Time) using Doxygen 1.10.0