Some questions about TTree's copy function

Hi:

1.what’s the difference of *newtree->CopyEntries(*oldtree, -1) and *newtree = oldtree->CloneTree();

  1. Is it dangerous if I want to clone a big tree(e.g. 1G~2G)? And if I want to modify one entry in a big tree, does that means I’ve to clone this tree and fill all of the entries again?

Thanks!

Hi,

CopyEntries is a lower level function and assume you already have 2 tree with similar layout and that you already have connected them.

CloneTree creates the output tree and connects and, optionally copies the data (and provide a faster copy if you are cloning all the entries).

Aka. Do not use CopyEntries :slight_smile:

[quote] does that means I’ve to clone this tree and fill all of the entries again? [/quote]Yes. You will need something like:

[code] TFile *oldfile = new TFile("$ROOTSYS/test/Event.root");
TTree oldtree = (TTree)oldfile->Get(“T”);
Int_t nentries = (Int_t)oldtree->GetEntries();

// Do the appropriate SetBranchAddress

//Create a new file + a clone of old tree in new file
TFile *newfile = new TFile(“small.root”,“recreate”);
TTree *newtree = oldtree->CloneTree(0);

for (Int_t i=0;i<nentries; i++) {
oldtree->GetEntry(i);
if(i==entry_with_need_to_modify) {
// do the modification
}
newtree->Fill();
}
newtree->Print();
newtree->AutoSave();
delete oldfile;
delete newfile;[/code]

Cheers,
Philippe

Thanks a lot!