LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
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"
9 
10 namespace lsst { namespace afw { namespace table { namespace io {
11 
27 class FitsReader : public Reader {
28 public:
29 
31 
41  class Factory {
42  public:
43 
45  virtual PTR(FitsReader) operator()(Fits * fits, PTR(InputArchive) archive, int flags) const = 0;
46 
47  virtual ~Factory() {}
48 
50  explicit Factory(std::string const & name);
51 
52  };
53 
61  template <typename ReaderT>
62  class FactoryT : public Factory {
63  public:
64 
66  virtual PTR(FitsReader) operator()(Fits * fits, PTR(InputArchive) archive, int flags) const {
67  return boost::make_shared<ReaderT>(fits, archive, flags);
68  }
69 
71  explicit FactoryT(std::string const & name) : Factory(name) {}
72 
73  };
74 
79  static PTR(FitsReader) make(Fits * fits, PTR(io::InputArchive) archive, int flags);
80 
87  template <typename ContainerT, typename SourceT>
88  static ContainerT apply(SourceT & source, int hdu, int flags) {
89  Fits fits(source, "r", Fits::AUTO_CLOSE | Fits::AUTO_CHECK);
90  fits.setHdu(hdu);
91  return apply<ContainerT>(fits, flags);
92  }
93 
95  template <typename ContainerT>
96  static ContainerT apply(Fits & fits, PTR(io::InputArchive) archive=PTR(io::InputArchive)(), int flags=0) {
97  PTR(FitsReader) reader = make(&fits, archive, flags);
98  return reader->template read<ContainerT>();
99  }
100 
102  template <typename ContainerT>
103  static ContainerT apply(Fits & fits, int flags=0) {
104  PTR(FitsReader) reader = make(&fits, PTR(io::InputArchive)(), flags);
105  return reader->template read<ContainerT>();
106  }
107 
115  explicit FitsReader(Fits * fits, PTR(InputArchive), int flags) : _fits(fits), _flags(flags) {}
116 
117 protected:
118 
120  virtual PTR(BaseTable) _readTable();
121 
123  virtual PTR(BaseRecord) _readRecord(PTR(BaseTable) const & table);
124 
126  void _startRecords(BaseTable & table);
127 
128  struct ProcessRecords;
129 
130  Fits * _fits; // cfitsio pointer in a conveniencer wrapper
131  int _flags; // subclass-defined flags to control FITS reading
132  std::size_t _row; // which row we're currently reading
133 private:
134 
135  friend class afw::table::Schema;
136 
137  // Implementation for Schema's constructors that take PropertyLists;
138  // it's here to keep FITS-related code a little more centralized.
139  static void _readSchema(
140  Schema & schema,
141  daf::base::PropertyList & metadata,
142  bool stripMetadata
143  );
144 
145  std::size_t _nRows; // how many total records there are in the FITS table
146  boost::shared_ptr<ProcessRecords> _processor; // a private Schema::forEach functor that reads records
147 };
148 
149 }}}} // namespace lsst::afw::table::io
150 
151 #endif // !AFW_TABLE_IO_FitsReader_h_INCLUDED
Defines the fields and offsets for a table.
Definition: Schema.h:46
A base class for code that reads table/record data from another source.
Definition: Reader.h:24
#define PTR(...)
Definition: base.h:41
FitsReader(Fits *fits, boost::shared_ptr< InputArchive >, int flags)
Construct from a wrapped cfitsio pointer and (ignored) InputArchive.
Definition: FitsReader.h:115
A Reader subclass for FITS binary tables.
Definition: FitsReader.h:27
Class for storing ordered metadata with comments.
Definition: PropertyList.h:81
void _startRecords(BaseTable &table)
Should be called by any reimplementation of _readTable.
Factory class used to construct FitsReaders.
Definition: FitsReader.h:41
virtual boost::shared_ptr< BaseRecord > _readRecord(boost::shared_ptr< BaseTable > const &table)
Read an individual record, creating it with the given table.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:194
static boost::shared_ptr< FitsReader > make(Fits *fits, boost::shared_ptr< io::InputArchive > archive, int flags)
Look for the header key (AFW_TYPE) that tells us the type of the FitsReader to use, then make it using the registered factory.
Factory(std::string const &name)
Create a factory that will be used when the AFW_TYPE fits key matches the given name.
tbl::Schema schema
Definition: CoaddPsf.cc:324
static void _readSchema(Schema &schema, daf::base::PropertyList &metadata, bool stripMetadata)
static ContainerT apply(Fits &fits, boost::shared_ptr< io::InputArchive > archive=boost::shared_ptr< io::InputArchive >(), int flags=0)
Low-level entry point for reading FITS files into arbitrary containers.
Definition: FitsReader.h:96
Subclass for Factory that constructs a FitsReader.
Definition: FitsReader.h:62
boost::shared_ptr< ProcessRecords > _processor
Definition: FitsReader.h:146
void setHdu(int hdu, bool relative=false)
Set the current HDU.
Base class for all records.
Definition: BaseRecord.h:27
virtual boost::shared_ptr< FitsReader > operator()(Fits *fits, boost::shared_ptr< InputArchive > archive, int flags) const =0
Create a new FITS reader from a cfitsio pointer holder and (optional) input archive and flags...
static ContainerT apply(SourceT &source, int hdu, int flags)
Entry point for reading FITS files into arbitrary containers.
Definition: FitsReader.h:88
static ContainerT apply(Fits &fits, int flags=0)
Low-level entry point for reading FITS files into arbitrary containers.
Definition: FitsReader.h:103
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:28
Base class for all tables.
Definition: BaseTable.h:44
FactoryT(std::string const &name)
Create a factory that will be used when the AFW_TYPE fits key matches the given name.
Definition: FitsReader.h:71
virtual boost::shared_ptr< BaseTable > _readTable()
Create a new table of the appropriate type.