Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
EdgeVector.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012-2021 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
32namespace Euclid {
33namespace Histogram {
34namespace Binning {
35
46template <typename VarType>
47class EdgeVector : public BinStrategy<VarType> {
48public:
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
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
77private:
78 using BinStrategy<VarType>::m_nbins;
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
T back(T... args)
T begin(T... args)
ssize_t getBinIndex(VarType value) const final
Definition EdgeVector.h:60
VarType getEdge(size_t i) const final
Definition EdgeVector.h:73
std::pair< VarType, VarType > getBinEdges(size_t i) const final
Definition EdgeVector.h:69
EdgeVector(const EdgeVector &)=default
T end(T... args)
T find_if(T... args)
T front(T... args)
T make_pair(T... args)
STL namespace.
T size(T... args)