LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
FitsReader.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 #ifndef AFW_TABLE_IO_FitsReader_h_INCLUDED
3 #define AFW_TABLE_IO_FitsReader_h_INCLUDED
4 
5 #include "lsst/afw/fits.h"
11 
12 namespace lsst { namespace afw { namespace table { namespace io {
13 
29 class FitsReader {
30 public:
31 
39  explicit FitsReader(std::string const & persistedClassName);
40 
61  template <typename ContainerT>
62  static ContainerT apply(afw::fits::Fits & fits, int ioFlags, PTR(InputArchive) archive=PTR(InputArchive)()) {
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  }
90 
97  template <typename ContainerT, typename SourceT>
98  static ContainerT apply(SourceT & source, int hdu, int ioFlags, PTR(InputArchive) archive=PTR(InputArchive)()) {
100  fits.setHdu(hdu);
101  return apply<ContainerT>(fits, ioFlags, archive);
102  }
103 
123  virtual PTR(BaseTable) makeTable(
124  FitsSchemaInputMapper & mapper,
125  PTR(daf::base::PropertyList) metadata,
126  int ioFlags,
127  bool stripMetadata
128  ) const;
129 
134  virtual bool usesArchive(int ioFlags) const { return false; }
135 
136  virtual ~FitsReader() {}
137 
138 private:
139 
140  static FitsReader const * _lookupFitsReader(daf::base::PropertyList const & metadata);
141 
142  void _setupArchive(
143  afw::fits::Fits & fits,
144  FitsSchemaInputMapper & mapper,
145  PTR(InputArchive) archive,
146  int ioFlags
147  ) const;
148 
149 };
150 
151 }}}} // namespace lsst::afw::table::io
152 
153 #endif // !AFW_TABLE_IO_FitsReader_h_INCLUDED
virtual bool usesArchive(int ioFlags) const
Definition: FitsReader.h:134
#define PTR(...)
Definition: base.h:41
A utility class for reading FITS binary tables.
Definition: FitsReader.h:29
void setHdu(int hdu, bool relative=false)
Set the current HDU.
Class for storing ordered metadata with comments.
Definition: PropertyList.h:81
void readMetadata(daf::base::PropertySet &metadata, bool strip=false)
Read a FITS header into a PropertySet or PropertyList.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:194
void _setupArchive(afw::fits::Fits &fits, FitsSchemaInputMapper &mapper, boost::shared_ptr< InputArchive > archive, int ioFlags) const
std::size_t countRows()
Return the number of row in a table.
FitsReader(std::string const &persistedClassName)
int row
Definition: CR.cc:153
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
virtual boost::shared_ptr< BaseTable > makeTable(FitsSchemaInputMapper &mapper, boost::shared_ptr< daf::base::PropertyList > metadata, int ioFlags, bool stripMetadata) const
static ContainerT apply(SourceT &source, int hdu, int ioFlags, boost::shared_ptr< InputArchive > archive=boost::shared_ptr< InputArchive >())
Definition: FitsReader.h:98
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:28
static FitsReader const * _lookupFitsReader(daf::base::PropertyList const &metadata)
static ContainerT apply(afw::fits::Fits &fits, int ioFlags, boost::shared_ptr< InputArchive > archive=boost::shared_ptr< InputArchive >())
Definition: FitsReader.h:62
Base class for all tables.
Definition: BaseTable.h:44
void readRecord(BaseRecord &record, afw::fits::Fits &fits, std::size_t row)