Re: [ROOT] tree and TClonesArray

From: HP Wei (hp@rentec.com)
Date: Fri Dec 06 2002 - 23:17:59 MET


>You can do:
>   TClonesArray *arr =0;
>   tree->SetBranchAddress("T", &arr);
>   tree->SetBranchStatus("*",0);
>   tree->SetBranchStatus("f1",1);
>   tree->SetBranchStatus("f2",1);
>   //then in the loop (see below
>   tree->GetEntry(i);

  Hi REne,
     I compared this method with the following one:
     
     (1) From the branch T_, find the dimension of the TClonesArray at i-th
         entry.
     (2) double *pf1 = (double *) malloc(dimension*sizeof(double));
     (3) tree->SetBranchAddress("T.f1", pf1);
     (4) tree->SetBranchStatus("T.f1", 1);
     (5) tree->GetEntry(i)
     then, the array pointed by pf1 contains the data at the i-th entry.
     
     This method appears to be about three time faster than the 
     above TClonesArray method.
     
     Is this normal ?  Or am I missing something in the TClonesArray method?
   --HP
     
>On Fri, 6 Dec 2002, HP Wei wrote:
>
>> I have a tree with one branch ("T") into which I populate with
>> TClonesArray of objects of class CL:
>> 
>> Class CL : public TObject {
>> public:
>>    double f1;
>>    double f2;
>>    int    f3;
>>    int    f4;
>>    
>>    ....
>> };
>> 
>> The split is set to 1 when the tree is filled with data.
>> 
>> Now, I want to read data from the resulting root file.
>> As in the tcl.C example,  I do the following:
>> TClonesArray *arr =0;
>> tree->SetBranchAddress("T", &arr);
>> tree->GetEvent(event_number);
>> 
>> This will extract data for f1, f2, f3, and f3... (all data fields defined
>> in class CL.)
>> 
>> Suppose I want only f1, and f2.
>> What is the best way ?
>> 
>> --HP
>> 
>> 
>



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:22 MET