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