SourceXtractorPlusPlus  0.11
Please provide a description of the project.
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 
38 
40 
41 namespace SourceXtractor {
42 
44  auto source_to_row = m_output_registry->getSourceToRowConverter(m_output_properties);
46 }
47 
50 }
51 
53  auto& output_config = manager.getConfiguration<OutputConfig>();
54  m_output_properties = output_config.getOutputProperties();
55  m_flush_size = output_config.getFlushSize();
56 
57  auto out_file = output_config.getOutputFile();
58 
60 
61  if (out_file != "") {
62  // Check if we can, at least, create it.
63  // Otherwise, the error will be triggered only at the end of the full process!
64  {
65  std::ofstream check_writeable{out_file};
66  if (!check_writeable) {
67  throw Elements::Exception(
68  std::system_error(errno, std::system_category(), "Failed to open the output catalog").what());
69  }
70  }
71 
73  std::shared_ptr<LdacWriter> ldac_writer;
74 
75  switch (output_config.getOutputFileFormat()) {
77  fits_table_writer = Euclid::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  ldac_writer = std::make_shared<LdacWriter>(out_file, manager);
83  m_source_handler = [ldac_writer](const SourceInterface &source) {
84  ldac_writer->notifySource(source);
85  };
86  table_writer = ldac_writer;
87  break;
89  table_writer = std::make_shared<Euclid::Table::AsciiWriter>(out_file);
90  break;
91  }
92  } else {
93  table_writer = std::make_shared<Euclid::Table::AsciiWriter>(std::cout);
94  }
95 
96  m_table_handler = [table_writer](const Euclid::Table::Table& table) {
97  try {
98  table_writer->addData(table);
99  }
100  // This one doesn't inherit from std::exception, so wrap it up here
101  catch (const CCfits::FitsException &e) {
102  throw Elements::Exception(e.message());
103  }
104  };
105 }
106 
107 } // SourceXtractor namespace
108 
void configure(Euclid::Configuration::ConfigManager &manager) override
Method which should initialize the object.
constexpr double e
std::unique_ptr< Output > getOutput() const
std::shared_ptr< OutputRegistry > m_output_registry
Definition: OutputFactory.h:57
T system_category(T... args)
STL class.
TableOutput::TableHandler m_table_handler
Definition: OutputFactory.h:58
TableOutput::SourceHandler m_source_handler
Definition: OutputFactory.h:59
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:60
The SourceInterface is an abstract "source" that has properties attached to it.
std::unique_ptr< T > make_unique(Args &&... args)