Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
RColumnRegister.hxx
Go to the documentation of this file.
1// Author: Enrico Guiraud, Danilo Piparo, Massimo Tumolo CERN 06/2018
2// Author: Vincenzo Eduardo Padulano CERN 05/2024
3
4/*************************************************************************
5 * Copyright (C) 1995-2024, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_RDF_RCOLUMNREGISTER
13#define ROOT_RDF_RCOLUMNREGISTER
14
15#include <TString.h>
16
17#include <algorithm>
18#include <unordered_map>
19#include <memory>
20#include <string>
21#include <string_view>
22#include <vector>
23#include <utility>
24
25namespace ROOT {
26namespace RDF {
28}
29namespace Detail {
30namespace RDF {
32class RDefineBase;
33class RLoopManager;
34}
35} // namespace Detail
36
37namespace Internal {
38namespace RDF {
39
40namespace RDFDetail = ROOT::Detail::RDF;
41
42class RVariationBase;
46
47/**
48 * \class ROOT::Internal::RDF::RColumnRegister
49 * \brief A binder for user-defined columns, variations and aliases.
50 *
51 * The storage is copy-on-write and shared between all instances of the class that have the same values.
52 *
53 * Several components of an RDF computation graph make use of a column register. It keeps track of which columns have
54 * been defined, varied or aliased at each point of the computation graph.
55 * In many cases, the contents of the different column register instances are the same or only differ by a single
56 * extra defined/varied/aliased column. For this reason, in order to avoid unnecessary data duplication, fDefines,
57 * fAliases, fVariations and fColumnNames are all shared_ptr<const T> that (whenever possible) are shared across
58 * RColumnRegister instances that are part of the same computation graph. If a new column, alias or variation is added
59 * between one node and the next, then the new node contains a new instance of a RColumnRegister that shares all data
60 * members with the previous instance except for the one data member that needed updating, which is replaced with a new
61 * updated instance.
62 *
63 * The contents of the collections that keep track of other objects of the computation graph are not owned by the
64 * RColumnRegister object. They are registered centrally by the RLoopManager and only accessed via reference in the
65 * RColumnRegister.
66 */
68 using VariationsMap_t = std::unordered_multimap<std::string_view, ROOT::Internal::RDF::RVariationsWithReaders *>;
69 using DefinesMap_t = std::vector<std::pair<std::string_view, ROOT::Internal::RDF::RDefinesWithReaders *>>;
70 using AliasesMap_t = std::vector<std::pair<std::string_view, std::string_view>>;
71
72 /// The head node of the computation graph this register belongs to. Never null.
74
75 /// Immutable multimap of Variations, can be shared among several nodes.
76 /// The key is the name of an existing column, the values are all variations
77 /// that affect that column. Variations that affect multiple columns are
78 /// inserted in the map multiple times, once per column, and conversely each
79 /// column (i.e. each key) can have several associated variations.
80 std::shared_ptr<const VariationsMap_t> fVariations;
81 /// Immutable collection of Defines, can be shared among several nodes.
82 /// The pointee changes if a new Define node is added to the RColumnRegister.
83 /// It is a vector because we rely on insertion order to recreate the branch
84 /// of the computation graph where necessary.
85 std::shared_ptr<const DefinesMap_t> fDefines;
86 /// Immutable map of Aliases, can be shared among several nodes.
87 /// The pointee changes if a new Alias node is added to the RColumnRegister.
88 /// It is a vector because we rely on insertion order to recreate the branch
89 /// of the computation graph where necessary.
90 std::shared_ptr<const AliasesMap_t> fAliases;
91
92 RVariationsWithReaders *FindVariationAndReaders(const std::string &colName, const std::string &variationName);
93
94public:
96
97 ////////////////////////////////////////////////////////////////////////////
98 /// \brief Return the list of the names of the defined columns (Defines + Aliases).
99 std::vector<std::string_view> GenerateColumnNames() const;
100
101 std::vector<std::string_view> BuildDefineNames() const;
102
103 RDFDetail::RDefineBase *GetDefine(std::string_view colName) const;
104
105 bool IsDefineOrAlias(std::string_view name) const;
106
107 void AddDefine(std::shared_ptr<RDFDetail::RDefineBase> column);
108
109 void AddAlias(std::string_view alias, std::string_view colName);
110
111 bool IsAlias(std::string_view name) const;
112 bool IsDefine(std::string_view name) const;
113
114 std::string_view ResolveAlias(std::string_view alias) const;
115
116 void AddVariation(std::shared_ptr<RVariationBase> variation);
117
118 std::vector<std::string> GetVariationsFor(const std::string &column) const;
119
120 std::vector<std::string> GetVariationDeps(const std::string &column) const;
121
122 std::vector<std::string> GetVariationDeps(const std::vector<std::string> &columns) const;
123
125
126 RDFDetail::RColumnReaderBase *GetReader(unsigned int slot, const std::string &colName,
127 const std::string &variationName, const std::type_info &tid);
128
129 RDFDetail::RColumnReaderBase *
130 GetReaderUnchecked(unsigned int slot, const std::string &colName, const std::string &variationName);
131};
132
133} // Namespace RDF
134} // Namespace Internal
135} // Namespace ROOT
136
137#endif // ROOT_RDF_RCOLUMNREGISTER
char name[80]
Definition TGX11.cxx:148
The head node of a RDF computation graph.
std::vector< std::string_view > GenerateColumnNames() const
Return the list of the names of the defined columns (Defines + Aliases).
bool IsDefineOrAlias(std::string_view name) const
Check if the provided name is tracked in the names list.
bool IsAlias(std::string_view name) const
Return true if the given column name is an existing alias.
std::vector< std::string_view > BuildDefineNames() const
Return the list of the names of defined columns (no aliases).
std::vector< std::pair< std::string_view, ROOT::Internal::RDF::RDefinesWithReaders * > > DefinesMap_t
std::vector< std::string > GetVariationsFor(const std::string &column) const
Get the names of the variations that directly provide alternative values for this column.
std::string_view ResolveAlias(std::string_view alias) const
Return the actual column name that the alias resolves to.
RDFDetail::RColumnReaderBase * GetReaderUnchecked(unsigned int slot, const std::string &colName, const std::string &variationName)
Return a RDefineReader or a RVariationReader, or nullptr if not available.
std::shared_ptr< const VariationsMap_t > fVariations
Immutable multimap of Variations, can be shared among several nodes.
RDFDetail::RColumnReaderBase * GetReader(unsigned int slot, const std::string &colName, const std::string &variationName, const std::type_info &tid)
Return a RDefineReader or a RVariationReader, or nullptr if not available.
std::shared_ptr< const DefinesMap_t > fDefines
Immutable collection of Defines, can be shared among several nodes.
bool IsDefine(std::string_view name) const
Return true if the given column name is an existing defined column.
void AddVariation(std::shared_ptr< RVariationBase > variation)
Register a new systematic variation.
std::vector< std::pair< std::string_view, std::string_view > > AliasesMap_t
std::shared_ptr< const AliasesMap_t > fAliases
Immutable map of Aliases, can be shared among several nodes.
void AddDefine(std::shared_ptr< RDFDetail::RDefineBase > column)
Add a new defined column.
RColumnRegister(ROOT::Detail::RDF::RLoopManager *lm)
std::vector< std::string > GetVariationDeps(const std::string &column) const
Get the names of all variations that directly or indirectly affect a given column.
ROOT::RDF::RVariationsDescription BuildVariationsDescription() const
ROOT::Detail::RDF::RLoopManager * fLoopManager
The head node of the computation graph this register belongs to. Never null.
std::unordered_multimap< std::string_view, ROOT::Internal::RDF::RVariationsWithReaders * > VariationsMap_t
void AddAlias(std::string_view alias, std::string_view colName)
Add a new alias to the ledger.
RDFDetail::RDefineBase * GetDefine(std::string_view colName) const
Return the RDefine for the requested column name, or nullptr.
RVariationsWithReaders * FindVariationAndReaders(const std::string &colName, const std::string &variationName)
Return the RVariationsWithReaders object that handles the specified variation of the specified column...
A helper type that keeps track of RDefine objects and their corresponding RDefineReaders.
This type includes all parts of RVariation that do not depend on the callable signature.
Column reader that reads the value for a specific column, variation and slot.
A descriptor for the systematic variations known to a given RDataFrame node.
Special implementation of ROOT::RRangeCast for TCollection, including a check that the cast target ty...
Definition TObject.h:395