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));
60namespace Experimental {
66 std::unordered_map<std::string, std::shared_ptr<T>>
fMap;
72 ROOT::Internal::RDF::MakeResultMap<T>(std::shared_ptr<T> nominalResult,
73 std::vector<std::shared_ptr<T>> &&variedResults,
75 std::shared_ptr<ROOT::Internal::RDF::RActionBase> nominalAction,
76 std::shared_ptr<ROOT::Internal::RDF::RActionBase> variedAction);
78 friend std::unique_ptr<ROOT::Detail::RDF::RMergeableVariations<T>>
82 RResultMap(std::shared_ptr<T> &&nominalResult, std::vector<std::shared_ptr<T>> &&variedResults,
84 std::shared_ptr<ROOT::Internal::RDF::RActionBase> nominalAction,
85 std::shared_ptr<ROOT::Internal::RDF::RActionBase> variedAction)
86 :
fKeys{
ROOT::Internal::RDF::Union({std::string(
"nominal")}, keys)}, fLoopManager(&lm),
87 fNominalAction(std::move(nominalAction)), fVariedAction(std::move(variedAction))
89 R__ASSERT(variedResults.size() == keys.size() &&
"Keys and values have different sizes!");
91 fMap.insert({
"nominal", std::move(nominalResult)});
92 for (
const auto &k : keys) {
93 auto it = fMap.insert({k, variedResults[i++]});
95 "Failed to insert an element in RResultMap, maybe a duplicated key? This should never happen.");
101 if ((fVariedAction !=
nullptr && !fVariedAction->HasRun()) || !fNominalAction->HasRun())
106 using iterator =
typename decltype(fMap)::iterator;
112 auto it = fMap.find(key);
113 if (it == fMap.end())
114 throw std::runtime_error(
"RResultMap: no result with key \"" + key +
"\".");
116 RunEventLoopIfNeeded();
124 RunEventLoopIfNeeded();
130 RunEventLoopIfNeeded();
131 return fMap.cbegin();
136 RunEventLoopIfNeeded();
142 RunEventLoopIfNeeded();
146 const std::vector<std::string> &
GetKeys()
const {
return fKeys; }
178 std::unique_ptr<RMergeableVariationsBase> mVariationsBase;
183 mVariationsBase = std::unique_ptr<RMergeableVariationsBase>({}, {});
185 mVariationsBase->AddNominal(rmap.
fNominalAction->GetMergeableValue());
187 return std::make_unique<RMergeableVariations<T>>(std::move(*mVariationsBase));
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)
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.