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 bool fGlobalRegistration; ///<! if true, bypass use of global lists
46
47private:
48 TChain(const TChain&); // not implemented
49 TChain& operator=(const TChain&); // not implemented
50 void
53
54protected:
56
57 // Called when setting the branch address of friends. In the case of TChain, the TChainElement for branch
58 // 'bname' is created calling IsDelayed, to avoid missing branch errors when connecting it to the trees
59 // of this chain
60 Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr, TClass *realClass, EDataType datatype,
61 bool isptr, bool suppressMissingBranchError) override;
62
63public:
64 // TChain constants
69
70 // This used to be 1234567890, if user code hardcoded this number, the user code will need to change.
71 static constexpr auto kBigNumber = TTree::kMaxEntries;
72
73public:
75
77 TChain(const char *name, const char *title = "", Mode mode = kWithGlobalRegistration);
78 ~TChain() override;
79
80 virtual Int_t Add(TChain* chain);
81 virtual Int_t Add(const char* name, Long64_t nentries = TTree::kMaxEntries);
82 virtual Int_t AddFile(const char* name, Long64_t nentries = TTree::kMaxEntries, const char* tname = "");
84 TFriendElement *AddFriend(const char* chainname, const char* dummy = "") override;
85 TFriendElement *AddFriend(const char* chainname, TFile* dummy) override;
86 TFriendElement *AddFriend(TTree* chain, const char* alias = "", bool warn = false) override;
87 void Browse(TBrowser*) override;
88 virtual void CanDeleteRefs(bool flag = true);
89 virtual void CreatePackets();
90 void DirectoryAutoAdd(TDirectory *) override;
91 Long64_t Draw(const char* varexp, const TCut& selection, Option_t* option = "", Long64_t nentries = kMaxEntries, Long64_t firstentry = 0) override;
92 Long64_t Draw(const char* varexp, const char* selection, Option_t* option = "", Long64_t nentries = kMaxEntries, Long64_t firstentry = 0) override; // *MENU*
93 void Draw(Option_t* opt) override { Draw(opt, "", "", kMaxEntries, 0); }
94 Int_t Fill() override { MayNotUse("Fill()"); return -1; }
95 TBranch *FindBranch(const char* name) override;
96 TLeaf *FindLeaf(const char* name) override;
97 TBranch *GetBranch(const char* name) override;
98 bool GetBranchStatus(const char* branchname) const override;
99 Long64_t GetCacheSize() const override { return fTree ? fTree->GetCacheSize() : fCacheSize; }
101 TClusterIterator GetClusterIterator(Long64_t firstentry) override;
102 Int_t GetNtrees() const { return fNtrees; }
103 Long64_t GetEntries() const override;
104 Long64_t GetEntries(const char *sel) override { return TTree::GetEntries(sel); }
105 Int_t GetEntry(Long64_t entry=0, Int_t getall=0) override;
106 Long64_t GetEntryNumber(Long64_t entry) const override;
108 TFile *GetFile() const;
109 TLeaf *GetLeaf(const char* branchname, const char* leafname) override;
110 TLeaf *GetLeaf(const char* name) override;
111 TObjArray *GetListOfBranches() override;
112 // Warning, GetListOfFiles returns the list of TChainElements (not the list of files)
113 // see TChain::AddFile to see how to get the corresponding TFile objects
114 TObjArray *GetListOfFiles() const {return fFiles;}
115 TObjArray *GetListOfLeaves() override;
116 const char *GetAlias(const char *aliasName) const override;
117 Double_t GetMaximum(const char *columname) override;
118 Double_t GetMinimum(const char *columname) override;
119 Int_t GetNbranches() override;
120 Long64_t GetReadEntry() const override;
121 TList *GetStatus() const { return fStatus; }
122 TTree *GetTree() const override { return fTree; }
123 Int_t GetTreeNumber() const override { return fTreeNumber; }
124 Long64_t *GetTreeOffset() const { return fTreeOffset; }
126 Double_t GetWeight() const override;
127 bool InPlaceClone(TDirectory *newdirectory, const char *options = "") override;
130 void Lookup(bool force = false);
131 virtual void Loop(Option_t *option="", Long64_t nentries=kMaxEntries, Long64_t firstentry=0); // *MENU*
132 void ls(Option_t *option="") const override;
133 virtual Long64_t Merge(const char *name, Option_t *option = "");
134 Long64_t Merge(TCollection *list, Option_t *option = "") override;
135 Long64_t Merge(TCollection *list, TFileMergeInfo *info) override;
136 virtual Long64_t Merge(TFile *file, Int_t basketsize, Option_t *option="");
137 void Print(Option_t *option="") const override;
138 Long64_t Process(const char *filename, Option_t *option="", Long64_t nentries=kMaxEntries, Long64_t firstentry=0) override; // *MENU*
140 void RecursiveRemove(TObject *obj) override;
141 void RemoveFriend(TTree*) override;
142 void Reset(Option_t *option="") override;
143 void ResetAfterMerge(TFileMergeInfo *) override;
144 void ResetBranchAddress(TBranch *) override;
145 void ResetBranchAddresses() override;
146 void SavePrimitive (std::ostream &out, Option_t *option="") override;
147 Long64_t Scan(const char *varexp="", const char *selection="", Option_t *option="", Long64_t nentries=kMaxEntries, Long64_t firstentry=0) override; // *MENU*
148 virtual void SetAutoDelete(bool autodel=true);
149 Int_t SetBranchAddress(const char *bname,void *add, TBranch **ptr = nullptr) override;
150 Int_t SetBranchAddress(const char *bname,void *add, TBranch **ptr, TClass *realClass, EDataType datatype, bool isptr) override;
151 Int_t SetBranchAddress(const char *bname,void *add, TClass *realClass, EDataType datatype, bool isptr) override;
152 template <class T> Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr = nullptr) {
153 return TTree::SetBranchAddress<T>(bname, add, ptr);
154 }
155#ifndef R__NO_CLASS_TEMPLATE_SPECIALIZATION
156 // This can only be used when the template overload resolution can distinguish between
157 // T* and T**
158 template <class T> Int_t SetBranchAddress(const char *bname, T *add, TBranch **ptr = nullptr) {
159 return TTree::SetBranchAddress<T>(bname, add, ptr);
160 }
161#endif
162
163 void SetBranchStatus(const char *bname, bool status = true, UInt_t *found = nullptr) override;
164 Int_t SetCacheSize(Long64_t cacheSize = -1) override;
165 void SetDirectory(TDirectory *dir) override;
166 void SetEntryList(TEntryList *elist, Option_t *opt="") override;
167 virtual void SetEntryListFile(const char *filename="", Option_t *opt="");
168 void SetEventList(TEventList *evlist) override;
169 void SetMakeClass(Int_t make) override { TTree::SetMakeClass(make); if (fTree) fTree->SetMakeClass(make);}
170 void SetName(const char *name) override;
171 virtual void SetPacketSize(Int_t size = 100);
172 void SetWeight(Double_t w=1, Option_t *option="") override;
173 virtual void UseCache(Int_t maxCacheSize = 10, Int_t pageSize = 0);
174
175 ClassDefOverride(TChain,5) //A chain of TTrees
176};
177
178#endif // ROOT_TChain
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:60
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
#define BIT(n)
Definition Rtypes.h:91
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
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 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:821
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
Definition TChain.h:152
Int_t SetCacheSize(Long64_t cacheSize=-1) override
Set maximum size of the file cache .
Definition TChain.cxx:2416
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:748
TObjArray * GetListOfBranches() override
Return a pointer to the list of branches of the current tree.
Definition TChain.cxx:1041
Long64_t GetEntryNumber(Long64_t entry) const override
Return entry number corresponding to entry.
Definition TChain.cxx:948
Double_t GetWeight() const override
Return the chain weight.
Definition TChain.cxx:1174
virtual void SetAutoDelete(bool autodel=true)
Set the global branch kAutoDelete bit.
Definition TChain.cxx:2407
bool fCanDeleteRefs
! If true, TProcessIDs are deleted when closing a file
Definition TChain.h:40
Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr, TClass *realClass, EDataType datatype, bool isptr, bool suppressMissingBranchError) override
Definition TChain.cxx:3036
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:2683
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:659
void DirectoryAutoAdd(TDirectory *) override
Override the TTree::DirectoryAutoAdd behavior: we never auto add.
Definition TChain.cxx:769
TObjArray * GetListOfFiles() const
Definition TChain.h:114
Int_t Fill() override
Fill all branches.
Definition TChain.h:94
~TChain() override
Destructor.
Definition TChain.cxx:165
Int_t LoadBaskets(Long64_t maxmemory) override
Dummy function.
Definition TChain.cxx:1229
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:169
Long64_t GetEntries(const char *sel) override
Return the number of entries matching the selection.
Definition TChain.h:104
TTree * GetTree() const override
Definition TChain.h:122
void Print(Option_t *option="") const override
Print the header information of each tree in the chain.
Definition TChain.cxx:2213
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:2258
const char * GetAlias(const char *aliasName) const override
Returns the expanded value of the alias. Search in the friends if any.
Definition TChain.cxx:836
TChain(const TChain &)
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:478
void Reset(Option_t *option="") override
Resets the state of this chain.
Definition TChain.cxx:2296
void ResetAfterMerge(TFileMergeInfo *) override
Resets the state of this chain after a merge (keep the customization but forget the data).
Definition TChain.cxx:2318
Long64_t * fTreeOffset
[fTreeOffsetLen] Array of variables
Definition TChain.h:39
TBranch * FindBranch(const char *name) override
See TTree::GetReadEntry().
Definition TChain.cxx:806
void ResetBranchAddresses() override
Reset the addresses of the branches.
Definition TChain.cxx:2455
Int_t SetBranchAddress(const char *bname, T *add, TBranch **ptr=nullptr)
Definition TChain.h:158
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save TChain as a C++ statements on output stream out.
Definition TChain.cxx:2335
void SetEventList(TEventList *evlist) override
This function transfroms the given TEventList into a TEntryList.
Definition TChain.cxx:2867
TObjArray * GetListOfLeaves() override
Return a pointer to the list of leaves of the current tree.
Definition TChain.cxx:1058
bool GetBranchStatus(const char *branchname) const override
See TTree::GetReadEntry().
Definition TChain.cxx:870
static constexpr auto kBigNumber
Definition TChain.h:71
TBranch * GetBranch(const char *name) override
Return pointer to the branch name in the current tree.
Definition TChain.cxx:855
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:2392
Double_t GetMaximum(const char *columname) override
Return maximum of column with name columname.
Definition TChain.cxx:1073
void SetWeight(Double_t w=1, Option_t *option="") override
Set chain weight.
Definition TChain.cxx:2976
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:1801
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:2236
void RemoveFriend(TTree *) override
Remove a friend from the list of friends.
Definition TChain.cxx:2277
virtual Int_t AddFileInfoList(TCollection *list, Long64_t nfiles=TTree::kMaxEntries)
Add all files referenced in the list to the chain.
Definition TChain.cxx:573
TList * GetStatus() const
Definition TChain.h:121
Long64_t * GetTreeOffset() const
Definition TChain.h:124
virtual void CreatePackets()
Initialize the packet descriptor string.
Definition TChain.cxx:756
void ResetBranchAddress(TBranch *) override
Reset the addresses of the branch.
Definition TChain.cxx:2441
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:2646
Double_t GetMinimum(const char *columname) override
Return minimum of column with name columname.
Definition TChain.cxx:1108
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:1878
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:210
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:2143
bool InPlaceClone(TDirectory *newdirectory, const char *options="") override
Move content to a new file. (NOT IMPLEMENTED for TChain)
Definition TChain.cxx:1192
Int_t GetNbranches() override
Return the number of branches of the current tree.
Definition TChain.cxx:1145
bool fGlobalRegistration
! if true, bypass use of global lists
Definition TChain.h:45
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:2821
Long64_t GetChainEntryNumber(Long64_t entry) const override
Return absolute entry number in the chain.
Definition TChain.cxx:891
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:2925
void ls(Option_t *option="") const override
List the chain.
Definition TChain.cxx:1845
void SetBranchStatus(const char *bname, bool status=true, UInt_t *found=nullptr) override
Set branch status to Process or DoNotProcess.
Definition TChain.cxx:2619
Long64_t LoadTree(Long64_t entry) override
Find the tree which contains entry, and set it as the current tree.
Definition TChain.cxx:1339
TClusterIterator GetClusterIterator(Long64_t firstentry) override
Return an iterator over the cluster of baskets starting at firstentry.
Definition TChain.cxx:880
Int_t GetTreeOffsetLen() const
Definition TChain.h:125
void Browse(TBrowser *) override
Browse the contents of the chain.
Definition TChain.cxx:730
TObjArray * fFiles
-> List of file names containing the trees (TChainElement, owned)
Definition TChain.h:43
Int_t GetNtrees() const
Definition TChain.h:102
Long64_t GetReadEntry() const override
See TTree::GetReadEntry().
Definition TChain.cxx:1160
@ kWithGlobalRegistration
Definition TChain.h:74
@ kWithoutGlobalRegistration
Definition TChain.h:74
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:3032
void InvalidateCurrentTree()
Set the TTree to be reloaded as soon as possible.
Definition TChain.cxx:1211
Long64_t GetEntries() const override
Return the total number of entries in the chain.
Definition TChain.cxx:901
TFile * GetFile() const
Return a pointer to the current file.
Definition TChain.cxx:993
Int_t GetEntry(Long64_t entry=0, Int_t getall=0) override
Get entry from the file to memory.
Definition TChain.cxx:929
virtual void SetPacketSize(Int_t size=100)
Set number of entries per packet for parallel root.
Definition TChain.cxx:2947
Int_t fTreeNumber
! Current Tree number in fTreeOffset table
Definition TChain.h:38
Int_t GetTreeNumber() const override
Definition TChain.h:123
Long64_t GetCacheSize() const override
Definition TChain.h:99
void Lookup(bool force=false)
Check / locate the files in the chain.
Definition TChain.cxx:1731
void Draw(Option_t *opt) override
Default Draw method for all objects.
Definition TChain.h:93
Long64_t RefreshFriendAddresses()
Refresh branch/leaf addresses of friend trees.
Definition TChain.cxx:1241
TLeaf * GetLeaf(const char *branchname, const char *leafname) override
Return a pointer to the leaf name in the current tree.
Definition TChain.cxx:1006
Int_t GetEntryWithIndex(Long64_t major, Long64_t minor=0) override
Return entry corresponding to major and minor number.
Definition TChain.cxx:982
EStatusBits
Definition TChain.h:65
@ kAutoDelete
Definition TChain.h:67
@ kGlobalWeight
Definition TChain.h:66
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
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
<div class="legacybox"><h2>Legacy Code</h2> TEventList is a legacy interface: there will be no bug fi...
Definition TEventList.h:31
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:131
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:1134
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:138
A TTree represents a columnar dataset.
Definition TTree.h:89
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:9396
virtual Long64_t GetEntries() const
Definition TTree.h:500
Long64_t fCacheSize
! Maximum size of file buffers
Definition TTree.h:115
virtual Long64_t GetCacheSize() const
Definition TTree.h:490
static constexpr Long64_t kMaxEntries
Definition TTree.h:263
th1 Draw()