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
Persistable.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 #ifndef AFW_TABLE_IO_Persistable_h_INCLUDED
3 #define AFW_TABLE_IO_Persistable_h_INCLUDED
4 
5 #include "boost/noncopyable.hpp"
6 
7 #include "lsst/base.h"
8 #include "lsst/pex/exceptions.h"
9 
10 namespace lsst { namespace afw {
11 
12 namespace fits {
13 
14 class Fits;
15 class MemFileManager;
16 
17 } // namespace fits
18 
19 namespace table { namespace io {
20 
21 class InputArchive;
22 class OutputArchive;
23 class OutputArchiveHandle;
24 class CatalogVector;
25 
29 LSST_EXCEPTION_TYPE(PersistenceError, lsst::pex::exceptions::IoError,
30  lsst::afw::table::io::PersistenceError)
31 
32 
37 LSST_EXCEPTION_TYPE(MalformedArchiveError, lsst::afw::table::io::PersistenceError,
38  lsst::afw::table::io::MalformedArchiveError)
39 
47 #define LSST_ARCHIVE_ASSERT(EXPR) \
48  if (!(EXPR)) throw LSST_EXCEPT( \
49  lsst::afw::table::io::MalformedArchiveError, \
50  "Archive assertion failed: " # EXPR)
51 
74 class Persistable {
75 public:
76 
84  void writeFits(std::string const & fileName, std::string const & mode="w") const;
85 
93  void writeFits(fits::MemFileManager & manager, std::string const & mode="w") const;
94 
95 #ifndef SWIG // only expose the higher-level interfaces to Python
96 
102  void writeFits(fits::Fits & fitsfile) const;
103 
104 #endif // !SWIG
105 
107  virtual bool isPersistable() const { return false; }
108 
109  virtual ~Persistable() {}
110 
111 protected:
112 
113  // convenient for derived classes not in afw::table::io
115 
121  virtual std::string getPersistenceName() const;
122 
131  virtual std::string getPythonModule() const;
132 
140  virtual void write(OutputArchiveHandle & handle) const;
141 
143 
144  Persistable(Persistable const & other) {}
145 
146  void operator=(Persistable const & other) {}
147 
148 private:
149 
150  friend class io::OutputArchive;
151  friend class io::InputArchive;
152 
153  template <typename T> friend class PersistableFacade;
154 
155  static PTR(Persistable) _readFits(std::string const & fileName, int hdu=0);
156 
157  static PTR(Persistable) _readFits(fits::MemFileManager & manager, int hdu=0);
158 
159  static PTR(Persistable) _readFits(fits::Fits & fitsfile);
160 
161 };
162 
181 template <typename T>
183 public:
184 
185 #ifndef SWIG
186 
192  static PTR(T) readFits(fits::Fits & fitsfile) {
193  return boost::dynamic_pointer_cast<T>(Persistable::_readFits(fitsfile));
194  }
195 
196 #endif // !SWIG
197 
205  static PTR(T) readFits(std::string const & fileName, int hdu=0) {
206  return boost::dynamic_pointer_cast<T>(Persistable::_readFits(fileName, hdu));
207  }
208 
216  static PTR(T) readFits(fits::MemFileManager & manager, int hdu=0) {
217  return boost::dynamic_pointer_cast<T>(Persistable::_readFits(manager, hdu));
218  }
219 
220 };
221 
222 #ifndef SWIG
223 
231 class PersistableFactory : private boost::noncopyable {
232 protected:
233  typedef io::InputArchive InputArchive; // convenient for derived classes not in afw::table::io
235 public:
236 
248  explicit PersistableFactory(std::string const & name);
249 
251  virtual PTR(Persistable) read(InputArchive const & archive, CatalogVector const & catalogs) const = 0;
252 
260  static PersistableFactory const & lookup(std::string const & name, std::string const & module="");
261 
262  virtual ~PersistableFactory() {}
263 };
264 
265 #endif // !SWIG
266 
267 }}}} // namespace lsst::afw::table::io
268 
269 #endif // !AFW_TABLE_IO_Persistable_h_INCLUDED
LSST_EXCEPTION_TYPE(PersistenceError, lsst::pex::exceptions::IoError, lsst::afw::table::io::PersistenceError) LSST_EXCEPTION_TYPE(MalformedArchiveError
An exception thrown when problems occur during persistence.
table::Key< std::string > name
Definition: ApCorrMap.cc:71
An object passed to Persistable::write to allow it to persist itself.
void writeFits(std::string const &fileName, std::string const &mode="w") const
Write the object to a regular FITS file.
Include files required for standard LSST Exception handling.
A base class for factory classes used to reconstruct objects from records.
Definition: Persistable.h:231
#define PTR(...)
Definition: base.h:41
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:194
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:74
A multi-catalog archive object used to save table::io::Persistable objects.
Definition: OutputArchive.h:33
Persistable(Persistable const &other)
Definition: Persistable.h:144
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: Persistable.h:107
void operator=(Persistable const &other)
Definition: Persistable.h:146
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:106
virtual std::string getPythonModule() const
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
static boost::shared_ptr< Persistable > _readFits(std::string const &fileName, int hdu=0)
A vector of catalogs used by Persistable.
Definition: CatalogVector.h:26
io::OutputArchiveHandle OutputArchiveHandle
Definition: Persistable.h:114
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:28
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:182
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.