yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.0.2
YODA::Axis< T, typename > Class Template Reference

Discrete axis with edges of non-floating-point-type. More...

#include <BinnedAxis.h>

Public Types

using EdgeT = T
 
using ContainerT = std::vector< T >
 
using const_iterator = typename ContainerT::const_iterator
 

Public Member Functions

Constructors
 Axis ()
 Nullary constructor for unique pointers etc.
 
 Axis (const std::vector< T > &edges)
 Constructs discrete Axis from edges vector.
 
 Axis (std::vector< T > &&edges)
 Constructs discrete Axis from edges vector (rvalue).
 
 Axis (std::initializer_list< T > &&edges)
 Constructs discrete Axis from an initializer list.
 
 Axis (Axis< T > &&other)
 Move constructs Axis.
 
 Axis (const Axis< T > &other)
 Copy constructs Axis.
 
Axisoperator= (const Axis &other)
 
Axisoperator= (Axis &&other)
 
I/O
std::string type () const noexcept
 Returns a string representation of EdgeT.
 
int maxEdgeWidth () const noexcept
 
size_t index (const T &x) const
 Returns index of edge x.
 
EdgeT edge (const size_t i) const
 Returns edge corresponding to index i.
 
std::vector< EdgeTedges () const noexcept
 Returns a copy of the container of edges.
 
const_iterator begin () const
 Returns the const begin iterator for the edges container.
 
const_iterator end () const
 Returns the const end iterator for the edges container.
 
size_t size () const noexcept
 Returns number of edges + 1 for this Axis.
 
size_t numBins (const bool includeOverflows=false) const noexcept
 Returns number of bins of this axis.
 
bool hasSameEdges (const Axis< T > &other) const noexcept
 Checks if two axes have exactly the same edges.
 
std::vector< T > sharedEdges (const Axis< T > &other) const noexcept
 Finds shared between Axes edges.
 
bool isSubsetEdges (const Axis< T > &other) const noexcept
 Check if other axis edges are a subset of edges of this one.
 

Protected Member Functions

Utility
void fillEdges (std::vector< EdgeT > &&edges) noexcept
 Fills edge storage. Used in constructors.
 

Detailed Description

template<typename T, typename = void>
class YODA::Axis< T, typename >

Discrete axis with edges of non-floating-point-type.

Note
Based on unsorted std::vector<T>

Definition at line 91 of file BinnedAxis.h.

Member Typedef Documentation

◆ const_iterator

template<typename T , typename = void>
using YODA::Axis< T, typename >::const_iterator = typename ContainerT::const_iterator

Definition at line 95 of file BinnedAxis.h.

◆ ContainerT

template<typename T , typename = void>
using YODA::Axis< T, typename >::ContainerT = std::vector<T>

Definition at line 94 of file BinnedAxis.h.

◆ EdgeT

template<typename T , typename = void>
using YODA::Axis< T, typename >::EdgeT = T

Definition at line 93 of file BinnedAxis.h.

Constructor & Destructor Documentation

◆ Axis() [1/6]

template<typename T , typename = void>
YODA::Axis< T, typename >::Axis ( )
inline

Nullary constructor for unique pointers etc.

Definition at line 101 of file BinnedAxis.h.

101{ }

◆ Axis() [2/6]

template<typename T , typename U >
YODA::Axis< T, U >::Axis ( const std::vector< T > &  edges)

Constructs discrete Axis from edges vector.

Note
Vector is not sorted by constructor.

Concept check shall appear inside body of type's member function or outside of type, since otherwise type is considered incomplete.

Definition at line 223 of file BinnedAxis.h.

223 : Axis(std::vector<T>(edges)) {
226 static_assert(MetaUtils::checkConcept<Axis<EdgeT>, YODAConcepts::AxisImpl>(),
227 "Axis<T> should implement Axis concept.");
228 }
Axis()
Nullary constructor for unique pointers etc.
Definition BinnedAxis.h:101
std::vector< EdgeT > edges() const noexcept
Returns a copy of the container of edges.
Definition BinnedAxis.h:259

◆ Axis() [3/6]

template<typename T , typename U >
YODA::Axis< T, U >::Axis ( std::vector< T > &&  edges)

Constructs discrete Axis from edges vector (rvalue).

Note
Vector is not sorted by constructor.

Definition at line 231 of file BinnedAxis.h.

231 {
232 fillEdges(std::move(edges));
233 }
void fillEdges(std::vector< EdgeT > &&edges) noexcept
Fills edge storage. Used in constructors.
Definition BinnedAxis.h:309

◆ Axis() [4/6]

template<typename T , typename U >
YODA::Axis< T, U >::Axis ( std::initializer_list< T > &&  edges)

Constructs discrete Axis from an initializer list.

Note
Vector is not sorted by constructor.

Definition at line 236 of file BinnedAxis.h.

236 {
237 fillEdges(std::vector<T>{edges});
238 }

◆ Axis() [5/6]

template<typename T , typename = void>
YODA::Axis< T, typename >::Axis ( Axis< T > &&  other)
inline

Move constructs Axis.

Definition at line 119 of file BinnedAxis.h.

119: _edges(std::move(other._edges)) {}

◆ Axis() [6/6]

template<typename T , typename = void>
YODA::Axis< T, typename >::Axis ( const Axis< T > &  other)
inline

Copy constructs Axis.

Definition at line 122 of file BinnedAxis.h.

122: _edges(other._edges) {}

Member Function Documentation

◆ begin()

template<typename T , typename = void>
const_iterator YODA::Axis< T, typename >::begin ( ) const
inline

Returns the const begin iterator for the edges container.

Definition at line 182 of file BinnedAxis.h.

182{ return _edges.cbegin(); }

Referenced by YODA::Axis< T, typename >::sharedEdges().

◆ edge()

template<typename T , typename U >
Axis< T, U >::EdgeT YODA::Axis< T, U >::edge ( const size_t  i) const

Returns edge corresponding to index i.

Definition at line 248 of file BinnedAxis.h.

248 {
249 if (this->_edges.empty()) {
250 throw RangeError("Axis has no edges!");
251 }
252 if (!i || i > this->_edges.size()) {
253 throw RangeError("Invalid index, must be in range 1.." + std::to_string(this->_edges.size()));
254 }
255 return this->_edges.at(i-1);
256 }

◆ edges()

template<typename T , typename U >
std::vector< typename Axis< T, U >::EdgeT > YODA::Axis< T, U >::edges ( ) const
noexcept

Returns a copy of the container of edges.

Definition at line 259 of file BinnedAxis.h.

259 {
260 return this->_edges;
261 }

◆ end()

template<typename T , typename = void>
const_iterator YODA::Axis< T, typename >::end ( ) const
inline

Returns the const end iterator for the edges container.

Definition at line 185 of file BinnedAxis.h.

185{ return _edges.cend(); }

◆ fillEdges()

template<typename T , typename U >
void YODA::Axis< T, U >::fillEdges ( std::vector< EdgeT > &&  edges)
protectednoexcept

Fills edge storage. Used in constructors.

Definition at line 309 of file BinnedAxis.h.

309 {
310 for (auto& edge : edges) {
311 if (std::find(this->_edges.begin(),
312 this->_edges.end(), edge) == this->_edges.end()) // no duplicate edges allowed
313 _edges.emplace_back(std::move(edge));
314 }
315 }
EdgeT edge(const size_t i) const
Returns edge corresponding to index i.
Definition BinnedAxis.h:248

◆ hasSameEdges()

template<typename T , typename U >
bool YODA::Axis< T, U >::hasSameEdges ( const Axis< T > &  other) const
noexcept

Checks if two axes have exactly the same edges.

Definition at line 276 of file BinnedAxis.h.

276 {
277 return _edges.size() == other._edges.size() &&
278 std::equal(_edges.begin(), _edges.end(), other._edges.begin());
279 }

References YODA::Axis< T, typename >::size().

◆ index()

template<typename T , typename U >
size_t YODA::Axis< T, U >::index ( const T &  x) const

Returns index of edge x.

Note
Returns 0 if there is no x on this axis.

Definition at line 241 of file BinnedAxis.h.

241 {
242 auto it = std::find(this->_edges.begin(), this->_edges.end(), x);
243 if (it == this->_edges.end()) return 0; // otherflow
244 return it - this->_edges.begin() + 1;
245 }

◆ isSubsetEdges()

template<typename T , typename U >
bool YODA::Axis< T, U >::isSubsetEdges ( const Axis< T > &  other) const
noexcept

Check if other axis edges are a subset of edges of this one.

Remarks
Should it be symmetrical? E.g. ax1.subsetEdges(ax2) == ax2.subsetEdges(ax1)?
Note
std::includes demands sorted ranges

Definition at line 294 of file BinnedAxis.h.

294 {
295 if (_edges.size() == other._edges.size()) return hasSameEdges(other);
296
297 std::vector<T> edgesLhs(edges());
298 std::vector<T> edgesRhs(other.edges());
299
300 std::sort(edgesLhs.begin(), edgesLhs.end());
301 std::sort(edgesRhs.begin(), edgesRhs.end());
302
304 return std::includes(edgesLhs.begin(), edgesLhs.end(),
305 edgesRhs.begin(), edgesRhs.end());
306 }
bool hasSameEdges(const Axis< T > &other) const noexcept
Checks if two axes have exactly the same edges.
Definition BinnedAxis.h:276

◆ maxEdgeWidth()

template<typename T , typename = void>
int YODA::Axis< T, typename >::maxEdgeWidth ( ) const
inlinenoexcept

Definition at line 156 of file BinnedAxis.h.

156 {
157 int maxwidth = 0;
158 if constexpr (hasWidth<EdgeT>::value) {
159 auto it = std::max_element(_edges.begin(), _edges.end(),
160 [](const auto& a, const auto& b) {
161 return a.size() < b.size();
162 });
163 maxwidth = (*it).size();
164 }
165 return maxwidth;
166 }

◆ numBins()

template<typename T , typename U >
size_t YODA::Axis< T, U >::numBins ( const bool  includeOverflows = false) const
noexcept

Returns number of bins of this axis.

Includes +1 for the otherflow bin.

Definition at line 271 of file BinnedAxis.h.

271 {
272 return _edges.size() + (includeOverflows? 1 : 0);
273 }

References YODA::Axis< T, typename >::size().

◆ operator=() [1/2]

template<typename T , typename = void>
Axis & YODA::Axis< T, typename >::operator= ( Axis< T, typename > &&  other)
inline

Definition at line 129 of file BinnedAxis.h.

129 {
130 if (this != &other) _edges = std::move(other._edges);
131 return *this;
132 }

◆ operator=() [2/2]

template<typename T , typename = void>
Axis & YODA::Axis< T, typename >::operator= ( const Axis< T, typename > &  other)
inline

Definition at line 124 of file BinnedAxis.h.

124 {
125 if (this != &other) _edges = other._edges;
126 return *this;
127 }

◆ sharedEdges()

template<typename T , typename U >
std::vector< T > YODA::Axis< T, U >::sharedEdges ( const Axis< T > &  other) const
noexcept

Finds shared between Axes edges.

Note
Not sorted, order similar to initial (in constructor) not guaranteed.

Definition at line 282 of file BinnedAxis.h.

282 {
283 std::vector<EdgeT> res;
284 const auto& otherBegin = other._edges.begin();
285 const auto& otherEnd = other._edges.end();
286 for (const T& edge : this->_edges) {
287 if (std::find(otherBegin, otherEnd, edge) != otherEnd)
288 res.emplace_back(std::move(edge));
289 }
290 return res;
291 }

References YODA::Axis< T, typename >::begin().

◆ size()

template<typename T , typename U >
size_t YODA::Axis< T, U >::size ( ) const
noexcept

Returns number of edges + 1 for this Axis.

Includes +1 for the otherflow bin.

Definition at line 265 of file BinnedAxis.h.

265 {
266 return numBins(true);
267 }
size_t numBins(const bool includeOverflows=false) const noexcept
Returns number of bins of this axis.
Definition BinnedAxis.h:271

Referenced by YODA::Axis< T, typename >::hasSameEdges(), YODA::Axis< T, typename >::numBins(), and YODA::Axis< T, isCAxis< T > >::numBins().

◆ type()

template<typename T , typename = void>
std::string YODA::Axis< T, typename >::type ( ) const
inlinenoexcept

Returns a string representation of EdgeT.

Definition at line 154 of file BinnedAxis.h.

154{ return TypeID<EdgeT>::name(); }
static const char * name()

The documentation for this class was generated from the following file: