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 | Private Attributes | Static Private Attributes | List of all members
lsst::afw::formatters::ExposureFormatter< ImagePixelT, MaskPixelT, VariancePixelT > Class Template Reference

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

#include <ExposureFormatter.h>

Inheritance diagram for lsst::afw::formatters::ExposureFormatter< ImagePixelT, MaskPixelT, VariancePixelT >:
lsst::daf::persistence::Formatter lsst::daf::base::Citizen

Public Member Functions

virtual ~ExposureFormatter (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, unsigned 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

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

Private Attributes

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, typename MaskPixelT, typename VariancePixelT>
class lsst::afw::formatters::ExposureFormatter< ImagePixelT, MaskPixelT, VariancePixelT >

Class implementing persistence and retrieval for Exposures.

Definition at line 54 of file ExposureFormatter.h.

Constructor & Destructor Documentation

template<typename ImagePixelT , typename MaskPixelT , typename VariancePixelT >
lsst::afw::formatters::ExposureFormatter< ImagePixelT, MaskPixelT, VariancePixelT >::~ExposureFormatter ( void  )
virtual

Definition at line 124 of file ExposureFormatter.cc.

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

Definition at line 118 of file ExposureFormatter.cc.

119  :
120  lsst::daf::persistence::Formatter(typeid(this)), _policy(policy) {
121 }
lsst::pex::policy::Policy::Ptr _policy
Abstract base class for all formatters.
Definition: Formatter.h:79

Member Function Documentation

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

Definition at line 474 of file ExposureFormatter.cc.

475  {
476  typedef typename lsst::daf::persistence::Formatter::Ptr FormPtr;
478 }
boost::shared_ptr< Formatter > Ptr
Definition: Formatter.h:81
Class implementing persistence and retrieval for Exposures.
template<typename ImagePixelT , typename MaskPixelT , typename VariancePixelT >
template<class Archive >
void lsst::afw::formatters::ExposureFormatter< ImagePixelT, MaskPixelT, VariancePixelT >::delegateSerialize ( Archive &  ar,
unsigned int const  version,
lsst::daf::base::Persistable persistable 
)
static

Definition at line 456 of file ExposureFormatter.cc.

459 {
460  execTrace("ExposureFormatter delegateSerialize start");
463  if (ip == 0) {
464  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Serializing non-Exposure");
465  }
466  PTR(afwImg::Wcs) wcs = ip->getWcs();
467  ar & *ip->getMetadata() & ip->_maskedImage & wcs;
468  execTrace("ExposureFormatter delegateSerialize end");
469 }
A class to contain the data, WCS, and other information needed to describe an image of the sky...
Definition: Exposure.h:48
#define PTR(...)
Definition: base.h:41
tbl::Key< int > wcs
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:107
static void delegateSerialize(Archive &ar, unsigned int const version, lsst::daf::base::Persistable *persistable)
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
ExposureFormatter(lsst::pex::policy::Policy::Ptr policy)
template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
dafBase::Persistable * lsst::afw::formatters::ExposureFormatter< ImagePixelT, MaskPixelT, VariancePixelT >::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.
Todo:
Should really have FITS be a separate Storage.
Todo:
Need to implement overwriting of FITS metadata PropertySet

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

Definition at line 311 of file ExposureFormatter.cc.

313  {
314  execTrace("ExposureFormatter read start");
315  if (typeid(*storage) == typeid(dafPersist::BoostStorage)) {
316  execTrace("ExposureFormatter read BoostStorage");
317  dafPersist::BoostStorage* boost = dynamic_cast<dafPersist::BoostStorage*>(storage.get());
320  boost->getIArchive() & *ip;
321  execTrace("ExposureFormatter read end");
322  return ip;
323  } else if (typeid(*storage) == typeid(dafPersist::FitsStorage)) {
324  execTrace("ExposureFormatter read FitsStorage");
325  dafPersist::FitsStorage* fits = dynamic_cast<dafPersist::FitsStorage*>(storage.get());
326  afwGeom::Box2I box;
327  if (additionalData->exists("llcX")) {
328  int llcX = additionalData->get<int>("llcX");
329  int llcY = additionalData->get<int>("llcY");
330  int width = additionalData->get<int>("width");
331  int height = additionalData->get<int>("height");
332  box = afwGeom::Box2I(afwGeom::Point2I(llcX, llcY), afwGeom::Extent2I(width, height));
333  }
335  if(additionalData->exists("imageOrigin")){
336  std::string originStr = additionalData->get<std::string>("imageOrigin");
337  if(originStr == "LOCAL") {
338  origin = afwImg::LOCAL;
339  } else if (originStr == "PARENT") {
340  origin = afwImg::PARENT;
341  } else {
342  throw LSST_EXCEPT(
343  lsst::pex::exceptions::RuntimeError,
344  (boost::format("Unknown ImageOrigin type %s specified in additional"
345  "data for retrieving Exposure from fits")%originStr
346 
347  ).str()
348  );
349  }
350  }
353  fits->getPath(), box, origin);
354  execTrace("ExposureFormatter read end");
355  return ip;
356  } else if (typeid(*storage) == typeid(dafPersist::DbStorage)) {
357  execTrace("ExposureFormatter read DbStorage");
358  dafPersist::DbStorage* db = dynamic_cast<dafPersist::DbStorage*>(storage.get());
359 
360  // Select a table to retrieve from based on the itemName.
361  std::string itemName = additionalData->get<std::string>("itemName");
362  std::string tableName = itemName;
363  if (_policy->exists(itemName)) {
364  lsst::pex::policy::Policy::Ptr itemPolicy =
365  _policy->getPolicy(itemName);
366  if (itemPolicy->exists("TableName")) {
367  tableName = itemPolicy->getString("TableName");
368  }
369  }
370  if (tableName != "Raw_Amp_Exposure" &&
371  tableName != "Science_Amp_Exposure") {
372  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
373  "Unknown table name for retrieving Exposure from DbStorage: " +
374  tableName + " for item " + itemName);
375  }
376  db->setTableForQuery(tableName);
377 
378  // Set the identifier column tests.
379  db->condParam<int64_t>("id", additionalData->getAsInt64("ampExposureId"));
380  if (tableName == "Raw_Amp_Exposure") {
381  db->setQueryWhere("rawAmpExposureId = :id");
382  }
383  else { // Science_Amp_Exposure
384  db->setQueryWhere("scienceAmpExposureId = :id");
385  }
386 
387  db->outColumn("url");
388 
389  if (tableName == "Science_Amp_Exposure") {
390  // Set the Wcs information columns.
391  db->outColumn("ctype1");
392  db->outColumn("ctype2");
393  db->outColumn("crpix1");
394  db->outColumn("crpix2");
395  db->outColumn("crval1");
396  db->outColumn("crval2");
397  db->outColumn("cd11");
398  db->outColumn("cd21");
399  db->outColumn("cd12");
400  db->outColumn("cd22");
401 
402  // Set calibration data columns.
403  db->outColumn("photoFlam");
404  db->outColumn("photoZP");
405  }
406 
407  // Phew! Run the query.
408  db->query();
409  if (!db->next()) {
410  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unable to retrieve row");
411  }
412  // ...
413  if (db->next()) {
414  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Non-unique Exposure retrieved");
415  }
416  db->finishQuery();
417 
419  // - KTL - 2007-11-29
420 
421  // Restore image from FITS...
425 
426  // Look up the filter name given the ID.
427  int filterId = db->getColumnByPos<int>(1);
428  std::string filterName = lookupFilterName(db, filterId);
429  dp->set("FILTER", filterName);
430 
431  // Set the image headers.
432  // Set the Wcs headers in ip->_wcs.
433 
435  // with values from database. - KTL - 2007-12-18
436 
437  execTrace("ExposureFormatter read end");
438  return ip;
439  }
440  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized Storage for Exposure");
441 }
virtual void outColumn(std::string const &columnName, bool isExpr=false)
Definition: DbStorage.cc:194
A class to contain the data, WCS, and other information needed to describe an image of the sky...
Definition: Exposure.h:48
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
virtual void setQueryWhere(std::string const &whereClause)
Definition: DbStorage.cc:242
boost::shared_ptr< Policy > Ptr
Definition: Policy.h:172
T const & getColumnByPos(int pos)
Definition: DbStorage.cc:263
lsst::pex::policy::Policy::Ptr _policy
Class for FITS file storage.
Definition: FitsStorage.h:52
void condParam(std::string const &paramName, T const &value)
Definition: DbStorage.cc:218
An integer coordinate rectangle.
Definition: Box.h:53
Class for database storage.
Definition: DbStorage.h:63
void ImageT ImageT int float saturatedPixelValue int const width
Definition: saturated.cc:44
lsst::daf::base::PropertySet::Ptr getMetadata() const
Return flexible metadata.
Definition: Exposure.h:162
void ImageT ImageT int float saturatedPixelValue int const height
Definition: saturated.cc:44
virtual void setTableForQuery(std::string const &tableName, bool isExpr=false)
Definition: DbStorage.cc:175
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
Class for boost::serialization storage.
Definition: BoostStorage.h:58
virtual void finishQuery(void)
Definition: DbStorage.cc:278
template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
void lsst::afw::formatters::ExposureFormatter< ImagePixelT, MaskPixelT, VariancePixelT >::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.
Todo:
Implement update from FitsStorage, keeping DB-provided headers.

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

Definition at line 444 of file ExposureFormatter.cc.

449 {
451  // - KTL - 2007-11-29
452  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unexpected call to update for Exposure");
453 }
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
void lsst::afw::formatters::ExposureFormatter< ImagePixelT, MaskPixelT, VariancePixelT >::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.
Todo:
Check that rawCCDExposureId == scienceCCDExposureId – KTL – 2008-01-25

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

Definition at line 189 of file ExposureFormatter.cc.

192  {
193  execTrace("ExposureFormatter write start");
195  dynamic_cast<afwImg::Exposure<ImagePixelT, MaskPixelT, VariancePixelT> const*>(persistable);
196  if (ip == 0) {
197  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Persisting non-Exposure");
198  }
199  if (typeid(*storage) == typeid(dafPersist::BoostStorage)) {
200  execTrace("ExposureFormatter write BoostStorage");
201  dafPersist::BoostStorage* boost = dynamic_cast<dafPersist::BoostStorage*>(storage.get());
202  boost->getOArchive() & *ip;
203  execTrace("ExposureFormatter write end");
204  return;
205  }
206  else if (typeid(*storage) == typeid(dafPersist::FitsStorage)) {
207  execTrace("ExposureFormatter write FitsStorage");
208  dafPersist::FitsStorage* fits = dynamic_cast<dafPersist::FitsStorage*>(storage.get());
209 
210  ip->writeFits(fits->getPath());
211  execTrace("ExposureFormatter write end");
212  return;
213  } else if (typeid(*storage) == typeid(dafPersist::DbStorage)) {
214  execTrace("ExposureFormatter write DbStorage");
215  dafPersist::DbStorage* db = dynamic_cast<dafPersist::DbStorage*>(storage.get());
216 
217  // Get the Wcs headers.
219  ip->getWcs()->getFitsMetadata();
220 
221  // Get the image headers.
223  if (!dp) {
224  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
225  "Unable to retrieve metadata from MaskedImage's Image");
226  }
227 
228  // Select a table to insert into based on the itemName.
229  std::string itemName = additionalData->get<std::string>("itemName");
230  std::string tableName = itemName;
231  if (_policy->exists(itemName)) {
232  lsst::pex::policy::Policy::Ptr itemPolicy = _policy->getPolicy(itemName);
233  if (itemPolicy->exists("TableName")) {
234  tableName = itemPolicy->getString("TableName");
235  }
236  }
237  if (tableName != "Raw_Amp_Exposure" &&
238  tableName != "Science_Amp_Exposure") {
239  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
240  "Unknown table name for persisting Exposure to DbStorage: " +
241  tableName + "for item " + itemName);
242  }
243  db->setTableForInsert(tableName);
244 
245  // Set the identifier columns.
246 
247  int ampId = extractAmpId(additionalData);
248  // int ccdId = extractCcdId(additionalData);
249  int64_t fpaExposureId = extractFpaExposureId(dp);
250  int64_t ccdExposureId = extractCcdExposureId(dp);
251  int64_t ampExposureId = extractAmpExposureId(dp);
252 
253  if (tableName == "Raw_Amp_Exposure") {
254  db->setColumn<long long>("rawAmpExposureId", ampExposureId);
255  db->setColumn<long long>("rawCCDExposureId", ccdExposureId);
256  db->setColumn<long long>("rawFPAExposureId", fpaExposureId);
257  }
258  else { // Science_Amp_Exposure
259  db->setColumn<long long>("scienceAmpExposureId", ampExposureId);
260  db->setColumn<long long>("scienceCCDExposureId", ccdExposureId);
261  db->setColumn<long long>("scienceFPAExposureId", fpaExposureId);
262  db->setColumn<long long>("rawAmpExposureId", ampExposureId);
265  }
266 
267  db->setColumn<int>("ampId", ampId);
268 
269  // Set the URL column with the location of the FITS file.
270  setColumn<std::string>(db, "url",
271  additionalData, "StorageLocation.FitsStorage");
272 
273 
274  // Set the Wcs information columns.
275  setColumn<std::string>(db, "ctype1", wcsProps, "CTYPE1");
276  setColumn<std::string>(db, "ctype2", wcsProps, "CTYPE2");
277  setColumn<float, double>(db, "crpix1", wcsProps, "CRPIX1");
278  setColumn<float, double>(db, "crpix2", wcsProps, "CRPIX2");
279  setColumn<double>(db, "crval1", wcsProps, "CRVAL1");
280  setColumn<double>(db, "crval2", wcsProps, "CRVAL2");
281  if (tableName == "Raw_Amp_Exposure") {
282  setColumn<double>(db, "cd11", wcsProps, "CD1_1");
283  setColumn<double>(db, "cd21", wcsProps, "CD2_1");
284  setColumn<double>(db, "cd12", wcsProps, "CD1_2");
285  setColumn<double>(db, "cd22", wcsProps, "CD2_2");
286  }
287  else {
288  setColumn<double>(db, "cd1_1", wcsProps, "CD1_1");
289  setColumn<double>(db, "cd2_1", wcsProps, "CD2_1");
290  setColumn<double>(db, "cd1_2", wcsProps, "CD1_2");
291  setColumn<double>(db, "cd2_2", wcsProps, "CD2_2");
292  }
293 
294 
295  if (tableName == "Science_Amp_Exposure") {
296  // Set calibration data columns.
297  setColumn<float, double>(db, "photoFlam", dp, "PHOTFLAM");
298  setColumn<float, double>(db, "photoZP", dp, "PHOTZP");
299  }
300 
301  // Phew! Insert the row now.
302  db->insertRow();
303 
304  execTrace("ExposureFormatter write end");
305  return;
306  }
307  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Unrecognized Storage for Exposure");
308 }
int64_t extractAmpExposureId(boost::shared_ptr< lsst::daf::base::PropertySet const > const &properties)
int extractAmpId(boost::shared_ptr< lsst::daf::base::PropertySet const > const &properties)
void setColumn(std::string const &columnName, T const &value)
Definition: DbStorage.cc:152
A class to contain the data, WCS, and other information needed to describe an image of the sky...
Definition: Exposure.h:48
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
lsst::pex::policy::Policy::Ptr _policy
void writeFits(std::string const &fileName) const
Write an Exposure to a regular multi-extension FITS file.
Definition: Exposure.cc:237
Class for FITS file storage.
Definition: FitsStorage.h:52
Class for database storage.
Definition: DbStorage.h:63
int64_t extractFpaExposureId(boost::shared_ptr< lsst::daf::base::PropertySet const > const &properties)
int64_t extractCcdExposureId(boost::shared_ptr< lsst::daf::base::PropertySet const > const &properties)
lsst::daf::base::PropertySet::Ptr getMetadata() const
Return flexible metadata.
Definition: Exposure.h:162
boost::shared_ptr< Wcs const > getWcs() const
Definition: Exposure.h:154
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
virtual boost::archive::text_oarchive & getOArchive(void)
Class for boost::serialization storage.
Definition: BoostStorage.h:58
virtual void setTableForInsert(std::string const &tableName)
Definition: DbStorage.cc:143

Member Data Documentation

template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
lsst::pex::policy::Policy::Ptr lsst::afw::formatters::ExposureFormatter< ImagePixelT, MaskPixelT, VariancePixelT >::_policy
private

Definition at line 85 of file ExposureFormatter.h.

template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
lsst::daf::persistence::FormatterRegistration lsst::afw::formatters::ExposureFormatter< ImagePixelT, MaskPixelT, VariancePixelT >::registration
staticprivate

Definition at line 87 of file ExposureFormatter.h.


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