https://github.com/root-project/root
Raw File
Tip revision: 7a1917fead85b88017cb13346529a19fec3d8351 authored by Unknown Author on 13 December 2000, 12:08:01 UTC
This commit was manufactured by cvs2svn to create tag 'v2-26-final'.
Tip revision: 7a1917f
copytree2.C
{
// Example of Root macro to copy a subset of a Tree to a new Tree
// One branch of the new Tree is written to a separate file
// The input file has been generated by the program in $ROOTSYS/test/Event
// with   Event 1000 1 1 1

   gROOT->Reset();
   gSystem->Load("$ROOTSYS/test/libEvent.so");

   //Get old file, old tree and set top branch address
   TFile *oldfile = new TFile("$ROOTSYS/test/Event.root");
   TTree *oldtree = (TTree*)oldfile->Get("T");
   Event *event   = new Event();
   oldtree->SetBranchAddress("event",&event);
   oldtree->SetBranchStatus("*",0);
   oldtree->SetBranchStatus("event",1);
   oldtree->SetBranchStatus("fNtrack",1);
   oldtree->SetBranchStatus("fNseg",1);
   oldtree->SetBranchStatus("fH",1);


   //Create a new file + a clone of old tree header. Do not copy events
   TFile *newfile = new TFile("small.root","recreate");
   TTree *newtree = oldtree->CloneTree(0);

   //Divert branch fH to a separate file and copy all events
   newtree->GetBranch("fH")->SetFile("small_fH.root");
   newtree->CopyEntries(oldtree);

   newtree->Print();
   newfile->Write();
   delete oldfile;
   delete newfile;
}
back to top