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
10
12 : fTreeValue(std::make_unique<ROOT::Internal::TTreeReaderOpaqueValue>(r, colName.data()))
13{
14}
15
17
22
24 std::string_view colName,
25 std::string_view typeName)
26 : fTreeValue(std::make_unique<ROOT::Internal::TTreeReaderUntypedValue>(r, colName, typeName))
27{
28}
29
31
33{
34 if (entry == fLastEntry)
35 return &fRVec; // we already pointed our fRVec to the right address
36
37 auto &readerArray = *fTreeArray;
38 const auto readerArraySize = readerArray.GetSize();
39
40 // The reader could not read an array, signal this back to the node requesting the value
42 return nullptr;
43
44 if (readerArray.IsContiguous() && !(fCollectionType == ECollectionType::kRVecBool)) {
45 if (readerArraySize > 0) {
46 // trigger loading of the contents of the TTreeReaderArray
47 // the address of the first element in the reader array is not necessarily equal to
48 // the address returned by the GetAddress method
50 swap(fRVec, rvec);
51 } else {
52 fRVec.clear();
53 }
54 } else {
55 // The storage is not contiguous: we cannot but copy into the RVec
56#ifndef NDEBUG
57 if (!fCopyWarningPrinted && !(fCollectionType == ECollectionType::kRVecBool)) {
58 Warning("RTreeColumnReader::Get",
59 "Branch %s hangs from a non-split branch. A copy is being performed in order "
60 "to properly read the content.",
61 readerArray.GetBranchName());
62 fCopyWarningPrinted = true;
63 }
64#else
65 (void)fCopyWarningPrinted;
66#endif
67 if (readerArraySize > 0) {
68 // Caching the value type size since GetValueSize might be expensive.
69 if (fValueSize == 0)
70 fValueSize = readerArray.GetValueSize();
71 assert(fValueSize > 0 && "Could not retrieve size of collection value type.");
72 // Array is not contiguous, make a full copy of it.
73 fRVec.clear();
74 fRVec.reserve(readerArraySize * fValueSize);
75 for (std::size_t i{0}; i < readerArraySize; i++) {
76 auto val = readerArray.At(i);
77 std::copy(val, val + fValueSize, std::back_inserter(fRVec));
78 }
79 // RVec's `size()` method returns the value of the `fSize` data member, unlike std::vector's `size()`
80 // which returns the distance between begin and end divided by the size of the collection value type.
81 // This difference is important in this case: we reserved enough space in the RVec to fill
82 // `readerArraySize * fValueSize` bytes, but the reader will need to read just `readerArraySize` elements
83 // adjusted to the correct `fValueSize` bytes per element. Thus, we set the size of the RVec here to
84 // represent the correct size of the user-requested RVec<T>. This leaves the RVec<Byte_t> in an invalid
85 // state until it is cast to the correct type (by the `TryGet<T>` call).
86 fRVec.set_size(readerArraySize);
87 } else {
88 fRVec.clear();
89 }
90 }
91 fLastEntry = entry;
92 if (fCollectionType == ECollectionType::kStdArray)
93 return fRVec.data();
94 else
95 return &fRVec;
96}
97
99 std::string_view colName,
100 std::string_view valueTypeName,
102 : fTreeArray(std::make_unique<ROOT::Internal::TTreeReaderUntypedArray>(r, colName, valueTypeName)),
103 fCollectionType(collType)
104{
105}
106
size_t fValueSize
#define R__unlikely(expr)
Definition RConfig.hxx:599
long long Long64_t
Definition RtypesCore.h:69
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:229
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 r
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 simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
Definition TTreeReader.h:46
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...