Logo ROOT  
Reference Guide
RBookedDefines.hxx
Go to the documentation of this file.
1 // Author: Enrico Guiraud, Danilo Piparo, Massimo Tumolo CERN 06/2018
2 
3 /*************************************************************************
4  * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers. *
5  * All rights reserved. *
6  * *
7  * For the licensing terms see $ROOTSYS/LICENSE. *
8  * For the list of contributors see $ROOTSYS/README/CREDITS. *
9  *************************************************************************/
10 
11 #ifndef ROOT_RDFBOOKEDCUSTOMCOLUMNS
12 #define ROOT_RDFBOOKEDCUSTOMCOLUMNS
13 
14 #include <memory>
15 #include <map>
16 #include <vector>
17 #include <string>
18 #include <algorithm>
19 #include "TString.h"
20 
21 namespace ROOT {
22 namespace Detail {
23 namespace RDF {
24 class RDefineBase;
25 }
26 }
27 
28 namespace Internal {
29 namespace RDF {
30 
31 namespace RDFDetail = ROOT::Detail::RDF;
32 
33 /**
34  * \class ROOT::Internal::RDF::RBookedDefines
35  * \ingroup dataframe
36  * \brief Encapsulates the columns defined by the user
37  */
38 
40  using RDefineBasePtrMap_t = std::map<std::string, std::shared_ptr<RDFDetail::RDefineBase>>;
41  using ColumnNames_t = std::vector<std::string>;
42 
43  // Since RBookedDefines is meant to be an immutable, copy-on-write object, the actual values are set as const
44  using RDefineBasePtrMapPtr_t = std::shared_ptr<const RDefineBasePtrMap_t>;
45  using ColumnNamesPtr_t = std::shared_ptr<const ColumnNames_t>;
46 
47 private:
49  ColumnNamesPtr_t fDefinesNames; // also abused to keep track of aliases for each branch of the computation graph
50 
51 public:
52  ////////////////////////////////////////////////////////////////////////////
53  /// \brief Copy-ctor for RBookedDefines.
54  RBookedDefines(const RBookedDefines &) = default;
55 
56  ////////////////////////////////////////////////////////////////////////////
57  /// \brief Move-ctor for RBookedDefines.
59 
60  ////////////////////////////////////////////////////////////////////////////
61  /// \brief Copy-assignment operator for RBookedDefines.
63 
64  ////////////////////////////////////////////////////////////////////////////
65  /// \brief Creates the object starting from the provided maps
67  : fDefines(defines), fDefinesNames(defineNames)
68  {
69  }
70 
71  ////////////////////////////////////////////////////////////////////////////
72  /// \brief Creates a new wrapper with empty maps
74  : fDefines(std::make_shared<RDefineBasePtrMap_t>()),
75  fDefinesNames(std::make_shared<ColumnNames_t>())
76  {
77  }
78 
79  ////////////////////////////////////////////////////////////////////////////
80  /// \brief Returns the list of the names of the defined columns
81  ColumnNames_t GetNames() const { return *fDefinesNames; }
82 
83  ////////////////////////////////////////////////////////////////////////////
84  /// \brief Returns the list of the pointers to the defined columns
85  const RDefineBasePtrMap_t &GetColumns() const { return *fDefines; }
86 
87  ////////////////////////////////////////////////////////////////////////////
88  /// \brief Check if the provided name is tracked in the names list
89  bool HasName(std::string_view name) const;
90 
91  ////////////////////////////////////////////////////////////////////////////
92  /// \brief Add a new booked column.
93  /// Internally it recreates the map with the new column, and swaps it with the old one.
94  void AddColumn(const std::shared_ptr<RDFDetail::RDefineBase> &column, std::string_view name);
95 
96  ////////////////////////////////////////////////////////////////////////////
97  /// \brief Add a new name to the list returned by `GetNames` without booking a new column.
98  ///
99  /// This is needed because we abuse fDefinesNames to also keep track of the aliases defined
100  /// in each branch of the computation graph.
101  /// Internally it recreates the vector with the new name, and swaps it with the old one.
103 };
104 
105 } // Namespace RDF
106 } // Namespace Internal
107 } // Namespace ROOT
108 
109 #endif
ROOT::Internal::RDF::RBookedDefines::RBookedDefines
RBookedDefines()
Creates a new wrapper with empty maps.
Definition: RBookedDefines.hxx:73
ROOT::Internal::RDF::RBookedDefines::RBookedDefines
RBookedDefines(const RBookedDefines &)=default
Copy-ctor for RBookedDefines.
ROOT::Internal::RDF::RBookedDefines::ColumnNames_t
std::vector< std::string > ColumnNames_t
Definition: RBookedDefines.hxx:41
ROOT::Internal::RDF::RBookedDefines::fDefines
RDefineBasePtrMapPtr_t fDefines
Definition: RBookedDefines.hxx:48
ROOT::Internal::RDF::RBookedDefines::GetNames
ColumnNames_t GetNames() const
Returns the list of the names of the defined columns.
Definition: RBookedDefines.hxx:81
string_view
basic_string_view< char > string_view
Definition: libcpp_string_view.h:785
ROOT::Internal::RDF::RBookedDefines
Encapsulates the columns defined by the user.
Definition: RBookedDefines.hxx:39
ROOT::Internal::RDF::RBookedDefines::RDefineBasePtrMap_t
std::map< std::string, std::shared_ptr< RDFDetail::RDefineBase > > RDefineBasePtrMap_t
Definition: RBookedDefines.hxx:40
ROOT::Internal::RDF::RBookedDefines::RDefineBasePtrMapPtr_t
std::shared_ptr< const RDefineBasePtrMap_t > RDefineBasePtrMapPtr_t
Definition: RBookedDefines.hxx:44
ROOT::Internal::RDF::RBookedDefines::AddColumn
void AddColumn(const std::shared_ptr< RDFDetail::RDefineBase > &column, std::string_view name)
Add a new booked column.
Definition: RDFBookedDefines.cxx:13
ROOT::Internal::RDF::RBookedDefines::HasName
bool HasName(std::string_view name) const
Check if the provided name is tracked in the names list.
Definition: RDFBookedDefines.cxx:7
TString.h
ROOT::Detail::RDF
Definition: GraphUtils.hxx:28
ROOT::Internal::RDF::RBookedDefines::RBookedDefines
RBookedDefines(RDefineBasePtrMapPtr_t defines, ColumnNamesPtr_t defineNames)
Creates the object starting from the provided maps.
Definition: RBookedDefines.hxx:66
ROOT::Internal::RDF::RBookedDefines::operator=
RBookedDefines & operator=(const RBookedDefines &)=default
Copy-assignment operator for RBookedDefines.
ROOT::Internal::RDF::RBookedDefines::GetColumns
const RDefineBasePtrMap_t & GetColumns() const
Returns the list of the pointers to the defined columns.
Definition: RBookedDefines.hxx:85
ROOT::Internal::RDF::RBookedDefines::AddName
void AddName(std::string_view name)
Add a new name to the list returned by GetNames without booking a new column.
Definition: RDFBookedDefines.cxx:22
name
char name[80]
Definition: TGX11.cxx:110
ROOT::Internal::RDF::RBookedDefines::RBookedDefines
RBookedDefines(RBookedDefines &&)=default
Move-ctor for RBookedDefines.
ROOT::Internal::RDF::RBookedDefines::fDefinesNames
ColumnNamesPtr_t fDefinesNames
Definition: RBookedDefines.hxx:49
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: EExecutionPolicy.hxx:4
ROOT::Internal::RDF::RBookedDefines::ColumnNamesPtr_t
std::shared_ptr< const ColumnNames_t > ColumnNamesPtr_t
Definition: RBookedDefines.hxx:45