LSSTApplications  16.0+42,16.0-1-gce273f5+8,16.0-10-g230e10e+1,16.0-11-g9fe0e56+17,16.0-11-gce733cf+17,16.0-12-g5ad1ebf+9,16.0-12-gc85596e+2,16.0-13-gde155d7+2,16.0-14-g9428de4d,16.0-14-gc1cf4a94+2,16.0-15-g8e16a51+14,16.0-2-g0febb12+7,16.0-2-g839ba83+32,16.0-2-g9d5294e+22,16.0-2-gab3db49+7,16.0-2-gf41ba6b+6,16.0-2-gf4e7cdd+5,16.0-3-g6923fb6+15,16.0-3-g8e51203+2,16.0-3-g9645794+6,16.0-3-gcfd6c53+20,16.0-35-g34c7dfe62+1,16.0-4-g03cf288+11,16.0-4-g32d12de,16.0-4-g5f3a788+7,16.0-4-g7690030+30,16.0-4-g8a0f11a+16,16.0-4-ga5d8928+16,16.0-5-g0da18be+7,16.0-5-g4940a70,16.0-5-g563880a+2,16.0-5-g7742071+2,16.0-5-gb3f8a4b+26,16.0-6-g3610b4f+5,16.0-6-gf0acd13+14,16.0-8-g4dec96c+7,16.0-8-gc315727+16,16.0-9-g1de645c+7,16.0-9-gcc4efb7+6,w.2018.36
LSSTDataManagementBasePackage
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"
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;
33 namespace pexPolicy = lsst::pex::policy;
34 
35 using boost::serialization::make_nvp;
36 
37 dafPersist::FormatterRegistration PsfFormatter::registration("Psf", typeid(Psf), createInstance);
38 
40  : dafPersist::Formatter(typeid(this)), _policy(policy) {}
41 
42 PsfFormatter::PsfFormatter(PsfFormatter const&) = default;
43 PsfFormatter::PsfFormatter(PsfFormatter&&) = default;
44 PsfFormatter& PsfFormatter::operator=(PsfFormatter const&) = default;
45 PsfFormatter& PsfFormatter::operator=(PsfFormatter&&) = default;
46 
47 PsfFormatter::~PsfFormatter() = default;
48 
49 void PsfFormatter::write(dafBase::Persistable const* persistable,
52  LOGL_DEBUG(_log, "PsfFormatter write start");
53  Psf const* ps = dynamic_cast<Psf const*>(persistable);
54  if (ps == 0) {
55  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Persisting non-Psf");
56  }
57  // TODO: Replace this with something better in DM-10776
59  if (boost) {
60  LOGL_DEBUG(_log, "PsfFormatter write BoostStorage");
61  boost->getOArchive() & ps;
62  LOGL_DEBUG(_log, "PsfFormatter write end");
63  return;
64  }
66  if (xml) {
67  LOGL_DEBUG(_log, "PsfFormatter write XmlStorage");
68  xml->getOArchive() & make_nvp("psf", ps);
69  LOGL_DEBUG(_log, "PsfFormatter write end");
70  return;
71  }
72  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized FormatterStorage for Psf");
73 }
74 
77  LOGL_DEBUG(_log, "PsfFormatter read start");
78  Psf* ps;
79 
80  // TODO: Replace this with something better in DM-10776
82  if (boost) {
83  LOGL_DEBUG(_log, "PsfFormatter read BoostStorage");
84  boost->getIArchive() & ps;
85  LOGL_DEBUG(_log, "PsfFormatter read end");
86  return ps;
87  }
89  if (xml) {
90  LOGL_DEBUG(_log, "PsfFormatter read XmlStorage");
91  xml->getIArchive() & make_nvp("psf", ps);
92  LOGL_DEBUG(_log, "PsfFormatter read end");
93  return ps;
94  }
95  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized FormatterStorage for Psf");
96 }
97 
100  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unexpected call to update for Psf");
101 }
102 
103 template <class Archive>
104 void PsfFormatter::delegateSerialize(Archive& ar, unsigned int const, dafBase::Persistable* persistable) {
105  LOGL_DEBUG(_log, "PsfFormatter delegateSerialize start");
106  Psf* ps = dynamic_cast<Psf*>(persistable);
107  if (ps == 0) {
108  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Serializing non-Psf");
109  }
110 #if 0 // not present in baseclass
111  ar & make_nvp("width", ps->_width) & make_nvp("height", ps->_height);
112  ar & make_nvp("k", ps->_kernel);
113 #endif
114 
115  LOGL_DEBUG(_log, "PsfFormatter delegateSerialize end");
116 }
117 
118 std::shared_ptr<dafPersist::Formatter> PsfFormatter::createInstance(
121 }
122 } // namespace detection
123 } // namespace afw
124 } // namespace lsst
#define LOG_LOGGER
Definition: Log.h:712
Class for XML file storage.
Definition: XmlStorage.h:58
Definition: Span.h:36
PsfFormatter(PsfFormatter const &)
Construct a static instance of this helper class to register a Formatter subclass in the FormatterReg...
Definition: Formatter.h:138
#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.
A base class for image defects.
Definition: cameraGeom.dox:3
T dynamic_pointer_cast(T... args)
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:47
Auxiliary global template function for Formatter subclasses.
Formatter for persistence of Psf instances.
Definition: PsfFormatter.h:21
Class for boost::serialization storage.
Definition: BoostStorage.h:59
Base class for all persistable classes.
Definition: Persistable.h:73
void delegateSerialize(Archive &ar, unsigned int const version, lsst::daf::base::Persistable *persistable)
Template function that serializes a Persistable using boost::serialization.
Definition: FormatterImpl.h:58
#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:77
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104
Interface for BoostStorage class.