RE: Replacing a TBranch in a TTree...

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Tue, 15 Apr 2008 01:36:24 -0500


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 15 2008 - 08:36:36 CEST

This archive was generated by hypermail 2.2.0 : Mon Apr 21 2008 - 23:50:01 CEST