// Author: Enrico Guiraud, Danilo Piparo CERN 12/2016 /************************************************************************* * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers. * * All rights reserved. * * * * For the licensing terms see $ROOTSYS/LICENSE. * * For the list of contributors see $ROOTSYS/README/CREDITS. * *************************************************************************/ #ifndef ROOT_RDFUTILS #define ROOT_RDFUTILS #include "ROOT/RDataSource.hxx" // ColumnName2ColumnTypeName #include "ROOT/TypeTraits.hxx" #include "ROOT/RVec.hxx" #include "ROOT/RSnapshotOptions.hxx" #include "ROOT/RSpan.hxx" // for IsDataContainer #include "TH1.h" #include #include #include #include #include #include // std::decay class TTree; class TTreeReader; /// \cond HIDDEN_SYMBOLS namespace ROOT { namespace Detail { namespace RDF { using ColumnNames_t = std::vector; // fwd decl for ColumnName2ColumnTypeName class RCustomColumnBase; // type used for tag dispatching struct RInferredType { }; } // end ns Detail } // end ns RDF namespace Internal { namespace RDF { using namespace ROOT::TypeTraits; using namespace ROOT::Detail::RDF; using namespace ROOT::RDF; /// Check for container traits. /// /// Note that for all uses in RDF we don't want to classify std::string as a container. /// Template specializations of IsDataContainer make it return `true` for std::span, std::vector and /// RVec, which we do want to count as containers even though they do not satisfy all the traits tested by the /// generic IsDataContainer. template struct IsDataContainer { using Test_t = typename std::decay::type; template static constexpr bool Test(A *pt, A const *cpt = nullptr, decltype(pt->begin()) * = nullptr, decltype(pt->end()) * = nullptr, decltype(cpt->begin()) * = nullptr, decltype(cpt->end()) * = nullptr, typename A::iterator *pi = nullptr, typename A::const_iterator *pci = nullptr) { using It_t = typename A::iterator; using CIt_t = typename A::const_iterator; using V_t = typename A::value_type; return std::is_samebegin()), It_t>::value && std::is_sameend()), It_t>::value && std::is_samebegin()), CIt_t>::value && std::is_sameend()), CIt_t>::value && std::is_same::value && std::is_same::value && !std::is_same::value; } template static constexpr bool Test(...) { return false; } static constexpr bool value = Test(nullptr); }; template<> struct IsDataContainer> { static constexpr bool value = true; }; template<> struct IsDataContainer> { static constexpr bool value = true; }; template struct IsDataContainer> { static constexpr bool value = true; }; /// Detect whether a type is an instantiation of vector template struct IsVector_t : public std::false_type {}; template struct IsVector_t> : public std::true_type {}; const std::type_info &TypeName2TypeID(const std::string &name); std::string TypeID2TypeName(const std::type_info &id); std::string ColumnName2ColumnTypeName(const std::string &colName, TTree *, RDataSource *, RCustomColumnBase *, bool vector2rvec = true); char TypeName2ROOTTypeName(const std::string &b); unsigned int GetNSlots(); /// `type` is TypeList if MustRemove is false, otherwise it is a TypeList with the first type removed template struct RemoveFirstParameterIf { using type = TypeList; }; template struct RemoveFirstParameterIf { using type = RemoveFirstParameter_t; }; template using RemoveFirstParameterIf_t = typename RemoveFirstParameterIf::type; template struct RemoveFirstTwoParametersIf { using type = TypeList; }; template struct RemoveFirstTwoParametersIf { using typeTmp = typename RemoveFirstParameterIf::type; using type = typename RemoveFirstParameterIf::type; }; template using RemoveFirstTwoParametersIf_t = typename RemoveFirstTwoParametersIf::type; /// Detect whether a type is an instantiation of RVec template struct IsRVec_t : public std::false_type {}; template struct IsRVec_t> : public std::true_type {}; // Check the value_type type of a type with a SFINAE to allow compilation in presence // fundamental types template ::type>::value || std::is_same::value> struct ValueType { using value_type = typename T::value_type; }; template struct ValueType { using value_type = T; }; template struct ValueType, false> { using value_type = T; }; std::vector ReplaceDotWithUnderscore(const std::vector &columnNames); /// Erase `that` element from vector `v` template void Erase(const T &that, std::vector &v) { v.erase(std::remove(v.begin(), v.end(), that), v.end()); } /// Declare code in the interpreter via the TInterpreter::Declare method, throw in case of errors void InterpreterDeclare(const std::string &code); /// Jit code in the interpreter with TInterpreter::Calc, throw in case of errors. /// The optional `context` parameter, if present, is mentioned in the error message. /// The pointer returned by the call to TInterpreter::Calc is returned in case of success. Long64_t InterpreterCalc(const std::string &code, const std::string &context = ""); } // end NS RDF } // end NS Internal } // end NS ROOT /// \endcond #endif // RDFUTILS