11#ifndef ROOT_RCOLUMNVALUE
12#define ROOT_RCOLUMNVALUE
26#include <initializer_list>
65 using MustUseRVec_t = IsRVec_t<T>;
68 using ColumnValue_t =
typename std::conditional<MustUseRVec_t::value, TakeFirstParameter_t<T>,
T>
::type;
69 using TreeReader_t =
typename std::conditional<MustUseRVec_t::value, TTreeReaderArray<ColumnValue_t>,
74 enum class EColumnKind { kTree, kCustomColumn, kDataSource,
kInvalid };
78 unsigned int fSlot = std::numeric_limits<unsigned int>::max();
86 std::unique_ptr<TreeReader_t> fTreeReader;
92 RCustomColumnBase *fCustomColumn;
94 enum class EStorageType : char { kContiguous,
kUnknown, kSparse };
100 bool fCopyWarningPrinted =
false;
105 void SetTmpColumn(
unsigned int slot, RCustomColumnBase *customColumn)
107 fCustomColumn = customColumn;
110 if (0 != strcmp(customColumn->GetTypeId().name(),
typeid(
T).name()))
111 throw std::runtime_error(
112 std::string(
"RColumnValue: type specified for column \"" + customColumn->GetName() +
"\" is ") +
116 if (customColumn->IsDataSourceColumn()) {
117 fColumnKind = EColumnKind::kDataSource;
118 fDSValuePtr =
static_cast<T **
>(customColumn->GetValuePtr(slot));
120 fColumnKind = EColumnKind::kCustomColumn;
121 fCustomValuePtr =
static_cast<T *
>(customColumn->GetValuePtr(slot));
128 fColumnKind = EColumnKind::kTree;
129 fTreeReader = std::make_unique<TreeReader_t>(*
r, bn.c_str());
136 template <typename U = T, typename std::enable_if<!RColumnValue<U>::MustUseRVec_t::value,
int>
::type = 0>
139 if (fColumnKind == EColumnKind::kTree) {
140 return *(fTreeReader->Get());
142 fCustomColumn->Update(fSlot, entry);
143 return fColumnKind == EColumnKind::kCustomColumn ? *fCustomValuePtr : **fDSValuePtr;
150 template <
typename U =
T,
151 typename std::enable_if<RColumnValue<U>::MustUseRVec_t::value && !std::is_same<U, RVec<bool>>::value,
155 if (fColumnKind == EColumnKind::kTree) {
156 auto &readerArray = *fTreeReader;
166 (1 == (&readerArray[1] - &readerArray[0])) ? EStorageType::kContiguous : EStorageType::kSparse;
169 const auto readerArraySize = readerArray.GetSize();
170 if (EStorageType::kContiguous == fStorageType ||
172 if (readerArraySize > 0) {
176 auto readerArrayAddr = &readerArray.At(0);
177 T rvec(readerArrayAddr, readerArraySize);
181 swap(fRVec, emptyVec);
186 if (!fCopyWarningPrinted) {
188 "Branch %s hangs from a non-split branch. A copy is being performed in order "
189 "to properly read the content.",
190 readerArray.GetBranchName());
191 fCopyWarningPrinted =
true;
194 (
void)fCopyWarningPrinted;
196 if (readerArraySize > 0) {
197 T rvec(readerArray.begin(), readerArray.end());
201 swap(fRVec, emptyVec);
207 fCustomColumn->Update(fSlot, entry);
208 return fColumnKind == EColumnKind::kCustomColumn ? *fCustomValuePtr : **fDSValuePtr;
217 template <
typename U =
T,
218 typename std::enable_if<RColumnValue<U>::MustUseRVec_t::value && std::is_same<U, RVec<bool>>::value,
222 if (fColumnKind == EColumnKind::kTree) {
223 auto &readerArray = *fTreeReader;
224 const auto readerArraySize = readerArray.GetSize();
225 if (readerArraySize > 0) {
227 T rvec(readerArray.begin(), readerArray.end());
231 swap(fRVec, emptyVec);
236 fCustomColumn->Update(fSlot, entry);
237 return fColumnKind == EColumnKind::kCustomColumn ? *fCustomValuePtr : **fDSValuePtr;
251 if (EColumnKind::kTree == fColumnKind) {
260#if __cplusplus < 201703L
283template <
typename... BranchTypes>
285 using type = std::tuple<RColumnValue<BranchTypes>...>;
288template <
typename BranchType>
292template <
typename ValueTuple, std::size_t...
S>
296 std::initializer_list<int> expander{(std::get<S>(values).Reset(), 0)...};
void Warning(const char *location, const char *msgfmt,...)
typedef void((*Func_t)())
Helper class that updates and returns TTree branches as well as RDataFrame temporary columns.
A "std::vector"-like collection of values implementing handy operation to analyse them.
An interface for reading values stored in ROOT columnar datasets.
A simple, robust and fast interface to read values from ROOT colmnar datasets such as TTree,...
void swap(TDirectoryEntry &e1, TDirectoryEntry &e2) noexcept
std::string TypeID2TypeName(const std::type_info &id)
Returns the name of a type starting from its type_info An empty string is returned in case of failure...
void ResetRDFValueTuple(std::vector< RTypeErasedColumnValue > &values, std::index_sequence< S... >, ROOT::TypeTraits::TypeList< ColTypes... >)
This overload is specialized to act on RTypeErasedColumnValues instead of RColumnValues.
typename TRDFValueTuple< BranchType >::type RDFValueTuple_t
Namespace for new ROOT classes and functions.
RooArgSet S(const RooAbsArg &v1)
std::tuple< RColumnValue< BranchTypes >... > type
Lightweight storage for a collection of types.