LSST Applications g180d380827+770a9040cc,g2079a07aa2+86d27d4dc4,g2305ad1205+09cfdadad9,g2bbee38e9b+c6a8a0fb72,g337abbeb29+c6a8a0fb72,g33d1c0ed96+c6a8a0fb72,g3a166c0a6a+c6a8a0fb72,g3ddfee87b4+1ea5e09c42,g48712c4677+7e2ea9cd42,g487adcacf7+301d09421d,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+96fcb956a6,g64a986408d+23540ee355,g858d7b2824+23540ee355,g864b0138d7+aa38e45daa,g95921f966b+d83dc58ecd,g991b906543+23540ee355,g99cad8db69+7f13b58a93,g9c22b2923f+e2510deafe,g9ddcbc5298+9a081db1e4,ga1e77700b3+03d07e1c1f,gb0e22166c9+60f28cb32d,gb23b769143+23540ee355,gba4ed39666+c2a2e4ac27,gbb8dafda3b+49e7449578,gbd998247f1+585e252eca,gc120e1dc64+1bbfa184e1,gc28159a63d+c6a8a0fb72,gc3e9b769f7+385ea95214,gcf0d15dbbd+1ea5e09c42,gdaeeff99f8+f9a426f77a,ge6526c86ff+1bccc98490,ge79ae78c31+c6a8a0fb72,gee10cc3b42+585e252eca,w.2024.18
LSST Data Management Base Package
Loading...
Searching...
No Matches
ApCorrMap.cc
Go to the documentation of this file.
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
31
32namespace lsst {
33namespace afw {
34
37
38namespace image {
39
40// Even though this static const member is set in the header, it needs to be declared here if we need
41// to take its address (and Swig might).
42std::size_t const ApCorrMap::MAX_NAME_LENGTH;
43
44std::shared_ptr<math::BoundedField> const ApCorrMap::operator[](std::string const& name) const {
45 Iterator i = _internal.find(name);
46 if (i == _internal.end()) {
48 (boost::format("Aperture correction with name '%s' not found") % name).str());
49 }
50 return i->second;
51}
52
53std::shared_ptr<math::BoundedField> const ApCorrMap::get(std::string const& name) const {
54 Iterator i = _internal.find(name);
55 if (i == _internal.end()) {
57 }
58 return i->second;
59}
60
61void ApCorrMap::set(std::string const& name, std::shared_ptr<math::BoundedField> field) {
62 if (name.size() > MAX_NAME_LENGTH) {
63 throw LSST_EXCEPT(
65 (boost::format("Aperture correction name '%s' exceeds size limit of %d characters") % name %
66 MAX_NAME_LENGTH)
67 .str());
68 }
69 _internal.insert(std::make_pair(name, field));
70}
71
72namespace {
73
74struct PersistenceHelper {
75 table::Schema schema;
76 table::Key<std::string> name;
77 table::Key<int> field;
78
79 static PersistenceHelper const& get() {
80 static PersistenceHelper const instance;
81 return instance;
82 }
83
84private:
85 PersistenceHelper()
86 : schema(),
87 name(schema.addField<std::string>("name", "name of the aperture correction",
88 ApCorrMap::MAX_NAME_LENGTH)),
89 field(schema.addField<int>("field", "archive ID of the BoundedField object")) {}
90};
91
92class ApCorrMapFactory : public table::io::PersistableFactory {
93public:
94 std::shared_ptr<table::io::Persistable> read(InputArchive const& archive,
95 CatalogVector const& catalogs) const override {
96 PersistenceHelper const& keys = PersistenceHelper::get();
97 LSST_ARCHIVE_ASSERT(catalogs.size() == 1u);
98 LSST_ARCHIVE_ASSERT(catalogs.front().getSchema() == keys.schema);
99 std::shared_ptr<ApCorrMap> result = std::make_shared<ApCorrMap>();
100 for (table::BaseCatalog::const_iterator i = catalogs.front().begin(); i != catalogs.front().end();
101 ++i) {
102 result->set(i->get(keys.name), archive.get<math::BoundedField>(i->get(keys.field)));
103 }
104 return result;
105 }
106
107 ApCorrMapFactory(std::string const& name) : afw::table::io::PersistableFactory(name) {}
108};
109
110std::string getApCorrMapPersistenceName() { return "ApCorrMap"; }
111
112ApCorrMapFactory registration(getApCorrMapPersistenceName());
113
114} // namespace
115
116bool ApCorrMap::isPersistable() const noexcept {
117 for (auto const &i : *this) {
118 if (!i.second->isPersistable()) return false;
119 }
120 return true;
121}
122
123std::string ApCorrMap::getPersistenceName() const { return getApCorrMapPersistenceName(); }
124
125std::string ApCorrMap::getPythonModule() const { return "lsst.afw.image"; }
126
127void ApCorrMap::write(OutputArchiveHandle& handle) const {
128 PersistenceHelper const& keys = PersistenceHelper::get();
129 table::BaseCatalog catalog = handle.makeCatalog(keys.schema);
130 for (auto const &i : *this) {
131 std::shared_ptr<table::BaseRecord> record = catalog.addNew();
132 record->set(keys.name, i.first);
133 record->set(keys.field, handle.put(i.second));
134 }
135 handle.saveCatalog(catalog);
136}
137
138ApCorrMap& ApCorrMap::operator*=(double const scale) {
139 Internal replacement;
140 for (auto const &i : *this) {
141 replacement[i.first] = (*i.second) * scale;
142 }
143 _internal = replacement;
144 return *this;
145}
146
147std::shared_ptr<typehandling::Storable> ApCorrMap::cloneStorable() const {
148 return std::make_unique<ApCorrMap>(*this);
149}
150
151} // namespace image
152} // namespace afw
153} // namespace lsst
py::object result
Definition _schema.cc:429
table::Key< std::string > name
Definition Amplifier.cc:116
table::Key< int > field
Definition ApCorrMap.cc:77
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
Definition Persistable.h:48
table::Schema schema
Definition python.h:134
A thin wrapper around std::map to allow aperture corrections to be attached to Exposures.
Definition ApCorrMap.h:45
Internal::const_iterator Iterator
Iterator type returned by begin() and end().
Definition ApCorrMap.h:54
CatalogIterator< typename Internal::const_iterator > const_iterator
Definition Catalog.h:111
An object passed to Persistable::write to allow it to persist itself.
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
int put(Persistable const *obj, bool permissive=false)
Save an object to the archive and return a unique ID that can be used to retrieve it from an InputArc...
static std::shared_ptr< T > dynamicCast(std::shared_ptr< Persistable > const &ptr)
Dynamically cast a shared_ptr.
Reports attempts to exceed implementation-defined length limits for some classes.
Definition Runtime.h:76
Reports attempts to access elements using an invalid key.
Definition Runtime.h:151
T make_pair(T... args)
STL namespace.
std::shared_ptr< table::io::Persistable > read(table::io::InputArchive const &archive, table::io::CatalogVector const &catalogs) const override