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;
47 const std::vector<const std::type_info *> &colTypeIDs, std::shared_ptr<PrevNode> pd,
49 :
RActionBase(pd->GetLoopManagerUnchecked(), columns, colRegister, pd->GetVariations()),
50 fHelper(std::move(
h)),
54 fColTypeIDs(colTypeIDs)
56 fLoopManager->Register(
this);
72 return fHelper.GetMergeableValue();
80 RActionBase::GetColumnNames(), fColTypeIDs);
81 fHelper.InitTask(
r, slot);
86 assert(slot < fValues.size());
87 assert(readerIdx < fValues[slot].
size());
88 if (
auto *val = fValues[slot][readerIdx]->
template TryGet<void>(entry))
91 throw std::out_of_range{
"RDataFrame: Action (" + fHelper.GetActionName() +
92 ") could not retrieve value for column '" + fColumnNames[readerIdx] +
"' for entry " +
93 std::to_string(entry) +
94 ". You can use the DefaultValueFor operation to provide a default value, or "
95 "FilterAvailable/FilterMissing to discard/keep entries with missing values instead."};
100 auto &untypedValues = fValueAddresses[slot];
101 auto nReaders = fValues[slot].size();
102 untypedValues.resize(nReaders);
103 for (
decltype(nReaders) readerIdx{}; readerIdx < nReaders; readerIdx++)
104 untypedValues[readerIdx] = GetValue(slot, readerIdx, entry);
106 fHelper.Exec(slot, untypedValues);
112 if (fPrevNodes.front()->CheckFilters(slot, entry))
113 CallExec(slot, entry);
118 for (
auto const &node : fPrevNodes)
119 node->IncrChildrenCount();
125 fValues[slot].clear();
126 fHelper.CallFinalizeTask(slot);
137 std::shared_ptr<GraphDrawing::GraphNode>
138 GetGraph(std::unordered_map<
void *, std::shared_ptr<GraphDrawing::GraphNode>> &visitedMap)
final
141 const auto nodeType = HasRun() ? GraphDrawing::ENodeType::kUsedAction : GraphDrawing::ENodeType::kAction;
142 auto thisNode = std::make_shared<GraphDrawing::GraphNode>(fHelper.GetActionName(), visitedMap.size(), nodeType);
143 visitedMap[(
void *)
this] = thisNode;
145 for (
auto const &node : fPrevNodes) {
146 auto prevNode = node->GetGraph(visitedMap);
147 const auto &prevColumns = prevNode->GetDefinedColumns();
148 auto upmostNode = AddDefinesToGraph(thisNode, GetColRegister(), prevColumns, visitedMap);
150 thisNode->AddDefinedColumns(GetColRegister().GenerateColumnNames());
151 upmostNode->SetPrevNode(prevNode);
157 void *
PartialUpdate(
unsigned int slot)
final {
return fHelper.CallPartialUpdate(slot); }
159 [[maybe_unused]] std::unique_ptr<RActionBase>
MakeVariedAction(std::vector<void *> && ) final
161 throw std::runtime_error(
"not implemented.");
172 return std::make_unique<RActionCustomLoader>(fHelper.CallMakeNew(newResult), GetColumnNames(), fColTypeIDs,
173 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::vector< void * > > fValueAddresses
Value addresses of the current entry per slot, reused for every entry.
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....