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
54 RVec<Byte_t> rvec(readerArray.At(0), readerArraySize);
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
116 RVec<Byte_t> rvec(readerArray.At(0), readerArraySize);
117 swap(fRVec, rvec);
118 } else {
119 fRVec.clear();
120 }
121 } else {
122 if (readerArraySize > 0) {
123 // Caching the value type size since GetValueSize might be expensive.
124 if (fValueSize == 0)
125 fValueSize = readerArray.GetValueSize();
126 assert(fValueSize > 0 && "Could not retrieve size of collection value type.");
127 // Array is not contiguous, make a full copy of it.
128 fRVec.clear();
129 fRVec.reserve(readerArraySize * fValueSize);
130 for (std::size_t i{0}; i < readerArraySize; i++) {
131 auto val = readerArray.At(i);
132 std::copy(val, val + fValueSize, std::back_inserter(fRVec));
133 }
134 // RVec's `size()` method returns the value of the `fSize` data member, unlike std::vector's `size()`
135 // which returns the distance between begin and end divided by the size of the collection value type.
136 // This difference is important in this case: we reserved enough space in the RVec to fill
137 // `readerArraySize * fValueSize` bytes, but the reader will need to read just `readerArraySize` elements
138 // adjusted to the correct `fValueSize` bytes per element. Thus, we set the size of the RVec here to
139 // represent the correct size of the user-requested RVec<T>. This leaves the RVec<Byte_t> in an invalid
140 // state until it is cast to the correct type (by the `TryGet<T>` call).
141 fRVec.set_size(readerArraySize);
142 } else {
143 fRVec.clear();
144 }
145 }
146
147 fLastEntry = entry;
148 return &fRVec;
149}
150
152{
153 if (fCollectionType == ECollectionType::kStdArray)
154 return ReadStdArray(entry);
155
156 if (fCollectionType == ECollectionType::kStdVector)
157 return ReadStdVector(entry);
158
159 return ReadRVec(entry);
160}
161
163 std::string_view colName,
164 std::string_view valueTypeName,
165 ECollectionType collType)
166 : fTreeArray(std::make_unique<ROOT::Internal::TTreeReaderUntypedArray>(r, colName, valueTypeName)),
167 fCollectionType(collType)
168{
169}
170
172
174 TTreeReader &r, std::unique_ptr<ROOT::Detail::RDF::RColumnReaderBase> valueReader, std::string_view maskName,
175 unsigned int maskIndex)
176 : fValueReader{std::move(valueReader)},
177 fTreeValueMask{std::make_unique<TTreeReaderValue<uint64_t>>(r, maskName.data())},
178 fMaskIndex{maskIndex}
179{
180}
181
183
185{
186 const std::bitset<64> mask{*fTreeValueMask->Get()};
187 if (mask.test(fMaskIndex) == false)
188 return nullptr;
189
190 return fValueReader->TryGet<void>(event);
191}
size_t fValueSize
#define R__unlikely(expr)
Definition RConfig.hxx:568
cudaEvent_t event
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:84
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.
A "std::vector"-like collection of values implementing handy operation to analyse them.
Definition RVec.hxx:1509
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