lsst.afw  14.0-23-g38c323faa+3
PsfFormatter.cc
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 /*
3  * Implementation of PsfFormatter class
4  */
5 #include <stdexcept>
6 #include <string>
7 #include <vector>
8 
9 #include "boost/serialization/nvp.hpp"
10 
12 #include "lsst/afw/detection/Psf.h"
17 #include "lsst/pex/exceptions.h"
18 #include "lsst/log/Log.h"
19 #include "lsst/pex/policy/Policy.h"
20 
21 BOOST_CLASS_EXPORT(lsst::afw::detection::Psf)
22 
23 namespace {
24 LOG_LOGGER _log = LOG_GET("afw.detection.PsfFormatter");
25 }
26 
27 namespace lsst {
28 namespace afw {
29 namespace detection {
30 
31 namespace dafBase = lsst::daf::base;
33 namespace pexPolicy = lsst::pex::policy;
34 
35 using boost::serialization::make_nvp;
36 
37 dafPersist::FormatterRegistration PsfFormatter::registration("Psf", typeid(Psf), createInstance);
38 
39 PsfFormatter::PsfFormatter(std::shared_ptr<pexPolicy::Policy> policy)
40  : dafPersist::Formatter(typeid(this)), _policy(policy) {}
41 
43 
47  LOGL_DEBUG(_log, "PsfFormatter write start");
48  Psf const* ps = dynamic_cast<Psf const*>(persistable);
49  if (ps == 0) {
50  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Persisting non-Psf");
51  }
52  // TODO: Replace this with something better in DM-10776
54  if (boost) {
55  LOGL_DEBUG(_log, "PsfFormatter write BoostStorage");
56  boost->getOArchive() & ps;
57  LOGL_DEBUG(_log, "PsfFormatter write end");
58  return;
59  }
61  if (xml) {
62  LOGL_DEBUG(_log, "PsfFormatter write XmlStorage");
63  xml->getOArchive() & make_nvp("psf", ps);
64  LOGL_DEBUG(_log, "PsfFormatter write end");
65  return;
66  }
67  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized FormatterStorage for Psf");
68 }
69 
72  LOGL_DEBUG(_log, "PsfFormatter read start");
73  Psf* ps;
74 
75  // TODO: Replace this with something better in DM-10776
77  if (boost) {
78  LOGL_DEBUG(_log, "PsfFormatter read BoostStorage");
79  boost->getIArchive() & ps;
80  LOGL_DEBUG(_log, "PsfFormatter read end");
81  return ps;
82  }
84  if (xml) {
85  LOGL_DEBUG(_log, "PsfFormatter read XmlStorage");
86  xml->getIArchive() & make_nvp("psf", ps);
87  LOGL_DEBUG(_log, "PsfFormatter read end");
88  return ps;
89  }
90  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized FormatterStorage for Psf");
91 }
92 
95  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unexpected call to update for Psf");
96 }
97 
98 template <class Archive>
99 void PsfFormatter::delegateSerialize(Archive& ar, unsigned int const, dafBase::Persistable* persistable) {
100  LOGL_DEBUG(_log, "PsfFormatter delegateSerialize start");
101  Psf* ps = dynamic_cast<Psf*>(persistable);
102  if (ps == 0) {
103  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Serializing non-Psf");
104  }
105 #if 0 // not present in baseclass
106  ar & make_nvp("width", ps->_width) & make_nvp("height", ps->_height);
107  ar & make_nvp("k", ps->_kernel);
108 #endif
109 
110  LOGL_DEBUG(_log, "PsfFormatter delegateSerialize end");
111 }
112 
113 std::shared_ptr<dafPersist::Formatter> PsfFormatter::createInstance(
116 }
117 }
118 }
119 } // end lsst::afw::detection
static void delegateSerialize(Archive &ar, unsigned int const version, lsst::daf::base::Persistable *persistable)
Serialize a Psf to a Boost archive.
Definition: PsfFormatter.cc:99
virtual lsst::daf::base::Persistable * read(std::shared_ptr< lsst::daf::persistence::FormatterStorage > storage, std::shared_ptr< lsst::daf::base::PropertySet > additionalData)
Definition: PsfFormatter.cc:70
#define LOGL_DEBUG(logger, message...)
A base class for image defects.
virtual ~PsfFormatter(void)
Minimal destructor.
Definition: PsfFormatter.cc:42
T dynamic_pointer_cast(T... args)
virtual void update(lsst::daf::base::Persistable *persistable, std::shared_ptr< lsst::daf::persistence::FormatterStorage > storage, std::shared_ptr< lsst::daf::base::PropertySet > additionalData)
Definition: PsfFormatter.cc:93
virtual void write(lsst::daf::base::Persistable const *persistable, std::shared_ptr< lsst::daf::persistence::FormatterStorage > storage, std::shared_ptr< lsst::daf::base::PropertySet > additionalData)
Definition: PsfFormatter.cc:44
#define LSST_EXCEPT(type,...)
Formatter for persistence of Psf instances.
Definition: PsfFormatter.h:21
#define LOG_GET(logger)
A polymorphic base class for representing an image&#39;s Point Spread Function.
Definition: Psf.h:70