LSST Applications g0da5cf3356+25b44625d0,g17e5ecfddb+50a5ac4092,g1c76d35bf8+585f0f68a2,g295839609d+8ef6456700,g2e2c1a68ba+cc1f6f037e,g38293774b4+62d12e78cb,g3b44f30a73+2891c76795,g48ccf36440+885b902d19,g4b2f1765b6+0c565e8f25,g5320a0a9f6+bd4bf1dc76,g56364267ca+403c24672b,g56b687f8c9+585f0f68a2,g5c4744a4d9+78cd207961,g5ffd174ac0+bd4bf1dc76,g6075d09f38+3075de592a,g667d525e37+cacede5508,g6f3e93b5a3+da81c812ee,g71f27ac40c+cacede5508,g7212e027e3+eb621d73aa,g774830318a+18d2b9fa6c,g7985c39107+62d12e78cb,g79ca90bc5c+fa2cc03294,g881bdbfe6c+cacede5508,g91fc1fa0cf+82a115f028,g961520b1fb+2534687f64,g96f01af41f+f2060f23b6,g9ca82378b8+cacede5508,g9d27549199+78cd207961,gb065e2a02a+ad48cbcda4,gb1df4690d6+585f0f68a2,gb35d6563ee+62d12e78cb,gbc3249ced9+bd4bf1dc76,gbec6a3398f+bd4bf1dc76,gd01420fc67+bd4bf1dc76,gd59336e7c4+c7bb92e648,gf46e8334de+81c9a61069,gfed783d017+bd4bf1dc76,v25.0.1.rc3
LSST Data Management Base Package
Loading...
Searching...
No Matches
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"
9
10namespace lsst {
11namespace afw {
12
13namespace fits {
14
15class Fits;
16class MemFileManager;
17
18} // namespace fits
19
20namespace table {
21namespace io {
22
23class InputArchive;
24class OutputArchive;
25class OutputArchiveHandle;
26class 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
75public:
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
106protected:
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
144private:
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
175template <typename T>
177public:
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
229protected:
230 using InputArchive = io::InputArchive; // convenient for derived classes not in afw::table::io
232
233public:
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
269};
270} // namespace io
271} // namespace table
272} // namespace afw
273} // namespace lsst
274
275#endif // !AFW_TABLE_IO_Persistable_h_INCLUDED
table::Key< std::string > name
Definition: Amplifier.cc:116
#define LSST_EXCEPTION_TYPE(t, b, c)
Macro used to define new types of exceptions without additional data.
Definition: Exception.h:69
uint64_t * ptr
Definition: RangeSet.cc:88
Basic LSST definitions.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:308
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:125
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(std::string const &fileName, int hdu=fits::DEFAULT_HDU)
Read an object from a regular FITS file.
Definition: Persistable.h:194
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
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
STL namespace.