11#ifndef ROOT_RDF_TINTERFACE_UTILS
12#define ROOT_RDF_TINTERFACE_UTILS
51template<
typename T,
typename V>
75 std::unique_ptr<RDFInternal::RActionBase> actionPtr);
84class RIgnoreErrorLevelRAII {
89 RIgnoreErrorLevelRAII(
int errorIgnoreLevel) {
gErrorIgnoreLevel = errorIgnoreLevel; }
114template <typename T, bool ISV6HISTO = std::is_base_of<TH1, T>::value>
117 static bool HasAxisLimits(
T &
h)
119 auto xaxis =
h.GetXaxis();
120 return !(xaxis->GetXmin() == 0. && xaxis->GetXmax() == 0.);
125struct HistoUtils<
T, false> {
126 static void SetCanExtendAllAxes(
T &) {}
127 static bool HasAxisLimits(
T &) {
return true; }
131template <
typename... BranchTypes,
typename ActionTag,
typename ActionResultType,
typename PrevNodeType>
132std::unique_ptr<RActionBase>
133BuildAction(
const ColumnNames_t &bl,
const std::shared_ptr<ActionResultType> &
h,
const unsigned int nSlots,
136 using Helper_t = FillParHelper<ActionResultType>;
137 using Action_t = RAction<Helper_t, PrevNodeType,
TTraits::TypeList<BranchTypes...>>;
138 return std::make_unique<Action_t>(Helper_t(
h, nSlots), bl, std::move(prevNode), std::move(customColumns));
142template <
typename... BranchTypes,
typename PrevNodeType>
143std::unique_ptr<RActionBase> BuildAction(
const ColumnNames_t &bl,
const std::shared_ptr<::TH1D> &
h,
144 const unsigned int nSlots, std::shared_ptr<PrevNodeType> prevNode,
147 auto hasAxisLimits = HistoUtils<::TH1D>::HasAxisLimits(*
h);
150 using Helper_t = FillParHelper<::TH1D>;
151 using Action_t = RAction<Helper_t, PrevNodeType,
TTraits::TypeList<BranchTypes...>>;
152 return std::make_unique<Action_t>(Helper_t(
h, nSlots), bl, std::move(prevNode), std::move(customColumns));
154 using Helper_t = FillHelper;
155 using Action_t = RAction<Helper_t, PrevNodeType,
TTraits::TypeList<BranchTypes...>>;
156 return std::make_unique<Action_t>(Helper_t(
h, nSlots), bl, std::move(prevNode), std::move(customColumns));
160template <
typename... BranchTypes,
typename PrevNodeType>
161std::unique_ptr<RActionBase> BuildAction(
const ColumnNames_t &bl,
const std::shared_ptr<TGraph> &
g,
162 const unsigned int nSlots, std::shared_ptr<PrevNodeType> prevNode,
165 using Helper_t = FillTGraphHelper;
166 using Action_t = RAction<Helper_t, PrevNodeType,
TTraits::TypeList<BranchTypes...>>;
167 return std::make_unique<Action_t>(Helper_t(
g, nSlots), bl, std::move(prevNode), std::move(customColumns));
171template <
typename BranchType,
typename PrevNodeType,
typename ActionResultType>
172std::unique_ptr<RActionBase> BuildAction(
const ColumnNames_t &bl,
const std::shared_ptr<ActionResultType> &minV,
173 const unsigned int nSlots, std::shared_ptr<PrevNodeType> prevNode,
176 using Helper_t = MinHelper<ActionResultType>;
177 using Action_t = RAction<Helper_t, PrevNodeType, TTraits::TypeList<BranchType>>;
178 return std::make_unique<Action_t>(Helper_t(minV, nSlots), bl, std::move(prevNode), std::move(customColumns));
182template <
typename BranchType,
typename PrevNodeType,
typename ActionResultType>
183std::unique_ptr<RActionBase> BuildAction(
const ColumnNames_t &bl,
const std::shared_ptr<ActionResultType> &maxV,
184 const unsigned int nSlots, std::shared_ptr<PrevNodeType> prevNode,
187 using Helper_t = MaxHelper<ActionResultType>;
188 using Action_t = RAction<Helper_t, PrevNodeType, TTraits::TypeList<BranchType>>;
189 return std::make_unique<Action_t>(Helper_t(maxV, nSlots), bl, std::move(prevNode), std::move(customColumns));
193template <
typename BranchType,
typename PrevNodeType,
typename ActionResultType>
194std::unique_ptr<RActionBase> BuildAction(
const ColumnNames_t &bl,
const std::shared_ptr<ActionResultType> &sumV,
195 const unsigned int nSlots, std::shared_ptr<PrevNodeType> prevNode,
198 using Helper_t = SumHelper<ActionResultType>;
199 using Action_t = RAction<Helper_t, PrevNodeType, TTraits::TypeList<BranchType>>;
200 return std::make_unique<Action_t>(Helper_t(sumV, nSlots), bl, std::move(prevNode), std::move(customColumns));
204template <
typename BranchType,
typename PrevNodeType>
205std::unique_ptr<RActionBase> BuildAction(
const ColumnNames_t &bl,
const std::shared_ptr<double> &meanV,
206 const unsigned int nSlots, std::shared_ptr<PrevNodeType> prevNode,
209 using Helper_t = MeanHelper;
210 using Action_t = RAction<Helper_t, PrevNodeType, TTraits::TypeList<BranchType>>;
211 return std::make_unique<Action_t>(Helper_t(meanV, nSlots), bl, std::move(prevNode), std::move(customColumns));
215template <
typename BranchType,
typename PrevNodeType>
216std::unique_ptr<RActionBase> BuildAction(
const ColumnNames_t &bl,
const std::shared_ptr<double> &stdDeviationV,
217 const unsigned int nSlots, std::shared_ptr<PrevNodeType> prevNode,
220 using Helper_t = StdDevHelper;
221 using Action_t = RAction<Helper_t, PrevNodeType, TTraits::TypeList<BranchType>>;
222 return std::make_unique<Action_t>(Helper_t(stdDeviationV, nSlots), bl, prevNode, std::move(customColumns));
226template <
typename... BranchTypes,
typename PrevNodeType>
227std::unique_ptr<RActionBase> BuildAction(
const ColumnNames_t &bl,
const std::shared_ptr<RDisplay> &
d,
228 const unsigned int, std::shared_ptr<PrevNodeType> prevNode,
231 using Helper_t = DisplayHelper<PrevNodeType>;
232 using Action_t = RAction<Helper_t, PrevNodeType,
TTraits::TypeList<BranchTypes...>>;
233 return std::make_unique<Action_t>(Helper_t(
d, prevNode), bl, prevNode, std::move(customColumns));
238template <
typename Filter>
241 using FilterRet_t =
typename RDF::CallableTraits<Filter>::ret_type;
242 static_assert(std::is_convertible<FilterRet_t, bool>::value,
243 "filter expression returns a type that is not convertible to bool");
247 const std::map<std::string, std::string> &aliasMap,
const ColumnNames_t &dataSourceColumns);
252 std::string_view expression,
const std::map<std::string, std::string> &aliasMap,
257 const std::shared_ptr<RJittedCustomColumn> &jittedCustomColumn,
261 void *
r,
TTree *
tree,
const unsigned int nSlots,
263 std::shared_ptr<RJittedAction> *jittedActionOnHeap,
unsigned int namespaceID);
272std::shared_ptr<T> *MakeSharedOnHeap(
const std::shared_ptr<T> &shPtr)
274 return new std::shared_ptr<T>(shPtr);
281std::shared_ptr<RNodeBase>
UpcastNode(std::shared_ptr<RNodeBase> ptr);
295 auto getValue = [readers](
unsigned int slot) {
return *readers[slot]; };
298 auto newCol = std::make_shared<NewCol_t>(&lm,
name, std::move(getValue),
ColumnNames_t{}, nSlots, currentCols,
302 currentCols.AddName(
name);
303 currentCols.AddColumn(newCol,
name);
308template <
typename... ColumnTypes, std::size_t...
S>
310AddDSColumns(
RLoopManager &lm,
const std::vector<std::string> &requiredCols,
316 if (std::none_of(mustBeDefined.begin(), mustBeDefined.end(), [](
bool b) { return b; })) {
320 auto newColumns(currentCols);
323 int expander[] = {(mustBeDefined[
S] ? AddDSColumnsHelper<ColumnTypes>(lm, requiredCols[
S], newColumns, ds, nSlots)
334template <
typename F,
typename PrevNode>
340 using ColTypes_t =
typename TTraits::CallableTraits<F>::arg_types;
341 constexpr auto nColumns = ColTypes_t::list_size;
342 RDFInternal::CheckFilter(
f);
347 auto newColumns = ds ? RDFInternal::AddDSColumns(lm, cols, *customColumns, *ds, lm.
GetNSlots(),
348 std::make_index_sequence<nColumns>(), ColTypes_t())
353 delete customColumns;
355 jittedFilter->
SetFilter(std::make_unique<F_t>(std::move(
f), cols, *prevNodeOnHeap, newColumns,
name));
356 delete prevNodeOnHeap;
364 using ColTypes_t =
typename TTraits::CallableTraits<F>::arg_types;
365 constexpr auto nColumns = ColTypes_t::list_size;
368 auto newColumns = ds ? RDFInternal::AddDSColumns(*lm, cols, *customColumns, *ds, lm->
GetNSlots(),
369 std::make_index_sequence<nColumns>(), ColTypes_t())
374 delete customColumns;
377 std::make_unique<NewCol_t>(lm,
name, std::move(
f), cols, lm->
GetNSlots(), newColumns));
381template <
typename ActionTag,
typename... BranchTypes,
typename PrevNodeType,
typename ActionResultType>
382void CallBuildAction(std::shared_ptr<PrevNodeType> *prevNodeOnHeap,
const ColumnNames_t &bl,
const unsigned int nSlots,
383 const std::shared_ptr<ActionResultType> *rOnHeap,
384 std::shared_ptr<RJittedAction> *jittedActionOnHeap,
388 auto &prevNodePtr = *prevNodeOnHeap;
389 auto &loopManager = *prevNodePtr->GetLoopManagerUnchecked();
390 using ColTypes_t =
TypeList<BranchTypes...>;
391 constexpr auto nColumns = ColTypes_t::list_size;
392 auto ds = loopManager.GetDataSource();
393 auto newColumns = ds ? RDFInternal::AddDSColumns(loopManager, bl, *customColumns, *ds, loopManager.GetNSlots(),
394 std::make_index_sequence<nColumns>(), ColTypes_t())
398 BuildAction<BranchTypes...>(bl, *rOnHeap, nSlots, std::move(prevNodePtr), ActionTag{}, std::move(newColumns));
399 (*jittedActionOnHeap)->SetAction(std::move(actionPtr));
403 delete customColumns;
406 delete prevNodeOnHeap;
407 delete jittedActionOnHeap;
411template <typename T, bool Container = TTraits::IsContainer<T>::value && !std::is_same<T, std::string>::value>
412struct TMinReturnType {
417struct TMinReturnType<RInferredType, false> {
422struct TMinReturnType<
T, true> {
423 using type = TTraits::TakeFirstParameter_t<T>;
427template <
typename R,
typename F,
typename... Args>
430 return [
f](
unsigned int, Args...
a) ->
R {
return f(
a...); };
433template <
typename BranchType,
typename... Rest>
435 static constexpr bool value = TNeedJitting<Rest...>::value;
438template <
typename... Rest>
439struct TNeedJitting<RInferredType, Rest...> {
440 static constexpr bool value =
true;
444struct TNeedJitting<
T> {
445 static constexpr bool value =
false;
449struct TNeedJitting<RInferredType> {
450 static constexpr bool value =
true;
460 typename mergeArgsNoDecay_t =
typename CallableTraits<Merge>::arg_types_nodecay,
461 typename mergeArgs_t =
typename CallableTraits<Merge>::arg_types,
462 typename mergeRet_t =
typename CallableTraits<Merge>::ret_type>
465 constexpr bool isAggregatorOk =
466 (std::is_same<R, decayedU>::value) || (std::is_same<R, void>::value && std::is_lvalue_reference<U>::value);
467 static_assert(isAggregatorOk,
"aggregator function must have signature `U(U,T)` or `void(U&,T)`");
468 constexpr bool isMergeOk =
469 (std::is_same<TypeList<decayedU, decayedU>, mergeArgs_t>::value && std::is_same<decayedU, mergeRet_t>::value) ||
470 (std::is_same<
TypeList<std::vector<decayedU> &>, mergeArgsNoDecay_t>::value &&
471 std::is_same<void, mergeRet_t>::value);
472 static_assert(isMergeOk,
"merge function must have signature `U(U,U)` or `void(std::vector<U>&)`");
477template <
typename R,
typename T>
478void CheckAggregate(
T)
480 static_assert(
sizeof(
T) == 0,
"aggregator function must take exactly two arguments");
497std::vector<std::string>
GetFilterNames(
const std::shared_ptr<RLoopManager> &loopManager);
500template <
typename NodeType>
501std::vector<std::string>
GetFilterNames(
const std::shared_ptr<NodeType> &node)
503 std::vector<std::string> filterNames;
504 node->AddFilterName(filterNames);
513using IsTrueForAllImpl_t =
typename std::is_same<TBoolPack<bs...,
true>, TBoolPack<
true, bs...>>;
515template <
bool... Conditions>
517 static constexpr bool value = IsTrueForAllImpl_t<Conditions...>::value;
524struct IsList_t : std::false_type {};
527struct IsList_t<std::list<T>> : std::true_type {};
530struct IsDeque_t : std::false_type {};
533struct IsDeque_t<std::deque<T>> : std::true_type {};
547using MaxReturnType_t = MinReturnType_t<T>;
550using SumReturnType_t = MinReturnType_t<T>;
#define R(a, b, c, d, e, f, g, h, i)
R__EXTERN Int_t gErrorIgnoreLevel
typedef void((*Func_t)())
A wrapper around a concrete RCustomColumn, which forwards all calls to it RJittedCustomColumn is a pl...
void SetCustomColumn(std::unique_ptr< RCustomColumnBase > c)
A wrapper around a concrete RFilter, which forwards all calls to it RJittedFilter is the type of the ...
void SetFilter(std::unique_ptr< RFilterBase > f)
The head node of a RDF computation graph.
void RegisterCustomColumn(RCustomColumnBase *column)
RDataSource * GetDataSource() const
unsigned int GetNSlots() const
virtual RLoopManager * GetLoopManagerUnchecked()
Encapsulates the columns defined by the user.
ColumnNames_t GetNames() const
Returns the list of the names of the defined columns.
RDataSource defines an API that RDataFrame can use to read arbitrary data formats.
std::vector< T ** > GetColumnReaders(std::string_view columnName)
Called at most once per column by RDF.
The public interface to the RDataFrame federation of classes.
Smart pointer for the return type of actions.
A TTree represents a columnar dataset.
basic_string_view< char > string_view
const ColumnNames_t SelectColumns(unsigned int nRequiredNames, const ColumnNames_t &names, const ColumnNames_t &defaultNames)
Choose between local column names or default column names, throw in case of errors.
HeadNode_t CreateSnaphotRDF(const ColumnNames_t &validCols, std::string_view treeName, std::string_view fileName, bool isLazy, RLoopManager &loopManager, std::unique_ptr< RDFInternal::RActionBase > actionPtr)
std::shared_ptr< RNodeBase > UpcastNode(std::shared_ptr< RNodeBase > ptr)
std::vector< std::string > GetFilterNames(const std::shared_ptr< RLoopManager > &loopManager)
ColumnNames_t ConvertRegexToColumns(const RDFInternal::RBookedCustomColumns &customColumns, TTree *tree, ROOT::RDF::RDataSource *dataSource, std::string_view columnNameRegexp, std::string_view callerName)
std::string PrettyPrintAddr(const void *const addr)
ColumnNames_t GetTopLevelBranchNames(TTree &t)
Get all the top-level branches names, including the ones of the friend trees.
void CheckTypesAndPars(unsigned int nTemplateParams, unsigned int nColumnNames)
std::string DemangleTypeIdName(const std::type_info &typeInfo)
bool AtLeastOneEmptyString(const std::vector< std::string_view > strings)
ColumnNames_t FindUnknownColumns(const ColumnNames_t &requiredCols, const ColumnNames_t &datasetColumns, const ColumnNames_t &definedCols, const ColumnNames_t &dataSourceColumns)
std::string JitBuildAction(const ColumnNames_t &bl, void *prevNode, const std::type_info &art, const std::type_info &at, void *rOnHeap, TTree *tree, const unsigned int nSlots, const RDFInternal::RBookedCustomColumns &customCols, RDataSource *ds, std::shared_ptr< RJittedAction > *jittedActionOnHeap, unsigned int namespaceID)
bool IsInternalColumn(std::string_view colName)
ColumnNames_t GetValidatedColumnNames(RLoopManager &lm, const unsigned int nColumns, const ColumnNames_t &columns, const ColumnNames_t &validCustomColumns, RDataSource *ds)
Given the desired number of columns and the user-provided list of columns:
std::vector< bool > FindUndefinedDSColumns(const ColumnNames_t &requestedCols, const ColumnNames_t &definedCols)
Return a bitset each element of which indicates whether the corresponding element in selectedColumns ...
void BookDefineJit(std::string_view name, std::string_view expression, RLoopManager &lm, RDataSource *ds, const std::shared_ptr< RJittedCustomColumn > &jittedCustomColumn, const RDFInternal::RBookedCustomColumns &customCols, const ColumnNames_t &branches)
void BookFilterJit(RJittedFilter *jittedFilter, void *prevNodeOnHeap, std::string_view name, std::string_view expression, const std::map< std::string, std::string > &aliasMap, const ColumnNames_t &branches, const RDFInternal::RBookedCustomColumns &customCols, TTree *tree, RDataSource *ds, unsigned int namespaceID)
void CheckCustomColumn(std::string_view definedCol, TTree *treePtr, const ColumnNames_t &customCols, const std::map< std::string, std::string > &aliasMap, const ColumnNames_t &dataSourceColumns)
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
ROOT type_traits extensions.
T Sum(const RVec< T > &v)
Sum elements of an RVec.
RVec< T > Filter(const RVec< T > &v, F &&f)
Create a new collection with the elements passing the filter expressed by the predicate.
Namespace for new ROOT classes and functions.
ROOT::Detail::RDF::ColumnNames_t ColumnNames_t
RooArgSet S(const RooAbsArg &v1)
Short_t Max(Short_t a, Short_t b)
Double_t Mean(Long64_t n, const T *a, const Double_t *w=0)
Return the weighted mean of an array a with length n.
Short_t Min(Short_t a, Short_t b)
Double_t StdDev(Long64_t n, const T *a, const Double_t *w=0)
Lightweight storage for a collection of types.