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; // we already pointed our fRVec to the right address
38
39 auto &readerArray = *fTreeArray;
40 const auto readerArraySize = readerArray.GetSize();
41
42 // The reader could not read an array, signal this back to the node requesting the value
44 return nullptr;
45
46 if (readerArray.IsContiguous() && !(fCollectionType == ECollectionType::kRVecBool)) {
47 if (readerArraySize > 0) {
48 // trigger loading of the contents of the TTreeReaderArray
49 // the address of the first element in the reader array is not necessarily equal to
50 // the address returned by the GetAddress method
52 swap(fRVec, rvec);
53 } else {
54 fRVec.clear();
55 }
56 } else {
57 // The storage is not contiguous: we cannot but copy into the RVec
58#ifndef NDEBUG
59 if (!fCopyWarningPrinted && !(fCollectionType == ECollectionType::kRVecBool)) {
60 Warning("RTreeColumnReader::Get",
61 "Branch %s hangs from a non-split branch. A copy is being performed in order "
62 "to properly read the content.",
63 readerArray.GetBranchName());
64 fCopyWarningPrinted = true;
65 }
66#else
67 (void)fCopyWarningPrinted;
68#endif
69 if (readerArraySize > 0) {
70 // Caching the value type size since GetValueSize might be expensive.
71 if (fValueSize == 0)
72 fValueSize = readerArray.GetValueSize();
73 assert(fValueSize > 0 && "Could not retrieve size of collection value type.");
74 // Array is not contiguous, make a full copy of it.
75 fRVec.clear();
76 fRVec.reserve(readerArraySize * fValueSize);
77 for (std::size_t i{0}; i < readerArraySize; i++) {
78 auto val = readerArray.At(i);
79 std::copy(val, val + fValueSize, std::back_inserter(fRVec));
80 }
81 // RVec's `size()` method returns the value of the `fSize` data member, unlike std::vector's `size()`
82 // which returns the distance between begin and end divided by the size of the collection value type.
83 // This difference is important in this case: we reserved enough space in the RVec to fill
84 // `readerArraySize * fValueSize` bytes, but the reader will need to read just `readerArraySize` elements
85 // adjusted to the correct `fValueSize` bytes per element. Thus, we set the size of the RVec here to
86 // represent the correct size of the user-requested RVec<T>. This leaves the RVec<Byte_t> in an invalid
87 // state until it is cast to the correct type (by the `TryGet<T>` call).
88 fRVec.set_size(readerArraySize);
89 } else {
90 fRVec.clear();
91 }
92 }
93 fLastEntry = entry;
94 if (fCollectionType == ECollectionType::kStdArray)
95 return fRVec.data();
96 else
97 return &fRVec;
98}
99
101 std::string_view colName,
102 std::string_view valueTypeName,
104 : fTreeArray(std::make_unique<ROOT::Internal::TTreeReaderUntypedArray>(r, colName, valueTypeName)),
105 fCollectionType(collType)
106{
107}
108
110
112 TTreeReader &r, std::unique_ptr<ROOT::Detail::RDF::RColumnReaderBase> valueReader, std::string_view maskName,
113 unsigned int maskIndex)
114 : fValueReader{std::move(valueReader)},
115 fTreeValueMask{std::make_unique<TTreeReaderValue<uint64_t>>(r, maskName.data())},
116 fMaskIndex{maskIndex}
117{
118}
119
121
123{
124 const std::bitset<64> mask{*fTreeValueMask->Get()};
125 if (mask.test(fMaskIndex) == false)
126 return nullptr;
127
128 return fValueReader->TryGet<void>(event);
129}
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