Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RTreeColumnReader.cxx
Go to the documentation of this file.
2#include <TTreeReader.h>
3#include <TTreeReaderValue.h>
4#include <TTreeReaderArray.h>
5
6#include <bitset>
7
12
14 : fTreeValue(std::make_unique<ROOT::Internal::TTreeReaderOpaqueValue>(r, colName.data()))
15{
16}
17
19
24
26 std::string_view colName,
27 std::string_view typeName)
28 : fTreeValue(std::make_unique<ROOT::Internal::TTreeReaderUntypedValue>(r, colName, typeName))
29{
30}
31
33
35{
36 if (entry == fLastEntry)
37 return fRVec.data(); // We return the RVec we already created
38
39 auto &readerArray = *fTreeArray;
40 // GetSize is called here to trigger actual reading of the branch proxy, which also sets the appropriate read status
41 const auto readerArraySize = readerArray.GetSize();
42
43 // The reader could not read an array, signal this back to the node requesting the value
45 return nullptr;
46
47 // std::array storage should always be contiguous
48 assert(readerArray.IsContiguous() && "std::array storage should always be contiguous");
49
50 if (readerArraySize > 0) {
51 // trigger loading of the contents of the TTreeReaderArray
52 // the address of the first element in the reader array is not necessarily equal to
53 // the address returned by the GetAddress method
55 swap(fRVec, rvec);
56 } else {
57 fRVec.clear();
58 }
59
60 fLastEntry = entry;
61 return fRVec.data();
62}
63
65{
66 if (entry == fLastEntry)
67 return &fStdVector; // We return the std::vector we already created
68
69 auto &readerArray = *fTreeArray;
70 // GetSize is called here to trigger actual reading of the branch proxy, which also sets the appropriate read status
71 const auto readerArraySize = readerArray.GetSize();
72
73 // The reader could not read an array, signal this back to the node requesting the value
75 return nullptr;
76
77 // There is no zero-copy constructor for std::vector, so we need to copy the data in any case.
78 if (readerArraySize > 0) {
79 // Caching the value type size since GetValueSize might be expensive.
80 if (fValueSize == 0)
81 fValueSize = readerArray.GetValueSize();
82 assert(fValueSize > 0 && "Could not retrieve size of collection value type.");
83 // Array is not contiguous, make a full copy of it.
84 fStdVector.clear();
85 fStdVector.reserve(readerArraySize * fValueSize);
86 for (std::size_t i{0}; i < readerArraySize; i++) {
87 auto val = readerArray.At(i);
88 std::copy(val, val + fValueSize, std::back_inserter(fStdVector));
89 }
90 } else {
91 fStdVector.clear();
92 }
93
94 fLastEntry = entry;
95 return &fStdVector;
96}
97
99{
100 if (entry == fLastEntry)
101 return &fRVec; // We return the RVec we already created
102
103 auto &readerArray = *fTreeArray;
104 // GetSize is called here to trigger actual reading of the branch proxy, which also sets the appropriate read status
105 const auto readerArraySize = readerArray.GetSize();
106
107 // The reader could not read an array, signal this back to the node requesting the value
109 return nullptr;
110
111 if (readerArray.IsContiguous() && !(fCollectionType == ECollectionType::kRVecBool)) {
112 if (readerArraySize > 0) {
113 // trigger loading of the contents of the TTreeReaderArray
114 // the address of the first element in the reader array is not necessarily equal to
115 // the address returned by the GetAddress method
117 swap(fRVec, rvec);
118 } else {
119 fRVec.clear();
120 }
121 } else {
122 // The storage is not contiguous: we cannot but copy into the RVec
123#ifndef NDEBUG
124 if (!fCopyWarningPrinted && !(fCollectionType == ECollectionType::kRVecBool)) {
125 Warning("RTreeColumnReader::Get",
126 "Branch %s hangs from a non-split branch. A copy is being performed in order "
127 "to properly read the content.",
128 readerArray.GetBranchName());
129 fCopyWarningPrinted = true;
130 }
131#else
132 (void)fCopyWarningPrinted;
133#endif
134 if (readerArraySize > 0) {
135 // Caching the value type size since GetValueSize might be expensive.
136 if (fValueSize == 0)
137 fValueSize = readerArray.GetValueSize();
138 assert(fValueSize > 0 && "Could not retrieve size of collection value type.");
139 // Array is not contiguous, make a full copy of it.
140 fRVec.clear();
141 fRVec.reserve(readerArraySize * fValueSize);
142 for (std::size_t i{0}; i < readerArraySize; i++) {
143 auto val = readerArray.At(i);
144 std::copy(val, val + fValueSize, std::back_inserter(fRVec));
145 }
146 // RVec's `size()` method returns the value of the `fSize` data member, unlike std::vector's `size()`
147 // which returns the distance between begin and end divided by the size of the collection value type.
148 // This difference is important in this case: we reserved enough space in the RVec to fill
149 // `readerArraySize * fValueSize` bytes, but the reader will need to read just `readerArraySize` elements
150 // adjusted to the correct `fValueSize` bytes per element. Thus, we set the size of the RVec here to
151 // represent the correct size of the user-requested RVec<T>. This leaves the RVec<Byte_t> in an invalid
152 // state until it is cast to the correct type (by the `TryGet<T>` call).
153 fRVec.set_size(readerArraySize);
154 } else {
155 fRVec.clear();
156 }
157 }
158
159 fLastEntry = entry;
160 return &fRVec;
161}
162
164{
165 if (fCollectionType == ECollectionType::kStdArray)
166 return ReadStdArray(entry);
167
168 if (fCollectionType == ECollectionType::kStdVector)
169 return ReadStdVector(entry);
170
171 return ReadRVec(entry);
172}
173
175 std::string_view colName,
176 std::string_view valueTypeName,
178 : fTreeArray(std::make_unique<ROOT::Internal::TTreeReaderUntypedArray>(r, colName, valueTypeName)),
179 fCollectionType(collType)
180{
181}
182
184
186 TTreeReader &r, std::unique_ptr<ROOT::Detail::RDF::RColumnReaderBase> valueReader, std::string_view maskName,
187 unsigned int maskIndex)
188 : fValueReader{std::move(valueReader)},
189 fTreeValueMask{std::make_unique<TTreeReaderValue<uint64_t>>(r, maskName.data())},
190 fMaskIndex{maskIndex}
191{
192}
193
195
197{
198 const std::bitset<64> mask{*fTreeValueMask->Get()};
199 if (mask.test(fMaskIndex) == false)
200 return nullptr;
201
202 return fValueReader->TryGet<void>(event);
203}
size_t fValueSize
#define R__unlikely(expr)
Definition RConfig.hxx:594
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:252
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t mask
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
RMaskedColumnReader(TTreeReader &r, std::unique_ptr< ROOT::Detail::RDF::RColumnReaderBase > valueReader, std::string_view maskName, unsigned int maskIndex)
std::unique_ptr< ROOT::Internal::TTreeReaderOpaqueValue > fTreeValue
RTreeOpaqueColumnReader(TTreeReader &r, std::string_view colName)
Construct the RTreeColumnReader. Actual initialization is performed lazily by the Init method.
RTreeUntypedArrayColumnReader(TTreeReader &r, std::string_view colName, std::string_view valueTypeName, ECollectionType collType)
RTreeUntypedValueColumnReader(TTreeReader &r, std::string_view colName, std::string_view typeName)
Read a value in a branch without knowledge of its type.
An interface for reading values stored in ROOT columnar datasets.
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
Definition TTreeReader.h:46