LSST Applications 24.1.6,g063fba187b+56b85ce14a,g0f08755f38+df8a265115,g12f32b3c4e+891a09f10d,g1524ad2192+7a5d7b3fbd,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g28da252d5a+07cb1400be,g2bbee38e9b+ae03bbfc84,g2bc492864f+ae03bbfc84,g3156d2b45e+6e55a43351,g347aa1857d+ae03bbfc84,g35bb328faa+a8ce1bb630,g3a166c0a6a+ae03bbfc84,g3e281a1b8c+c5dd892a6c,g414038480c+6b9177ef31,g41af890bb2+8f257c4c0b,g781aacb6e4+a8ce1bb630,g7af13505b9+7137b3b17d,g80478fca09+6df6903293,g82479be7b0+091ce1d07f,g858d7b2824+df8a265115,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,g9726552aa6+414189b318,ga5288a1d22+4a2bca08d7,gacef1a1666+c9a8ff65f4,gb58c049af0+d64f4d3760,gbcfae0f0a0+de1d42d831,gc28159a63d+ae03bbfc84,gcf0d15dbbd+72117bf34e,gda6a2b7d83+72117bf34e,gdaeeff99f8+1711a396fd,ge500cccec5+c8c9c9af63,ge79ae78c31+ae03bbfc84,gf0baf85859+c1f95f4921,gfa517265be+df8a265115,gfa999e8aa5+17cd334064,gfb92a5be7c+df8a265115
LSST Data Management Base Package
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
lsst::afw::table::io::FitsWriter Class Reference

Writer object for FITS binary tables. More...

#include <FitsWriter.h>

Classes

struct  ProcessRecords
 

Public Types

using Fits = afw::fits::Fits
 

Public Member Functions

template<typename ContainerT >
void write (ContainerT const &container)
 Write records in a container to disk.
 
 FitsWriter (Fits *fits, int flags)
 Construct from a wrapped cfitsio pointer.
 
 FitsWriter (FitsWriter const &)=default
 
 FitsWriter (FitsWriter &&)=default
 
FitsWriteroperator= (FitsWriter const &)=default
 
FitsWriteroperator= (FitsWriter &&)=default
 
virtual ~FitsWriter ()=default
 

Static Public Member Functions

template<typename OutputT , typename ContainerT >
static void apply (OutputT &output, std::string const &mode, ContainerT const &container, int flags)
 Driver for writing FITS files.
 
template<typename ContainerT >
static void apply (Fits &fits, ContainerT const &container, int flags)
 Low-level driver for writing FITS files, operating on an open FITS file.
 

Protected Member Functions

virtual void _writeTable (std::shared_ptr< BaseTable const > const &table, std::size_t nRows)
 Write a table and its schema.
 
virtual void _writeRecord (BaseRecord const &source)
 Write an individual record.
 
virtual void _finish ()
 Finish writing a catalog.
 

Protected Attributes

Fits_fits
 
int _flags
 
std::size_t _row
 

Detailed Description

Writer object for FITS binary tables.

FitsWriter itself provides support for writing FITS binary tables from base containers. Derived record/base pairs should derive their own writer from FitsWriter and reimplement BaseTable::makeFitsWriter to return it. Subclasses will usually delegate most of the work back to FitsWriter.

Definition at line 25 of file FitsWriter.h.

Member Typedef Documentation

◆ Fits

Definition at line 27 of file FitsWriter.h.

Constructor & Destructor Documentation

◆ FitsWriter() [1/3]

lsst::afw::table::io::FitsWriter::FitsWriter ( Fits * fits,
int flags )
inlineexplicit

Construct from a wrapped cfitsio pointer.

Definition at line 78 of file FitsWriter.h.

◆ FitsWriter() [2/3]

lsst::afw::table::io::FitsWriter::FitsWriter ( FitsWriter const & )
default

◆ FitsWriter() [3/3]

lsst::afw::table::io::FitsWriter::FitsWriter ( FitsWriter && )
default

◆ ~FitsWriter()

virtual lsst::afw::table::io::FitsWriter::~FitsWriter ( )
virtualdefault

Member Function Documentation

◆ _finish()

virtual void lsst::afw::table::io::FitsWriter::_finish ( )
inlineprotectedvirtual

Finish writing a catalog.

Definition at line 94 of file FitsWriter.h.

94{}

◆ _writeRecord()

void lsst::afw::table::io::FitsWriter::_writeRecord ( BaseRecord const & source)
protectedvirtual

Write an individual record.

Definition at line 189 of file FitsWriter.cc.

189 {
190 ++_row;
191 _processor->apply(&record);
192}

◆ _writeTable()

void lsst::afw::table::io::FitsWriter::_writeTable ( std::shared_ptr< BaseTable const > const & table,
std::size_t nRows )
protectedvirtual

Write a table and its schema.

Definition at line 103 of file FitsWriter.cc.

103 {
104 Schema schema = table->getSchema();
106 LSST_FITS_CHECK_STATUS(*_fits, "creating table");
107 std::size_t nFlags = schema.getFlagFieldCount();
108 if (nFlags > 0) {
109 int n = _fits->addColumn<bool>("flags", nFlags, "bits for all Flag fields; see also TFLAGn");
110 _fits->writeKey("FLAGCOL", n + 1, "Column number for the bitflags.");
111 }
112 ProcessSchema::apply(*_fits, schema);
113 writeAliasMap(*_fits, *schema.getAliasMap());
114 // write the version number to the fits header, plus any other metadata
115 std::shared_ptr<daf::base::PropertyList> metadata = table->getMetadata();
116 if (!metadata) {
117 metadata = std::make_shared<daf::base::PropertyList>();
118 }
119 metadata->set<int>("AFW_TABLE_VERSION", Schema::VERSION);
120 _fits->writeMetadata(*metadata);
121 // In case the metadata was attached to the table, clean it up.
122 metadata->remove("AFW_TABLE_VERSION");
123 _row = -1;
124 _fits->addRows(nRows);
125 _processor = std::make_shared<ProcessRecords>(_fits, schema, nFlags, _row);
126}
int nFlags
Definition FitsWriter.cc:91
table::Schema schema
Definition python.h:134
void writeKey(std::string const &key, T const &value, std::string const &comment)
Add a FITS header key to the bottom of the header.
Definition fits.cc:686
void createTable()
Create a new binary table extension.
Definition fits.cc:1143
int addColumn(std::string const &ttype, int size, std::string const &comment)
Add a column to a table.
Definition fits.cc:1166
void writeMetadata(daf::base::PropertySet const &metadata)
Read a FITS header into a PropertySet or PropertyList.
Definition fits.cc:1121
std::size_t addRows(std::size_t nRows)
Append rows to a table, and return the index of the first new row.
Definition fits.cc:1175
static int const VERSION
Definition Schema.h:57
#define LSST_FITS_CHECK_STATUS(fitsObj,...)
Throw a FitsError exception if the status of the given Fits object is nonzero.
Definition fits.h:111

◆ apply() [1/2]

template<typename ContainerT >
static void lsst::afw::table::io::FitsWriter::apply ( Fits & fits,
ContainerT const & container,
int flags )
inlinestatic

Low-level driver for writing FITS files, operating on an open FITS file.

Definition at line 44 of file FitsWriter.h.

44 {
46 std::static_pointer_cast<BaseTable const>(container.getTable())->makeFitsWriter(&fits, flags);
47 writer->write(container);
48 }

◆ apply() [2/2]

template<typename OutputT , typename ContainerT >
static void lsst::afw::table::io::FitsWriter::apply ( OutputT & output,
std::string const & mode,
ContainerT const & container,
int flags )
inlinestatic

Driver for writing FITS files.

A container class will usually provide a member function that calls this driver, which opens the FITS file, calls makeFitsWriter on the container's table, and then calls Writer::write on it.

Definition at line 37 of file FitsWriter.h.

37 {
38 Fits fits(output, mode, Fits::AUTO_CLOSE | Fits::AUTO_CHECK);
39 apply(fits, container, flags);
40 }
static void apply(OutputT &output, std::string const &mode, ContainerT const &container, int flags)
Driver for writing FITS files.
Definition FitsWriter.h:37

◆ operator=() [1/2]

FitsWriter & lsst::afw::table::io::FitsWriter::operator= ( FitsWriter && )
default

◆ operator=() [2/2]

FitsWriter & lsst::afw::table::io::FitsWriter::operator= ( FitsWriter const & )
default

◆ write()

template<typename ContainerT >
void lsst::afw::table::io::FitsWriter::write ( ContainerT const & container)
inline

Write records in a container to disk.

The given container must have a getTable() member function that returns a shared_ptr to a table, and the iterators returned by begin() and end() must dereference to a type convertible to BaseRecord const &.

Definition at line 58 of file FitsWriter.h.

58 {
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) !=
66 throw LSST_EXCEPT(pex::exceptions::LogicError,
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 }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
@ IDENTICAL
Everything is the same.
Definition Schema.h:72
virtual void _writeRecord(BaseRecord const &source)
Write an individual record.
virtual void _writeTable(std::shared_ptr< BaseTable const > const &table, std::size_t nRows)
Write a table and its schema.
virtual void _finish()
Finish writing a catalog.
Definition FitsWriter.h:94
T insert(T... args)

Member Data Documentation

◆ _fits

Fits* lsst::afw::table::io::FitsWriter::_fits
protected

Definition at line 96 of file FitsWriter.h.

◆ _flags

int lsst::afw::table::io::FitsWriter::_flags
protected

Definition at line 97 of file FitsWriter.h.

◆ _row

std::size_t lsst::afw::table::io::FitsWriter::_row
protected

Definition at line 98 of file FitsWriter.h.


The documentation for this class was generated from the following files: