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

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 Types

typedef std::shared_ptr< FormatterPtr
 
typedef Ptr(* FactoryPtr) (lsst::pex::policy::Policy::Ptr)
 Pointer to a (static) factory function for a Formatter subclass. More...
 
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)
 

Public Member Functions

 ~ImageFormatter () override
 
 ImageFormatter (ImageFormatter const &)=default
 
 ImageFormatter (ImageFormatter &&)=default
 
ImageFormatteroperator= (ImageFormatter const &)=default
 
ImageFormatteroperator= (ImageFormatter &&)=default
 
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
 
lsst::daf::base::Persistableread (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
 
virtual void write (lsst::daf::base::Persistable const *persistable, FormatterStorage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)=0
 Write a Persistable instance to a FormatterStorage instance. More...
 
virtual lsst::daf::base::Persistableread (FormatterStorage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)=0
 Read a Persistable instance from a FormatterStorage instance. More...
 
virtual void update (lsst::daf::base::Persistable *persistable, FormatterStorage::Ptr storage, lsst::daf::base::PropertySet::Ptr additionalData)=0
 Update an existing Persistable instance with information from an additional FormatterStorage instance. More...
 
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 std::shared_ptr< lsst::daf::persistence::FormattercreateInstance (std::shared_ptr< lsst::pex::policy::Policy > policy)
 
template<class Archive >
static void delegateSerialize (Archive &ar, int const version, lsst::daf::base::Persistable *persistable)
 
static Formatter::Ptr lookupFormatter (std::string const &persistableType, lsst::pex::policy::Policy::Ptr policy)
 Lookup Formatter subclass by name of Persistable subclass. More...
 
static Formatter::Ptr lookupFormatter (std::type_info const &persistableType, lsst::pex::policy::Policy::Ptr policy)
 Lookup Formatter subclass by its type_info from typeid(). More...
 
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...
 
Census

Provide a list of current Citizens

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...
 
callbackIDs

Set callback Ids.

The old Id is returned

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...
 
callbacks

Set the New/Delete callback functions; in each case the previously installed callback is returned.

These callback functions return a value which is Added to the previously registered id.

The default callback functions are called default{New,Delete}Callback; you may want to set a break point in these callbacks from your favourite debugger

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...
 

Detailed Description

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

Class implementing persistence and retrieval for Images.

Definition at line 44 of file ImageFormatter.h.

Member Typedef Documentation

◆ FactoryPtr

typedef Ptr(* lsst::daf::persistence::Formatter::FactoryPtr) (lsst::pex::policy::Policy::Ptr)
inherited

Pointer to a (static) factory function for a Formatter subclass.

Definition at line 85 of file Formatter.h.

◆ memCallback

typedef memId(* lsst::daf::base::Citizen::memCallback) (const Citizen *ptr)
inherited

Definition at line 59 of file Citizen.h.

◆ memId

typedef unsigned long lsst::daf::base::Citizen::memId
inherited

Type of the block's ID.

Definition at line 56 of file Citizen.h.

◆ memNewCallback

typedef memId(* lsst::daf::base::Citizen::memNewCallback) (const memId cid)
inherited

A function used to register a callback.

Definition at line 58 of file Citizen.h.

◆ Ptr

Definition at line 81 of file Formatter.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
inherited
Enumerator
magicSentinel 

Definition at line 86 of file Citizen.h.

Constructor & Destructor Documentation

◆ ~ImageFormatter()

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

◆ ImageFormatter() [1/2]

template<typename ImagePixelT >
lsst::afw::formatters::ImageFormatter< ImagePixelT >::ImageFormatter ( ImageFormatter< ImagePixelT > const &  )
default

◆ ImageFormatter() [2/2]

template<typename ImagePixelT >
lsst::afw::formatters::ImageFormatter< ImagePixelT >::ImageFormatter ( ImageFormatter< ImagePixelT > &&  )
default

Member Function Documentation

◆ census() [1/3]

int lsst::daf::base::Citizen::census ( int  ,
memId  startingMemId = 0 
)
staticinherited

How many active Citizens are there?

Parameters
startingMemIdDon't print Citizens with lower IDs

Definition at line 238 of file Citizen.cc.

240  {
241  if (startingMemId == 0) { // easy
242  ReadGuard guard(citizenLock);
243  return _activeCitizens.size();
244  }
245 
246  int n = 0;
247  ReadGuard guard(citizenLock);
248  for (table::iterator cur = _activeCitizens.begin(); cur != _activeCitizens.end(); cur++) {
249  if (cur->first->_CitizenId >= startingMemId) {
250  n++;
251  }
252  }
253 
254  return n;
255 }
T end(T... args)
T size(T... args)
T begin(T... args)

◆ census() [2/3]

void lsst::daf::base::Citizen::census ( std::ostream stream,
memId  startingMemId = 0 
)
staticinherited

Print a list of all active Citizens to stream, sorted by ID.

Parameters
streamstream to print to
startingMemIdDon't print Citizens with lower IDs

Definition at line 259 of file Citizen.cc.

261  {
262  ReadGuard guard(citizenLock);
263 
265 
266  for (std::vector<Citizen const*>::const_iterator citizen = leaks->begin(), end = leaks->end();
267  citizen != end; ++citizen) {
268  if ((*citizen)->getId() >= startingMemId) {
269  stream << (*citizen)->repr() << "\n";
270  }
271  }
272 }
STL class.
STL class.
T begin(T... args)
int end
Definition: BoundedField.cc:99
static const std::vector< const Citizen * > * census()
Return a (newly allocated) std::vector of active Citizens sorted by ID.
Definition: Citizen.cc:287

◆ census() [3/3]

std::vector< dafBase::Citizen const * > const * lsst::daf::base::Citizen::census ( )
staticinherited

Return a (newly allocated) std::vector of active Citizens sorted by ID.

You are responsible for deleting it; or you can say std::unique_ptr<std::vector<Citizen const*> const> leaks(Citizen::census()); and not bother (that becomes std::unique_ptr in C++11)

Definition at line 287 of file Citizen.cc.

287  {
289  ReadGuard guard(citizenLock);
290  vec->reserve(_activeCitizens.size());
291 
292  for (table::iterator cur = _activeCitizens.begin(); cur != _activeCitizens.end(); cur++) {
293  vec->push_back(dynamic_cast<Citizen const*>(cur->first));
294  }
295 
296  std::sort(vec->begin(), vec->end(), cmpId);
297 
298  return vec;
299 }
T end(T... args)
T push_back(T... args)
T size(T... args)
STL class.
T begin(T... args)
T sort(T... args)
T reserve(T... args)

◆ createInstance()

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

Definition at line 262 of file ImageFormatter.cc.

263  {
264  return std::shared_ptr<lsst::daf::persistence::Formatter>(new ImageFormatter<ImagePixelT>(policy));
265 }

◆ delegateSerialize()

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 237 of file ImageFormatter.cc.

237  {
238  LOGL_DEBUG(_log, "ImageFormatter delegateSerialize start");
239  Image<ImagePixelT>* ip = dynamic_cast<Image<ImagePixelT>*>(persistable);
240  if (ip == 0) {
241  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Serializing non-Image");
242  }
243  int width, height;
244  if (Archive::is_saving::value) {
245  width = ip->getWidth();
246  height = ip->getHeight();
247  }
248  ar& make_nvp("width", width) & make_nvp("height", height);
249  if (Archive::is_loading::value) {
251  typename Image<ImagePixelT>::Array array = ni->getArray();
252  ar& make_nvp("array", boost::serialization::make_array(array.getData(), array.getNumElements()));
253  ip->swap(*ni);
254  } else {
255  ndarray::Array<ImagePixelT, 2, 2> array = ndarray::dynamic_dimension_cast<2>(ip->getArray());
256  if (array.empty()) array = ndarray::copy(ip->getArray());
257  ar& make_nvp("array", boost::serialization::make_array(array.getData(), array.getNumElements()));
258  }
259 }
int getHeight() const
Return the number of rows in the image.
Definition: ImageBase.h:321
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:513
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:47
STL class.
int getWidth() const
Return the number of columns in the image.
Definition: ImageBase.h:319
void swap(Image &rhs)
Definition: Image.cc:466
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:67
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104

◆ getId()

dafBase::Citizen::memId lsst::daf::base::Citizen::getId ( ) const
inherited

Return the Citizen's ID.

Definition at line 206 of file Citizen.cc.

206 { return _CitizenId; }

◆ getNextMemId()

dafBase::Citizen::memId lsst::daf::base::Citizen::getNextMemId ( )
staticinherited

Return the memId of the next object to be allocated.

Definition at line 209 of file Citizen.cc.

209 { return _nextMemId(); }

◆ hasBeenCorrupted()

bool lsst::daf::base::Citizen::hasBeenCorrupted ( )
staticinherited

Check all allocated blocks for corruption.

Definition at line 316 of file Citizen.cc.

316  {
317  ReadGuard guard(citizenLock);
318  for (table::iterator cur = _activeCitizens.begin(); cur != _activeCitizens.end(); cur++) {
319  if (cur->first->_hasBeenCorrupted()) {
320  return true;
321  }
322  }
323  for (table::iterator cur = _persistentCitizens.begin(); cur != _persistentCitizens.end(); cur++) {
324  if (cur->first->_hasBeenCorrupted()) {
325  return true;
326  }
327  }
328 
329  return false;
330 }
T end(T... args)
T begin(T... args)

◆ init()

int lsst::daf::base::Citizen::init ( )
staticinherited

Called once when the memory system is being initialised.

Definition at line 196 of file Citizen.cc.

196  {
197  volatile int dummy = 1;
198  return dummy;
199 }

◆ lookupFormatter() [1/2]

Formatter::Ptr lsst::daf::persistence::Formatter::lookupFormatter ( std::string const &  name,
lsst::pex::policy::Policy::Ptr  policy 
)
staticinherited

Lookup Formatter subclass by name of Persistable subclass.

Parameters
[in]nameName of Persistable subclass
[in]policyPolicy for configuring the Formatter
Returns
Shared pointer to Formatter instance

Returned pointer is not owned and should not be deleted.

Definition at line 84 of file Formatter.cc.

85  {
87 }
static FormatterRegistry & getInstance(void)
Get a reference to the singleton instance of the FormatterRegistry.
Formatter::Ptr lookupFormatter(std::type_info const &persistableType, lsst::pex::policy::Policy::Ptr policy)
Create a new instance of a Formatter subclass given the typeid() of its corresponding Persistable sub...

◆ lookupFormatter() [2/2]

Formatter::Ptr lsst::daf::persistence::Formatter::lookupFormatter ( std::type_info const &  type,
lsst::pex::policy::Policy::Ptr  policy 
)
staticinherited

Lookup Formatter subclass by its type_info from typeid().

Parameters
[in]typestd::type_info of Formatter subclass from typeid()
[in]policyPolicy for configuring the Formatter
Returns
Shared pointer to Formatter instance

Definition at line 94 of file Formatter.cc.

95  {
97 }
static FormatterRegistry & getInstance(void)
Get a reference to the singleton instance of the FormatterRegistry.
Formatter::Ptr lookupFormatter(std::type_info const &persistableType, lsst::pex::policy::Policy::Ptr policy)
Create a new instance of a Formatter subclass given the typeid() of its corresponding Persistable sub...

◆ markPersistent()

void lsst::daf::base::Citizen::markPersistent ( void  )
inherited

Mark a Citizen as persistent and not destroyed until process end.

Definition at line 225 of file Citizen.cc.

225  {
226  WriteGuard guard(citizenLock);
227  _persistentCitizens[this] = _activeCitizens[this];
228  _activeCitizens.erase(this);
229 }
T erase(T... args)

◆ operator=() [1/2]

template<typename ImagePixelT >
ImageFormatter& lsst::afw::formatters::ImageFormatter< ImagePixelT >::operator= ( ImageFormatter< ImagePixelT > const &  )
default

◆ operator=() [2/2]

template<typename ImagePixelT >
ImageFormatter& lsst::afw::formatters::ImageFormatter< ImagePixelT >::operator= ( ImageFormatter< ImagePixelT > &&  )
default

◆ read() [1/2]

template<typename ImagePixelT >
Persistable * lsst::afw::formatters::ImageFormatter< ImagePixelT >::read ( std::shared_ptr< lsst::daf::persistence::FormatterStorage storage,
std::shared_ptr< lsst::daf::base::PropertySet additionalData 
)
override

Definition at line 168 of file ImageFormatter.cc.

169  {
170  LOGL_DEBUG(_log, "ImageFormatter read start");
171  // TODO: Replace this with something better in DM-10776
173  if (boost) {
174  LOGL_DEBUG(_log, "ImageFormatter read BoostStorage");
176  boost->getIArchive() & *ip;
177  LOGL_DEBUG(_log, "ImageFormatter read end");
178  return ip;
179  }
180  auto xml = std::dynamic_pointer_cast<XmlStorage>(storage);
181  if (xml) {
182  LOGL_DEBUG(_log, "ImageFormatter read XmlStorage");
184  xml->getIArchive() & make_nvp("img", *ip);
185  LOGL_DEBUG(_log, "ImageFormatter read end");
186  return ip;
187  }
188  auto fits = std::dynamic_pointer_cast<FitsStorage>(storage);
189  if (fits) {
190  LOGL_DEBUG(_log, "ImageFormatter read FitsStorage");
192  if (additionalData->exists("llcX")) {
193  int llcX = additionalData->get<int>("llcX");
194  int llcY = additionalData->get<int>("llcY");
195  int width = additionalData->get<int>("width");
196  int height = additionalData->get<int>("height");
197  box = lsst::geom::Box2I(lsst::geom::Point2I(llcX, llcY), lsst::geom::Extent2I(width, height));
198  }
200  if (additionalData->exists("imageOrigin")) {
201  std::string originStr = additionalData->get<std::string>("imageOrigin");
202  if (originStr == "LOCAL") {
203  origin = afwImg::LOCAL;
204  } else if (originStr == "PARENT") {
205  origin = afwImg::PARENT;
206  } else {
208  (boost::format("Unknown ImageOrigin type %s specified in additional"
209  "data for retrieving Image from fits") %
210  originStr)
211  .str());
212  }
213  }
215 
216  Image<ImagePixelT>* ip =
217  new Image<ImagePixelT>(fits->getPath(), fits->getHdu(),
219  // @note We're throwing away the metadata
220  // @todo Do something with these fields?
221  // int _X0;
222  // int _Y0;
223  LOGL_DEBUG(_log, "ImageFormatter read end");
224  return ip;
225  }
226  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized FormatterStorage for Image");
227 }
Class for XML file storage.
Definition: XmlStorage.h:58
Definition: Span.h:36
Class for FITS file storage.
Definition: FitsStorage.h:52
#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.
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:129
T dynamic_pointer_cast(T... args)
T get(T... args)
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:47
Class for boost::serialization storage.
Definition: BoostStorage.h:59
An integer coordinate rectangle.
Definition: Box.h:54
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:67
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104

◆ read() [2/2]

virtual lsst::daf::base::Persistable* lsst::daf::persistence::Formatter::read ( FormatterStorage::Ptr  storage,
lsst::daf::base::PropertySet::Ptr  additionalData 
)
pure virtualinherited

Read a Persistable instance from a FormatterStorage instance.

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

◆ repr()

std::string lsst::daf::base::Citizen::repr ( ) const
inherited

Return a string representation of a Citizen.

Definition at line 219 of file Citizen.cc.

219  {
220  return boost::str(boost::format("%d: %08x %s") % _CitizenId % this %
221  lsst::utils::demangleType(_typeName));
222 }
std::string demangleType(std::string const _typeName)
Definition: Demangle.cc:113
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:129

◆ setCorruptionCallback()

dafBase::Citizen::memCallback lsst::daf::base::Citizen::setCorruptionCallback ( Citizen::memCallback  func)
staticinherited

Set the CorruptionCallback function.

Parameters
funcfunction be called when block is found to be corrupted

Definition at line 391 of file Citizen.cc.

393  {
394  Citizen::memCallback old = _corruptionCallback;
395  _corruptionCallback = func;
396 
397  return old;
398 }
memId(* memCallback)(const Citizen *ptr)
Definition: Citizen.h:59

◆ setDeleteCallback()

dafBase::Citizen::memCallback lsst::daf::base::Citizen::setDeleteCallback ( Citizen::memCallback  func)
staticinherited

Set the DeleteCallback function.

Parameters
funcfunction be called when desired block is deleted

Definition at line 381 of file Citizen.cc.

383  {
384  Citizen::memCallback old = _deleteCallback;
385  _deleteCallback = func;
386 
387  return old;
388 }
memId(* memCallback)(const Citizen *ptr)
Definition: Citizen.h:59

◆ setDeleteCallbackId()

dafBase::Citizen::memId lsst::daf::base::Citizen::setDeleteCallbackId ( Citizen::memId  id)
staticinherited

Call the current DeleteCallback when block is deleted.

Parameters
idDesired ID

Definition at line 347 of file Citizen.cc.

348  {
349  WriteGuard guard(citizenLock);
350  Citizen::memId oldId = _deleteId;
351  _deleteId = id;
352 
353  return oldId;
354 }
unsigned long memId
Type of the block&#39;s ID.
Definition: Citizen.h:56
int id
Definition: CR.cc:143

◆ setNewCallback()

dafBase::Citizen::memNewCallback lsst::daf::base::Citizen::setNewCallback ( Citizen::memNewCallback  func)
staticinherited

Set the NewCallback function.

Parameters
funcThe new function to be called when a designated block is allocated

Definition at line 371 of file Citizen.cc.

373  {
374  Citizen::memNewCallback old = _newCallback;
375  _newCallback = func;
376 
377  return old;
378 }
memId(* memNewCallback)(const memId cid)
A function used to register a callback.
Definition: Citizen.h:58

◆ setNewCallbackId()

dafBase::Citizen::memId lsst::daf::base::Citizen::setNewCallbackId ( Citizen::memId  id)
staticinherited

Call the NewCallback when block is allocated.

Parameters
idDesired ID

Definition at line 337 of file Citizen.cc.

338  {
339  WriteGuard guard(citizenLock);
340  Citizen::memId oldId = _newId;
341  _newId = id;
342 
343  return oldId;
344 }
unsigned long memId
Type of the block&#39;s ID.
Definition: Citizen.h:56
int id
Definition: CR.cc:143

◆ update() [1/2]

template<typename ImagePixelT >
void lsst::afw::formatters::ImageFormatter< ImagePixelT >::update ( lsst::daf::base::Persistable persistable,
std::shared_ptr< lsst::daf::persistence::FormatterStorage storage,
std::shared_ptr< lsst::daf::base::PropertySet additionalData 
)
override

Definition at line 230 of file ImageFormatter.cc.

231  {
232  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unexpected call to update for Image");
233 }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:47
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104

◆ update() [2/2]

virtual void lsst::daf::persistence::Formatter::update ( lsst::daf::base::Persistable persistable,
FormatterStorage::Ptr  storage,
lsst::daf::base::PropertySet::Ptr  additionalData 
)
pure virtualinherited

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

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

◆ write() [1/2]

template<typename ImagePixelT >
void lsst::afw::formatters::ImageFormatter< ImagePixelT >::write ( lsst::daf::base::Persistable const *  persistable,
std::shared_ptr< lsst::daf::persistence::FormatterStorage storage,
std::shared_ptr< lsst::daf::base::PropertySet additionalData 
)
override

Definition at line 120 of file ImageFormatter.cc.

122  {
123  LOGL_DEBUG(_log, "ImageFormatter write start");
124  Image<ImagePixelT> const* ip = dynamic_cast<Image<ImagePixelT> const*>(persistable);
125  if (ip == 0) {
126  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Persisting non-Image");
127  }
128  // TODO: Replace this with something better in DM-10776
130  if (boost) {
131  LOGL_DEBUG(_log, "ImageFormatter write BoostStorage");
132  boost->getOArchive() & *ip;
133  LOGL_DEBUG(_log, "ImageFormatter write end");
134  return;
135  }
136  auto xml = std::dynamic_pointer_cast<XmlStorage>(storage);
137  if (xml) {
138  LOGL_DEBUG(_log, "ImageFormatter write XmlStorage");
139  xml->getOArchive() & make_nvp("img", *ip);
140  LOGL_DEBUG(_log, "ImageFormatter write end");
141  return;
142  }
143  auto fits = std::dynamic_pointer_cast<FitsStorage>(storage);
144  if (fits) {
145  LOGL_DEBUG(_log, "ImageFormatter write FitsStorage");
146 
147  fits::ImageWriteOptions options;
148  if (additionalData) {
149  try {
150  options = fits::ImageWriteOptions(*additionalData->getAsPropertySetPtr("image"));
151  } catch (std::exception const& exc) {
152  LOGLS_WARN(_log, "Unable to construct image write options ("
153  << exc.what() << "); writing with default options");
154  }
155  }
156 
157  ip->writeFits(fits->getPath(), options);
158  // @todo Do something with these fields?
159  // int _X0;
160  // int _Y0;
161  LOGL_DEBUG(_log, "ImageFormatter write end");
162  return;
163  }
164  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized FormatterStorage for Image");
165 }
#define LOGLS_WARN(logger, message)
Log a warn-level message using an iostream-based interface.
Definition: Log.h:657
Class for XML file storage.
Definition: XmlStorage.h:58
Definition: Span.h:36
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 an image to a regular FITS file.
tuple options
Definition: lsstimport.py:47
Class for FITS file storage.
Definition: FitsStorage.h:52
#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
T what(T... args)
T dynamic_pointer_cast(T... args)
STL class.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:47
Class for boost::serialization storage.
Definition: BoostStorage.h:59
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:67
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104

◆ write() [2/2]

virtual void lsst::daf::persistence::Formatter::write ( lsst::daf::base::Persistable const *  persistable,
FormatterStorage::Ptr  storage,
lsst::daf::base::PropertySet::Ptr  additionalData 
)
pure virtualinherited

Write a Persistable instance to a FormatterStorage instance.

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

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