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");
118 if (
typeid(*storage) ==
typeid(BoostStorage)) {
119 LOGL_DEBUG(_log,
"DecoratedImageFormatter write BoostStorage");
120 BoostStorage* boost =
dynamic_cast<BoostStorage*
>(storage.get());
121 boost->getOArchive() & *ip;
122 LOGL_DEBUG(_log,
"DecoratedImageFormatter write end");
124 }
else if (
typeid(*storage) ==
typeid(XmlStorage)) {
125 LOGL_DEBUG(_log,
"DecoratedImageFormatter write XmlStorage");
126 XmlStorage* boost =
dynamic_cast<XmlStorage*
>(storage.get());
127 boost->getOArchive() & make_nvp(
"img", *ip);
128 LOGL_DEBUG(_log,
"DecoratedImageFormatter write end");
130 }
else if (
typeid(*storage) ==
typeid(FitsStorage)) {
131 LOGL_DEBUG(_log,
"DecoratedImageFormatter write FitsStorage");
132 FitsStorage* fits =
dynamic_cast<FitsStorage*
>(storage.get());
139 LOGL_DEBUG(_log,
"DecoratedImageFormatter write end");
142 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized FormatterStorage for DecoratedImage");
145 template <
typename ImagePixelT>
147 std::shared_ptr<lsst::daf::base::PropertySet>) {
148 LOGL_DEBUG(_log,
"DecoratedImageFormatter read start");
149 if (
typeid(*storage) ==
typeid(BoostStorage)) {
150 LOGL_DEBUG(_log,
"DecoratedImageFormatter read BoostStorage");
151 BoostStorage* boost =
dynamic_cast<BoostStorage*
>(storage.get());
153 boost->getIArchive() & *ip;
154 LOGL_DEBUG(_log,
"DecoratedImageFormatter read end");
156 }
else if (
typeid(*storage) ==
typeid(XmlStorage)) {
157 LOGL_DEBUG(_log,
"DecoratedImageFormatter read XmlStorage");
158 XmlStorage* boost =
dynamic_cast<XmlStorage*
>(storage.get());
160 boost->getIArchive() & make_nvp(
"img", *ip);
161 LOGL_DEBUG(_log,
"DecoratedImageFormatter read end");
163 }
else if (
typeid(*storage) ==
typeid(FitsStorage)) {
164 LOGL_DEBUG(_log,
"DecoratedImageFormatter read FitsStorage");
165 FitsStorage* fits =
dynamic_cast<FitsStorage*
>(storage.get());
171 LOGL_DEBUG(_log,
"DecoratedImageFormatter read end");
174 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized FormatterStorage for DecoratedImage");
177 template <
typename ImagePixelT>
179 std::shared_ptr<lsst::daf::persistence::FormatterStorage>,
180 std::shared_ptr<lsst::daf::base::PropertySet>) {
181 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unexpected call to update for DecoratedImage");
184 template <
typename ImagePixelT>
185 template <
class Archive>
187 LOGL_DEBUG(_log,
"DecoratedImageFormatter delegateSerialize start");
190 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Serializing non-DecoratedImage");
192 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
193 "DecoratedImage serialization not yet implemented");
196 template <
typename ImagePixelT>
198 std::shared_ptr<lsst::pex::policy::Policy> policy) {
199 return std::shared_ptr<lsst::daf::persistence::Formatter>(
203 #define InstantiateFormatter(ImagePixelT) \
204 template class DecoratedImageFormatter<ImagePixelT>; \
205 template void DecoratedImageFormatter<ImagePixelT>::delegateSerialize(boost::archive::text_oarchive&, \
206 int const, Persistable*); \
207 template void DecoratedImageFormatter<ImagePixelT>::delegateSerialize(boost::archive::text_iarchive&, \
208 int const, Persistable*); \
209 template void DecoratedImageFormatter<ImagePixelT>::delegateSerialize(boost::archive::binary_oarchive&, \
210 int const, Persistable*); \
211 template void DecoratedImageFormatter<ImagePixelT>::delegateSerialize(boost::archive::binary_iarchive&, \
212 int const, Persistable*);
220 #undef InstantiateFormatter
table::Key< std::string > name
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.