Logo ROOT   6.16/01
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 extraConversions = 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} // end NS RDF
135} // end NS Internal
136} // end NS ROOT
137
138/// \endcond
139
140#endif // RDFUTILS
SVector< double, 2 > v
Definition: Dict.h:5
#define b(i)
Definition: RSha256.hxx:100
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 colmnar datasets such as TTree,...
Definition: TTreeReader.h:44
A TTree object has a header with a name and a title.
Definition: TTree.h:71
std::vector< std::string > ReplaceDotWithUnderscore(const std::vector< std::string > &columnNames)
Replace occurrences of '.
Definition: RDFUtils.cxx:259
const std::type_info & TypeName2TypeID(const std::string &name)
Return the type_info associated to a name.
Definition: RDFUtils.cxx:40
unsigned int GetNSlots()
Definition: RDFUtils.cxx:246
char TypeName2ROOTTypeName(const std::string &b)
Convert type name (e.g.
Definition: RDFUtils.cxx:219
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:82
std::string ColumnName2ColumnTypeName(const std::string &colName, unsigned int namespaceID, TTree *tree, RDataSource *ds, bool isCustomColumn, bool vector2tvec, unsigned int customColID)
Return a string containing the type of the given branch.
Definition: RDFUtils.cxx:186
double T(double x)
Definition: ChebyshevPol.h:34
ROOT type_traits extensions.
Definition: TypeTraits.hxx:23
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
ROOT::Detail::RDF::ColumnNames_t ColumnNames_t
Definition: RDataFrame.cxx:790
STL namespace.
Lightweight storage for a collection of types.
Definition: TypeTraits.hxx:27