11#ifndef ROOT_RDF_RRESULTMAP
12#define ROOT_RDF_RRESULTMAP
22#include <unordered_map>
29namespace Experimental {
47MakeResultMap(std::shared_ptr<T> nominalResult, std::vector<std::shared_ptr<T>> &&variedResults,
49 std::shared_ptr<ROOT::Internal::RDF::RActionBase> nominalAction,
50 std::shared_ptr<ROOT::Internal::RDF::RActionBase> variedAction)
53 lm, std::move(nominalAction), std::move(variedAction));
66 std::shared_ptr<T> nominalResult{inmap.
fMap.at(
"nominal")};
67 auto nominalAction{inmap.
fNominalAction->CloneAction(
reinterpret_cast<void *
>(&nominalResult))};
69 std::size_t nVariations{inmap.
fMap.size() - 1};
70 std::vector<std::shared_ptr<T>> variedResults;
71 variedResults.reserve(nVariations);
72 for (
auto i = 0u; i < nVariations; ++i)
73 variedResults.emplace_back(
new T{*nominalResult});
75 std::vector<void *> typeErasedResults;
76 typeErasedResults.reserve(nVariations);
77 for (
auto &res : variedResults)
78 typeErasedResults.push_back(&res);
79 auto variedAction{inmap.
fVariedAction->CloneAction(
reinterpret_cast<void *
>(&typeErasedResults))};
81 std::vector<std::string> variationNames{inmap.
fKeys};
82 Erase<std::string>(
"nominal", variationNames);
86 std::move(nominalAction), std::move(variedAction));
95namespace Experimental {
101 std::unordered_map<std::string, std::shared_ptr<T>>
fMap;
107 ROOT::Internal::RDF::MakeResultMap<T>(std::shared_ptr<T> nominalResult,
108 std::vector<std::shared_ptr<T>> &&variedResults,
110 std::shared_ptr<ROOT::Internal::RDF::RActionBase> nominalAction,
111 std::shared_ptr<ROOT::Internal::RDF::RActionBase> variedAction);
114 friend std::unique_ptr<ROOT::Detail::RDF::RMergeableVariations<T>>
115 ROOT::Detail::RDF::GetMergeableValue<T>(
RResultMap<T> &rmap);
116 friend class ::ROOT::RDF::RResultHandle;
119 RResultMap(std::shared_ptr<T> &&nominalResult, std::vector<std::shared_ptr<T>> &&variedResults,
121 std::shared_ptr<ROOT::Internal::RDF::RActionBase> nominalAction,
122 std::shared_ptr<ROOT::Internal::RDF::RActionBase> variedAction)
123 :
fKeys{
ROOT::Internal::RDF::Union({std::string(
"nominal")}, keys)}, fLoopManager(&lm),
124 fNominalAction(std::move(nominalAction)), fVariedAction(std::move(variedAction))
126 R__ASSERT(variedResults.size() == keys.size() &&
"Keys and values have different sizes!");
128 fMap.insert({
"nominal", std::move(nominalResult)});
129 for (
const auto &k : keys) {
130 auto it = fMap.insert({k, variedResults[i++]});
132 "Failed to insert an element in RResultMap, maybe a duplicated key? This should never happen.");
138 if ((fVariedAction !=
nullptr && !fVariedAction->HasRun()) || !fNominalAction->HasRun())
143 using iterator =
typename decltype(fMap)::iterator;
149 auto it = fMap.find(key);
150 if (it == fMap.end())
151 throw std::runtime_error(
"RResultMap: no result with key \"" + key +
"\".");
153 RunEventLoopIfNeeded();
161 RunEventLoopIfNeeded();
167 RunEventLoopIfNeeded();
168 return fMap.cbegin();
173 RunEventLoopIfNeeded();
179 RunEventLoopIfNeeded();
183 const std::vector<std::string> &
GetKeys()
const {
return fKeys; }
215 std::unique_ptr<RMergeableVariationsBase> mVariationsBase;
220 mVariationsBase = std::unique_ptr<RMergeableVariationsBase>({}, {});
222 mVariationsBase->AddNominal(rmap.
fNominalAction->GetMergeableValue());
224 return std::make_unique<RMergeableVariations<T>>(std::move(*mVariationsBase));
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
The head node of a RDF computation graph.
A container for variation names and variation results.
typename decltype(fMap)::const_iterator const_iterator
T & operator[](const std::string &key)
ROOT::Detail::RDF::RLoopManager * fLoopManager
RResultMap(std::shared_ptr< T > &&nominalResult, std::vector< std::shared_ptr< T > > &&variedResults, std::vector< std::string > &&keys, ROOT::Detail::RDF::RLoopManager &lm, std::shared_ptr< ROOT::Internal::RDF::RActionBase > nominalAction, std::shared_ptr< ROOT::Internal::RDF::RActionBase > variedAction)
const std::vector< std::string > & GetKeys() const
typename decltype(fMap)::iterator iterator
void RunEventLoopIfNeeded()
const_iterator cend() const
std::shared_ptr< ROOT::Internal::RDF::RActionBase > fNominalAction
std::unordered_map< std::string, std::shared_ptr< T > > fMap
iterator begin()
Iterator to walk through key-value pairs of all variations for a given object.
std::vector< std::string > fKeys
std::shared_ptr< ROOT::Internal::RDF::RActionBase > fVariedAction
std::unique_ptr< RMergeableVariations< T > > GetMergeableValue(ROOT::RDF::Experimental::RResultMap< T > &rmap)
Retrieve mergeable values after calling ROOT::RDF::VariationsFor .
ROOT::RDF::Experimental::RResultMap< T > MakeResultMap(std::shared_ptr< T > nominalResult, std::vector< std::shared_ptr< T > > &&variedResults, std::vector< std::string > &&keys, RLoopManager &lm, std::shared_ptr< ROOT::Internal::RDF::RActionBase > nominalAction, std::shared_ptr< ROOT::Internal::RDF::RActionBase > variedAction)
ROOT::RDF::Experimental::RResultMap< T > CloneResultAndAction(const ROOT::RDF::Experimental::RResultMap< T > &inmap)
Clones an RResultMap and its corresponding RVariedAction.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...