LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
LSSTDataManagementBasePackage
PsfFormatter.cc
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
12 #include <stdexcept>
13 #include <string>
14 #include <vector>
15 
16 #include "boost/serialization/nvp.hpp"
17 
19 #include "lsst/afw/detection/Psf.h"
24 #include "lsst/pex/exceptions.h"
25 #include "lsst/log/Log.h"
26 #include "lsst/pex/policy/Policy.h"
27 
28 BOOST_CLASS_EXPORT(lsst::afw::detection::Psf)
29 
30 namespace {
31 LOG_LOGGER _log = LOG_GET("afw.detection.PsfFormatter");
32 }
33 
34 namespace afwDetect = lsst::afw::detection;
35 namespace afwMath = lsst::afw::math;
36 namespace dafBase = lsst::daf::base;
37 namespace dafPersist = lsst::daf::persistence;
38 namespace pexPolicy = lsst::pex::policy;
39 
40 using boost::serialization::make_nvp;
41 
46 afwDetect::PsfFormatter::registration("Psf", typeid(afwDetect::Psf), createInstance);
47 
52  pexPolicy::Policy::Ptr policy) :
53  dafPersist::Formatter(typeid(this)), _policy(policy) {}
54 
58 
60  dafBase::Persistable const* persistable,
63  LOGL_DEBUG(_log, "PsfFormatter write start");
64  afwDetect::Psf const* ps = dynamic_cast<afwDetect::Psf const*>(persistable);
65  if (ps == 0) {
66  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Persisting non-Psf");
67  }
68  if (typeid(*storage) == typeid(dafPersist::BoostStorage)) {
69  LOGL_DEBUG(_log, "PsfFormatter write BoostStorage");
71  dynamic_cast<dafPersist::BoostStorage*>(storage.get());
72  boost->getOArchive() & ps;
73  LOGL_DEBUG(_log, "PsfFormatter write end");
74  return;
75  }
76  else if (typeid(*storage) == typeid(dafPersist::XmlStorage)) {
77  LOGL_DEBUG(_log, "PsfFormatter write XmlStorage");
79  dynamic_cast<dafPersist::XmlStorage*>(storage.get());
80  xml->getOArchive() & make_nvp("psf", ps);
81  LOGL_DEBUG(_log, "PsfFormatter write end");
82  return;
83  }
84  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized Storage for Psf");
85 }
86 
89  LOGL_DEBUG(_log, "PsfFormatter read start");
90  afwDetect::Psf* ps;
91  if (typeid(*storage) == typeid(dafPersist::BoostStorage)) {
92  LOGL_DEBUG(_log, "PsfFormatter read BoostStorage");
94  dynamic_cast<dafPersist::BoostStorage*>(storage.get());
95  boost->getIArchive() & ps;
96  LOGL_DEBUG(_log, "PsfFormatter read end");
97  return ps;
98  }
99  else if (typeid(*storage) == typeid(dafPersist::XmlStorage)) {
100  LOGL_DEBUG(_log, "PsfFormatter read XmlStorage");
102  dynamic_cast<dafPersist::XmlStorage*>(storage.get());
103  xml->getIArchive() & make_nvp("psf", ps);
104  LOGL_DEBUG(_log, "PsfFormatter read end");
105  return ps;
106  }
107  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized Storage for Psf");
108 }
109 
113  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unexpected call to update for Psf");
114 }
115 
119 template <class Archive>
121  Archive& ar,
122  unsigned int const,
123  dafBase::Persistable* persistable
124  ) {
125  LOGL_DEBUG(_log, "PsfFormatter delegateSerialize start");
126  afwDetect::Psf* ps = dynamic_cast<afwDetect::Psf*>(persistable);
127  if (ps == 0) {
128  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Serializing non-Psf");
129  }
130 #if 0 // not present in baseclass
131  ar & make_nvp("width", ps->_width) & make_nvp("height", ps->_height);
132  ar & make_nvp("k", ps->_kernel);
133 #endif
134 
135  LOGL_DEBUG(_log, "PsfFormatter delegateSerialize end");
136 }
137 
143  pexPolicy::Policy::Ptr policy) {
145 }
std::shared_ptr< Policy > Ptr
Definition: Policy.h:172
#define LOG_LOGGER
Definition: Log.h:712
Class for XML file storage.
Definition: XmlStorage.h:58
static void delegateSerialize(Archive &ar, unsigned int const version, lsst::daf::base::Persistable *persistable)
Serialize a Psf to a Boost archive.
Include files required for standard LSST Exception handling.
std::shared_ptr< Formatter > Ptr
Definition: Formatter.h:81
Construct a static instance of this helper class to register a Formatter subclass in the FormatterReg...
Definition: Formatter.h:138
PsfFormatter(lsst::pex::policy::Policy::Ptr policy)
Constructor.
Definition: PsfFormatter.cc:51
virtual boost::archive::text_oarchive & getOArchive(void)
Get a boost::serialization archive suitable for output.
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:513
LSST DM logging module built on log4cxx.
Interface for XmlStorage class.
virtual lsst::daf::base::Persistable * read(lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
Read a Persistable instance from a Storage instance.
Definition: PsfFormatter.cc:87
virtual boost::archive::xml_iarchive & getIArchive(void)
Get a boost::serialization XML archive suitable for input.
Definition: XmlStorage.cc:114
virtual void write(lsst::daf::base::Persistable const *persistable, lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
Write a Persistable instance to a Storage instance.
Definition: PsfFormatter.cc:59
virtual void update(lsst::daf::base::Persistable *persistable, lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
Update an existing Persistable instance with information from an additional Storage instance...
std::shared_ptr< Storage > Ptr
Definition: Storage.h:62
static lsst::daf::persistence::Formatter::Ptr createInstance(lsst::pex::policy::Policy::Ptr policy)
Factory method for PsfFormatter.
virtual ~PsfFormatter(void)
Minimal destructor.
Definition: PsfFormatter.cc:57
static lsst::daf::persistence::FormatterRegistration registration
Register this Formatter subclass through a static instance of FormatterRegistration.
Definition: PsfFormatter.h:57
virtual boost::archive::text_iarchive & getIArchive(void)
Get a boost::serialization archive suitable for input.
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
Definition: Exception.h:46
Auxiliary global template function for Formatter subclasses.
Formatter for persistence of Psf instances.
Definition: PsfFormatter.h:30
Interface for PsfFormatter class.
Class for boost::serialization storage.
Definition: BoostStorage.h:59
Base class for all persistable classes.
Definition: Persistable.h:74
virtual boost::archive::xml_oarchive & getOArchive(void)
Get a boost::serialization XML archive suitable for output.
Definition: XmlStorage.cc:107
std::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:85
#define LOG_GET(logger)
Returns a Log object associated with logger.
Definition: Log.h:83
Interface for LogicalLocation class.
A polymorphic base class for representing an image&#39;s Point Spread Function.
Definition: Psf.h:68
Interface for BoostStorage class.