LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
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"
10#include "lsst/afw/fits.h"
11
12namespace lsst {
13namespace afw {
14namespace table {
15namespace io {
16
26public:
28
36 template <typename OutputT, typename ContainerT>
37 static void apply(OutputT& output, std::string const& mode, ContainerT const& container, int flags) {
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
86protected:
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
100private:
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
static void apply(OutputT &output, std::string const &mode, ContainerT const &container, int flags)
Driver for writing FITS files.
Definition: FitsWriter.h:37
FitsWriter & operator=(FitsWriter const &)=default
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.