LSSTApplications  19.0.0-14-gb0260a2+4cd158d902,20.0.0+126303c00d,20.0.0+2f3d0e5c40,20.0.0+36ef800059,20.0.0+8d0ab3d2aa,20.0.0+bebc1f60e8,20.0.0+e271cb8385,20.0.0+e2e26847c2,20.0.0+eaf69e532d,20.0.0-1-g10df615+d6cc7df41f,20.0.0-1-g253301a+36ef800059,20.0.0-1-g2b7511a+bebc1f60e8,20.0.0-1-g4d801e7+6fee74fd2f,20.0.0-1-g5b95a8c+6c6c03acd5,20.0.0-1-g660595b+f45b7d88f4,20.0.0-1-gc96f8cb+d4517efcba,20.0.0-1-gd1c87d7+85c46248f3,20.0.0-1-gedffbd8+17eaf5db5c,20.0.0-16-g111fe95+d4517efcba,20.0.0-16-g233ea98+c27695f312,20.0.0-17-ga9337b4+cbc55e0393,20.0.0-19-gcdd82e7+317a1f5500,20.0.0-2-g4dae9ad+d4517efcba,20.0.0-2-g7818986+85c46248f3,20.0.0-2-gec03fae+ff10c6d78d,20.0.0-29-g26d13349+2d5e4f2fd7,20.0.0-3-g4cc78c6+63636aeed8,20.0.0-3-g6a8623c+317a1f5500,20.0.0-3-g750bffe+699cb77157,20.0.0-4-gfea843c+f45b7d88f4,20.0.0-5-g357b56b+f45b7d88f4,20.0.0-5-gfcebe35+ef19f498ed,20.0.0-54-gba713e9+a7d430d1e1,20.0.0-7-gcda7bf1+31d79aecbb,20.0.0-9-g61a2a9a3d+14f89e4eca,20.0.0-9-g70cec07d+482e8042f7,w.2020.40
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 <climits>
6 #include "lsst/base.h"
7 #include "lsst/pex/exceptions.h"
9 
10 namespace lsst {
11 namespace afw {
12 
13 namespace fits {
14 
15 class Fits;
16 class MemFileManager;
17 
18 } // namespace fits
19 
20 namespace table {
21 namespace io {
22 
23 class InputArchive;
24 class OutputArchive;
25 class OutputArchiveHandle;
26 class CatalogVector;
27 
32 
33 
40 
41 
48 #define LSST_ARCHIVE_ASSERT(EXPR) \
49  if (!(EXPR)) \
50  throw LSST_EXCEPT(lsst::afw::table::io::MalformedArchiveError, "Archive assertion failed: " #EXPR)
51 
74 class Persistable {
75 public:
83  void writeFits(std::string const& fileName, std::string const& mode = "w") const;
84 
92  void writeFits(fits::MemFileManager& manager, std::string const& mode = "w") const;
93 
99  void writeFits(fits::Fits& fitsfile) const;
100 
102  virtual bool isPersistable() const noexcept { return false; }
103 
104  virtual ~Persistable() noexcept = default;
105 
106 protected:
107  // convenient for derived classes not in afw::table::io
109 
115  virtual std::string getPersistenceName() const;
116 
125  virtual std::string getPythonModule() const;
126 
134  virtual void write(OutputArchiveHandle& handle) const;
135 
136  Persistable() noexcept = default;
137 
138  Persistable(Persistable const& other) noexcept = default;
139  Persistable(Persistable&& other) noexcept = default;
140 
141  Persistable& operator=(Persistable const& other) noexcept = default;
142  Persistable& operator=(Persistable&& other) noexcept = default;
143 
144 private:
145  friend class io::OutputArchive;
146  friend class io::InputArchive;
147 
148  template <typename T>
149  friend class PersistableFacade;
150 
151  static std::shared_ptr<Persistable> _readFits(std::string const& fileName, int hdu = fits::DEFAULT_HDU);
152 
153  static std::shared_ptr<Persistable> _readFits(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU);
154 
155  static std::shared_ptr<Persistable> _readFits(fits::Fits& fitsfile);
156 };
157 
175 template <typename T>
177 public:
184  return dynamicCast(Persistable::_readFits(fitsfile));
185  }
186 
194  static std::shared_ptr<T> readFits(std::string const& fileName, int hdu = fits::DEFAULT_HDU) {
195  return dynamicCast(Persistable::_readFits(fileName, hdu));
196  }
197 
206  return dynamicCast(Persistable::_readFits(manager, hdu));
207  }
208 
218  static std::shared_ptr<T> dynamicCast(std::shared_ptr<Persistable> const &ptr);
219 };
220 
229 protected:
230  typedef io::InputArchive InputArchive; // convenient for derived classes not in afw::table::io
232 
233 public:
245  explicit PersistableFactory(std::string const& name);
246 
249  CatalogVector const& catalogs) const = 0;
250 
258  static PersistableFactory const& lookup(std::string const& name, std::string const& module = "");
259 
260  virtual ~PersistableFactory() noexcept = default;
261 
262  // No copying
264  PersistableFactory& operator=(const PersistableFactory&) = delete;
265 
266  // No moving
268  PersistableFactory& operator=(PersistableFactory&&) = delete;
269 };
270 } // namespace io
271 } // namespace table
272 } // namespace afw
273 } // namespace lsst
274 
275 #endif // !AFW_TABLE_IO_Persistable_h_INCLUDED
lsst::afw::table::io::PersistenceError
An exception thrown when problems occur during persistence.
Definition: Persistable.h:31
lsst::afw::table::io::Persistable::getPythonModule
virtual std::string getPythonModule() const
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
Definition: Persistable.cc:36
lsst::afw::table::io::Persistable::writeFits
void writeFits(std::string const &fileName, std::string const &mode="w") const
Write the object to a regular FITS file.
Definition: Persistable.cc:24
std::string
STL class.
std::shared_ptr
STL class.
lsst::afw::fits::DEFAULT_HDU
const int DEFAULT_HDU
Specify that the default HDU should be read.
Definition: fitsDefaults.h:18
base.h
lsst::afw::table::io::OutputArchiveHandle
An object passed to Persistable::write to allow it to persist itself.
Definition: OutputArchive.h:118
lsst::afw::fits::Fits
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:297
lsst::afw::table::io::Persistable::~Persistable
virtual ~Persistable() noexcept=default
lsst::afw
Definition: imageAlgorithm.dox:1
lsst::afw::table::io::InputArchive
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:31
lsst::afw::table::io::PersistableFacade::readFits
static std::shared_ptr< T > readFits(fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU)
Read an object from a FITS file in memory.
Definition: Persistable.h:205
lsst::afw::fits::MemFileManager
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:121
lsst::afw::geom.transform.transformContinued.name
string name
Definition: transformContinued.py:32
lsst::afw::table::io::Persistable::isPersistable
virtual bool isPersistable() const noexcept
Return true if this particular object can be persisted using afw::table::io.
Definition: Persistable.h:102
lsst::afw::table::io::PersistableFactory::~PersistableFactory
virtual ~PersistableFactory() noexcept=default
lsst::afw::table::io::PersistableFactory::CatalogVector
io::CatalogVector CatalogVector
Definition: Persistable.h:231
lsst::afw::table::io::PersistableFactory::InputArchive
io::InputArchive InputArchive
Definition: Persistable.h:230
lsst::afw::table::io::Persistable::getPersistenceName
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
Definition: Persistable.cc:34
fits
Fits * fits
Definition: FitsWriter.cc:90
fitsDefaults.h
other
ItemVariant const * other
Definition: Schema.cc:56
lsst::afw::table::io::CatalogVector
A vector of catalogs used by Persistable.
Definition: CatalogVector.h:29
lsst::afw::table::io::Persistable::write
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
Definition: Persistable.cc:38
lsst::afw::table::io::PersistableFactory::read
virtual std::shared_ptr< Persistable > read(InputArchive const &archive, CatalogVector const &catalogs) const =0
Construct a new object from the given InputArchive and vector of catalogs.
lsst::afw::table::io::PersistableFactory
A base class for factory classes used to reconstruct objects from records.
Definition: Persistable.h:228
lsst::afw::table::io::OutputArchive
A multi-catalog archive object used to save table::io::Persistable objects.
Definition: OutputArchive.h:34
ptr
uint64_t * ptr
Definition: RangeSet.cc:88
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
lsst::afw::table::io::Persistable
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:74
lsst.pex::exceptions::IoError
Reports errors in external input/output operations.
Definition: Runtime.h:160
exceptions.h
lsst::afw::table::io::MalformedArchiveError
An exception thrown when an InputArchive's contents do not make sense.
Definition: Persistable.h:39
lsst::afw::table::io::PersistableFacade::readFits
static std::shared_ptr< T > readFits(fits::Fits &fitsfile)
Read an object from an already open FITS object.
Definition: Persistable.h:183
std
STL namespace.
lsst::afw::table::io::PersistableFacade
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:176
LSST_EXCEPTION_TYPE
#define LSST_EXCEPTION_TYPE(t, b, c)
Macro used to define new types of exceptions without additional data.
Definition: Exception.h:69
lsst::afw::table::io::PersistableFacade::readFits
static std::shared_ptr< T > readFits(std::string const &fileName, int hdu=fits::DEFAULT_HDU)
Read an object from a regular FITS file.
Definition: Persistable.h:194
lsst::meas::modelfit.psf.psfContinued.module
module
Definition: psfContinued.py:42