Hi Francois-Xavier, As already reported by Chistian, the solution to this problem is to use friend Trees. See Users Guide and examples in the tutorials. Rene Brun On Thu, 5 Sep 2002, GENTIT Francois-Xavier DAPNIA wrote: > Dear Root developers, > I am surprised that there is no simple solution to the problem of adding > more objects to an already existing tree. The simple solutions I have tried > results in files with 2 trees, T;1 and T;2. If I insist to remain with only > one tree in the file, I have found no other solution than creating an other > file, copying the content of the first file into the second file, and then > adding the new elements. Here is the code I use to append the object fRun of > class TBCrun to an already existing tree containing objects of class TBCrun: > > TBCrun *run = new TBCrun(); > TFile *oldf = new TFile("file1.root"); > TTree *oldt = (TTree *)oldf->Get("T"); > Int_t nrun = (Int_t)oldt->GetEntries(); > TBranch *b1 = oldt->GetBranch("Run"); > b1->SetAddress(&run); > TFile *newf = new TFile("file2.root","recreate"); > TTree *newt = new TTree("T","T"); > TBranch *b2 = newt->Branch("Run","TBCrun",&run,bufsize,99); > for (Int_t k=0;k<nrun;k++) { > oldf->cd(); > nb1 += oldt->GetEntry(k,1); > newf->cd(); > nb2 += newt->Fill(); > } > newt->SetBranchAddress("Run",&fRun); > newt->Fill(); > newf->Write(); > > It works, but seems incredibly complicate to just add one element to the > tree. It has also the disadvantage of creating a second file, which imposes > later to delete the first file, and rename the second file with the name of > the deleted file. Would it be feasible to add a method "Append" to the class > TTree? > > > François-Xavier Gentit > DAPNIA/SPP CEA Saclay > http://gentit.home.cern.ch/gentit/ > >
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:08 MET