LSST Applications g0265f82a02+d6b5cd48b5,g02d81e74bb+80768bd682,g04242d3e92+8eaa23c173,g06b2ea86fd+734f9505a2,g2079a07aa2+14824f138e,g212a7c68fe+5f4fc2ea00,g2305ad1205+293ab1327e,g2bbee38e9b+d6b5cd48b5,g337abbeb29+d6b5cd48b5,g3ddfee87b4+8eaa23c173,g487adcacf7+abec5a19c5,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+97ef3b4495,g5a732f18d5+66d966b544,g5d7b63bc56+636c3c3fd8,g64a986408d+80768bd682,g858d7b2824+80768bd682,g8a8a8dda67+a6fc98d2e7,g99cad8db69+6282a5f541,g9ddcbc5298+d4bad12328,ga1e77700b3+246acaaf9c,ga8c6da7877+9e3c062e8e,gb0e22166c9+3863383f4c,gb6a65358fc+d6b5cd48b5,gba4ed39666+9664299f35,gbb8dafda3b+60f904e7bc,gc120e1dc64+1bf26d0180,gc28159a63d+d6b5cd48b5,gcf0d15dbbd+8eaa23c173,gd2a12a3803+f8351bc914,gdaeeff99f8+a38ce5ea23,ge79ae78c31+d6b5cd48b5,gee10cc3b42+a6fc98d2e7,gf1cff7945b+80768bd682,v24.1.5.rc1
LSST Data Management Base Package
Loading...
Searching...
No Matches
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.
 
template<typename T >
std::shared_ptr< T > readComponent (afw::fits::Fits *fitsFile, std::string c)
 Read an arbitrary component, if available.
 
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.
 

Detailed Description

Definition at line 217 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 231 of file ExposureFitsReader.cc.

231 {
232 auto popInt = [&metadata](std::string const& name) {
233 // The default of zero will cause archive.get to return a
234 // null/empty pointer, just as if a null/empty pointer was
235 // originally written to the archive.
236 int r = 0;
237 if (metadata.exists(name)) {
238 r = metadata.get<int>(name);
239 // We remove metadata entries to maintaing our practice
240 // of stripped metadata entries that have been used to
241 // construct more structured components.
242 metadata.remove(name);
243 }
244 return r;
245 };
246 _hdu = popInt("AR_HDU");
247 if (_hdu == 0) {
248 _state = ArchiveState::MISSING;
249 } else {
250 --_hdu; // Switch from FITS 1-indexed convention to LSST 0-indexed convention.
251 _state = ArchiveState::PRESENT;
252 }
253 // Read in traditional components using old-style IDs, for backwards compatibility
254 _ids[PSF] = popInt("PSF_ID");
255 _ids[WCS] = popInt("SKYWCS_ID");
256 _ids[COADD_INPUTS] = popInt("COADD_INPUTS_ID");
257 _ids[AP_CORR_MAP] = popInt("AP_CORR_MAP_ID");
258 _ids[VALID_POLYGON] = popInt("VALID_POLYGON_ID");
259 _ids[TRANSMISSION_CURVE] = popInt("TRANSMISSION_CURVE_ID");
260 _ids[DETECTOR] = popInt("DETECTOR_ID");
261 _ids[PHOTOCALIB] = popInt("PHOTOCALIB_ID");
262
263 // "Extra" components use a different keyword convention to avoid collisions with non-persistence IDs
265 for (std::string const& headerKey : metadata) {
266 static std::string const PREFIX = "ARCHIVE_ID_";
267 if (headerKey.substr(0, PREFIX.size()) == PREFIX) {
268 std::string componentName = headerKey.substr(PREFIX.size());
269 int archiveId = metadata.get<int>(headerKey);
270 _genericIds.emplace(componentName, archiveId);
271 if (!_contains(_ids, archiveId)) {
272 _extraIds.emplace(componentName);
273 }
274 toStrip.push_back(headerKey);
275 toStrip.push_back(componentName + "_ID"); // strip corresponding old-style ID, if it exists
276 }
277 }
278 for (std::string const& key : toStrip) {
279 metadata.remove(key);
280 }
281 }
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 293 of file ExposureFitsReader.cc.

293 {
294 if (!_ensureLoaded(fitsFile)) {
295 return nullptr;
296 }
297 return _archive.get<T>(_ids[c]);
298 }
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 320 of file ExposureFitsReader.cc.

320 {
321 if (!_ensureLoaded(fitsFile)) {
322 return nullptr;
323 }
324
325 if (_genericIds.count(c) > 0) {
326 int archiveId = _genericIds.at(c);
327 return _archive.get<T>(archiveId);
328 } else {
329 return nullptr;
330 }
331 }
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 342 of file ExposureFitsReader.cc.

343 {
345
346 if (!_ensureLoaded(fitsFile)) {
347 return result;
348 }
349
350 // Not safe to call getAll if a component cannot be unpersisted
351 // Instead, look for the archives registered in the metadata
352 for (std::string const& componentName : _extraIds) {
353 try {
354 result.emplace(componentName, readComponent<table::io::Persistable>(fitsFile, componentName));
355 } catch (pex::exceptions::NotFoundError const& err) {
356 LOGLS_WARN(_log,
357 "Could not read component " << componentName << "; skipping: " << err.what());
358 }
359 }
360 return result;
361 }
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: