SourceXtractorPlusPlus  0.14
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OutputConfig.cpp
Go to the documentation of this file.
1 
23 #include <sstream>
24 
25 #include <boost/algorithm/string.hpp>
26 
28 
31 
33 
34 using namespace Euclid::Configuration;
35 namespace po = boost::program_options;
36 
37 namespace SourceXtractor {
38 
39 static const std::string OUTPUT_FILE {"output-catalog-filename"};
40 static const std::string OUTPUT_FILE_FORMAT {"output-catalog-format"};
41 static const std::string OUTPUT_PROPERTIES {"output-properties"};
42 static const std::string OUTPUT_FLUSH_SIZE {"output-flush-size"};
43 
45  {"ASCII", OutputConfig::OutputFileFormat::ASCII},
46  {"FITS", OutputConfig::OutputFileFormat::FITS},
47  {"FITS_LDAC", OutputConfig::OutputFileFormat::FITS_LDAC}
48 };
49 
50 OutputConfig::OutputConfig(long manager_id) : Configuration(manager_id), m_format(OutputFileFormat::ASCII),
51  m_flush_size(100) {
52 }
53 
55  return { {"Output configuration", {
56  {OUTPUT_FILE.c_str(), po::value<std::string>()->default_value(""),
57  "The file to store the output catalog"},
58  {OUTPUT_FILE_FORMAT.c_str(), po::value<std::string>()->default_value("FITS"),
59  "The format of the output catalog, one of ASCII or FITS (default: FITS)"},
60  {OUTPUT_PROPERTIES.c_str(), po::value<std::string>()->default_value("PixelCentroid"),
61  "The output properties to add in the output catalog"},
62  {OUTPUT_FLUSH_SIZE.c_str(), po::value<int>()->default_value(100),
63  "Write to the catalog after this number of sources have been processed (0 means once at the end)"}
64  }}};
65 }
66 
67 void OutputConfig::preInitialize(const UserValues& args) {
68  auto format_name = boost::to_upper_copy(args.at(OUTPUT_FILE_FORMAT).as<std::string>());
69  if (format_map.count(format_name) == 0) {
70  throw Elements::Exception() << "Unknown output file format: " << format_name;
71  }
72 }
73 
74 void OutputConfig::initialize(const UserValues& args) {
75  m_out_file = args.at(OUTPUT_FILE).as<std::string>();
76 
77  std::stringstream properties_str {args.at(OUTPUT_PROPERTIES).as<std::string>()};
78  std::string name;
79  while (std::getline(properties_str, name, ',')) {
81  }
82 
83  auto format_name = boost::to_upper_copy(args.at(OUTPUT_FILE_FORMAT).as<std::string>());
84  m_format = format_map.at(format_name);
85 
86  int flush_size = args.at(OUTPUT_FLUSH_SIZE).as<int>();
87  m_flush_size = (flush_size >= 0) ? flush_size : 0;
88 }
89 
91  return m_out_file;
92 }
93 
95  return m_format;
96 }
97 
99  return m_output_properties;
100 }
101 
103  return m_flush_size;
104 }
105 
106 } // SEImplementation namespace
107 
108 
109 
T getline(T...args)
void initialize(const UserValues &args) override
STL class.
static std::map< std::string, OutputConfig::OutputFileFormat > format_map
STL class.
T at(T...args)
OutputFileFormat m_format
Definition: OutputConfig.h:67
const std::vector< std::string > getOutputProperties()
std::vector< std::string > m_output_properties
Definition: OutputConfig.h:68
static const std::string OUTPUT_FILE_FORMAT
void preInitialize(const UserValues &args) override
std::map< std::string, Configuration::OptionDescriptionList > getProgramOptions() override
T c_str(T...args)
static const std::string OUTPUT_FLUSH_SIZE
static const std::string OUTPUT_FILE
static const std::string OUTPUT_PROPERTIES
T emplace_back(T...args)
OutputFileFormat getOutputFileFormat()