Re: Replacing a TBranch in a TTree...

From: Pierre-Luc Drouin <pldrouin_at_physics.carleton.ca>
Date: Mon, 21 Apr 2008 16:09:57 -0400


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 Mon Apr 21 2008 - 22:10:06 CEST

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