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 * \ingroup dataframe
50 * \brief A binder for user-defined columns, variations and aliases.
51 *
52 * The storage is copy-on-write and shared between all instances of the class that have the same values.
53 *
54 * Several components of an RDF computation graph make use of a column register. It keeps track of which columns have
55 * been defined, varied or aliased at each point of the computation graph.
56 * In many cases, the contents of the different column register instances are the same or only differ by a single
57 * extra defined/varied/aliased column. For this reason, in order to avoid unnecessary data duplication, fDefines,
58 * fAliases, fVariations and fColumnNames are all shared_ptr<const T> that (whenever possible) are shared across
59 * RColumnRegister instances that are part of the same computation graph. If a new column, alias or variation is added
60 * between one node and the next, then the new node contains a new instance of a RColumnRegister that shares all data
61 * members with the previous instance except for the one data member that needed updating, which is replaced with a new
62 * updated instance.
63 *
64 * The contents of the collections that keep track of other objects of the computation graph are not owned by the
65 * RColumnRegister object. They are registered centrally by the RLoopManager and only accessed via reference in the
66 * RColumnRegister.
67 */
69 using VariationsMap_t = std::unordered_multimap<std::string_view, ROOT::Internal::RDF::RVariationsWithReaders *>;
70 using DefinesMap_t = std::vector<std::pair<std::string_view, ROOT::Internal::RDF::RDefinesWithReaders *>>;
71 using AliasesMap_t = std::vector<std::pair<std::string_view, std::string_view>>;
72
73 /// The head node of the computation graph this register belongs to. Never null.
75
76 /// Immutable multimap of Variations, can be shared among several nodes.
77 /// The key is the name of an existing column, the values are all variations
78 /// that affect that column. Variations that affect multiple columns are
79 /// inserted in the map multiple times, once per column, and conversely each
80 /// column (i.e. each key) can have several associated variations.
81 std::shared_ptr<const VariationsMap_t> fVariations;
82 /// Immutable collection of Defines, can be shared among several nodes.
83 /// The pointee changes if a new Define node is added to the RColumnRegister.
84 /// It is a vector because we rely on insertion order to recreate the branch
85 /// of the computation graph where necessary.
86 std::shared_ptr<const DefinesMap_t> fDefines;
87 /// Immutable map of Aliases, can be shared among several nodes.
88 /// The pointee changes if a new Alias node is added to the RColumnRegister.
89 /// It is a vector because we rely on insertion order to recreate the branch
90 /// of the computation graph where necessary.
91 std::shared_ptr<const AliasesMap_t> fAliases;
92
93 RVariationsWithReaders *FindVariationAndReaders(const std::string &colName, const std::string &variationName);
94
95public:
97
98 ////////////////////////////////////////////////////////////////////////////
99 /// \brief Return the list of the names of the defined columns (Defines + Aliases).
100 std::vector<std::string_view> GenerateColumnNames() const;
101
102 std::vector<std::string_view> BuildDefineNames() const;
103
104 RDFDetail::RDefineBase *GetDefine(std::string_view colName) const;
105
106 bool IsDefineOrAlias(std::string_view name) const;
107
108 void AddDefine(std::shared_ptr<RDFDetail::RDefineBase> column);
109
110 void AddAlias(std::string_view alias, std::string_view colName);
111
112 bool IsAlias(std::string_view name) const;
113 bool IsDefine(std::string_view name) const;
114
115 std::string_view ResolveAlias(std::string_view alias) const;
116
117 void AddVariation(std::shared_ptr<RVariationBase> variation);
118
119 std::vector<std::string> GetVariationsFor(const std::string &column) const;
120
121 std::vector<std::string> GetVariationDeps(const std::string &column) const;
122
123 std::vector<std::string> GetVariationDeps(const std::vector<std::string> &columns) const;
124
126
127 RDFDetail::RColumnReaderBase *GetReader(unsigned int slot, const std::string &colName,
128 const std::string &variationName, const std::type_info &tid);
129};
130
131} // Namespace RDF
132} // Namespace Internal
133} // Namespace ROOT
134
135#endif // ROOT_RDF_RCOLUMNREGISTER
char name[80]
Definition TGX11.cxx:110
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.
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:384
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...