SourceXtractorPlusPlus  0.16
Please provide a description of the project.
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 static const std::string OUTPUT_UNSORTED {"output-flush-unsorted"};
44 
46  {"ASCII", OutputConfig::OutputFileFormat::ASCII},
47  {"FITS", OutputConfig::OutputFileFormat::FITS},
48  {"FITS_LDAC", OutputConfig::OutputFileFormat::FITS_LDAC}
49 };
50 
51 OutputConfig::OutputConfig(long manager_id) : Configuration(manager_id), m_format(OutputFileFormat::ASCII),
52  m_flush_size(100), m_unsorted(false) {
53 }
54 
56  return { {"Output configuration", {
57  {OUTPUT_FILE.c_str(), po::value<std::string>()->default_value(""),
58  "The file to store the output catalog"},
59  {OUTPUT_FILE_FORMAT.c_str(), po::value<std::string>()->default_value("FITS"),
60  "The format of the output catalog, one of ASCII, FITS or FITS_LDAC (default: FITS)"},
61  {OUTPUT_PROPERTIES.c_str(), po::value<std::string>()->default_value("PixelCentroid"),
62  "The output properties to add in the output catalog"},
63  {OUTPUT_FLUSH_SIZE.c_str(), po::value<int>()->default_value(100),
64  "Write to the catalog after this number of sources have been processed (0 means once at the end)"},
65  {OUTPUT_UNSORTED.c_str(), po::bool_switch(),
66  "Write finished sources to the catalog without waiting for previously detected unfinished sources"}
67  }}};
68 }
69 
71  auto format_name = boost::to_upper_copy(args.at(OUTPUT_FILE_FORMAT).as<std::string>());
72  if (format_map.count(format_name) == 0) {
73  throw Elements::Exception() << "Unknown output file format: " << format_name;
74  }
75 }
76 
78  m_out_file = args.at(OUTPUT_FILE).as<std::string>();
79 
80  std::stringstream properties_str {args.at(OUTPUT_PROPERTIES).as<std::string>()};
81  std::string name;
82  while (std::getline(properties_str, name, ',')) {
84  }
85 
86  auto format_name = boost::to_upper_copy(args.at(OUTPUT_FILE_FORMAT).as<std::string>());
87  m_format = format_map.at(format_name);
88 
89  int flush_size = args.at(OUTPUT_FLUSH_SIZE).as<int>();
90  m_flush_size = (flush_size >= 0) ? flush_size : 0;
91 
92  m_unsorted = args.at(OUTPUT_UNSORTED).as<bool>();
93 }
94 
96  return m_out_file;
97 }
98 
100  return m_format;
101 }
102 
104  return m_output_properties;
105 }
106 
108  return m_flush_size;
109 }
110 
112  return m_unsorted;
113 }
114 
115 } // SEImplementation namespace
116 
117 
118 
T at(T... args)
T c_str(T... args)
std::map< std::string, Configuration::OptionDescriptionList > getProgramOptions() override
void preInitialize(const UserValues &args) override
OutputFileFormat getOutputFileFormat()
OutputFileFormat m_format
Definition: OutputConfig.h:69
const std::vector< std::string > getOutputProperties()
void initialize(const UserValues &args) override
std::vector< std::string > m_output_properties
Definition: OutputConfig.h:70
T emplace_back(T... args)
T getline(T... args)
static const std::string OUTPUT_FILE_FORMAT
static const std::string OUTPUT_FLUSH_SIZE
static const std::string OUTPUT_FILE
static std::map< std::string, OutputConfig::OutputFileFormat > format_map
static const std::string OUTPUT_UNSORTED
static const std::string OUTPUT_PROPERTIES