4#ifndef ROOT_RActionCustomLoader
5#define ROOT_RActionCustomLoader
21template <
typename Helper,
typename PrevNode>
29 using PrevNodeCommon_t = std::conditional_t<std::is_same_v<PrevNode, ROOT::Detail::RDF::RJittedFilter>,
32 std::vector<std::shared_ptr<PrevNodeCommon_t>>
fPrevNodes;
35 std::vector<std::vector<RColumnReaderBase *>>
fValues;
44 const std::vector<const std::type_info *> &colTypeIDs, std::shared_ptr<PrevNode> pd,
46 :
RActionBase(pd->GetLoopManagerUnchecked(), columns, colRegister, pd->GetVariations()),
47 fHelper(std::move(
h)),
50 fColTypeIDs(colTypeIDs)
52 fLoopManager->Register(
this);
68 return fHelper.GetMergeableValue();
76 RActionBase::GetColumnNames(), fColTypeIDs);
77 fHelper.InitTask(
r, slot);
82 assert(slot < fValues.size());
83 assert(readerIdx < fValues[slot].
size());
84 if (
auto *val = fValues[slot][readerIdx]->
template TryGet<void>(entry))
87 throw std::out_of_range{
"RDataFrame: Action (" + fHelper.GetActionName() +
88 ") could not retrieve value for column '" + fColumnNames[readerIdx] +
"' for entry " +
89 std::to_string(entry) +
90 ". You can use the DefaultValueFor operation to provide a default value, or "
91 "FilterAvailable/FilterMissing to discard/keep entries with missing values instead."};
96 std::vector<void *> untypedValues;
97 auto nReaders = fValues[slot].size();
98 untypedValues.reserve(nReaders);
99 for (
decltype(nReaders) readerIdx{}; readerIdx < nReaders; readerIdx++)
100 untypedValues.push_back(GetValue(slot, readerIdx, entry));
102 fHelper.Exec(slot, untypedValues);
108 if (fPrevNodes.front()->CheckFilters(slot, entry))
109 CallExec(slot, entry);
114 for (
auto const &node : fPrevNodes)
115 node->IncrChildrenCount();
121 fValues[slot].clear();
122 fHelper.CallFinalizeTask(slot);
133 std::shared_ptr<GraphDrawing::GraphNode>
134 GetGraph(std::unordered_map<
void *, std::shared_ptr<GraphDrawing::GraphNode>> &visitedMap)
final
137 const auto nodeType = HasRun() ? GraphDrawing::ENodeType::kUsedAction : GraphDrawing::ENodeType::kAction;
138 auto thisNode = std::make_shared<GraphDrawing::GraphNode>(fHelper.GetActionName(), visitedMap.size(), nodeType);
139 visitedMap[(
void *)
this] = thisNode;
141 for (
auto const &node : fPrevNodes) {
142 auto prevNode = node->GetGraph(visitedMap);
143 const auto &prevColumns = prevNode->GetDefinedColumns();
144 auto upmostNode = AddDefinesToGraph(thisNode, GetColRegister(), prevColumns, visitedMap);
146 thisNode->AddDefinedColumns(GetColRegister().GenerateColumnNames());
147 upmostNode->SetPrevNode(prevNode);
153 void *
PartialUpdate(
unsigned int slot)
final {
return fHelper.CallPartialUpdate(slot); }
155 [[maybe_unused]] std::unique_ptr<RActionBase>
MakeVariedAction(std::vector<void *> && ) final
157 throw std::runtime_error(
"not implemented.");
168 return std::make_unique<RActionCustomLoader>(fHelper.CallMakeNew(newResult), GetColumnNames(), fColTypeIDs,
169 std::static_pointer_cast<PrevNode>(fPrevNodes.front()),
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
long long Long64_t
Portable signed long integer 8 bytes.
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 r
RActionCustomLoader(Helper &&h, const std::vector< std::string > &columns, const std::vector< const std::type_info * > &colTypeIDs, std::shared_ptr< PrevNode > pd, const RColumnRegister &colRegister)
std::conditional_t< std::is_same_v< PrevNode, ROOT::Detail::RDF::RJittedFilter >, ROOT::Detail::RDF::RFilterBase, PrevNode > PrevNodeCommon_t
void Finalize() final
Clean-up and finalize the action result (e.g.
std::vector< std::vector< RColumnReaderBase * > > fValues
Column readers per slot and per input column.
std::vector< std::shared_ptr< PrevNodeCommon_t > > fPrevNodes
Previous nodes in the computation graph. First element is nominal, others are varied.
void TriggerChildrenCount() final
void * PartialUpdate(unsigned int slot) final
Forwards to the action helpers; will throw since PartialUpdate not supported for most snapshot helper...
void * GetValue(unsigned int slot, std::size_t readerIdx, Long64_t entry)
std::unique_ptr< RActionBase > MakeVariedAction(std::vector< void * > &&) final
~RActionCustomLoader() final
RActionCustomLoader & operator=(const RActionCustomLoader &)=delete
RActionCustomLoader(RActionCustomLoader &&)=delete
void InitSlot(TTreeReader *r, unsigned int slot) final
void CallExec(unsigned int slot, Long64_t entry)
std::shared_ptr< GraphDrawing::GraphNode > GetGraph(std::unordered_map< void *, std::shared_ptr< GraphDrawing::GraphNode > > &visitedMap) final
ROOT::RDF::SampleCallback_t GetSampleCallback() final
void FinalizeSlot(unsigned int slot) final
Clean-up operations to be performed at the end of a task.
std::unique_ptr< RActionBase > CloneAction(void *newResult) final
Returns a new action with a cloned helper.
std::unique_ptr< ROOT::Detail::RDF::RMergeableValueBase > GetMergeableValue() const final
Retrieve a wrapper to the result of the action that knows how to merge with others of the same type.
void Run(unsigned int slot, Long64_t entry) final
RActionCustomLoader(const RActionCustomLoader &)=delete
std::vector< const std::type_info * > fColTypeIDs
RActionCustomLoader & operator=(RActionCustomLoader &&)=delete
A binder for user-defined columns, variations and aliases.
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
std::vector< RDFDetail::RColumnReaderBase * > GetUntypedColumnReaders(unsigned int slot, TTreeReader *treeReader, ROOT::Internal::RDF::RColumnRegister &colRegister, ROOT::Detail::RDF::RLoopManager &lm, const std::vector< std::string > &colNames, const std::vector< const std::type_info * > &colTypeIDs, const std::string &variationName="nominal")
std::function< void(unsigned int, const ROOT::RDF::RSampleInfo &)> SampleCallback_t
The type of a data-block callback, registered with an RDataFrame computation graph via e....