|
| 1 | +// -*- LSST-C++ -*- |
| 2 | +/* |
| 3 | + * LSST Data Management System |
| 4 | + * Copyright 2008-2014 LSST Corporation. |
| 5 | + * |
| 6 | + * This product includes software developed by the |
| 7 | + * LSST Project (http://www.lsst.org/). |
| 8 | + * |
| 9 | + * This program is free software: you can redistribute it and/or modify |
| 10 | + * it under the terms of the GNU General Public License as published by |
| 11 | + * the Free Software Foundation, either version 3 of the License, or |
| 12 | + * (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the LSST License Statement and |
| 20 | + * the GNU General Public License along with this program. If not, |
| 21 | + * see <http://www.lsstcorp.org/LegalNotices/>. |
| 22 | + */ |
| 23 | + |
| 24 | +#include <memory> |
| 25 | + |
| 26 | +#include "lsst/afw/image/ImageSummary.h" |
| 27 | +#include "lsst/afw/table/io/InputArchive.h" |
| 28 | +#include "lsst/afw/table/io/OutputArchive.h" |
| 29 | +#include "lsst/afw/table/io/CatalogVector.h" |
| 30 | +#include "lsst/afw/table/io/Persistable.cc" |
| 31 | + |
| 32 | +namespace lsst { |
| 33 | +namespace afw { |
| 34 | + |
| 35 | +template std::shared_ptr<image::ImageSummary> table::io::PersistableFacade<image::ImageSummary>::dynamicCast( |
| 36 | + std::shared_ptr<table::io::Persistable> const&); |
| 37 | + |
| 38 | +namespace image { |
| 39 | + |
| 40 | +ImageSummary::ImageSummary(table::Schema const& schema) { |
| 41 | + auto tbl = table::BaseTable::make(schema); |
| 42 | + _internal = tbl->makeRecord(); |
| 43 | +} |
| 44 | + |
| 45 | +ImageSummary::ImageSummary(ImageSummary const& other) { |
| 46 | + _internal = other._internal->getTable()->copyRecord(*other._internal); |
| 47 | +} |
| 48 | + |
| 49 | +ImageSummary& ImageSummary::operator=(ImageSummary const& other) { |
| 50 | + _internal->assign(*other._internal); |
| 51 | + return *this; |
| 52 | +} |
| 53 | + |
| 54 | + |
| 55 | +namespace { |
| 56 | + |
| 57 | +class ImageSummaryFactory : public table::io::PersistableFactory { |
| 58 | +public: |
| 59 | + std::shared_ptr<table::io::Persistable> read(InputArchive const& archive, |
| 60 | + CatalogVector const& catalogs) const override { |
| 61 | + LSST_ARCHIVE_ASSERT(catalogs.size() == 1u); |
| 62 | + LSST_ARCHIVE_ASSERT(catalogs.front().size() == 1u); |
| 63 | + std::shared_ptr<ImageSummary> result = std::make_shared<ImageSummary>(catalogs.front().getSchema()); |
| 64 | + result->setInternal(catalogs.front().front()); |
| 65 | + return result; |
| 66 | + } |
| 67 | + |
| 68 | + ImageSummaryFactory(std::string const& name) : afw::table::io::PersistableFactory(name) {} |
| 69 | +}; |
| 70 | + |
| 71 | +std::string getImageSummaryPersistenceName() { return "ImageSummary"; } |
| 72 | + |
| 73 | +ImageSummaryFactory registration(getImageSummaryPersistenceName()); |
| 74 | + |
| 75 | +} // namespace |
| 76 | + |
| 77 | +bool ImageSummary::isPersistable() const noexcept {return true;} |
| 78 | + |
| 79 | +std::string ImageSummary::getPersistenceName() const { return getImageSummaryPersistenceName(); } |
| 80 | + |
| 81 | +std::string ImageSummary::getPythonModule() const { return "lsst.afw.image"; } |
| 82 | + |
| 83 | +void ImageSummary::write(OutputArchiveHandle& handle) const { |
| 84 | + table::BaseCatalog catalog = handle.makeCatalog(_internal->getSchema()); |
| 85 | + std::shared_ptr<table::BaseRecord> record = catalog.addNew(); |
| 86 | + record->assign(*_internal); |
| 87 | + handle.saveCatalog(catalog); |
| 88 | +} |
| 89 | + |
| 90 | +std::shared_ptr<typehandling::Storable> ImageSummary::cloneStorable() const { |
| 91 | + return std::make_unique<ImageSummary>(*this); |
| 92 | +} |
| 93 | + |
| 94 | +void ImageSummary::setBool(std::string const& key, bool value) { |
| 95 | + _internal->set(_internal->getSchema().find<table::Flag>(key).key, value); |
| 96 | +} |
| 97 | + |
| 98 | +void ImageSummary::setInt64(std::string const& key, std::int64_t value) { |
| 99 | + _internal->set(_internal->getSchema().find<std::int64_t>(key).key, value); |
| 100 | +} |
| 101 | + |
| 102 | +void ImageSummary::setDouble(std::string const& key, double value) { |
| 103 | + _internal->set(_internal->getSchema().find<double>(key).key, value); |
| 104 | +} |
| 105 | + |
| 106 | +} // namespace image |
| 107 | +} // namespace afw |
| 108 | +} // namespace lsst |
0 commit comments