Alexandria  2.16
Please provide a description of the project.
EdgeVector.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2020 Euclid Science Ground Segment
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License as published by the Free
6  * Software Foundation; either version 3.0 of the License, or (at your option)
7  * any later version.
8  *
9  * This library is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
25 #ifndef ALEXANDRIA_HISTOGRAM_BINNING_EDGEVECTOR_H
26 #define ALEXANDRIA_HISTOGRAM_BINNING_EDGEVECTOR_H
27 
28 #include "Histogram/Histogram.h"
29 #include <utility>
30 #include <vector>
31 
32 namespace Euclid {
33 namespace Histogram {
34 namespace Binning {
35 
46 template<typename VarType>
47 class EdgeVector : public BinStrategy<VarType> {
48 public:
49  virtual ~EdgeVector() = default;
50 
51  EdgeVector(EdgeVector&&) = default;
52 
53  template<typename... Args>
54  explicit EdgeVector(Args&& ... args): m_edges(std::forward<Args>(args)...) {
55  m_nbins = m_edges.size() - 1;
56  }
57 
58  EdgeVector(const EdgeVector&) = default;
59 
60  ssize_t getBinIndex(VarType value) const final {
61  if (value < m_edges.front() || value > m_edges.back())
62  return -1;
63  auto next_edge = std::find_if(m_edges.begin(), m_edges.end(), [value](const VarType edge) { return edge > value; });
64  if (next_edge == m_edges.end())
65  --next_edge;
66  return next_edge - m_edges.begin() - 1;
67  }
68 
69  std::pair<VarType, VarType> getBinEdges(size_t i) const final {
70  return std::make_pair(m_edges[i], m_edges[i + 1]);
71  }
72 
73  VarType getEdge(size_t i) const final {
74  return m_edges[i];
75  }
76 
77 private:
80 };
81 
82 } // end of namespace Binning
83 } // end of namespace Histogram
84 } // end of namespace Euclid
85 
86 #endif // ALEXANDRIA_HISTOGRAM_BINNING_EDGEVECTOR_H
Euclid::Histogram::Binning::EdgeVector::getBinIndex
ssize_t getBinIndex(VarType value) const final
Definition: EdgeVector.h:60
std::pair
std::vector< VarType >
std::find_if
T find_if(T... args)
std::vector::size
T size(T... args)
std::vector::back
T back(T... args)
Euclid::Histogram::Binning::EdgeVector::getEdge
VarType getEdge(size_t i) const final
Definition: EdgeVector.h:73
std::vector::front
T front(T... args)
Euclid::Histogram::Binning::EdgeVector::getBinEdges
std::pair< VarType, VarType > getBinEdges(size_t i) const final
Definition: EdgeVector.h:69
Euclid::Histogram::Binning::EdgeVector::EdgeVector
EdgeVector(const EdgeVector &)=default
Euclid::Histogram::BinStrategy::m_nbins
size_t m_nbins
Definition: Histogram.h:127
Euclid::Histogram::Binning::EdgeVector::EdgeVector
EdgeVector(EdgeVector &&)=default
Histogram.h
std::vector::begin
T begin(T... args)
std
STL namespace.
Euclid::Histogram::Binning::EdgeVector::m_edges
std::vector< VarType > m_edges
Definition: EdgeVector.h:79
Euclid::Histogram::Binning::EdgeVector::~EdgeVector
virtual ~EdgeVector()=default
std::make_pair
T make_pair(T... args)
std::vector::end
T end(T... args)
Euclid::Histogram::Binning::EdgeVector::EdgeVector
EdgeVector(Args &&... args)
Definition: EdgeVector.h:54
Euclid::Histogram::Binning::EdgeVector
Definition: EdgeVector.h:47
Euclid
Definition: InstOrRefHolder.h:29
Euclid::Histogram::BinStrategy
Definition: Histogram.h:49