24 #include <CCfits/CCfits> 33 namespace po = boost::program_options;
34 namespace fs = boost::filesystem;
37 namespace Configuration {
49 return {{
"Input catalog options", {
51 "The file containing the input catalog"},
53 "The format of the input catalog (AUTO, FITS or ASCII)"},
55 "The name of the column representing the source ID"},
57 "The index of the column representing the source ID"}
87 const fs::path& base_dir) {
89 if (catalog_file.is_relative()) {
90 catalog_file = base_dir / catalog_file;
92 if (!fs::exists(catalog_file)) {
95 if (fs::is_directory(catalog_file)) {
105 FormatType autoDetectFormatType(fs::path file) {
106 logger.
info() <<
"Auto-detecting format of file " << file;
107 FormatType result = FormatType::ASCII;
111 in.read(first_header_array.
data(), 80);
114 if (first_header_str.compare(0, 9,
"SIMPLE =") == 0) {
115 result = FormatType::FITS;
118 logger.
info() <<
"Detected " << (result == FormatType::FITS ?
"FITS" :
"ASCII") <<
" format";
122 FormatType getFormatTypeFromOptions(
const Configuration::UserValues& args,
123 const fs::path& file) {
126 format = autoDetectFormatType(file);
128 format = FormatType::FITS;
130 format = FormatType::ASCII;
137 return make_unique<Table::FitsReader>(filename.native(), 1);
139 return make_unique<Table::AsciiReader>(filename.native());
143 std::string getIdColumnFromOptions(
const Configuration::UserValues& args,
144 const Table::ColumnInfo& column_info) {
148 if (column_info.find(id_column_name) ==
nullptr) {
150 <<
"ID column with name " << id_column_name;
155 if (index > column_info.size()) {
157 <<
") is out of range (" << column_info.size() <<
")";
159 id_column_name = column_info.getDescription(index-1).name;
161 logger.
info() <<
"Using ID column \"" << id_column_name <<
'"';
162 return id_column_name;
208 class ConverterImpl {
214 :
m_converter(column_info, id_column_name,
std::move(attribute_handlers)) {
231 throw Elements::Exception() <<
"getTableToCatalogConverter() call to not finalized CatalogConfig";
251 return converter(table);
static const std::string SOURCE_ID_COLUMN_NAME
SourceCatalog::Catalog readAsCatalog() const
Returns the Catalog object.
std::shared_ptr< Table::ColumnInfo > getColumnInfo() const
Superclass of all configuration classes.
void addAttributeHandler(std::shared_ptr< SourceCatalog::AttributeFromRow > handler)
Adds an attribute handler which will be used for adding attributes at the catalog objects...
static const std::string SOURCE_ID_COLUMN_INDEX
static const std::string INPUT_CATALOG_FILE
void info(const std::string &logMessage)
State & getCurrentState()
Returns the current state of the configuration.
boost::filesystem::path m_base_dir
const boost::filesystem::path & getFilename() const
Returns the filename of the input catalog.
void initialize(const UserValues &args) override
Initializes the CatalogConfig instance.
std::vector< std::shared_ptr< SourceCatalog::AttributeFromRow > > m_attribute_handlers
Table::Table readAsTable() const
Returns the catalog as a Table::Table object.
The postInitialize() method has been called.
void preInitialize(const UserValues &args) override
Checks that all the options are valid. See the exceptions thrown for a detailed list of the checks...
static Elements::Logging logger
std::string m_id_column_name
std::unique_ptr< Table::TableReader > getTableReader() const
void setBaseDir(const boost::filesystem::path &base_dir)
Sets the directory used when resolving relative paths.
TableToCatalogConverter getTableToCatalogConverter() const
boost::filesystem::path m_filename
CatalogConfig(long manager_id)
Constructs a new CatalogConfig object.
std::shared_ptr< Table::ColumnInfo > m_column_info
Catalog contains a container of sources.
SourceCatalog::CatalogFromTable m_converter
std::map< std::string, OptionDescriptionList > getProgramOptions() override
Returns the program options defined by the CatalogConfig.
static Logging getLogger(const std::string &name="")
The initialize() method has been called.
static const std::string INPUT_CATALOG_FORMAT
std::string getIdColumn() const