SourceXtractorPlusPlus  0.8
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OutputFactory.cpp
Go to the documentation of this file.
1 
22 #include <system_error>
23 #include <iostream>
24 #include <fstream>
25 #include <system_error>
26 #include <CCfits/CCfits>
27 #include <ModelFitting/utils.h>
28 
29 #include "Table/AsciiWriter.h"
30 #include "Table/FitsWriter.h"
31 
33 
37 
39 
40 namespace SourceXtractor {
41 
43  auto source_to_row = m_output_registry->getSourceToRowConverter(m_output_properties);
45 }
46 
49 }
50 
52  auto& output_config = manager.getConfiguration<OutputConfig>();
53  m_output_properties = output_config.getOutputProperties();
54  m_flush_size = output_config.getFlushSize();
55 
56  auto out_file = output_config.getOutputFile();
57 
59 
60  if (out_file != "") {
61  // Check if we can, at least, create it.
62  // Otherwise, the error will be triggered only at the end of the full process!
63  {
64  std::ofstream check_writeable{out_file};
65  if (!check_writeable) {
66  throw Elements::Exception(
67  std::system_error(errno, std::system_category(), "Failed to open the output catalog").what());
68  }
69  }
70 
72 
73  switch (output_config.getOutputFileFormat()) {
75  fits_table_writer = make_unique<Euclid::Table::FitsWriter>(out_file, true);
76  fits_table_writer->setHduName("CATALOG");
77  table_writer = std::move(fits_table_writer);
78  break;
80  table_writer = std::make_shared<Euclid::Table::AsciiWriter>(out_file);
81  break;
82  }
83  } else {
84  table_writer = std::make_shared<Euclid::Table::AsciiWriter>(std::cout);
85  }
86 
87  m_table_handler = [table_writer](const Euclid::Table::Table& table) {
88  try {
89  table_writer->addData(table);
90  }
91  // This one doesn't inherit from std::exception, so wrap it up here
92  catch (const CCfits::FitsException &e) {
93  throw Elements::Exception(e.message());
94  }
95  };
96 }
97 
98 } // SourceXtractor namespace
99 
void configure(Euclid::Configuration::ConfigManager &manager) override
Method which should initialize the object.
constexpr double e
std::shared_ptr< OutputRegistry > m_output_registry
Definition: OutputFactory.h:56
T system_category(T...args)
STL class.
TableOutput::TableHandler m_table_handler
Definition: OutputFactory.h:57
FitsWriter & setHduName(const std::string &name)
void reportConfigDependencies(Euclid::Configuration::ConfigManager &manager) const override
Registers all the Configuration dependencies.
T move(T...args)
STL class.
std::vector< std::string > m_output_properties
Definition: OutputFactory.h:58
std::unique_ptr< Output > getOutput() const