Alexandria  2.22.0
Please provide a description of the project.
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>
76  : public std::iterator<std::forward_iterator_tag,
77  typename std::conditional<Const, const FluxErrorPair, FluxErrorPair>::type> {
78  public:
82 
87 
91  PhotometryIterator(const PhotometryIterator<false>& other); // cppcheck-suppress noExplicitConstructor
92 
97 
101  bool operator==(const PhotometryIterator& other) const;
102 
106  bool operator!=(const PhotometryIterator& other) const;
107 
111  reference operator*();
112 
116  pointer operator->();
117 
121  ssize_t operator-(const PhotometryIterator& other) const;
122 
126  const std::string& filterName() const;
127 
128  protected:
136  PhotometryIterator(const filters_iter_t& filters_iter, const values_iter_t& values_iter);
137 
138  friend class Photometry;
139 
140  private:
143  };
144 
147 
159  : m_filter_name_vector_ptr(filter_name_vector_ptr), m_value_vector(std::move(value_vector)) {
160  if (m_filter_name_vector_ptr == nullptr) {
161  throw Elements::Exception() << "Photometry filter names vector pointer is null";
162  }
163  // Only check the size, but not the consistency
164  if (m_filter_name_vector_ptr->size() != m_value_vector.size()) {
165  throw Elements::Exception() << "Photometry filter names vector has different size than the values vector";
166  }
167  }
168 
170  virtual ~Photometry() = default;
171 
173  return const_iterator{m_filter_name_vector_ptr->cbegin(), m_value_vector.cbegin()};
174  }
175 
177  return const_iterator{m_filter_name_vector_ptr->cend(), m_value_vector.cend()};
178  }
179 
181  return const_iterator{m_filter_name_vector_ptr->cbegin(), m_value_vector.cbegin()};
182  }
183 
184  const_iterator end() const {
185  return const_iterator{m_filter_name_vector_ptr->cend(), m_value_vector.cend()};
186  }
187 
189  return iterator{m_filter_name_vector_ptr->begin(), m_value_vector.begin()};
190  }
191 
193  return iterator{m_filter_name_vector_ptr->end(), m_value_vector.end()};
194  }
195 
200  std::size_t size() const {
201  return m_filter_name_vector_ptr->size();
202  }
203 
213  std::unique_ptr<FluxErrorPair> find(const std::string& filter_name) const;
214 
215  const std::shared_ptr<std::vector<std::string>>& getFilterNames() const;
216 
217 private:
220 
223 };
224 // Eof class Photometry
225 
226 #define PHOTOMETRY_IMPL
228 #undef PHOTOMETRY_IMPL
229 
230 } /* namespace SourceCatalog */
231 } // end of namespace Euclid
232 
233 #endif /* PHOTOMETRY_H_ */
Attribute interface extended by all source attributes.
Definition: Attribute.h:41
typename std::conditional< Const, std::vector< FluxErrorPair >::const_iterator, std::vector< FluxErrorPair >::iterator >::type values_iter_t
Definition: Photometry.h:86
PhotometryIterator(const filters_iter_t &filters_iter, const values_iter_t &values_iter)
typename std::conditional< Const, std::vector< std::string >::const_iterator, std::vector< std::string >::iterator >::type filters_iter_t
Definition: Photometry.h:84
bool operator==(const PhotometryIterator &other) const
PhotometryIterator(const PhotometryIterator< false > &other)
ssize_t operator-(const PhotometryIterator &other) const
typename std::conditional< Const, const FluxErrorPair, FluxErrorPair >::type value_t
Definition: Photometry.h:79
bool operator!=(const PhotometryIterator &other) const
const_iterator cend() const
Definition: Photometry.h:176
const_iterator cbegin() const
Definition: Photometry.h:172
std::shared_ptr< std::vector< std::string > > m_filter_name_vector_ptr
Shared pointer to the common list of filter names.
Definition: Photometry.h:219
PhotometryIterator< false > iterator
Definition: Photometry.h:146
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:158
std::vector< FluxErrorPair > m_value_vector
The photometry map.
Definition: Photometry.h:222
const_iterator end() const
Definition: Photometry.h:184
PhotometryIterator< true > const_iterator
Definition: Photometry.h:145
std::size_t size() const
Return the size of the photometry map.
Definition: Photometry.h:200
virtual ~Photometry()=default
default destructor
const_iterator begin() const
Definition: Photometry.h:180
#define ELEMENTS_API
STL namespace.
bool operator==(const FluxErrorPair &other) const
FluxErrorPair(double flux, double error, bool missing_photometry_flag=false, bool upper_limit_flag=false)
bool operator!=(const FluxErrorPair &other) const
FluxErrorPair(const FluxErrorPair &)=default