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