LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
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
A Reader subclass for FITS binary tables.
Definition: FitsReader.h:27
void setHdu(int hdu, bool relative=false)
Set the current HDU.
Class for storing ordered metadata with comments.
Definition: PropertyList.h:81
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.
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...
#define PTR(...)
Definition: base.h:41
Factory class used to construct FitsReaders.
Definition: FitsReader.h:41
void _startRecords(BaseTable &table)
Should be called by any reimplementation of _readTable.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:194
FitsReader(Fits *fits, boost::shared_ptr< InputArchive >, int flags)
Construct from a wrapped cfitsio pointer and (ignored) InputArchive.
Definition: FitsReader.h:115
tbl::Schema schema
Definition: CoaddPsf.cc:324
Subclass for Factory that constructs a FitsReader.
Definition: FitsReader.h:62
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
static void _readSchema(Schema &schema, daf::base::PropertyList &metadata, bool stripMetadata)
boost::shared_ptr< ProcessRecords > _processor
Definition: FitsReader.h:146
Base class for all records.
Definition: BaseRecord.h:27
static ContainerT apply(Fits &fits, int flags=0)
Low-level entry point for reading FITS files into arbitrary containers.
Definition: FitsReader.h:103
virtual boost::shared_ptr< BaseTable > _readTable()
Create a new table of the appropriate type.
static ContainerT apply(SourceT &source, int hdu, int flags)
Entry point for reading FITS files into arbitrary containers.
Definition: FitsReader.h:88
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:28
virtual boost::shared_ptr< BaseRecord > _readRecord(boost::shared_ptr< BaseTable > const &table)
Read an individual record, creating it with the given table.
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
Factory(std::string const &name)
Create a factory that will be used when the AFW_TYPE fits key matches the given name.
Base class for all tables.
Definition: BaseTable.h:44