LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
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 //
30 //
31 //##====---------------- ----------------====##/
32 
33 #ifndef LSST_AFW_IMAGE_FILTER_H
34 #define LSST_AFW_IMAGE_FILTER_H
35 
36 #include <string>
37 #include "boost/shared_ptr.hpp"
38 #include "lsst/base.h"
39 #include "lsst/tr1/unordered_map.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  boost::shared_ptr<FilterProperty> Ptr;
58  boost::shared_ptr<FilterProperty const> ConstPtr;
59 
60  explicit FilterProperty(std::string const& name, double lambdaEff, bool force=false) :
61  _name(name), _lambdaEff(lambdaEff) { _insert(force); }
62  explicit FilterProperty(
63  std::string const& name,
65  bool force=false
66  );
67  explicit FilterProperty(std::string const& name, lsst::pex::policy::Policy const& pol, bool force=false);
71  std::string const& getName() const { return _name; }
75  double getLambdaEff() const { return _lambdaEff; }
76  /*
77  * Compare two FilterProperties
78  */
79  bool operator==(FilterProperty const& rhs) const;
83  bool operator!=(FilterProperty const& rhs
84  ) const { return !(*this == rhs); }
88  static void reset() { _initRegistry(); }
89 
90  static FilterProperty const& lookup(std::string const& name);
91 private:
92  typedef std::tr1::unordered_map<std::string const, FilterProperty> PropertyMap;
93 
94  static void _initRegistry();
95  void _insert(bool force=false);
96 
97  std::string _name; // name of filter
98  double _lambdaEff; // effective wavelength (nm)
99 
100  static PropertyMap *_propertyMap; // mapping from name -> FilterProperty
101 };
102 
103 /************************************************************************************************************/
107 class Filter
108 {
109 public :
110  enum { AUTO=-1, UNKNOWN=-1 };
114  explicit Filter(std::string const& name,
115  bool const force=false
116  ) : _id(_lookup(name, force)), _name(name) {}
120  explicit Filter(int id=UNKNOWN
121  ) : _id(id), _name(_lookup(id)) {}
125  explicit Filter(CONST_PTR(lsst::daf::base::PropertySet), bool const force=false);
126 
127  /*
128  * Compare two Filters
129  */
130  bool operator==(Filter const& rhs) const;
131  bool operator!=(Filter const& rhs) const { return !(*this == rhs); }
132 
136  int getId() const { return _id; }
140  std::string const& getName() const { return _name; }
141 
142  FilterProperty const& getFilterProperty() const;
146  static void reset() { _initRegistry(); }
147  /*
148  * Define a filter
149  */
150  static int define(FilterProperty const& filterProperty, int id=AUTO, bool force=false);
151  /*
152  * Define an alias for a filter
153  */
154  static int defineAlias(std::string const& oldName, std::string const& newName, bool force=false);
155 
156  static std::vector<std::string> getNames();
157 private :
158  typedef std::tr1::unordered_map<std::string const, std::string const> AliasMap;
159  typedef std::tr1::unordered_map<std::string const, unsigned int const> NameMap;
160  typedef std::tr1::unordered_map<unsigned int const, std::string const> IdMap;
161 
162  static void _initRegistry();
163  static int _lookup(std::string const& name, bool const force=false);
164  static std::string const& _lookup(int id);
165 
166  int _id;
167  std::string _name;
168 
169  static int _id0; // next Id to use
170  static AliasMap *_aliasMap; // mapping from alias -> name
171  static IdMap *_idMap; // mapping from id -> name
172  static NameMap *_nameMap; // mapping from name -> id
173 };
174 
175 namespace detail {
177 }
178 
179 }}} // lsst::afw::image
180 
181 #endif // LSST_AFW_IMAGE_FILTER_H
std::tr1::unordered_map< std::string const, std::string const > AliasMap
Definition: Filter.h:158
table::Key< std::string > name
Definition: ApCorrMap.cc:71
bool operator==(Filter const &rhs) const
Definition: Filter.cc:205
std::tr1::unordered_map< std::string const, FilterProperty > PropertyMap
Definition: Filter.h:92
static NameMap * _nameMap
Definition: Filter.h:172
void _insert(bool force=false)
Definition: Filter.cc:75
static void _initRegistry()
Definition: Filter.cc:213
a container for holding hierarchical configuration data in memory.
Definition: Policy.h:169
boost::shared_ptr< FilterProperty > Ptr
Definition: Filter.h:57
static int _lookup(std::string const &name, bool const force=false)
Definition: Filter.cc:319
#define PTR(...)
Definition: base.h:41
static PropertyMap * _propertyMap
Definition: Filter.h:100
std::string const & getName() const
Definition: Filter.h:140
bool operator!=(Filter const &rhs) const
Definition: Filter.h:131
FilterProperty const & getFilterProperty() const
Definition: Filter.cc:365
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
std::tr1::unordered_map< unsigned int const, std::string const > IdMap
Definition: Filter.h:160
static int define(FilterProperty const &filterProperty, int id=AUTO, bool force=false)
Definition: Filter.cc:245
static FilterProperty const & lookup(std::string const &name)
Definition: Filter.cc:124
int getId() const
Definition: Filter.h:136
static int defineAlias(std::string const &oldName, std::string const &newName, bool force=false)
Definition: Filter.cc:282
bool operator!=(FilterProperty const &rhs) const
Definition: Filter.h:83
Holds an integer identifier for an LSST filter.
Definition: Filter.h:107
FilterProperty(std::string const &name, double lambdaEff, bool force=false)
Definition: Filter.h:60
boost::shared_ptr< FilterProperty const > ConstPtr
Definition: Filter.h:58
Class for storing generic metadata.
Definition: PropertySet.h:82
int id
Definition: CR.cc:151
#define CONST_PTR(...)
Definition: base.h:47
static IdMap * _idMap
Definition: Filter.h:171
static AliasMap * _aliasMap
Definition: Filter.h:170
Filter(int id=UNKNOWN)
Definition: Filter.h:120
int stripFilterKeywords(boost::shared_ptr< lsst::daf::base::PropertySet > metadata)
Definition: Filter.cc:167
std::string _name
Definition: Filter.h:167
Filter(std::string const &name, bool const force=false)
Definition: Filter.h:114
bool operator==(FilterProperty const &rhs) const
Definition: Filter.cc:102
double getLambdaEff() const
Definition: Filter.h:75
std::tr1::unordered_map< std::string const, unsigned int const > NameMap
Definition: Filter.h:159
std::string const & getName() const
Definition: Filter.h:71
static void reset()
Definition: Filter.h:146
static std::vector< std::string > getNames()
Definition: Filter.cc:184