Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RAxisConfig.hxx
Go to the documentation of this file.
1/// \file ROOT/RAxisConfig.hxx
2/// \ingroup HistV7
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
25namespace ROOT {
26namespace Experimental {
27
28/**
29\class RAxisConfig
30Objects used to configure the different axis types. It can store the
31properties of all ROOT-provided axis types, together with the type of the axis.
32
33TODO: that's what a variant will be invented for!
34*/
36public:
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
45private:
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
64public:
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
140namespace Internal {
141
142/// Converts a RAxisConfig of whatever kind to the corresponding RAxisBase-derived
143/// object.
144template <RAxisConfig::EKind>
145struct AxisConfigToType; // Only specializations are defined.
146
147} // namespace Internal
148} // namespace Experimental
149} // namespace ROOT
150
151#endif // ROOT7_RAxisConfig header guard
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Objects used to configure the different axis types.
const std::vector< std::string > & GetBinLabels() const noexcept
Get the bin labels; non-empty if the GetKind() == kLabels.
std::vector< std::string > fLabels
Bin labels for a RAxisLabels.
const std::vector< double > & GetBinBorders() const noexcept
Get the bin borders; non-empty if the GetKind() == kIrregular.
static constexpr const Grow_t Grow
Tag signalling that an axis should be able to grow; used for calling the appropriate constructor like...
const std::string & GetTitle() const
Get the axis's title.
EKind GetKind() const noexcept
Get the axis kind represented by this RAxisConfig.
EKind fKind
The kind of axis represented by this configuration.
RAxisConfig(int nbins, double from, double to)
Represents a RAxisEquidistant with nbins from from to to.
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 ...
@ kGrow
represents a RAxisGrow
@ kEquidistant
represents a RAxisEquidistant
@ kIrregular
represents a RAxisIrregular
@ kLabels
represents a RAxisLabels
RAxisConfig(std::string_view title, const std::vector< double > &binborders)
Represents a RAxisIrregular with binborders and title.
RAxisConfig(const std::vector< double > &binborders)
Represents a RAxisIrregular with binborders.
RAxisConfig(std::string_view title, std::vector< double > &&binborders) noexcept
Represents a RAxisIrregular with binborders and title.
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.
RAxisConfig(std::vector< std::string > &&labels)
Represents a RAxisLabels with labels.
RAxisConfig(std::string_view title, std::vector< std::string > &&labels)
Represents a RAxisLabels with labels and title.
std::vector< double > fBinBorders
Bin borders of the RAxisIrregular.
int GetNBinsNoOver() const noexcept
Get the number of bins, excluding under- and overflow.
RAxisConfig(std::vector< double > &&binborders) noexcept
Represents a RAxisIrregular with binborders.
RAxisConfig(Grow_t, int nbins, double from, double to)
Represents a RAxisGrow with nbins from from to to.
RAxisConfig(const std::vector< std::string_view > &labels)
Represents a RAxisLabels with labels.
RAxisConfig(std::string_view title, const std::vector< std::string_view > &labels)
Represents a RAxisLabels with labels and title.
RAxisConfig(std::string_view title, int nbins, double from, double to)
Represents a RAxisEquidistant with nbins from from to to, and axis title.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
Converts a RAxisConfig of whatever kind to the corresponding RAxisBase-derived object.
Tag type signalling that an axis should be able to grow; used for calling the appropriate constructor...