LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
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< Storage > Ptr
Definition: Storage.h:62
std::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:85
Class for XML file storage.
Definition: XmlStorage.h:58
#define LOGL_DEBUG(logger, message...)
Definition: Log.h:513
static void delegateSerialize(Archive &ar, unsigned int const version, lsst::daf::base::Persistable *persistable)
std::shared_ptr< Formatter > Ptr
Definition: Formatter.h:81
virtual boost::archive::text_iarchive & getIArchive(void)
std::shared_ptr< Policy > Ptr
Definition: Policy.h:172
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)
Definition: PsfFormatter.cc:51
virtual boost::archive::xml_iarchive & getIArchive(void)
Definition: XmlStorage.cc:114
#define LOG_GET(logger)
Definition: Log.h:83
Interface for XmlStorage class.
virtual lsst::daf::base::Persistable * read(lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
Definition: PsfFormatter.cc:87
virtual void write(lsst::daf::base::Persistable const *persistable, lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
Definition: PsfFormatter.cc:59
virtual void update(lsst::daf::base::Persistable *persistable, lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
static lsst::daf::persistence::Formatter::Ptr createInstance(lsst::pex::policy::Policy::Ptr policy)
static lsst::daf::persistence::FormatterRegistration registration
Definition: PsfFormatter.h:57
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
virtual boost::archive::text_oarchive & getOArchive(void)
Auxiliary global template function for Formatter subclasses.
Formatter for persistence of Psf instances.
Definition: PsfFormatter.h:30
virtual boost::archive::xml_oarchive & getOArchive(void)
Definition: XmlStorage.cc:107
Interface for PsfFormatter class.
Class for boost::serialization storage.
Definition: BoostStorage.h:59
Base class for all persistable classes.
Definition: Persistable.h:74
Include files required for standard LSST Exception handling.
Interface for LogicalLocation class.
A polymorphic base class for representing an image&#39;s Point Spread Function.
Definition: Psf.h:68
#define LOG_LOGGER
Definition: Log.h:712
Interface for BoostStorage class.