SourceXtractorPlusPlus  0.10
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 
std::string
STL class.
std::move
T move(T... args)
std::pair
conf.filename
string filename
Definition: conf.py:63
std::vector
STL class.
Euclid::Configuration::ProgramOptionsHelper::wildcard
static std::string wildcard(const std::string &name, const std::string &instance="*")
SourceXtractor::ExternalFlagConfig::getProgramOptions
std::map< std::string, OptionDescriptionList > getProgramOptions() override
Definition: ExternalFlagConfig.cpp:53
SourceXtractor::ExternalFlagConfig::Type::MOST
@ MOST
SourceXtractor::ExternalFlagConfig::Type::MAX
@ MAX
SourceXtractor::ExternalFlagConfig::Type::AND
@ AND
SourceXtractor
Definition: Aperture.h:30
std::map::at
T at(T... args)
SourceXtractor::ExternalFlagConfig::getFlagInfoList
const std::vector< std::pair< std::string, FlagInfo > > & getFlagInfoList() const
Definition: ExternalFlagConfig.cpp:110
std::string::c_str
T c_str(T... args)
SourceXtractor::FitsReader::readFile
static std::shared_ptr< Image< T > > readFile(const std::string &filename)
Definition: FitsReader.h:46
SourceXtractor::ExternalFlagConfig::initialize
void initialize(const UserValues &args) override
Definition: ExternalFlagConfig.cpp:92
SourceXtractor::ExternalFlagConfig::preInitialize
void preInitialize(const UserValues &args) override
Definition: ExternalFlagConfig.cpp:63
Elements::Exception
std::map
STL class.
SourceXtractor::ExternalFlagConfig::Type
Type
Definition: ExternalFlagConfig.h:41
SourceXtractor::ExternalFlagConfig::m_flag_info_list
std::vector< std::pair< std::string, FlagInfo > > m_flag_info_list
Definition: ExternalFlagConfig.h:64
FitsReader.h
Euclid::Configuration::ProgramOptionsHelper::findWildcardNames
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
STL namespace.
SourceXtractor::ExternalFlagConfig::Type::MIN
@ MIN
std::map::count
T count(T... args)
Euclid::Configuration::ProgramOptionsHelper
ProgramOptionsHelper.h
SourceXtractor::ExternalFlagConfig::Type::OR
@ OR
ExternalFlagConfig.h