26 : fDefine(std::move(define)), fReadersPerVariation(nSlots)
35 auto it = defineReaders.find(variationName);
36 if (it != defineReaders.end())
40 if (variationName !=
"nominal")
41 define = &define->GetVariedDefine(variationName);
43#if !defined(__clang__) && __GNUC__ >= 7 && __GNUC_MINOR__ >= 3
44 const auto insertion = defineReaders.insert({variationName, std::make_unique<RDefineReader>(slot, *define)});
45 return *insertion.first->second;
48 auto reader = std::make_unique<RDefineReader>(slot, *define);
50 defineReaders[variationName] = std::move(reader);
56 : fVariation(std::move(variation)), fReadersPerVariation(nSlots)
71 auto it = varReaders.find(variationName);
72 if (it != varReaders.end())
75#if !defined(__clang__) && __GNUC__ >= 7 && __GNUC_MINOR__ >= 3
76 const auto insertion =
77 varReaders.insert({variationName, std::make_unique<RVariationReader>(slot, colName, variationName, *
fVariation)});
78 return *insertion.first->second;
81 auto reader = std::make_unique<RVariationReader>(slot, colName, variationName, *
fVariation);
83 varReaders[variationName] = std::move(reader);
89 : fLoopManager(lm), fDefines(std::make_shared<
DefinesMap_t>()),
90 fAliases(std::make_shared<std::unordered_map<std::string, std::string>>()),
114 names.emplace_back(kv.first);
124 return it ==
fDefines->end() ? nullptr : &it->second->GetDefine();
132 return ccolnamesEnd != std::find(
fColumnNames->begin(), ccolnamesEnd,
name);
140 auto newDefines = std::make_shared<DefinesMap_t>(*
fDefines);
141 const std::string &colName = define->GetName();
144 (*newDefines)[colName] = std::make_shared<RDefinesWithReaders>(define,
fLoopManager->GetNSlots());
154 auto newVariations = std::make_shared<VariationsMap_t>(*
fVariations);
155 const std::vector<std::string> &colNames = variation->GetColumnNames();
156 for (
auto &colName : colNames)
157 newVariations->insert({colName, std::make_shared<RVariationsWithReaders>(variation,
fLoopManager->GetNSlots())});
158 fVariations = std::move(newVariations);
163std::vector<std::string> RColumnRegister::GetVariationsFor(
const std::string &column)
const
165 std::vector<std::string> variations;
166 auto range = fVariations->equal_range(column);
167 for (
auto it = range.first; it != range.second; ++it)
168 for (
const auto &variationName : it->second->GetVariation().GetVariationNames())
169 variations.emplace_back(variationName);
179std::vector<std::string> RColumnRegister::GetVariationDeps(
const std::string &column)
const
181 return GetVariationDeps(std::vector<std::string>{column});
189std::vector<std::string> RColumnRegister::GetVariationDeps(
const ColumnNames_t &columns)
const
192 std::set<std::string> variationNames;
194 for (
const auto &col : columns) {
195 const auto &variations = GetVariationsFor(col);
196 for (
const auto &var : variations)
197 variationNames.insert(var);
200 auto defineIt = fDefines->find(col);
201 if (defineIt != fDefines->end()) {
202 for (
const auto &
v : defineIt->second->GetDefine().GetVariations())
203 variationNames.insert(
v);
207 return {variationNames.begin(), variationNames.end()};
214RColumnRegister::FindVariationAndReaders(
const std::string &colName,
const std::string &variationName)
216 auto range = fVariations->equal_range(colName);
217 if (range.first == fVariations->end())
219 for (
auto it = range.first; it != range.second; ++it) {
220 if (
IsStrInVec(variationName, it->second->GetVariation().GetVariationNames()))
221 return it->second.get();
229 std::set<const RVariationBase *> uniqueVariations;
230 for (
auto &
e : *fVariations)
231 uniqueVariations.insert(&
e.second->GetVariation());
233 const std::vector<const RVariationBase *> variations(uniqueVariations.begin(), uniqueVariations.end());
243void RColumnRegister::AddName(std::string_view
name)
245 const auto &names = *fColumnNames;
246 if (std::find(names.begin(), names.end(),
name) != names.end())
249 auto newColsNames = std::make_shared<ColumnNames_t>(names);
250 newColsNames->emplace_back(std::string(
name));
251 fColumnNames = newColsNames;
256void RColumnRegister::AddAlias(std::string_view alias, std::string_view colName)
260 auto newAliases = std::make_shared<std::unordered_map<std::string, std::string>>(*fAliases);
261 (*newAliases)[std::string(alias)] =
ResolveAlias(colName);
262 fAliases = std::move(newAliases);
268bool RColumnRegister::IsAlias(
const std::string &
name)
const
270 return fAliases->find(
name) != fAliases->end();
278std::string RColumnRegister::ResolveAlias(std::string_view alias)
const
280 std::string aliasStr{alias};
283 if (aliasStr.size() > 1 && aliasStr[0] ==
'#')
284 return "R_rdf_sizeof_" + aliasStr.substr(1);
286 auto it = fAliases->find(aliasStr);
287 if (it != fAliases->end())
296 const std::string &variationName,
297 const std::type_info &requestedType)
300 if (variationName !=
"nominal") {
301 auto *variationAndReaders = FindVariationAndReaders(colName, variationName);
302 if (variationAndReaders !=
nullptr) {
303 const auto &actualType = variationAndReaders->GetVariation().GetTypeId();
305 return &variationAndReaders->GetReader(slot, colName, variationName);
310 auto it = fDefines->find(colName);
311 if (it != fDefines->end()) {
312 const auto &actualType = it->second->GetDefine().GetTypeId();
314 return &it->second->GetReader(slot, variationName);
bool IsDefineOrAlias(std::string_view name) const
Check if the provided name is tracked in the names list.
ColumnNames_t BuildDefineNames() const
Return the list of the names of defined columns (no aliases).
std::shared_ptr< const std::unordered_map< std::string, std::string > > fAliases
Immutable map of Aliases, can be shared among several nodes.
RDFDetail::RDefineBase * GetDefine(const std::string &colName) const
Return the RDefine for the requested column name, or nullptr.
std::shared_ptr< const ColumnNames_t > fColumnNames
Names of Defines and Aliases registered so far.
std::unordered_multimap< std::string, std::shared_ptr< RVariationsWithReaders > > VariationsMap_t
See fVariations for more information on this type.
void AddVariation(std::shared_ptr< RVariationBase > variation)
Register a new systematic variation.
std::shared_ptr< VariationsMap_t > fVariations
Immutable multimap of Variations, can be shared among several nodes.
void AddDefine(std::shared_ptr< RDFDetail::RDefineBase > column)
Add a new defined column.
RColumnRegister(const RColumnRegister &)=default
std::shared_ptr< DefinesMap_t > fDefines
Immutable collection of Defines, can be shared among several nodes.
std::shared_ptr< RDFDetail::RLoopManager > fLoopManager
std::vector< std::string > ColumnNames_t
void AddName(std::string_view name)
Add a new name to the list returned by GetNames without booking a new column.
std::unordered_map< std::string, std::shared_ptr< RDefinesWithReaders > > DefinesMap_t
Column reader for defined columns.
std::vector< std::unordered_map< std::string, std::unique_ptr< RDefineReader > > > fReadersPerVariation
RDefineReader & GetReader(unsigned int slot, const std::string &variationName)
std::shared_ptr< RDefineBase > fDefine
RDefinesWithReaders(std::shared_ptr< RDefineBase > define, unsigned int nSlots)
Column reader that reads the value for a specific column, variation and slot.
std::vector< std::unordered_map< std::string, std::unique_ptr< RVariationReader > > > fReadersPerVariation
RVariationsWithReaders(std::shared_ptr< RVariationBase > variation, unsigned int nSlots)
RVariationReader & GetReader(unsigned int slot, const std::string &colName, const std::string &variationName)
Return a column reader for the given slot, column and variation.
std::shared_ptr< RVariationBase > fVariation
A descriptor for the systematic variations known to a given RDataFrame node.
bool IsStrInVec(const std::string &str, const std::vector< std::string > &vec)
std::string ResolveAlias(const std::string &col, const std::map< std::string, std::string > &aliasMap)
void CheckReaderTypeMatches(const std::type_info &colType, const std::type_info &requestedType, const std::string &colName)
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.