[Fwd: Re: TFile::Copy]

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Feb 10 1998 - 10:42:45 MET



attached mail follows:


William J. Deninger wrote: > Hello, > > I'm trying to figure out how to copy a TTree from one TFile to another. > TFile::Copy doesn't seem to be implemented yet, and the following doesn't > seem to work either: > > f1 = new TFile("f:/data/G2T076_076.root","update"); > f1.Delete("traceback;*"); // deleting old TTree object > > f2 = new TFile("f:/data/G2T076_076;1.root"); // file containing newest TTree > object > f1.cd(); > TTree *traceback = (TTree *) f2.Get("traceback"); // retrieve updated TTree > object > traceback.Write(); // write to f1 > f1.Write(); > f1.Close(); > > Any suggestions? In version 1.03/09 I introduced a function TTree::CloneTree to do the job. Example: assume an existing file with a Tree h1 and you want to copy this Tree to another file: Root > TFile f1("oldfile.root"); Root > TTree *h1 = (TTree*)f1.Get("h1"); Root > TFile f2("newfile.root","recreate"); Root > TTree *h1new = h1->CloneTree(h1->GetEntries()); Root > h1new->Write(); Rene Brun



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:29 MET