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", {
54 {
FILTER_MAPPING_FILE.c_str(), po::value<std::string>()->default_value(
"filter_mapping.txt"),
55 "The file containing the photometry mapping of the catalog columns"},
56 {
EXCLUDE_FILTER.c_str(), po::value<std::vector<std::string>>()->default_value(std::vector<std::string>{},
""),
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";
76 static std::pair<PhotometricBandMappingConfig::MappingMap, PhotometricBandMappingConfig::UpperLimitThresholdMap>
parseFile(fs::path filename) {
79 std::ifstream in {filename.string()};
81 regex expr {
"\\s*([^\\s#]+)\\s+([^\\s#]+)\\s+([^\\s#]+)(\\s+[^\\s#]+\\s*$)?"};
82 while (std::getline(in, line)) {
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)));
94 if (match_res.str(4)==
""){
95 threshold_mapping.emplace_back(match_res.str(1), 3.0);
97 float n=std::stof(match_res.str(4));
98 threshold_mapping.emplace_back(match_res.str(1), n);
101 return std::make_pair(filter_name_mapping,threshold_mapping);
109 auto all_filter_name_mapping = parsed.first;
110 auto all_threshold_mapping = parsed.second;
113 auto exclude_vector = args.at(
EXCLUDE_FILTER).as<std::vector<std::string>>();
114 std::set<std::string> exclude_filters {exclude_vector.begin(), exclude_vector.end()};
116 for (
auto& pair : all_threshold_mapping) {
117 if (exclude_filters.count(pair.first) <= 0) {
122 for (
auto& pair : all_filter_name_mapping) {
123 if (exclude_filters.count(pair.first) > 0) {
124 exclude_filters.erase(pair.first);
131 if (!exclude_filters.empty()) {
132 std::stringstream wrong_filters {};
133 for (
auto& f : exclude_filters) {
134 wrong_filters << f <<
" ";
137 << wrong_filters.str();
144 throw Elements::Exception() <<
"setBaseDir() call to initialized PhotometricBandMappingConfig";
152 <<
"PhotometricBandMappingConfig";
161 <<
"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.
std::vector< std::pair< std::string, float > > UpperLimitThresholdMap
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)
UpperLimitThresholdMap m_threshold_map
static Elements::Logging logger
boost::filesystem::path m_base_dir
static std::pair< PhotometricBandMappingConfig::MappingMap, PhotometricBandMappingConfig::UpperLimitThresholdMap > parseFile(fs::path filename)
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...
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.
std::vector< std::pair< std::string, std::pair< std::string, std::string > >> MappingMap
std::map< std::string, boost::program_options::variable_value > UserValues