ROOT
Version v6.32
master
v6.34
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 the window are made.
8
/// 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
28
// A little class to automatically handle the generation of unique
29
// widget ids.
30
class
IDList
{
31
private
:
32
Int_t
nID
;
// Generates unique widget IDs.
33
public
:
34
IDList
() :
nID
(0) {}
35
~IDList
() {}
36
Int_t
GetUnID
(
void
) {
return
++
nID
; }
37
} ;
38
39
class
TableTest
:
public
TGMainFrame
{
40
41
private
:
42
IDList
fIDs ;
// Generator for unique widget IDs.
43
UInt_t
fNTableRows
;
44
UInt_t
fNTableColumns
;
45
TGTable
*fTable;
46
TFile
*fFile;
47
48
TTreeTableInterface
*fInterface;
49
50
public
:
51
TableTest
(
const
TGWindow
*
p
,
UInt_t
ntrows
,
UInt_t
ntcols
,
52
UInt_t
w
= 100,
UInt_t
h
= 100) ;
53
~TableTest
()
override
;
54
55
void
DoExit() ;
56
57
TGTable
*GetTable() {
return
fTable; }
58
TTreeTableInterface
*GetInterface() {
return
fInterface; }
59
60
ClassDefOverride
(
TableTest
, 0)
61
};
62
63
TableTest::TableTest(
const
TGWindow
*
p
,
UInt_t
ntrows
,
UInt_t
ntcols
,
64
UInt_t
w
,
UInt_t
h
)
65
:
TGMainFrame
(
p
,
w
,
h
),
fNTableRows
(
ntrows
),
fNTableColumns
(
ntcols
),
66
fTable(nullptr)
67
{
68
SetCleanup(
kDeepCleanup
) ;
69
Connect(
"CloseWindow()"
,
"TableTest"
,
this
,
"DoExit()"
) ;
70
DontCallClose() ;
71
72
// Open root file for the tree
73
fFile =
new
TFile
(
"$ROOTSYS/tutorials/hsimple.root"
);
74
75
if
(!fFile || fFile->IsZombie()) {
76
printf
(
"Please run <ROOT location>/tutorials/hsimple.C first."
);
77
return
;
78
}
79
80
// Get the ntuple from the file.
81
TNtuple
*
ntuple
= (
TNtuple
*)fFile->Get(
"ntuple"
);
82
83
// Setup the expressions for the columns and the selection of the
84
// interface.
85
TString
varexp
=
"px:py:pz:random:sin(px):log(px/py):log(pz)"
;
86
TString
select
=
""
;
87
TString
options =
""
;
88
89
// Create the interface.
90
fInterface =
new
TTreeTableInterface
(
ntuple
,
varexp
.Data(),
select
.Data(),
91
options.
Data
());
92
93
// Create the table and add it to the TableTest that is a TGMainFrame.
94
fTable =
new
TGTable
(
this
, fIDs.GetUnID(), fInterface,
fNTableRows
,
95
fNTableColumns
);
96
AddFrame(fTable,
new
TGLayoutHints
(
kLHintsExpandX
|
kLHintsExpandY
));
97
98
// Calls to layout and draw the TableTest that is a TGMainFrame.
99
SetWindowName(
"Tree Table Test"
) ;
100
MapSubwindows
() ;
101
Layout
();
102
Resize(GetDefaultWidth()+20, 600) ;
103
MapWindow() ;
104
105
} ;
106
107
TableTest::~TableTest()
108
{
109
// Destructor
110
delete
fInterface;
111
fFile->Close();
112
Cleanup() ;
113
}
114
115
void
TableTest::DoExit()
116
{
117
// Exit this application via the Exit button or Window Manager.
118
// Use one of the both lines according to your needs.
119
// Please note to re-run this macro in the same ROOT session,
120
// you have to compile it to get signals/slots 'on place'.
121
122
DeleteWindow();
// to stay in the ROOT session
123
// gApplication->Terminate(); // to exit and close the ROOT session
124
}
125
126
TGTable
*
ntupleTableTest
(
UInt_t
ntrows
= 50,
UInt_t
ntcols
= 10) {
127
TableTest
*
test
=
new
TableTest
(
nullptr
,
ntrows
,
ntcols
, 500, 200);
128
return
test
->GetTable();
129
}
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:341
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:53
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:397
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:712
tutorials
gui
ntupleTableTest.C
ROOT tags/v6-32-12 - Reference Guide Generated on Tue Apr 8 2025 06:01:06 (GVA Time) using Doxygen 1.10.0