Delete Entire Tree

Hello All,

I would like to save some ROOT files but one of the TTrees is not important to me. Is there a way to remove it completely?

Many thanks.
Karthik.

What do you mean by “save some ROOT files” ?
Why do you create the Tree if you do not use it?

Rene

[quote=“brun”]What do you mean by “save some ROOT files” ?
Why do you create the Tree if you do not use it?
Rene[/quote]

Rene,

I needed the data in the other TTrees temporarily. After I use them one, I do not need to save those TTrees.
This is what I do now (from one of the examples):

... ofile = TFile::Open(oldfile); nfile = TFile::Open(newfile,"recreate"); TTree *oldtree = (TTree*)file->Get("Data2"); // pick the tree I want oldtree->SetBranchStatus("*",0); oldtree->SetBranchStatus("runID",1); oldtree->SetBranchStatus("eventID1",1); ... ... (select only the branches I want in the selected tree) ... TTree *newtree = oldtree->CloneTree(); newfile->Write(); ...

I run this, then delete the old root file, and move the new file to the old file.
It would be nice if I could just delete the Trees in place without creating new files.

Karthik.

[quote]It would be nice if I could just delete the Trees in place without creating new files.[/quote]Actually it probably would not, as the resulting file would take more space than necessary as it would not ‘free’ the gap left by the removed TTree (and thus your next question would be 'how do I compact my sparsely filled ROOT file).

Alternatively you may not (if the TTree that you do not need are small) have to store them in the first place; if they fit in memory call mytemptree->StDirectory(0);

Cheers,
Philippe.