LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
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;
84  FitsWriter& operator=(FitsWriter&&) = 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
FitsWriter & operator=(FitsWriter const &)=default
Writer object for FITS binary tables.
Definition: FitsWriter.h:25
Basic LSST definitions.
void write(ContainerT const &container)
Write records in a container to disk.
Definition: FitsWriter.h:58
T end(T... args)
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:297
Fits * fits
Definition: FitsWriter.cc:90
STL class.
A base class for image defects.
const char * source()
Source function that allows astChannel to source from a Stream.
Definition: Stream.h:224
T static_pointer_cast(T... args)
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
Reports errors in the logical structure of the program.
Definition: Runtime.h:46
virtual void _writeTable(std::shared_ptr< BaseTable const > const &table, std::size_t nRows)
Write a table and its schema.
Definition: FitsWriter.cc:103
T insert(T... args)
STL class.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
Base class for all records.
Definition: BaseRecord.h:31
T begin(T... args)
static void apply(OutputT &output, std::string const &mode, ContainerT const &container, int flags)
Driver for writing FITS files.
Definition: FitsWriter.h:37
virtual void _writeRecord(BaseRecord const &source)
Write an individual record.
Definition: FitsWriter.cc:189
virtual void _finish()
Finish writing a catalog.
Definition: FitsWriter.h:95
Base class for all tables.
Definition: BaseTable.h:61
Everything is the same.
Definition: Schema.h:71
FitsWriter(Fits *fits, int flags)
Construct from a wrapped cfitsio pointer.
Definition: FitsWriter.h:79