Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
tree110_copy.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_tree
3/// \notebook -nodraw
4/// Copy a subset of a Tree to a new Tree
5///
6/// The input file has been generated by the program in `$ROOTSYS/test/Event`
7/// with `Event 1000 1 1 1`.
8///
9/// \macro_code
10///
11/// \author Rene Brun
12
13#ifdef ACTUAL_RUN // -------- Second pass: dictionary already built --------
14
15#include "./Event.h" // now safe to include Event, its dictionary is loaded
16
17void run()
18{
19 TFile oldfile("tree108.root");
21 oldfile.GetObject("t4", oldtree);
22
23 // Deactivate all branches
24 oldtree->SetBranchStatus("*", 0);
25
26 // Activate only four of them
27 for (auto activeBranchName : {"event_split", "fNtrack", "fNseg", "fH"})
28 oldtree->SetBranchStatus(activeBranchName, 1);
29
30 // Create a new file + a clone of old tree in new file
31 TFile newfile("tree110.root", "recreate");
32 auto newtree = oldtree->CloneTree();
33
34 newtree->Print();
35 newfile.Write();
36}
37
38#else // -------- First pass: build dictionary + rerun macro --------
39
40void tree110_copy()
41{
42 TString tutdir = gROOT->GetTutorialDir();
43 gROOT->ProcessLine(".L " + tutdir + "/io/tree/Event.cxx+");
44 gROOT->ProcessLine("#define ACTUAL_RUN yes");
45 gROOT->ProcessLine("#include \"" __FILE__ "\"");
46 gROOT->ProcessLine("run()");
47}
48
49#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