Re: 2D arrays and TTrees

From: Rene Brun (Rene.Brun@cern.ch)
Date: Mon Feb 15 1999 - 08:57:31 MET


Hi Glen,
In a ROOT TTree, each branch has its own buffer. If you assign a
complete
array (as in your example) to a branch, you must read the complete
array.
It is up to you to decide and structure your data into different
branches.
ROOT performs this job automatically if your data is organized in the
form
of objects (automatic split).
In your example, you could create 10 branches, eg:
  tree->Branch("adc0",&adc[0][0],"adc0[10]");
  tree->Branch("adc1",&adc[0][1],"adc1[10]");
  tree->Branch("adc2",&adc[0][2],"adc2[10]");
...

When reading, you can set active (via SetBranchStatus) only the branches
required in your analysis. With this split, you should gain a factor 10
when reading.

Rene Brun


Glen R. Salo wrote:
> 
> Dear Rooters,
> 
> I am trying to figure out how to read a single element, row, or column of data
> from 2D array in a TTree without reading the entire array for each event.  As
> shown in the example below, I can read any element from the array I wish, but
> by using the command b->GetEvent(i), the entire array is read.  Is there a way
> to avoid reading the entire event/array?
> 
> Macro to create sample data set.
> {
> gROOT->Reset();
> Float_t adc[10][10];
> 
> TFile *file=new TFile("adc.root","RECREATE");
> TTree *tree=new TTree("tree","Testing still");
> tree->Branch("adc",adc,"adc[10][10]/F");
> for (Int_t k=0; k<150; k++) {
>   for(Int_t j=0; j<10; j++) {
>     for(Int_t i=0; i<10; i++) adc[i][j]=k*100+j*10+i;
>   }
>   tree->Fill();
> }
> tree->Write();
> tree->Print();
> file->Close();
> }
> 
> Macro to read a element [1][1] from each event of the data set.
> 
> {
> gROOT->Reset();
> Float_t na[10][10];
> TFile file("adc.root");
> 
> TBranch *b = tree->GetBranch("adc");
> TLeaf *l = b->GetLeaf("adc");
> tree->SetBranchAddress("adc",&na);
> 
> for (Int_t i=0; i<150; i++) {
>   b->GetEvent(i);
>   printf("na[1][1] = %f, ",na[1][1]);
> }
> 
> }



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