Logo ROOT  
Reference Guide
TLeafElement.cxx
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 /** \class TLeafElement
13 \ingroup tree
14 
15 A TLeaf for the general case when using the branches created via
16 a TStreamerInfo (i.e. using TBranchElement).
17 */
18 
19 #include "TLeafElement.h"
20 
21 #include "TVirtualStreamerInfo.h"
22 #include "Bytes.h"
23 #include "TBuffer.h"
24 
26 
27 ////////////////////////////////////////////////////////////////////////////////
28 /// Default constructor for LeafObject.
29 
31 {
32  fAbsAddress = 0;
33  fID = -1;
34  fType = -1;
35 }
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// Create a LeafObject.
39 
41  : TLeaf(parent, name,name)
42 {
43  fLenType = 0;
44  fAbsAddress = 0;
45  fID = id;
46  fType = type;
48  Int_t bareType = type;
49  if (bareType > TVirtualStreamerInfo::kOffsetP)
51  else if (bareType > TVirtualStreamerInfo::kOffsetL)
53 
54  if ((bareType >= TVirtualStreamerInfo::kUChar && bareType <= TVirtualStreamerInfo::kULong)
55  || bareType == TVirtualStreamerInfo::kULong64)
56  {
57  SetUnsigned();
58  }
59 
60  auto bareTypeCopy = static_cast<EDataType>(bareType);
61  switch (bareTypeCopy) {
62  case kChar_t: // fall-through
63  case kUChar_t: // fall-through
64  case kchar: // fall-through
65  case kBool_t:
66  fLenType = 1;
67  break;
68  case kShort_t: // fall-through
69  case kUShort_t: // fall-through
70  case kFloat16_t:
71  fLenType = 2;
72  break;
73  case kFloat_t: // fall-through
74  case kDouble32_t: // fall-through
75  case kInt_t: // fall-through
76  case kUInt_t:
77  fLenType = 4;
78  break;
79  case kLong_t: // fall-through
80  case kULong_t: // fall-through
81  case kLong64_t: // fall-through
82  case kULong64_t: // fall-through
83  case kDouble_t:
84  fLenType = 8;
85  break;
86  // All cases I don't know how to handle.
87  case kOther_t: // fall-through
88  case kNoType_t: // fall-through
89  case kCounter: // fall-through
90  case kCharStar: // fall-through
91  case kBits: // fall-through
92  case kVoid_t: // fall-through
93  case kDataTypeAliasUnsigned_t: // fall-through
94  case kDataTypeAliasSignedChar_t: // fall-through
95  case kNumDataTypes: // fall-through
96  fLenType = 0;
97  };
98  }
99 }
100 
101 ////////////////////////////////////////////////////////////////////////////////
102 /// Default destructor for a LeafObject.
103 
105 {
106 }
107 
108 ////////////////////////////////////////////////////////////////////////////////
109 /// Determine if this TLeafElement supports bulk IO
112 {
113  if (R__likely(fDeserializeTypeCache.load(std::memory_order_relaxed) != DeserializeType::kInvalid))
114  return fDeserializeTypeCache;
115 
116  TClass *clptr = nullptr;
118  if (fBranch->GetExpectedType(clptr, type)) { // Returns non-zero in case of failure
119  fDeserializeTypeCache.store(DeserializeType::kDestructive, std::memory_order_relaxed);
120  return DeserializeType::kDestructive; // I don't know what it is, but we aren't going to use bulk IO.
121  }
122  fDataTypeCache.store(type, std::memory_order_release);
123  if (clptr) { // Something that requires a dictionary to read; skip.
124  fDeserializeTypeCache.store(DeserializeType::kDestructive, std::memory_order_relaxed);
126  }
127 
129  fDeserializeTypeCache.store(DeserializeType::kZeroCopy, std::memory_order_relaxed);
131  } else if ((type == EDataType::kFloat_t) || (type == EDataType::kDouble_t) ||
134  fDeserializeTypeCache.store(DeserializeType::kInPlace, std::memory_order_relaxed);
136  }
137 
138  fDeserializeTypeCache.store(DeserializeType::kDestructive, std::memory_order_relaxed);
140 }
141 
142 ////////////////////////////////////////////////////////////////////////////////
143 /// Deserialize N events from an input buffer.
145 {
146  EDataType type = fDataTypeCache.load(std::memory_order_consume);
147  return input_buf.ByteSwapBuffer(fLen*N, type);
148 }
149 
150 ////////////////////////////////////////////////////////////////////////////////
151 /// Returns pointer to method corresponding to name name is a string
152 /// with the general form "method(list of params)" If list of params is
153 /// omitted, () is assumed;
154 
156 {
157  return 0;
158 }
159 
160 ////////////////////////////////////////////////////////////////////////////////
161 /// Return the full name (including the parent's branch names) of the leaf.
162 
164 {
165  return GetBranch()->GetFullName();
166 }
167 
168 ////////////////////////////////////////////////////////////////////////////////
169 /// Copy/set fMinimum and fMaximum to include/be wide than those of the parameter
170 
172 {
173  if (input) {
174  if (input->GetMaximum() > this->GetMaximum())
175  ((TBranchElement*)fBranch)->fMaximum = input->GetMaximum();
176  return kTRUE;
177  } else {
178  return kFALSE;
179  }
180 }
181 
182 ////////////////////////////////////////////////////////////////////////////////
183 /// Return true if this leaf is does not have any sub-branch/leaf.
184 
186 {
188  return kTRUE;
189 }
kULong64_t
@ kULong64_t
Definition: TDataType.h:38
kDouble_t
@ kDouble_t
Definition: TDataType.h:37
kUChar_t
@ kUChar_t
Definition: TDataType.h:35
kInt_t
@ kInt_t
Definition: TDataType.h:36
TLeafElement::fDeserializeTypeCache
std::atomic< DeserializeType > fDeserializeTypeCache
! Cache of the type of deserialization.
Definition: TLeafElement.h:38
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TLeafElement::GetMethodCall
TMethodCall * GetMethodCall(const char *name)
Returns pointer to method corresponding to name name is a string with the general form "method(list o...
Definition: TLeafElement.cxx:155
kNoType_t
@ kNoType_t
Definition: TDataType.h:39
kCharStar
@ kCharStar
Definition: TDataType.h:40
kLong_t
@ kLong_t
Definition: TDataType.h:36
TVirtualStreamerInfo::kUChar
@ kUChar
Definition: TVirtualStreamerInfo.h:87
kChar_t
@ kChar_t
Definition: TDataType.h:35
TBranchElement
Definition: TBranchElement.h:39
kULong_t
@ kULong_t
Definition: TDataType.h:36
TVirtualStreamerInfo::kULong64
@ kULong64
Definition: TVirtualStreamerInfo.h:88
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TBranch::GetListOfBranches
TObjArray * GetListOfBranches()
Definition: TBranch.h:242
kNumDataTypes
@ kNumDataTypes
Definition: TDataType.h:46
TLeafElement::GetFullName
virtual TString GetFullName() const
Return the full name (including the parent's branch names) of the leaf.
Definition: TLeafElement.cxx:163
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
TLeafElement::TLeafElement
TLeafElement()
Default constructor for LeafObject.
Definition: TLeafElement.cxx:30
TVirtualStreamerInfo::kOffsetL
@ kOffsetL
Definition: TVirtualStreamerInfo.h:84
N
#define N
kUInt_t
@ kUInt_t
Definition: TDataType.h:36
TLeafElement::~TLeafElement
virtual ~TLeafElement()
Default destructor for a LeafObject.
Definition: TLeafElement.cxx:104
TLeafElement::ReadBasketFast
virtual bool ReadBasketFast(TBuffer &, Long64_t)
Deserialize N events from an input buffer.
Definition: TLeafElement.cxx:144
R__likely
#define R__likely(expr)
Definition: RConfig.hxx:605
TBuffer
Definition: TBuffer.h:43
TVirtualStreamerInfo::kObject
@ kObject
Definition: TVirtualStreamerInfo.h:89
kchar
@ kchar
Definition: TDataType.h:37
TLeafElement
Definition: TLeafElement.h:32
TString
Definition: TString.h:136
bool
kFloat16_t
@ kFloat16_t
Definition: TDataType.h:39
id
XFontStruct * id
Definition: TGX11.cxx:109
TLeafElement::fAbsAddress
char * fAbsAddress
! Absolute leaf Address
Definition: TLeafElement.h:35
TLeaf::fLenType
Int_t fLenType
Number of bytes for this data type.
Definition: TLeaf.h:73
TBranch
Definition: TBranch.h:89
TBranch::GetExpectedType
virtual Int_t GetExpectedType(TClass *&clptr, EDataType &type)
Fill expectedClass and expectedType with information on the data type of the object/values contained ...
Definition: TBranch.cxx:1710
TLeafElement::fType
Int_t fType
leaf type
Definition: TLeafElement.h:37
kDouble32_t
@ kDouble32_t
Definition: TDataType.h:37
kCounter
@ kCounter
Definition: TDataType.h:40
TBuffer.h
TVirtualStreamerInfo::kULong
@ kULong
Definition: TVirtualStreamerInfo.h:87
kDataTypeAliasUnsigned_t
@ kDataTypeAliasUnsigned_t
Definition: TDataType.h:43
TLeaf::DeserializeType::kDestructive
@ kDestructive
TLeaf
Definition: TLeaf.h:57
TLeaf::fLen
Int_t fLen
Number of fixed length elements in the leaf's data.
Definition: TLeaf.h:72
TObjArray::GetEntriesFast
Int_t GetEntriesFast() const
Definition: TObjArray.h:64
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
kUShort_t
@ kUShort_t
Definition: TDataType.h:35
TLeafElement::fID
Int_t fID
element serial number in fInfo
Definition: TLeafElement.h:36
TLeaf::DeserializeType::kInvalid
@ kInvalid
TLeafElement::IsOnTerminalBranch
virtual Bool_t IsOnTerminalBranch() const
Return true if this leaf is does not have any sub-branch/leaf.
Definition: TLeafElement.cxx:185
TBuffer::ByteSwapBuffer
Bool_t ByteSwapBuffer(Long64_t n, EDataType type)
Byte-swap N primitive-elements in the buffer.
Definition: TBuffer.cxx:392
kLong64_t
@ kLong64_t
Definition: TDataType.h:38
TLeaf::DeserializeType::kInPlace
@ kInPlace
kFloat_t
@ kFloat_t
Definition: TDataType.h:37
kVoid_t
@ kVoid_t
Definition: TDataType.h:41
kOther_t
@ kOther_t
Definition: TDataType.h:38
TVirtualStreamerInfo.h
TLeaf::GetBranch
TBranch * GetBranch() const
Definition: TLeaf.h:115
TLeaf::GetMaximum
virtual Int_t GetMaximum() const
Definition: TLeaf.h:133
TLeafElement::IncludeRange
virtual Bool_t IncludeRange(TLeaf *)
Copy/set fMinimum and fMaximum to include/be wide than those of the parameter.
Definition: TLeafElement.cxx:171
TLeafElement::GetDeserializeType
virtual DeserializeType GetDeserializeType() const
Determine if this TLeafElement supports bulk IO.
Definition: TLeafElement.cxx:111
TClass
Definition: TClass.h:80
EDataType
EDataType
Definition: TDataType.h:28
kBits
@ kBits
Definition: TDataType.h:40
Bytes.h
TLeafElement::fDataTypeCache
std::atomic< EDataType > fDataTypeCache
! Cache of the EDataType of deserialization.
Definition: TLeafElement.h:39
name
char name[80]
Definition: TGX11.cxx:110
kDataTypeAliasSignedChar_t
@ kDataTypeAliasSignedChar_t
Definition: TDataType.h:44
TLeafElement.h
TLeaf::DeserializeType::kZeroCopy
@ kZeroCopy
TMethodCall
Definition: TMethodCall.h:37
type
int type
Definition: TGX11.cxx:121
TBranch::GetFullName
TString GetFullName() const
Return the 'full' name of the branch.
Definition: TBranch.cxx:1886
TLeaf::DeserializeType
DeserializeType
Definition: TLeaf.h:99
TLeaf::SetUnsigned
virtual void SetUnsigned()
Definition: TLeaf.h:165
TVirtualStreamerInfo::kOffsetP
@ kOffsetP
Definition: TVirtualStreamerInfo.h:84
kShort_t
@ kShort_t
Definition: TDataType.h:35
kBool_t
@ kBool_t
Definition: TDataType.h:38
TLeaf::fBranch
TBranch * fBranch
! Pointer to supporting branch (we do not own the branch)
Definition: TLeaf.h:78
int