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 the command Event 1000 1 1 1
Author: Rene Brun
This notebook tutorial was automatically generated with ROOTBOOK-izer (Beta) from the macro found in the ROOT repository on Tuesday, January 17, 2017 at 02:42 PM.
In [1]:
.! $ROOTSYS/test/eventexe 1000 1 1 1
In [2]:
gSystem->Load("$ROOTSYS/test/libEvent");
Get old file, old tree and set top branch address
In [3]:
TFile *oldfile;
TString dir = "$ROOTSYS/test/Event.root";
gSystem->ExpandPathName(dir);
if (!gSystem->AccessPathName(dir))
{oldfile = new TFile("$ROOTSYS/test/Event.root");}
else {oldfile = new TFile("./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
In [4]:
TFile *newfile = new TFile("small.root","recreate");
TTree *newtree = oldtree->CloneTree(0);
Divert branch fh to a separate file and copy all events
In [5]:
newtree->GetBranch("fH")->SetFile("small_fH.root");
newtree->CopyEntries(oldtree);
newtree->Print();
newfile->Write();
delete oldfile;
delete newfile;