LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | List of all members
lsst::afw::table::io::FitsReader Class Reference

A utility class for reading FITS binary tables. More...

#include <FitsReader.h>

Public Member Functions

 FitsReader (std::string const &persistedClassName)
 
virtual boost::shared_ptr
< BaseTable
makeTable (FitsSchemaInputMapper &mapper, boost::shared_ptr< daf::base::PropertyList > metadata, int ioFlags, bool stripMetadata) const
 
virtual bool usesArchive (int ioFlags) const
 
virtual ~FitsReader ()
 

Static Public Member Functions

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

Private Member Functions

void _setupArchive (afw::fits::Fits &fits, FitsSchemaInputMapper &mapper, boost::shared_ptr< InputArchive > archive, int ioFlags) const
 

Static Private Member Functions

static FitsReader const * _lookupFitsReader (daf::base::PropertyList const &metadata)
 

Detailed Description

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.

Constructor & Destructor Documentation

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.

virtual lsst::afw::table::io::FitsReader::~FitsReader ( )
inlinevirtual

Definition at line 136 of file FitsReader.h.

136 {}

Member Function Documentation

static FitsReader const* lsst::afw::table::io::FitsReader::_lookupFitsReader ( daf::base::PropertyList const &  metadata)
staticprivate
void lsst::afw::table::io::FitsReader::_setupArchive ( afw::fits::Fits fits,
FitsSchemaInputMapper mapper,
boost::shared_ptr< InputArchive archive,
int  ioFlags 
) const
private
template<typename ContainerT >
static ContainerT lsst::afw::table::io::FitsReader::apply ( afw::fits::Fits fits,
int  ioFlags,
boost::shared_ptr< InputArchive archive = boost::shared_ptr< InputArchive >() 
)
inlinestatic

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]fitsAn afw::fits::Fits helper that points to a FITS binary table HDU.
[in]ioFlagsA 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]archiveAn 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.

62  {
63  PTR(daf::base::PropertyList) metadata = boost::make_shared<daf::base::PropertyList>();
64  fits.readMetadata(*metadata, true);
65  FitsReader const * reader = _lookupFitsReader(*metadata);
66  FitsSchemaInputMapper mapper(*metadata, true);
67  reader->_setupArchive(fits, mapper, archive, ioFlags);
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()) {
71  throw LSST_EXCEPT(
72  pex::exceptions::RuntimeError,
73  "Invalid table class for catalog."
74  );
75  }
76  std::size_t nRows = fits.countRows();
77  container.reserve(nRows);
78  for (std::size_t row = 0; row < nRows; ++row) {
79  mapper.readRecord(
80  // We need to be able to support reading Catalog<T const>, since it shares the same template
81  // as Catalog<T> (which invokes this method in readFits).
82  const_cast<typename boost::remove_const<typename ContainerT::Record>::type&>(
83  *container.addNew()
84  ),
85  fits, row
86  );
87  }
88  return container;
89  }
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.
Definition: PropertyList.h:81
FitsReader(std::string const &persistedClassName)
#define PTR(...)
Definition: base.h:41
lsst::daf::base::PropertyList PropertyList
Definition: Wcs.cc:59
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())
Definition: saturated.cc:47
int row
Definition: CR.cc:153
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
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)
template<typename ContainerT , typename SourceT >
static ContainerT lsst::afw::table::io::FitsReader::apply ( SourceT &  source,
int  hdu,
int  ioFlags,
boost::shared_ptr< InputArchive archive = boost::shared_ptr< InputArchive >() 
)
inlinestatic

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.

Definition at line 98 of file FitsReader.h.

98  {
99  afw::fits::Fits fits(source, "r", afw::fits::Fits::AUTO_CLOSE | afw::fits::Fits::AUTO_CHECK);
100  fits.setHdu(hdu);
101  return apply<ContainerT>(fits, ioFlags, archive);
102  }
virtual boost::shared_ptr< BaseTable > lsst::afw::table::io::FitsReader::makeTable ( FitsSchemaInputMapper mapper,
boost::shared_ptr< daf::base::PropertyList metadata,
int  ioFlags,
bool  stripMetadata 
) const
virtual

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]mapperA representation of the FITS binary table schema, capable of producing an afw::table::Schema from it while allowing customization of the mapping beforehand.
[in]metadataEntries from the FITS header, which should usually be attached to the returned table object via its setMetadata method.
[in]ioFlagsSubclass-dependent bitflags that control optional persistence behaavior (see e.g. SourceFitsFlags).
[in]stripMetadataIf True, remove entries from the metadata that were added by the persistence code.
virtual bool lsst::afw::table::io::FitsReader::usesArchive ( int  ioFlags) const
inlinevirtual

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

Definition at line 134 of file FitsReader.h.

134 { return false; }

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