I forgot to mention that the code does not crash when I use "delete yb"
instead of yb->delete(), but the branch buffer is not correctly cleared
in the root file and then the file size increases linearly with the
iteration over j...
Pierre-Luc Drouin wrote:
> 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 15 2008 - 05:54:41 CEST
This archive was generated by hypermail 2.2.0 : Tue Apr 15 2008 - 11:50:02 CEST