Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
SpecZCatalogConfig.cpp
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
29
30namespace po = boost::program_options;
31
32namespace Euclid {
33namespace Configuration {
34
35static const std::string SPECZ_COLUMN_NAME{"spec-z-column-name"};
36static const std::string SPECZ_COLUMN_INDEX{"spec-z-column-index"};
37static const std::string SPECZ_ERR_COLUMN_NAME{"spec-z-err-column-name"};
38static const std::string SPECZ_ERR_COLUMN_INDEX{"spec-z-err-column-index"};
39
41 declareDependency<CatalogConfig>();
42}
43
45 return {{"Input catalog options",
46 {{SPECZ_COLUMN_NAME.c_str(), po::value<std::string>(),
47 "The name of the column representing the spectroscopic redshift"},
48 {SPECZ_COLUMN_INDEX.c_str(), po::value<int>(),
49 "The 1-based index of the column representing the spectroscopic redshift"},
50 {SPECZ_ERR_COLUMN_NAME.c_str(), po::value<std::string>(),
51 "The name of the column representing spectroscopic redshift error"},
52 {SPECZ_ERR_COLUMN_INDEX.c_str(), po::value<int>(),
53 "The 1-based index of the column representing the spectroscopic redshift error"}}}};
54}
55
57 if (args.find(SPECZ_COLUMN_NAME) != args.end() && args.find(SPECZ_COLUMN_INDEX) != args.end()) {
58 throw Elements::Exception() << "Options " << SPECZ_COLUMN_NAME << " and " << SPECZ_COLUMN_INDEX
59 << " are mutually exclusive";
60 }
61 if (args.find(SPECZ_COLUMN_NAME) == args.end() && args.find(SPECZ_COLUMN_INDEX) == args.end()) {
62 throw Elements::Exception() << "One of the options " << SPECZ_COLUMN_NAME << " and " << SPECZ_COLUMN_INDEX
63 << " must be given";
64 }
65 if (args.find(SPECZ_COLUMN_INDEX) != args.end() && args.at(SPECZ_COLUMN_INDEX).as<int>() < 1) {
66 throw Elements::Exception() << SPECZ_COLUMN_INDEX << " must be a one-based "
67 << "index but was " << args.at(SPECZ_COLUMN_INDEX).as<int>();
68 }
69 if (args.find(SPECZ_ERR_COLUMN_NAME) != args.end() && args.find(SPECZ_ERR_COLUMN_INDEX) != args.end()) {
70 throw Elements::Exception() << "Options " << SPECZ_ERR_COLUMN_NAME << " and " << SPECZ_ERR_COLUMN_INDEX
71 << " are mutually exclusive";
72 }
73 if (args.find(SPECZ_ERR_COLUMN_INDEX) != args.end() && args.at(SPECZ_ERR_COLUMN_INDEX).as<int>() < 1) {
74 throw Elements::Exception() << SPECZ_ERR_COLUMN_INDEX << " must be a one-based "
75 << "index but was " << args.at(SPECZ_ERR_COLUMN_INDEX).as<int>();
76 }
77}
78
80 const Table::ColumnInfo& column_info) {
81 if (args.find(SPECZ_COLUMN_NAME) != args.end()) {
83 if (column_info.find(name) == nullptr) {
84 throw Elements::Exception() << "Input catalog file does not contain the "
85 << " SpecZ column with name " << name;
86 }
87 return name;
88 } else {
89 std::size_t index = args.at(SPECZ_COLUMN_INDEX).as<int>();
90 if (index > column_info.size()) {
91 throw Elements::Exception() << SPECZ_COLUMN_INDEX << " (" << index << ") is out of range (" << column_info.size()
92 << ")";
93 }
94 return column_info.getDescription(index - 1).name;
95 }
96}
97
99 const Table::ColumnInfo& column_info) {
100 if (args.find(SPECZ_ERR_COLUMN_NAME) != args.end()) {
102 if (column_info.find(name) == nullptr) {
103 throw Elements::Exception() << "Input catalog file does not contain the "
104 << " SpecZ error column with name " << name;
105 }
106 return name;
107 } else {
108 std::size_t index = args.at(SPECZ_ERR_COLUMN_INDEX).as<int>();
109 if (index > column_info.size()) {
110 throw Elements::Exception() << SPECZ_ERR_COLUMN_INDEX << " (" << index << ") is out of range ("
111 << column_info.size() << ")";
112 }
113 return column_info.getDescription(index - 1).name;
114 }
115}
116
118 auto column_info = getDependency<CatalogConfig>().getColumnInfo();
119
120 std::string flux_column = getFluxColumnFromOptions(args, *column_info);
121
123
124 if (args.find(SPECZ_ERR_COLUMN_NAME) == args.end() && args.find(SPECZ_ERR_COLUMN_INDEX) == args.end()) {
125 handler_ptr.reset(new SourceCatalog::SpectroscopicRedshiftAttributeFromRow{column_info, flux_column});
126 } else {
127 std::string err_column = getErrColumnFromOptions(args, *column_info);
128 handler_ptr.reset(new SourceCatalog::SpectroscopicRedshiftAttributeFromRow{column_info, flux_column, err_column});
129 }
130
131 getDependency<CatalogConfig>().addAttributeHandler(handler_ptr);
132}
133
134} // namespace Configuration
135} // namespace Euclid
T at(T... args)
T c_str(T... args)
Superclass of all configuration classes.
void preInitialize(const UserValues &args) override
Checks that all the options are valid. See the exceptions thrown for a detailed list of the checks.
void initialize(const UserValues &args) override
Adds the SpectroscopicRedshiftAttributeFromRow handler to the CatalogCnofig.
std::map< std::string, OptionDescriptionList > getProgramOptions() override
Returns the program options defined by the SpecZCatalogConfig.
SpecZCatalogConfig(long manager_id)
Constructs a new SpecZCatalogConfig object.
Implementation of the AttributeFromRow for a SpectroscopicRedshift attribute. This class implements t...
Provides information about the columns of a Table.
Definition ColumnInfo.h:52
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.
const ColumnDescription & getDescription(std::size_t index) const
Returns the description of the column with the given index or throws an exception if the index is big...
std::size_t size() const
Returns the number of columns represented by this ColumnInfo.
T end(T... args)
T find(T... args)
static const std::string SPECZ_COLUMN_NAME
static const std::string SPECZ_ERR_COLUMN_NAME
static std::string getFluxColumnFromOptions(const Configuration::UserValues &args, const Table::ColumnInfo &column_info)
static std::string getErrColumnFromOptions(const Configuration::UserValues &args, const Table::ColumnInfo &column_info)
static const std::string SPECZ_COLUMN_INDEX
static const std::string SPECZ_ERR_COLUMN_INDEX
T reset(T... args)