lsst.afw  16.0-56-g615901931+1
Filter.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 //
26 //##====---------------- ----------------====##/
27 //
28 // Class encapsulating an identifier for an LSST filter.
29 //
30 //##====---------------- ----------------====##/
31 
32 #ifndef LSST_AFW_IMAGE_FILTER_H
33 #define LSST_AFW_IMAGE_FILTER_H
34 
35 #include <cmath>
36 #include <string>
37 #include <unordered_map>
38 #include <vector>
39 #include <memory>
40 #include "lsst/base.h"
42 
43 
44 namespace lsst {
45 namespace afw {
46 namespace image {
47 
51 class FilterProperty final {
52 public:
53  explicit FilterProperty(std::string const& name, double lambdaEff, double lambdaMin = NAN,
54  double lambdaMax = NAN, bool force = false)
55  : _name(name), _lambdaEff(lambdaEff), _lambdaMin(lambdaMin), _lambdaMax(lambdaMax) {
56  _insert(force);
57  }
63  explicit FilterProperty(std::string const& name,
65  bool force = false);
66 
67  FilterProperty(FilterProperty const&) = default;
68  FilterProperty(FilterProperty&&) noexcept = default;
69  FilterProperty& operator=(FilterProperty const&) = default;
70  FilterProperty& operator=(FilterProperty&&) noexcept = default;
71  ~FilterProperty() noexcept = default;
72 
76  std::string const& getName() const noexcept { return _name; }
80  double getLambdaEff() const noexcept { return _lambdaEff; }
84  double getLambdaMin() const noexcept { return _lambdaMin; }
88  double getLambdaMax() const noexcept { return _lambdaMax; }
94  bool operator==(FilterProperty const& rhs) const noexcept;
98  bool operator!=(FilterProperty const& rhs
99  ) const noexcept {
100  return !(*this == rhs);
101  }
105  static void reset() { _initRegistry(); }
106 
112  static FilterProperty const& lookup(std::string const& name);
113 
114 private:
116 
120  static void _initRegistry();
126  void _insert(bool force = false);
127 
128  std::string _name; // name of filter
129  double _lambdaEff; // effective wavelength (nm)
130  double _lambdaMin; // minimum wavelength (nm)
131  double _lambdaMax; // maximum wavelength (nm)
132 
133  static PropertyMap* _propertyMap; // mapping from name -> FilterProperty
134 };
135 
139 class Filter final {
140 public:
141  static int const AUTO;
142  static int const UNKNOWN;
143 
147  explicit Filter(std::string const& name,
148  bool const force = false
149  )
150  : _id(_lookup(name, force)), _name(name) {}
154  explicit Filter(int id = UNKNOWN
155  )
156  : _id(id), _name(_lookup(id)) {}
163  explicit Filter(std::shared_ptr<lsst::daf::base::PropertySet const> metadata, bool const force = false);
164 
165  Filter(Filter const&) = default;
166  Filter(Filter&&) noexcept = default;
167  Filter& operator=(Filter const&) = default;
168  Filter& operator=(Filter&&) noexcept = default;
169  ~Filter() noexcept = default;
170 
174  bool operator==(Filter const& rhs) const noexcept;
175  bool operator!=(Filter const& rhs) const noexcept { return !(*this == rhs); }
176 
180  int getId() const noexcept { return _id; }
184  std::string const& getName() const noexcept { return _name; }
190  std::string const& getCanonicalName() const { return _lookup(_id); }
196  std::vector<std::string> getAliases() const;
197 
201  FilterProperty const& getFilterProperty() const;
205  static void reset() { _initRegistry(); }
213  static int define(FilterProperty const& filterProperty, int id = AUTO, bool force = false);
221  static int defineAlias(std::string const& oldName, std::string const& newName, bool force = false);
222 
226  static std::vector<std::string> getNames();
227 
228 private:
232 
236  static void _initRegistry();
243  static int _lookup(std::string const& name, bool const force = false);
247  static std::string const& _lookup(int id);
248 
249  int _id;
250  std::string _name;
251 
252  static int _id0; // next Id to use
253  static AliasMap* _aliasMap; // mapping from alias -> name
254  static IdMap* _idMap; // mapping from id -> name
255  static NameMap* _nameMap; // mapping from name -> id
256 };
257 
258 namespace detail {
266 } // namespace detail
267 } // namespace image
268 } // namespace afw
269 } // namespace lsst
270 
271 #endif // LSST_AFW_IMAGE_FILTER_H
std::string const & getCanonicalName() const
Return a filter&#39;s canonical name.
Definition: Filter.h:190
static void reset()
Clear all definitions.
Definition: Filter.h:105
std::string const & getName() const noexcept
Return a filter&#39;s name.
Definition: Filter.h:76
static int const UNKNOWN
Definition: Filter.h:142
int stripFilterKeywords(std::shared_ptr< lsst::daf::base::PropertySet > metadata)
Remove Filter-related keywords from the metadata.
Definition: Filter.cc:125
STL class.
static FilterProperty const & lookup(std::string const &name)
Lookup the properties of a filter "name".
Definition: Filter.cc:94
A base class for image defects.
int getId() const noexcept
Return a Filter&#39;s integral id.
Definition: Filter.h:180
bool operator==(FilterProperty const &rhs) const noexcept
Return true iff two FilterProperties are identical.
Definition: Filter.cc:82
static int const AUTO
Definition: Filter.h:141
FilterProperty & operator=(FilterProperty const &)=default
table::Key< int > id
Definition: Detector.cc:163
double getLambdaMax() const noexcept
Return the filter&#39;s maximum wavelength (nm) where the transmission is above 1% of the maximum...
Definition: Filter.h:88
Holds an integer identifier for an LSST filter.
Definition: Filter.h:139
~FilterProperty() noexcept=default
bool operator!=(FilterProperty const &rhs) const noexcept
Return true iff rhs != this.
Definition: Filter.h:98
double getLambdaEff() const noexcept
Return the filter&#39;s effective wavelength (nm)
Definition: Filter.h:80
Filter(int id=UNKNOWN)
Creates a Filter with the given identifier.
Definition: Filter.h:154
Filter(std::string const &name, bool const force=false)
Creates a Filter with the given name.
Definition: Filter.h:147
bool operator!=(Filter const &rhs) const noexcept
Definition: Filter.h:175
Describe the properties of a Filter (e.g.
Definition: Filter.h:51
FilterProperty(std::string const &name, double lambdaEff, double lambdaMin=NAN, double lambdaMax=NAN, bool force=false)
Definition: Filter.h:53
static void reset()
Clear all definitions.
Definition: Filter.h:205
std::string const & getName() const noexcept
Return a Filter&#39;s name.
Definition: Filter.h:184
double getLambdaMin() const noexcept
Return the filter&#39;s minimum wavelength (nm) where the transmission is above 1% of the maximum...
Definition: Filter.h:84