Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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;
36 class TVirtualCollectionProxy;
37 class TVirtualCollectionIterators;
38 class TVirtualCollectionPtrIterators;
39 class TVirtualArray;
40 
41 #include "TStreamerInfoActions.h"
42 
43 class TBranchElement : public TBranch {
44 
45 // Friends
46  friend class TTreeCloner;
47  friend class TLeafElement;
48 
49 // Types
50 protected:
51  enum EStatusBits {
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 : 1; ///<! Initialization flag for branch assignment
93  Bool_t fInInitInfo : 1;///<! True during the 2nd part of InitInfo (cut recursion).
94  Bool_t fInitOffsets: 1;///<! Initialization flag to not endlessly recalculate offsets
95  TClassRef fTargetClass; ///<! Reference to the target in-memory class
96  TClassRef fCurrentClass; ///<! Reference to current (transient) class definition
97  TClassRef fParentClass; ///<! Reference to class definition in fParentName
98  TClassRef fBranchClass; ///<! Reference to class definition in fClassName
99  TClassRef fClonesClass; ///<! Reference to class definition in fClonesName
100  Int_t *fBranchOffset; ///<! Sub-Branch offsets with respect to current transient class
101  Int_t fBranchID; ///<! ID number assigned by a TRefTable.
102  TStreamerInfoActions::TIDs fNewIDs; ///<! Nested List of the serial number of all the StreamerInfo to be used.
103  TStreamerInfoActions::TActionSequence *fReadActionSequence; ///<! Set of actions to be executed to extract the data from the basket.
104  TStreamerInfoActions::TActionSequence *fFillActionSequence; ///<! Set of actions to be executed to write the data to the basket.
105  TVirtualCollectionIterators *fIterators; ///<! holds the iterators when the branch is of fType==4.
106  TVirtualCollectionIterators *fWriteIterators; ///<! holds the read (non-staging) iterators when the branch is of fType==4 and associative containers.
107  TVirtualCollectionPtrIterators *fPtrIterators; ///<! holds the iterators when the branch is of fType==4 and it is a split collection of pointers.
108 
109 // Not implemented
110 private:
111  TBranchElement(const TBranchElement&); // not implemented
112  TBranchElement& operator=(const TBranchElement&); // not implemented
113 
114  static void SwitchContainer(TObjArray *);
115 
116 // Implementation use only functions.
117 protected:
118  void BuildTitle(const char* name);
119  virtual void InitializeOffsets();
120  virtual void InitInfo();
121  Bool_t IsMissingCollection() const;
122  TStreamerInfo *FindOnfileInfo(TClass *valueClass, const TObjArray &branches) const;
123  TClass *GetParentClass(); // Class referenced by fParentName
124  TStreamerInfo *GetInfoImp() const;
125  void ReleaseObject();
126  void SetupInfo();
127  void SetBranchCount(TBranchElement* bre);
128  void SetBranchCount2(TBranchElement* bre) { fBranchCount2 = bre; }
129  Int_t Unroll(const char* name, TClass* cltop, TClass* cl, char* ptr, Int_t basketsize, Int_t splitlevel, Int_t btype);
130  inline void ValidateAddress() const;
131 
132  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);
133  void Init(TTree *tree, TBranch *parent, const char* name, TClonesArray* clones, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = ROOT::RCompressionSetting::EAlgorithm::kInherit);
134  void Init(TTree *tree, TBranch *parent, const char* name, TVirtualCollectionProxy* cont, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = ROOT::RCompressionSetting::EAlgorithm::kInherit);
135 
136  void SetActionSequence(TClass *originalClass, TStreamerInfo *localInfo, TStreamerInfoActions::TActionSequence::SequenceGetter_t create, TStreamerInfoActions::TActionSequence *&actionSequence);
137  void ReadLeavesImpl(TBuffer& b);
138  void ReadLeavesMakeClass(TBuffer& b);
139  void ReadLeavesCollection(TBuffer& b);
140  void ReadLeavesCollectionSplitPtrMember(TBuffer& b);
141  void ReadLeavesCollectionSplitVectorPtrMember(TBuffer& b);
142  void ReadLeavesCollectionMember(TBuffer& b);
143  void ReadLeavesClones(TBuffer& b);
144  void ReadLeavesClonesMember(TBuffer& b);
145  void ReadLeavesCustomStreamer(TBuffer& b);
146  void ReadLeavesMember(TBuffer& b);
147  void ReadLeavesMemberBranchCount(TBuffer& b);
148  void ReadLeavesMemberCounter(TBuffer& b);
149  void SetReadLeavesPtr();
150  void SetReadActionSequence();
151  void SetupAddressesImpl();
152 
153  void FillLeavesImpl(TBuffer& b);
154  void FillLeavesMakeClass(TBuffer& b);
155  void FillLeavesCollection(TBuffer& b);
156  void FillLeavesCollectionSplitVectorPtrMember(TBuffer& b);
157  void FillLeavesCollectionSplitPtrMember(TBuffer& b);
158  void FillLeavesCollectionMember(TBuffer& b);
159  void FillLeavesAssociativeCollectionMember(TBuffer& b);
160  void FillLeavesClones(TBuffer& b);
161  void FillLeavesClonesMember(TBuffer& b);
162  void FillLeavesCustomStreamer(TBuffer& b);
163  void FillLeavesMemberBranchCount(TBuffer& b);
164  void FillLeavesMemberCounter(TBuffer& b);
165  void FillLeavesMember(TBuffer& b);
166  void SetFillLeavesPtr();
167  void SetFillActionSequence();
168 
169 // Public Interface.
170 public:
171  TBranchElement();
172  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);
173  TBranchElement(TTree *tree, const char* name, TClonesArray* clones, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = ROOT::RCompressionSetting::EAlgorithm::kInherit);
174  TBranchElement(TTree *tree, const char* name, TVirtualCollectionProxy* cont, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = ROOT::RCompressionSetting::EAlgorithm::kInherit);
175  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);
176  TBranchElement(TBranch *parent, const char* name, TClonesArray* clones, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = ROOT::RCompressionSetting::EAlgorithm::kInherit);
177  TBranchElement(TBranch *parent, const char* name, TVirtualCollectionProxy* cont, Int_t basketsize = 32000, Int_t splitlevel = 0, Int_t compress = ROOT::RCompressionSetting::EAlgorithm::kInherit);
178 
179  virtual ~TBranchElement();
180 
181  virtual void Browse(TBrowser* b);
182  virtual TBranch *FindBranch(const char *name);
183  virtual TLeaf *FindLeaf(const char *name);
184  virtual char *GetAddress() const;
185  TBranchElement *GetBranchCount() const { return fBranchCount; }
186  TBranchElement *GetBranchCount2() const { return fBranchCount2; }
187  Int_t *GetBranchOffset() const { return fBranchOffset; }
188  UInt_t GetCheckSum() { return fCheckSum; }
189  virtual const char *GetClassName() const { return fClassName.Data(); }
190  virtual TClass *GetClass() const { return fBranchClass; }
191  virtual const char *GetClonesName() const { return fClonesName.Data(); }
192  TVirtualCollectionProxy *GetCollectionProxy();
193  TClass *GetCurrentClass(); // Class referenced by transient description
194  virtual Int_t GetEntry(Long64_t entry = 0, Int_t getall = 0);
195  virtual Int_t GetExpectedType(TClass *&clptr,EDataType &type);
196  const char *GetIconName() const;
197  Int_t GetID() const { return fID; }
198  TStreamerInfo *GetInfo() const;
199  Bool_t GetMakeClass() const;
200  char *GetObject() const;
201  TVirtualArray *GetOnfileObject() const { return fOnfileObject; }
202  virtual const char *GetParentName() const { return fParentName.Data(); }
203  virtual Int_t GetMaximum() const;
204  Int_t GetNdata() const { return fNdata; }
205  Int_t GetType() const { return fType; }
206  Int_t GetStreamerType() const { return fStreamerType; }
207  virtual TClass *GetTargetClass() { return fTargetClass; }
208  virtual const char *GetTypeName() const;
209  Double_t GetValue(Int_t i, Int_t len, Bool_t subarr = kFALSE) const { return GetTypedValue<Double_t>(i, len, subarr); }
210  template<typename T > T GetTypedValue(Int_t i, Int_t len, Bool_t subarr = kFALSE) const;
211  virtual void *GetValuePointer() const;
212  Int_t GetClassVersion() { return fClassVersion; }
213  Bool_t IsBranchFolder() const { return TestBit(kBranchFolder); }
214  Bool_t IsFolder() const;
215  virtual Bool_t IsObjectOwner() const { return TestBit(kDeleteObject); }
216  virtual Bool_t Notify() { if (fAddress) { ResetAddress(); } return 1; }
217  virtual void Print(Option_t* option = "") const;
218  void PrintValue(Int_t i) const;
219  virtual void Reset(Option_t* option = "");
220  virtual void ResetAfterMerge(TFileMergeInfo *);
221  virtual void ResetAddress();
222  virtual void ResetDeleteObject();
223  virtual void ResetInitInfo(bool recurse);
224  virtual void SetAddress(void* addobj);
225  virtual Bool_t SetMakeClass(Bool_t decomposeObj = kTRUE);
226  virtual void SetObject(void *objadd);
227  virtual void SetBasketSize(Int_t buffsize);
228  virtual void SetBranchFolder() { SetBit(kBranchFolder); }
229  virtual void SetClassName(const char* name) { fClassName = name; }
230  virtual void SetOffset(Int_t offset);
231  virtual void SetMissing();
232  inline void SetParentClass(TClass* clparent);
233  virtual void SetParentName(const char* name) { fParentName = name; }
234  virtual void SetTargetClass(const char *name);
235  virtual void SetupAddresses();
236  virtual void SetType(Int_t btype) { fType = btype; }
237  virtual void UpdateFile();
238  void Unroll(const char *name, TClass *cl, TStreamerInfo *sinfo, char* objptr, Int_t bufsize, Int_t splitlevel);
239 
240  enum EBranchElementType {
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 private:
255  virtual Int_t FillImpl(ROOT::Internal::TBranchIMTHelper *);
256 
257  ClassDef(TBranchElement,10) // Branch in case of an object
258 };
259 
260 inline void TBranchElement::SetParentClass(TClass* clparent)
261 {
262  fParentClass = clparent;
263  fParentName = clparent ? clparent->GetName() : "";
264 }
265 
266 inline void TBranchElement::ValidateAddress() const
267 {
268  // Check to see if the user changed the object pointer without telling us.
269 
270  if (fID < 0) {
271  // We are a top-level branch.
272  if (!fTree->GetMakeClass() && fAddress && (*((char**) fAddress) != fObject)) {
273  // The semantics of fAddress and fObject are violated.
274  // Assume the user changed the pointer on us.
275  // Note: The cast is here because we want to be able to
276  // be called from the constant get functions.
277 
278  // FIXME: Disable the check/warning TTree until we add a missing interface.
279  if (TestBit(kDeleteObject)) {
280  // This should never happen!
281  Error("ValidateAddress", "We owned an object whose address changed! our ptr: %p new ptr: %p",
282  (void*)fObject, (void*)*((char**) fAddress));
283  const_cast<TBranchElement*>(this)->ResetBit(kDeleteObject);
284  }
285  const_cast<TBranchElement*>(this)->SetAddress(fAddress);
286  }
287  }
288 }
289 
290 #endif // ROOT_TBranchElement