Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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
15A TLeaf for the general case when using the branches created via
16a TStreamerInfo (i.e. using TBranchElement).
17*/
18
19#include "TLeafElement.h"
20
22#include "Bytes.h"
23#include "TBuffer.h"
24
25
26////////////////////////////////////////////////////////////////////////////////
27/// Default constructor for LeafObject.
28
30{
31 fAbsAddress = nullptr;
32 fID = -1;
33 fType = -1;
34}
35
36////////////////////////////////////////////////////////////////////////////////
37/// Create a LeafObject.
38
39TLeafElement::TLeafElement(TBranch *parent, const char *name, Int_t id, Int_t type)
40 : TLeaf(parent, name,name)
41{
42 fLenType = 0;
43 fAbsAddress = nullptr;
44 fID = id;
45 fType = type;
47 Int_t bareType = type;
48 if (bareType > TVirtualStreamerInfo::kOffsetP)
50 else if (bareType > TVirtualStreamerInfo::kOffsetL)
52
53 if ((bareType >= TVirtualStreamerInfo::kUChar && bareType <= TVirtualStreamerInfo::kULong)
54 || bareType == TVirtualStreamerInfo::kULong64)
55 {
57 }
58
59 auto bareTypeCopy = static_cast<EDataType>(bareType);
60 switch (bareTypeCopy) {
61 case kChar_t: // fall-through
62 case kUChar_t: // fall-through
63 case kchar: // fall-through
64 case kBool_t:
65 fLenType = 1;
66 break;
67 case kShort_t: // fall-through
68 case kUShort_t: // fall-through
69 case kFloat16_t:
70 fLenType = 2;
71 break;
72 case kFloat_t: // fall-through
73 case kDouble32_t: // fall-through
74 case kInt_t: // fall-through
75 case kUInt_t:
76 fLenType = 4;
77 break;
78 case kLong_t: // fall-through
79 case kULong_t: // fall-through
80 case kLong64_t: // fall-through
81 case kULong64_t: // fall-through
82 case kDouble_t:
83 fLenType = 8;
84 break;
85 // All cases I don't know how to handle.
86 case kOther_t: // fall-through
87 case kNoType_t: // fall-through
88 case kCounter: // fall-through
89 case kCharStar: // fall-through
90 case kBits: // fall-through
91 case kVoid_t: // fall-through
92 case kDataTypeAliasUnsigned_t: // fall-through
93 case kDataTypeAliasSignedChar_t: // fall-through
94 case kNumDataTypes: // fall-through
95 fLenType = 0;
96 };
97 }
98}
99
100////////////////////////////////////////////////////////////////////////////////
101/// Default destructor for a LeafObject.
102
106
107////////////////////////////////////////////////////////////////////////////////
108/// Determine if this TLeafElement supports bulk IO
111{
112 if (R__unlikely(fDeserializeTypeCache.load(std::memory_order_relaxed) != DeserializeType::kInvalid))
114
115 TClass *clptr = nullptr;
117 if (fBranch->GetExpectedType(clptr, type)) { // Returns non-zero in case of failure
118 fDeserializeTypeCache.store(DeserializeType::kExternal, std::memory_order_relaxed);
119 return DeserializeType::kExternal; // I don't know what it is, but we aren't going to use bulk IO.
120 }
121 fDataTypeCache.store(type, std::memory_order_release);
122 if (clptr) { // Something that requires a dictionary to read; skip.
123 fDeserializeTypeCache.store(DeserializeType::kExternal, std::memory_order_relaxed);
125 }
126
128 fDeserializeTypeCache.store(DeserializeType::kZeroCopy, std::memory_order_relaxed);
130 } else if ((type == EDataType::kFloat_t) || (type == EDataType::kDouble_t) ||
131 (type == EDataType::kInt_t) || (type == EDataType::kUInt_t) ||
132 (type == EDataType::kLong64_t) || (type == EDataType::kULong64_t)) {
133 fDeserializeTypeCache.store(DeserializeType::kInPlace, std::memory_order_relaxed);
135 }
136
137 fDeserializeTypeCache.store(DeserializeType::kExternal, std::memory_order_relaxed);
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// Deserialize N events from an input buffer.
144{
145 if (R__unlikely(fDeserializeTypeCache.load(std::memory_order_relaxed) == DeserializeType::kInvalid))
146 GetDeserializeType(); // Set fDataTypeCache if need be.
147 EDataType type = fDataTypeCache.load(std::memory_order_consume);
148 return input_buf.ByteSwapBuffer(fLen*N, type);
149}
150
151////////////////////////////////////////////////////////////////////////////////
152/// Returns pointer to method corresponding to name name is a string
153/// with the general form "method(list of params)" If list of params is
154/// omitted, () is assumed;
155
157{
158 return nullptr;
159}
160
161////////////////////////////////////////////////////////////////////////////////
162/// Return the full name (including the parent's branch names) of the leaf.
163
165{
166 TBranchElement *br = static_cast<TBranchElement*>(GetBranch());
167 if (br->GetType() == 3 || br->GetType() == 4) {
168 TString bname(br->GetFullName());
169 if (bname.Length() && bname[bname.Length()-1]=='.')
170 bname.Remove(bname.Length()-1);
171 return bname + "_";
172 } else
173 return GetBranch()->GetFullName();
174}
175
176////////////////////////////////////////////////////////////////////////////////
177/// Copy/set fMinimum and fMaximum to include/be wide than those of the parameter
178
180{
181 if (input) {
182 if (input->GetMaximum() > this->GetMaximum())
183 ((TBranchElement*)fBranch)->fMaximum = input->GetMaximum();
184 return true;
185 } else {
186 return false;
187 }
188}
189
190////////////////////////////////////////////////////////////////////////////////
191/// Return true if this leaf is does not have any sub-branch/leaf.
192
194{
195 if (fBranch->GetListOfBranches()->GetEntriesFast()) return false;
196 return true;
197}
#define R__unlikely(expr)
Definition RConfig.hxx:586
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
EDataType
Definition TDataType.h:28
@ kNoType_t
Definition TDataType.h:33
@ kFloat_t
Definition TDataType.h:31
@ kULong64_t
Definition TDataType.h:32
@ kInt_t
Definition TDataType.h:30
@ kNumDataTypes
Definition TDataType.h:40
@ kchar
Definition TDataType.h:31
@ kLong_t
Definition TDataType.h:30
@ kDouble32_t
Definition TDataType.h:31
@ kShort_t
Definition TDataType.h:29
@ kBool_t
Definition TDataType.h:32
@ kBits
Definition TDataType.h:34
@ kDataTypeAliasSignedChar_t
Definition TDataType.h:38
@ kULong_t
Definition TDataType.h:30
@ kLong64_t
Definition TDataType.h:32
@ kVoid_t
Definition TDataType.h:35
@ kUShort_t
Definition TDataType.h:29
@ kDouble_t
Definition TDataType.h:31
@ kCharStar
Definition TDataType.h:34
@ kChar_t
Definition TDataType.h:29
@ kUChar_t
Definition TDataType.h:29
@ kDataTypeAliasUnsigned_t
Definition TDataType.h:37
@ kCounter
Definition TDataType.h:34
@ kUInt_t
Definition TDataType.h:30
@ kFloat16_t
Definition TDataType.h:33
@ kOther_t
Definition TDataType.h:32
#define N
XFontStruct * id
Definition TGX11.cxx:147
char name[80]
Definition TGX11.cxx:148
A Branch for the case of an object.
TString GetFullName() const override
Return the 'full' name of the branch.
Int_t GetType() const
A TTree is a list of TBranches.
Definition TBranch.h:93
virtual TString GetFullName() const
Return the 'full' name of the branch.
Definition TBranch.cxx:2030
Buffer base class used for serializing objects.
Definition TBuffer.h:43
Bool_t ByteSwapBuffer(Long64_t n, EDataType type)
Byte-swap N primitive-elements in the buffer.
Definition TBuffer.cxx:393
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
TMethodCall * GetMethodCall(const char *name)
Returns pointer to method corresponding to name name is a string with the general form "method(list o...
char * fAbsAddress
! Absolute leaf Address
std::atomic< DeserializeType > fDeserializeTypeCache
! Cache of the type of deserialization.
bool ReadBasketFast(TBuffer &, Long64_t) override
Deserialize N events from an input buffer.
~TLeafElement() override
Default destructor for a LeafObject.
Int_t fType
leaf type
bool IsOnTerminalBranch() const override
Return true if this leaf is does not have any sub-branch/leaf.
bool IncludeRange(TLeaf *) override
Copy/set fMinimum and fMaximum to include/be wide than those of the parameter.
std::atomic< EDataType > fDataTypeCache
! Cache of the EDataType of deserialization.
Int_t fID
element serial number in fInfo
TString GetFullName() const override
Return the full name (including the parent's branch names) of the leaf.
DeserializeType GetDeserializeType() const override
Determine if this TLeafElement supports bulk IO.
TLeafElement()
Default constructor for LeafObject.
TLeaf(const TLeaf &)
Copy constructor.
Definition TLeaf.cxx:99
Int_t fLenType
Number of bytes for this data type.
Definition TLeaf.h:76
virtual Int_t GetMaximum() const
Definition TLeaf.h:137
Int_t fLen
Number of fixed length elements in the leaf's data.
Definition TLeaf.h:75
DeserializeType
Definition TLeaf.h:102
TBranch * GetBranch() const
Definition TLeaf.h:119
TBranch * fBranch
! Pointer to supporting branch (we do not own the branch)
Definition TLeaf.h:81
virtual void SetUnsigned()
Definition TLeaf.h:169
Method or function calling interface.
Definition TMethodCall.h:37
Basic string class.
Definition TString.h:138
Ssiz_t Length() const
Definition TString.h:425
TString & Remove(Ssiz_t pos)
Definition TString.h:694
@ kUChar
Equal to TDataType's kchar.