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

Detailed Description

View in nbviewer Open in SWAN
Copy a subset of a Tree to a new Tree, one branch in a separate file.

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

#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");
TTree *oldtree;
oldfile.GetObject("t4", oldtree);
// 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 header. Do not copy events
TFile newfile("tree111.root", "recreate");
auto 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();
}
#else // -------- First pass: build dictionary + rerun macro --------
void tree111_copy()
{
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
#define gROOT
Definition TROOT.h:417
virtual void SetFile(TFile *file=nullptr)
Set file where this branch writes/reads its buffers.
Definition TBranch.cxx:2875
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Definition TFile.h:130
Basic string class.
Definition TString.h:138
A TTree represents a columnar dataset.
Definition TTree.h:89
virtual void SetBranchStatus(const char *bname, bool status=true, UInt_t *found=nullptr)
Set branch status to Process or DoNotProcess.
Definition TTree.cxx:8779
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
Definition TTree.cxx:5430
virtual TTree * CloneTree(Long64_t nentries=-1, Option_t *option="")
Create a clone of this tree and copy nentries.
Definition TTree.cxx:3173
Author
Rene Brun

Definition in file tree111_copy.C.