LSST Applications g042eb84c57+730a74494b,g04e9c324dd+8c5ae1fdc5,g134cb467dc+1f1e3e7524,g199a45376c+0ba108daf9,g1fd858c14a+fa7d31856b,g210f2d0738+f66ac109ec,g262e1987ae+83a3acc0e5,g29ae962dfc+d856a2cb1f,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+a1e0c9f713,g47891489e3+0d594cb711,g4d44eb3520+c57ec8f3ed,g4d7b6aa1c5+f66ac109ec,g53246c7159+8c5ae1fdc5,g56a1a4eaf3+fd7ad03fde,g64539dfbff+f66ac109ec,g67b6fd64d1+0d594cb711,g67fd3c3899+f66ac109ec,g6985122a63+0d594cb711,g74acd417e5+3098891321,g786e29fd12+668abc6043,g81db2e9a8d+98e2ab9f28,g87389fa792+8856018cbb,g89139ef638+0d594cb711,g8d7436a09f+80fda9ce03,g8ea07a8fe4+760ca7c3fc,g90f42f885a+033b1d468d,g97be763408+a8a29bda4b,g99822b682c+e3ec3c61f9,g9d5c6a246b+0d5dac0c3d,ga41d0fce20+9243b26dd2,gbf99507273+8c5ae1fdc5,gd7ef33dd92+0d594cb711,gdab6d2f7ff+3098891321,ge410e46f29+0d594cb711,geaed405ab2+c4bbc419c6,gf9a733ac38+8c5ae1fdc5,w.2025.38
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
35template std::shared_ptr<image::ApCorrMap> table::io::PersistableFacade<image::ApCorrMap>::dynamicCast(
36 std::shared_ptr<table::io::Persistable> const&);
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
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
54 Iterator i = _internal.find(name);
55 if (i == _internal.end()) {
57 }
58 return i->second;
59}
60
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 %
67 .str());
68 }
69 _internal.insert(std::make_pair(name, field));
70}
71
72namespace {
73
74struct PersistenceHelper {
75 table::Schema schema;
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);
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
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
148 return std::make_unique<ApCorrMap>(*this);
149}
150
151} // namespace image
152} // namespace afw
153} // namespace lsst
#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
std::shared_ptr< typehandling::Storable > cloneStorable() const override
Create a new ApCorrMap that is a copy of this one.
Definition ApCorrMap.cc:147
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
Definition ApCorrMap.cc:127
bool isPersistable() const noexcept override
Whether the map is persistable (true IFF all contained BoundedFields are persistable).
Definition ApCorrMap.cc:116
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
Definition ApCorrMap.cc:125
void set(std::string const &name, std::shared_ptr< math::BoundedField > field)
Add or replace an aperture correction.
Definition ApCorrMap.cc:61
std::shared_ptr< math::BoundedField > const get(std::string const &name) const
Return the field with the given name, returning an empty pointer when the name is not present.
Definition ApCorrMap.cc:53
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
Definition ApCorrMap.cc:123
static std::size_t const MAX_NAME_LENGTH
Maximum number of characters for an aperture correction name (required for persistence).
Definition ApCorrMap.h:50
std::shared_ptr< math::BoundedField > const operator[](std::string const &name) const
Return the field with the given name, throwing NotFoundError when the name is not present.
Definition ApCorrMap.cc:44
Internal::const_iterator Iterator
Iterator type returned by begin() and end().
Definition ApCorrMap.h:54
ApCorrMap & operator*=(double const scale)
Scale all fields by a constant.
Definition ApCorrMap.cc:138
CatalogIterator< typename Internal::const_iterator > const_iterator
Definition Catalog.h:111
A class used as a handle to a particular field in a table.
Definition Key.h:53
Defines the fields and offsets for a table.
Definition Schema.h:51
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.
io::OutputArchiveHandle OutputArchiveHandle
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)
T make_shared(T... args)
CatalogT< BaseRecord > BaseCatalog
Definition fwd.h:72
STL namespace.
decltype(sizeof(void *)) size_t
Definition doctest.h:524
std::shared_ptr< table::io::Persistable > read(table::io::InputArchive const &archive, table::io::CatalogVector const &catalogs) const override