32 #include "lsst/daf/base.h"
33 #include "lsst/daf/base/PropertyList.h"
34 #include "lsst/daf/persistence.h"
35 #include "lsst/log/Log.h"
40 LOG_LOGGER _log = LOG_GET(
"afw.PropertyListFormatter");
45 namespace formatters {
47 lsst::daf::persistence::FormatterRegistration PropertyListFormatter::registration(
50 PropertyListFormatter::PropertyListFormatter(std::shared_ptr<lsst::pex::policy::Policy>)
51 : lsst::daf::persistence::Formatter(typeid(this)) {}
53 void PropertyListFormatter::write(lsst::daf::base::Persistable
const* persistable,
54 std::shared_ptr<lsst::daf::persistence::Storage> storage,
55 std::shared_ptr<lsst::daf::base::PropertySet>) {
56 LOGL_DEBUG(_log,
"PropertyListFormatter write start");
59 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Persisting non-PropertyList");
61 if (
typeid(*storage) ==
typeid(lsst::daf::persistence::FitsStorage)) {
62 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
63 "FitsStorage for PropertyList read-only (writing is not supported)");
65 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized Storage for PropertyList");
69 std::unique_ptr<daf::base::PropertyList> readMetadataAsUniquePtr(std::string
const& fileName,
int hdu,
74 metadata->combine(inheritedMetadata);
80 lsst::daf::base::Persistable* PropertyListFormatter::read(
81 std::shared_ptr<lsst::daf::persistence::Storage> storage,
82 std::shared_ptr<lsst::daf::base::PropertySet>) {
83 LOGL_DEBUG(_log,
"PropertyListFormatter read start");
84 if (
typeid(*storage) ==
typeid(lsst::daf::persistence::FitsStorage)) {
85 LOGL_DEBUG(_log,
"PropertyListFormatter read FitsStorage");
87 auto fits =
dynamic_cast<lsst::daf::persistence::FitsStorage*
>(storage.get());
88 auto ip = readMetadataAsUniquePtr(fits->getPath(), fits->getHdu(),
false);
90 LOGL_DEBUG(_log,
"PropertyListFormatter read end");
93 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized Storage for PropertyList");
96 void PropertyListFormatter::update(lsst::daf::base::Persistable*,
97 std::shared_ptr<lsst::daf::persistence::Storage>,
98 std::shared_ptr<lsst::daf::base::PropertySet>) {
99 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unexpected call to update for PropertyList");
102 template <
class Archive>
103 void PropertyListFormatter::delegateSerialize(Archive&,
int const,
104 lsst::daf::base::Persistable* persistable) {
105 LOGL_DEBUG(_log,
"PropertyListFormatter delegateSerialize start");
108 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Serializing non-PropertyList");
110 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"PropertyList serialization not yet implemented");
113 std::shared_ptr<lsst::daf::persistence::Formatter> PropertyListFormatter::createInstance(
114 std::shared_ptr<lsst::pex::policy::Policy> policy) {
std::shared_ptr< daf::base::PropertyList > readMetadata(std::string const &fileName, int hdu=INT_MIN, bool strip=false)
Read FITS header.
lsst::daf::base::PropertyList PropertyList