Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
NodesUtils.hxx
Go to the documentation of this file.
1 // Author: Enrico Guiraud, Danilo Piparo CERN 02/2018
2 
3 /*************************************************************************
4  * Copyright (C) 1995-2018, 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 
16 #include "ROOT/RVec.hxx"
17 #include "ROOT/RDF/Utils.hxx" // ColumnNames_t
18 
19 /// \cond
20 template <typename T>
21 class TTreeReaderValue;
22 
23 template <typename T>
24 class TTreeReaderArray;
25 /// \endcond
26 
27 namespace ROOT {
28 namespace Internal {
29 namespace RDF {
30 using namespace ROOT::VecOps;
31 using namespace ROOT::Detail::RDF;
32 using namespace ROOT::RDF;
33 
34 /// Choose between TTreeReader{Array,Value} depending on whether the branch type
35 /// T is a `RVec<T>` or any other type (respectively).
36 template <typename T>
37 struct TReaderValueOrArray {
38  using Proxy_t = TTreeReaderValue<T>;
39 };
40 
41 template <typename T>
42 struct TReaderValueOrArray<RVec<T>> {
43  using Proxy_t = TTreeReaderArray<T>;
44 };
45 
46 template <typename T>
47 using ReaderValueOrArray_t = typename TReaderValueOrArray<T>::Proxy_t;
48 
49 /// Initialize a tuple of RColumnValues.
50 /// For real TTree branches a TTreeReader{Array,Value} is built and passed to the
51 /// RColumnValue. For temporary columns a pointer to the corresponding variable
52 /// is passed instead.
53 template <typename RDFValueTuple, std::size_t... S>
54 void InitRDFValues(unsigned int slot, RDFValueTuple &valueTuple, TTreeReader *r, const ColumnNames_t &bn,
55  const RBookedCustomColumns &customCols, std::index_sequence<S...>,
56  const std::array<bool, sizeof...(S)> &isCustomColumn)
57 {
58  // hack to expand a parameter pack without c++17 fold expressions.
59  // The statement defines a variable with type std::initializer_list<int>, containing all zeroes, and SetTmpColumn or
60  // SetProxy are conditionally executed as the braced init list is expanded. The final ... expands S.
61  int expander[] = {(isCustomColumn[S]
62  ? std::get<S>(valueTuple).SetTmpColumn(slot, customCols.GetColumns().at(bn[S]).get())
63  : std::get<S>(valueTuple).MakeProxy(r, bn[S]),
64  0)...,
65  0};
66  (void)expander; // avoid "unused variable" warnings for expander on gcc4.9
67  (void)slot; // avoid _bogus_ "unused variable" warnings for slot on gcc 4.9
68  (void)r; // avoid "unused variable" warnings for r on gcc5.2
69 }
70 
71 } // namespace RDF
72 } // namespace Internal
73 } // namespace ROOT
74 
75 #endif