26 #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 {
52 return {{
"Input catalog options",
54 "The file containing the photometry mapping of the catalog columns"},
56 "A list of filters to ignore"}}}};
61 if (mapping_file.is_relative()) {
62 mapping_file = base_dir / mapping_file;
64 if (!fs::exists(mapping_file)) {
65 throw Elements::Exception() <<
"Photometry mapping file " << mapping_file <<
" does not exist";
67 if (fs::is_directory(mapping_file)) {
68 throw Elements::Exception() <<
"Photometry mapping file " << mapping_file <<
" is not a file";
79 regex expr{
"\\s*([^\\s#]+)\\s+([^\\s#]+)\\s+([^\\s#]+)(\\s+[^\\s#]+\\s*$)?"};
86 if (!regex_match(line, match_res, expr)) {
87 logger.
error() <<
"Syntax error in " << filename <<
": " << line;
90 filter_name_mapping.emplace_back(match_res.str(1),
std::make_pair(match_res.str(2), match_res.str(3)));
92 if (match_res.str(4) ==
"") {
93 threshold_mapping.emplace_back(match_res.str(1), 3.0);
96 threshold_mapping.emplace_back(match_res.str(1), n);
107 auto all_filter_name_mapping = parsed.first;
108 auto all_threshold_mapping = parsed.second;
114 for (
auto& pair : all_threshold_mapping) {
115 if (exclude_filters.count(pair.first) <= 0) {
120 for (
auto& pair : all_filter_name_mapping) {
121 if (exclude_filters.count(pair.first) > 0) {
122 exclude_filters.erase(pair.first);
128 if (!exclude_filters.empty()) {
130 for (
auto& f : exclude_filters) {
131 wrong_filters << f <<
" ";
139 throw Elements::Exception() <<
"setBaseDir() call to initialized PhotometricBandMappingConfig";
147 <<
"PhotometricBandMappingConfig";
155 <<
"PhotometricBandMappingConfig";
void error(const std::string &logMessage)
static Logging getLogger(const std::string &name="")
Superclass of all configuration classes.
State & getCurrentState()
Returns the current state of the configuration.
@ INITIALIZED
The initialize() method has been called.
UpperLimitThresholdMap m_threshold_map
const MappingMap & getPhotometricBandMapping()
Returns the list of the photometric band mapping which will be red from the catalog.
boost::filesystem::path m_base_dir
std::map< std::string, OptionDescriptionList > getProgramOptions() override
Returns the program options defined by the PhotometryCatalogConfig.
const UpperLimitThresholdMap & getUpperLimitThresholdMapping()
Returns the mapping of threshold used in the upper limit computation which will be red from the catal...
PhotometricBandMappingConfig(long manager_id)
Constructs a new PhotometricBandMappingConfig object.
void initialize(const UserValues &args) override
It initializes the photometric bands list.
void setBaseDir(const boost::filesystem::path &base_dir)
Sets the directory used when resolving relative paths.
static Elements::Logging logger
static const std::string EXCLUDE_FILTER
static fs::path getMappingFileFromOptions(const Configuration::UserValues &args, const fs::path &base_dir)
static std::pair< PhotometricBandMappingConfig::MappingMap, PhotometricBandMappingConfig::UpperLimitThresholdMap > parseFile(fs::path filename)
static const std::string FILTER_MAPPING_FILE