24 #include "boost/make_shared.hpp"
31 namespace lsst {
namespace afw {
namespace image {
39 if (i == _internal.end()) {
41 pex::exceptions::NotFoundError,
42 (
boost::format(
"Aperture correction with name '%s' not found") % name).str()
50 if (i == _internal.end()) {
59 pex::exceptions::LengthError,
60 (
boost::format(
"Aperture correction name '%s' exceeds size limit of %d characters")
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;
83 name(
schema.addField<std::string>(
"name",
"name of the aperture correction",
84 ApCorrMap::MAX_NAME_LENGTH)),
85 field(
schema.addField<int>(
"field",
"archive ID of the BoundedField object"))
87 schema.getCitizen().markPersistent();
92 class ApCorrMapFactory :
public table::io::PersistableFactory {
95 virtual PTR(table::io::Persistable)
96 read(InputArchive const & archive, CatalogVector const & catalogs)
const {
97 PersistenceHelper
const & keys = PersistenceHelper::get();
100 PTR(ApCorrMap) result
101 = boost::make_shared<ApCorrMap>();
103 table::
BaseCatalog::const_iterator i = catalogs.front().begin();
104 i != catalogs.front().end();
112 ApCorrMapFactory(std::string
const & name) : afw::table::io::PersistableFactory(name) {}
116 std::string getApCorrMapPersistenceName() {
120 ApCorrMapFactory registration(getApCorrMapPersistenceName());
126 if (!i->second->isPersistable())
return false;
132 return getApCorrMapPersistenceName();
136 return "lsst.afw.image";
140 PersistenceHelper
const & keys = PersistenceHelper::get();
144 record->set(keys.name, i->first);
145 record->set(keys.field, handle.
put(i->second));
153 replacement[i->first] = (*i->second)*scale;
table::Key< std::string > name
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
for(FootprintList::const_iterator ptr=feet->begin(), end=feet->end();ptr!=end;++ptr)
CatalogT< BaseRecord > BaseCatalog
An object passed to Persistable::write to allow it to persist itself.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
int put(Persistable const *obj, bool permissive=false)
Save a nested Persistable to the same archive.
A custom container class for records, based on std::vector.
A thin wrapper around std::map to allow aperture corrections to be attached to Exposures.
void set(std::string const &name, boost::shared_ptr< math::BoundedField > field)
Add or replace an aperture correction.
std::map< std::string, boost::shared_ptr< math::BoundedField > > Internal
boost::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
table::Key< table::Array< Kernel::Pixel > > image
virtual std::string getPythonModule() const
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
#define LSST_EXCEPT(type,...)
Base class for all records.
virtual bool isPersistable() const
Whether the map is persistable (true IFF all contained BoundedFields are persistable).
static std::size_t const MAX_NAME_LENGTH
Maximum number of characters for an aperture correction name (required for persistence).
An abstract base class for 2-d functions defined on an integer bounding boxes.
void operator*=(double const scale)
Scale all fields by a constant.
Internal::const_iterator Iterator
Iterator type returned by begin() and end(). Dereferences to a pair<string,PTR(BoundedField)>.
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.