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
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Attributes | List of all members
lsst::afw::formatters::ImageFormatter< ImagePixelT > Class Template Reference

Class implementing persistence and retrieval for Images. More...

#include <ImageFormatter.h>

Inheritance diagram for lsst::afw::formatters::ImageFormatter< ImagePixelT >:
lsst::daf::persistence::Formatter lsst::daf::base::Citizen

Public Member Functions

virtual ~ImageFormatter (void)
 
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)
 
virtual void update (lsst::daf::base::Persistable *persistable, lsst::daf::persistence::Storage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)
 
- Public Member Functions inherited from lsst::daf::persistence::Formatter
virtual ~Formatter (void)
 
- Public Member Functions inherited from lsst::daf::base::Citizen
 Citizen (const std::type_info &)
 
 Citizen (Citizen const &)
 
 ~Citizen ()
 
Citizenoperator= (Citizen const &)
 
std::string repr () const
 Return a string representation of a Citizen. More...
 
void markPersistent (void)
 Mark a Citizen as persistent and not destroyed until process end. More...
 
memId getId () const
 Return the Citizen's ID. More...
 

Static Public Member Functions

static
lsst::daf::persistence::Formatter::Ptr 
createInstance (lsst::pex::policy::Policy::Ptr policy)
 
template<class Archive >
static void delegateSerialize (Archive &ar, int const version, lsst::daf::base::Persistable *persistable)
 
- Static Public Member Functions inherited from lsst::daf::persistence::Formatter
static Formatter::Ptr lookupFormatter (std::string const &persistableType, lsst::pex::policy::Policy::Ptr policy)
 
static Formatter::Ptr lookupFormatter (std::type_info const &persistableType, lsst::pex::policy::Policy::Ptr policy)
 
- Static Public Member Functions inherited from lsst::daf::base::Citizen
static bool hasBeenCorrupted ()
 Check all allocated blocks for corruption. More...
 
static memId getNextMemId ()
 Return the memId of the next object to be allocated. More...
 
static int init ()
 Called once when the memory system is being initialised. More...
 
static int census (int, memId startingMemId=0)
 How many active Citizens are there? More...
 
static void census (std::ostream &stream, memId startingMemId=0)
 Print a list of all active Citizens to stream, sorted by ID. More...
 
static const std::vector
< const Citizen * > * 
census ()
 Return a (newly allocated) std::vector of active Citizens sorted by ID. More...
 
static memId setNewCallbackId (memId id)
 Call the NewCallback when block is allocated. More...
 
static memId setDeleteCallbackId (memId id)
 Call the current DeleteCallback when block is deleted. More...
 
static memNewCallback setNewCallback (memNewCallback func)
 Set the NewCallback function. More...
 
static memCallback setDeleteCallback (memCallback func)
 Set the DeleteCallback function. More...
 
static memCallback setCorruptionCallback (memCallback func)
 Set the CorruptionCallback function. More...
 

Private Member Functions

 ImageFormatter (lsst::pex::policy::Policy::Ptr policy)
 

Static Private Attributes

static
lsst::daf::persistence::FormatterRegistration 
registration
 

Additional Inherited Members

- Public Types inherited from lsst::daf::persistence::Formatter
typedef boost::shared_ptr
< Formatter
Ptr
 
typedef Ptr(* FactoryPtr )(lsst::pex::policy::Policy::Ptr)
 
- Public Types inherited from lsst::daf::base::Citizen
enum  { magicSentinel = 0xdeadbeef }
 
typedef unsigned long memId
 Type of the block's ID. More...
 
typedef memId(* memNewCallback )(const memId cid)
 A function used to register a callback. More...
 
typedef memId(* memCallback )(const Citizen *ptr)
 
- Protected Member Functions inherited from lsst::daf::persistence::Formatter
 Formatter (std::type_info const &type)
 

Detailed Description

template<typename ImagePixelT>
class lsst::afw::formatters::ImageFormatter< ImagePixelT >

Class implementing persistence and retrieval for Images.

Definition at line 54 of file ImageFormatter.h.

Constructor & Destructor Documentation

template<typename ImagePixelT >
lsst::afw::formatters::ImageFormatter< ImagePixelT >::~ImageFormatter ( void  )
virtual

Definition at line 123 of file ImageFormatter.cc.

124 {
125 }
template<typename ImagePixelT >
lsst::afw::formatters::ImageFormatter< ImagePixelT >::ImageFormatter ( lsst::pex::policy::Policy::Ptr  policy)
explicitprivate

Definition at line 114 of file ImageFormatter.cc.

117  :
119 {
120 }
Abstract base class for all formatters.
Definition: Formatter.h:79

Member Function Documentation

template<typename ImagePixelT >
lsst::daf::persistence::Formatter::Ptr lsst::afw::formatters::ImageFormatter< ImagePixelT >::createInstance ( lsst::pex::policy::Policy::Ptr  policy)
static

Definition at line 280 of file ImageFormatter.cc.

281  {
282  return lsst::daf::persistence::Formatter::Ptr(new ImageFormatter<ImagePixelT>(policy));
283 }
boost::shared_ptr< Formatter > Ptr
Definition: Formatter.h:81
template<typename ImagePixelT >
template<class Archive >
template void lsst::afw::formatters::ImageFormatter< ImagePixelT >::delegateSerialize ( Archive &  ar,
int const  version,
lsst::daf::base::Persistable persistable 
)
static

Definition at line 250 of file ImageFormatter.cc.

251  {
252  execTrace("ImageFormatter delegateSerialize start");
253  Image<ImagePixelT>* ip = dynamic_cast<Image<ImagePixelT>*>(persistable);
254  if (ip == 0) {
255  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Serializing non-Image");
256  }
257  int width, height;
258  if (Archive::is_saving::value) {
259  width = ip->getWidth();
260  height = ip->getHeight();
261  }
262  ar & make_nvp("width", width) & make_nvp("height", height);
263  if (Archive::is_loading::value) {
264  boost::scoped_ptr<Image<ImagePixelT> > ni(
265  new Image<ImagePixelT>(geom::Extent2I(width, height))
266  );
267  typename Image<ImagePixelT>::Array array = ni->getArray();
268  ar & make_nvp("array",
269  boost::serialization::make_array(array.getData(), array.getNumElements()));
270  ip->swap(*ni);
271  } else {
273  if(array.empty())
274  array = ndarray::copy(ip->getArray());
275  ar & make_nvp("array", boost::serialization::make_array(array.getData(), array.getNumElements()));
276  }
277 }
Array< T, N, C_ > dynamic_dimension_cast(Array< T, N, C > const &array)
Definition: casts.h:105
SelectEigenView< T >::Type copy(Eigen::EigenBase< T > const &other)
Copy an arbitrary Eigen expression into a new EigenView.
Definition: eigen.h:390
void ImageT ImageT int float saturatedPixelValue int const width
Definition: saturated.cc:44
int getNumElements() const
Return the total number of elements in the array.
Definition: ArrayBase.h:142
int getHeight() const
Return the number of rows in the image.
Definition: Image.h:239
Element * getData() const
Return a raw pointer to the first element of the array.
Definition: ArrayBase.h:117
void ImageT ImageT int float saturatedPixelValue int const height
Definition: saturated.cc:44
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
bool empty() const
Return true if the first dimension has no elements.
A multidimensional strided array.
Definition: Array.h:47
int getWidth() const
Return the number of columns in the image.
Definition: Image.h:237
void swap(Image &rhs)
Definition: Image.cc:606
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:415
template<typename ImagePixelT >
Persistable * lsst::afw::formatters::ImageFormatter< ImagePixelT >::read ( lsst::daf::persistence::Storage::Ptr  storage,
lsst::daf::base::PropertySet::Ptr  additionalData 
)
virtual

Read a Persistable instance from a Storage instance.

Parameters
[in]storagePointer to the Storage instance.
[in]additionalDataAdditional data used to find the proper instance within the Storage.
Returns
Shared pointer to the new Persistable instance.

Implements lsst::daf::persistence::Formatter.

Definition at line 173 of file ImageFormatter.cc.

174  {
175  execTrace("ImageFormatter read start");
176  if (typeid(*storage) == typeid(BoostStorage)) {
177  execTrace("ImageFormatter read BoostStorage");
178  BoostStorage* boost = dynamic_cast<BoostStorage*>(storage.get());
180  boost->getIArchive() & *ip;
181  execTrace("ImageFormatter read end");
182  return ip;
183  }
184  else if (typeid(*storage) == typeid(XmlStorage)) {
185  execTrace("ImageFormatter read XmlStorage");
186  XmlStorage* boost = dynamic_cast<XmlStorage*>(storage.get());
188  boost->getIArchive() & make_nvp("img", *ip);
189  execTrace("ImageFormatter read end");
190  return ip;
191  }
192  else if(typeid(*storage) == typeid(FitsStorage)) {
193 
194  execTrace("ImageFormatter read FitsStorage");
195  FitsStorage* fits = dynamic_cast<FitsStorage*>(storage.get());
196  geom::Box2I box;
197  if (additionalData->exists("llcX")) {
198  int llcX = additionalData->get<int>("llcX");
199  int llcY = additionalData->get<int>("llcY");
200  int width = additionalData->get<int>("width");
201  int height = additionalData->get<int>("height");
202  box = geom::Box2I(
203  geom::Point2I(llcX, llcY),
204  geom::Extent2I(width, height)
205  );
206  }
208  if (additionalData->exists("imageOrigin")) {
209  std::string originStr = additionalData->get<std::string>("imageOrigin");
210  if (originStr == "LOCAL") {
211  origin = afwImg::LOCAL;
212  } else if (originStr == "PARENT") {
213  origin = afwImg::PARENT;
214  } else {
215  throw LSST_EXCEPT(
216  lsst::pex::exceptions::RuntimeError,
217  (boost::format("Unknown ImageOrigin type %s specified in additional"
218  "data for retrieving Image from fits")%originStr
219 
220  ).str()
221  );
222  }
223  }
225 
227  fits->getPath(), fits->getHdu(),
229  box, origin
230  );
231  // \note We're throwing away the metadata
232  // \todo Do something with these fields?
233  // int _X0;
234  // int _Y0;
235  execTrace("ImageFormatter read end");
236  return ip;
237  }
238  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized Storage for Image");
239 }
Class for XML file storage.
Definition: XmlStorage.h:57
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
Class for FITS file storage.
Definition: FitsStorage.h:52
virtual boost::archive::xml_iarchive & getIArchive(void)
Definition: XmlStorage.cc:114
An integer coordinate rectangle.
Definition: Box.h:53
void ImageT ImageT int float saturatedPixelValue int const width
Definition: saturated.cc:44
void ImageT ImageT int float saturatedPixelValue int const height
Definition: saturated.cc:44
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
Class for boost::serialization storage.
Definition: BoostStorage.h:58
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:415
template<typename ImagePixelT >
void lsst::afw::formatters::ImageFormatter< ImagePixelT >::update ( lsst::daf::base::Persistable persistable,
lsst::daf::persistence::Storage::Ptr  storage,
lsst::daf::base::PropertySet::Ptr  additionalData 
)
virtual

Update an existing Persistable instance with information from an additional Storage instance.

Parameters
[in,out]persistablePointer to the Persistable instance.
[in]storageShared pointer to the additional Storage instance.
[in]additionalDataAdditional data used to find the proper instance within the Storage.

Implements lsst::daf::persistence::Formatter.

Definition at line 242 of file ImageFormatter.cc.

245  {
246  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unexpected call to update for Image");
247 }
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
template<typename ImagePixelT >
void lsst::afw::formatters::ImageFormatter< ImagePixelT >::write ( lsst::daf::base::Persistable const *  persistable,
lsst::daf::persistence::Storage::Ptr  storage,
lsst::daf::base::PropertySet::Ptr  additionalData 
)
virtual

Write a Persistable instance to a Storage instance.

Parameters
[in]persistablePointer to the Persistable instance.
[in]storageShared pointer to the Storage instance.
[in]additionalDataAdditional data used to find the proper place to put the instance into the Storage.

Implements lsst::daf::persistence::Formatter.

Definition at line 133 of file ImageFormatter.cc.

136  {
137 
138  execTrace("ImageFormatter write start");
139  Image<ImagePixelT> const* ip = dynamic_cast<Image<ImagePixelT> const*>(persistable);
140  if (ip == 0) {
141  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Persisting non-Image");
142  }
143  if (typeid(*storage) == typeid(BoostStorage)) {
144  execTrace("ImageFormatter write BoostStorage");
145  BoostStorage* boost = dynamic_cast<BoostStorage*>(storage.get());
146  boost->getOArchive() & *ip;
147  execTrace("ImageFormatter write end");
148  return;
149  }
150  else if (typeid(*storage) == typeid(XmlStorage)) {
151  execTrace("ImageFormatter write XmlStorage");
152  XmlStorage* boost = dynamic_cast<XmlStorage*>(storage.get());
153  boost->getOArchive() & make_nvp("img", *ip);
154  execTrace("ImageFormatter write end");
155  return;
156  }
157  else if (typeid(*storage) == typeid(FitsStorage)) {
158  execTrace("ImageFormatter write FitsStorage");
159  FitsStorage* fits = dynamic_cast<FitsStorage*>(storage.get());
160  typedef Image<ImagePixelT> Image;
161 
162  ip->writeFits(fits->getPath());
163  // \todo Do something with these fields?
164  // int _X0;
165  // int _Y0;
166  execTrace("ImageFormatter write end");
167  return;
168  }
169  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized Storage for Image");
170 }
Class for XML file storage.
Definition: XmlStorage.h:57
virtual std::string const & getPath(void)
Definition: FitsStorage.cc:109
Class for FITS file storage.
Definition: FitsStorage.h:52
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
Write an image to a regular FITS file.
#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
Class for boost::serialization storage.
Definition: BoostStorage.h:58
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:415

Member Data Documentation

template<typename ImagePixelT >
lsst::daf::persistence::FormatterRegistration lsst::afw::formatters::ImageFormatter< ImagePixelT >::registration
staticprivate

Definition at line 87 of file ImageFormatter.h.


The documentation for this class was generated from the following files: