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.
Definition at line 29 of file FitsReader.h.
lsst::afw::table::io::FitsReader::FitsReader |
( |
std::string const & |
persistedClassName | ) |
|
|
explicit |
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.
template<typename ContainerT >
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). |
Definition at line 62 of file FitsReader.h.
66 FitsSchemaInputMapper mapper(*metadata, true);
68 PTR(BaseTable) table = reader->
makeTable(mapper, metadata, ioFlags, true);
69 ContainerT container(boost::dynamic_pointer_cast<typename ContainerT::Table>(table));
70 if (!container.getTable()) {
72 pex::exceptions::RuntimeError,
73 "Invalid table class for catalog."
76 std::size_t nRows = fits.countRows();
77 container.reserve(nRows);
78 for (std::size_t
row = 0;
row < nRows; ++
row) {
82 const_cast<typename boost::remove_const<typename ContainerT::Record>::type&
>(
virtual boost::shared_ptr< BaseTable > makeTable(FitsSchemaInputMapper &mapper, boost::shared_ptr< daf::base::PropertyList > metadata, int ioFlags, bool stripMetadata) const
Class for storing ordered metadata with comments.
FitsReader(std::string const &persistedClassName)
lsst::daf::base::PropertyList PropertyList
void _setupArchive(afw::fits::Fits &fits, FitsSchemaInputMapper &mapper, boost::shared_ptr< InputArchive > archive, int ioFlags) const
if(width!=gim.getWidth()||height!=gim.getHeight()||x0!=gim.getX0()||y0!=gim.getY0())
#define LSST_EXCEPT(type,...)
boost::shared_ptr< daf::base::PropertySet > readMetadata(std::string const &fileName, int hdu=0, bool strip=false)
Return the metadata (header entries) from a FITS file.
static FitsReader const * _lookupFitsReader(daf::base::PropertyList const &metadata)