Alexandria  2.14.1
Please provide a description of the project.
SpectroscopicRedshiftAttributeFromRow.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2020 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 <utility>
30 #include <string>
31 #include <memory>
32 
33 #include "ElementsKernel/Logging.h"
35 #include "SourceCatalog/Catalog.h"
36 #include "Table/Table.h"
37 #include "Table/CastVisitor.h"
38 
39 using namespace Euclid::SourceCatalog;
40 using namespace std;
41 
42 namespace Euclid {
43 namespace SourceCatalog {
44 
45 static Elements::Logging logger = Elements::Logging::getLogger("SpectroscopicRedshiftAttributeFromRow");
46 
56 public:
78  const std::string& specz_value_column_name,
79  const std::string& specz_error_column_name) {
80 
81  unique_ptr<size_t> specz_value_column_index_ptr = column_info_ptr->find(specz_value_column_name);
82  if (specz_value_column_index_ptr == nullptr) {
83  throw Elements::Exception() << "Column info does not have the spectroscopic redshift value column!";
84  }
85 
86  unique_ptr<size_t> specz_error_column_index_ptr = column_info_ptr->find(specz_error_column_name);
87  if (specz_error_column_index_ptr == nullptr) {
88  throw Elements::Exception() << "Column info does not have the spectroscopic redshift error column!";
89  }
90 
91  m_has_error_column=true;
92  m_error_column_index = *(specz_error_column_index_ptr);
93  m_value_column_index = *(specz_value_column_index_ptr);
94 
95  }
96 
115  const std::string& specz_value_column_name) {
116 
117  unique_ptr<size_t> specz_value_column_index_ptr = column_info_ptr->find(specz_value_column_name);
118  if (specz_value_column_index_ptr == nullptr) {
119  throw Elements::Exception() << "Column info does not have the spectroscopic redshift value column!";
120  }
121 
122  m_has_error_column=false;
123  m_error_column_index = 0;
124  m_value_column_index = *(specz_value_column_index_ptr);
125 
126  // Log a warning as row is set to zero
127  logger.warn() << "specz error values are set to zero by default! ";
128  }
129 
131 
132  }
133 
141  double z = boost::apply_visitor(Table::CastVisitor<double>{}, row[m_value_column_index]);
142  double e = 0.;
143  if (m_has_error_column) {
144  e = boost::apply_visitor(Table::CastVisitor<double>{}, row[m_error_column_index]);
145  }
147  }
148 
149 private:
156 
157 };
158 
159 
160 } // namespace SourceCatalog
161 } // end of namespace Euclid
162 
163 #endif // SPECTROSCOPICATTRIBUTEFROMROW_H_
std::string
STL class.
std::shared_ptr< Euclid::Table::ColumnInfo >
Euclid::SourceCatalog::SpectroscopicRedshiftAttributeFromRow::m_error_column_index
size_t m_error_column_index
Definition: SpectroscopicRedshiftAttributeFromRow.h:155
Euclid::SourceCatalog::SpectroscopicRedshiftAttributeFromRow::~SpectroscopicRedshiftAttributeFromRow
virtual ~SpectroscopicRedshiftAttributeFromRow()
Definition: SpectroscopicRedshiftAttributeFromRow.h:130
Elements::Logging
Euclid::SourceCatalog::SpectroscopicRedshift
Store the spectroscopic redshift of a source.
Definition: SpectroscopicRedshift.h:40
Euclid::SourceCatalog::SpectroscopicRedshiftAttributeFromRow::m_has_error_column
bool m_has_error_column
Definition: SpectroscopicRedshiftAttributeFromRow.h:154
CastVisitor.h
AttributeFromRow.h
Catalog.h
Euclid::SourceCatalog::SpectroscopicRedshiftAttributeFromRow::m_value_column_index
size_t m_value_column_index
Definition: SpectroscopicRedshiftAttributeFromRow.h:153
Elements::Logging::warn
void warn(const std::string &logMessage)
Elements::Exception
Euclid::SourceCatalog::logger
static Elements::Logging logger
Definition: SpectroscopicRedshiftAttributeFromRow.h:45
Euclid::SourceCatalog::SpectroscopicRedshiftAttributeFromRow::SpectroscopicRedshiftAttributeFromRow
SpectroscopicRedshiftAttributeFromRow(std::shared_ptr< Euclid::Table::ColumnInfo > column_info_ptr, const std::string &specz_value_column_name)
Create a SpectroscopicRedshiftAttributeFromRow object.
Definition: SpectroscopicRedshiftAttributeFromRow.h:114
e
constexpr double e
Euclid::SourceCatalog::AttributeFromRow
Interface for building a source Attribute from a table Row.
Definition: AttributeFromRow.h:45
Elements::Logging::getLogger
static Logging getLogger(const std::string &name="")
std
STL namespace.
Euclid::Table::Row
Represents one row of a Table.
Definition: Row.h:64
Euclid::SourceCatalog::SpectroscopicRedshiftAttributeFromRow
Implementation of the AttributeFromRow for a SpectroscopicRedshift attribute. This class implements t...
Definition: SpectroscopicRedshiftAttributeFromRow.h:55
Logging.h
Euclid::Table::CastVisitor< double >
Definition: CastVisitor.h:73
Euclid::SourceCatalog
Definition: SourceCatalog.dox:2
Euclid::Table::ColumnInfo::find
std::unique_ptr< std::size_t > find(const std::string &name) const
Returns the index of a column, given the name of it, or nullptr if there is no column with this name.
Definition: ColumnInfo.cpp:70
std::unique_ptr
STL class.
Euclid
Definition: InstOrRefHolder.h:29
Euclid::SourceCatalog::SpectroscopicRedshiftAttributeFromRow::SpectroscopicRedshiftAttributeFromRow
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.
Definition: SpectroscopicRedshiftAttributeFromRow.h:77
Table.h
Euclid::SourceCatalog::SpectroscopicRedshiftAttributeFromRow::createAttribute
std::unique_ptr< Attribute > createAttribute(const Euclid::Table::Row &row) override
Create a photometricAttribute from a Table row.
Definition: SpectroscopicRedshiftAttributeFromRow.h:140