lsst.afw  14.0-49-g535656444+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 <string>
36 #include <unordered_map>
37 #include <vector>
38 #include <memory>
39 #include "lsst/base.h"
40 #include "lsst/pex/policy/Policy.h"
41 
42 namespace lsst {
43 namespace daf {
44 namespace base {
45 class PropertySet;
46 }
47 }
48 
49 namespace afw {
50 namespace image {
51 
56 public:
57  explicit FilterProperty(std::string const& name, double lambdaEff, bool force = false)
58  : _name(name), _lambdaEff(lambdaEff) {
59  _insert(force);
60  }
66  explicit FilterProperty(std::string const& name,
68  bool force = false);
76  explicit FilterProperty(std::string const& name, lsst::pex::policy::Policy const& pol,
77  bool force = false);
78 
79  FilterProperty(FilterProperty const&) = default;
80  FilterProperty(FilterProperty&&) = default;
81  FilterProperty& operator=(FilterProperty const&) = default;
82  FilterProperty& operator=(FilterProperty&&) = default;
83  ~FilterProperty() = default;
84 
88  std::string const& getName() const { return _name; }
92  double getLambdaEff() const { return _lambdaEff; }
98  bool operator==(FilterProperty const& rhs) const;
102  bool operator!=(FilterProperty const& rhs
103  ) const {
104  return !(*this == rhs);
105  }
109  static void reset() { _initRegistry(); }
110 
116  static FilterProperty const& lookup(std::string const& name);
117 
118 private:
120 
124  static void _initRegistry();
130  void _insert(bool force = false);
131 
132  std::string _name; // name of filter
133  double _lambdaEff; // effective wavelength (nm)
134 
135  static PropertyMap* _propertyMap; // mapping from name -> FilterProperty
136 };
137 
141 class Filter {
142 public:
143  static int const AUTO;
144  static int const UNKNOWN;
145 
149  explicit Filter(std::string const& name,
150  bool const force = false
151  )
152  : _id(_lookup(name, force)), _name(name) {}
156  explicit Filter(int id = UNKNOWN
157  )
158  : _id(id), _name(_lookup(id)) {}
165  explicit Filter(std::shared_ptr<lsst::daf::base::PropertySet const>, bool const force = false);
166 
167  Filter(Filter const&) = default;
168  Filter(Filter&&) = default;
169  Filter& operator=(Filter const&) = default;
170  Filter& operator=(Filter&&) = default;
171  ~Filter() = default;
172 
176  bool operator==(Filter const& rhs) const;
177  bool operator!=(Filter const& rhs) const { return !(*this == rhs); }
178 
182  int getId() const { return _id; }
186  std::string const& getName() const { return _name; }
192  std::string const& getCanonicalName() const { return _lookup(_id); }
198  std::vector<std::string> getAliases() const;
199 
203  FilterProperty const& getFilterProperty() const;
207  static void reset() { _initRegistry(); }
215  static int define(FilterProperty const& filterProperty, int id = AUTO, bool force = false);
223  static int defineAlias(std::string const& oldName, std::string const& newName, bool force = false);
224 
228  static std::vector<std::string> getNames();
229 
230 private:
234 
238  static void _initRegistry();
245  static int _lookup(std::string const& name, bool const force = false);
249  static std::string const& _lookup(int id);
250 
251  int _id;
253 
254  static int _id0; // next Id to use
255  static AliasMap* _aliasMap; // mapping from alias -> name
256  static IdMap* _idMap; // mapping from id -> name
257  static NameMap* _nameMap; // mapping from name -> id
258 };
259 
260 namespace detail {
268 }
269 }
270 }
271 } // lsst::afw::image
272 
273 #endif // LSST_AFW_IMAGE_FILTER_H
std::string const & getCanonicalName() const
Return a filter&#39;s canonical name.
Definition: Filter.h:192
static void reset()
Clear all definitions.
Definition: Filter.h:109
table::Key< std::string > name
Definition: ApCorrMap.cc:71
bool operator!=(Filter const &rhs) const
Definition: Filter.h:177
std::string const & _name
Definition: Mask.cc:576
int getId() const
Return a Filter&#39;s integral id.
Definition: Filter.h:182
static int const UNKNOWN
Definition: Filter.h:144
bool operator==(CoordKey const &lhs, CoordKey const &rhs)
Compare CoordKeys for equality using the constituent Keys.
int stripFilterKeywords(std::shared_ptr< lsst::daf::base::PropertySet > metadata)
Remove Filter-related keywords from the metadata.
Definition: Filter.cc:123
STL class.
double getLambdaEff() const
Return the filter&#39;s effective wavelength (nm)
Definition: Filter.h:92
A base class for image defects.
int _id
Definition: Mask.cc:577
static int const AUTO
Definition: Filter.h:143
std::string const & getName() const
Return a filter&#39;s name.
Definition: Filter.h:88
Holds an integer identifier for an LSST filter.
Definition: Filter.h:141
FilterProperty(std::string const &name, double lambdaEff, bool force=false)
Definition: Filter.h:57
std::string const & getName() const
Return a Filter&#39;s name.
Definition: Filter.h:186
bool operator!=(FilterProperty const &rhs) const
Return true iff rhs != this.
Definition: Filter.h:102
Filter(int id=UNKNOWN)
Creates a Filter with the given identifier.
Definition: Filter.h:156
Filter(std::string const &name, bool const force=false)
Creates a Filter with the given name.
Definition: Filter.h:149
Describe the properties of a Filter (e.g.
Definition: Filter.h:55
static void reset()
Clear all definitions.
Definition: Filter.h:207