00001 // @(#)root/hbook:$Id: THbookTree.cxx 20882 2007-11-19 11:31:26Z rdm $ 00002 // Author: Rene Brun 18/02/2002 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2002, Rene Brun and Fons Rademakers. * 00006 * All rights reserved. * 00007 * * 00008 * For the licensing terms see $ROOTSYS/LICENSE. * 00009 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00010 *************************************************************************/ 00011 00012 ////////////////////////////////////////////////////////////////////////// 00013 // // 00014 // THbookTree // 00015 // // 00016 // A wrapper class supporting Hbook ntuples (CWN and RWN). // 00017 // The normal TTree calls can be used, including TTree::Draw(). // 00018 // Data read directly from the Hbook file via THbookFile. // 00019 // // 00020 // IMPORTANT NOTE // 00021 // When setting the branch address (via THbookTree::SetBranchAddress) // 00022 // for a branch in an Hbook block containing several names, eg // 00023 // Hbook block SELEVN with the following variables: // 00024 // ****************************************************************** // 00025 // * 1 * R*4 * * * SELEVN * WGGS // 00026 // * 2 * R*4 * * * SELEVN * AM12 // 00027 // * 3 * R*4 * * * SELEVN * AM34 // 00028 // * 4 * R*4 * * * SELEVN * AM14 // 00029 // * 5 * R*4 * * * SELEVN * AM32 // 00030 // * 6 * R*4 * * * SELEVN * PtPI(4) // 00031 // * 7 * R*4 * * * SELEVN * PHIPI(4) // 00032 // * 8 * R*4 * * * SELEVN * THTPI(4) // 00033 // one must define a C struct like: // 00034 // struct { // 00035 // Float_t Wggs; // 00036 // Float_t Am12; // 00037 // Float_t Am34; // 00038 // Float_t Am14; // 00039 // Float_t Am32; // 00040 // Float_t Ptpi[4]; // 00041 // Float_t Phipi[4]; // 00042 // Float_t Thtpi[4]; // 00043 // } event; // 00044 // // 00045 // and set ONLY the first variable address with: // 00046 // h96->SetBranchAddress("Wggs",&event.Wggs); // 00047 // // 00048 ////////////////////////////////////////////////////////////////////////// 00049 00050 #include "THbookTree.h" 00051 #include "THbookBranch.h" 00052 #include "TTreeFormula.h" 00053 00054 00055 ClassImp(THbookTree) 00056 00057 //______________________________________________________________________________ 00058 THbookTree::THbookTree(): TTree() 00059 { 00060 //default constructor 00061 fID = 0; 00062 fType = 0; 00063 fX = 0; 00064 fFile = 0; 00065 fInit = kFALSE; 00066 } 00067 00068 //______________________________________________________________________________ 00069 THbookTree::THbookTree(const char *name,Int_t id) 00070 :TTree(name,name) 00071 { 00072 //constructor 00073 fID = id; 00074 fType = 0; 00075 fX = 0; 00076 fFile = 0; 00077 fInit = kFALSE; 00078 } 00079 00080 00081 //______________________________________________________________________________ 00082 THbookTree::~THbookTree() 00083 { 00084 //destructor 00085 if (fX) delete [] fX; 00086 if (fFile) fFile->DeleteID(fID); 00087 } 00088 00089 00090 //______________________________________________________________________________ 00091 Int_t THbookTree::GetEntry(Long64_t entry, Int_t /*getall*/) 00092 { 00093 //get one entry from the hbook ntuple 00094 fReadEntry = entry; 00095 return fFile->GetEntry(entry,fID,fType,GetX()); 00096 } 00097 00098 00099 //______________________________________________________________________________ 00100 void THbookTree::InitBranches(Long64_t entry) 00101 { 00102 //Initialize the branch addresses 00103 Int_t nfill = GetPlayer()->GetNfill(); 00104 if (nfill > 0) {fInit = kFALSE; return;} 00105 if (fInit) return; 00106 fInit = kTRUE; 00107 if (!GetPlayer()->GetVar1()) { 00108 GetEntry(entry); 00109 return; 00110 } 00111 //fFile->InitLeaves(fID, 5,GetPlayer()->GetMultiplicity()); 00112 fFile->InitLeaves(fID, 0,GetPlayer()->GetSelect()); 00113 fFile->InitLeaves(fID, 3,GetPlayer()->GetVar3()); 00114 fFile->InitLeaves(fID, 2,GetPlayer()->GetVar2()); 00115 fFile->InitLeaves(fID, 1,GetPlayer()->GetVar1()); 00116 } 00117 00118 //______________________________________________________________________________ 00119 void THbookTree::Print(Option_t *option) const 00120 { 00121 //Print an overview of the hbook ntuple 00122 TTree::Print(option); 00123 } 00124 00125 //______________________________________________________________________________ 00126 Long64_t THbookTree::SetEntries(Long64_t n) 00127 { 00128 //Set the number of entries in the tree header and its branches 00129 fEntries = n; 00130 TIter next(GetListOfBranches()); 00131 THbookBranch *branch; 00132 while ((branch=(THbookBranch*)next())) { 00133 branch->SetEntries(n); 00134 } 00135 return n; 00136 }