Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RBookedCustomColumns.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 RCustomColumnBase;
25 }
26 }
27 
28 namespace Internal {
29 namespace RDF {
30 
31 namespace RDFDetail = ROOT::Detail::RDF;
32 
33 /**
34  * \class ROOT::Internal::RDF::RBookedCustomColumns
35  * \ingroup dataframe
36  * \brief Encapsulates the columns defined by the user
37  */
38 
39 class RBookedCustomColumns {
40  using RCustomColumnBasePtrMap_t = std::map<std::string, std::shared_ptr<RDFDetail::RCustomColumnBase>>;
41  using ColumnNames_t = std::vector<std::string>;
42 
43  // Since RBookedCustomColumns is meant to be an immutable, copy-on-write object, the actual values are set as const
44  using RCustomColumnBasePtrMapPtr_t = std::shared_ptr<const RCustomColumnBasePtrMap_t>;
45  using ColumnNamesPtr_t = std::shared_ptr<const ColumnNames_t>;
46 
47 private:
48  RCustomColumnBasePtrMapPtr_t fCustomColumns;
49  ColumnNamesPtr_t fCustomColumnsNames;
50 
51 public:
52  ////////////////////////////////////////////////////////////////////////////
53  /// \brief Copy-ctor for RBookedCustomColumns.
54  RBookedCustomColumns(const RBookedCustomColumns &) = default;
55 
56  ////////////////////////////////////////////////////////////////////////////
57  /// \brief Move-ctor for RBookedCustomColumns.
58  RBookedCustomColumns(RBookedCustomColumns &&) = default;
59 
60  ////////////////////////////////////////////////////////////////////////////
61  /// \brief Copy-assignment operator for RBookedCustomColumns.
62  RBookedCustomColumns &operator=(const RBookedCustomColumns &) = default;
63 
64  ////////////////////////////////////////////////////////////////////////////
65  /// \brief Creates the object starting from the provided maps
66  RBookedCustomColumns(RCustomColumnBasePtrMapPtr_t customColumns, ColumnNamesPtr_t customColumnNames)
67  : fCustomColumns(customColumns), fCustomColumnsNames(customColumnNames)
68  {
69  }
70 
71  ////////////////////////////////////////////////////////////////////////////
72  /// \brief Creates a new wrapper with empty maps
73  RBookedCustomColumns()
74  : fCustomColumns(std::make_shared<RCustomColumnBasePtrMap_t>()),
75  fCustomColumnsNames(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 *fCustomColumnsNames; }
82 
83  ////////////////////////////////////////////////////////////////////////////
84  /// \brief Returns the list of the pointers to the defined columns
85  const RCustomColumnBasePtrMap_t &GetColumns() const { return *fCustomColumns; }
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 Internally it recreates the map with the new column, and swaps with the old one.
93  void AddColumn(const std::shared_ptr<RDFDetail::RCustomColumnBase> &column, std::string_view name);
94 
95  ////////////////////////////////////////////////////////////////////////////
96  /// \brief Internally it recreates the map with the new column name, and swaps with the old one.
97  void AddName(std::string_view name);
98 };
99 
100 } // Namespace RDF
101 } // Namespace Internal
102 } // Namespace ROOT
103 
104 #endif