LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
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  ~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:296
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:44
Basic LSST definitions.
Everything is the same.
Definition: Schema.h:71
FitsWriter(Fits *fits, int flags)
Construct from a wrapped cfitsio pointer.
Definition: FitsWriter.h:79