Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
tree112_copy.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_tree
3/// \notebook -nodraw
4/// Example of Root macro to copy a subset of a Tree to a new Tree, selecting entries.
5///
6/// Only selected entries are copied to the new Tree.
7/// The input file has been generated by the program in `$ROOTSYS/test/Event`
8/// with `Event 1000 1 99 1`
9///
10/// \macro_code
11///
12/// \author Rene Brun
13
14#ifdef R__WIN32
16#else
18#endif
19
20void tree112_copy()
21{
22 // Get old file, old tree and set top branch address
23 TString dir = "$ROOTSYS/test/Event.root";
25 const auto filename = gSystem->AccessPathName(dir) ? "./Event.root" : "$ROOTSYS/test/Event.root";
26
29 oldfile.GetObject("T", oldtree);
30
31 const auto nentries = oldtree->GetEntries();
32
33 Event *event = nullptr;
34 oldtree->SetBranchAddress("event", &event);
35
36 // Create a new file + a clone of old tree in new file
37 TFile newfile("small.root", "recreate");
38 auto newtree = oldtree->CloneTree(0);
39
40 for (auto i : ROOT::TSeqI(nentries)) {
41 oldtree->GetEntry(i);
42 if (event->GetNtrack() > 605)
43 newtree->Fill();
44 event->Clear();
45 }
46
47 newtree->Print();
48 newfile.Write();
49}
#define R__LOAD_LIBRARY(LIBRARY)
Definition Rtypes.h:472
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
int nentries
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
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:139
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition TSystem.cxx:1286
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition TSystem.cxx:1308
A TTree represents a columnar dataset.
Definition TTree.h:84
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
TSeq< int > TSeqI
Definition TSeq.hxx:203