LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
FitsWriter.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 #ifndef AFW_TABLE_IO_FitsWriter_h_INCLUDED
3 #define AFW_TABLE_IO_FitsWriter_h_INCLUDED
4 
5 #include <set>
6 
7 #include "lsst/base.h"
8 #include "lsst/pex/exceptions.h"
10 #include "lsst/afw/fits.h"
11 
12 namespace lsst {
13 namespace afw {
14 namespace table {
15 namespace io {
16 
25 class FitsWriter {
26 public:
28 
36  template <typename OutputT, typename ContainerT>
37  static void apply(OutputT& output, std::string const& mode, ContainerT const& container, int flags) {
38  Fits fits(output, mode, Fits::AUTO_CLOSE | Fits::AUTO_CHECK);
39  apply(fits, container, flags);
40  }
41 
43  template <typename ContainerT>
44  static void apply(Fits& fits, ContainerT const& container, int flags) {
46  std::static_pointer_cast<BaseTable const>(container.getTable())->makeFitsWriter(&fits, flags);
47  writer->write(container);
48  }
49 
57  template <typename ContainerT>
58  void write(ContainerT const& container) {
60  for (typename ContainerT::const_iterator i = container.begin(); i != container.end(); ++i) {
61  if (i->getTable() != container.getTable()) tables.insert(i->getTable());
62  }
63  for (std::set<std::shared_ptr<BaseTable const>>::iterator j = tables.begin(); j != tables.end();
64  ++j) {
65  if ((**j).getSchema().compare(container.getTable()->getSchema(), Schema::IDENTICAL) !=
68  "Cannot save Catalog with heterogenous schemas");
69  }
70  }
71  _writeTable(container.getTable(), container.size());
72  for (typename ContainerT::const_iterator i = container.begin(); i != container.end(); ++i) {
73  _writeRecord(*i);
74  }
75  _finish();
76  }
77 
79  explicit FitsWriter(Fits* fits, int flags) : _fits(fits), _flags(flags) {}
80 
81  FitsWriter(FitsWriter const&) = default;
82  FitsWriter(FitsWriter&&) = default;
83  FitsWriter& operator=(FitsWriter const&) = default;
85  virtual ~FitsWriter() = default;
86 
87 protected:
89  virtual void _writeTable(std::shared_ptr<BaseTable const> const& table, std::size_t nRows);
90 
92  virtual void _writeRecord(BaseRecord const& source);
93 
95  virtual void _finish() {}
96 
97  Fits* _fits; // wrapped cfitsio pointer
98  int _flags; // subclass-defined flags to control writing
99  std::size_t _row; // which row we're currently processing
100 
101 private:
102  struct ProcessRecords;
103 
104  std::shared_ptr<ProcessRecords> _processor; // a private Schema::forEach functor that write records
105 };
106 } // namespace io
107 } // namespace table
108 } // namespace afw
109 } // namespace lsst
110 
111 #endif // !AFW_TABLE_IO_FitsWriter_h_INCLUDED
lsst::afw::table::io::FitsWriter::Fits
afw::fits::Fits Fits
Definition: FitsWriter.h:27
lsst::afw::table::io::FitsWriter::operator=
FitsWriter & operator=(FitsWriter &&)=default
std::string
STL class.
std::shared_ptr
STL class.
lsst::afw::table::io::FitsWriter::_writeRecord
virtual void _writeRecord(BaseRecord const &source)
Write an individual record.
Definition: FitsWriter.cc:189
lsst::afw::table::io::FitsWriter::_finish
virtual void _finish()
Finish writing a catalog.
Definition: FitsWriter.h:95
lsst::afw::table::io::FitsWriter::_row
std::size_t _row
Definition: FitsWriter.h:99
lsst::afw::fits::Fits
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:297
fits.h
lsst::afw
Definition: imageAlgorithm.dox:1
lsst::afw::table::io::FitsWriter::_flags
int _flags
Definition: FitsWriter.h:98
lsst::afw::table::io::FitsWriter::FitsWriter
FitsWriter(FitsWriter const &)=default
fits
Fits * fits
Definition: FitsWriter.cc:90
ast::detail::source
const char * source()
Source function that allows astChannel to source from a Stream.
Definition: Stream.h:224
base.h
lsst::afw::fits::Fits::AUTO_CHECK
@ AUTO_CHECK
Definition: fits.h:308
lsst::afw::fits::Fits::AUTO_CLOSE
@ AUTO_CLOSE
Definition: fits.h:307
lsst::afw::table::io::FitsWriter::FitsWriter
FitsWriter(Fits *fits, int flags)
Construct from a wrapped cfitsio pointer.
Definition: FitsWriter.h:79
lsst::afw::table::BaseRecord
Base class for all records.
Definition: BaseRecord.h:31
lsst.pex::exceptions::LogicError
Reports errors in the logical structure of the program.
Definition: Runtime.h:46
lsst::afw::table::io::FitsWriter::FitsWriter
FitsWriter(FitsWriter &&)=default
lsst::afw::table::io::FitsWriter::_fits
Fits * _fits
Definition: FitsWriter.h:97
lsst::afw::table::io::FitsWriter::operator=
FitsWriter & operator=(FitsWriter const &)=default
lsst::afw::table::Schema::IDENTICAL
@ IDENTICAL
Everything is the same.
Definition: Schema.h:71
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
lsst::afw::table::io::FitsWriter::~FitsWriter
virtual ~FitsWriter()=default
lsst::afw::table::io::FitsWriter::_writeTable
virtual void _writeTable(std::shared_ptr< BaseTable const > const &table, std::size_t nRows)
Write a table and its schema.
Definition: FitsWriter.cc:103
std::set::begin
T begin(T... args)
std::set::insert
T insert(T... args)
lsst::afw::table::io::FitsWriter::apply
static void apply(Fits &fits, ContainerT const &container, int flags)
Low-level driver for writing FITS files, operating on an open FITS file.
Definition: FitsWriter.h:44
lsst::afw::table::io::FitsWriter
Writer object for FITS binary tables.
Definition: FitsWriter.h:25
BaseTable.h
std::size_t
std::set::end
T end(T... args)
lsst::afw::table::io::FitsWriter::write
void write(ContainerT const &container)
Write records in a container to disk.
Definition: FitsWriter.h:58
lsst::afw::table::io::FitsWriter::apply
static void apply(OutputT &output, std::string const &mode, ContainerT const &container, int flags)
Driver for writing FITS files.
Definition: FitsWriter.h:37
std::set
STL class.
lsst::afw::table::io::FitsWriter::ProcessRecords
Definition: FitsWriter.cc:136
exceptions.h