11#ifndef ROOT_RDF_TINTERFACE_UTILS
12#define ROOT_RDF_TINTERFACE_UTILS
31#include <RConfigure.h>
53template <
typename Proxied>
93struct HistoNSparseD{};
97struct GraphAsymmErrors{};
112template <
typename T,
bool ISV6HISTO = std::is_base_of<TH1, std::decay_t<T>>::value>
116 auto xaxis =
h.GetXaxis();
117 return !(
xaxis->GetXmin() == 0. &&
xaxis->GetXmax() == 0.);
128std::unique_ptr<RActionBase>
129BuildAction(
const ColumnNames_t &
bl,
const std::shared_ptr<ActionResultType> &
h,
const unsigned int nSlots,
138template <
typename...
ColTypes,
typename PrevNodeType>
139std::unique_ptr<RActionBase>
140BuildAction(
const ColumnNames_t &
bl,
const std::shared_ptr<::TH1D> &
h,
const unsigned int nSlots,
141 std::shared_ptr<PrevNodeType> prevNode, ActionTags::Histo1D,
const RColumnRegister &
colRegister)
158std::unique_ptr<RActionBase>
159BuildAction(
const ColumnNames_t &
bl,
const std::shared_ptr<ActionResultType> &
h,
const unsigned int nSlots,
160 std::shared_ptr<PrevNodeType> prevNode, ActionTags::Histo3D,
const RColumnRegister &
colRegister)
169 if constexpr (
sizeof...(ColTypes) > 3) {
180std::unique_ptr<RActionBase>
182 const unsigned int nSlots, std::shared_ptr<PrevNodeType> prevNode, ActionTags::Hist,
192std::unique_ptr<RActionBase>
194 const unsigned int nSlots, std::shared_ptr<PrevNodeType> prevNode, ActionTags::HistWithWeight,
204std::unique_ptr<RActionBase>
206 const unsigned int, std::shared_ptr<PrevNodeType> prevNode, ActionTags::Hist,
216std::unique_ptr<RActionBase>
218 const unsigned int, std::shared_ptr<PrevNodeType> prevNode, ActionTags::HistWithWeight,
227template <
typename...
ColTypes,
typename PrevNodeType>
228std::unique_ptr<RActionBase>
229BuildAction(
const ColumnNames_t &
bl,
const std::shared_ptr<TGraph> &
g,
const unsigned int nSlots,
230 std::shared_ptr<PrevNodeType> prevNode, ActionTags::Graph,
const RColumnRegister &
colRegister)
237template <
typename...
ColTypes,
typename PrevNodeType>
238std::unique_ptr<RActionBase>
239BuildAction(
const ColumnNames_t &
bl,
const std::shared_ptr<TGraphAsymmErrors> &
g,
const unsigned int nSlots,
240 std::shared_ptr<PrevNodeType> prevNode, ActionTags::GraphAsymmErrors,
const RColumnRegister &
colRegister)
248template <
typename ColType,
typename PrevNodeType,
typename ActionResultType>
249std::unique_ptr<RActionBase>
251 std::shared_ptr<PrevNodeType> prevNode, ActionTags::Min,
const RColumnRegister &
colRegister)
259template <
typename ColType,
typename PrevNodeType,
typename ActionResultType>
260std::unique_ptr<RActionBase>
262 std::shared_ptr<PrevNodeType> prevNode, ActionTags::Max,
const RColumnRegister &
colRegister)
270template <
typename ColType,
typename PrevNodeType,
typename ActionResultType>
271std::unique_ptr<RActionBase>
273 std::shared_ptr<PrevNodeType> prevNode, ActionTags::Sum,
const RColumnRegister &
colRegister)
281template <
typename ColType,
typename PrevNodeType>
282std::unique_ptr<RActionBase>
284 std::shared_ptr<PrevNodeType> prevNode, ActionTags::Mean,
const RColumnRegister &
colRegister)
292template <
typename ColType,
typename PrevNodeType>
293std::unique_ptr<RActionBase>
295 std::shared_ptr<PrevNodeType> prevNode, ActionTags::StdDev,
const RColumnRegister &
colRegister)
305template <
typename...
ColTypes,
typename PrevNodeType>
306std::unique_ptr<RActionBase>
307BuildAction(
const ColumnNames_t &
bl,
const std::shared_ptr<displayHelperArgs_t> &
helperArgs,
const unsigned int,
308 std::shared_ptr<PrevNodeType> prevNode, ActionTags::Display,
const RColumnRegister &
colRegister)
317 std::string fFileName;
318 std::string fDirName;
319 std::string fTreeName;
325 bool fIncludeVariations;
328template <
typename PrevNodeType>
329std::unique_ptr<RActionBase>
331 const unsigned int nSlots, std::shared_ptr<PrevNodeType> prevNode,
const RColumnRegister &
colRegister,
332 const std::vector<const std::type_info *> &
colTypeIDs)
344 for (
auto i = 0
u; i <
sz; ++i)
350 using Helper_t = UntypedSnapshotRNTupleHelper;
360 using Helper_t = SnapshotHelperWithVariations;
366 using Helper_t = UntypedSnapshotTTreeHelper;
374 throw std::invalid_argument(
"Multi-threaded snapshot with variations is not supported yet.");
377 using Helper_t = UntypedSnapshotTTreeHelperMT;
390std::unique_ptr<RActionBase>
391BuildAction(
const ColumnNames_t &
bl,
const std::shared_ptr<Helper_t> &
h,
const unsigned int ,
392 std::shared_ptr<PrevNodeType> prevNode, ActionTags::Book,
const RColumnRegister &
colRegister)
400template <
typename Filter>
403 using FilterRet_t =
typename RDF::CallableTraits<Filter>::ret_type;
404 static_assert(std::is_convertible<FilterRet_t, bool>::value,
405 "filter expression returns a type that is not convertible to bool");
423std::shared_ptr<RJittedFilter>
BookFilterJit(std::shared_ptr<RNodeBase> prevNode, std::string_view
name,
424 std::string_view expression,
const RColumnRegister &
colRegister,
433std::shared_ptr<RJittedVariation>
438std::string
JitBuildAction(
const ColumnNames_t &
bl,
const std::type_info &
art,
const std::type_info &at,
TTree *tree,
451 return new std::weak_ptr<T>(
shPtr);
458 return new std::shared_ptr<T>(
shPtr);
465std::shared_ptr<RNodeBase>
UpcastNode(std::shared_ptr<RNodeBase> ptr);
481 if (
lm.HasDataSourceColumnReaders(
colName,
typeid(T)))
485 lm.GetSuppressErrorsForMissingBranches().find(
colName) ==
lm.GetSuppressErrorsForMissingBranches().
end())
489 std::vector<std::unique_ptr<RColumnReaderBase>>
colReaders;
537 using PrevNode_t =
typename decltype(prevNode)::element_type;
539 using ColTypes_t =
typename TTraits::CallableTraits<Callable_t>::arg_types;
540 constexpr auto nColumns = ColTypes_t::list_size;
543 auto ds =
lm.GetDataSource();
545 if (
ds !=
nullptr && !
cols.empty())
569 return std::unique_ptr<RDefineBase>(
576template <
typename RDefineTypeTag,
typename F>
588 using ColTypes_t =
typename TTraits::CallableTraits<Callable_t>::arg_types;
590 auto ds =
lm.GetDataSource();
591 if (
ds !=
nullptr && !
cols.empty())
598 std::unique_ptr<RDefineBase>
newCol{
603template <
bool IsSingleColumn,
typename F>
616 using ColTypes_t =
typename TTraits::CallableTraits<Callable_t>::arg_types;
618 auto ds =
lm.GetDataSource();
633 std::shared_ptr<HelperArgType> *
helperArg)
noexcept
642 constexpr auto nColumns = ColTypes_t::list_size;
643 auto ds =
lm.GetDataSource();
644 if (
ds !=
nullptr && !
cols.empty())
665 using type = TTraits::TakeFirstParameter_t<T>;
669template <
typename R,
typename F,
typename... Args>
672 return [
f](
unsigned int, Args...
a)
mutable ->
R {
return f(
a...); };
680template <
typename...
Rest>
682 static constexpr bool value =
true;
687 static constexpr bool value =
false;
692 static constexpr bool value =
true;
695template <
typename ...ColTypes>
702 static constexpr bool value =
false;
709template <
typename R,
typename Merge,
typename U,
typename T,
typename decayedU = std::decay_t<U>,
710 typename mergeArgsNoDecay_t =
typename CallableTraits<Merge>::arg_types_nodecay,
711 typename mergeArgs_t =
typename CallableTraits<Merge>::arg_types,
712 typename mergeRet_t =
typename CallableTraits<Merge>::ret_type>
716 (std::is_same<R, decayedU>::value) || (std::is_same<R, void>::value && std::is_lvalue_reference<U>::value);
717 static_assert(
isAggregatorOk,
"aggregator function must have signature `U(U,T)` or `void(U&,T)`");
719 (std::is_same<TypeList<decayedU, decayedU>,
mergeArgs_t>
::value && std::is_same<decayedU, mergeRet_t>::value) ||
721 std::is_same<void, mergeRet_t>::value);
722 static_assert(
isMergeOk,
"merge function must have signature `U(U,U)` or `void(std::vector<U>&)`");
727template <
typename R,
typename T>
730 static_assert(
sizeof(T) == 0,
"aggregator function must take exactly two arguments");
748template <
typename NodeType>
749std::vector<std::string>
GetFilterNames(
const std::shared_ptr<NodeType> &node)
757 std::string fTreeName;
758 std::string fDirName;
779struct IsList_t : std::false_type {};
782struct IsList_t<std::list<T>> : std::true_type {};
788struct IsDeque_t<std::deque<T>> : std::true_type {};
800template <
typename Elem>
808std::pair<std::vector<std::string>, std::vector<std::string>>
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Int_t gErrorIgnoreLevel
errors with level below this value will be ignored. Default is kUnset.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
A wrapper around a concrete RDefine, which forwards all calls to it RJittedDefine is a placeholder th...
A wrapper around a concrete RFilter, which forwards all calls to it RJittedFilter is the type of the ...
The head node of a RDF computation graph.
A histogram data structure to bin data along multiple dimensions.
A histogram for aggregation of data along multiple dimensions.
A binder for user-defined columns, variations and aliases.
RDataSource defines an API that RDataFrame can use to read arbitrary data formats.
The public interface to the RDataFrame federation of classes.
const_iterator end() const
A "std::vector"-like collection of values implementing handy operation to analyse them.
A TTree represents a columnar dataset.
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.
void CheckForNoVariations(const std::string &where, std::string_view definedColView, const RColumnRegister &colRegister)
Throw if the column has systematic variations attached.
ParsedTreePath ParseTreePath(std::string_view fullTreeName)
std::shared_ptr< RJittedDefine > BookDefinePerSampleJit(std::string_view name, std::string_view expression, RLoopManager &lm, const RColumnRegister &colRegister)
Book the jitting of a DefinePerSample call.
void CheckValidCppVarName(std::string_view var, const std::string &where)
void RemoveDuplicates(ColumnNames_t &columnNames)
ColumnNames_t GetValidatedColumnNames(RLoopManager &lm, const unsigned int nColumns, const ColumnNames_t &columns, const RColumnRegister &colRegister, RDataSource *ds)
Given the desired number of columns and the user-provided list of columns:
std::shared_ptr< RNodeBase > UpcastNode(std::shared_ptr< RNodeBase > ptr)
void CheckSnapshotOptionsFormatCompatibility(const ROOT::RDF::RSnapshotOptions &opts)
void CheckForDefinition(const std::string &where, std::string_view definedColView, const RColumnRegister &colRegister, const ColumnNames_t &dataSourceColumns)
Throw if column definedColView is not already there.
std::vector< std::string > GetFilterNames(const std::shared_ptr< RLoopManager > &loopManager)
std::string PrettyPrintAddr(const void *const addr)
std::shared_ptr< RDFDetail::RJittedFilter > BookFilterJit(std::shared_ptr< RDFDetail::RNodeBase > prevNode, std::string_view name, std::string_view expression, const RColumnRegister &colRegister, TTree *tree, RDataSource *ds)
Book the jitting of a Filter call.
std::string JitBuildAction(const ColumnNames_t &cols, const std::type_info &helperArgType, const std::type_info &at, TTree *tree, const unsigned int nSlots, const RColumnRegister &colRegister, RDataSource *ds, const bool vector2RVec)
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)
std::unique_ptr< ROOT::Detail::RDF::RColumnReaderBase > CreateColumnReader(ROOT::RDF::RDataSource &ds, unsigned int slot, std::string_view col, const std::type_info &tid, TTreeReader *treeReader)
std::pair< std::vector< std::string >, std::vector< std::string > > AddSizeBranches(ROOT::RDF::RDataSource *ds, std::vector< std::string > &&colsWithoutAliases, std::vector< std::string > &&colsWithAliases)
Return copies of colsWithoutAliases and colsWithAliases with size branches for variable-sized array b...
void RemoveRNTupleSubFields(ColumnNames_t &columnNames)
ColumnNames_t FilterArraySizeColNames(const ColumnNames_t &columnNames, const std::string &action)
Take a list of column names, return that list with entries starting by '#' filtered out.
std::shared_ptr< RJittedVariation > BookVariationJit(const std::vector< std::string > &colNames, std::string_view variationName, const std::vector< std::string > &variationTags, std::string_view expression, RLoopManager &lm, RDataSource *ds, const RColumnRegister &colRegister, bool isSingleColumn)
Book the jitting of a Vary call.
std::vector< std::string > GetValidatedArgTypes(const ColumnNames_t &colNames, const RColumnRegister &colRegister, TTree *tree, RDataSource *ds, const std::string &context, bool vector2RVec)
void CheckForDuplicateSnapshotColumns(const ColumnNames_t &cols)
ColumnNames_t ConvertRegexToColumns(const ColumnNames_t &colNames, std::string_view columnNameRegexp, std::string_view callerName)
ColumnNames_t FindUnknownColumns(const ColumnNames_t &requiredCols, const RColumnRegister &definedCols, const ColumnNames_t &dataSourceColumns)
unsigned int & NThreadPerTH3()
Obtain or set the number of threads that will share a clone of a thread-safe 3D histogram.
void CheckForRedefinition(const std::string &where, std::string_view definedColView, const RColumnRegister &colRegister, const ColumnNames_t &dataSourceColumns)
Throw if column definedColView is already there.
std::shared_ptr< RJittedDefine > BookDefineJit(std::string_view name, std::string_view expression, RLoopManager &lm, RDataSource *ds, const RColumnRegister &colRegister)
Book the jitting of a Define call.
ROOT type_traits extensions.
Bool_t IsImplicitMTEnabled()
Returns true if the implicit multi-threading in ROOT is enabled.
A collection of options to steer the creation of the dataset on disk through Snapshot().
Lightweight storage for a collection of types.