LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Types | Public Member Functions | List of all members
lsst::afw::image::ExposureFitsReader::ArchiveReader Class Reference

Public Types

enum  Component {
  PSF = 0 , WCS , COADD_INPUTS , AP_CORR_MAP ,
  VALID_POLYGON , TRANSMISSION_CURVE , DETECTOR , PHOTOCALIB ,
  N_ARCHIVE_COMPONENTS
}
 

Public Member Functions

 ArchiveReader (daf::base::PropertyList &metadata)
 
template<typename T >
std::shared_ptr< T > readComponent (afw::fits::Fits *fitsFile, Component c)
 Read a known component, if available. More...
 
template<typename T >
std::shared_ptr< T > readComponent (afw::fits::Fits *fitsFile, std::string c)
 Read an arbitrary component, if available. More...
 
std::map< std::string, std::shared_ptr< table::io::Persistable > > readExtraComponents (afw::fits::Fits *fitsFile)
 Read the components that are stored using arbitrary-component support. More...
 

Detailed Description

Definition at line 320 of file ExposureFitsReader.cc.

Member Enumeration Documentation

◆ Component

Constructor & Destructor Documentation

◆ ArchiveReader()

lsst::afw::image::ExposureFitsReader::ArchiveReader::ArchiveReader ( daf::base::PropertyList metadata)
inlineexplicit

Definition at line 334 of file ExposureFitsReader.cc.

334  {
335  auto popInt = [&metadata](std::string const& name) {
336  // The default of zero will cause archive.get to return a
337  // null/empty pointer, just as if a null/empty pointer was
338  // originally written to the archive.
339  int r = 0;
340  if (metadata.exists(name)) {
341  r = metadata.get<int>(name);
342  // We remove metadata entries to maintaing our practice
343  // of stripped metadata entries that have been used to
344  // construct more structured components.
345  metadata.remove(name);
346  }
347  return r;
348  };
349  _hdu = popInt("AR_HDU");
350  if (_hdu == 0) {
351  _state = ArchiveState::MISSING;
352  } else {
353  --_hdu; // Switch from FITS 1-indexed convention to LSST 0-indexed convention.
354  _state = ArchiveState::PRESENT;
355  }
356  // Read in traditional components using old-style IDs, for backwards compatibility
357  _ids[PSF] = popInt("PSF_ID");
358  _ids[WCS] = popInt("SKYWCS_ID");
359  _ids[COADD_INPUTS] = popInt("COADD_INPUTS_ID");
360  _ids[AP_CORR_MAP] = popInt("AP_CORR_MAP_ID");
361  _ids[VALID_POLYGON] = popInt("VALID_POLYGON_ID");
362  _ids[TRANSMISSION_CURVE] = popInt("TRANSMISSION_CURVE_ID");
363  _ids[DETECTOR] = popInt("DETECTOR_ID");
364  _ids[PHOTOCALIB] = popInt("PHOTOCALIB_ID");
365 
366  // "Extra" components use a different keyword convention to avoid collisions with non-persistence IDs
367  std::vector<std::string> toStrip;
368  for (std::string const& headerKey : metadata) {
369  static std::string const PREFIX = "ARCHIVE_ID_";
370  if (headerKey.substr(0, PREFIX.size()) == PREFIX) {
371  std::string componentName = headerKey.substr(PREFIX.size());
372  int archiveId = metadata.get<int>(headerKey);
373  _genericIds.emplace(componentName, archiveId);
374  if (!_contains(_ids, archiveId)) {
375  _extraIds.emplace(componentName);
376  }
377  toStrip.push_back(headerKey);
378  toStrip.push_back(componentName + "_ID"); // strip corresponding old-style ID, if it exists
379  }
380  }
381  for (std::string const& key : toStrip) {
382  metadata.remove(key);
383  }
384  }
table::Key< std::string > name
Definition: Amplifier.cc:116
T emplace(T... args)
T push_back(T... args)
T size(T... args)
T substr(T... args)

Member Function Documentation

◆ readComponent() [1/2]

template<typename T >
std::shared_ptr<T> lsst::afw::image::ExposureFitsReader::ArchiveReader::readComponent ( afw::fits::Fits fitsFile,
Component  c 
)
inline

Read a known component, if available.

Parameters
fitsFileThe file from which to read the component. Must match the metadata used to construct this object.
cThe component to read. Must be convertible to T.
Returns
The desired component, or nullptr if the file could not be read.

Definition at line 396 of file ExposureFitsReader.cc.

396  {
397  if (!_ensureLoaded(fitsFile)) {
398  return nullptr;
399  }
400  return _archive.get<T>(_ids[c]);
401  }
std::shared_ptr< Persistable > get(int id) const
Load the Persistable with the given ID and return it.

◆ readComponent() [2/2]

template<typename T >
std::shared_ptr<T> lsst::afw::image::ExposureFitsReader::ArchiveReader::readComponent ( afw::fits::Fits fitsFile,
std::string  c 
)
inline

Read an arbitrary component, if available.

Parameters
fitsFileThe file from which to read the component. Must match the metadata used to construct this object.
cThe archive ID of the component to read.
Returns
The desired component, or nullptr if the file could not be read.
Exceptions
pex::exceptions::NotFoundErrorThrown if the component is registered in the file metadata but could not be found.
Note
When accessing from python, components with derived subclasses, such as TransmissionCurve, are not properly type converted and thus the specialized reader must be used instead of readComponent.

Definition at line 423 of file ExposureFitsReader.cc.

423  {
424  if (!_ensureLoaded(fitsFile)) {
425  return nullptr;
426  }
427 
428  if (_genericIds.count(c) > 0) {
429  int archiveId = _genericIds.at(c);
430  return _archive.get<T>(archiveId);
431  } else {
432  return nullptr;
433  }
434  }
T at(T... args)
T count(T... args)

◆ readExtraComponents()

std::map<std::string, std::shared_ptr<table::io::Persistable> > lsst::afw::image::ExposureFitsReader::ArchiveReader::readExtraComponents ( afw::fits::Fits fitsFile)
inline

Read the components that are stored using arbitrary-component support.

Parameters
fitsFileThe file from which to read the components. Must match the metadata used to construct this object.
Returns
a map from string IDs to components, or an empty map if the file could not be read.

Definition at line 445 of file ExposureFitsReader.cc.

446  {
448 
449  if (!_ensureLoaded(fitsFile)) {
450  return result;
451  }
452 
453  // Not safe to call getAll if a component cannot be unpersisted
454  // Instead, look for the archives registered in the metadata
455  for (std::string const& componentName : _extraIds) {
456  try {
457  result.emplace(componentName, readComponent<table::io::Persistable>(fitsFile, componentName));
458  } catch (pex::exceptions::NotFoundError const& err) {
459  LOGLS_WARN(_log,
460  "Could not read component " << componentName << "; skipping: " << err.what());
461  }
462  }
463  return result;
464  }
py::object result
Definition: _schema.cc:429
#define LOGLS_WARN(logger, message)
Log a warn-level message using an iostream-based interface.
Definition: Log.h:659

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