You can try the following:
TFile *f = TFile::Open("myfile.root","update");
TTree *T = (TTree*)f->Get("mytree");
TBranch *b = T->GetBranch("branchname");
T->GetListOfBranches()->Remove(b);
delete b;
T->Print();
T->Write();
Note that the code above deletes the branch logically from the Tree. The
branch baskets are still
in the file, so it does not reduce the file size.
Otherwise you have to copy your old Tree to a new file as shown below
TFile *f = TFile::Open("myfile.root");
TTree *T = (TTree*)f->Get("mytree");
T->SetBranchStatus("branchname",0);
TFile *newfile = new TFile("new.root","recreate");
TTree *newtree = T->CloneTree();
newtree->Print();
newtree->Write();
Rene Brun
Pietro Govoni wrote:
> Dear Rooters,
>
> I would like to remove a TBranch from a TTree, I was wandering whether
> some functions or pieces of code already exist to do it, can you help me?
>
> Thank you very much,
>
> pietro
Received on Fri Jul 10 2009 - 16:29:12 CEST
This archive was generated by hypermail 2.2.0 : Fri Jul 10 2009 - 23:50:02 CEST