29#include <CCfits/CCfits>
33namespace po = boost::program_options;
34namespace fs = boost::filesystem;
37namespace Configuration {
50 {
"Input catalog options",
53 "The format of the input catalog (AUTO, FITS or ASCII)"},
62 <<
" are mutually exclusive";
82 if (catalog_file.is_relative()) {
83 catalog_file = base_dir / catalog_file;
85 if (!fs::exists(catalog_file)) {
88 if (fs::is_directory(catalog_file)) {
94enum class FormatType { FITS, ASCII };
96FormatType autoDetectFormatType(fs::path file) {
97 logger.
info() <<
"Auto-detecting format of file " << file;
98 FormatType result = FormatType::ASCII;
102 in.read(first_header_array.
data(), 80);
103 first_header_array.
back() =
'\0';
106 if (first_header_str.compare(0, 9,
"SIMPLE =") == 0) {
107 result = FormatType::FITS;
110 logger.
info() <<
"Detected " << (result == FormatType::FITS ?
"FITS" :
"ASCII") <<
" format";
117 format = autoDetectFormatType(file);
119 format = FormatType::FITS;
121 format = FormatType::ASCII;
128 return Euclid::make_unique<Table::FitsReader>(filename.native(), 1);
130 return Euclid::make_unique<Table::AsciiReader>(filename.native());
138 if (column_info.find(id_column_name) ==
nullptr) {
140 <<
"ID column with name " << id_column_name;
145 if (index > column_info.size()) {
147 << column_info.size() <<
")";
149 id_column_name = column_info.getDescription(index - 1).name;
151 logger.
info() <<
"Using ID column \"" << id_column_name <<
'"';
152 return id_column_name;
203 :
m_converter(column_info, id_column_name,
std::move(attribute_handlers)) {}
217 throw Elements::Exception() <<
"getTableToCatalogConverter() call to not finalized CatalogConfig";
236 return converter(table);
SourceCatalog::CatalogFromTable m_converter
static Logging getLogger(const std::string &name="")
void info(const std::string &logMessage)
boost::filesystem::path m_filename
void addAttributeHandler(std::shared_ptr< SourceCatalog::AttributeFromRow > handler)
Adds an attribute handler which will be used for adding attributes at the catalog objects.
const boost::filesystem::path & getFilename() const
Returns the filename of the input catalog.
std::map< std::string, OptionDescriptionList > getProgramOptions() override
Returns the program options defined by the CatalogConfig.
Table::Table readAsTable() const
Returns the catalog as a Table::Table object.
CatalogConfig(long manager_id)
Constructs a new CatalogConfig object.
SourceCatalog::Catalog readAsCatalog() const
Returns the Catalog object.
std::shared_ptr< Table::ColumnInfo > m_column_info
TableToCatalogConverter getTableToCatalogConverter() const
std::unique_ptr< Table::TableReader > getTableReader() const
void setBaseDir(const boost::filesystem::path &base_dir)
Sets the directory used when resolving relative paths.
std::string getIdColumn() const
std::string m_id_column_name
std::vector< std::shared_ptr< SourceCatalog::AttributeFromRow > > m_attribute_handlers
boost::filesystem::path m_base_dir
std::shared_ptr< Table::ColumnInfo > getColumnInfo() const
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.
Superclass of all configuration classes.
State & getCurrentState()
Returns the current state of the configuration.
std::map< std::string, boost::program_options::variable_value > UserValues
@ FINAL
The postInitialize() method has been called.
@ INITIALIZED
The initialize() method has been called.
Catalog contains a container of sources.
static const std::string SOURCE_ID_COLUMN_NAME
static Elements::Logging logger
static const std::string SOURCE_ID_COLUMN_INDEX
static const std::string INPUT_CATALOG_FILE
static const std::string INPUT_CATALOG_FORMAT