32 #include "boost/format.hpp" 33 #include "boost/algorithm/string/trim.hpp" 42 #include "lsst/afw/table/io/Persistable.cc" 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;
197 schema.getCitizen().markPersistent();
201 class FilterFactory :
public table::io::PersistableFactory {
204 CatalogVector
const& catalogs)
const override {
205 PersistenceHelper
const&
keys = PersistenceHelper::get();
208 return std::make_shared<Filter>(catalogs.front().begin()->get(keys.name),
true);
211 FilterFactory(
std::string const&
name) : afw::table::io::PersistableFactory(name) {}
214 std::string getPersistenceName() {
return "Filter"; }
216 FilterFactory registration(getPersistenceName());
227 PersistenceHelper
const&
keys = PersistenceHelper::get();
230 record->set(keys.name,
getName());
238 void Filter::_initRegistry() {
264 NameMap::iterator keyVal = _nameMap->
find(name);
266 if (keyVal != _nameMap->end()) {
267 int oid = keyVal->second;
269 if (
id == oid ||
id == AUTO) {
276 _nameMap->erase(keyVal);
297 NameMap::iterator keyVal = _nameMap->find(oldName);
298 if (keyVal == _nameMap->end()) {
301 int const id = keyVal->second;
304 AliasMap::iterator aliasKeyVal = _aliasMap->find(newName);
305 if (aliasKeyVal != _aliasMap->end()) {
306 if (aliasKeyVal->second == oldName) {
313 _aliasMap->erase(aliasKeyVal);
326 NameMap::iterator keyVal = _nameMap->find(name);
328 if (keyVal == _nameMap->end()) {
329 AliasMap::iterator aliasKeyVal = _aliasMap->find(name);
330 if (aliasKeyVal != _aliasMap->end()) {
331 return _lookup(aliasKeyVal->second);
341 return keyVal->second;
349 IdMap::iterator keyVal = _idMap->find(
id);
351 if (keyVal == _idMap->end()) {
355 return keyVal->second;
361 int const id = _lookup(_name,
true);
double getAsDouble(std::string const &name) const
Get the last value for any arithmetic property name (possibly hierarchical).
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.
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.
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.
Reports attempts to access elements using an invalid key.
A base class for image defects.
bool operator==(FilterProperty const &rhs) const noexcept
Return true iff two FilterProperties are identical.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
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.
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
std::vector< std::string > getAliases() const
Return all aliases by which this filter is known.
bool exists(std::string const &name) const
Determine if a name (possibly hierarchical) exists.
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.
table::Key< std::string > name
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,...)
Create an exception with a given type.
Class for storing generic metadata.
ItemVariant const * other
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.
Reports errors that are due to events beyond the control of the program.
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.