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");
43 using lsst::daf::persistence::FormatterStorage;
47 namespace formatters {
49 lsst::daf::persistence::FormatterRegistration PropertyListFormatter::registration(
52 PropertyListFormatter::PropertyListFormatter(std::shared_ptr<lsst::pex::policy::Policy>)
53 : lsst::daf::persistence::Formatter(typeid(this)) {}
55 void PropertyListFormatter::write(lsst::daf::base::Persistable
const* persistable,
56 std::shared_ptr<lsst::daf::persistence::FormatterStorage> storage,
57 std::shared_ptr<lsst::daf::base::PropertySet>) {
58 LOGL_DEBUG(_log,
"PropertyListFormatter write start");
61 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Persisting non-PropertyList");
64 auto & actualStorage = *storage;
65 if (
typeid(actualStorage) ==
typeid(lsst::daf::persistence::FitsStorage)) {
66 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
67 "FitsStorage for PropertyList read-only (writing is not supported)");
69 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized FormatterStorage for PropertyList");
73 std::unique_ptr<daf::base::PropertyList> readMetadataAsUniquePtr(std::string
const& fileName,
int hdu,
78 metadata->combine(inheritedMetadata);
84 lsst::daf::base::Persistable* PropertyListFormatter::read(
85 std::shared_ptr<lsst::daf::persistence::FormatterStorage> storage,
86 std::shared_ptr<lsst::daf::base::PropertySet>) {
87 LOGL_DEBUG(_log,
"PropertyListFormatter read start");
89 auto fits = std::dynamic_pointer_cast<lsst::daf::persistence::FitsStorage>(storage);
91 LOGL_DEBUG(_log,
"PropertyListFormatter read FitsStorage");
93 auto ip = readMetadataAsUniquePtr(fits->getPath(), fits->getHdu(),
false);
95 LOGL_DEBUG(_log,
"PropertyListFormatter read end");
98 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized FormatterStorage for PropertyList");
101 void PropertyListFormatter::update(lsst::daf::base::Persistable*,
102 std::shared_ptr<lsst::daf::persistence::FormatterStorage>,
103 std::shared_ptr<lsst::daf::base::PropertySet>) {
104 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unexpected call to update for PropertyList");
107 template <
class Archive>
108 void PropertyListFormatter::delegateSerialize(Archive&,
int const,
109 lsst::daf::base::Persistable* persistable) {
110 LOGL_DEBUG(_log,
"PropertyListFormatter delegateSerialize start");
113 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Serializing non-PropertyList");
115 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"PropertyList serialization not yet implemented");
118 std::shared_ptr<lsst::daf::persistence::Formatter> PropertyListFormatter::createInstance(
119 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