LSSTApplications  11.0-22-g33de520,13.0+153,14.0+52,14.0+57,14.0-1-g013352c+36,14.0-1-g13ef843+9,14.0-1-g4b114ac+14,14.0-1-g7257b6a+12,14.0-1-g8b7e855+51,14.0-13-g7a60b79+2,14.0-14-g87d16e8+10,14.0-14-gbf7a6f8a,14.0-17-g4f4ea82+5,14.0-2-g319577b+11,14.0-2-ga5af9b6+10,14.0-22-gc48c03f+3,14.0-3-g20413be+3,14.0-46-g76222d5f+3,14.0-47-g0a51fac97,14.0-5-g744ff5f+2,14.0-5-g86eb1bd+31,14.0-6-gd5b81a9+6,14.0-6-ge2c9487+42,14.0-8-g7f6dd6b+6,14.0-8-gb81b6e9+4,14.0-9-g11010eb,14.0-9-g330837b+5
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 { return false; }
103 
104  virtual ~Persistable() = 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() = default;
137 
138  Persistable(Persistable const& other) = default;
139  Persistable(Persistable && other) = default;
140 
141  Persistable & operator=(Persistable const& other) = default;
142  Persistable & operator=(Persistable && other) = 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 std::dynamic_pointer_cast<T>(Persistable::_readFits(fitsfile));
185  }
186 
194  static std::shared_ptr<T> readFits(std::string const& fileName, int hdu = fits::DEFAULT_HDU) {
195  return std::dynamic_pointer_cast<T>(Persistable::_readFits(fileName, hdu));
196  }
197 
206  return std::dynamic_pointer_cast<T>(Persistable::_readFits(manager, hdu));
207  }
208 };
209 
218 protected:
219  typedef io::InputArchive InputArchive; // convenient for derived classes not in afw::table::io
221 
222 public:
234  explicit PersistableFactory(std::string const& name);
235 
237  virtual std::shared_ptr<Persistable> read(InputArchive const& archive,
238  CatalogVector const& catalogs) const = 0;
239 
247  static PersistableFactory const& lookup(std::string const& name, std::string const& module = "");
248 
249  virtual ~PersistableFactory() = default;
250 
251  // No copying
252  PersistableFactory(const PersistableFactory&) = delete;
253  PersistableFactory& operator=(const PersistableFactory&) = delete;
254 
255  // No moving
257  PersistableFactory& operator=(PersistableFactory&&) = delete;
258 };
259 }
260 }
261 }
262 } // namespace lsst::afw::table::io
263 
264 #endif // !AFW_TABLE_IO_Persistable_h_INCLUDED
table::Key< std::string > name
Definition: ApCorrMap.cc:71
An object passed to Persistable::write to allow it to persist itself.
Basic LSST definitions.
A base class for factory classes used to reconstruct objects from records.
Definition: Persistable.h:217
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: Persistable.h:102
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:280
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
STL class.
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:34
A base class for image defects.
Definition: cameraGeom.dox:3
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:102
Include files required for standard LSST Exception handling.
T dynamic_pointer_cast(T... args)
A vector of catalogs used by Persistable.
Definition: CatalogVector.h:29
io::OutputArchiveHandle OutputArchiveHandle
Definition: Persistable.h:108
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:31
static std::shared_ptr< T > readFits(fits::Fits &fitsfile)
Read an object from an already open FITS object.
Definition: Persistable.h:183
#define LSST_EXCEPTION_TYPE(t, b, c)
Macro used to define new types of exceptions without additional data.
Definition: Exception.h:68
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:176
An exception thrown when problems occur during persistence.
Definition: Persistable.h:31
An exception thrown when an InputArchive&#39;s contents do not make sense.
Definition: Persistable.h:39
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
const int DEFAULT_HDU
Specify that the default HDU should be read.
Definition: fitsDefaults.h:18