11#ifndef ROOT_RVARIEDACTION
12#define ROOT_RVARIEDACTION
39template <
typename Helper,
typename PrevNode,
typename ColumnTypes_t>
41 using TypeInd_t = std::make_index_sequence<ColumnTypes_t::list_size>;
51 std::vector<std::vector<std::array<RColumnReaderBase *, ColumnTypes_t::list_size>>>
fInputValues;
54 std::array<bool, ColumnTypes_t::list_size>
fIsDefine;
61 std::vector<std::shared_ptr<PrevNodeType>>
MakePrevFilters(std::shared_ptr<PrevNode> nominal)
const
64 std::vector<std::shared_ptr<PrevNodeType>> prevFilters;
65 prevFilters.reserve(variations.size());
68 prevFilters.resize(variations.size(), nominal);
71 const auto &prevVariations = nominal->GetVariations();
72 for (
const auto &variation : variations) {
74 prevFilters.emplace_back(std::static_pointer_cast<PrevNodeType>(nominal->GetVariedFilter(variation)));
76 prevFilters.emplace_back(nominal);
92 for (
auto i = 0u;
i < columnNames.size(); ++
i) {
93 auto *define = colRegister.GetDefine(columnNames[
i]);
102 const std::vector<std::shared_ptr<PrevNodeType>> &prevNodes,
const RColumnRegister &colRegister)
129 std::for_each(
fHelpers.begin(),
fHelpers.end(), [](Helper &
h) { h.Initialize(); });
140 std::for_each(
fHelpers.begin(),
fHelpers.end(), [=](Helper &
h) { h.InitTask(r, slot); });
143 template <
typename... ColTypes, std::size_t... S>
153 for (
auto varIdx = 0u; varIdx <
GetVariations().size(); ++varIdx) {
154 if (
fPrevNodes[varIdx]->CheckFilters(slot, entry))
168 std::for_each(
fHelpers.begin(),
fHelpers.end(), [=](Helper &
h) { h.CallFinalizeTask(slot); });
175 std::for_each(
fHelpers.begin(),
fHelpers.end(), [](Helper &
h) { h.Finalize(); });
186 std::vector<ROOT::RDF::SampleCallback_t> callbacks;
188 callbacks.push_back(
h.GetSampleCallback());
190 auto callEachCallback = [cs = std::move(callbacks)](
unsigned int slot,
const RSampleInfo &info) {
195 return callEachCallback;
201 std::shared_ptr<RDFGraphDrawing::GraphNode>
202 GetGraph(std::unordered_map<
void *, std::shared_ptr<RDFGraphDrawing::GraphNode>> &visitedMap)
final
204 auto prevNode =
fPrevNodes[0]->GetGraph(visitedMap);
205 const auto &prevColumns = prevNode->GetDefinedColumns();
208 const auto nodeType =
HasRun() ? RDFGraphDrawing::ENodeType::kUsedAction : RDFGraphDrawing::ENodeType::kAction;
209 auto thisNode = std::make_shared<RDFGraphDrawing::GraphNode>(
"Varied " +
fHelpers[0].GetActionName(),
210 visitedMap.size(), nodeType);
211 visitedMap[(
void *)
this] = thisNode;
213 auto upmostNode = AddDefinesToGraph(thisNode,
GetColRegister(), prevColumns, visitedMap);
215 thisNode->AddDefinedColumns(
GetColRegister().GenerateColumnNames());
216 upmostNode->SetPrevNode(prevNode);
228 std::vector<std::unique_ptr<RDFDetail::RMergeableValueBase>> values;
231 values.emplace_back(
h.GetMergeableValue());
233 return std::make_unique<RDFDetail::RMergeableVariationsBase>(std::move(keys), std::move(values));
238 throw std::logic_error(
"Cannot produce a varied action from a varied action.");
241 std::unique_ptr<RActionBase>
CloneAction(
void *typeErasedResults)
final
243 const auto &vectorOfTypeErasedResults = *
reinterpret_cast<const std::vector<void *> *
>(typeErasedResults);
244 assert(vectorOfTypeErasedResults.size() ==
fHelpers.size() &&
245 "The number of results and the number of helpers are not the same!");
247 std::vector<Helper> clonedHelpers;
248 clonedHelpers.reserve(
fHelpers.size());
249 for (std::size_t
i = 0;
i <
fHelpers.size();
i++) {
250 clonedHelpers.emplace_back(
fHelpers[
i].CallMakeNew(vectorOfTypeErasedResults[
i]));
253 return std::unique_ptr<RVariedAction>(
260 template <
typename H = Helper>
261 auto PartialUpdateImpl(
unsigned int slot) ->
decltype(std::declval<H>().PartialUpdate(slot), (
void *)(
nullptr))
263 return &
fHelpers[0].PartialUpdate(slot);
267 void *
PartialUpdateImpl(...) {
throw std::runtime_error(
"This action does not support callbacks!"); }
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
Base class for non-leaf nodes of the computational graph.
RActionBase(RLoopManager *lm, const ColumnNames_t &colNames, const RColumnRegister &colRegister, const std::vector< std::string > &prevVariations)
unsigned int GetNSlots() const
const std::vector< std::string > & GetVariations() const
const ColumnNames_t & GetColumnNames() const
virtual bool HasRun() const
RLoopManager * fLoopManager
A raw pointer to the RLoopManager at the root of this functional graph.
RColumnRegister & GetColRegister()
A binder for user-defined columns, variations and aliases.
void Finalize() final
Clean-up and finalize the action result (e.g.
void Run(unsigned int slot, Long64_t entry) final
std::vector< std::shared_ptr< PrevNodeType > > fPrevNodes
Owning pointers to upstream nodes for each systematic variation.
std::unique_ptr< RMergeableValueBase > GetMergeableValue() const final
Retrieve a container holding the names and values of the variations.
RVariedAction(std::vector< Helper > &&helpers, const ColumnNames_t &columns, std::shared_ptr< PrevNode > prevNode, const RColumnRegister &colRegister)
void CallExec(unsigned int slot, unsigned int varIdx, Long64_t entry, TypeList< ColTypes... >, std::index_sequence< S... >)
auto PartialUpdateImpl(unsigned int slot) -> decltype(std::declval< H >().PartialUpdate(slot),(void *)(nullptr))
std::unique_ptr< RActionBase > CloneAction(void *typeErasedResults) final
ROOT::RDF::SampleCallback_t GetSampleCallback() final
Return a callback that in turn runs the callbacks of each variation's helper.
void FinalizeSlot(unsigned int slot) final
Clean-up operations to be performed at the end of a task.
std::vector< std::shared_ptr< PrevNodeType > > MakePrevFilters(std::shared_ptr< PrevNode > nominal) const
Creates new filter nodes, one per variation, from the upstream nominal one.
std::make_index_sequence< ColumnTypes_t::list_size > TypeInd_t
std::vector< std::vector< std::array< RColumnReaderBase *, ColumnTypes_t::list_size > > > fInputValues
Column readers per slot (outer dimension), per variation and per input column (inner dimension,...
std::vector< Helper > fHelpers
Action helpers per variation.
void * PartialUpdateImpl(...)
RVariedAction & operator=(const RVariedAction &)=delete
void InitSlot(TTreeReader *r, unsigned int slot) final
std::conditional_t< std::is_same< PrevNode, RJittedFilter >::value, RFilterBase, PrevNode > PrevNodeType
std::shared_ptr< RDFGraphDrawing::GraphNode > GetGraph(std::unordered_map< void *, std::shared_ptr< RDFGraphDrawing::GraphNode > > &visitedMap) final
std::array< bool, ColumnTypes_t::list_size > fIsDefine
The nth flag signals whether the nth input column is a custom column or not.
void * PartialUpdate(unsigned int slot) final
Return the partially-updated value connected to the first variation.
std::unique_ptr< RActionBase > MakeVariedAction(std::vector< void * > &&) final
RVariedAction(const RVariedAction &)=delete
RVariedAction(std::vector< Helper > &&helpers, const ColumnNames_t &columns, const std::vector< std::shared_ptr< PrevNodeType > > &prevNodes, const RColumnRegister &colRegister)
This constructor takes in input a vector of previous nodes, motivated by the CloneAction logic.
void TriggerChildrenCount() final
This type represents a sample identifier, to be used in conjunction with RDataFrame features such as ...
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
bool IsStrInVec(const std::string &str, const std::vector< std::string > &vec)
std::array< RDFDetail::RColumnReaderBase *, sizeof...(ColTypes)> GetColumnReaders(unsigned int slot, TTreeReader *r, TypeList< ColTypes... >, const RColumnReadersInfo &colInfo, const std::string &variationName="nominal")
Create a group of column readers, one per type in the parameter pack.
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....
std::vector< std::string > ColumnNames_t
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
This type aggregates some of the arguments passed to GetColumnReaders.
Lightweight storage for a collection of types.