28 #include <boost/regex.hpp>
30 using boost::regex_match;
32 #include <boost/algorithm/string.hpp>
38 namespace po = boost::program_options;
39 namespace fs = boost::filesystem;
42 namespace Configuration {
53 return {{
"Input catalog options", {
55 "The file containing the photometry mapping of the catalog columns"},
57 "A list of filters to ignore"}
62 const fs::path& base_dir) {
64 if (mapping_file.is_relative()) {
65 mapping_file = base_dir / mapping_file;
67 if (!fs::exists(mapping_file)) {
68 throw Elements::Exception() <<
"Photometry mapping file " << mapping_file <<
" does not exist";
70 if (fs::is_directory(mapping_file)) {
71 throw Elements::Exception() <<
"Photometry mapping file " << mapping_file <<
" is not a file";
80 regex expr {
"\\s*([^\\s#]+)\\s+([^\\s#]+)\\s+([^\\s#]+)\\s*(#.*)?"};
87 if (!regex_match(line, match_res, expr)) {
88 logger.
error() <<
"Syntax error in " << filename <<
": " << line;
91 filter_name_mapping.emplace_back(match_res.str(1),
std::make_pair(match_res.str(2), match_res.str(3)));
93 return filter_name_mapping;
100 auto all_filter_name_mapping =
parseFile(filename);
105 for (
auto& pair : all_filter_name_mapping) {
106 if (exclude_filters.count(pair.first) > 0) {
107 exclude_filters.erase(pair.first);
113 if (!exclude_filters.empty()) {
115 for (
auto& f : exclude_filters) {
116 wrong_filters << f <<
" ";
119 << wrong_filters.str();
126 throw Elements::Exception() <<
"setBaseDir() call to initialized PhotometricBandMappingConfig";
134 <<
"PhotometricBandMappingConfig";
Superclass of all configuration classes.
void setBaseDir(const boost::filesystem::path &base_dir)
Sets the directory used when resolving relative paths.
static const std::string FILTER_MAPPING_FILE
State & getCurrentState()
Returns the current state of the configuration.
void initialize(const UserValues &args) override
It initializes the photometric bands list.
static const std::string EXCLUDE_FILTER
PhotometricBandMappingConfig(long manager_id)
Constructs a new PhotometricBandMappingConfig object.
static fs::path getMappingFileFromOptions(const Configuration::UserValues &args, const fs::path &base_dir)
static Elements::Logging logger
boost::filesystem::path m_base_dir
std::map< std::string, OptionDescriptionList > getProgramOptions() override
Returns the program options defined by the PhotometryCatalogConfig.
static PhotometricBandMappingConfig::MappingMap parseFile(fs::path filename)
const MappingMap & getPhotometricBandMapping()
Returns the list of the photometric band mapping which will be red from the catalog.
void error(const std::string &logMessage)
static Logging getLogger(const std::string &name="")
The initialize() method has been called.