LSST Applications g0afe43252f+b86e4b8053,g0e535e6de9+ad13c1b82d,g11f7dcd041+017865fdd3,g1ce3e0751c+f991eae79d,g25e82e299b+da9c58a417,g28da252d5a+9a4345bd89,g2bbee38e9b+b6588ad223,g2bc492864f+b6588ad223,g2cdde0e794+8523d0dbb4,g347aa1857d+b6588ad223,g35bb328faa+b86e4b8053,g3a166c0a6a+b6588ad223,g461a3dce89+b86e4b8053,g52b1c1532d+b86e4b8053,g7d11c3e888+3343bff751,g80478fca09+f22f659b46,g8543c18506+fadcf71ecf,g858d7b2824+c704b22fcc,g8cd86fa7b1+497903d09f,g965a9036f2+c704b22fcc,g979bb04a14+43c1c4070b,g9ddcbc5298+f24b38b85a,gae0086650b+b86e4b8053,gb781091699+0f9934ae6f,gbb886bcc26+486567bf06,gc28159a63d+b6588ad223,gc30aee3386+a2f0f6cab9,gc9f6898e11+66e322ebb3,gcaf7e4fdec+c704b22fcc,gcd45df26be+c704b22fcc,gcdd4ae20e8+02080e1d2d,gcf0d15dbbd+02080e1d2d,gdaeeff99f8+006e14e809,gdbce86181e+42405ade82,ge3d4d395c2+224150c836,ge79ae78c31+b6588ad223,gf048a9a2f4+69e41b07e6,gf0baf85859+b4cca3d10f,w.2024.30
LSST Data Management Base Package
Loading...
Searching...
No Matches
Persistable.cc
Go to the documentation of this file.
1// -*- lsst-c++ -*-
2
3#include <map>
4
9#include "lsst/afw/fits.h"
10
11namespace lsst {
12namespace afw {
13namespace table {
14namespace io {
15
16// ----- Persistable ----------------------------------------------------------------------------------------
17
19 OutputArchive archive;
20 archive.put(this);
21 archive.writeFits(fitsfile);
22}
23
28
33
35
37
41 "afw::table-based persistence is not supported for this object.");
42}
43
44std::shared_ptr<Persistable> Persistable::_readFits(std::string const &fileName, int hdu) {
46 fitsfile.setHdu(hdu);
47 return _readFits(fitsfile);
48}
49
50std::shared_ptr<Persistable> Persistable::_readFits(fits::MemFileManager &manager, int hdu) {
52 fitsfile.setHdu(hdu);
53 return _readFits(fitsfile);
54}
55
56std::shared_ptr<Persistable> Persistable::_readFits(fits::Fits &fitsfile) {
57 InputArchive archive = InputArchive::readFits(fitsfile);
58 return archive.get(1); // the first object saved always has id=1
59}
60
61// ----- PersistableFactory ---------------------------------------------------------------------------------
62
63namespace {
64
66
67RegistryMap &getRegistry() {
68 static RegistryMap instance;
69 return instance;
70}
71
72} // namespace
73
75
77 RegistryMap::const_iterator i = getRegistry().find(name);
78 if (i == getRegistry().end()) {
79 if (!module.empty()) {
80 bool success = base::ModuleImporter::import(module);
81 if (!success) {
82 throw LSST_EXCEPT(
84 (boost::format(
85 "PersistableFactory with name '%s' not found, and import of module "
86 "'%s' failed (possibly because Python calls were not available from C++).") %
87 name % module)
88 .str());
89 }
90 i = getRegistry().find(name);
91 if (i == getRegistry().end()) {
92 throw LSST_EXCEPT(
94 (boost::format(
95 "PersistableFactory with name '%s' not found even after successful import "
96 "of module '%s'. Please report this as a bug in the persistence "
97 "implementation for this object.") %
98 name % module)
99 .str());
100 }
101 } else {
102 throw LSST_EXCEPT(
104 (boost::format(
105 "PersistableFactory with name '%s' not found, and no Python module to import "
106 "was provided. Please report this as a bug in the persistence implementation "
107 "for this object.") %
108 name)
109 .str());
110 }
111 }
112 return *i->second;
113}
114} // namespace io
115} // namespace table
116} // namespace afw
117} // namespace lsst
table::Key< std::string > name
Definition Amplifier.cc:116
int end
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
Mechanism for safely importing Python modules from C++; should not be included except by its own impl...
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
Tag types used to declare specialized field types.
Definition misc.h:31
static InputArchive readFits(fits::Fits &fitsfile)
Read an object from an already open FITS object.
An object passed to Persistable::write to allow it to persist itself.
A multi-catalog archive object used to save table::io::Persistable objects.
int put(std::shared_ptr< Persistable const > obj, bool permissive=false)
Save an object to the archive and return a unique ID that can be used to retrieve it from an InputArc...
void writeFits(fits::Fits &fitsfile) const
Write the archive to an already-open FITS object.
A base class for factory classes used to reconstruct objects from records.
static PersistableFactory const & lookup(std::string const &name, std::string const &module="")
Return the factory that has been registered with the given name.
PersistableFactory(std::string const &name)
Constructor for the factory.
void writeFits(std::string const &fileName, std::string const &mode="w") const
Write the object to a regular FITS file.
virtual bool isPersistable() const noexcept
Return true if this particular object can be persisted using afw::table::io.
virtual std::string getPythonModule() const
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
static bool import(std::string const &name)
Import the given Python module, and return true if successful.
Reports errors in the logical structure of the program.
Definition Runtime.h:46
Reports attempts to access elements using an invalid key.
Definition Runtime.h:151