copytree.C

Go to the documentation of this file.
00001 void copytree() {
00002 // Example of Root macro to copy a subset of a Tree to a new Tree
00003 // The input file has been generated by the program in $ROOTSYS/test/Event
00004 // with   Event 1000 1 1 1
00005 //Author: Rene Brun
00006    
00007    gSystem->Load("$ROOTSYS/test/libEvent");
00008 
00009    //Get old file, old tree and set top branch address
00010    TFile *oldfile = new TFile("$ROOTSYS/test/Event.root");
00011    TTree *oldtree = (TTree*)oldfile->Get("T");
00012    Event *event   = new Event();
00013    oldtree->SetBranchAddress("event",&event);
00014    oldtree->SetBranchStatus("*",0);
00015    oldtree->SetBranchStatus("event",1);
00016    oldtree->SetBranchStatus("fNtrack",1);
00017    oldtree->SetBranchStatus("fNseg",1);
00018    oldtree->SetBranchStatus("fH",1);
00019 
00020    //Create a new file + a clone of old tree in new file
00021    TFile *newfile = new TFile("small.root","recreate");
00022    TTree *newtree = oldtree->CloneTree();
00023 
00024    newtree->Print();
00025    newfile->Write();
00026    delete oldfile;
00027    delete newfile;
00028 }

Generated on Tue Jul 5 15:45:11 2011 for ROOT_528-00b_version by  doxygen 1.5.1