39 # define __attribute__(x)
46 #include "boost/serialization/shared_ptr.hpp"
47 #include "boost/serialization/binary_object.hpp"
48 #include "boost/serialization/nvp.hpp"
50 #include <boost/archive/text_oarchive.hpp>
51 #include <boost/archive/text_iarchive.hpp>
52 #include <boost/archive/binary_oarchive.hpp>
53 #include <boost/archive/binary_iarchive.hpp>
65 using boost::serialization::make_nvp;
74 namespace afwGeom = lsst::afw::geom;
78 namespace formatters {
80 template <
typename ImagePixelT>
83 static std::string
name();
87 static std::string
name =
"ImageU";
91 static std::string
name =
"ImageI";
95 static std::string
name =
"ImageF";
99 static std::string
name =
"ImageD";
103 static std::string
name =
"ImageL";
107 template <
typename ImagePixelT>
113 template <
typename ImagePixelT>
118 lsst::daf::persistence::Formatter(typeid(this))
122 template <
typename ImagePixelT>
128 namespace dafBase = lsst::daf::base;
132 template <
typename ImagePixelT>
135 Storage::Ptr storage,
138 LOGL_DEBUG(_log,
"ImageFormatter write start");
141 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Persisting non-Image");
144 LOGL_DEBUG(_log,
"ImageFormatter write BoostStorage");
150 else if (
typeid(*storage) ==
typeid(
XmlStorage)) {
151 LOGL_DEBUG(_log,
"ImageFormatter write XmlStorage");
157 else if (
typeid(*storage) ==
typeid(
FitsStorage)) {
158 LOGL_DEBUG(_log,
"ImageFormatter write FitsStorage");
169 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized Storage for Image");
172 template <
typename ImagePixelT>
175 LOGL_DEBUG(_log,
"ImageFormatter read start");
177 LOGL_DEBUG(_log,
"ImageFormatter read BoostStorage");
184 else if (
typeid(*storage) ==
typeid(
XmlStorage)) {
185 LOGL_DEBUG(_log,
"ImageFormatter read XmlStorage");
194 LOGL_DEBUG(_log,
"ImageFormatter read FitsStorage");
197 if (additionalData->exists(
"llcX")) {
198 int llcX = additionalData->get<
int>(
"llcX");
199 int llcY = additionalData->get<
int>(
"llcY");
200 int width = additionalData->get<
int>(
"width");
201 int height = additionalData->get<
int>(
"height");
208 if (additionalData->exists(
"imageOrigin")) {
209 std::string originStr = additionalData->get<std::string>(
"imageOrigin");
210 if (originStr ==
"LOCAL") {
212 }
else if (originStr ==
"PARENT") {
216 lsst::pex::exceptions::RuntimeError,
217 (
boost::format(
"Unknown ImageOrigin type %s specified in additional"
218 "data for retrieving Image from fits")%originStr
238 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized Storage for Image");
241 template <
typename ImagePixelT>
246 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unexpected call to update for Image");
249 template <
typename ImagePixelT>
template <
class Archive>
251 Archive& ar,
int const,
Persistable* persistable) {
252 LOGL_DEBUG(_log,
"ImageFormatter delegateSerialize start");
255 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Serializing non-Image");
258 if (Archive::is_saving::value) {
262 ar & make_nvp(
"width", width) & make_nvp(
"height", height);
263 if (Archive::is_loading::value) {
264 std::unique_ptr<Image<ImagePixelT> > ni(
268 ar & make_nvp(
"array",
269 boost::serialization::make_array(array.getData(), array.getNumElements()));
272 ndarray::Array<ImagePixelT, 2, 2> array = ndarray::dynamic_dimension_cast<2>(ip->
getArray());
274 array = ndarray::copy(ip->
getArray());
275 ar & make_nvp(
"array", boost::serialization::make_array(array.getData(), array.getNumElements()));
279 template <
typename ImagePixelT>
285 #define InstantiateFormatter(ImagePixelT) \
286 template class ImageFormatter<ImagePixelT >; \
287 template void ImageFormatter<ImagePixelT >::delegateSerialize(boost::archive::text_oarchive&, int const, Persistable*); \
288 template void ImageFormatter<ImagePixelT >::delegateSerialize(boost::archive::text_iarchive&, int const, Persistable*); \
289 template void ImageFormatter<ImagePixelT >::delegateSerialize(boost::archive::xml_oarchive&, int const, Persistable*); \
290 template void ImageFormatter<ImagePixelT >::delegateSerialize(boost::archive::xml_iarchive&, int const, Persistable*); \
291 template void ImageFormatter<ImagePixelT >::delegateSerialize(boost::archive::binary_oarchive&, int const, Persistable*); \
292 template void ImageFormatter<ImagePixelT >::delegateSerialize(boost::archive::binary_iarchive&, int const, Persistable*);
300 #undef InstantiateSerializer
virtual int getHdu(void)
Return the HDU to read from the FITS file.
std::shared_ptr< Policy > Ptr
Class for XML file storage.
table::Key< std::string > name
daf_persistence package header file
Class for FITS file storage.
virtual boost::archive::text_oarchive & getOArchive(void)
Get a boost::serialization archive suitable for output.
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
void writeFits(std::string const &fileName, boost::shared_ptr< lsst::daf::base::PropertySet const > metadata=boost::shared_ptr< lsst::daf::base::PropertySet const >(), std::string const &mode="w") const
Write an image to a regular FITS file.
An integer coordinate rectangle.
table::Key< table::Array< Kernel::Pixel > > image
LSST DM logging module built on log4cxx.
virtual boost::archive::xml_iarchive & getIArchive(void)
Get a boost::serialization XML archive suitable for input.
void ImageT ImageT int float saturatedPixelValue int const width
int getHeight() const
Return the number of rows in the image.
void ImageT ImageT int float saturatedPixelValue int const height
virtual boost::archive::text_iarchive & getIArchive(void)
Get a boost::serialization archive suitable for input.
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
virtual std::string const & getPath(void)
Return the pathname for the FITS file.
Class for boost::serialization storage.
Base class for all persistable classes.
virtual boost::archive::xml_oarchive & getOArchive(void)
Get a boost::serialization XML archive suitable for output.
std::shared_ptr< PropertySet > Ptr
#define LOG_GET(logger)
Returns a Log object associated with logger.
int getWidth() const
Return the number of columns in the image.
A class to represent a 2-dimensional array of pixels.
Abstract base class for storage implementations.