Revision 67efe942c51eb1925b2270c8544ff64da615901a authored by Rene Brun on 13 December 2009, 22:30:05 UTC, committed by Rene Brun on 13 December 2009, 22:30:05 UTC
git-svn-id: http://root.cern.ch/svn/root/trunk@31869 27541ba8-7e3a-0410-8455-c3a389f83636
1 parent a7ddee3
copytree3.C
void copytree3() {
// Example of Root macro to copy a subset of a Tree to a new Tree
// Only selected entries are copied to the new Tree.
// The input file has been generated by the program in $ROOTSYS/test/Event
// with Event 1000 1 99 1
//Author: Rene Brun
gSystem->Load("$ROOTSYS/test/libEvent");
//Get old file, old tree and set top branch address
TFile *oldfile = new TFile("$ROOTSYS/test/Event.root");
TTree *oldtree = (TTree*)oldfile->Get("T");
Int_t nentries = (Int_t)oldtree->GetEntries();
Event *event = 0;
oldtree->SetBranchAddress("event",&event);
//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 (event->GetNtrack() > 605) newtree->Fill();
event->Clear();
}
newtree->Print();
newtree->AutoSave();
delete oldfile;
delete newfile;
}
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...