Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TChain.h
Go to the documentation of this file.
1// @(#)root/tree:$Id$
2// Author: Rene Brun 03/02/97
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_TChain
13#define ROOT_TChain
14
15
16//////////////////////////////////////////////////////////////////////////
17// //
18// TChain //
19// //
20// A chain of TTrees. //
21// //
22//////////////////////////////////////////////////////////////////////////
23
24#include "TTree.h"
25
26class TFile;
27class TBrowser;
28class TCut;
29class TEntryList;
30class TEventList;
31class TCollection;
32
33class TChain : public TTree {
34
35protected:
36 Int_t fTreeOffsetLen; ///< Current size of fTreeOffset array
37 Int_t fNtrees; ///< Number of trees
38 Int_t fTreeNumber; ///<! Current Tree number in fTreeOffset table
39 Long64_t *fTreeOffset; ///<[fTreeOffsetLen] Array of variables
40 bool fCanDeleteRefs; ///<! If true, TProcessIDs are deleted when closing a file
41 TTree *fTree; ///<! Pointer to current tree (Note: We do *not* own this tree.)
42 TFile *fFile; ///<! Pointer to current file (We own the file).
43 TObjArray *fFiles; ///< -> List of file names containing the trees (TChainElement, owned)
44 TList *fStatus; ///< -> List of active/inactive branches (TChainElement, owned)
45 TChain *fProofChain; ///<! chain proxy when going to be processed by PROOF
46 bool fGlobalRegistration; ///<! if true, bypass use of global lists
47
48private:
49 TChain(const TChain&); // not implemented
50 TChain& operator=(const TChain&); // not implemented
51 void
52 ParseTreeFilename(const char *name, TString &filename, TString &treename, TString &query, TString &suffix) const;
53
54protected:
57
58public:
59 // TChain constants
64 kProofLite = BIT(18)
65 };
66
67 // This used to be 1234567890, if user code hardcoded this number, the user code will need to change.
68 static constexpr auto kBigNumber = TTree::kMaxEntries;
69
70public:
72
74 TChain(const char *name, const char *title = "", Mode mode = kWithGlobalRegistration);
75 ~TChain() override;
76
77 virtual Int_t Add(TChain* chain);
78 virtual Int_t Add(const char* name, Long64_t nentries = TTree::kMaxEntries);
79 virtual Int_t AddFile(const char* name, Long64_t nentries = TTree::kMaxEntries, const char* tname = "");
81 TFriendElement *AddFriend(const char* chainname, const char* dummy = "") override;
82 TFriendElement *AddFriend(const char* chainname, TFile* dummy) override;
83 TFriendElement *AddFriend(TTree* chain, const char* alias = "", bool warn = false) override;
84 void Browse(TBrowser*) override;
85 virtual void CanDeleteRefs(bool flag = true);
86 virtual void CreatePackets();
87 void DirectoryAutoAdd(TDirectory *) override;
88 Long64_t Draw(const char* varexp, const TCut& selection, Option_t* option = "", Long64_t nentries = kMaxEntries, Long64_t firstentry = 0) override;
89 Long64_t Draw(const char* varexp, const char* selection, Option_t* option = "", Long64_t nentries = kMaxEntries, Long64_t firstentry = 0) override; // *MENU*
90 void Draw(Option_t* opt) override { Draw(opt, "", "", kMaxEntries, 0); }
91 Int_t Fill() override { MayNotUse("Fill()"); return -1; }
92 TBranch *FindBranch(const char* name) override;
93 TLeaf *FindLeaf(const char* name) override;
94 TBranch *GetBranch(const char* name) override;
95 bool GetBranchStatus(const char* branchname) const override;
96 Long64_t GetCacheSize() const override { return fTree ? fTree->GetCacheSize() : fCacheSize; }
97 Long64_t GetChainEntryNumber(Long64_t entry) const override;
98 TClusterIterator GetClusterIterator(Long64_t firstentry) override;
99 Int_t GetNtrees() const { return fNtrees; }
100 Long64_t GetEntries() const override;
101 Long64_t GetEntries(const char *sel) override { return TTree::GetEntries(sel); }
102 Int_t GetEntry(Long64_t entry=0, Int_t getall=0) override;
103 Long64_t GetEntryNumber(Long64_t entry) const override;
104 Int_t GetEntryWithIndex(Int_t major, Int_t minor=0) override;
105 TFile *GetFile() const;
106 TLeaf *GetLeaf(const char* branchname, const char* leafname) override;
107 TLeaf *GetLeaf(const char* name) override;
108 TObjArray *GetListOfBranches() override;
109 // Warning, GetListOfFiles returns the list of TChainElements (not the list of files)
110 // see TChain::AddFile to see how to get the corresponding TFile objects
111 TObjArray *GetListOfFiles() const {return fFiles;}
112 TObjArray *GetListOfLeaves() override;
113 const char *GetAlias(const char *aliasName) const override;
114 Double_t GetMaximum(const char *columname) override;
115 Double_t GetMinimum(const char *columname) override;
116 Int_t GetNbranches() override;
117 Long64_t GetReadEntry() const override;
118 TList *GetStatus() const { return fStatus; }
119 TTree *GetTree() const override { return fTree; }
120 Int_t GetTreeNumber() const override { return fTreeNumber; }
121 Long64_t *GetTreeOffset() const { return fTreeOffset; }
123 Double_t GetWeight() const override;
124 bool InPlaceClone(TDirectory *newdirectory, const char *options = "") override;
125 Int_t LoadBaskets(Long64_t maxmemory) override;
126 Long64_t LoadTree(Long64_t entry) override;
127 void Lookup(bool force = false);
128 virtual void Loop(Option_t *option="", Long64_t nentries=kMaxEntries, Long64_t firstentry=0); // *MENU*
129 void ls(Option_t *option="") const override;
130 virtual Long64_t Merge(const char *name, Option_t *option = "");
131 Long64_t Merge(TCollection *list, Option_t *option = "") override;
132 Long64_t Merge(TCollection *list, TFileMergeInfo *info) override;
133 virtual Long64_t Merge(TFile *file, Int_t basketsize, Option_t *option="");
134 void Print(Option_t *option="") const override;
135 Long64_t Process(const char *filename, Option_t *option="", Long64_t nentries=kMaxEntries, Long64_t firstentry=0) override; // *MENU*
136 Long64_t Process(TSelector* selector, Option_t* option = "", Long64_t nentries = kMaxEntries, Long64_t firstentry = 0) override;
137 void RecursiveRemove(TObject *obj) override;
138 void RemoveFriend(TTree*) override;
139 void Reset(Option_t *option="") override;
140 void ResetAfterMerge(TFileMergeInfo *) override;
141 void ResetBranchAddress(TBranch *) override;
142 void ResetBranchAddresses() override;
143 void SavePrimitive (std::ostream &out, Option_t *option="") override;
144 Long64_t Scan(const char *varexp="", const char *selection="", Option_t *option="", Long64_t nentries=kMaxEntries, Long64_t firstentry=0) override; // *MENU*
145 virtual void SetAutoDelete(bool autodel=true);
146 Int_t SetBranchAddress(const char *bname,void *add, TBranch **ptr = nullptr) override;
147 Int_t SetBranchAddress(const char *bname,void *add, TBranch **ptr, TClass *realClass, EDataType datatype, bool isptr) override;
148 Int_t SetBranchAddress(const char *bname,void *add, TClass *realClass, EDataType datatype, bool isptr) override;
149 template <class T> Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr = nullptr) {
150 return TTree::SetBranchAddress<T>(bname, add, ptr);
151 }
152#ifndef R__NO_CLASS_TEMPLATE_SPECIALIZATION
153 // This can only be used when the template overload resolution can distinguish between
154 // T* and T**
155 template <class T> Int_t SetBranchAddress(const char *bname, T *add, TBranch **ptr = nullptr) {
156 return TTree::SetBranchAddress<T>(bname, add, ptr);
157 }
158#endif
159
160 void SetBranchStatus(const char *bname, bool status = true, UInt_t *found = nullptr) override;
161 Int_t SetCacheSize(Long64_t cacheSize = -1) override;
162 void SetDirectory(TDirectory *dir) override;
163 void SetEntryList(TEntryList *elist, Option_t *opt="") override;
164 virtual void SetEntryListFile(const char *filename="", Option_t *opt="");
165 void SetEventList(TEventList *evlist) override;
166 void SetMakeClass(Int_t make) override { TTree::SetMakeClass(make); if (fTree) fTree->SetMakeClass(make);}
167 void SetName(const char *name) override;
168 virtual void SetPacketSize(Int_t size = 100);
169 virtual void SetProof(bool on = true, bool refresh = false, bool gettreeheader = false);
170 void SetWeight(Double_t w=1, Option_t *option="") override;
171 virtual void UseCache(Int_t maxCacheSize = 10, Int_t pageSize = 0);
172
173 ClassDefOverride(TChain,5) //A chain of TTrees
174};
175
176#endif // ROOT_TChain
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
double Double_t
Definition RtypesCore.h:59
long long Long64_t
Definition RtypesCore.h:80
const char Option_t
Definition RtypesCore.h:66
#define BIT(n)
Definition Rtypes.h:85
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
EDataType
Definition TDataType.h:28
Option_t Option_t option
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
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 Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t sel
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Option_t Option_t TPoint TPoint const char mode
char name[80]
Definition TGX11.cxx:110
int nentries
A TTree is a list of TBranches.
Definition TBranch.h:93
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
A chain is a collection of files containing TTree objects.
Definition TChain.h:33
TChain & operator=(const TChain &)
TLeaf * FindLeaf(const char *name) override
See TTree::GetReadEntry().
Definition TChain.cxx:853
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
Definition TChain.h:149
Int_t SetCacheSize(Long64_t cacheSize=-1) override
Set maximum size of the file cache .
Definition TChain.cxx:2436
virtual void CanDeleteRefs(bool flag=true)
When closing a file during the chain processing, the file may be closed with option "R" if flag is se...
Definition TChain.cxx:757
TObjArray * GetListOfBranches() override
Return a pointer to the list of branches of the current tree.
Definition TChain.cxx:1099
Long64_t GetEntryNumber(Long64_t entry) const override
Return entry number corresponding to entry.
Definition TChain.cxx:995
Double_t GetWeight() const override
Return the chain weight.
Definition TChain.cxx:1215
virtual void SetAutoDelete(bool autodel=true)
Set the global branch kAutoDelete bit.
Definition TChain.cxx:2427
bool fCanDeleteRefs
! If true, TProcessIDs are deleted when closing a file
Definition TChain.h:40
void SetEntryList(TEntryList *elist, Option_t *opt="") override
Set the input entry list (processing the entries of the chain will then be limited to the entries in ...
Definition TChain.cxx:2672
Int_t fNtrees
Number of trees.
Definition TChain.h:37
TFriendElement * AddFriend(const char *chainname, const char *dummy="") override
Add a TFriendElement to the list of friends of this chain.
Definition TChain.cxx:656
void DirectoryAutoAdd(TDirectory *) override
Override the TTree::DirectoryAutoAdd behavior: we never auto add.
Definition TChain.cxx:778
TObjArray * GetListOfFiles() const
Definition TChain.h:111
Int_t Fill() override
Fill all branches.
Definition TChain.h:91
~TChain() override
Destructor.
Definition TChain.cxx:173
Int_t LoadBaskets(Long64_t maxmemory) override
Dummy function.
Definition TChain.cxx:1270
void SetMakeClass(Int_t make) override
Set all the branches in this TTree to be in decomposed object mode (also known as MakeClass mode).
Definition TChain.h:166
Long64_t GetEntries(const char *sel) override
Return the number of entries matching the selection.
Definition TChain.h:101
TTree * GetTree() const override
Definition TChain.h:119
void Print(Option_t *option="") const override
Print the header information of each tree in the chain.
Definition TChain.cxx:2211
void RecursiveRemove(TObject *obj) override
Make sure that obj (which is being deleted or will soon be) is no longer referenced by this TTree.
Definition TChain.cxx:2274
const char * GetAlias(const char *aliasName) const override
Returns the expanded value of the alias. Search in the friends if any.
Definition TChain.cxx:874
TChain(const TChain &)
virtual void SetProof(bool on=true, bool refresh=false, bool gettreeheader=false)
Enable/Disable PROOF processing on the current default Proof (gProof).
Definition TChain.cxx:2981
virtual Int_t AddFile(const char *name, Long64_t nentries=TTree::kMaxEntries, const char *tname="")
Add a new file to this chain.
Definition TChain.cxx:468
void Reset(Option_t *option="") override
Resets the state of this chain.
Definition TChain.cxx:2316
void ResetAfterMerge(TFileMergeInfo *) override
Resets the state of this chain after a merge (keep the customization but forget the data).
Definition TChain.cxx:2338
Long64_t * fTreeOffset
[fTreeOffsetLen] Array of variables
Definition TChain.h:39
TBranch * FindBranch(const char *name) override
See TTree::GetReadEntry().
Definition TChain.cxx:832
void ResetBranchAddresses() override
Reset the addresses of the branches.
Definition TChain.cxx:2475
Int_t SetBranchAddress(const char *bname, T *add, TBranch **ptr=nullptr)
Definition TChain.h:155
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save TChain as a C++ statements on output stream out.
Definition TChain.cxx:2355
void SetEventList(TEventList *evlist) override
This function transfroms the given TEventList into a TEntryList.
Definition TChain.cxx:2863
TObjArray * GetListOfLeaves() override
Return a pointer to the list of leaves of the current tree.
Definition TChain.cxx:1122
bool GetBranchStatus(const char *branchname) const override
See TTree::GetReadEntry().
Definition TChain.cxx:914
static constexpr auto kBigNumber
Definition TChain.h:68
TBranch * GetBranch(const char *name) override
Return pointer to the branch name in the current tree.
Definition TChain.cxx:893
Int_t GetEntryWithIndex(Int_t major, Int_t minor=0) override
Return entry corresponding to major and minor number.
Definition TChain.cxx:1028
Long64_t Scan(const char *varexp="", const char *selection="", Option_t *option="", Long64_t nentries=kMaxEntries, Long64_t firstentry=0) override
Loop on tree and print entries passing selection.
Definition TChain.cxx:2412
Double_t GetMaximum(const char *columname) override
Return maximum of column with name columname.
Definition TChain.cxx:1143
void SetWeight(Double_t w=1, Option_t *option="") override
Set chain weight.
Definition TChain.cxx:3028
virtual void Loop(Option_t *option="", Long64_t nentries=kMaxEntries, Long64_t firstentry=0)
Loop on nentries of this chain starting at firstentry. (NOT IMPLEMENTED)
Definition TChain.cxx:1799
TChain * fProofChain
! chain proxy when going to be processed by PROOF
Definition TChain.h:45
Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr=nullptr) override
Set branch address.
Definition TChain.cxx:2504
Long64_t Process(const char *filename, Option_t *option="", Long64_t nentries=kMaxEntries, Long64_t firstentry=0) override
Process all entries in this chain, calling functions in filename.
Definition TChain.cxx:2234
void RemoveFriend(TTree *) override
Remove a friend from the list of friends.
Definition TChain.cxx:2293
virtual Int_t AddFileInfoList(TCollection *list, Long64_t nfiles=TTree::kMaxEntries)
Add all files referenced in the list to the chain.
Definition TChain.cxx:566
TList * GetStatus() const
Definition TChain.h:118
Long64_t * GetTreeOffset() const
Definition TChain.h:121
virtual void CreatePackets()
Initialize the packet descriptor string.
Definition TChain.cxx:765
void ResetBranchAddress(TBranch *) override
Reset the addresses of the branch.
Definition TChain.cxx:2461
TList * fStatus
-> List of active/inactive branches (TChainElement, owned)
Definition TChain.h:44
void SetDirectory(TDirectory *dir) override
Remove reference to this chain from current directory and add reference to new directory dir.
Definition TChain.cxx:2635
Double_t GetMinimum(const char *columname) override
Return minimum of column with name columname.
Definition TChain.cxx:1160
virtual Long64_t Merge(const char *name, Option_t *option="")
Merge all the entries in the chain into a new tree in a new file.
Definition TChain.cxx:1876
TTree * fTree
! Pointer to current tree (Note: We do not own this tree.)
Definition TChain.h:41
virtual Int_t Add(TChain *chain)
Add all files referenced by the passed chain to this chain.
Definition TChain.cxx:219
void ParseTreeFilename(const char *name, TString &filename, TString &treename, TString &query, TString &suffix) const
Get the tree url or filename and other information from the name.
Definition TChain.cxx:2141
bool InPlaceClone(TDirectory *newdirectory, const char *options="") override
Move content to a new file. (NOT IMPLEMENTED for TChain)
Definition TChain.cxx:1233
Int_t GetNbranches() override
Return the number of branches of the current tree.
Definition TChain.cxx:1179
bool fGlobalRegistration
! if true, bypass use of global lists
Definition TChain.h:46
void ReleaseChainProof()
virtual void SetEntryListFile(const char *filename="", Option_t *opt="")
Set the input entry list (processing the entries of the chain will then be limited to the entries in ...
Definition TChain.cxx:2817
Long64_t GetChainEntryNumber(Long64_t entry) const override
Return absolute entry number in the chain.
Definition TChain.cxx:942
Int_t fTreeOffsetLen
Current size of fTreeOffset array.
Definition TChain.h:36
void SetName(const char *name) override
Change the name of this TChain.
Definition TChain.cxx:2938
void ls(Option_t *option="") const override
List the chain.
Definition TChain.cxx:1843
void SetBranchStatus(const char *bname, bool status=true, UInt_t *found=nullptr) override
Set branch status to Process or DoNotProcess.
Definition TChain.cxx:2608
Long64_t LoadTree(Long64_t entry) override
Find the tree which contains entry, and set it as the current tree.
Definition TChain.cxx:1298
TClusterIterator GetClusterIterator(Long64_t firstentry) override
Return an iterator over the cluster of baskets starting at firstentry.
Definition TChain.cxx:931
Int_t GetTreeOffsetLen() const
Definition TChain.h:122
void Browse(TBrowser *) override
Browse the contents of the chain.
Definition TChain.cxx:739
TObjArray * fFiles
-> List of file names containing the trees (TChainElement, owned)
Definition TChain.h:43
Int_t GetNtrees() const
Definition TChain.h:99
Long64_t GetReadEntry() const override
See TTree::GetReadEntry().
Definition TChain.cxx:1194
@ kWithGlobalRegistration
Definition TChain.h:71
@ kWithoutGlobalRegistration
Definition TChain.h:71
TFile * fFile
! Pointer to current file (We own the file).
Definition TChain.h:42
virtual void UseCache(Int_t maxCacheSize=10, Int_t pageSize=0)
Dummy function kept for back compatibility.
Definition TChain.cxx:3084
void InvalidateCurrentTree()
Set the TTree to be reloaded as soon as possible.
Definition TChain.cxx:1252
Long64_t GetEntries() const override
Return the total number of entries in the chain.
Definition TChain.cxx:952
TFile * GetFile() const
Return a pointer to the current file.
Definition TChain.cxx:1039
Int_t GetEntry(Long64_t entry=0, Int_t getall=0) override
Get entry from the file to memory.
Definition TChain.cxx:976
virtual void SetPacketSize(Int_t size=100)
Set number of entries per packet for parallel root.
Definition TChain.cxx:2960
Int_t fTreeNumber
! Current Tree number in fTreeOffset table
Definition TChain.h:38
Int_t GetTreeNumber() const override
Definition TChain.h:120
Long64_t GetCacheSize() const override
Definition TChain.h:96
void Lookup(bool force=false)
Check / locate the files in the chain.
Definition TChain.cxx:1729
void Draw(Option_t *opt) override
Default Draw method for all objects.
Definition TChain.h:90
TLeaf * GetLeaf(const char *branchname, const char *leafname) override
Return a pointer to the leaf name in the current tree.
Definition TChain.cxx:1052
EStatusBits
Definition TChain.h:60
@ kProofLite
Definition TChain.h:64
@ kAutoDelete
Definition TChain.h:62
@ kProofUptodate
Definition TChain.h:63
@ kGlobalWeight
Definition TChain.h:61
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
Collection abstract base class.
Definition TCollection.h:65
A specialized string object used for TTree selections.
Definition TCut.h:25
Describe directory structure in memory.
Definition TDirectory.h:45
A List of entry numbers in a TTree or TChain.
Definition TEntryList.h:26
A TEventList object is a list of selected events (entries) in a TTree.
Definition TEventList.h:31
A ROOT file is composed of a header, followed by consecutive data records (TKey instances) with a wel...
Definition TFile.h:53
A TFriendElement TF describes a TTree object TF in a file.
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition TLeaf.h:57
A doubly linked list.
Definition TList.h:38
An array of TObjects.
Definition TObjArray.h:31
Mother of all ROOT objects.
Definition TObject.h:41
void MayNotUse(const char *method) const
Use this method to signal that a method (defined in a base class) may not be called in a derived clas...
Definition TObject.cxx:1029
A TSelector object is used by the TTree::Draw, TTree::Scan, TTree::Process to navigate in a TTree and...
Definition TSelector.h:31
Basic string class.
Definition TString.h:139
A TTree represents a columnar dataset.
Definition TTree.h:79
virtual void SetMakeClass(Int_t make)
Set all the branches in this TTree to be in decomposed object mode (also known as MakeClass mode).
Definition TTree.cxx:9167
virtual Long64_t GetEntries() const
Definition TTree.h:463
Long64_t fCacheSize
! Maximum size of file buffers
Definition TTree.h:105
virtual Long64_t GetCacheSize() const
Definition TTree.h:453
static constexpr Long64_t kMaxEntries
Definition TTree.h:229
th1 Draw()