LSST Applications  21.0.0+3c14b91618,21.0.0+9f51b1e3f7,21.0.0-1-ga51b5d4+6691386486,21.0.0-10-g2408eff+1a328412bf,21.0.0-10-g560fb7b+52fd22d7b4,21.0.0-10-g8d1d15d+2f9043cae0,21.0.0-10-gcf60f90+d15de71c48,21.0.0-11-g25eff31+d43066e4ef,21.0.0-15-g490e301a+a676f0d5cf,21.0.0-2-g103fe59+4758c8ef83,21.0.0-2-g1367e85+a9f57e981a,21.0.0-2-g45278ab+9f51b1e3f7,21.0.0-2-g5242d73+a9f57e981a,21.0.0-2-g7f82c8f+1bcc828e4f,21.0.0-2-g8f08a60+e6fd6d9ff9,21.0.0-2-ga326454+1bcc828e4f,21.0.0-2-gde069b7+66c51b65da,21.0.0-2-gecfae73+251b9830c3,21.0.0-2-gfc62afb+a9f57e981a,21.0.0-20-g09baf175d+e1e7d1c708,21.0.0-3-g357aad2+854c3902c3,21.0.0-3-g4be5c26+a9f57e981a,21.0.0-3-g65f322c+feaa1990e9,21.0.0-3-g7d9da8d+3c14b91618,21.0.0-3-ge02ed75+bda8df9b93,21.0.0-4-g591bb35+bda8df9b93,21.0.0-4-g65b4814+52fd22d7b4,21.0.0-4-g88306b8+656365ce3f,21.0.0-4-gccdca77+86bf7a300d,21.0.0-4-ge8a399c+b99e86088e,21.0.0-5-gd00fb1e+6a0dc09319,21.0.0-51-gd3b42663+bf9f0d1c8b,21.0.0-6-g2d4f3f3+9f51b1e3f7,21.0.0-7-g04766d7+ee2ae02087,21.0.0-7-g98eecf7+3609eddee2,21.0.0-7-gde99fe0+bda8df9b93,21.0.0-8-gd70ce6f+79e45e76e4,master-gac4afde19b+bda8df9b93,w.2021.10
LSST Data Management Base Package
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
#define LSST_EXCEPTION_TYPE(t, b, c)
Macro used to define new types of exceptions without additional data.
Definition: Exception.h:69
Fits * fits
Definition: FitsWriter.cc:90
uint64_t * ptr
Definition: RangeSet.cc:88
ItemVariant const * other
Definition: Schema.cc:56
Basic LSST definitions.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:297
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:121
A vector of catalogs used by Persistable.
Definition: CatalogVector.h:29
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:31
An exception thrown when an InputArchive's contents do not make sense.
Definition: Persistable.h:39
An object passed to Persistable::write to allow it to persist itself.
A multi-catalog archive object used to save table::io::Persistable objects.
Definition: OutputArchive.h:34
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:176
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
static std::shared_ptr< T > readFits(fits::Fits &fitsfile)
Read an object from an already open FITS object.
Definition: Persistable.h:183
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
A base class for factory classes used to reconstruct objects from records.
Definition: Persistable.h:228
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.
virtual ~PersistableFactory() noexcept=default
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:74
void writeFits(std::string const &fileName, std::string const &mode="w") const
Write the object to a regular FITS file.
Definition: Persistable.cc:24
virtual bool isPersistable() const noexcept
Return true if this particular object can be persisted using afw::table::io.
Definition: Persistable.h:102
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
virtual ~Persistable() noexcept=default
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
Definition: Persistable.cc:34
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
Definition: Persistable.cc:38
An exception thrown when problems occur during persistence.
Definition: Persistable.h:31
Reports errors in external input/output operations.
Definition: Runtime.h:160
const int DEFAULT_HDU
Specify that the default HDU should be read.
Definition: fitsDefaults.h:18
A base class for image defects.
STL namespace.
table::Key< std::string > name
Definition: Amplifier.cc:116