32 #include "boost/format.hpp" 33 #include "boost/algorithm/string/trim.hpp" 50 FilterProperty::PropertyMap* FilterProperty::_propertyMap = NULL;
53 : _name(name), _lambdaEff(NAN), _lambdaMin(NAN), _lambdaMax(NAN) {
54 if (prop.
exists(
"lambdaEff")) {
57 if (prop.
exists(
"lambdaMin")) {
60 if (prop.
exists(
"lambdaMax")) {
66 void FilterProperty::_insert(
bool force) {
71 PropertyMap::iterator keyVal = _propertyMap->
find(
getName());
73 if (keyVal != _propertyMap->
end()) {
74 if (keyVal->second == *
this) {
81 _propertyMap->
erase(keyVal);
88 return (_lambdaEff == rhs._lambdaEff);
93 void FilterProperty::_initRegistry() {
106 PropertyMap::iterator keyVal = _propertyMap->
find(name);
108 if (keyVal == _propertyMap->
end()) {
112 return keyVal->second;
124 if (metadata->exists(key)) {
125 std::string filterName = boost::algorithm::trim_right_copy(metadata->getAsString(key));
126 _id = _lookup(filterName, force);
136 if (metadata->exists(key)) {
137 metadata->remove(key);
149 std::string const& canonicalName = getCanonicalName();
150 for (AliasMap::iterator ptr = _aliasMap->begin(),
end = _aliasMap->end(); ptr !=
end; ++ptr) {
151 if (ptr->second == canonicalName) {
166 for (NameMap::const_iterator ptr = _nameMap->begin(),
end = _nameMap->end(); ptr !=
end; ++ptr) {
167 if (ptr->first != unknownFilter) {
177 return std::make_unique<Filter>(*this);
181 return singleClassEquals(*
this,
other);
186 struct PersistenceHelper {
190 static PersistenceHelper
const&
get() {
191 static PersistenceHelper
const instance;
199 class FilterFactory :
public table::io::PersistableFactory {
202 CatalogVector
const& catalogs)
const override {
203 PersistenceHelper
const&
keys = PersistenceHelper::get();
206 return std::make_shared<Filter>(catalogs.front().begin()->get(keys.name),
true);
209 FilterFactory(
std::string const&
name) : afw::table::io::PersistableFactory(name) {}
212 std::string getPersistenceName() {
return "Filter"; }
214 FilterFactory registration(getPersistenceName());
225 PersistenceHelper
const&
keys = PersistenceHelper::get();
228 record->set(keys.name,
getName());
236 void Filter::_initRegistry() {
262 NameMap::iterator keyVal = _nameMap->
find(name);
264 if (keyVal != _nameMap->end()) {
265 int oid = keyVal->second;
267 if (
id == oid ||
id == AUTO) {
274 _nameMap->erase(keyVal);
295 NameMap::iterator keyVal = _nameMap->find(oldName);
296 if (keyVal == _nameMap->end()) {
299 int const id = keyVal->second;
302 AliasMap::iterator aliasKeyVal = _aliasMap->find(newName);
303 if (aliasKeyVal != _aliasMap->end()) {
304 if (aliasKeyVal->second == oldName) {
311 _aliasMap->erase(aliasKeyVal);
324 NameMap::iterator keyVal = _nameMap->find(name);
326 if (keyVal == _nameMap->end()) {
327 AliasMap::iterator aliasKeyVal = _aliasMap->find(name);
328 if (aliasKeyVal != _aliasMap->end()) {
329 return _lookup(aliasKeyVal->second);
339 return keyVal->second;
347 IdMap::iterator keyVal = _idMap->find(
id);
349 if (keyVal == _idMap->end()) {
353 return keyVal->second;
359 int const id = _lookup(_name,
true);
double getAsDouble(std::string const &name) const
bool operator==(Filter const &rhs) const noexcept
Are two filters identical?
std::string const & getName() const noexcept
Return a filter's name.
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
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.
std::shared_ptr< typehandling::Storable > cloneStorable() const override
Create a new Filter that is a copy of this one.
Interface supporting iteration over heterogenous containers.
int stripFilterKeywords(std::shared_ptr< lsst::daf::base::PropertySet > metadata)
Remove Filter-related keywords from the metadata.
table::Key< std::string > name
ItemVariant const * other
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
Rotation angle is unknown.
static FilterProperty const & lookup(std::string const &name)
Lookup the properties of a filter "name".
bool equals(typehandling::Storable const &other) const noexcept override
Compare this object to another Storable.
A base class for image defects.
bool operator==(FilterProperty const &rhs) const noexcept
Return true iff two FilterProperties are identical.
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
static int define(FilterProperty const &filterProperty, int id=AUTO, bool force=false)
Define a filter name to have the specified id.
std::vector< std::string > getAliases() const
Return all aliases by which this filter is known.
bool exists(std::string const &name) const
static int defineAlias(std::string const &oldName, std::string const &newName, bool force=false)
Define an alias for a filter.
Holds an integer identifier for an LSST filter.
std::size_t hash_value() const noexcept override
Return a hash of this object.
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
#define LSST_EXCEPT(type,...)
Filter(std::string const &name, bool const force=false)
Creates a Filter with the given name.
FilterProperty const & getFilterProperty() const
Return a Filter's FilterProperty.
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
Describe the properties of a Filter (e.g.
FilterProperty(std::string const &name, double lambdaEff, double lambdaMin=NAN, double lambdaMax=NAN, bool force=false)
static std::vector< std::string > getNames()
Return a list of known filters.
std::size_t hash_value() const noexcept
Return a hash of this object.
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.