Logo ROOT  
Reference Guide
RAxisConfig.hxx
Go to the documentation of this file.
1 /// \file ROOT/RAxisConfig.hxx
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
42  kNumKinds
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
ROOT::Experimental::RAxisConfig::Grow
constexpr static const Grow_t Grow
Tag signalling that an axis should be able to grow; used for calling the appropriate constructor like...
Definition: RAxisConfig.hxx:84
ROOT::Experimental::RAxisConfig::GetTitle
const std::string & GetTitle() const
Get the axis's title.
Definition: RAxisConfig.hxx:137
ROOT::Experimental::RAxisConfig::kGrow
@ kGrow
represents a RAxisGrow
Definition: RAxisConfig.hxx:51
ROOT::Experimental::RAxisConfig::GetBinLabels
const std::vector< std::string > & GetBinLabels() const noexcept
Get the bin labels; non-empty if the GetKind() == kLabels.
Definition: RAxisConfig.hxx:149
ROOT::Experimental::RAxisConfig::Grow_t
Tag type signalling that an axis should be able to grow; used for calling the appropriate constructor...
Definition: RAxisConfig.hxx:79
ROOT::Experimental::RAxisConfig
Definition: RAxisConfig.hxx:47
ROOT::Experimental::RAxisConfig::RAxisConfig
RAxisConfig(const std::vector< double > &binborders)
Represents a RAxisIrregular with binborders.
Definition: RAxisConfig.hxx:109
ROOT::Experimental::RAxisConfig::GetBinBorders
const std::vector< double > & GetBinBorders() const noexcept
Get the bin borders; non-empty if the GetKind() == kIrregular.
Definition: RAxisConfig.hxx:146
string_view
basic_string_view< char > string_view
Definition: libcpp_string_view.h:785
ROOT::Experimental::RAxisConfig::kEquidistant
@ kEquidistant
represents a RAxisEquidistant
Definition: RAxisConfig.hxx:50
ROOT::Experimental::RAxisConfig::fLabels
std::vector< std::string > fLabels
Bin labels for a RAxisLabels.
Definition: RAxisConfig.hxx:62
ROOT::Experimental::RAxisConfig::kIrregular
@ kIrregular
represents a RAxisIrregular
Definition: RAxisConfig.hxx:52
ROOT::Experimental::RAxisConfig::fTitle
std::string fTitle
Definition: RAxisConfig.hxx:58
ROOT::Experimental::RAxisConfig::kLabels
@ kLabels
represents a RAxisLabels
Definition: RAxisConfig.hxx:53
RStringView.hxx
ROOT::Experimental::RAxisConfig::GetKind
EKind GetKind() const noexcept
Get the axis kind represented by this RAxisConfig.
Definition: RAxisConfig.hxx:140
ROOT::Experimental::RAxisConfig::fKind
EKind fKind
The kind of axis represented by this configuration.
Definition: RAxisConfig.hxx:60
ROOT::Experimental::RAxisConfig::kNumKinds
@ kNumKinds
Definition: RAxisConfig.hxx:54
ROOT::Experimental::RAxisConfig::fNBinsNoOver
int fNBinsNoOver
Definition: RAxisConfig.hxx:59
ROOT::Experimental::RAxisConfig::GetNBinsNoOver
int GetNBinsNoOver() const noexcept
Get the number of bins, excluding under- and overflow.
Definition: RAxisConfig.hxx:143
ROOT::Experimental::Internal::swap
void swap(RDirectoryEntry &e1, RDirectoryEntry &e2) noexcept
Definition: RDirectoryEntry.hxx:112
ROOT::Experimental::RAxisConfig::fBinBorders
std::vector< double > fBinBorders
Bin borders of the RAxisIrregular.
Definition: RAxisConfig.hxx:61
ROOT::Experimental::RAxisConfig::RAxisConfig
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:66
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::Experimental::RAxisConfig::EKind
EKind
Definition: RAxisConfig.hxx:49