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::Storage;
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");
96 if (
typeid(*storage) ==
typeid(BoostStorage)) {
97 LOGL_DEBUG(_log,
"MaskFormatter write BoostStorage");
98 BoostStorage* boost =
dynamic_cast<BoostStorage*
>(storage.get());
99 boost->getOArchive() & *ip;
100 LOGL_DEBUG(_log,
"MaskFormatter write end");
102 }
else if (
typeid(*storage) ==
typeid(FitsStorage)) {
103 LOGL_DEBUG(_log,
"MaskFormatter write FitsStorage");
104 FitsStorage* fits =
dynamic_cast<FitsStorage*
>(storage.get());
108 LOGL_DEBUG(_log,
"MaskFormatter write end");
111 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized Storage for Mask");
114 template <
typename MaskPixelT>
116 std::shared_ptr<lsst::daf::base::PropertySet>) {
117 LOGL_DEBUG(_log,
"MaskFormatter read start");
118 if (
typeid(*storage) ==
typeid(BoostStorage)) {
119 LOGL_DEBUG(_log,
"MaskFormatter read BoostStorage");
120 BoostStorage* boost =
dynamic_cast<BoostStorage*
>(storage.get());
122 boost->getIArchive() & *ip;
123 LOGL_DEBUG(_log,
"MaskFormatter read end");
125 }
else if (
typeid(*storage) ==
typeid(FitsStorage)) {
126 LOGL_DEBUG(_log,
"MaskFormatter read FitsStorage");
127 FitsStorage* fits =
dynamic_cast<FitsStorage*
>(storage.get());
129 LOGL_DEBUG(_log,
"MaskFormatter read end");
132 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized Storage for Mask");
135 template <
typename MaskPixelT>
137 std::shared_ptr<lsst::daf::base::PropertySet>) {
138 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unexpected call to update for Mask");
141 template <
typename MaskPixelT>
142 template <
class Archive>
144 LOGL_DEBUG(_log,
"MaskFormatter delegateSerialize start");
147 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Serializing non-Mask");
149 ar & ip->_offsetRows & ip->_offsetCols;
150 ar & ip->_maskPlaneDict;
154 if (Archive::is_saving::value) {
155 cols = ip->_vwImagePtr->cols();
156 rows = ip->_vwImagePtr->rows();
157 planes = ip->_vwImagePtr->planes();
159 ar& cols& rows& planes;
160 if (Archive::is_loading::value) {
161 ip->_vwImagePtr->set_size(cols, rows, planes);
163 unsigned int pixels = cols * rows * planes;
164 MaskPixelT* data = ip->_vwImagePtr->data();
165 ar& boost::serialization::make_array(data, pixels);
166 LOGL_DEBUG(_log,
"MaskFormatter delegateSerialize end");
169 template <
typename MaskPixelT>
171 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.