Logo ROOT  
Reference Guide
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
28class TTree;
29class TTreeReader;
30
31/// \cond HIDDEN_SYMBOLS
32
33namespace ROOT {
34
35namespace Detail {
36namespace RDF {
37using ColumnNames_t = std::vector<std::string>;
38
39// fwd decl for ColumnName2ColumnTypeName
40class RCustomColumnBase;
41
42// type used for tag dispatching
43struct RInferredType {
44};
45
46} // end ns Detail
47} // end ns RDF
48
49namespace Internal {
50namespace RDF {
51using namespace ROOT::TypeTraits;
52using namespace ROOT::Detail::RDF;
53using namespace ROOT::RDF;
54
55/// Detect whether a type is an instantiation of vector<T,A>
56template <typename>
57struct IsVector_t : public std::false_type {};
58
59template <typename T, typename A>
60struct IsVector_t<std::vector<T, A>> : public std::true_type {};
61
62const std::type_info &TypeName2TypeID(const std::string &name);
63
64std::string TypeID2TypeName(const std::type_info &id);
65
66std::string ColumnName2ColumnTypeName(const std::string &colName, unsigned int namespaceID, TTree *, RDataSource *,
67 bool isCustomColumn, bool vector2rvec = true, unsigned int customColID = 0);
68
69char TypeName2ROOTTypeName(const std::string &b);
70
71unsigned int GetNSlots();
72
73/// `type` is TypeList if MustRemove is false, otherwise it is a TypeList with the first type removed
74template <bool MustRemove, typename TypeList>
75struct RemoveFirstParameterIf {
76 using type = TypeList;
77};
78
79template <typename TypeList>
80struct RemoveFirstParameterIf<true, TypeList> {
81 using type = RemoveFirstParameter_t<TypeList>;
82};
83
84template <bool MustRemove, typename TypeList>
85using RemoveFirstParameterIf_t = typename RemoveFirstParameterIf<MustRemove, TypeList>::type;
86
87template <bool MustRemove, typename TypeList>
88struct RemoveFirstTwoParametersIf {
89 using type = TypeList;
90};
91
92template <typename TypeList>
93struct RemoveFirstTwoParametersIf<true, TypeList> {
94 using typeTmp = typename RemoveFirstParameterIf<true, TypeList>::type;
96};
97
98template <bool MustRemove, typename TypeList>
99using RemoveFirstTwoParametersIf_t = typename RemoveFirstTwoParametersIf<MustRemove, TypeList>::type;
100
101/// Detect whether a type is an instantiation of RVec<T>
102template <typename>
103struct IsRVec_t : public std::false_type {};
104
105template <typename T>
106struct 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
111struct ValueType {
112 using value_type = typename T::value_type;
113};
114
115template <typename T>
116struct ValueType<T, false> {
117 using value_type = T;
118};
119
120template <typename T>
121struct ValueType<ROOT::VecOps::RVec<T>, false> {
122 using value_type = T;
123};
124
125std::vector<std::string> ReplaceDotWithUnderscore(const std::vector<std::string> &columnNames);
126
127/// Erase `that` element from vector `v`
128template <typename T>
129void 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
135void 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.
140Long64_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
#define b(i)
Definition: RSha256.hxx:100
long long Long64_t
Definition: RtypesCore.h:69
char name[80]
Definition: TGX11.cxx:109
int type
Definition: TGX11.cxx:120
RDataSource defines an API that RDataFrame can use to read arbitrary data formats.
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
Definition: TTreeReader.h:43
A TTree represents a columnar dataset.
Definition: TTree.h:72
ROOT::VecOps::RVec< T > RVec
Definition: RVec.hxx:62
std::vector< std::string > ReplaceDotWithUnderscore(const std::vector< std::string > &columnNames)
Replace occurrences of '.
Definition: RDFUtils.cxx:283
const std::type_info & TypeName2TypeID(const std::string &name)
Return the type_info associated to a name.
Definition: RDFUtils.cxx:41
unsigned int GetNSlots()
Definition: RDFUtils.cxx:270
char TypeName2ROOTTypeName(const std::string &b)
Convert type name (e.g.
Definition: RDFUtils.cxx:243
std::string TypeID2TypeName(const std::type_info &id)
Returns the name of a type starting from its type_info An empty string is returned in case of failure...
Definition: RDFUtils.cxx:83
Long64_t InterpreterCalc(const std::string &code, const std::string &context)
Definition: RDFUtils.cxx:310
std::string ColumnName2ColumnTypeName(const std::string &colName, unsigned int namespaceID, TTree *tree, RDataSource *ds, bool isCustomColumn, bool vector2rvec, unsigned int customColID)
Return a string containing the type of the given branch.
Definition: RDFUtils.cxx:210
void InterpreterDeclare(const std::string &code)
Definition: RDFUtils.cxx:302
double T(double x)
Definition: ChebyshevPol.h:34
ROOT type_traits extensions.
Definition: TypeTraits.hxx:23
VSD Structures.
Definition: StringConv.hxx:21
ROOT::Detail::RDF::ColumnNames_t ColumnNames_t
Definition: RDataFrame.cxx:788
Lightweight storage for a collection of types.
Definition: TypeTraits.hxx:27