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 
Euclid::Configuration::ConfigManager::registerConfiguration
void registerConfiguration()
SourceXtractor::TableOutput
Definition: TableOutput.h:32
std::shared_ptr
STL class.
SourceXtractor::OutputFactory::m_table_handler
TableOutput::TableHandler m_table_handler
Definition: OutputFactory.h:58
std::system_error
STL class.
std::move
T move(T... args)
Euclid::Configuration::ConfigManager
Euclid::Configuration::ConfigManager::getConfiguration
T & getConfiguration()
SourceXtractor::OutputConfig::OutputFileFormat::ASCII
@ ASCII
SourceXtractor::OutputConfig::OutputFileFormat::FITS_LDAC
@ FITS_LDAC
LdacWriter.h
Euclid::Table::TableWriter::addData
void addData(const Table &table)
Euclid::Table::FitsWriter::setHduName
FitsWriter & setHduName(const std::string &name)
std::system_category
T system_category(T... args)
SourceXtractor
Definition: Aperture.h:30
std::cout
std::ofstream
STL class.
Elements::Exception
SourceXtractor::OutputFactory::m_flush_size
size_t m_flush_size
Definition: OutputFactory.h:61
SourceXtractor::OutputConfig::OutputFileFormat::FITS
@ FITS
Euclid::make_unique
std::unique_ptr< T > make_unique(Args &&... args)
DetectionImageConfig.h
e
constexpr double e
SourceXtractor::OutputFactory::configure
void configure(Euclid::Configuration::ConfigManager &manager) override
Method which should initialize the object.
Definition: OutputFactory.cpp:52
AsciiWriter.h
SourceXtractor::OutputConfig
Definition: OutputConfig.h:36
OutputConfig.h
SourceXtractor::OutputFactory::m_output_registry
std::shared_ptr< OutputRegistry > m_output_registry
Definition: OutputFactory.h:57
OutputRegistry.h
Euclid::Table::Table
SourceXtractor::OutputFactory::m_source_handler
TableOutput::SourceHandler m_source_handler
Definition: OutputFactory.h:59
SourceXtractor::OutputFactory::getOutput
std::unique_ptr< Output > getOutput() const
Definition: OutputFactory.cpp:43
SourceXtractor::SourceInterface
The SourceInterface is an abstract "source" that has properties attached to it.
Definition: SourceInterface.h:46
SourceXtractor::OutputFactory::reportConfigDependencies
void reportConfigDependencies(Euclid::Configuration::ConfigManager &manager) const override
Registers all the Configuration dependencies.
Definition: OutputFactory.cpp:48
std::unique_ptr
STL class.
memory_tools.h
FitsWriter.h
SourceXtractor::OutputFactory::m_output_properties
std::vector< std::string > m_output_properties
Definition: OutputFactory.h:60
OutputFactory.h