Disk-resident to memory-resident trees

Hello,

I was wondering what is the best an easiest way to turn a disk-resident tree to a memory resident tree.
Currently when I try to do:

TFile f("treeFile.root","READ"); TTree* rt = (TTree*) f->Get("bonsai"); TTree* rt2 = rt->CloneTree();

I get this error:

[quote]Error in TTree::Fill: Failed filling branch:bonsai.y, nbytes=-1
This error is symptomatic of a Tree created as a memory-resident Tree
Instead of doing:
TTree *T = new TTree(…)
TFile *f = new TFile(…)
you should do:
TFile *f = new TFile(…)
TTree *T = new TTree(…)
[/quote]

Which is precisely what I don’t want to do.

N.

Found the answer in this post:
root.cern.ch/phpBB2/viewtopic.ph … ident+tree

Need to do:

TFile f("treeFile.root","READ"); TTree* rt = (TTree*) f->Get("bonsai"); gROOT->cd(0); // tells ROOT the next TTree is memory-resident TTree* rt2 = rt->CloneTree();