LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
LSST Data Management Base Package
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 (auto const &table : tables) {
64  if ((*table).getSchema().compare(container.getTable()->getSchema(), Schema::IDENTICAL) !=
67  "Cannot save Catalog with heterogenous schemas");
68  }
69  }
70  _writeTable(container.getTable(), container.size());
71  for (typename ContainerT::const_iterator i = container.begin(); i != container.end(); ++i) {
72  _writeRecord(*i);
73  }
74  _finish();
75  }
76 
78  explicit FitsWriter(Fits* fits, int flags) : _fits(fits), _flags(flags) {}
79 
80  FitsWriter(FitsWriter const&) = default;
81  FitsWriter(FitsWriter&&) = default;
82  FitsWriter& operator=(FitsWriter const&) = default;
84  virtual ~FitsWriter() = default;
85 
86 protected:
88  virtual void _writeTable(std::shared_ptr<BaseTable const> const& table, std::size_t nRows);
89 
91  virtual void _writeRecord(BaseRecord const& source);
92 
94  virtual void _finish() {}
95 
96  Fits* _fits; // wrapped cfitsio pointer
97  int _flags; // subclass-defined flags to control writing
98  std::size_t _row; // which row we're currently processing
99 
100 private:
101  struct ProcessRecords;
102 
103  std::shared_ptr<ProcessRecords> _processor; // a private Schema::forEach functor that write records
104 };
105 } // namespace io
106 } // namespace table
107 } // namespace afw
108 } // namespace lsst
109 
110 #endif // !AFW_TABLE_IO_FitsWriter_h_INCLUDED
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
Fits * fits
Definition: FitsWriter.cc:90
Basic LSST definitions.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:297
Base class for all records.
Definition: BaseRecord.h:31
@ IDENTICAL
Everything is the same.
Definition: Schema.h:72
Writer object for FITS binary tables.
Definition: FitsWriter.h:25
FitsWriter(Fits *fits, int flags)
Construct from a wrapped cfitsio pointer.
Definition: FitsWriter.h:78
virtual void _writeRecord(BaseRecord const &source)
Write an individual record.
Definition: FitsWriter.cc:189
FitsWriter & operator=(FitsWriter &&)=default
FitsWriter & operator=(FitsWriter const &)=default
static void apply(OutputT &output, std::string const &mode, ContainerT const &container, int flags)
Driver for writing FITS files.
Definition: FitsWriter.h:37
void write(ContainerT const &container)
Write records in a container to disk.
Definition: FitsWriter.h:58
FitsWriter(FitsWriter const &)=default
FitsWriter(FitsWriter &&)=default
virtual void _writeTable(std::shared_ptr< BaseTable const > const &table, std::size_t nRows)
Write a table and its schema.
Definition: FitsWriter.cc:103
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
virtual void _finish()
Finish writing a catalog.
Definition: FitsWriter.h:94
Reports errors in the logical structure of the program.
Definition: Runtime.h:46
T insert(T... args)
const char * source()
Source function that allows astChannel to source from a Stream.
Definition: Stream.h:224
A base class for image defects.