Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
Utils.hxx
Go to the documentation of this file.
1 // Author: Enrico Guiraud, Danilo Piparo CERN 12/2016
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_RDFUTILS
12 #define ROOT_RDFUTILS
13 
14 #include "ROOT/RDataSource.hxx" // ColumnName2ColumnTypeName
15 #include "ROOT/TypeTraits.hxx"
16 #include "ROOT/RVec.hxx"
18 #include "TH1.h"
19 
20 #include <array>
21 #include <deque>
22 #include <functional>
23 #include <memory>
24 #include <string>
25 #include <type_traits> // std::decay
26 #include <vector>
27 
28 class TTree;
29 class TTreeReader;
30 
31 /// \cond HIDDEN_SYMBOLS
32 
33 namespace ROOT {
34 
35 namespace Detail {
36 namespace RDF {
37 using ColumnNames_t = std::vector<std::string>;
38 
39 // fwd decl for ColumnName2ColumnTypeName
40 class RCustomColumnBase;
41 
42 // type used for tag dispatching
43 struct RInferredType {
44 };
45 
46 } // end ns Detail
47 } // end ns RDF
48 
49 namespace Internal {
50 namespace RDF {
51 using namespace ROOT::TypeTraits;
52 using namespace ROOT::Detail::RDF;
53 using namespace ROOT::RDF;
54 
55 /// Detect whether a type is an instantiation of vector<T,A>
56 template <typename>
57 struct IsVector_t : public std::false_type {};
58 
59 template <typename T, typename A>
60 struct IsVector_t<std::vector<T, A>> : public std::true_type {};
61 
62 const std::type_info &TypeName2TypeID(const std::string &name);
63 
64 std::string TypeID2TypeName(const std::type_info &id);
65 
66 std::string ColumnName2ColumnTypeName(const std::string &colName, unsigned int namespaceID, TTree *, RDataSource *,
67  bool isCustomColumn, bool vector2rvec = true, unsigned int customColID = 0);
68 
69 char TypeName2ROOTTypeName(const std::string &b);
70 
71 unsigned int GetNSlots();
72 
73 /// `type` is TypeList if MustRemove is false, otherwise it is a TypeList with the first type removed
74 template <bool MustRemove, typename TypeList>
75 struct RemoveFirstParameterIf {
76  using type = TypeList;
77 };
78 
79 template <typename TypeList>
80 struct RemoveFirstParameterIf<true, TypeList> {
81  using type = RemoveFirstParameter_t<TypeList>;
82 };
83 
84 template <bool MustRemove, typename TypeList>
85 using RemoveFirstParameterIf_t = typename RemoveFirstParameterIf<MustRemove, TypeList>::type;
86 
87 template <bool MustRemove, typename TypeList>
88 struct RemoveFirstTwoParametersIf {
89  using type = TypeList;
90 };
91 
92 template <typename TypeList>
93 struct RemoveFirstTwoParametersIf<true, TypeList> {
94  using typeTmp = typename RemoveFirstParameterIf<true, TypeList>::type;
95  using type = typename RemoveFirstParameterIf<true, typeTmp>::type;
96 };
97 
98 template <bool MustRemove, typename TypeList>
99 using RemoveFirstTwoParametersIf_t = typename RemoveFirstTwoParametersIf<MustRemove, TypeList>::type;
100 
101 /// Detect whether a type is an instantiation of RVec<T>
102 template <typename>
103 struct IsRVec_t : public std::false_type {};
104 
105 template <typename T>
106 struct IsRVec_t<ROOT::VecOps::RVec<T>> : public std::true_type {};
107 
108 // Check the value_type type of a type with a SFINAE to allow compilation in presence
109 // fundamental types
110 template <typename T, bool IsContainer = IsContainer<typename std::decay<T>::type>::value>
111 struct ValueType {
112  using value_type = typename T::value_type;
113 };
114 
115 template <typename T>
116 struct ValueType<T, false> {
117  using value_type = T;
118 };
119 
120 template <typename T>
121 struct ValueType<ROOT::VecOps::RVec<T>, false> {
122  using value_type = T;
123 };
124 
125 std::vector<std::string> ReplaceDotWithUnderscore(const std::vector<std::string> &columnNames);
126 
127 /// Erase `that` element from vector `v`
128 template <typename T>
129 void Erase(const T &that, std::vector<T> &v)
130 {
131  v.erase(std::remove(v.begin(), v.end(), that), v.end());
132 }
133 
134 /// Declare code in the interpreter via the TInterpreter::Declare method, throw in case of errors
135 void InterpreterDeclare(const std::string &code);
136 
137 /// Jit code in the interpreter with TInterpreter::Calc, throw in case of errors.
138 /// The optional `context` parameter, if present, is mentioned in the error message.
139 /// The pointer returned by the call to TInterpreter::Calc is returned in case of success.
140 Long64_t InterpreterCalc(const std::string &code, const std::string &context = "");
141 
142 } // end NS RDF
143 } // end NS Internal
144 } // end NS ROOT
145 
146 /// \endcond
147 
148 #endif // RDFUTILS