Logo ROOT  
Reference Guide
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 
32 namespace ROOT {
33 namespace Internal {
34 namespace RDF {
35 
36 using namespace ROOT::TypeTraits;
37 namespace RDFDetail = ROOT::Detail::RDF;
38 
39 template <typename T>
40 std::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 
64 template <typename T>
65 std::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]".
91 template <typename... ColTypes>
92 std::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::TypeTraits
ROOT type_traits extensions.
Definition: TypeTraits.hxx:21
r
ROOT::R::TRInterface & r
Definition: Object.C:4
ROOT::Internal::RDF::MakeColumnReadersHelper
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)
Definition: ColumnReaderUtils.hxx:66
extract_docstrings.ds
ds
Definition: extract_docstrings.py:40
ROOT::TypeTraits::TypeList
Lightweight storage for a collection of types.
Definition: TypeTraits.hxx:25
ROOT::Internal::RDF::RBookedDefines
Encapsulates the columns defined by the user.
Definition: RBookedDefines.hxx:39
RDefineBase.hxx
ROOT::Internal::RDF::RDefineReader
Column reader for defined (aka custom) columns.
Definition: RDefineReader.hxx:30
ROOT::Detail::RDF
Definition: GraphUtils.hxx:28
ROOT::RDF::RDataSource
RDataSource defines an API that RDataFrame can use to read arbitrary data formats.
Definition: RDataSource.hxx:106
RDataSource.hxx
ROOT::Detail::RDF::RDefineBase
Definition: RDefineBase.hxx:34
TTreeReader.h
ROOT::Internal::RDF::RColumnReadersInfo
This type aggregates some of the arguments passed to InitColumnReaders.
Definition: ColumnReaderUtils.hxx:80
ROOT::Internal::RDF::MakeColumnReaders
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.
Definition: ColumnReaderUtils.hxx:93
ROOT::Internal::RDF::RTreeColumnReader
RTreeColumnReader specialization for TTree values read via TTreeReaderValues.
Definition: RTreeColumnReader.hxx:31
ROOT::Internal::RDF::RColumnReadersInfo::fDataSource
ROOT::RDF::RDataSource * fDataSource
Definition: ColumnReaderUtils.hxx:85
TTreeReader
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
Definition: TTreeReader.h:44
RDefineReader.hxx
TypeTraits.hxx
ROOT::Internal::RDF::RColumnReadersInfo::fIsDefine
const bool * fIsDefine
Definition: ColumnReaderUtils.hxx:83
void
typedef void((*Func_t)())
ROOT::Internal::RDF::RDSColumnReader
Column reader type that deals with values read from RDataSources.
Definition: RDSColumnReader.hxx:23
RDSColumnReader.hxx
ROOT::Internal::RDF::RColumnReadersInfo::fColNames
const std::vector< std::string > & fColNames
Definition: ColumnReaderUtils.hxx:81
ROOT::Internal::RDF::RColumnReadersInfo::fCustomCols
const RBookedDefines & fCustomCols
Definition: ColumnReaderUtils.hxx:82
R__ASSERT
#define R__ASSERT(e)
Definition: TError.h:120
ROOT::Internal::RDF::MakeColumnReader
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)
Definition: ColumnReaderUtils.hxx:41
ROOT::Math::Chebyshev::T
double T(double x)
Definition: ChebyshevPol.h:34
RColumnReaderBase.hxx
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: EExecutionPolicy.hxx:4
RTreeColumnReader.hxx
ROOT::Internal::RDF::RColumnReadersInfo::fDSValuePtrsMap
const std::map< std::string, std::vector< void * > > & fDSValuePtrsMap
Definition: ColumnReaderUtils.hxx:84
TError.h