Alexandria 2.31.0
SDC-CH common library for the Euclid project
|
Configuration class for enabling catalog input. More...
#include <CatalogConfig.h>
Public Types | |
using | TableToCatalogConverter = std::function< SourceCatalog::Catalog(const Table::Table &)> |
![]() | |
enum class | State { CONSTRUCTED , PRE_INITIALIZED , INITIALIZED , FINAL } |
Defines the different states the configuration object can be in. More... | |
using | OptionDescriptionList = std::vector< boost::program_options::option_description > |
using | UserValues = std::map< std::string, boost::program_options::variable_value > |
Public Member Functions | |
CatalogConfig (long manager_id) | |
Constructs a new CatalogConfig object. | |
virtual | ~CatalogConfig ()=default |
Destructor. | |
std::map< std::string, OptionDescriptionList > | getProgramOptions () override |
Returns the program options defined by the CatalogConfig. | |
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 |
Initializes the CatalogConfig instance. | |
void | setBaseDir (const boost::filesystem::path &base_dir) |
Sets the directory used when resolving relative paths. | |
void | addAttributeHandler (std::shared_ptr< SourceCatalog::AttributeFromRow > handler) |
Adds an attribute handler which will be used for adding attributes at the catalog objects. | |
std::unique_ptr< Table::TableReader > | getTableReader () const |
std::shared_ptr< Table::ColumnInfo > | getColumnInfo () const |
std::string | getIdColumn () const |
TableToCatalogConverter | getTableToCatalogConverter () const |
Table::Table | readAsTable () const |
Returns the catalog as a Table::Table object. | |
SourceCatalog::Catalog | readAsCatalog () const |
Returns the Catalog object. | |
const boost::filesystem::path & | getFilename () const |
Returns the filename of the input catalog. | |
![]() | |
Configuration (long manager_id) | |
Constructs a new Configuration instance. | |
virtual | ~Configuration ()=default |
Destructor. | |
virtual void | postInitialize (const UserValues &args) |
Method which is called after the initialization phase. | |
const std::set< std::type_index > & | getDependencies () |
Returns the dependencies of the configuration. | |
State & | getCurrentState () |
Returns the current state of the configuration. | |
State | getCurrentState () const |
Returns the current state of the configuration. | |
Private Attributes | |
boost::filesystem::path | m_base_dir |
boost::filesystem::path | m_filename |
bool | m_fits_format = true |
std::string | m_id_column_name |
std::vector< std::shared_ptr< SourceCatalog::AttributeFromRow > > | m_attribute_handlers |
std::shared_ptr< Table::ColumnInfo > | m_column_info |
Additional Inherited Members | |
![]() | |
template<typename T > | |
void | declareDependency () |
Declares a Configuration as dependency. | |
template<typename T > | |
T & | getDependency () |
Returns a dependency. | |
template<typename T > | |
const T & | getDependency () const |
Configuration class for enabling catalog input.
The CatalogConfiguration class provides the basis for reading input catalogs. It provides all the functionality for reading an input catalog as an object of type Table::Table (using the method readAsTable() ) or of type SourceCatalog::Catalog (using the method readAsCatalog() ). For performing partial reading of the catalog the methods getTableReader() and getTableToCatalogConverter() can be used instead.
Any other configurations (like catalog specific configurations) can use the getColumnInfo() method to retrieve the table column information, after the CatalogConfig has been initialized.
Because this is a generic class, it has no knowledge of the specific catalog attributes. By default it does not use any attribute handlers and it only parses the ID of the catalog entries. The more specific catalog configurations (for example coordinates catalog), should declare the CatalogConfig as a dependency and they should add an attribute handler during the initialize phase. The more specific catalog configuration classes can use the getColumnInfo() method to get the catalog columns information (if needed).
Definition at line 66 of file CatalogConfig.h.
using Euclid::Configuration::CatalogConfig::TableToCatalogConverter = std::function<SourceCatalog::Catalog(const Table::Table&)> |
A function that converts objects of type Table::Table to objects of type SourceCatalog::Catalog
Definition at line 71 of file CatalogConfig.h.
|
explicit |
Constructs a new CatalogConfig object.
Definition at line 46 of file CatalogConfig.cpp.
|
virtualdefault |
Destructor.
void Euclid::Configuration::CatalogConfig::addAttributeHandler | ( | std::shared_ptr< SourceCatalog::AttributeFromRow > | handler | ) |
Adds an attribute handler which will be used for adding attributes at the catalog objects.
This method can be called by other configuration classes before the post- initialization phase, to add extra attributes to the catalog.
handler | The AttributeHandler to add |
Elements::Exception | If the CatalogConfig instance has already been finalized |
Definition at line 171 of file CatalogConfig.cpp.
References Euclid::Configuration::Configuration::FINAL, Euclid::Configuration::Configuration::getCurrentState(), and m_attribute_handlers.
std::shared_ptr< Table::ColumnInfo > Euclid::Configuration::CatalogConfig::getColumnInfo | ( | ) | const |
Definition at line 185 of file CatalogConfig.cpp.
References Euclid::Configuration::Configuration::getCurrentState(), Euclid::Configuration::Configuration::INITIALIZED, and m_column_info.
const boost::filesystem::path & Euclid::Configuration::CatalogConfig::getFilename | ( | ) | const |
Returns the filename of the input catalog.
This method can be called only on instances of CatalogConfig which are finalized.
Elements::Exception | If the instance is not yet final |
Definition at line 239 of file CatalogConfig.cpp.
References Euclid::Configuration::Configuration::getCurrentState(), Euclid::Configuration::Configuration::INITIALIZED, and m_filename.
std::string Euclid::Configuration::CatalogConfig::getIdColumn | ( | ) | const |
Definition at line 192 of file CatalogConfig.cpp.
References m_id_column_name.
|
overridevirtual |
Returns the program options defined by the CatalogConfig.
These options are:
All options are in a group called "Input catalog options".
Reimplemented from Euclid::Configuration::Configuration.
Definition at line 48 of file CatalogConfig.cpp.
References std::string::c_str(), Euclid::Configuration::INPUT_CATALOG_FILE, Euclid::Configuration::INPUT_CATALOG_FORMAT, Euclid::Configuration::SOURCE_ID_COLUMN_INDEX, and Euclid::Configuration::SOURCE_ID_COLUMN_NAME.
std::unique_ptr< Table::TableReader > Euclid::Configuration::CatalogConfig::getTableReader | ( | ) | const |
Definition at line 178 of file CatalogConfig.cpp.
References Euclid::Configuration::Configuration::FINAL, Euclid::Configuration::Configuration::getCurrentState(), m_filename, and m_fits_format.
Referenced by readAsTable().
CatalogConfig::TableToCatalogConverter Euclid::Configuration::CatalogConfig::getTableToCatalogConverter | ( | ) | const |
Definition at line 215 of file CatalogConfig.cpp.
References Euclid::Configuration::Configuration::FINAL, Euclid::Configuration::Configuration::getCurrentState(), m_attribute_handlers, m_column_info, and m_id_column_name.
Referenced by readAsCatalog().
|
overridevirtual |
Initializes the CatalogConfig instance.
args | The user parameters |
Elements::Exception | If there is any I/O error with reading the input-catalog-file |
Elements::Exception | If the file has wrong format type |
Elements::Exception | If the given file has no ID column, as described by the source-id-column-name and source-id-column-index parameters |
Elements::Exception | If there is any I/O error with reading the input-catalog-file |
Reimplemented from Euclid::Configuration::Configuration.
Definition at line 157 of file CatalogConfig.cpp.
References m_base_dir, m_column_info, m_filename, m_fits_format, and m_id_column_name.
|
overridevirtual |
Checks that all the options are valid. See the exceptions thrown for a detailed list of the checks.
args | The user parameters |
Elements::Exception | If both the source-id-column-name and source-id-column-index are given |
Elements::Exception | If the source-id-column-index is an invalid one-based index (less than 1) |
Elements::Exception | If the input-catalog-format is not one of AUTO, FITS or ASCII |
Reimplemented from Euclid::Configuration::Configuration.
Definition at line 58 of file CatalogConfig.cpp.
References std::map< K, T >::at(), std::map< K, T >::end(), std::map< K, T >::find(), Euclid::Configuration::INPUT_CATALOG_FORMAT, Euclid::Configuration::SOURCE_ID_COLUMN_INDEX, and Euclid::Configuration::SOURCE_ID_COLUMN_NAME.
SourceCatalog::Catalog Euclid::Configuration::CatalogConfig::readAsCatalog | ( | ) | const |
Returns the Catalog object.
This method can be called to read and retrieve the catalog as a Catalog object. It is a convenience method alternative from using the getTableReader() and getTableToCatalogConverter() methods Note that this method is going to read the full catalog each time it is called.
Elements::Exception | If the instance is not yet final |
Elements::Exception | If there is any I/O error with reading the input-catalog-file |
Elements::Exception | If the file has wrong format type |
Elements::Exception | If any of the registered attribute handlers fails |
Definition at line 230 of file CatalogConfig.cpp.
References Euclid::Configuration::Configuration::FINAL, Euclid::Configuration::Configuration::getCurrentState(), getTableToCatalogConverter(), and readAsTable().
Table::Table Euclid::Configuration::CatalogConfig::readAsTable | ( | ) | const |
Returns the catalog as a Table::Table object.
This method can be called to read and retrieve the catalog as a Table::Table object. When this method is called the information from the attribute handlers is ignored and each row contains all the columns from the file. Note that this method is going to read the full catalog each time it is called.
Elements::Exception | If the instance is not yet final |
Elements::Exception | If there is any I/O error with reading the input-catalog-file |
Elements::Exception | If the file has wrong format type |
Elements::Exception | If any of the registered attribute handlers fails |
Definition at line 222 of file CatalogConfig.cpp.
References Euclid::Configuration::Configuration::FINAL, Euclid::Configuration::Configuration::getCurrentState(), getTableReader(), Elements::Logging::info(), Euclid::Configuration::logger, and m_filename.
Referenced by readAsCatalog().
void Euclid::Configuration::CatalogConfig::setBaseDir | ( | const boost::filesystem::path & | base_dir | ) |
Sets the directory used when resolving relative paths.
This method can be called by other Configuration classes during the pre- initialization phase. By default the current working directory is used.
base_dir | The directory to use for resolving relative paths |
Elements::Exception | If the CatalogConfig instance has already been initialized |
Definition at line 164 of file CatalogConfig.cpp.
References Euclid::Configuration::Configuration::getCurrentState(), Euclid::Configuration::Configuration::INITIALIZED, and m_base_dir.
|
private |
Definition at line 251 of file CatalogConfig.h.
Referenced by addAttributeHandler(), and getTableToCatalogConverter().
|
private |
Definition at line 247 of file CatalogConfig.h.
Referenced by initialize(), and setBaseDir().
|
private |
Definition at line 252 of file CatalogConfig.h.
Referenced by getColumnInfo(), getTableToCatalogConverter(), and initialize().
|
private |
Definition at line 248 of file CatalogConfig.h.
Referenced by getFilename(), getTableReader(), initialize(), and readAsTable().
|
private |
Definition at line 249 of file CatalogConfig.h.
Referenced by getTableReader(), and initialize().
|
private |
Definition at line 250 of file CatalogConfig.h.
Referenced by getIdColumn(), getTableToCatalogConverter(), and initialize().