11#ifndef ROOT_RVARIEDACTION
12#define ROOT_RVARIEDACTION
38template <
typename Helper,
typename PrevNode,
typename ColumnTypes_t>
40 using TypeInd_t = std::make_index_sequence<ColumnTypes_t::list_size>;
50 std::vector<std::vector<std::array<RColumnReaderBase *, ColumnTypes_t::list_size>>>
fInputValues;
53 std::array<bool, ColumnTypes_t::list_size>
fIsDefine;
55 std::vector<std::shared_ptr<PrevNodeType>>
MakePrevFilters(std::shared_ptr<PrevNode> nominal)
const
57 const auto &variations = GetVariations();
58 std::vector<std::shared_ptr<PrevNodeType>> prevFilters;
59 prevFilters.reserve(variations.size());
60 if (
static_cast<RNodeBase *
>(nominal.get()) == fLoopManager) {
62 prevFilters.resize(variations.size(), nominal);
65 const auto &prevVariations = nominal->GetVariations();
66 for (
const auto &variation : variations) {
68 prevFilters.emplace_back(std::static_pointer_cast<PrevNodeType>(nominal->GetVariedFilter(variation)));
70 prevFilters.emplace_back(nominal);
81 :
RActionBase(prevNode->GetLoopManagerUnchecked(), columns, colRegister, prevNode->GetVariations()),
82 fHelpers(std::move(helpers)), fPrevNodes(MakePrevFilters(prevNode)), fInputValues(
GetNSlots())
84 fLoopManager->Register(
this);
86 for (
auto i = 0u; i < columns.size(); ++i) {
87 auto *define = colRegister.
GetDefine(columns[i]);
88 fIsDefine[i] = define !=
nullptr;
101 std::for_each(fHelpers.begin(), fHelpers.end(), [](Helper &
h) { h.Initialize(); });
109 for (
const auto &variation : GetVariations())
110 fInputValues[slot].emplace_back(
GetColumnReaders(slot,
r, ColumnTypes_t{}, info, variation));
112 std::for_each(fHelpers.begin(), fHelpers.end(), [=](Helper &
h) { h.InitTask(r, slot); });
115 template <
typename... ColTypes, std::size_t... S>
119 fHelpers[varIdx].Exec(slot, fInputValues[slot][varIdx][S]->
template Get<ColTypes>(entry)...);
125 for (
auto varIdx = 0u; varIdx < GetVariations().size(); ++varIdx) {
126 if (fPrevNodes[varIdx]->CheckFilters(slot, entry))
127 CallExec(slot, varIdx, entry, ColumnTypes_t{},
TypeInd_t{});
133 std::for_each(fPrevNodes.begin(), fPrevNodes.end(), [](
auto &
f) { f->IncrChildrenCount(); });
139 fInputValues[slot].clear();
140 std::for_each(fHelpers.begin(), fHelpers.end(), [=](Helper &
h) { h.CallFinalizeTask(slot); });
147 std::for_each(fHelpers.begin(), fHelpers.end(), [](Helper &
h) { h.Finalize(); });
152 void *
PartialUpdate(
unsigned int slot)
final {
return PartialUpdateImpl(slot); }
157 std::shared_ptr<RDFGraphDrawing::GraphNode>
158 GetGraph(std::unordered_map<
void *, std::shared_ptr<RDFGraphDrawing::GraphNode>> &visitedMap)
final
160 auto prevNode = fPrevNodes[0]->GetGraph(visitedMap);
161 const auto &prevColumns = prevNode->GetDefinedColumns();
164 const auto nodeType = HasRun() ? RDFGraphDrawing::ENodeType::kUsedAction : RDFGraphDrawing::ENodeType::kAction;
165 auto thisNode = std::make_shared<RDFGraphDrawing::GraphNode>(
"Varied " + fHelpers[0].GetActionName(),
166 visitedMap.size(), nodeType);
167 visitedMap[(
void *)
this] = thisNode;
169 auto upmostNode = AddDefinesToGraph(thisNode, GetColRegister(), prevColumns, visitedMap);
171 thisNode->AddDefinedColumns(GetColRegister().GetNames());
172 upmostNode->SetPrevNode(prevNode);
182 std::vector<std::string> keys{GetVariations()};
184 std::vector<std::unique_ptr<RDFDetail::RMergeableValueBase>> values;
185 values.reserve(fHelpers.size());
186 for (
auto &&
h : fHelpers)
187 values.emplace_back(
h.GetMergeableValue());
189 return std::make_unique<RDFDetail::RMergeableVariationsBase>(std::move(keys), std::move(values));
194 throw std::logic_error(
"Cannot produce a varied action from a varied action.");
200 template <
typename H = Helper>
201 auto PartialUpdateImpl(
unsigned int slot) ->
decltype(std::declval<H>().PartialUpdate(slot), (
void *)(
nullptr))
203 return &fHelpers[0].PartialUpdate(slot);
207 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
virtual void MakeVariations(const std::vector< std::string > &variations)=0
Create clones of this Define that work with values in varied "universes".
Base class for non-leaf nodes of the computational graph.
A binder for user-defined columns, variations and aliases.
RDFDetail::RDefineBase * GetDefine(const std::string &colName) const
Return the RDefine for the requested column name, or nullptr.
Just like an RAction, but it has N action helpers (one per variation + nominal) and N previous nodes.
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 (with the "nominal" at index 0).
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))
ROOT::RDF::SampleCallback_t GetSampleCallback() final
Return the per-sample callback connected to the nominal result.
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
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 nominal result.
std::unique_ptr< RActionBase > MakeVariedAction(std::vector< void * > &&) final
RVariedAction(const RVariedAction &)=delete
void TriggerChildrenCount() final
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::vector< std::string > ColumnNames_t
std::function< void(unsigned int, const ROOT::RDF::RSampleInfo &)> SampleCallback_t
The type of a data-block callback, registered with a RDataFrame computation graph via e....
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
This type aggregates some of the arguments passed to GetColumnReaders.
Lightweight storage for a collection of types.