lsst.afw  13.0-49-g6f23dda
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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"
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"
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;
32 namespace dafPersist = lsst::daf::persistence;
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 
42 PsfFormatter::~PsfFormatter(void) {}
43 
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);
49  if (ps == 0) {
50  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Persisting non-Psf");
51  }
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");
57  return;
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");
63  return;
64  }
65  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized Storage for Psf");
66 }
67 
68 dafBase::Persistable* PsfFormatter::read(std::shared_ptr<dafPersist::Storage> storage,
69  std::shared_ptr<dafBase::PropertySet>) {
70  LOGL_DEBUG(_log, "PsfFormatter read start");
71  Psf* ps;
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");
77  return ps;
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");
83  return ps;
84  }
85  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized Storage for Psf");
86 }
87 
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");
91 }
92 
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);
97  if (ps == 0) {
98  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Serializing non-Psf");
99  }
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);
103 #endif
104 
105  LOGL_DEBUG(_log, "PsfFormatter delegateSerialize end");
106 }
107 
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));
111 }
112 }
113 }
114 } // end lsst::afw::detection
Formatter for persistence of Psf instances.
Definition: PsfFormatter.h:21
A polymorphic base class for representing an image&#39;s Point Spread Function.
Definition: Psf.h:70