LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
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.