Class FitsReader

Class Documentation

class FitsReader

A utility class for reading FITS binary tables.

FitsReader itself provides the implementation for reading standard FITS binary tables (with a limited subset of FITS column types), but it also allows subclasses to be used instead, depending on what’s actually in the FITS file. If the FITS header has the key “AFW_TABLE” with a value other than “BASE”, FitsReader::apply consults a registry of subclasses to retreive one corresponding to that key. This means the type of records/tables loaded correctly depends on the file itself, rather than the caller. For instance, if you load a FITS table corresponding to a saved SourceCatalog using BaseCatalog::readFits, you’ll actually get a BaseCatalog whose record are actually SourceRecords and whose table is actually a SourceTable. On the other hand, if you try to load a non-Source FITS table into a SourceCatalog, you’ll get an exception when it tries to dynamic_cast the table to a SourceTable.

Public Functions

FitsReader(std::string const &persistedClassName)

Construct a FitsReader, registering it to be used for all persisted tables with the given tag.

Because they need to live in the static registry, each distinct subclass of FitsReader should be constructed only once, in a static-scope variable. The FitsReader constructor will add a pointer to that variable to the registry.

FitsReader(FitsReader const&)
FitsReader(FitsReader&&)
FitsReader &operator=(FitsReader const&)
FitsReader &operator=(FitsReader&&)
virtual std::shared_ptr<BaseTable> makeTable(FitsSchemaInputMapper &mapper, std::shared_ptr<daf::base::PropertyList> metadata, int ioFlags, bool stripMetadata) const

Callback to create a Table object from a FITS binary table schema.

Subclass readers must override to return the appropriate Table subclass. Most implementations can simply call mapper.finalize() to create the Schema, then construct a new Table and set its metadata to the given PropertyList. Readers for record classes that have first-class objects in addition to regular fields should call mapper.customize() with a custom FitsColumnReader before calling finalize().

Parameters
  • [in] mapper: A representation of the FITS binary table schema, capable of producing an afw::table::Schema from it while allowing customization of the mapping beforehand.

  • [in] metadata: Entries from the FITS header, which should usually be attached to the returned table object via its setMetadata method.

  • [in] ioFlags: Subclass-dependent bitflags that control optional persistence behaavior (see e.g. SourceFitsFlags).

  • [in] stripMetadata: If True, remove entries from the metadata that were added by the persistence code.

virtual bool usesArchive(int ioFlags) const

Callback that should return true if the FitsReader subclass makes use of an InputArchive to read first-class objects from additional FITS HDUs.

virtual ~FitsReader()

Public Static Functions

template<typename ContainerT>
static ContainerT apply(afw::fits::Fits &fits, int ioFlags, std::shared_ptr<InputArchive> archive = std::shared_ptr<InputArchive>())

Create a new Catalog by reading a FITS binary table.

This is the lower-level implementation delegated to by all Catalog::readFits() methods. It creates a new Catalog of type ContainerT, creates a FitsReader according to the tag found in the file, then reads the schema and adds records to the Catalog.

Parameters
  • [in] fits: An afw::fits::Fits helper that points to a FITS binary table HDU.

  • [in] ioFlags: A set of subclass-dependent bitflags that control optional aspects of FITS persistence. For instance, SourceFitsFlags are used by SourceCatalog to control how to read and write Footprints.

  • [in] archive: An archive of Persistables containing objects that may be associated with table records. For record subclasses that have associated Persistables (e.g. SourceRecord Footprints, or ExposureRecord Psfs), this archive is usually persisted in additional HDUs in the FITS file after the main binary table, and will be loaded automatically if the passed archive is null. The explicit archive argument is provided only for cases in which the catalog itself is part of a larger object, and does not “own” its own archive (e.g. CoaddPsf persistence).

template<typename ContainerT, typename SourceT>
static ContainerT apply(SourceT &source, int hdu, int ioFlags, std::shared_ptr<InputArchive> archive = std::shared_ptr<InputArchive>())

Create a new Catalog by reading a FITS file.

This is a simply a convenience function that creates an afw::fits::Fits object from either a string filename or a afw::fits::MemFileManager, then calls the other apply() overload.