LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
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/pex/logging/Trace.h"
26 #include "lsst/pex/policy/Policy.h"
27 
28 BOOST_CLASS_EXPORT(lsst::afw::detection::Psf)
29 
30 #define EXEC_TRACE 20
31 static void execTrace(std::string s, int level = EXEC_TRACE) {
32  lsst::pex::logging::Trace("afw.detection.PsfFormatter", level, s);
33 }
34 
35 namespace afwDetect = lsst::afw::detection;
36 namespace afwMath = lsst::afw::math;
37 namespace dafBase = lsst::daf::base;
38 namespace dafPersist = lsst::daf::persistence;
39 namespace pexPolicy = lsst::pex::policy;
40 
41 using boost::serialization::make_nvp;
42 
47 afwDetect::PsfFormatter::registration("Psf", typeid(afwDetect::Psf), createInstance);
48 
53  pexPolicy::Policy::Ptr policy) :
54  dafPersist::Formatter(typeid(this)), _policy(policy) {}
55 
59 
61  dafBase::Persistable const* persistable,
64  execTrace("PsfFormatter write start");
65  afwDetect::Psf const* ps = dynamic_cast<afwDetect::Psf const*>(persistable);
66  if (ps == 0) {
67  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Persisting non-Psf");
68  }
69  if (typeid(*storage) == typeid(dafPersist::BoostStorage)) {
70  execTrace("PsfFormatter write BoostStorage");
72  dynamic_cast<dafPersist::BoostStorage*>(storage.get());
73  boost->getOArchive() & ps;
74  execTrace("PsfFormatter write end");
75  return;
76  }
77  else if (typeid(*storage) == typeid(dafPersist::XmlStorage)) {
78  execTrace("PsfFormatter write XmlStorage");
80  dynamic_cast<dafPersist::XmlStorage*>(storage.get());
81  xml->getOArchive() & make_nvp("psf", ps);
82  execTrace("PsfFormatter write end");
83  return;
84  }
85  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized Storage for Psf");
86 }
87 
90  execTrace("PsfFormatter read start");
91  afwDetect::Psf* ps;
92  if (typeid(*storage) == typeid(dafPersist::BoostStorage)) {
93  execTrace("PsfFormatter read BoostStorage");
95  dynamic_cast<dafPersist::BoostStorage*>(storage.get());
96  boost->getIArchive() & ps;
97  execTrace("PsfFormatter read end");
98  return ps;
99  }
100  else if (typeid(*storage) == typeid(dafPersist::XmlStorage)) {
101  execTrace("PsfFormatter read XmlStorage");
103  dynamic_cast<dafPersist::XmlStorage*>(storage.get());
104  xml->getIArchive() & make_nvp("psf", ps);
105  execTrace("PsfFormatter read end");
106  return ps;
107  }
108  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized Storage for Psf");
109 }
110 
114  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unexpected call to update for Psf");
115 }
116 
120 template <class Archive>
122  Archive& ar,
123  unsigned int const,
124  dafBase::Persistable* persistable
125  ) {
126  execTrace("PsfFormatter delegateSerialize start");
127  afwDetect::Psf* ps = dynamic_cast<afwDetect::Psf*>(persistable);
128  if (ps == 0) {
129  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Serializing non-Psf");
130  }
131 #if 0 // not present in baseclass
132  ar & make_nvp("width", ps->_width) & make_nvp("height", ps->_height);
133  ar & make_nvp("k", ps->_kernel);
134 #endif
135 
136  execTrace("PsfFormatter delegateSerialize end");
137 }
138 
144  pexPolicy::Policy::Ptr policy) {
146 }
#define EXEC_TRACE
Definition: PsfFormatter.cc:30
Class for XML file storage.
Definition: XmlStorage.h:57
boost::shared_ptr< Formatter > Ptr
Definition: Formatter.h:81
static void delegateSerialize(Archive &ar, unsigned int const version, lsst::daf::base::Persistable *persistable)
Include files required for standard LSST Exception handling.
virtual boost::archive::text_iarchive & getIArchive(void)
boost::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:90
boost::shared_ptr< Policy > Ptr
Definition: Policy.h:172
definition of the Trace messaging facilities
limited backward compatibility to the DC2 run-time trace facilities
Definition: Trace.h:93
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:52
virtual boost::archive::xml_iarchive & getIArchive(void)
Definition: XmlStorage.cc:114
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:88
virtual void write(lsst::daf::base::Persistable const *persistable, lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
Definition: PsfFormatter.cc:60
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
boost::shared_ptr< Storage > Ptr
Definition: Storage.h:62
Interface for PsfFormatter class.
Class for boost::serialization storage.
Definition: BoostStorage.h:58
Base class for all persistable classes.
Definition: Persistable.h:74
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.