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);