32#include "boost/format.hpp"
33#include "boost/algorithm/string/trim.hpp"
48FilterProperty::PropertyMap* FilterProperty::_propertyMap =
nullptr;
51 : _name(
name), _lambdaEff(NAN), _lambdaMin(NAN), _lambdaMax(NAN) {
52 if (prop.
exists(
"lambdaEff")) {
55 if (prop.
exists(
"lambdaMin")) {
58 if (prop.
exists(
"lambdaMax")) {
64void FilterProperty::_insert(
bool force) {
69 PropertyMap::iterator keyVal = _propertyMap->find(
getName());
71 if (keyVal != _propertyMap->end()) {
72 if (keyVal->second == *
this) {
79 _propertyMap->erase(keyVal);
86 return (_lambdaEff == rhs._lambdaEff);
91void FilterProperty::_initRegistry() {
96 _propertyMap =
new PropertyMap;
104 PropertyMap::iterator keyVal = _propertyMap->find(
name);
106 if (keyVal == _propertyMap->end()) {
110 return keyVal->second;
117int const Filter::AUTO = -1;
118int const Filter::UNKNOWN = -1;
122 if (metadata->exists(key)) {
123 std::string filterName = boost::algorithm::trim_right_copy(metadata->getAsString(key));
124 _id = _lookup(filterName, force);
134 if (metadata->exists(key)) {
135 metadata->remove(key);
147 std::string const& canonicalName = getCanonicalName();
148 for (
auto const &ptr : *_aliasMap) {
149 if (ptr.second == canonicalName) {
164 for (
auto const &ptr : *_nameMap) {
165 if (ptr.first != unknownFilter) {
175 return std::make_unique<Filter>(*
this);
178bool Filter::equals(typehandling::Storable
const& other)
const noexcept {
179 return singleClassEquals(*
this, other);
184struct PersistenceHelper {
188 static PersistenceHelper
const& get() {
189 static PersistenceHelper
const instance;
194 PersistenceHelper() :
schema(),
name(
schema.addField<
std::string>(
"name",
"name of the filter")) {}
197class FilterFactory :
public table::io::PersistableFactory {
200 CatalogVector
const& catalogs)
const override {
201 PersistenceHelper
const&
keys = PersistenceHelper::get();
204 return std::make_shared<Filter>(catalogs.front().begin()->get(
keys.name),
true);
210std::string _getPersistenceName() {
return "Filter"; }
212FilterFactory registration(_getPersistenceName());
216bool Filter::isPersistable() const noexcept {
return true; }
223 PersistenceHelper
const&
keys = PersistenceHelper::get();
227 handle.saveCatalog(catalog);
234void Filter::_initRegistry() {
240 _aliasMap =
new AliasMap;
241 _nameMap =
new NameMap;
244 define(
FilterProperty(unknownFilter, daf::base::PropertySet(),
true));
247int Filter::_id0 = Filter::UNKNOWN;
250Filter::AliasMap* Filter::_aliasMap =
nullptr;
251Filter::NameMap* Filter::_nameMap =
nullptr;
252Filter::IdMap* Filter::_idMap =
nullptr;
260 NameMap::iterator keyVal = _nameMap->find(
name);
262 if (keyVal != _nameMap->end()) {
263 int oid = keyVal->second;
265 if (
id == oid ||
id == AUTO) {
272 _nameMap->erase(keyVal);
293 NameMap::iterator keyVal = _nameMap->find(oldName);
294 if (keyVal == _nameMap->end()) {
297 int const id = keyVal->second;
300 AliasMap::iterator aliasKeyVal = _aliasMap->find(newName);
301 if (aliasKeyVal != _aliasMap->end()) {
302 if (aliasKeyVal->second == oldName) {
309 _aliasMap->erase(aliasKeyVal);
322 NameMap::iterator keyVal = _nameMap->find(
name);
324 if (keyVal == _nameMap->end()) {
325 AliasMap::iterator aliasKeyVal = _aliasMap->find(
name);
326 if (aliasKeyVal != _aliasMap->end()) {
327 return _lookup(aliasKeyVal->second);
337 return keyVal->second;
345 IdMap::iterator keyVal = _idMap->find(
id);
347 if (keyVal == _idMap->end()) {
351 return keyVal->second;
357 int const id = _lookup(_name,
true);
360 return FilterProperty::lookup(
name);
#define LSST_EXCEPT(type,...)
table::Key< std::string > name
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
bool exists(std::string const &name) const
double getAsDouble(std::string const &name) const
int stripFilterKeywords(std::shared_ptr< lsst::daf::base::PropertySet > metadata)
Remove Filter-related keywords from the metadata.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
bool operator==(FilterProperty const &rhs) const noexcept
Return true iff two FilterProperties are identical.
std::string getPythonModule() const override
std::string getPersistenceName() const override
@ UNKNOWN
Rotation angle is unknown.
void write(OutputArchiveHandle &handle) const override
std::size_t hash_value() const noexcept
Return a hash of this object.
std::string const & getName() const noexcept
Return a filter's name.
FilterProperty(FilterProperty const &)=default
CatalogT< BaseRecord > BaseCatalog
A base class for image defects.
std::shared_ptr< table::io::Persistable > read(table::io::InputArchive const &archive, table::io::CatalogVector const &catalogs) const override