30 #define __attribute__(x)
36 #include "boost/serialization/shared_ptr.hpp"
37 #include "boost/serialization/binary_object.hpp"
38 #include <boost/archive/binary_oarchive.hpp>
39 #include <boost/archive/binary_iarchive.hpp>
43 #include "lsst/daf/base.h"
44 #include "lsst/daf/persistence.h"
45 #include "lsst/log/Log.h"
51 LOG_LOGGER _log = LOG_GET(
"afw.MaskFormatter");
54 using lsst::daf::base::Persistable;
55 using lsst::daf::persistence::BoostStorage;
56 using lsst::daf::persistence::FitsStorage;
57 using lsst::daf::persistence::FormatterStorage;
63 namespace formatters {
65 template <
typename imagePixelT>
68 static std::string
name();
73 static std::string
name =
"Mask";
77 template <
typename MaskPixelT>
81 template <
typename MaskPixelT>
83 : lsst::daf::persistence::Formatter(typeid(this)) {}
85 template <
typename MaskPixelT>
88 template <
typename MaskPixelT>
90 std::shared_ptr<lsst::daf::base::PropertySet>) {
91 LOGL_DEBUG(_log,
"MaskFormatter write start");
94 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Persisting non-Mask");
97 auto boost = std::dynamic_pointer_cast<BoostStorage>(storage);
99 LOGL_DEBUG(_log,
"MaskFormatter write BoostStorage");
100 boost->getOArchive() & *ip;
101 LOGL_DEBUG(_log,
"MaskFormatter write end");
104 auto fits = std::dynamic_pointer_cast<FitsStorage>(storage);
106 LOGL_DEBUG(_log,
"MaskFormatter write FitsStorage");
110 LOGL_DEBUG(_log,
"MaskFormatter write end");
113 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized FormatterStorage for Mask");
116 template <
typename MaskPixelT>
118 std::shared_ptr<lsst::daf::base::PropertySet>) {
119 LOGL_DEBUG(_log,
"MaskFormatter read start");
121 auto boost = std::dynamic_pointer_cast<BoostStorage>(storage);
123 LOGL_DEBUG(_log,
"MaskFormatter read BoostStorage");
125 boost->getIArchive() & *ip;
126 LOGL_DEBUG(_log,
"MaskFormatter read end");
129 auto fits = std::dynamic_pointer_cast<FitsStorage>(storage);
131 LOGL_DEBUG(_log,
"MaskFormatter read FitsStorage");
133 LOGL_DEBUG(_log,
"MaskFormatter read end");
136 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized FormatterStorage for Mask");
139 template <
typename MaskPixelT>
141 std::shared_ptr<lsst::daf::base::PropertySet>) {
142 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unexpected call to update for Mask");
145 template <
typename MaskPixelT>
146 template <
class Archive>
148 LOGL_DEBUG(_log,
"MaskFormatter delegateSerialize start");
151 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Serializing non-Mask");
153 ar & ip->_offsetRows & ip->_offsetCols;
154 ar & ip->_maskPlaneDict;
158 if (Archive::is_saving::value) {
159 cols = ip->_vwImagePtr->cols();
160 rows = ip->_vwImagePtr->rows();
161 planes = ip->_vwImagePtr->planes();
163 ar& cols& rows& planes;
164 if (Archive::is_loading::value) {
165 ip->_vwImagePtr->set_size(cols, rows, planes);
167 unsigned int pixels = cols * rows * planes;
168 MaskPixelT* data = ip->_vwImagePtr->data();
169 ar& boost::serialization::make_array(data, pixels);
170 LOGL_DEBUG(_log,
"MaskFormatter delegateSerialize end");
173 template <
typename MaskPixelT>
175 std::shared_ptr<lsst::pex::policy::Policy> policy) {
std::uint16_t MaskPixel
default type for Masks and MaskedImage Masks
Represent a 2-dimensional array of bitmask pixels.
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 >(), std::string const &mode="w") const
Write a mask to a regular FITS file.