LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
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< Policy > Ptr
Definition: Policy.h:172
definition of the Trace messaging facilities
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
boost::shared_ptr< Formatter > Ptr
Definition: Formatter.h:81
boost::shared_ptr< Storage > Ptr
Definition: Storage.h:62
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
virtual boost::archive::text_oarchive & getOArchive(void)
virtual void update(lsst::daf::base::Persistable *persistable, lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
Interface for XmlStorage class.
virtual boost::archive::xml_iarchive & getIArchive(void)
Definition: XmlStorage.cc:114
static lsst::daf::persistence::FormatterRegistration registration
Definition: PsfFormatter.h:57
virtual boost::archive::text_iarchive & getIArchive(void)
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
static lsst::daf::persistence::Formatter::Ptr createInstance(lsst::pex::policy::Policy::Ptr policy)
Auxiliary global template function for Formatter subclasses.
Formatter for persistence of Psf instances.
Definition: PsfFormatter.h:30
Interface for PsfFormatter class.
static void delegateSerialize(Archive &ar, unsigned int const version, lsst::daf::base::Persistable *persistable)
Class for boost::serialization storage.
Definition: BoostStorage.h:58
Base class for all persistable classes.
Definition: Persistable.h:74
boost::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:90
virtual boost::archive::xml_oarchive & getOArchive(void)
Definition: XmlStorage.cc:107
Interface for LogicalLocation class.
A polymorphic base class for representing an image&#39;s Point Spread Function.
Definition: Psf.h:68
Include files required for standard LSST Exception handling.
virtual lsst::daf::base::Persistable * read(lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
Definition: PsfFormatter.cc:88
PsfFormatter(lsst::pex::policy::Policy::Ptr policy)
Definition: PsfFormatter.cc:52
Interface for BoostStorage class.