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() {
98 _propertyMap =
new PropertyMap;
106 PropertyMap::iterator keyVal = _propertyMap->find(
name);
108 if (keyVal == _propertyMap->end()) {
112 return keyVal->second;
119 int const Filter::AUTO = -1;
120 int const Filter::UNKNOWN = -1;
124 if (metadata->exists(
key)) {
125 std::string filterName = boost::algorithm::trim_right_copy(metadata->getAsString(
key));
126 _id = _lookup(filterName, force);
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);
180 bool Filter::equals(typehandling::Storable
const&
other)
const noexcept {
181 return singleClassEquals(*
this,
other);
186 struct PersistenceHelper {
190 static PersistenceHelper
const& get() {
191 static PersistenceHelper
const instance;
196 PersistenceHelper() :
schema(),
name(
schema.addField<
std::string>(
"name",
"name of the filter")) {}
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);
212 std::string _getPersistenceName() {
return "Filter"; }
214 FilterFactory registration(_getPersistenceName());
218 bool Filter::isPersistable() const noexcept {
return true; }
225 PersistenceHelper
const&
keys = PersistenceHelper::get();
229 handle.saveCatalog(catalog);
236 void Filter::_initRegistry() {
242 _aliasMap =
new AliasMap;
243 _nameMap =
new NameMap;
246 define(
FilterProperty(unknownFilter, daf::base::PropertySet(),
true));
249 int Filter::_id0 = Filter::UNKNOWN;
252 Filter::AliasMap* Filter::_aliasMap = NULL;
253 Filter::NameMap* Filter::_nameMap = NULL;
254 Filter::IdMap* Filter::_idMap = NULL;
256 int Filter::define(
FilterProperty const& fp,
int id,
bool force) {
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);
362 return FilterProperty::lookup(
name);
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
table::Key< std::string > name
ItemVariant const * other
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
Class for storing generic metadata.
virtual void remove(std::string const &name)
Remove all values for a property name (possibly hierarchical).
bool exists(std::string const &name) const
Determine if a name (possibly hierarchical) exists.
double getAsDouble(std::string const &name) const
Get the last value for any arithmetic property name (possibly hierarchical).
Reports attempts to access elements using an invalid key.
Reports errors that are due to events beyond the control of the program.
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
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
A base class for image defects.