LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
MaskedImageFormatter.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 
38 #ifndef __GNUC__
39 # define __attribute__(x) /*NOTHING*/
40 #endif
41 static char const* SVNid __attribute__((unused)) =
42  "$Id$";
43 
44 #include "boost/serialization/shared_ptr.hpp"
45 #include <boost/archive/binary_iarchive.hpp>
46 #include <boost/archive/binary_oarchive.hpp>
47 #include <boost/archive/text_iarchive.hpp>
48 #include <boost/archive/text_oarchive.hpp>
49 
50 #include "lsst/daf/base.h"
51 #include "lsst/daf/persistence.h"
52 #include "lsst/pex/logging/Trace.h"
57 
58 #define EXEC_TRACE 20
59 static void execTrace(std::string s, int level = EXEC_TRACE) {
60  lsst::pex::logging::Trace("afw.MaskedImageFormatter", level, s);
61 }
62 
70 
71 namespace lsst {
72 namespace afw {
73 namespace formatters {
74 
75 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
77 public:
78  static std::string name();
79 };
80 
82  static std::string name = "MaskedImageU";
83  return name;
84 }
86  static std::string name = "MaskedImageI";
87  return name;
88 }
90  static std::string name = "MaskedImageF";
91  return name;
92 }
94  static std::string name = "MaskedImageD";
95  return name;
96 }
98  static std::string name = "MaskedImageL";
99  return name;
100 }
101 
102 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
104  MaskPixelT,
105  VariancePixelT>::registration(
108  createInstance);
109 
110 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
113  )
114  :
115  lsst::daf::persistence::Formatter(typeid(this)) {
116 }
117 
118 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
120 }
121 
122 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
124  Persistable const* persistable,
125  Storage::Ptr storage,
127  execTrace("MaskedImageFormatter write start");
129  dynamic_cast<MaskedImage<ImagePixelT, MaskPixelT> const*>(persistable);
130  if (ip == 0) {
131  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Persisting non-MaskedImage");
132  }
133  if (typeid(*storage) == typeid(BoostStorage)) {
134  execTrace("MaskedImageFormatter write BoostStorage");
135  BoostStorage* boost = dynamic_cast<BoostStorage*>(storage.get());
136  boost->getOArchive() & *ip;
137  execTrace("MaskedImageFormatter write end");
138  return;
139  }
140  else if (typeid(*storage) == typeid(FitsStorage)) {
141  execTrace("MaskedImageFormatter write FitsStorage");
142  FitsStorage* fits = dynamic_cast<FitsStorage*>(storage.get());
143  ip->writeFits(fits->getPath());
144  execTrace("MaskedImageFormatter write end");
145  return;
146  }
147  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized Storage for MaskedImage");
148 }
149 
150 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
152  Storage::Ptr storage,
154  )
155 {
156  execTrace("MaskedImageFormatter read start");
157  if (typeid(*storage) == typeid(BoostStorage)) {
158  execTrace("MaskedImageFormatter read BoostStorage");
159  BoostStorage* boost = dynamic_cast<BoostStorage*>(storage.get());
161  boost->getIArchive() & *ip;
162  execTrace("MaskedImageFormatter read end");
163  return ip;
164  }
165  else if (typeid(*storage) == typeid(FitsStorage)) {
166  execTrace("MaskedImageFormatter read FitsStorage");
167  FitsStorage* fits = dynamic_cast<FitsStorage*>(storage.get());
169  execTrace("MaskedImageFormatter read end");
170  return ip;
171  }
172  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized Storage for MaskedImage");
173 }
174 
175 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
177  Persistable*,
178  Storage::Ptr,
180  )
181 {
182  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
183  "Unexpected call to update for MaskedImage");
184 }
185 
186 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT> template <class Archive>
188  Archive& ar, unsigned int const, Persistable* persistable) {
189  execTrace("MaskedImageFormatter delegateSerialize start");
191  dynamic_cast<MaskedImage<ImagePixelT, MaskPixelT, VariancePixelT>*>(persistable);
192  if (ip == 0) {
193  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Serializing non-MaskedImage");
194  }
195  ar & ip->_image & ip->_variance & ip->_mask;
196  execTrace("MaskedImageFormatter delegateSerialize end");
197 }
198 
199 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
201  MaskPixelT,
202  VariancePixelT>::createInstance(
206 }
207 
209 #define INSTANTIATE(I, M, V) \
210  template class MaskedImageFormatter<I, M, V>; \
211  template void MaskedImageFormatter<I, M, V>::delegateSerialize<boost::archive::text_oarchive>( \
212  boost::archive::text_oarchive &, unsigned int const, Persistable *); \
213  template void MaskedImageFormatter<I, M, V>::delegateSerialize<boost::archive::text_iarchive>( \
214  boost::archive::text_iarchive &, unsigned int const, Persistable *); \
215  template void MaskedImageFormatter<I, M, V>::delegateSerialize<boost::archive::binary_oarchive>( \
216  boost::archive::binary_oarchive &, unsigned int const, Persistable *); \
217  template void MaskedImageFormatter<I, M, V>::delegateSerialize<boost::archive::binary_iarchive>( \
218  boost::archive::binary_iarchive &, unsigned int const, Persistable *);
219 
222 INSTANTIATE(float, MaskPixel, VariancePixel)
223 INSTANTIATE(double, MaskPixel, VariancePixel)
224 INSTANTIATE(uint64_t, MaskPixel, VariancePixel)
226 
227 }}} // namespace lsst::afw::formatters
boost::uint16_t MaskPixel
static void delegateSerialize(Archive &ar, unsigned int const version, lsst::daf::base::Persistable *persistable)
table::Key< std::string > name
Definition: ApCorrMap.cc:71
boost::shared_ptr< Formatter > Ptr
Definition: Formatter.h:81
#define __attribute__(x)
daf_persistence package header file
virtual boost::archive::text_iarchive & getIArchive(void)
boost::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:90
virtual std::string const & getPath(void)
Definition: FitsStorage.cc:109
definition of the Trace messaging facilities
virtual void write(lsst::daf::base::Persistable const *persistable, lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
virtual lsst::daf::base::Persistable * read(lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
boost::shared_ptr< Policy > Ptr
Definition: Policy.h:172
limited backward compatibility to the DC2 run-time trace facilities
Definition: Trace.h:93
Construct a static instance of this helper class to register a Formatter subclass in the FormatterReg...
Definition: Formatter.h:138
Class for FITS file storage.
Definition: FitsStorage.h:52
Interface for MaskedImageFormatter class.
void writeFits(std::string const &fileName, boost::shared_ptr< daf::base::PropertySet const > metadata=boost::shared_ptr< daf::base::PropertySet const >(), boost::shared_ptr< daf::base::PropertySet const > imageMetadata=boost::shared_ptr< daf::base::PropertySet const >(), boost::shared_ptr< daf::base::PropertySet const > maskMetadata=boost::shared_ptr< daf::base::PropertySet const >(), boost::shared_ptr< daf::base::PropertySet const > varianceMetadata=boost::shared_ptr< daf::base::PropertySet const >()) const
Write a MaskedImage to a regular FITS file.
Definition: MaskedImage.cc:562
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:77
Interface for MaskFormatter class.
float VariancePixel
! default type for Masks and MaskedImage Masks
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
virtual boost::archive::text_oarchive & getOArchive(void)
#define INSTANTIATE(T)
Class implementing persistence and retrieval for MaskedImages.
Class for boost::serialization storage.
Definition: BoostStorage.h:58
Base class for all persistable classes.
Definition: Persistable.h:74
Implementation of the Class MaskedImage.
MaskedImageFormatter(lsst::pex::policy::Policy::Ptr policy)
#define EXEC_TRACE
virtual void update(lsst::daf::base::Persistable *persistable, lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
Abstract base class for storage implementations.
Definition: Storage.h:60
Interface for ImageFormatter class.