Logo ROOT   6.14/05
Reference Guide
RDFNodesUtils.hxx
Go to the documentation of this file.
1 // Author: Enrico Guiraud, Danilo Piparo CERN 02/2018
2 
3 /*************************************************************************
4  * Copyright (C) 1995-2016, 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_RDFNODES_UTILS
12 #define ROOT_RDFNODES_UTILS
13 
15 #include "ROOT/RVec.hxx"
16 #include "ROOT/RDFUtils.hxx" // ColumnNames_t
17 
18 namespace ROOT {
19 namespace Internal {
20 namespace RDF {
21 using namespace ROOT::VecOps;
22 using namespace ROOT::Detail::RDF;
23 using namespace ROOT::RDF;
24 
25 /// Choose between TTreeReader{Array,Value} depending on whether the branch type
26 /// T is a `RVec<T>` or any other type (respectively).
27 template <typename T>
30 };
31 
32 template <typename T>
35 };
36 
37 template <typename T>
39 
40 /// Initialize a tuple of TColumnValues.
41 /// For real TTree branches a TTreeReader{Array,Value} is built and passed to the
42 /// TColumnValue. For temporary columns a pointer to the corresponding variable
43 /// is passed instead.
44 template <typename RDFValueTuple, std::size_t... S>
45 void InitRDFValues(unsigned int slot, RDFValueTuple &valueTuple, TTreeReader *r, const ColumnNames_t &bn,
46  const ColumnNames_t &tmpbn,
47  const std::map<std::string, std::shared_ptr<RCustomColumnBase>> &customCols,
49 {
50  // isTmpBranch has length bn.size(). Elements are true if the corresponding
51  // branch is a temporary branch created with Define, false if they are
52  // actual branches present in the TTree.
53  std::array<bool, sizeof...(S)> isTmpColumn;
54  for (auto i = 0u; i < isTmpColumn.size(); ++i)
55  isTmpColumn[i] = std::find(tmpbn.begin(), tmpbn.end(), bn.at(i)) != tmpbn.end();
56 
57  // hack to expand a parameter pack without c++17 fold expressions.
58  // The statement defines a variable with type std::initializer_list<int>, containing all zeroes, and SetTmpColumn or
59  // SetProxy are conditionally executed as the braced init list is expanded. The final ... expands S.
60  int expander[] = {(isTmpColumn[S] ? std::get<S>(valueTuple).SetTmpColumn(slot, customCols.at(bn.at(S)).get())
61  : std::get<S>(valueTuple).MakeProxy(r, bn.at(S)),
62  0)...,
63  0};
64  (void)expander; // avoid "unused variable" warnings for expander on gcc4.9
65  (void)slot; // avoid _bogus_ "unused variable" warnings for slot on gcc 4.9
66  (void)r; // avoid "unused variable" warnings for r on gcc5.2
67 }
68 
69 } // namespace RDF
70 } // namespace Internal
71 } // namespace ROOT
72 
73 #endif
TTreeReader is a simple, robust and fast interface to read values from a TTree, TChain or TNtuple...
Definition: TTreeReader.h:43
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
double T(double x)
Definition: ChebyshevPol.h:34
typename TReaderValueOrArray< T >::Proxy_t ReaderValueOrArray_t
Extracts data from a TTree.
A "std::vector"-like collection of values implementing handy operation to analyse them...
Definition: RVec.hxx:146
RooArgSet S(const RooAbsArg &v1)
ROOT::R::TRInterface & r
Definition: Object.C:4
Choose between TTreeReader{Array,Value} depending on whether the branch type T is a RVec<T> or any ot...
Extracts array data from a TTree.
typedef void((*Func_t)())
void InitRDFValues(unsigned int slot, RDFValueTuple &valueTuple, TTreeReader *r, const ColumnNames_t &bn, const ColumnNames_t &tmpbn, const std::map< std::string, std::shared_ptr< RCustomColumnBase >> &customCols, std::index_sequence< S... >)
Initialize a tuple of TColumnValues.