26 #include <boost/regex.hpp>
31 using boost::regex_match;
33 #include <boost/algorithm/string.hpp>
39 namespace po = boost::program_options;
40 namespace fs = boost::filesystem;
43 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 if (mapping_file.is_relative()) {
63 mapping_file = base_dir / mapping_file;
65 if (!fs::exists(mapping_file)) {
66 throw Elements::Exception() <<
"Photometry mapping file " << mapping_file <<
" does not exist";
68 if (fs::is_directory(mapping_file)) {
69 throw Elements::Exception() <<
"Photometry mapping file " << mapping_file <<
" is not a file";
81 regex expr{
"\\s*([^\\s#]+)\\s+([^\\s#]+)\\s+([^\\s#]+)(\\s+[^\\s#]+)?(\\s+[^\\s#]+\\s*$)?"};
88 if (!regex_match(line, match_res, expr)) {
89 logger.
error() <<
"Syntax error in " << filename <<
": " << line;
92 filter_name_mapping.emplace_back(match_res.str(1),
std::make_pair(match_res.str(2), match_res.str(3)));
95 if (match_res.size() < 5 || match_res.str(4) ==
"") {
96 threshold_mapping.emplace_back(match_res.str(1), 3.0);
99 threshold_mapping.emplace_back(match_res.str(1), n);
103 if (match_res.size() < 6 || match_res.str(5) ==
"") {
104 convert_from_mag_mapping.emplace_back(match_res.str(1),
false);
107 convert_from_mag_mapping.emplace_back(match_res.str(1), f);
111 return std::make_tuple(filter_name_mapping, threshold_mapping, convert_from_mag_mapping);
119 auto all_filter_name_mapping = std::get<0>(parsed);
120 auto all_threshold_mapping = std::get<1>(parsed);
121 auto all_convert_mapping = std::get<2>(parsed);
127 for (
auto& pair : all_threshold_mapping) {
128 if (exclude_filters.count(pair.first) == 0) {
133 for (
auto& pair : all_convert_mapping) {
134 if (exclude_filters.count(pair.first) == 0) {
139 for (
auto& pair : all_filter_name_mapping) {
140 if (exclude_filters.count(pair.first) > 0) {
141 exclude_filters.erase(pair.first);
149 if (!exclude_filters.empty()) {
151 for (
auto& f : exclude_filters) {
152 wrong_filters << f <<
" ";
160 throw Elements::Exception() <<
"setBaseDir() call to initialized PhotometricBandMappingConfig";
168 <<
"PhotometricBandMappingConfig";
176 <<
"PhotometricBandMappingConfig";
184 <<
"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.
ConvertFromMagMap m_convert_from_mag_map
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.
const ConvertFromMagMap & getConvertFromMagMapping()
Returns the mapping of the flag indicating if the photometry has to be computed from a MAG_AB.
static std::tuple< PhotometricBandMappingConfig::MappingMap, PhotometricBandMappingConfig::UpperLimitThresholdMap, PhotometricBandMappingConfig::ConvertFromMagMap > parseFile(fs::path filename)
static Elements::Logging logger
static const std::string EXCLUDE_FILTER
static fs::path getMappingFileFromOptions(const Configuration::UserValues &args, const fs::path &base_dir)
static const std::string FILTER_MAPPING_FILE