SourceXtractorPlusPlus 0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
ExternalFlagConfig.cpp
Go to the documentation of this file.
1
23#include <boost/filesystem.hpp>
24#include <boost/algorithm/string.hpp>
25
26#include <boost/regex.hpp>
27using boost::regex;
28using boost::regex_match;
29using boost::smatch;
30
31#include "Configuration/ProgramOptionsHelper.h"
32
34
36
37namespace po = boost::program_options;
38namespace fs = boost::filesystem;
40
41namespace SourceXtractor {
42
43namespace {
44
45const std::string FLAG_IMAGE {"flag-image"};
46const std::string FLAG_TYPE {"flag-type"};
47
54};
55
56}
57
59 return {{"External flag options", {
60 {poh::wildcard(FLAG_IMAGE).c_str(), po::value<std::string>(),
61 "The FITS file containing the external flag, several images can be provided, replace * by any identifier (ex. use numbers)"},
62 {poh::wildcard(FLAG_TYPE).c_str(), po::value<std::string>(),
63 "The combination type of the external flag (OR, AND, MIN, MAX, MOST)"}
64 }}};
65}
66
67
69 for (auto& name : poh::findWildcardNames({FLAG_IMAGE, FLAG_TYPE}, args)) {
70
71 // Check that the user gave both the filename and the type
72 if (args.count(poh::wildcard(FLAG_IMAGE, name)) == 0) {
73 throw Elements::Exception() << "Missing option " << poh::wildcard(FLAG_IMAGE, name);
74 }
75
76 std::string type;
77 if (args.count(poh::wildcard(FLAG_TYPE, name)) == 0) {
78 type = "OR";
79 } else {
80 type = boost::to_upper_copy(args.at(poh::wildcard(FLAG_TYPE, name)).as<std::string>());
81 }
82
83 // Check that the type is a valid option
84 if (available_types.count(type) == 0) {
85 throw Elements::Exception() << "Invalid option " << poh::wildcard(FLAG_TYPE, name)
86 << " : " << type;
87 }
88 }
89}
90
92 for (auto& name : poh::findWildcardNames({FLAG_IMAGE, FLAG_TYPE}, args)) {
93
94 auto& filename = args.at(poh::wildcard(FLAG_IMAGE, name)).as<std::string>();
96 boost::regex hdu_regex(".*\\[[0-9]*\\]$");
97
98 for (int i=0;; i++) {
100 if (boost::regex_match(filename, hdu_regex)) {
101 if (i==0) {
103 } else {
104 break;
105 }
106 } else {
107 try {
109 } catch (...) {
110 if (i==0) {
111 // Skip past primary HDU if it doesn't have an image
112 continue;
113 } else {
114 if (flag_images.size() == 0) {
115 throw;
116 }
117 break;
118 }
119 }
120 }
121
123 }
124
126 if (args.count(poh::wildcard(FLAG_TYPE, name)) == 0) {
127 type_str = "OR";
128 } else {
129 type_str = boost::to_upper_copy(args.at(poh::wildcard(FLAG_TYPE, name)).as<std::string>());
130 }
131 Type type = available_types.at(type_str);
132
133 m_flag_info_list.emplace_back(name, FlagInfo{std::move(flag_images), type});
134 }
135}
136
140
141} // SourceXtractor namespace
142
143
144
static std::string wildcard(const std::string &name, const std::string &instance="*")
static std::set< std::string > findWildcardNames(const std::vector< std::string > &option_name_list, const std::map< std::string, boost::program_options::variable_value > &options)
std::map< std::string, OptionDescriptionList > getProgramOptions() override
void initialize(const UserValues &args) override
const std::vector< std::pair< std::string, FlagInfo > > & getFlagInfoList() const
void preInitialize(const UserValues &args) override
std::vector< std::pair< std::string, FlagInfo > > m_flag_info_list
T move(T... args)
STL namespace.