30 #define __attribute__(x) 37 #include "boost/serialization/shared_ptr.hpp" 38 #include "boost/serialization/binary_object.hpp" 39 #include "boost/serialization/nvp.hpp" 40 #include <boost/archive/binary_oarchive.hpp> 41 #include <boost/archive/binary_iarchive.hpp> 43 #include "lsst/daf/base.h" 44 #include "lsst/daf/persistence.h" 45 #include "lsst/log/Log.h" 50 LOG_LOGGER _log = LOG_GET(
"afw.DecoratedImageFormatter");
53 using boost::serialization::make_nvp;
54 using lsst::daf::base::Persistable;
55 using lsst::daf::persistence::BoostStorage;
56 using lsst::daf::persistence::XmlStorage;
57 using lsst::daf::persistence::FitsStorage;
58 using lsst::daf::persistence::FormatterStorage;
63 namespace formatters {
65 template <
typename ImagePixelT>
68 static std::string
name();
73 static std::string
name =
"DecoratedImageU";
78 static std::string
name =
"DecoratedImageI";
83 static std::string
name =
"DecoratedImageF";
88 static std::string
name =
"DecoratedImageD";
93 static std::string
name =
"DecoratedImageL";
97 template <
typename ImagePixelT>
102 template <
typename ImagePixelT>
104 : lsst::daf::persistence::Formatter(
typeid(
this)) {}
106 template <
typename ImagePixelT>
109 template <
typename ImagePixelT>
111 std::shared_ptr<FormatterStorage> storage,
112 std::shared_ptr<lsst::daf::base::PropertySet>) {
113 LOGL_DEBUG(_log,
"DecoratedImageFormatter write start");
116 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Persisting non-DecoratedImage");
120 auto boost = std::dynamic_pointer_cast<BoostStorage>(storage);
122 LOGL_DEBUG(_log,
"DecoratedImageFormatter write BoostStorage");
123 boost->getOArchive() & *ip;
124 LOGL_DEBUG(_log,
"DecoratedImageFormatter write end");
127 auto xml = std::dynamic_pointer_cast<XmlStorage>(storage);
129 LOGL_DEBUG(_log,
"DecoratedImageFormatter write XmlStorage");
130 xml->getOArchive() & make_nvp(
"img", *ip);
131 LOGL_DEBUG(_log,
"DecoratedImageFormatter write end");
134 auto fits = std::dynamic_pointer_cast<FitsStorage>(storage);
136 LOGL_DEBUG(_log,
"DecoratedImageFormatter write FitsStorage");
142 LOGL_DEBUG(_log,
"DecoratedImageFormatter write end");
145 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
146 "Unrecognized FormatterStorage for DecoratedImage");
149 template <
typename ImagePixelT>
151 std::shared_ptr<lsst::daf::base::PropertySet>) {
152 LOGL_DEBUG(_log,
"DecoratedImageFormatter read start");
154 auto boost = std::dynamic_pointer_cast<BoostStorage>(storage);
156 LOGL_DEBUG(_log,
"DecoratedImageFormatter read BoostStorage");
158 boost->getIArchive() & *ip;
159 LOGL_DEBUG(_log,
"DecoratedImageFormatter read end");
162 auto xml = std::dynamic_pointer_cast<XmlStorage>(storage);
164 LOGL_DEBUG(_log,
"DecoratedImageFormatter read XmlStorage");
166 boost->getIArchive() & make_nvp(
"img", *ip);
167 LOGL_DEBUG(_log,
"DecoratedImageFormatter read end");
170 auto fits = std::dynamic_pointer_cast<FitsStorage>(storage);
172 LOGL_DEBUG(_log,
"DecoratedImageFormatter read FitsStorage");
178 LOGL_DEBUG(_log,
"DecoratedImageFormatter read end");
181 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
182 "Unrecognized FormatterStorage for DecoratedImage");
185 template <
typename ImagePixelT>
187 std::shared_ptr<lsst::daf::persistence::FormatterStorage>,
188 std::shared_ptr<lsst::daf::base::PropertySet>) {
189 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unexpected call to update for DecoratedImage");
192 template <
typename ImagePixelT>
193 template <
class Archive>
195 LOGL_DEBUG(_log,
"DecoratedImageFormatter delegateSerialize start");
198 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Serializing non-DecoratedImage");
200 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
201 "DecoratedImage serialization not yet implemented");
204 template <
typename ImagePixelT>
206 std::shared_ptr<lsst::pex::policy::Policy> policy) {
207 return std::shared_ptr<lsst::daf::persistence::Formatter>(
211 #define InstantiateFormatter(ImagePixelT) \ 212 template class DecoratedImageFormatter<ImagePixelT>; \ 213 template void DecoratedImageFormatter<ImagePixelT>::delegateSerialize(boost::archive::text_oarchive&, \ 214 int const, Persistable*); \ 215 template void DecoratedImageFormatter<ImagePixelT>::delegateSerialize(boost::archive::text_iarchive&, \ 216 int const, Persistable*); \ 217 template void DecoratedImageFormatter<ImagePixelT>::delegateSerialize(boost::archive::binary_oarchive&, \ 218 int const, Persistable*); \ 219 template void DecoratedImageFormatter<ImagePixelT>::delegateSerialize(boost::archive::binary_iarchive&, \ 220 int const, Persistable*); 228 #undef InstantiateFormatter
A base class for image defects.
void writeFits(std::string const &fileName, std::shared_ptr< lsst::daf::base::PropertySet const > metadata=std::shared_ptr< lsst::daf::base::PropertySet const >(), std::string const &mode="w") const
Write a FITS file.
A container for an Image and its associated metadata.