LSSTApplications  16.0+42,16.0-1-gce273f5+8,16.0-10-g230e10e+1,16.0-11-g9fe0e56+17,16.0-11-gce733cf+17,16.0-12-g5ad1ebf+9,16.0-12-gc85596e+2,16.0-13-gde155d7+2,16.0-14-g9428de4d,16.0-14-gc1cf4a94+2,16.0-15-g8e16a51+14,16.0-2-g0febb12+7,16.0-2-g839ba83+32,16.0-2-g9d5294e+22,16.0-2-gab3db49+7,16.0-2-gf41ba6b+6,16.0-2-gf4e7cdd+5,16.0-3-g6923fb6+15,16.0-3-g8e51203+2,16.0-3-g9645794+6,16.0-3-gcfd6c53+20,16.0-35-g34c7dfe62+1,16.0-4-g03cf288+11,16.0-4-g32d12de,16.0-4-g5f3a788+7,16.0-4-g7690030+30,16.0-4-g8a0f11a+16,16.0-4-ga5d8928+16,16.0-5-g0da18be+7,16.0-5-g4940a70,16.0-5-g563880a+2,16.0-5-g7742071+2,16.0-5-gb3f8a4b+26,16.0-6-g3610b4f+5,16.0-6-gf0acd13+14,16.0-8-g4dec96c+7,16.0-8-gc315727+16,16.0-9-g1de645c+7,16.0-9-gcc4efb7+6,w.2018.36
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 /*
26  * Implementation of DecoratedImageFormatter class
27  */
28 
29 #ifndef __GNUC__
30 #define __attribute__(x) /*NOTHING*/
31 #endif
32 static char const* SVNid __attribute__((unused)) = "$Id$";
33 
34 #include <cstdint>
35 #include <memory>
36 #include <string>
37 #include "boost/serialization/shared_ptr.hpp"
38 #include "boost/serialization/binary_object.hpp"
39 #include "boost/serialization/nvp.hpp"
40 #include <boost/archive/binary_oarchive.hpp>
41 #include <boost/archive/binary_iarchive.hpp>
42 
43 #include "lsst/daf/base.h"
44 #include "lsst/daf/persistence.h"
45 #include "lsst/log/Log.h"
47 #include "lsst/afw/image/Image.h"
48 
49 namespace {
50 LOG_LOGGER _log = LOG_GET("afw.DecoratedImageFormatter");
51 }
52 
53 using boost::serialization::make_nvp;
60 
61 namespace lsst {
62 namespace afw {
63 namespace formatters {
64 
65 template <typename ImagePixelT>
67 public:
68  static std::string name();
69 };
70 
71 template <>
73  static std::string name = "DecoratedImageU";
74  return name;
75 }
76 template <>
78  static std::string name = "DecoratedImageI";
79  return name;
80 }
81 template <>
83  static std::string name = "DecoratedImageF";
84  return name;
85 }
86 template <>
88  static std::string name = "DecoratedImageD";
89  return name;
90 }
91 template <>
93  static std::string name = "DecoratedImageL";
94  return name;
95 }
96 
97 template <typename ImagePixelT>
100  createInstance);
101 
102 template <typename ImagePixelT>
104  : lsst::daf::persistence::Formatter(typeid(this)) {}
105 
106 template <typename ImagePixelT>
108 
109 template <typename ImagePixelT>
113  LOGL_DEBUG(_log, "DecoratedImageFormatter write start");
114  DecoratedImage<ImagePixelT> const* ip = dynamic_cast<DecoratedImage<ImagePixelT> const*>(persistable);
115  if (ip == 0) {
116  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Persisting non-DecoratedImage");
117  }
118 
119  // TODO: Replace this with something better in DM-10776
121  if (boost) {
122  LOGL_DEBUG(_log, "DecoratedImageFormatter write BoostStorage");
123  boost->getOArchive() & *ip;
124  LOGL_DEBUG(_log, "DecoratedImageFormatter write end");
125  return;
126  }
127  auto xml = std::dynamic_pointer_cast<XmlStorage>(storage);
128  if (xml) {
129  LOGL_DEBUG(_log, "DecoratedImageFormatter write XmlStorage");
130  xml->getOArchive() & make_nvp("img", *ip);
131  LOGL_DEBUG(_log, "DecoratedImageFormatter write end");
132  return;
133  }
134  auto fits = std::dynamic_pointer_cast<FitsStorage>(storage);
135  if (fits) {
136  LOGL_DEBUG(_log, "DecoratedImageFormatter write FitsStorage");
137 
138  ip->writeFits(fits->getPath());
139  // @todo Do something with these fields?
140  // int _X0;
141  // int _Y0;
142  LOGL_DEBUG(_log, "DecoratedImageFormatter write end");
143  return;
144  }
146  "Unrecognized FormatterStorage for DecoratedImage");
147 }
148 
149 template <typename ImagePixelT>
153  LOGL_DEBUG(_log, "DecoratedImageFormatter read start");
154  // TODO: Replace this with something better in DM-10776
156  if (boost) {
157  LOGL_DEBUG(_log, "DecoratedImageFormatter read BoostStorage");
159  boost->getIArchive() & *ip;
160  LOGL_DEBUG(_log, "DecoratedImageFormatter read end");
161  return ip;
162  }
163  auto xml = std::dynamic_pointer_cast<XmlStorage>(storage);
164  if (xml) {
165  LOGL_DEBUG(_log, "DecoratedImageFormatter read XmlStorage");
167  boost->getIArchive() & make_nvp("img", *ip);
168  LOGL_DEBUG(_log, "DecoratedImageFormatter read end");
169  return ip;
170  }
171  auto fits = std::dynamic_pointer_cast<FitsStorage>(storage);
172  if (fits) {
173  LOGL_DEBUG(_log, "DecoratedImageFormatter read FitsStorage");
175  if (additionalData->exists("llcX")) {
176  int llcX = additionalData->get<int>("llcX");
177  int llcY = additionalData->get<int>("llxY");
178  int width = additionalData->get<int>("width");
179  int height = additionalData->get<int>("height");
180  box = lsst::geom::Box2I(lsst::geom::Point2I(llcX, llcY), lsst::geom::Extent2I(width, height));
181  }
183  new DecoratedImage<ImagePixelT>(fits->getPath(), fits->getHdu(), box);
184  LOGL_DEBUG(_log, "DecoratedImageFormatter read end");
185  return ip;
186  }
188  "Unrecognized FormatterStorage for DecoratedImage");
189 }
190 
191 template <typename ImagePixelT>
195  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unexpected call to update for DecoratedImage");
196 }
197 
198 template <typename ImagePixelT>
199 template <class Archive>
201  LOGL_DEBUG(_log, "DecoratedImageFormatter delegateSerialize start");
202  DecoratedImage<ImagePixelT>* ip = dynamic_cast<DecoratedImage<ImagePixelT>*>(persistable);
203  if (ip == 0) {
204  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Serializing non-DecoratedImage");
205  }
207  "DecoratedImage serialization not yet implemented");
208 }
209 
210 template <typename ImagePixelT>
215 }
216 
217 #define InstantiateFormatter(ImagePixelT) \
218  template class DecoratedImageFormatter<ImagePixelT>; \
219  template void DecoratedImageFormatter<ImagePixelT>::delegateSerialize(boost::archive::text_oarchive&, \
220  int const, Persistable*); \
221  template void DecoratedImageFormatter<ImagePixelT>::delegateSerialize(boost::archive::text_iarchive&, \
222  int const, Persistable*); \
223  template void DecoratedImageFormatter<ImagePixelT>::delegateSerialize(boost::archive::binary_oarchive&, \
224  int const, Persistable*); \
225  template void DecoratedImageFormatter<ImagePixelT>::delegateSerialize(boost::archive::binary_iarchive&, \
226  int const, Persistable*);
227 
230 InstantiateFormatter(float);
231 InstantiateFormatter(double);
233 
234 #undef InstantiateFormatter
235 } // namespace formatters
236 } // namespace afw
237 } // namespace lsst
Abstract base class for FormatterStorage implementations.
#define LOG_LOGGER
Definition: Log.h:712
Class for XML file storage.
Definition: XmlStorage.h:58
Definition: Span.h:36
#define __attribute__(x)
DecoratedImageFormatter(DecoratedImageFormatter const &)=default
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
daf_persistence package header file
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:513
Fits * fits
Definition: FitsWriter.cc:90
STL class.
LSST DM logging module built on log4cxx.
void write(lsst::daf::base::Persistable const *persistable, std::shared_ptr< lsst::daf::persistence::FormatterStorage > storage, std::shared_ptr< lsst::daf::base::PropertySet > additionalData) override
A base class for image defects.
Definition: cameraGeom.dox:3
void writeFits(std::string const &fileName, std::shared_ptr< lsst::daf::base::PropertySet const > metadata=std::shared_ptr< lsst::daf::base::PropertySet const >(), std::string const &mode="w") const
Write a FITS file.
lsst::daf::base::Persistable * read(std::shared_ptr< lsst::daf::persistence::FormatterStorage > storage, std::shared_ptr< lsst::daf::base::PropertySet > additionalData) override
void update(lsst::daf::base::Persistable *persistable, std::shared_ptr< lsst::daf::persistence::FormatterStorage > storage, std::shared_ptr< lsst::daf::base::PropertySet > additionalData) override
T dynamic_pointer_cast(T... args)
Abstract base class for all formatters.
Definition: Formatter.h:79
static std::shared_ptr< lsst::daf::persistence::Formatter > createInstance(std::shared_ptr< lsst::pex::policy::Policy > policy)
T get(T... args)
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:47
#define InstantiateFormatter(ImagePixelT)
static void delegateSerialize(Archive &ar, int const version, lsst::daf::base::Persistable *persistable)
Class for boost::serialization storage.
Definition: BoostStorage.h:59
Base class for all persistable classes.
Definition: Persistable.h:73
Class implementing persistence and retrieval for DecoratedImages.
#define LOG_GET(logger)
Returns a Log object associated with logger.
Definition: Log.h:83
An integer coordinate rectangle.
Definition: Box.h:54
A container for an Image and its associated metadata.
Definition: Image.h:409
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104