Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ColumnReaderUtils.hxx
Go to the documentation of this file.
1// Author: Enrico Guiraud CERN 09/2020
2
3/*************************************************************************
4 * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#ifndef ROOT_RDF_COLUMNREADERUTILS
12#define ROOT_RDF_COLUMNREADERUTILS
13
14#include "RColumnReaderBase.hxx"
15#include "RDefineBase.hxx"
16#include "RDefineReader.hxx"
17#include "RDSColumnReader.hxx"
18#include "RTreeColumnReader.hxx"
19
20#include <ROOT/RDataSource.hxx>
21#include <ROOT/TypeTraits.hxx>
22#include <TError.h> // R__ASSERT
23#include <TTreeReader.h>
24
25#include <array>
26#include <map>
27#include <memory>
28#include <string>
29#include <typeinfo> // for typeid
30#include <vector>
31
32namespace ROOT {
33namespace Internal {
34namespace RDF {
35
36using namespace ROOT::TypeTraits;
38
39template <typename T>
40std::unique_ptr<RDFDetail::RColumnReaderBase>
42 const std::vector<void *> *DSValuePtrsPtr, const std::string &colName)
43{
44 using Ret_t = std::unique_ptr<RDFDetail::RColumnReaderBase>;
45
46 if (define != nullptr) // it's a Define'd column
47 return Ret_t(new RDefineReader(slot, *define, typeid(T)));
48
49 if (DSValuePtrsPtr != nullptr) {
50 // reading from a RDataSource with the old column reader interface
51 auto &DSValuePtrs = *DSValuePtrsPtr;
52 return Ret_t(new RDSColumnReader<T>(DSValuePtrs[slot]));
53 }
54
55 if (ds != nullptr) {
56 // reading from a RDataSource with the new column reader interface
57 return ds->GetColumnReaders(slot, colName, typeid(T));
58 }
59
60 // reading from a TTree
61 return Ret_t(new RTreeColumnReader<T>(*r, colName));
62}
63
64template <typename T>
65std::unique_ptr<RDFDetail::RColumnReaderBase>
67 const std::map<std::string, std::vector<void *>> &DSValuePtrsMap, TTreeReader *r,
68 ROOT::RDF::RDataSource *ds, const std::string &colName)
69{
70 const auto DSValuePtrsIt = DSValuePtrsMap.find(colName);
71 const std::vector<void *> *DSValuePtrsPtr = DSValuePtrsIt != DSValuePtrsMap.end() ? &DSValuePtrsIt->second : nullptr;
72 R__ASSERT(define != nullptr || r != nullptr || DSValuePtrsPtr != nullptr || ds != nullptr);
73 return MakeColumnReader<T>(slot, define, r, ds, DSValuePtrsPtr, colName);
74}
75
76/// This type aggregates some of the arguments passed to InitColumnReaders.
77/// We need to pass a single RColumnReadersInfo object rather than each argument separately because with too many
78/// arguments passed, gcc 7.5.0 and cling disagree on the ABI, which leads to the last function argument being read
79/// incorrectly from a compiled InitColumnReaders symbols when invoked from a jitted symbol.
81 const std::vector<std::string> &fColNames;
83 const bool *fIsDefine;
84 const std::map<std::string, std::vector<void *>> &fDSValuePtrsMap;
86};
87
88/// Create a group of column readers, one per type in the parameter pack.
89/// colInfo.fColNames and colInfo.fIsDefine are expected to have size equal to the parameter pack, and elements ordered
90/// accordingly, i.e. fIsDefine[0] refers to fColNames[0] which is of type "ColTypes[0]".
91template <typename... ColTypes>
92std::array<std::unique_ptr<RDFDetail::RColumnReaderBase>, sizeof...(ColTypes)>
94{
95 // see RColumnReadersInfo for why we pass these arguments like this rather than directly as function arguments
96 const auto &colNames = colInfo.fColNames;
97 const auto &customCols = colInfo.fCustomCols;
98 const bool *isDefine = colInfo.fIsDefine;
99 const auto &DSValuePtrsMap = colInfo.fDSValuePtrsMap;
100 auto *ds = colInfo.fDataSource;
101
102 const auto &customColMap = customCols.GetColumns();
103
104 int i = -1;
105 std::array<std::unique_ptr<RDFDetail::RColumnReaderBase>, sizeof...(ColTypes)> ret{
106 {{(++i, MakeColumnReadersHelper<ColTypes>(slot, isDefine[i] ? customColMap.at(colNames[i]).get() : nullptr,
107 DSValuePtrsMap, r, ds, colNames[i]))}...}};
108 return ret;
109
110 // avoid bogus "unused variable" warnings
111 (void)ds;
112 (void)slot;
113 (void)r;
114}
115
116} // namespace RDF
117} // namespace Internal
118} // namespace ROOT
119
120#endif // ROOT_RDF_COLUMNREADERS
ROOT::R::TRInterface & r
Definition Object.C:4
#define R__ASSERT(e)
Definition TError.h:120
typedef void((*Func_t)())
Encapsulates the columns defined by the user.
Column reader type that deals with values read from RDataSources.
Column reader for defined (aka custom) columns.
RTreeColumnReader specialization for TTree values read via TTreeReaderValues.
RDataSource defines an API that RDataFrame can use to read arbitrary data formats.
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
Definition TTreeReader.h:44
std::array< std::unique_ptr< RDFDetail::RColumnReaderBase >, sizeof...(ColTypes)> MakeColumnReaders(unsigned int slot, TTreeReader *r, TypeList< ColTypes... >, const RColumnReadersInfo &colInfo)
Create a group of column readers, one per type in the parameter pack.
std::unique_ptr< RDFDetail::RColumnReaderBase > MakeColumnReader(unsigned int slot, RDFDetail::RDefineBase *define, TTreeReader *r, ROOT::RDF::RDataSource *ds, const std::vector< void * > *DSValuePtrsPtr, const std::string &colName)
std::unique_ptr< RDFDetail::RColumnReaderBase > MakeColumnReadersHelper(unsigned int slot, RDFDetail::RDefineBase *define, const std::map< std::string, std::vector< void * > > &DSValuePtrsMap, TTreeReader *r, ROOT::RDF::RDataSource *ds, const std::string &colName)
ROOT type_traits extensions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
This type aggregates some of the arguments passed to InitColumnReaders.
const std::map< std::string, std::vector< void * > > & fDSValuePtrsMap
const std::vector< std::string > & fColNames
Lightweight storage for a collection of types.