SourceXtractorPlusPlus  0.10
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 
29 #include "Table/AsciiWriter.h"
30 #include "Table/FitsWriter.h"
31 
33 
37 
39 
41 
42 namespace SourceXtractor {
43 
45  auto source_to_row = m_output_registry->getSourceToRowConverter(m_output_properties);
47 }
48 
51 }
52 
54  auto& output_config = manager.getConfiguration<OutputConfig>();
55  m_output_properties = output_config.getOutputProperties();
56  m_flush_size = output_config.getFlushSize();
57 
58  auto out_file = output_config.getOutputFile();
59 
61 
62  if (out_file != "") {
63  // Check if we can, at least, create it.
64  // Otherwise, the error will be triggered only at the end of the full process!
65  {
66  std::ofstream check_writeable{out_file};
67  if (!check_writeable) {
68  throw Elements::Exception(
69  std::system_error(errno, std::system_category(), "Failed to open the output catalog").what());
70  }
71  }
72 
74 
75  switch (output_config.getOutputFileFormat()) {
77  fits_table_writer = make_unique<Euclid::Table::FitsWriter>(out_file, true);
78  fits_table_writer->setHduName("CATALOG");
79  table_writer = std::move(fits_table_writer);
80  break;
82  table_writer = std::make_shared<Euclid::Table::AsciiWriter>(out_file);
83  break;
84  }
85  } else {
86  table_writer = std::make_shared<Euclid::Table::AsciiWriter>(std::cout);
87  }
88 
89  m_table_handler = [table_writer](const Euclid::Table::Table& table) {
90  try {
91  table_writer->addData(table);
92  }
93  // This one doesn't inherit from std::exception, so wrap it up here
94  catch (const CCfits::FitsException &e) {
95  throw Elements::Exception(e.message());
96  }
97  };
98 }
99 
100 } // SourceXtractor namespace
101 
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
std::unique_ptr< T > make_unique(Args &&...args)