41 if (i == _internal.end()) {
42 throw LSST_EXCEPT(pex::exceptions::NotFoundError,
43 (boost::format(
"Aperture correction with name '%s' not found") % name).str());
50 if (i == _internal.end()) {
51 return std::shared_ptr<math::BoundedField>();
59 pex::exceptions::LengthError,
60 (boost::format(
"Aperture correction name '%s' exceeds size limit of %d characters") % name %
64 _internal.insert(std::make_pair(name, field));
69 struct PersistenceHelper {
71 table::Key<std::string>
name;
74 static PersistenceHelper
const&
get() {
75 static PersistenceHelper
const instance;
82 name(
schema.addField<std::string>(
"name",
"name of the aperture correction",
83 ApCorrMap::MAX_NAME_LENGTH)),
84 field(
schema.addField<int>(
"field",
"archive ID of the BoundedField object")) {
85 schema.getCitizen().markPersistent();
89 class ApCorrMapFactory :
public table::io::PersistableFactory {
91 virtual std::shared_ptr<table::io::Persistable> read(InputArchive
const& archive,
92 CatalogVector
const& catalogs)
const {
93 PersistenceHelper
const& keys = PersistenceHelper::get();
96 std::shared_ptr<ApCorrMap>
result = std::make_shared<ApCorrMap>();
99 result->set(i->get(keys.name), archive.get<math::BoundedField>(i->get(keys.field)));
104 ApCorrMapFactory(std::string
const&
name) : afw::table::io::PersistableFactory(name) {}
107 std::string getApCorrMapPersistenceName() {
return "ApCorrMap"; }
109 ApCorrMapFactory registration(getApCorrMapPersistenceName());
115 if (!i->second->isPersistable())
return false;
120 std::string ApCorrMap::getPersistenceName()
const {
return getApCorrMapPersistenceName(); }
122 std::string ApCorrMap::getPythonModule()
const {
return "lsst.afw.image"; }
124 void ApCorrMap::write(OutputArchiveHandle& handle)
const {
125 PersistenceHelper
const& keys = PersistenceHelper::get();
128 std::shared_ptr<table::BaseRecord> record = catalog.addNew();
129 record->set(keys.name, i->first);
130 record->set(keys.field, handle.put(i->second));
132 handle.saveCatalog(catalog);
136 Internal replacement;
138 replacement[i->first] = (*i->second) * scale;
140 _internal = replacement;
static std::size_t const MAX_NAME_LENGTH
Maximum number of characters for an aperture correction name (required for persistence).
CatalogT< BaseRecord > BaseCatalog
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
A thin wrapper around std::map to allow aperture corrections to be attached to Exposures.
ApCorrMap & operator*=(double const scale)
Scale all fields by a constant.
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...
table::Key< std::string > name
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...
CatalogIterator< typename Internal::const_iterator > const_iterator
virtual bool isPersistable() const
Whether the map is persistable (true IFF all contained BoundedFields are persistable).
void set(std::string const &name, std::shared_ptr< math::BoundedField > field)
Add or replace an aperture correction.
Internal::const_iterator Iterator
Iterator type returned by begin() and end().
afw::table::Schema schema