Logo ROOT   6.12/07
Reference Guide
THbookTree.cxx
Go to the documentation of this file.
1 // @(#)root/hbook:$Id$
2 // Author: Rene Brun 18/02/2002
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2002, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /** \class THbookTree
13  \ingroup Hist
14  A wrapper class supporting Hbook ntuples (CWN and RWN).
15  The normal TTree calls can be used, including TTree::Draw().
16  Data read directly from the Hbook file via THbookFile.
17 
18  IMPORTANT NOTE
19  When setting the branch address (via THbookTree::SetBranchAddress)
20  for a branch in an Hbook block containing several names, eg
21  Hbook block SELEVN with the following variables:
22 
23 ~~~
24  ******************************************************************
25  * 1 * R*4 * * * SELEVN * WGGS
26  * 2 * R*4 * * * SELEVN * AM12
27  * 3 * R*4 * * * SELEVN * AM34
28  * 4 * R*4 * * * SELEVN * AM14
29  * 5 * R*4 * * * SELEVN * AM32
30  * 6 * R*4 * * * SELEVN * PtPI(4)
31  * 7 * R*4 * * * SELEVN * PHIPI(4)
32  * 8 * R*4 * * * SELEVN * THTPI(4)
33 
34  one must define a C struct like:
35  struct {
36  Float_t Wggs;
37  Float_t Am12;
38  Float_t Am34;
39  Float_t Am14;
40  Float_t Am32;
41  Float_t Ptpi[4];
42  Float_t Phipi[4];
43  Float_t Thtpi[4];
44  } event;
45 
46  and set ONLY the first variable address with:
47  h96->SetBranchAddress("Wggs",&event.Wggs);
48 ~~~
49 */
50 
51 #include "THbookTree.h"
52 #include "THbookBranch.h"
53 #include "TTreeFormula.h"
54 
55 
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 ///default constructor
60 
62 {
63  fID = 0;
64  fType = 0;
65  fX = 0;
66  fFile = 0;
67  fInit = kFALSE;
68 }
69 
70 ////////////////////////////////////////////////////////////////////////////////
71 ///constructor
72 
74  :TTree(name,name)
75 {
76  fID = id;
77  fType = 0;
78  fX = 0;
79  fFile = 0;
80  fInit = kFALSE;
81 }
82 
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 ///destructor
86 
88 {
89  if (fX) delete [] fX;
90  if (fFile) fFile->DeleteID(fID);
91 }
92 
93 
94 ////////////////////////////////////////////////////////////////////////////////
95 ///get one entry from the hbook ntuple
96 
98 {
99  fReadEntry = entry;
100  return fFile->GetEntry(entry,fID,fType,GetX());
101 }
102 
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 ///Initialize the branch addresses
106 
108 {
109  Int_t nfill = GetPlayer()->GetNfill();
110  if (nfill > 0) {fInit = kFALSE; return;}
111  if (fInit) return;
112  fInit = kTRUE;
113  if (!GetPlayer()->GetVar1()) {
114  GetEntry(entry);
115  return;
116  }
117  //fFile->InitLeaves(fID, 5,GetPlayer()->GetMultiplicity());
122 }
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 ///Print an overview of the hbook ntuple
126 
127 void THbookTree::Print(Option_t *option) const
128 {
129  TTree::Print(option);
130 }
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 ///Set the number of entries in the tree header and its branches
134 
136 {
137  fEntries = n;
138  TIter next(GetListOfBranches());
139  THbookBranch *branch;
140  while ((branch=(THbookBranch*)next())) {
141  branch->SetEntries(n);
142  }
143  return n;
144 }
long long Long64_t
Definition: RtypesCore.h:69
TTreeFormula * GetVar2()
Definition: TTree.h:444
const char Option_t
Definition: RtypesCore.h:62
virtual void Print(Option_t *option="") const
Print a summary of the tree contents.
Definition: TTree.cxx:6864
TTreeFormula * GetSelect()
Definition: TTree.h:429
Bool_t fInit
Definition: THbookTree.h:36
int Int_t
Definition: RtypesCore.h:41
TVirtualTreePlayer * GetPlayer()
Load the TTreePlayer (if not already done).
Definition: TTree.cxx:5984
Int_t fID
Definition: THbookTree.h:33
virtual TObjArray * GetListOfBranches()
Definition: TTree.h:407
Int_t GetEntry(Int_t entry, Int_t id, Int_t atype, Float_t *x)
Read in memory all columns of entry number of ntuple id from the Hbook file.
Definition: THbookFile.cxx:515
XFontStruct * id
Definition: TGX11.cxx:108
char * fX
Definition: THbookTree.h:35
HBOOK Branch.
Definition: THbookBranch.h:26
void DeleteID(Int_t id)
remove id from file and memory
Definition: THbookFile.cxx:419
Int_t fType
Definition: THbookTree.h:34
Long64_t fReadEntry
! Number of the entry being processed
Definition: TTree.h:98
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
get one entry from the hbook ntuple
Definition: THbookTree.cxx:97
virtual void InitBranches(Long64_t entry)
Initialize the branch addresses.
Definition: THbookTree.cxx:107
TTreeFormula * GetVar3()
Definition: TTree.h:446
THbookFile * fFile
Definition: THbookTree.h:37
void InitLeaves(Int_t id, Int_t var, TTreeFormula *formula)
This function is called from the first entry in TTreePlayer::InitLoop It analyzes the list of variabl...
Definition: THbookFile.cxx:552
const Bool_t kFALSE
Definition: RtypesCore.h:88
#define ClassImp(name)
Definition: Rtypes.h:359
virtual void SetEntries(Long64_t n)
Set the number of entries in this branch.
Definition: THbookBranch.h:41
virtual Long64_t SetEntries(Long64_t n=-1)
Set the number of entries in the tree header and its branches.
Definition: THbookTree.cxx:135
A wrapper class supporting Hbook ntuples (CWN and RWN).
Definition: THbookTree.h:30
virtual ~THbookTree()
destructor
Definition: THbookTree.cxx:87
Long64_t fEntries
Number of entries.
Definition: TTree.h:75
Float_t * GetX()
Definition: THbookTree.h:47
TTreeFormula * GetVar1()
Definition: TTree.h:442
A TTree object has a header with a name and a title.
Definition: TTree.h:70
const Bool_t kTRUE
Definition: RtypesCore.h:87
virtual void Print(Option_t *option="") const
Print an overview of the hbook ntuple.
Definition: THbookTree.cxx:127
const Int_t n
Definition: legend1.C:16
virtual Int_t GetNfill() const =0
char name[80]
Definition: TGX11.cxx:109
THbookTree()
default constructor
Definition: THbookTree.cxx:61