LSSTApplications  17.0+124,17.0+14,17.0+73,18.0.0+37,18.0.0+80,18.0.0-4-g68ffd23+4,18.1.0-1-g0001055+12,18.1.0-1-g03d53ef+5,18.1.0-1-g1349e88+55,18.1.0-1-g2505f39+44,18.1.0-1-g5315e5e+4,18.1.0-1-g5e4b7ea+14,18.1.0-1-g7e8fceb+4,18.1.0-1-g85f8cd4+48,18.1.0-1-g8ff0b9f+4,18.1.0-1-ga2c679d+1,18.1.0-1-gd55f500+35,18.1.0-10-gb58edde+2,18.1.0-11-g0997b02+4,18.1.0-13-gfe4edf0b+12,18.1.0-14-g259bd21+21,18.1.0-19-gdb69f3f+2,18.1.0-2-g5f9922c+24,18.1.0-2-gd3b74e5+11,18.1.0-2-gfbf3545+32,18.1.0-26-g728bddb4+5,18.1.0-27-g6ff7ca9+2,18.1.0-3-g52aa583+25,18.1.0-3-g8ea57af+9,18.1.0-3-gb69f684+42,18.1.0-3-gfcaddf3+6,18.1.0-32-gd8786685a,18.1.0-4-gf3f9b77+6,18.1.0-5-g1dd662b+2,18.1.0-5-g6dbcb01+41,18.1.0-6-gae77429+3,18.1.0-7-g9d75d83+9,18.1.0-7-gae09a6d+30,18.1.0-9-gc381ef5+4,w.2019.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;
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
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
Basic LSST definitions.
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