Alexandria  2.19
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Photometry.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 
26 #ifndef PHOTOMETRY_H_
27 #define PHOTOMETRY_H_
28 
29 #include <iterator>
30 #include <memory>
31 #include <vector>
32 
34 #include "ElementsKernel/Export.h"
35 
37 
38 namespace Euclid {
39 namespace SourceCatalog {
40 
41 struct FluxErrorPair {
42  double flux;
43  double error;
46  FluxErrorPair(double flux, double error, bool missing_photometry_flag = false, bool upper_limit_flag = false);
47  FluxErrorPair(const FluxErrorPair&) = default;
48  bool operator==(const FluxErrorPair& other) const;
49  bool operator!=(const FluxErrorPair& other) const;
50 };
51 
67 
68 public:
74  template <bool Const>
75  class PhotometryIterator : public std::iterator<std::forward_iterator_tag,
76  typename std::conditional<Const, const FluxErrorPair, FluxErrorPair>::type> {
77  public:
81 
82  using filters_iter_t =
84  using values_iter_t =
86 
91 
95  PhotometryIterator& operator++();
96 
100  bool operator==(const PhotometryIterator& other) const;
101 
105  bool operator!=(const PhotometryIterator& other) const;
106 
110  reference operator*();
111 
115  pointer operator->();
116 
120  ssize_t operator-(const PhotometryIterator& other) const;
121 
125  const std::string& filterName() const;
126 
127  protected:
135  PhotometryIterator(const filters_iter_t& filters_iter, const values_iter_t& values_iter);
136 
137  friend class Photometry;
138 
139  private:
142  };
143 
146 
158  : m_filter_name_vector_ptr(filter_name_vector_ptr), m_value_vector(std::move(value_vector)) {
159  if (m_filter_name_vector_ptr == nullptr) {
160  throw Elements::Exception() << "Photometry filter names vector pointer is null";
161  }
162  // Only check the size, but not the consistency
163  if (m_filter_name_vector_ptr->size() != m_value_vector.size()) {
164  throw Elements::Exception() << "Photometry filter names vector has different size than the values vector";
165  }
166  }
167 
169  virtual ~Photometry() = default;
170 
172  return const_iterator{m_filter_name_vector_ptr->cbegin(), m_value_vector.cbegin()};
173  }
174 
176  return const_iterator{m_filter_name_vector_ptr->cend(), m_value_vector.cend()};
177  }
178 
180  return const_iterator{m_filter_name_vector_ptr->cbegin(), m_value_vector.cbegin()};
181  }
182 
183  const_iterator end() const {
184  return const_iterator{m_filter_name_vector_ptr->cend(), m_value_vector.cend()};
185  }
186 
188  return iterator{m_filter_name_vector_ptr->begin(), m_value_vector.begin()};
189  }
190 
192  return iterator{m_filter_name_vector_ptr->end(), m_value_vector.end()};
193  }
194 
199  std::size_t size() const {
200  return m_filter_name_vector_ptr->size();
201  }
202 
212  std::unique_ptr<FluxErrorPair> find(const std::string& filter_name) const;
213 
214  const std::shared_ptr<std::vector<std::string>>& getFilterNames() const;
215 
216 private:
219 
222 };
223 // Eof class Photometry
224 
225 #define PHOTOMETRY_IMPL
227 #undef PHOTOMETRY_IMPL
228 
229 } /* namespace SourceCatalog */
230 } // end of namespace Euclid
231 
232 #endif /* PHOTOMETRY_H_ */
const_iterator cbegin() const
Definition: Photometry.h:171
const_iterator end() const
Definition: Photometry.h:183
Attribute interface extended by all source attributes.
Definition: Attribute.h:41
Photometry(std::shared_ptr< std::vector< std::string >> filter_name_vector_ptr, std::vector< FluxErrorPair > value_vector)
Constructor which should never be called directly. Use the PhotometryAttributeHandler to build Photom...
Definition: Photometry.h:157
PhotometryIterator< false > iterator
Definition: Photometry.h:145
FluxErrorPair(double flux, double error, bool missing_photometry_flag=false, bool upper_limit_flag=false)
typename std::conditional< Const, std::vector< FluxErrorPair >::const_iterator, std::vector< FluxErrorPair >::iterator >::type values_iter_t
Definition: Photometry.h:85
typename std::conditional< Const, const FluxErrorPair, FluxErrorPair >::type value_t
Definition: Photometry.h:78
bool operator!=(const Euclid::SourceCatalog::Source::id_type &a, const Euclid::SourceCatalog::Source::id_type &b)
boost::variant specifies an equality operator (==), but, in older boost versions, not an inequality o...
Definition: Source.h:145
const_iterator begin() const
Definition: Photometry.h:179
std::size_t size() const
Return the size of the photometry map.
Definition: Photometry.h:199
STL class.
#define ELEMENTS_API
PhotometryIterator< true > const_iterator
Definition: Photometry.h:144
typename std::conditional< Const, std::vector< std::string >::const_iterator, std::vector< std::string >::iterator >::type filters_iter_t
Definition: Photometry.h:83
bool operator==(const FluxErrorPair &other) const
STL class.
STL class.
std::shared_ptr< std::vector< std::string > > m_filter_name_vector_ptr
Shared pointer to the common list of filter names.
Definition: Photometry.h:218
std::vector< FluxErrorPair > m_value_vector
The photometry map.
Definition: Photometry.h:221
const_iterator cend() const
Definition: Photometry.h:175
bool operator!=(const FluxErrorPair &other) const