29 #include <CCfits/CCfits>
33 namespace po = boost::program_options;
34 namespace fs = boost::filesystem;
37 namespace Configuration {
49 return {{
"Input catalog options",
52 "The format of the input catalog (AUTO, FITS or ASCII)"},
61 <<
" are mutually exclusive";
80 if (catalog_file.is_relative()) {
81 catalog_file = base_dir / catalog_file;
83 if (!fs::exists(catalog_file)) {
86 if (fs::is_directory(catalog_file)) {
92 enum class FormatType { FITS, ASCII };
94 FormatType autoDetectFormatType(fs::path file) {
95 logger.
info() <<
"Auto-detecting format of file " << file;
96 FormatType result = FormatType::ASCII;
100 in.read(first_header_array.
data(), 80);
103 if (first_header_str.compare(0, 9,
"SIMPLE =") == 0) {
104 result = FormatType::FITS;
107 logger.
info() <<
"Detected " << (result == FormatType::FITS ?
"FITS" :
"ASCII") <<
" format";
111 FormatType getFormatTypeFromOptions(
const Configuration::UserValues& args,
const fs::path& file) {
114 format = autoDetectFormatType(file);
116 format = FormatType::FITS;
118 format = FormatType::ASCII;
125 return Euclid::make_unique<Table::FitsReader>(filename.native(), 1);
127 return Euclid::make_unique<Table::AsciiReader>(filename.native());
131 std::string getIdColumnFromOptions(
const Configuration::UserValues& args,
const Table::ColumnInfo& column_info) {
135 if (column_info.find(id_column_name) ==
nullptr) {
137 <<
"ID column with name " << id_column_name;
142 if (index > column_info.size()) {
145 id_column_name = column_info.getDescription(index - 1).name;
147 logger.
info() <<
"Using ID column \"" << id_column_name <<
'"';
148 return id_column_name;
194 class ConverterImpl {
199 :
m_converter(column_info, id_column_name,
std::move(attribute_handlers)) {}
213 throw Elements::Exception() <<
"getTableToCatalogConverter() call to not finalized CatalogConfig";
232 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.
@ 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