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");
63 if (
typeid(*storage) ==
typeid(lsst::daf::persistence::FitsStorage)) {
64 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
65 "FitsStorage for PropertyList read-only (writing is not supported)");
67 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized FormatterStorage for PropertyList");
71 std::unique_ptr<daf::base::PropertyList> readMetadataAsUniquePtr(std::string
const& fileName,
int hdu,
76 metadata->combine(inheritedMetadata);
82 lsst::daf::base::Persistable* PropertyListFormatter::read(
83 std::shared_ptr<lsst::daf::persistence::FormatterStorage> storage,
84 std::shared_ptr<lsst::daf::base::PropertySet>) {
85 LOGL_DEBUG(_log,
"PropertyListFormatter read start");
86 if (
typeid(*storage) ==
typeid(lsst::daf::persistence::FitsStorage)) {
87 LOGL_DEBUG(_log,
"PropertyListFormatter read FitsStorage");
89 auto fits =
dynamic_cast<lsst::daf::persistence::FitsStorage*
>(storage.get());
90 auto ip = readMetadataAsUniquePtr(fits->getPath(), fits->getHdu(),
false);
92 LOGL_DEBUG(_log,
"PropertyListFormatter read end");
95 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unrecognized FormatterStorage for PropertyList");
98 void PropertyListFormatter::update(lsst::daf::base::Persistable*,
99 std::shared_ptr<lsst::daf::persistence::FormatterStorage>,
100 std::shared_ptr<lsst::daf::base::PropertySet>) {
101 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Unexpected call to update for PropertyList");
104 template <
class Archive>
105 void PropertyListFormatter::delegateSerialize(Archive&,
int const,
106 lsst::daf::base::Persistable* persistable) {
107 LOGL_DEBUG(_log,
"PropertyListFormatter delegateSerialize start");
110 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Serializing non-PropertyList");
112 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"PropertyList serialization not yet implemented");
115 std::shared_ptr<lsst::daf::persistence::Formatter> PropertyListFormatter::createInstance(
116 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