Logo ROOT   6.08/07
Reference Guide
TBranchElement.h
Go to the documentation of this file.
1 // @(#)root/tree:$Id$
2 // Author: Rene Brun 14/01/2001
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_TBranchElement
13 #define ROOT_TBranchElement
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TBranchElement //
19 // //
20 // A Branch for the case of an object. //
21 //////////////////////////////////////////////////////////////////////////
22 
23 
24 #ifndef ROOT_TBranch
25 #include "TBranch.h"
26 #endif
27 
28 #ifndef ROOT_TClassRef
29 #include "TClassRef.h"
30 #endif
31 
32 #ifndef ROOT_TTree
33 #include "TTree.h"
34 #endif
35 
36 #ifndef ROOT_TError
37 #include "TError.h"
38 #endif
39 
40 #include <vector>
41 
42 class TFolder;
43 class TStreamerInfo;
47 class TVirtualArray;
48 
49 namespace TStreamerInfoActions { class TActionSequence; }
50 
51 
52 class TBranchElement : public TBranch {
53 
54 // Friends
55  friend class TTreeCloner;
56 
57 // Types
58 protected:
59  enum {
60  kBranchFolder = BIT(14),
61  kDeleteObject = BIT(16), ///< We are the owner of fObject.
62  kCache = BIT(18), ///< Need to pushd/pop fOnfileObject.
63  kOwnOnfileObj = BIT(19), ///< We are the owner of fOnfileObject.
64  kAddressSet = BIT(20), ///< The addressing set have been called for this branch
65  kMakeClass = BIT(21), ///< This branch has been switched to using the MakeClass Mode
66  kDecomposedObj= BIT(21) ///< More explicit alias for kMakeClass.
67  };
68 
69  // Note on fType values:
70  // -1 unsplit object with custom streamer at time of writing
71  // 0 unsplit object with default streamer at time of writing
72  // OR simple data member of split object (fID==-1 for the former)
73  // 1 base class of a split object.
74  // 2 class typed data member of a split object
75  // 3 branch count of a split TClonesArray
76  // 31 data member of the content of a split TClonesArray
77  // 4 branch count of a split STL Collection.
78  // 41 data member of the content of a split STL collection
79 
80 
81 // Data Members
82 protected:
83  TString fClassName; ///< Class name of referenced object
84  TString fParentName; ///< Name of parent class
85  TString fClonesName; ///< Name of class in TClonesArray (if any)
86  TVirtualCollectionProxy *fCollProxy; ///<! collection interface (if any)
87  UInt_t fCheckSum; ///< CheckSum of class
88  Version_t fClassVersion; ///< Version number of class
89  Int_t fID; ///< element serial number in fInfo
90  Int_t fType; ///< branch type
91  Int_t fStreamerType; ///< branch streamer type
92  Int_t fMaximum; ///< Maximum entries for a TClonesArray or variable array
93  Int_t fSTLtype; ///<! STL container type
94  Int_t fNdata; ///<! Number of data in this branch
95  TBranchElement *fBranchCount; ///< pointer to primary branchcount branch
96  TBranchElement *fBranchCount2; ///< pointer to secondary branchcount branch
97  TStreamerInfo *fInfo; ///<! Pointer to StreamerInfo
98  char *fObject; ///<! Pointer to object at *fAddress
99  TVirtualArray *fOnfileObject; ///<! Place holder for the onfile representation of data members.
100  Bool_t fInit; ///<! Initialization flag for branch assignment
101  Bool_t fInitOffsets; ///<! Initialization flag to not endlessly recalculate offsets
102  TClassRef fTargetClass; ///<! Reference to the target in-memory class
103  TClassRef fCurrentClass; ///<! Reference to current (transient) class definition
104  TClassRef fParentClass; ///<! Reference to class definition in fParentName
105  TClassRef fBranchClass; ///<! Reference to class definition in fClassName
106  TClassRef fClonesClass; ///<! Reference to class definition in fClonesName
107  Int_t *fBranchOffset; ///<! Sub-Branch offsets with respect to current transient class
108  Int_t fBranchID; ///<! ID number assigned by a TRefTable.
109  std::vector<Int_t> fIDs; ///<! List of the serial number of all the StreamerInfo to be used.
110  TStreamerInfoActions::TActionSequence *fReadActionSequence; ///<! Set of actions to be executed to extract the data from the basket.
111  TStreamerInfoActions::TActionSequence *fFillActionSequence; ///<! Set of actions to be executed to write the data to the basket.
112  TVirtualCollectionIterators *fIterators; ///<! holds the iterators when the branch is of fType==4.
113  TVirtualCollectionIterators *fWriteIterators; ///<! holds the read (non-staging) iterators when the branch is of fType==4 and associative containers.
114  TVirtualCollectionPtrIterators *fPtrIterators; ///<! holds the iterators when the branch is of fType==4 and it is a split collection of pointers.
115 
116 // Not implemented
117 private:
118  TBranchElement(const TBranchElement&); // not implemented
119  TBranchElement& operator=(const TBranchElement&); // not implemented
120 
121  static void SwitchContainer(TObjArray *);
122 
123 // Implementation use only functions.
124 protected:
125  void BuildTitle(const char* name);
126  virtual void InitializeOffsets();
127  virtual void InitInfo();
128  Bool_t IsMissingCollection() const;
129  TClass *GetParentClass(); // Class referenced by fParentName
130  TStreamerInfo *GetInfoImp() const;
131  void ReleaseObject();
132  void SetBranchCount(TBranchElement* bre);
133  void SetBranchCount2(TBranchElement* bre) { fBranchCount2 = bre; }
134  Int_t Unroll(const char* name, TClass* cltop, TClass* cl, char* ptr, Int_t basketsize, Int_t splitlevel, Int_t btype);
135  inline void ValidateAddress() const;
136 
137  void Init(TTree *tree, TBranch *parent, const char* name, TStreamerInfo* sinfo, Int_t id, char* pointer, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t btype = 0);
138  void Init(TTree *tree, TBranch *parent, const char* name, TClonesArray* clones, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = -1);
139  void Init(TTree *tree, TBranch *parent, const char* name, TVirtualCollectionProxy* cont, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = -1);
140 
141  void ReadLeavesImpl(TBuffer& b);
142  void ReadLeavesMakeClass(TBuffer& b);
143  void ReadLeavesCollection(TBuffer& b);
144  void ReadLeavesCollectionSplitPtrMember(TBuffer& b);
145  void ReadLeavesCollectionSplitVectorPtrMember(TBuffer& b);
146  void ReadLeavesCollectionMember(TBuffer& b);
147  void ReadLeavesClones(TBuffer& b);
148  void ReadLeavesClonesMember(TBuffer& b);
149  void ReadLeavesCustomStreamer(TBuffer& b);
150  void ReadLeavesMember(TBuffer& b);
151  void ReadLeavesMemberBranchCount(TBuffer& b);
152  void ReadLeavesMemberCounter(TBuffer& b);
153  void SetReadLeavesPtr();
154  void SetReadActionSequence();
155  void SetupAddressesImpl();
156 
157  void FillLeavesImpl(TBuffer& b);
158  void FillLeavesMakeClass(TBuffer& b);
159  void FillLeavesCollection(TBuffer& b);
160  void FillLeavesCollectionSplitVectorPtrMember(TBuffer& b);
161  void FillLeavesCollectionSplitPtrMember(TBuffer& b);
162  void FillLeavesCollectionMember(TBuffer& b);
163  void FillLeavesAssociativeCollectionMember(TBuffer& b);
164  void FillLeavesClones(TBuffer& b);
165  void FillLeavesClonesMember(TBuffer& b);
166  void FillLeavesCustomStreamer(TBuffer& b);
167  void FillLeavesMemberBranchCount(TBuffer& b);
168  void FillLeavesMemberCounter(TBuffer& b);
169  void FillLeavesMember(TBuffer& b);
170  void SetFillLeavesPtr();
171  void SetFillActionSequence();
172 // Public Interface.
173 public:
174  TBranchElement();
175  TBranchElement(TTree *tree, const char* name, TStreamerInfo* sinfo, Int_t id, char* pointer, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t btype = 0);
176  TBranchElement(TTree *tree, const char* name, TClonesArray* clones, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = -1);
177  TBranchElement(TTree *tree, const char* name, TVirtualCollectionProxy* cont, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = -1);
178  TBranchElement(TBranch *parent, const char* name, TStreamerInfo* sinfo, Int_t id, char* pointer, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t btype = 0);
179  TBranchElement(TBranch *parent, const char* name, TClonesArray* clones, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = -1);
180  TBranchElement(TBranch *parent, const char* name, TVirtualCollectionProxy* cont, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = -1);
181 
182  virtual ~TBranchElement();
183 
184  virtual void Browse(TBrowser* b);
185  virtual Int_t Fill();
186  virtual TBranch *FindBranch(const char *name);
187  virtual TLeaf *FindLeaf(const char *name);
188  virtual char *GetAddress() const;
189  TBranchElement *GetBranchCount() const { return fBranchCount; }
190  TBranchElement *GetBranchCount2() const { return fBranchCount2; }
191  Int_t *GetBranchOffset() const { return fBranchOffset; }
192  UInt_t GetCheckSum() { return fCheckSum; }
193  virtual const char *GetClassName() const { return fClassName.Data(); }
194  virtual TClass *GetClass() const { return fBranchClass; }
195  virtual const char *GetClonesName() const { return fClonesName.Data(); }
196  TVirtualCollectionProxy *GetCollectionProxy();
197  TClass *GetCurrentClass(); // Class referenced by transient description
198  virtual Int_t GetEntry(Long64_t entry = 0, Int_t getall = 0);
199  virtual Int_t GetExpectedType(TClass *&clptr,EDataType &type);
200  const char *GetIconName() const;
201  Int_t GetID() const { return fID; }
202  TStreamerInfo *GetInfo() const;
203  Bool_t GetMakeClass() const;
204  char *GetObject() const;
205  virtual const char *GetParentName() const { return fParentName.Data(); }
206  virtual Int_t GetMaximum() const;
207  Int_t GetNdata() const { return fNdata; }
208  Int_t GetType() const { return fType; }
209  Int_t GetStreamerType() const { return fStreamerType; }
210  virtual TClass *GetTargetClass() { return fTargetClass; }
211  virtual const char *GetTypeName() const;
212  Double_t GetValue(Int_t i, Int_t len, Bool_t subarr = kFALSE) const { return GetTypedValue<Double_t>(i, len, subarr); }
213  template<typename T > T GetTypedValue(Int_t i, Int_t len, Bool_t subarr = kFALSE) const;
214  virtual void *GetValuePointer() const;
215  Int_t GetClassVersion() { return fClassVersion; }
216  Bool_t IsBranchFolder() const { return TestBit(kBranchFolder); }
217  Bool_t IsFolder() const;
218  virtual Bool_t IsObjectOwner() const { return TestBit(kDeleteObject); }
219  virtual Bool_t Notify() { if (fAddress) { ResetAddress(); } return 1; }
220  virtual void Print(Option_t* option = "") const;
221  void PrintValue(Int_t i) const;
222  virtual void Reset(Option_t* option = "");
223  virtual void ResetAfterMerge(TFileMergeInfo *);
224  virtual void ResetAddress();
225  virtual void ResetDeleteObject();
226  virtual void SetAddress(void* addobj);
227  virtual Bool_t SetMakeClass(Bool_t decomposeObj = kTRUE);
228  virtual void SetObject(void *objadd);
229  virtual void SetBasketSize(Int_t buffsize);
230  virtual void SetBranchFolder() { SetBit(kBranchFolder); }
231  virtual void SetClassName(const char* name) { fClassName = name; }
232  virtual void SetOffset(Int_t offset);
233  inline void SetParentClass(TClass* clparent);
234  virtual void SetParentName(const char* name) { fParentName = name; }
235  virtual void SetTargetClass(const char *name);
236  virtual void SetupAddresses();
237  virtual void SetType(Int_t btype) { fType = btype; }
238  virtual void UpdateFile();
239 
241  kLeafNode = 0,
242  kBaseClassNode = 1, // -- We are a base class element.
243  // Note: This does not include an STL container class which is
244  // being used as a base class because the streamer element
245  // in that case is not the base streamer element it is the
246  // STL streamer element.
247  kObjectNode = 2,
248  kClonesNode = 3,
249  kSTLNode = 4,
250  kClonesMemberNode = 31,
251  kSTLMemberNode = 41
252  };
253 
254  ClassDef(TBranchElement,10) // Branch in case of an object
255 };
256 
258 {
259  fParentClass = clparent;
260  fParentName = clparent ? clparent->GetName() : "";
261 }
262 
264 {
265  // Check to see if the user changed the object pointer without telling us.
266 
267  if (fID < 0) {
268  // We are a top-level branch.
269  if (!fTree->GetMakeClass() && fAddress && (*((char**) fAddress) != fObject)) {
270  // The semantics of fAddress and fObject are violated.
271  // Assume the user changed the pointer on us.
272  // Note: The cast is here because we want to be able to
273  // be called from the constant get functions.
274 
275  // FIXME: Disable the check/warning TTree until we add a missing interface.
276  if (TestBit(kDeleteObject)) {
277  // This should never happen!
278  Error("ValidateAddress", "We owned an object whose address changed! our ptr: %p new ptr: %p",
279  (void*)fObject, (void*)*((char**) fAddress));
280  const_cast<TBranchElement*>(this)->ResetBit(kDeleteObject);
281  }
282  const_cast<TBranchElement*>(this)->SetAddress(fAddress);
283  }
284  }
285 }
286 
287 #endif // ROOT_TBranchElement
Describe Streamer information for one class version.
Definition: TStreamerInfo.h:47
TClassRef fTargetClass
! Reference to the target in-memory class
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition: TLeaf.h:37
TBranchElement * GetBranchCount2() const
A TFolder object is a collection of objects and folders.
Definition: TFolder.h:32
An array of TObjects.
Definition: TObjArray.h:39
TBranchElement * fBranchCount2
pointer to secondary branchcount branch
long long Long64_t
Definition: RtypesCore.h:69
Int_t GetType() const
short Version_t
Definition: RtypesCore.h:61
virtual TClass * GetTargetClass()
const char Option_t
Definition: RtypesCore.h:62
Double_t GetValue(Int_t i, Int_t len, Bool_t subarr=kFALSE) const
double T(double x)
Definition: ChebyshevPol.h:34
TString fParentName
Name of parent class.
Int_t * GetBranchOffset() const
#define BIT(n)
Definition: Rtypes.h:120
Int_t GetNdata() const
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
UInt_t fCheckSum
CheckSum of class.
TStreamerInfoActions::TActionSequence * fFillActionSequence
! Set of actions to be executed to write the data to the basket.
Bool_t fInit
! Initialization flag for branch assignment
TBranchElement * GetBranchCount() const
virtual void SetBranchFolder()
Int_t fNdata
! Number of data in this branch
TTreeCloner & operator=(const TTreeCloner &)=delete
TVirtualArray * fOnfileObject
! Place holder for the onfile representation of data members.
#define ClassDef(name, id)
Definition: Rtypes.h:254
TStreamerInfoActions::TActionSequence * fReadActionSequence
! Set of actions to be executed to extract the data from the basket.
Int_t fMaximum
Maximum entries for a TClonesArray or variable array.
void Init(TClassEdit::TInterpreterLookupHelper *helper)
Definition: TClassEdit.cxx:119
Int_t * fBranchOffset
! Sub-Branch offsets with respect to current transient class
TVirtualCollectionProxy * fCollProxy
! collection interface (if any)
Int_t GetID() const
Version_t fClassVersion
Version number of class.
TString fClassName
Class name of referenced object.
void Error(const char *location, const char *msgfmt,...)
virtual const char * GetClonesName() const
TString fClonesName
Name of class in TClonesArray (if any)
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:41
Int_t fID
element serial number in fInfo
void SetParentClass(TClass *clparent)
void ValidateAddress() const
Small helper class to generically acquire and release iterators.
Wrapper around an object and giving indirect access to its content even if the object is not of a cla...
Definition: TVirtualArray.h:26
virtual void SetType(Int_t btype)
TClassRef fParentClass
! Reference to class definition in fParentName
TBranchElement * fBranchCount
pointer to primary branchcount branch
Int_t fStreamerType
branch streamer type
unsigned int UInt_t
Definition: RtypesCore.h:42
TClassRef fCurrentClass
! Reference to current (transient) class definition
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
TClassRef fBranchClass
! Reference to class definition in fClassName
void Reset(Detail::TBranchProxy *x)
A Branch for the case of an object.
PyObject * fType
Int_t fSTLtype
! STL container type
void Print(std::ostream &os, const OptionType &opt)
virtual void SetClassName(const char *name)
double Double_t
Definition: RtypesCore.h:55
virtual const char * GetClassName() const
Return the name of the user class whose content is stored in this branch, if any. ...
int type
Definition: TGX11.cxx:120
void SetBranchCount2(TBranchElement *bre)
Int_t fBranchID
! ID number assigned by a TRefTable.
std::vector< Int_t > fIDs
! List of the serial number of all the StreamerInfo to be used.
EDataType
Definition: TDataType.h:30
TClassRef fClonesClass
! Reference to class definition in fClonesName
UInt_t GetCheckSum()
Bool_t IsBranchFolder() const
Bool_t fInitOffsets
! Initialization flag to not endlessly recalculate offsets
TClassRef is used to implement a permanent reference to a TClass object.
Definition: TClassRef.h:33
An array of clone (identical) objects.
Definition: TClonesArray.h:32
Class implementing or helping the various TTree cloning method.
Definition: TTreeCloner.h:40
Int_t GetClassVersion()
TVirtualCollectionIterators * fWriteIterators
! holds the read (non-staging) iterators when the branch is of fType==4 and associative containers...
Int_t fType
branch type
virtual TClass * GetClass() const
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
TVirtualCollectionIterators * fIterators
! holds the iterators when the branch is of fType==4.
virtual const char * GetParentName() const
Definition: tree.py:1
char * fObject
! Pointer to object at *fAddress
A TTree object has a header with a name and a title.
Definition: TTree.h:98
virtual void SetParentName(const char *name)
A TTree is a list of TBranches.
Definition: TBranch.h:58
const Bool_t kTRUE
Definition: Rtypes.h:91
TVirtualCollectionPtrIterators * fPtrIterators
! holds the iterators when the branch is of fType==4 and it is a split collection of pointers...
virtual Bool_t Notify()
This method must be overridden to handle object notification.
Int_t GetStreamerType() const
virtual Bool_t IsObjectOwner() const
TStreamerInfo * fInfo
! Pointer to StreamerInfo
char name[80]
Definition: TGX11.cxx:109
const char * Data() const
Definition: TString.h:349