LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
DecoratedImageFormatter.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/scoped_ptr.hpp"
45 #include "boost/serialization/shared_ptr.hpp"
46 #include "boost/serialization/binary_object.hpp"
47 #include "boost/serialization/nvp.hpp"
48 #include <boost/archive/binary_oarchive.hpp>
49 #include <boost/archive/binary_iarchive.hpp>
50 
51 #include "lsst/daf/base.h"
52 #include "lsst/daf/persistence.h"
53 #include "lsst/pex/logging/Trace.h"
55 #include "lsst/afw/image/Image.h"
56 
57 
58 #define EXEC_TRACE 20
59 static void execTrace(std::string s, int level = EXEC_TRACE) {
60  lsst::pex::logging::Trace("afw.DecoratedImageFormatter", level, s);
61 }
62 
63 using boost::serialization::make_nvp;
70 
71 namespace lsst {
72 namespace afw {
73 namespace formatters {
74 
75 template <typename ImagePixelT>
77 public:
78  static std::string name();
79 };
80 
82  static std::string name = "DecoratedImageU";
83  return name;
84 }
85 template<> std::string DecoratedImageFormatterTraits<int>::name() {
86  static std::string name = "DecoratedImageI";
87  return name;
88 }
90  static std::string name = "DecoratedImageF";
91  return name;
92 }
94  static std::string name = "DecoratedImageD";
95  return name;
96 }
98  static std::string name = "DecoratedImageL";
99  return name;
100 }
101 
102 template <typename ImagePixelT>
106  createInstance);
107 
108 template <typename ImagePixelT>
111  )
112  : lsst::daf::persistence::Formatter(typeid(this))
113 {
114 }
115 
116 template <typename ImagePixelT>
118 }
119 
120 template <typename ImagePixelT>
122  Persistable const* persistable,
123  Storage::Ptr storage,
125  )
126 {
127  execTrace("DecoratedImageFormatter write start");
128  DecoratedImage<ImagePixelT> const* ip = dynamic_cast<DecoratedImage<ImagePixelT> const*>(persistable);
129  if (ip == 0) {
130  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Persisting non-DecoratedImage");
131  }
132  if (typeid(*storage) == typeid(BoostStorage)) {
133  execTrace("DecoratedImageFormatter write BoostStorage");
134  BoostStorage* boost = dynamic_cast<BoostStorage*>(storage.get());
135  boost->getOArchive() & *ip;
136  execTrace("DecoratedImageFormatter write end");
137  return;
138  } else if (typeid(*storage) == typeid(XmlStorage)) {
139  execTrace("DecoratedImageFormatter write XmlStorage");
140  XmlStorage* boost = dynamic_cast<XmlStorage*>(storage.get());
141  boost->getOArchive() & make_nvp("img", *ip);
142  execTrace("DecoratedImageFormatter write end");
143  return;
144  } else if (typeid(*storage) == typeid(FitsStorage)) {
145  execTrace("DecoratedImageFormatter write FitsStorage");
146  FitsStorage* fits = dynamic_cast<FitsStorage*>(storage.get());
148 
149  ip->writeFits(fits->getPath());
150  // \todo Do something with these fields?
151  // int _X0;
152  // int _Y0;
153  execTrace("DecoratedImageFormatter write end");
154  return;
155  }
156  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
157  "Unrecognized Storage for DecoratedImage");
158 }
159 
160 template <typename ImagePixelT>
162  Storage::Ptr storage,
164  )
165 {
166  execTrace("DecoratedImageFormatter read start");
167  if (typeid(*storage) == typeid(BoostStorage)) {
168  execTrace("DecoratedImageFormatter read BoostStorage");
169  BoostStorage* boost = dynamic_cast<BoostStorage*>(storage.get());
171  boost->getIArchive() & *ip;
172  execTrace("DecoratedImageFormatter read end");
173  return ip;
174  } else if (typeid(*storage) == typeid(XmlStorage)) {
175  execTrace("DecoratedImageFormatter read XmlStorage");
176  XmlStorage* boost = dynamic_cast<XmlStorage*>(storage.get());
178  boost->getIArchive() & make_nvp("img", *ip);
179  execTrace("DecoratedImageFormatter read end");
180  return ip;
181  } else if(typeid(*storage) == typeid(FitsStorage)) {
182 
183  execTrace("DecoratedImageFormatter read FitsStorage");
184  FitsStorage* fits = dynamic_cast<FitsStorage*>(storage.get());
185 
187  // \todo Do something with these fields?
188  // int _X0;
189  // int _Y0;
190  execTrace("DecoratedImageFormatter read end");
191  return ip;
192  }
193  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
194  "Unrecognized Storage for DecoratedImage");
195 }
196 
197 template <typename ImagePixelT>
202  )
203 {
204  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
205  "Unexpected call to update for DecoratedImage");
206 }
207 
208 template <typename ImagePixelT> template <class Archive>
210  Archive&,
211  int const,
212  Persistable* persistable
213  )
214 {
215  execTrace("DecoratedImageFormatter delegateSerialize start");
216  DecoratedImage<ImagePixelT>* ip = dynamic_cast<DecoratedImage<ImagePixelT>*>(persistable);
217  if (ip == 0) {
218  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Serializing non-DecoratedImage");
219  }
220  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
221  "DecoratedImage serialization not yet implemented");
222 }
223 
224 template <typename ImagePixelT>
227  )
228 {
230 }
231 
232 #define InstantiateFormatter(ImagePixelT) \
233  template class DecoratedImageFormatter<ImagePixelT >; \
234  template void DecoratedImageFormatter<ImagePixelT >::delegateSerialize(boost::archive::text_oarchive&, int const, Persistable*); \
235  template void DecoratedImageFormatter<ImagePixelT >::delegateSerialize(boost::archive::text_iarchive&, int const, Persistable*); \
236  template void DecoratedImageFormatter<ImagePixelT >::delegateSerialize(boost::archive::binary_oarchive&, int const, Persistable*); \
237  template void DecoratedImageFormatter<ImagePixelT >::delegateSerialize(boost::archive::binary_iarchive&, int const, Persistable*);
238 
239 InstantiateFormatter(boost::uint16_t);
241 InstantiateFormatter(float);
242 InstantiateFormatter(double);
243 InstantiateFormatter(boost::uint64_t);
244 
245 #undef InstantiateFormatter
246 
247 
248 }}} // namespace lsst::afw::formatters
static lsst::daf::persistence::FormatterRegistration registration
Class for XML file storage.
Definition: XmlStorage.h:57
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
boost::shared_ptr< Policy > Ptr
Definition: Policy.h:172
definition of the Trace messaging facilities
virtual void update(lsst::daf::base::Persistable *persistable, lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
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
virtual boost::archive::xml_iarchive & getIArchive(void)
Definition: XmlStorage.cc:114
virtual lsst::daf::base::Persistable * read(lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
DecoratedImageFormatter(lsst::pex::policy::Policy::Ptr policy)
Support for 2-D images.
#define EXEC_TRACE
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
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
virtual boost::archive::text_oarchive & getOArchive(void)
virtual boost::archive::xml_oarchive & getOArchive(void)
Definition: XmlStorage.cc:107
#define InstantiateFormatter(ImagePixelT)
boost::shared_ptr< Storage > Ptr
Definition: Storage.h:62
static void delegateSerialize(Archive &ar, int const version, lsst::daf::base::Persistable *persistable)
Class for boost::serialization storage.
Definition: BoostStorage.h:58
Base class for all persistable classes.
Definition: Persistable.h:74
Class implementing persistence and retrieval for DecoratedImages.
virtual void write(lsst::daf::base::Persistable const *persistable, lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
Interface for DecoratedImageFormatter class.
static lsst::daf::persistence::Formatter::Ptr createInstance(lsst::pex::policy::Policy::Ptr policy)
Abstract base class for storage implementations.
Definition: Storage.h:60
A container for an Image and its associated metadata.
Definition: Image.h:614