SourceXtractorPlusPlus  0.11
Please provide a description of the project.
ExternalFlagConfig.cpp
Go to the documentation of this file.
1 
23 #include <boost/filesystem.hpp>
24 #include <boost/algorithm/string.hpp>
25 
27 
29 
31 
32 namespace po = boost::program_options;
33 namespace fs = boost::filesystem;
35 
36 namespace SourceXtractor {
37 
38 namespace {
39 
40 const std::string FLAG_IMAGE {"flag-image"};
41 const std::string FLAG_TYPE {"flag-type"};
42 
49 };
50 
51 }
52 
54  return {{"External flag options", {
55  {poh::wildcard(FLAG_IMAGE).c_str(), po::value<std::string>(),
56  "The FITS file containing the external flag"},
57  {poh::wildcard(FLAG_TYPE).c_str(), po::value<std::string>(),
58  "The combination type of the external flag (OR, AND, MIN, MAX, MOST)"}
59  }}};
60 }
61 
62 
64  for (auto& name : poh::findWildcardNames({FLAG_IMAGE, FLAG_TYPE}, args)) {
65 
66  // Check that the user gave both the filename and the type
67  if (args.count(poh::wildcard(FLAG_IMAGE, name)) == 0) {
68  throw Elements::Exception() << "Missing option " << poh::wildcard(FLAG_IMAGE, name);
69  }
70 
71  std::string type;
72  if (args.count(poh::wildcard(FLAG_TYPE, name)) == 0) {
73  type = "OR";
74  } else {
75  type = boost::to_upper_copy(args.at(poh::wildcard(FLAG_TYPE, name)).as<std::string>());
76  }
77 
78  // Check that the file exists
79  auto& filename = args.at(poh::wildcard(FLAG_IMAGE, name)).as<std::string>();
80  if (!fs::exists(filename)) {
81  throw Elements::Exception() << "File " << filename << " does not exist";
82  }
83 
84  // Check that the type is a valid option
85  if (available_types.count(type) == 0) {
86  throw Elements::Exception() << "Invalid option " << poh::wildcard(FLAG_TYPE, name)
87  << " : " << type;
88  }
89  }
90 }
91 
93  for (auto& name : poh::findWildcardNames({FLAG_IMAGE, FLAG_TYPE}, args)) {
94 
95  auto& filename = args.at(poh::wildcard(FLAG_IMAGE, name)).as<std::string>();
97 
98  std::string type_str;
99  if (args.count(poh::wildcard(FLAG_TYPE, name)) == 0) {
100  type_str = "OR";
101  } else {
102  type_str = boost::to_upper_copy(args.at(poh::wildcard(FLAG_TYPE, name)).as<std::string>());
103  }
104  Type type = available_types.at(type_str);
105 
106  m_flag_info_list.emplace_back(name, FlagInfo{std::move(image), type});
107  }
108 }
109 
110 auto ExternalFlagConfig::getFlagInfoList() const -> const std::vector<std::pair<std::string, FlagInfo>>& {
111  return m_flag_info_list;
112 }
113 
114 } // SourceXtractor namespace
115 
116 
117 
static std::string wildcard(const std::string &name, const std::string &instance="*")
STL namespace.
std::map< std::string, OptionDescriptionList > getProgramOptions() override
STL class.
STL class.
T at(T... args)
std::vector< std::pair< std::string, FlagInfo > > m_flag_info_list
string filename
Definition: conf.py:63
void initialize(const UserValues &args) override
void preInitialize(const UserValues &args) override
const std::vector< std::pair< std::string, FlagInfo > > & getFlagInfoList() const
T move(T... args)
T count(T... args)
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)
STL class.
T c_str(T... args)