Logo ROOT  
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 }
THbookTree::fX
char * fX
Definition: THbookTree.h:41
THbookTree::fType
Int_t fType
Definition: THbookTree.h:40
n
const Int_t n
Definition: legend1.C:16
THbookTree::GetEntry
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
get one entry from the hbook ntuple
Definition: THbookTree.cxx:97
THbookBranch.h
THbookFile::DeleteID
void DeleteID(Int_t id)
remove id from file and memory
Definition: THbookFile.cxx:421
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TVirtualTreePlayer::GetNfill
virtual Int_t GetNfill() const =0
TTree::GetPlayer
TVirtualTreePlayer * GetPlayer()
Load the TTreePlayer (if not already done).
Definition: TTree.cxx:6198
TTree::GetVar2
TTreeFormula * GetVar2()
Definition: TTree.h:523
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
THbookTree::fFile
THbookFile * fFile
Definition: THbookTree.h:43
THbookTree::InitBranches
virtual void InitBranches(Long64_t entry)
Initialize the branch addresses.
Definition: THbookTree.cxx:107
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
TTree
Definition: TTree.h:79
THbookFile::InitLeaves
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:554
TTreeFormula.h
THbookBranch::SetEntries
virtual void SetEntries(Long64_t n)
Set the number of entries in this branch.
Definition: THbookBranch.h:47
THbookTree
Definition: THbookTree.h:30
TTree::Print
virtual void Print(Option_t *option="") const
Print a summary of the tree contents.
Definition: TTree.cxx:7090
THbookTree::SetEntries
virtual Long64_t SetEntries(Long64_t n=-1)
Set the number of entries in the tree header and its branches.
Definition: THbookTree.cxx:135
THbookTree::GetX
Float_t * GetX()
Definition: THbookTree.h:53
THbookTree::~THbookTree
virtual ~THbookTree()
destructor
Definition: THbookTree.cxx:87
TTree::GetSelect
TTreeFormula * GetSelect()
Definition: TTree.h:507
THbookTree.h
id
XFontStruct * id
Definition: TGX11.cxx:109
TTree::GetListOfBranches
virtual TObjArray * GetListOfBranches()
Definition: TTree.h:483
THbookTree::THbookTree
THbookTree()
default constructor
Definition: THbookTree.cxx:61
TTree::GetVar3
TTreeFormula * GetVar3()
Definition: TTree.h:525
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
THbookTree::Print
virtual void Print(Option_t *option="") const
Print an overview of the hbook ntuple.
Definition: THbookTree.cxx:127
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
THbookBranch
HBOOK Branch.
Definition: THbookBranch.h:26
TTree::fReadEntry
Long64_t fReadEntry
! Number of the entry being processed
Definition: TTree.h:107
THbookTree::fInit
Bool_t fInit
Definition: THbookTree.h:42
TTree::GetVar1
TTreeFormula * GetVar1()
Definition: TTree.h:521
TTree::fEntries
Long64_t fEntries
Number of entries.
Definition: TTree.h:84
name
char name[80]
Definition: TGX11.cxx:110
THbookTree::fID
Int_t fID
Definition: THbookTree.h:39
TIter
Definition: TCollection.h:233
THbookFile::GetEntry
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:517
int