LSST Applications g070148d5b3+33e5256705,g0d53e28543+25c8b88941,g0da5cf3356+2dd1178308,g1081da9e2a+62d12e78cb,g17e5ecfddb+7e422d6136,g1c76d35bf8+ede3a706f7,g295839609d+225697d880,g2e2c1a68ba+cc1f6f037e,g2ffcdf413f+853cd4dcde,g38293774b4+62d12e78cb,g3b44f30a73+d953f1ac34,g48ccf36440+885b902d19,g4b2f1765b6+7dedbde6d2,g5320a0a9f6+0c5d6105b6,g56b687f8c9+ede3a706f7,g5c4744a4d9+ef6ac23297,g5ffd174ac0+0c5d6105b6,g6075d09f38+66af417445,g667d525e37+2ced63db88,g670421136f+2ced63db88,g71f27ac40c+2ced63db88,g774830318a+463cbe8d1f,g7876bc68e5+1d137996f1,g7985c39107+62d12e78cb,g7fdac2220c+0fd8241c05,g96f01af41f+368e6903a7,g9ca82378b8+2ced63db88,g9d27549199+ef6ac23297,gabe93b2c52+e3573e3735,gb065e2a02a+3dfbe639da,gbc3249ced9+0c5d6105b6,gbec6a3398f+0c5d6105b6,gc9534b9d65+35b9f25267,gd01420fc67+0c5d6105b6,geee7ff78d7+a14128c129,gf63283c776+ede3a706f7,gfed783d017+0c5d6105b6,w.2022.47
LSST Data Management Base Package
Loading...
Searching...
No Matches
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) {
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
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
Basic LSST definitions.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:308
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)