Jayoung Wu wrote: > > Can I create 3 dimension array for one of Branch in ROOT? > Only 1 and 2-d arrays are supported in version 1.03/09. Version 2.00 available next week includes supports for multi-dimensional arrays in general. In the new version TTree::MakeCode has been modified to generate correct array declarations. Rene Brun > "maketree.C" filled the tree in the following way: > ------------------------------------------------------------------- > Float_t sum,intrpos[3],bgo[10][2][20]; > // Create a new ROOT binary machine independant file > TFile *f = new TFile("aticdata.root","RECREATE"); > // Create a ROOT Tree and branches > TTree *tree = new TTree("EVENT","Event Tree"); > TBranch *branch1 = tree->Branch("SUM",&sum,"sum/F"); > TBranch *branch2 = tree->Branch("INTRPOS",intrpos,"intrpos[3]/F"); > TBranch *branch3 = tree->Branch("BGO",bgo,"bgo[10][2][20]/F"); > ^^^^^^^^^^^^^^ > ??? > // Fill the tree > for(event=1; event<=NUMOFEVENTS; event++) { > sum = XXX; > intrpos[0]=XXX; > intrpos[1]=XXX; > intrpos[2]=XXX; > for(i=0; i<10; i++) > for(j=0; j<2; j++) > for(k=0; k<20; k++) bgo[i][j][k]=XXX; > > tree->Fill(); > ------------------------------------------------------------------- > > When I retrieve each branch value from the tree("EVENT") in the following > manner I succededed in retrieving sum and intrpos. However bgo gives > garbage. ^^^ ^^^^^^^ ^^^ > > Is this because bgo is 3 dim array or my code is wrong? > > ---------------------------- retrieving routine ------------- > #include <stdio.h> > > #include "TROOT.h" > #include "TFile.h" > #include "TTree.h" > #include "TBranch.h" > #include "TObject.h" > > Int_t main() > { > Int_t nevent; > Int_t nbyte; > > Float_t sum; > Float_t intrpos[3]; > Float_t bgo[10][2][20]; > > TROOT readtree("readtree","Test of reading TREE"); > > // Connect ROOT file > TFile *f = new TFile("aticdata.root"); > > // Read Tree named "EVENT" in memory. > // Tree pointer is assigned the same name. > TTree *EVENT = (TTree *)f->Get("EVENT"); > > // Access each branch > TBranch *bsum = (TBranch *)EVENT->GetBranch("SUM"); > TBranch *bintrpos = (TBranch *)EVENT->GetBranch("INTRPOS"); > TBranch *bbgo = (TBranch *)EVENT->GetBranch("BGO"); > > // Set addresses > bsum->SetAddress(&sum); > bintrpos->SetAddress(&intrpos[0]); > bbgo->SetAddress(&bgo[0][0][0]); > > // Read from each branch > nevent = EVENT->GetEntries(); > nbyte = 0; > > for(Int_t i=0; i<nevent; i++) { > nbyte += EVENT->GetEvent(i); > printf("%d %g\n",i,sum); > printf("%d %g %g %g\n",i,intrpos[0],intrpos[1],intrpos[2]); > for(Int_t j=0; j<10; j++) > for(Int_t k=0; k<2; k++) > for(Int_t l=0; l<20; l++) > printf("%d %g\n",i,bgo[j][k][l]); > > } > > f->Close(); > return 0; > } > > ---- > Thanks a lot! > Jayoung
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:30 MET