Logo ROOT   master
Reference Guide
RAxisConfig.hxx
Go to the documentation of this file.
1 /// \file ROOT/RAxisConfig.h
2 /// \ingroup Hist ROOT7
3 /// \author Axel Naumann <axel@cern.ch>
4 /// \date 2020-02-05
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6 /// is welcome!
7 
8 /*************************************************************************
9  * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
10  * All rights reserved. *
11  * *
12  * For the licensing terms see $ROOTSYS/LICENSE. *
13  * For the list of contributors see $ROOTSYS/README/CREDITS. *
14  *************************************************************************/
15 
16 #ifndef ROOT7_RAxisConfig
17 #define ROOT7_RAxisConfig
18 
19 #include <string>
20 #include <utility>
21 #include <vector>
22 
23 #include "ROOT/RStringView.hxx"
24 
25 namespace ROOT {
26 namespace Experimental {
27 
28 /**
29 \class RAxisConfig
30 Objects used to configure the different axis types. It can store the
31 properties of all ROOT-provided axis types, together with the type of the axis.
32 
33 TODO: that's what a variant will be invented for!
34 */
35 class RAxisConfig {
36 public:
37  enum EKind {
38  kEquidistant, ///< represents a RAxisEquidistant
39  kGrow, ///< represents a RAxisGrow
40  kIrregular, ///< represents a RAxisIrregular
41  kLabels, ///< represents a RAxisLabels
43  };
44 
45 private:
46  std::string fTitle;
48  EKind fKind; ///< The kind of axis represented by this configuration
49  std::vector<double> fBinBorders; ///< Bin borders of the RAxisIrregular
50  std::vector<std::string> fLabels; ///< Bin labels for a RAxisLabels
51 
52  /// Represents a `RAxisEquidistant` or `RAxisGrow` with `nbins` (excluding over- and
53  /// underflow bins) from `from` to `to`, with an axis title.
54  explicit RAxisConfig(std::string_view title, int nbins, double from, double to, EKind kind)
55  : fTitle(title), fNBinsNoOver(nbins), fKind(kind), fBinBorders(2)
56  {
57  if (from > to)
58  std::swap(to, from);
59 
60  fBinBorders[0] = from;
61  fBinBorders[1] = to;
62  }
63 
64 public:
65  /// Tag type signalling that an axis should be able to grow; used for calling
66  /// the appropriate constructor.
67  struct Grow_t {
68  };
69  /// Tag signalling that an axis should be able to grow; used for calling the
70  /// appropriate constructor like so:
71  /// RAxisConfig ac(RAxisConfig::Grow, 10, 0., 1.);
72  constexpr static const Grow_t Grow{};
73 
74  /// Represents a `RAxisEquidistant` with `nbins` from `from` to `to`, and
75  /// axis title.
76  RAxisConfig(std::string_view title, int nbins, double from, double to)
77  : RAxisConfig(title, nbins, from, to, kEquidistant)
78  {}
79 
80  /// Represents a `RAxisEquidistant` with `nbins` from `from` to `to`.
81  RAxisConfig(int nbins, double from, double to): RAxisConfig("", nbins, from, to, kEquidistant) {}
82 
83  /// Represents a `RAxisGrow` with `nbins` from `from` to `to`, and axis title.
84  RAxisConfig(std::string_view title, Grow_t, int nbins, double from, double to)
85  : RAxisConfig(title, nbins, from, to, kGrow)
86  {}
87 
88  /// Represents a `RAxisGrow` with `nbins` from `from` to `to`.
89  RAxisConfig(Grow_t, int nbins, double from, double to): RAxisConfig("", nbins, from, to, kGrow) {}
90 
91  /// Represents a `RAxisIrregular` with `binborders` and title.
92  RAxisConfig(std::string_view title, const std::vector<double> &binborders)
93  : fTitle(title), fNBinsNoOver(binborders.size() - 1), fKind(kIrregular), fBinBorders(binborders)
94  {}
95 
96  /// Represents a `RAxisIrregular` with `binborders`.
97  RAxisConfig(const std::vector<double> &binborders): RAxisConfig("", binborders) {}
98 
99  /// Represents a `RAxisIrregular` with `binborders` and title.
100  RAxisConfig(std::string_view title, std::vector<double> &&binborders) noexcept
101  : fTitle(title), fNBinsNoOver(binborders.size() - 1), fKind(kIrregular),
102  fBinBorders(std::move(binborders))
103  {}
104 
105  /// Represents a `RAxisIrregular` with `binborders`.
106  RAxisConfig(std::vector<double> &&binborders) noexcept: RAxisConfig("", std::move(binborders)) {}
107 
108  /// Represents a `RAxisLabels` with `labels` and title.
109  RAxisConfig(std::string_view title, const std::vector<std::string_view> &labels)
110  : fTitle(title), fNBinsNoOver(labels.size()), fKind(kLabels), fLabels(labels.begin(), labels.end())
111  {}
112 
113  /// Represents a `RAxisLabels` with `labels`.
114  RAxisConfig(const std::vector<std::string_view> &labels): RAxisConfig("", labels) {}
115 
116  /// Represents a `RAxisLabels` with `labels` and title.
117  RAxisConfig(std::string_view title, std::vector<std::string> &&labels)
118  : fTitle(title), fNBinsNoOver(labels.size()), fKind(kLabels), fLabels(std::move(labels))
119  {}
120 
121  /// Represents a `RAxisLabels` with `labels`.
122  RAxisConfig(std::vector<std::string> &&labels): RAxisConfig("", std::move(labels)) {}
123 
124  /// Get the axis's title
125  const std::string &GetTitle() const { return fTitle; }
126 
127  /// Get the axis kind represented by this `RAxisConfig`.
128  EKind GetKind() const noexcept { return fKind; }
129 
130  /// Get the number of bins, excluding under- and overflow.
131  int GetNBinsNoOver() const noexcept { return fNBinsNoOver; }
132 
133  /// Get the bin borders; non-empty if the GetKind() == kIrregular.
134  const std::vector<double> &GetBinBorders() const noexcept { return fBinBorders; }
135 
136  /// Get the bin labels; non-empty if the GetKind() == kLabels.
137  const std::vector<std::string> &GetBinLabels() const noexcept { return fLabels; }
138 };
139 
140 namespace Internal {
141 
142 /// Converts a RAxisConfig of whatever kind to the corresponding RAxisBase-derived
143 /// object.
144 template <RAxisConfig::EKind>
145 struct AxisConfigToType; // Only specializations are defined.
146 
147 } // namespace Internal
148 } // namespace Experimental
149 } // namespace ROOT
150 
151 #endif // ROOT7_RAxisConfig header guard
RAxisConfig(Grow_t, int nbins, double from, double to)
Represents a RAxisGrow with nbins from from to to.
Definition: RAxisConfig.hxx:89
Returns the available number of logical cores.
Definition: RNumpyDS.hxx:30
int GetNBinsNoOver() const noexcept
Get the number of bins, excluding under- and overflow.
EKind GetKind() const noexcept
Get the axis kind represented by this RAxisConfig.
RAxisConfig(std::string_view title, Grow_t, int nbins, double from, double to)
Represents a RAxisGrow with nbins from from to to, and axis title.
Definition: RAxisConfig.hxx:84
RAxisConfig(std::string_view title, const std::vector< std::string_view > &labels)
Represents a RAxisLabels with labels and title.
STL namespace.
const std::string & GetTitle() const
Get the axis&#39;s title.
RAxisConfig(int nbins, double from, double to)
Represents a RAxisEquidistant with nbins from from to to.
Definition: RAxisConfig.hxx:81
std::vector< double > fBinBorders
Bin borders of the RAxisIrregular.
Definition: RAxisConfig.hxx:49
RAxisConfig(const std::vector< std::string_view > &labels)
Represents a RAxisLabels with labels.
RAxisConfig(std::string_view title, int nbins, double from, double to)
Represents a RAxisEquidistant with nbins from from to to, and axis title.
Definition: RAxisConfig.hxx:76
Tag type signalling that an axis should be able to grow; used for calling the appropriate constructor...
Definition: RAxisConfig.hxx:67
const std::vector< std::string > & GetBinLabels() const noexcept
Get the bin labels; non-empty if the GetKind() == kLabels.
const std::vector< double > & GetBinBorders() const noexcept
Get the bin borders; non-empty if the GetKind() == kIrregular.
void swap(RDirectoryEntry &e1, RDirectoryEntry &e2) noexcept
RAxisConfig(std::string_view title, const std::vector< double > &binborders)
Represents a RAxisIrregular with binborders and title.
Definition: RAxisConfig.hxx:92
RAxisConfig(std::string_view title, std::vector< double > &&binborders) noexcept
Represents a RAxisIrregular with binborders and title.
RAxisConfig(std::string_view title, int nbins, double from, double to, EKind kind)
Represents a RAxisEquidistant or RAxisGrow with nbins (excluding over- and underflow bins) from from ...
Definition: RAxisConfig.hxx:54
RAxisConfig(std::vector< std::string > &&labels)
Represents a RAxisLabels with labels.
Objects used to configure the different axis types.
Definition: RAxisConfig.hxx:35
represents a RAxisEquidistant
Definition: RAxisConfig.hxx:38
RAxisConfig(const std::vector< double > &binborders)
Represents a RAxisIrregular with binborders.
Definition: RAxisConfig.hxx:97
Converts a RAxisConfig of whatever kind to the corresponding RAxisBase-derived object.
EKind fKind
The kind of axis represented by this configuration.
Definition: RAxisConfig.hxx:48
RAxisConfig(std::string_view title, std::vector< std::string > &&labels)
Represents a RAxisLabels with labels and title.
static constexpr const Grow_t Grow
Tag signalling that an axis should be able to grow; used for calling the appropriate constructor like...
Definition: RAxisConfig.hxx:72
std::vector< std::string > fLabels
Bin labels for a RAxisLabels.
Definition: RAxisConfig.hxx:50
RAxisConfig(std::vector< double > &&binborders) noexcept
Represents a RAxisIrregular with binborders.