LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
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 <type_traits>
6 
7 #include "lsst/afw/fits.h"
13 
14 namespace lsst { namespace afw { namespace table { namespace io {
15 
31 class FitsReader {
32 public:
33 
41  explicit FitsReader(std::string const & persistedClassName);
42 
63  template <typename ContainerT>
64  static ContainerT apply(afw::fits::Fits & fits, int ioFlags, PTR(InputArchive) archive=PTR(InputArchive)()) {
65  PTR(daf::base::PropertyList) metadata = std::make_shared<daf::base::PropertyList>();
66  fits.readMetadata(*metadata, true);
67  FitsReader const * reader = _lookupFitsReader(*metadata);
68  FitsSchemaInputMapper mapper(*metadata, true);
69  reader->_setupArchive(fits, mapper, archive, ioFlags);
70  PTR(BaseTable) table = reader->makeTable(mapper, metadata, ioFlags, true);
71  ContainerT container(std::dynamic_pointer_cast<typename ContainerT::Table>(table));
72  if (!container.getTable()) {
73  throw LSST_EXCEPT(
74  pex::exceptions::RuntimeError,
75  "Invalid table class for catalog."
76  );
77  }
78  std::size_t nRows = fits.countRows();
79  container.reserve(nRows);
80  for (std::size_t row = 0; row < nRows; ++row) {
81  mapper.readRecord(
82  // We need to be able to support reading Catalog<T const>, since it shares the same template
83  // as Catalog<T> (which invokes this method in readFits).
84  const_cast<typename std::remove_const<typename ContainerT::Record>::type&>(
85  *container.addNew()
86  ),
87  fits, row
88  );
89  }
90  return container;
91  }
92 
99  template <typename ContainerT, typename SourceT>
100  static ContainerT apply(SourceT & source, int hdu, int ioFlags, PTR(InputArchive) archive=PTR(InputArchive)()) {
102  fits.setHdu(hdu);
103  return apply<ContainerT>(fits, ioFlags, archive);
104  }
105 
125  virtual PTR(BaseTable) makeTable(
126  FitsSchemaInputMapper & mapper,
127  PTR(daf::base::PropertyList) metadata,
128  int ioFlags,
129  bool stripMetadata
130  ) const;
131 
136  virtual bool usesArchive(int ioFlags) const { return false; }
137 
138  virtual ~FitsReader() {}
139 
140 private:
141 
142  static FitsReader const * _lookupFitsReader(daf::base::PropertyList const & metadata);
143 
144  void _setupArchive(
145  afw::fits::Fits & fits,
146  FitsSchemaInputMapper & mapper,
147  PTR(InputArchive) archive,
148  int ioFlags
149  ) const;
150 
151 };
152 
153 }}}} // namespace lsst::afw::table::io
154 
155 #endif // !AFW_TABLE_IO_FitsReader_h_INCLUDED
virtual boost::shared_ptr< BaseTable > makeTable(FitsSchemaInputMapper &mapper, boost::shared_ptr< daf::base::PropertyList > metadata, int ioFlags, bool stripMetadata) const
A utility class for reading FITS binary tables.
Definition: FitsReader.h:31
static ContainerT apply(SourceT &source, int hdu, int ioFlags, boost::shared_ptr< InputArchive > archive=boost::shared_ptr< InputArchive >())
Definition: FitsReader.h:100
Class for storing ordered metadata with comments.
Definition: PropertyList.h:82
FitsReader(std::string const &persistedClassName)
static ContainerT apply(afw::fits::Fits &fits, int ioFlags, boost::shared_ptr< InputArchive > archive=boost::shared_ptr< InputArchive >())
Definition: FitsReader.h:64
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:201
virtual bool usesArchive(int ioFlags) const
Definition: FitsReader.h:136
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.
void setHdu(int hdu, bool relative=false)
Set the current HDU.
int row
Definition: CR.cc:159
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
#define PTR(...)
Definition: base.h:41
void readMetadata(daf::base::PropertySet &metadata, bool strip=false)
Read a FITS header into a PropertySet or PropertyList.
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:28
Base class for all tables.
Definition: BaseTable.h:43
static FitsReader const * _lookupFitsReader(daf::base::PropertyList const &metadata)
void readRecord(BaseRecord &record, afw::fits::Fits &fits, std::size_t row)