9 #include "boost/serialization/nvp.hpp"
13 #include "lsst/daf/persistence/FormatterImpl.h"
14 #include "lsst/daf/persistence/LogicalLocation.h"
15 #include "lsst/daf/persistence/BoostStorage.h"
16 #include "lsst/daf/persistence/XmlStorage.h"
17 #include "lsst/pex/exceptions.h"
18 #include "lsst/log/Log.h"
19 #include "lsst/pex/policy/Policy.h"
24 LOG_LOGGER _log = LOG_GET(
"afw.detection.PsfFormatter");
31 namespace dafBase = lsst::daf::base;
32 namespace dafPersist = lsst::daf::persistence;
33 namespace pexPolicy = lsst::pex::policy;
35 using boost::serialization::make_nvp;
37 dafPersist::FormatterRegistration PsfFormatter::registration(
"Psf",
typeid(Psf), createInstance);
39 PsfFormatter::PsfFormatter(std::shared_ptr<pexPolicy::Policy> policy)
40 : dafPersist::Formatter(typeid(this)), _policy(policy) {}
42 PsfFormatter::~PsfFormatter(
void) {}
44 void PsfFormatter::write(dafBase::Persistable
const* persistable,
45 std::shared_ptr<dafPersist::Storage> storage,
46 std::shared_ptr<dafBase::PropertySet>) {
47 LOGL_DEBUG(_log,
"PsfFormatter write start");
48 Psf const* ps =
dynamic_cast<Psf const*
>(persistable);
50 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Persisting non-Psf");
52 if (
typeid(*storage) ==
typeid(dafPersist::BoostStorage)) {
53 LOGL_DEBUG(_log,
"PsfFormatter write BoostStorage");
54 dafPersist::BoostStorage* boost =
dynamic_cast<dafPersist::BoostStorage*
>(storage.get());
55 boost->getOArchive() & ps;
56 LOGL_DEBUG(_log,
"PsfFormatter write end");
58 }
else if (
typeid(*storage) ==
typeid(dafPersist::XmlStorage)) {
59 LOGL_DEBUG(_log,
"PsfFormatter write XmlStorage");
60 dafPersist::XmlStorage* xml =
dynamic_cast<dafPersist::XmlStorage*
>(storage.get());
61 xml->getOArchive() & make_nvp(
"psf", ps);
62 LOGL_DEBUG(_log,
"PsfFormatter write end");
65 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized Storage for Psf");
68 dafBase::Persistable* PsfFormatter::read(std::shared_ptr<dafPersist::Storage> storage,
69 std::shared_ptr<dafBase::PropertySet>) {
70 LOGL_DEBUG(_log,
"PsfFormatter read start");
72 if (
typeid(*storage) ==
typeid(dafPersist::BoostStorage)) {
73 LOGL_DEBUG(_log,
"PsfFormatter read BoostStorage");
74 dafPersist::BoostStorage* boost =
dynamic_cast<dafPersist::BoostStorage*
>(storage.get());
75 boost->getIArchive() & ps;
76 LOGL_DEBUG(_log,
"PsfFormatter read end");
78 }
else if (
typeid(*storage) ==
typeid(dafPersist::XmlStorage)) {
79 LOGL_DEBUG(_log,
"PsfFormatter read XmlStorage");
80 dafPersist::XmlStorage* xml =
dynamic_cast<dafPersist::XmlStorage*
>(storage.get());
81 xml->getIArchive() & make_nvp(
"psf", ps);
82 LOGL_DEBUG(_log,
"PsfFormatter read end");
85 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized Storage for Psf");
88 void PsfFormatter::update(dafBase::Persistable*, std::shared_ptr<dafPersist::Storage>,
89 std::shared_ptr<dafBase::PropertySet>) {
90 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unexpected call to update for Psf");
93 template <
class Archive>
94 void PsfFormatter::delegateSerialize(Archive& ar,
unsigned int const, dafBase::Persistable* persistable) {
95 LOGL_DEBUG(_log,
"PsfFormatter delegateSerialize start");
96 Psf* ps =
dynamic_cast<Psf*
>(persistable);
98 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Serializing non-Psf");
100 #if 0 // not present in baseclass
101 ar & make_nvp(
"width", ps->_width) & make_nvp(
"height", ps->_height);
102 ar & make_nvp(
"k", ps->_kernel);
105 LOGL_DEBUG(_log,
"PsfFormatter delegateSerialize end");
108 std::shared_ptr<dafPersist::Formatter> PsfFormatter::createInstance(
109 std::shared_ptr<pexPolicy::Policy> policy) {
110 return std::shared_ptr<dafPersist::Formatter>(
new PsfFormatter(policy));
A polymorphic base class for representing an image's Point Spread Function.