Re: Replacing a TBranch in a TTree...

From: Pierre-Luc Drouin <pldrouin_at_physics.carleton.ca>
Date: Tue, 22 Apr 2008 11:38:27 -0400


I know that the code does not really reduce the size of the file, but at least it avoids it to expand when deleting and creating a branch of the same size. Thank you for adding the DeleteBaskets function!

Pierre-Luc Drouin

Rene Brun wrote:
> 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 - 17:38:48 CEST

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