Alexandria  2.25.0
SDC-CH common library for the Euclid project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SpectroscopicRedshiftAttributeFromRow.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 SPECTROSCOPICATTRIBUTEFROMROW_H_
27 #define SPECTROSCOPICATTRIBUTEFROMROW_H_
28 #include <map>
29 #include <memory>
30 #include <string>
31 #include <utility>
32 
33 #include "ElementsKernel/Logging.h"
35 #include "SourceCatalog/Catalog.h"
36 #include "Table/CastVisitor.h"
37 #include "Table/Table.h"
38 
39 namespace Euclid {
40 namespace SourceCatalog {
41 
42 static Elements::Logging logger = Elements::Logging::getLogger("SpectroscopicRedshiftAttributeFromRow");
43 
53 public:
75  const std::string& specz_value_column_name,
76  const std::string& specz_error_column_name) {
77 
78  std::unique_ptr<size_t> specz_value_column_index_ptr = column_info_ptr->find(specz_value_column_name);
79  if (specz_value_column_index_ptr == nullptr) {
80  throw Elements::Exception() << "Column info does not have the spectroscopic redshift value column!";
81  }
82 
83  std::unique_ptr<size_t> specz_error_column_index_ptr = column_info_ptr->find(specz_error_column_name);
84  if (specz_error_column_index_ptr == nullptr) {
85  throw Elements::Exception() << "Column info does not have the spectroscopic redshift error column!";
86  }
87 
88  m_has_error_column = true;
89  m_error_column_index = *(specz_error_column_index_ptr);
90  m_value_column_index = *(specz_value_column_index_ptr);
91  }
92 
111  const std::string& specz_value_column_name) {
112 
113  std::unique_ptr<size_t> specz_value_column_index_ptr = column_info_ptr->find(specz_value_column_name);
114  if (specz_value_column_index_ptr == nullptr) {
115  throw Elements::Exception() << "Column info does not have the spectroscopic redshift value column!";
116  }
117 
118  m_has_error_column = false;
120  m_value_column_index = *(specz_value_column_index_ptr);
121 
122  // Log a warning as row is set to zero
123  logger.warn() << "specz error values are set to zero by default! ";
124  }
125 
127 
135  double z = boost::apply_visitor(Table::CastVisitor<double>{}, row[m_value_column_index]);
136  double e = 0.;
137  if (m_has_error_column) {
138  e = boost::apply_visitor(Table::CastVisitor<double>{}, row[m_error_column_index]);
139  }
141  }
142 
143 private:
150 };
151 
152 } // namespace SourceCatalog
153 } // end of namespace Euclid
154 
155 #endif // SPECTROSCOPICATTRIBUTEFROMROW_H_
SpectroscopicRedshiftAttributeFromRow(std::shared_ptr< Euclid::Table::ColumnInfo > column_info_ptr, const std::string &specz_value_column_name)
Create a SpectroscopicRedshiftAttributeFromRow object.
STL class.
std::unique_ptr< Attribute > createAttribute(const Euclid::Table::Row &row) override
Create a photometricAttribute from a Table row.
Implementation of the AttributeFromRow for a SpectroscopicRedshift attribute. This class implements t...
constexpr double e
SpectroscopicRedshiftAttributeFromRow(std::shared_ptr< Euclid::Table::ColumnInfo > column_info_ptr, const std::string &specz_value_column_name, const std::string &specz_error_column_name)
Create a SpectroscopicRedshiftAttributeFromRow object.
void warn(const std::string &logMessage)
Interface for building a source Attribute from a table Row.
Represents one row of a Table.
Definition: Row.h:64
STL class.
static Logging getLogger(const std::string &name="")
Store the spectroscopic redshift of a source.