Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
tree110_copy.C File Reference

Detailed Description

View in nbviewer Open in SWAN
Copy a subset of a Tree to a new Tree

The input file has been generated by the program in $ROOTSYS/test/Event with Event 1000 1 1 1.

#ifdef ACTUAL_RUN // -------- Second pass: dictionary already built --------
#include "./Event.h" // now safe to include Event, its dictionary is loaded
void run()
{
TFile oldfile("tree108.root");
oldfile.GetObject("t4", oldtree);
// Deactivate all branches
oldtree->SetBranchStatus("*", 0);
// Activate only four of them
for (auto activeBranchName : {"event_split", "fNtrack", "fNseg", "fH"})
oldtree->SetBranchStatus(activeBranchName, 1);
// Create a new file + a clone of old tree in new file
TFile newfile("tree110.root", "recreate");
auto newtree = oldtree->CloneTree();
newtree->Print();
newfile.Write();
}
#else // -------- First pass: build dictionary + rerun macro --------
{
TString tutdir = gROOT->GetTutorialDir();
gROOT->ProcessLine(".L " + tutdir + "/io/tree/Event.cxx+");
gROOT->ProcessLine("#define ACTUAL_RUN yes");
gROOT->ProcessLine("#include \"" __FILE__ "\"");
gROOT->ProcessLine("run()");
}
#endif
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define gROOT
Definition TROOT.h:411
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:131
Basic string class.
Definition TString.h:138
A TTree represents a columnar dataset.
Definition TTree.h:89
Author
Rene Brun

Definition in file tree110_copy.C.