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 "RColumnRegister.hxx"
16#include "RDefineBase.hxx"
17#include "RDefineReader.hxx"
18#include "RDSColumnReader.hxx"
19#include "RLoopManager.hxx"
20#include "RTreeColumnReader.hxx"
21#include "RVariationBase.hxx"
22#include "RVariationReader.hxx"
23
24#include <ROOT/RDataSource.hxx>
25#include <ROOT/TypeTraits.hxx>
26#include <TTreeReader.h>
27
28#include <array>
29#include <cassert>
30#include <map>
31#include <memory>
32#include <string>
33#include <typeinfo> // for typeid
34#include <vector>
35
36namespace ROOT {
37namespace Internal {
38namespace RDF {
39
40using namespace ROOT::TypeTraits;
42
43template <typename T>
44RDFDetail::RColumnReaderBase *GetColumnReader(unsigned int slot, RColumnReaderBase *defineOrVariationReader,
45 RLoopManager &lm, TTreeReader *r, const std::string &colName)
46{
47 if (defineOrVariationReader != nullptr)
48 return defineOrVariationReader;
49
50 // Check if we already inserted a reader for this column in the dataset column readers (RDataSource or Tree/TChain
51 // readers)
52 auto *datasetColReader = lm.GetDatasetColumnReader(slot, colName, typeid(T));
53 if (datasetColReader != nullptr)
54 return datasetColReader;
55
56 assert(r != nullptr && "We could not find a reader for this column, this should never happen at this point.");
57
58 // Make a RTreeColumnReader for this column and insert it in RLoopManager's map
59 auto treeColReader = std::make_unique<RTreeColumnReader<T>>(*r, colName);
60 return lm.AddTreeColumnReader(slot, colName, std::move(treeColReader), typeid(T));
61}
62
63/// This type aggregates some of the arguments passed to GetColumnReaders.
64/// We need to pass a single RColumnReadersInfo object rather than each argument separately because with too many
65/// arguments passed, gcc 7.5.0 and cling disagree on the ABI, which leads to the last function argument being read
66/// incorrectly from a compiled GetColumnReaders symbols when invoked from a jitted symbol.
68 const std::vector<std::string> &fColNames;
70 const bool *fIsDefine;
72};
73
74/// Create a group of column readers, one per type in the parameter pack.
75template <typename... ColTypes>
76std::array<RDFDetail::RColumnReaderBase *, sizeof...(ColTypes)>
78 const std::string &variationName = "nominal")
79{
80 // see RColumnReadersInfo for why we pass these arguments like this rather than directly as function arguments
81 const auto &colNames = colInfo.fColNames;
82 auto &lm = colInfo.fLoopManager;
83 auto &colRegister = colInfo.fColRegister;
84
85 int i = -1;
86 std::array<RDFDetail::RColumnReaderBase *, sizeof...(ColTypes)> ret{
87 (++i, GetColumnReader<ColTypes>(slot, colRegister.GetReader(slot, colNames[i], variationName, typeid(ColTypes)),
88 lm, r, colNames[i]))...};
89 return ret;
90}
91
92// Shortcut overload for the case of no columns
93inline std::array<RDFDetail::RColumnReaderBase *, 0>
94GetColumnReaders(unsigned int, TTreeReader *, TypeList<>, const RColumnReadersInfo &, const std::string & = "nominal")
95{
96 return {};
97}
98
99} // namespace RDF
100} // namespace Internal
101} // namespace ROOT
102
103#endif // ROOT_RDF_COLUMNREADERS
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
The head node of a RDF computation graph.
RColumnReaderBase * GetDatasetColumnReader(unsigned int slot, const std::string &col, const std::type_info &ti) const
RColumnReaderBase * AddTreeColumnReader(unsigned int slot, const std::string &col, std::unique_ptr< RColumnReaderBase > &&reader, const std::type_info &ti)
Register a new RTreeColumnReader with this RLoopManager.
A binder for user-defined columns, variations and aliases.
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
Definition TTreeReader.h:44
std::array< RDFDetail::RColumnReaderBase *, sizeof...(ColTypes)> GetColumnReaders(unsigned int slot, TTreeReader *r, TypeList< ColTypes... >, const RColumnReadersInfo &colInfo, const std::string &variationName="nominal")
Create a group of column readers, one per type in the parameter pack.
RDFDetail::RColumnReaderBase * GetColumnReader(unsigned int slot, RColumnReaderBase *defineOrVariationReader, RLoopManager &lm, TTreeReader *r, 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 GetColumnReaders.
const std::vector< std::string > & fColNames
Lightweight storage for a collection of types.