Re: Replacing a TBranch in a TTree...

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Tue, 22 Apr 2008 09:25:27 +0200


Pierre-Luc,

I looked at your patch, but your code is not doing what you believe. In particular, it does not delete the baskets from disk. In the SVN trunk (see:
http://root.cern.ch/viewvc/trunk/tree/tree/src/TBranch.cxx?revision=23378&view=markup I have implemented TBranch::DeleteBaskets. Look at the warning that says:

   /// NOTE that this function must be used with extreme care. Deleting branch baskets
/   /// fragments the file and may introduce inefficiencies when adding new entries
/   /// in the Tree or later on when reading the Tree.
/

Rene Brun

Pierre-Luc Drouin wrote:
> Hi,
>
> I have spent some time looking through TTree and TBranch code and I
> have written a function DeleteBaskets for the TBranch class that frees
> the space used by the baskets on disk and that calls the Reset()
> function to reinitialize the baskets for that branch. This would be
> nice if this function was added to TBranch. I send a patch file for
> TBranch.cxx
>
> Thanks!
> Pierre-Luc Drouin
>
> Philippe Canal wrote:
>> Hi,
>>
>> Why do you remove/delete the branch you just added?
>> (I guess this is an artefact of your reducing the problem).
>>
>> Anyway, adding branch is possible (exactly as you did).
>> Howvever removing branch is not supported (your example would
>> effectively render the information in the branch y
>> inaccessible but it would still take up (now useless) space
>> on the disk.
>>
>> If you need to remove/replace a branch you need to create
>> a new file and call CloneTree to make a (altered) copy of the TTree
>> (see $ROOTSYS/tutorials/tree for examples)>
>>
>> Cheers,
>> Philippe.
>>
>> PS. By the way to not use yb->Delete() use delete yb; instead.
>>
>> -----Original Message-----
>> From: owner-roottalk_at_root.cern.ch
>> [mailto:owner-roottalk_at_root.cern.ch] On
>> Behalf Of Pierre-Luc Drouin
>> Sent: Monday, April 14, 2008 10:29 PM
>> To: roottalk_at_root.cern.ch
>> Subject: [ROOT] Replacing a TBranch in a TTree...
>>
>> Hi,
>>
>> How can I replace the content of a TBranch in a TTree? I have tried
>> the following test but this leads to a segmentation fault when the
>> branch "y" is created the second time...
>>
>> TFile file("test.root","recreate");
>>
>> TTree *tree=new TTree("mytree","mytree");
>> Double_t x,y;
>> tree->Branch("x",&x,"x/D");
>>
>> for(Int_t i=0; i<1000000; i++){
>> x=i;
>> tree->Fill();
>> }
>>
>> TBranch *yb;
>>
>> for(Int_t j=0; j<10; j++){
>> yb=tree->Branch("y",&y,"y/D");
>>
>> for(Int_t i=0; i<1000000; i++){
>> x=i;
>> y=2*i;
>> yb->Fill();
>> }
>> tree->GetListOfBranches()->Remove(yb);
>> yb->Delete();
>> }
>>
>> file.Write();
>> file.Close();
>>
>> Thanks!
>> Pierre-Luc Drouin
>>
>>
>>
>
Received on Tue Apr 22 2008 - 09:22:45 CEST

This archive was generated by hypermail 2.2.0 : Tue Apr 22 2008 - 17:50:01 CEST