Re: filling TBranch

From: stefan kluth (skluth@mh1.lbl.gov)
Date: Mon Jul 27 1998 - 18:20:03 MEST


Hi Stas,

try 

tr->Branch("data",data,"data[100]/F",1024);

That should work. If you want a dynamic array in your tree you can do it
like this:

TRandom gen;
int na;
float* af;
TTree* tree = new TTree( "tree", "ROOT test tree" );
TBranch* brna= tree->Branch( "na", &na, "na/I", 8000 );
TBranch* braf= tree->Branch( "af", af, "af[na]/F", 8000 );

for( int i= 0; i < 10; ++i ) {

  na= gen.Gaus( 10.0, 3.0 );
  af= new float[na];
  for( int j= 0; j < na; ++j ) af[j]= gen.Gaus( 5.0, 10.0 );
  braf->SetAddress( &af[0] );
  tree->Fill();
  delete[] af;

}

Note the use of the braf->SetAddress( &af[0] ) function to make shure the
branch knows where to find the array in case it has changed. 

cheers, Stefan

---Stefan Kluth---------------Lynen Fellow----------------|\--|\-------
-  LBNL, MS 50A 2160       -  phone:  +1 510 495 2376  -  |/  |/      -
-  1 Cyclotron Rd.         -  fax:    +1 510 495 2957  -  |\/\|\/\|'  -
---Berkeley, CA94720, USA-----e-mail: SKluth@lbl.gov------|/\/|/\/|----



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:35 MET