Alexandria  2.19
Please provide a description of the 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, const std::string& specz_error_column_name) {
76 
77  std::unique_ptr<size_t> specz_value_column_index_ptr = column_info_ptr->find(specz_value_column_name);
78  if (specz_value_column_index_ptr == nullptr) {
79  throw Elements::Exception() << "Column info does not have the spectroscopic redshift value column!";
80  }
81 
82  std::unique_ptr<size_t> specz_error_column_index_ptr = column_info_ptr->find(specz_error_column_name);
83  if (specz_error_column_index_ptr == nullptr) {
84  throw Elements::Exception() << "Column info does not have the spectroscopic redshift error column!";
85  }
86 
87  m_has_error_column = true;
88  m_error_column_index = *(specz_error_column_index_ptr);
89  m_value_column_index = *(specz_value_column_index_ptr);
90  }
91 
110  const std::string& specz_value_column_name) {
111 
112  std::unique_ptr<size_t> specz_value_column_index_ptr = column_info_ptr->find(specz_value_column_name);
113  if (specz_value_column_index_ptr == nullptr) {
114  throw Elements::Exception() << "Column info does not have the spectroscopic redshift value column!";
115  }
116 
117  m_has_error_column = false;
119  m_value_column_index = *(specz_value_column_index_ptr);
120 
121  // Log a warning as row is set to zero
122  logger.warn() << "specz error values are set to zero by default! ";
123  }
124 
126 
134  double z = boost::apply_visitor(Table::CastVisitor<double>{}, row[m_value_column_index]);
135  double e = 0.;
136  if (m_has_error_column) {
137  e = boost::apply_visitor(Table::CastVisitor<double>{}, row[m_error_column_index]);
138  }
140  }
141 
142 private:
149 };
150 
151 } // namespace SourceCatalog
152 } // end of namespace Euclid
153 
154 #endif // SPECTROSCOPICATTRIBUTEFROMROW_H_
SpectroscopicRedshiftAttributeFromRow(std::shared_ptr< Euclid::Table::ColumnInfo > column_info_ptr, const std::string &specz_value_column_name)
Create a SpectroscopicRedshiftAttributeFromRow object.
constexpr double e
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...
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.