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
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
lsst::afw::image::Filter Class Reference

Holds an integer identifier for an LSST filter. More...

#include <Filter.h>

Public Types

enum  { AUTO =-1, UNKNOWN =-1 }
 

Public Member Functions

 Filter (std::string const &name, bool const force=false)
 
 Filter (int id=UNKNOWN)
 
 Filter (boost::shared_ptr< lsst::daf::base::PropertySet const >, bool const force=false)
 
bool operator== (Filter const &rhs) const
 
bool operator!= (Filter const &rhs) const
 
int getId () const
 
std::string const & getName () const
 
FilterProperty const & getFilterProperty () const
 

Static Public Member Functions

static void reset ()
 
static int define (FilterProperty const &filterProperty, int id=AUTO, bool force=false)
 
static int defineAlias (std::string const &oldName, std::string const &newName, bool force=false)
 
static std::vector< std::string > getNames ()
 

Private Types

typedef
std::tr1::unordered_map
< std::string const,
std::string const > 
AliasMap
 
typedef
std::tr1::unordered_map
< std::string const, unsigned
int const > 
NameMap
 
typedef
std::tr1::unordered_map
< unsigned int const,
std::string const > 
IdMap
 

Static Private Member Functions

static void _initRegistry ()
 
static int _lookup (std::string const &name, bool const force=false)
 
static std::string const & _lookup (int id)
 

Private Attributes

int _id
 
std::string _name
 

Static Private Attributes

static int _id0 = Filter::UNKNOWN
 
static AliasMap_aliasMap = NULL
 
static IdMap_idMap = NULL
 
static NameMap_nameMap = NULL
 

Detailed Description

Holds an integer identifier for an LSST filter.

Definition at line 107 of file Filter.h.

Member Typedef Documentation

typedef std::tr1::unordered_map<std::string const, std::string const> lsst::afw::image::Filter::AliasMap
private

Definition at line 158 of file Filter.h.

typedef std::tr1::unordered_map<unsigned int const, std::string const> lsst::afw::image::Filter::IdMap
private

Definition at line 160 of file Filter.h.

typedef std::tr1::unordered_map<std::string const, unsigned int const> lsst::afw::image::Filter::NameMap
private

Definition at line 159 of file Filter.h.

Member Enumeration Documentation

anonymous enum
Enumerator
AUTO 
UNKNOWN 

Definition at line 110 of file Filter.h.

Constructor & Destructor Documentation

lsst::afw::image::Filter::Filter ( std::string const &  name,
bool const  force = false 
)
inlineexplicit

Creates a Filter with the given name

Parameters
nameName of filter
forceAllow us to construct an unknown Filter

Definition at line 114 of file Filter.h.

116  : _id(_lookup(name, force)), _name(name) {}
table::Key< std::string > name
Definition: ApCorrMap.cc:71
static int _lookup(std::string const &name, bool const force=false)
Definition: Filter.cc:319
std::string _name
Definition: Filter.h:167
lsst::afw::image::Filter::Filter ( int  id = UNKNOWN)
inlineexplicit

Creates a Filter with the given identifier

Parameters
idId number of desired filter

Definition at line 120 of file Filter.h.

121  : _id(id), _name(_lookup(id)) {}
static int _lookup(std::string const &name, bool const force=false)
Definition: Filter.cc:319
std::string _name
Definition: Filter.h:167
lsst::afw::image::Filter::Filter ( boost::shared_ptr< lsst::daf::base::PropertySet const >  metadata,
bool const  force = false 
)
explicit

Create a Filter from a PropertySet (e.g. a FITS header)

Parameters
metadataMetadata to process (e.g. a IFITS header)
forceAllow us to construct an unknown Filter

Definition at line 149 of file Filter.cc.

152 {
153  std::string const key = "FILTER";
154  if( metadata->exists(key) ) {
155  std::string filterName = boost::algorithm::trim_right_copy(metadata->getAsString(key));
156  _id = _lookup(filterName, force);
157  _name = filterName;
158  }
159 }
static int _lookup(std::string const &name, bool const force=false)
Definition: Filter.cc:319
std::string _name
Definition: Filter.h:167

Member Function Documentation

void lsst::afw::image::Filter::_initRegistry ( )
staticprivate

Initialise the Filter registry

Definition at line 213 of file Filter.cc.

214 {
215  _id0 = UNKNOWN;
216  delete _aliasMap;
217  delete _nameMap;
218  delete _idMap;
219 
220  _aliasMap = new AliasMap;
221  _nameMap = new NameMap;
222  _idMap = new IdMap;
223 
224  define(FilterProperty(unknownFilter, lsst::pex::policy::Policy(), true));
225 }
std::tr1::unordered_map< std::string const, std::string const > AliasMap
Definition: Filter.h:158
static NameMap * _nameMap
Definition: Filter.h:172
a container for holding hierarchical configuration data in memory.
Definition: Policy.h:169
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 IdMap * _idMap
Definition: Filter.h:171
static AliasMap * _aliasMap
Definition: Filter.h:170
std::tr1::unordered_map< std::string const, unsigned int const > NameMap
Definition: Filter.h:159
int lsst::afw::image::Filter::_lookup ( std::string const &  name,
bool const  force = false 
)
staticprivate

Lookup the ID associated with a name

Definition at line 319 of file Filter.cc.

322 {
323  if (!_nameMap) {
324  _initRegistry();
325  }
326 
327  NameMap::iterator keyVal = _nameMap->find(name);
328 
329  if (keyVal == _nameMap->end()) {
330  AliasMap::iterator aliasKeyVal = _aliasMap->find(name);
331  if (aliasKeyVal != _aliasMap->end()) {
332  return _lookup(aliasKeyVal->second);
333  }
334 
335  if (force) {
336  return UNKNOWN;
337  } else {
338  throw LSST_EXCEPT(pexEx::NotFoundError, "Unable to find filter " + name);
339  }
340  }
341 
342  return keyVal->second;
343 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
static NameMap * _nameMap
Definition: Filter.h:172
static void _initRegistry()
Definition: Filter.cc:213
static int _lookup(std::string const &name, bool const force=false)
Definition: Filter.cc:319
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
static AliasMap * _aliasMap
Definition: Filter.h:170
std::string const & lsst::afw::image::Filter::_lookup ( int  id)
staticprivate

Lookup the name associated with an ID

Definition at line 348 of file Filter.cc.

349 {
350  if (!_idMap) {
351  _initRegistry();
352  }
353 
354  IdMap::iterator keyVal = _idMap->find(id);
355 
356  if (keyVal == _idMap->end()) {
357  throw LSST_EXCEPT(pexEx::NotFoundError, (boost::format("Unable to find filter %d") % id).str());
358  }
359 
360  return keyVal->second;
361 }
static void _initRegistry()
Definition: Filter.cc:213
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
static IdMap * _idMap
Definition: Filter.h:171
int lsst::afw::image::Filter::define ( FilterProperty const &  fp,
int  id = AUTO,
bool  force = false 
)
static

Define a filter name to have the specified id

If id == Filter::AUTO a value will be chosen for you.

It is an error to attempt to change a name's id (unless you specify force)

Definition at line 245 of file Filter.cc.

246 {
247  if (!_nameMap) {
248  _initRegistry();
249  }
250 
251  std::string const& name = fp.getName();
252  NameMap::iterator keyVal = _nameMap->find(name);
253 
254  if (keyVal != _nameMap->end()) {
255  int oid = keyVal->second;
256 
257  if (id == oid || id == AUTO) {
258  return oid; // OK, same value as before
259  }
260 
261  if (!force) {
262  throw LSST_EXCEPT(pexEx::RuntimeError, "Filter " + name + " is already defined");
263  }
264  _nameMap->erase(keyVal);
265  _idMap->erase(oid);
266  }
267 
268  if (id == AUTO) {
269  id = _id0;
270  ++_id0;
271  }
272 
273  _nameMap->insert(std::make_pair(name, id));
274  _idMap->insert(std::make_pair(id, name));
275 
276  return id;
277 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
static NameMap * _nameMap
Definition: Filter.h:172
static void _initRegistry()
Definition: Filter.cc:213
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
int id
Definition: CR.cc:151
static IdMap * _idMap
Definition: Filter.h:171
int lsst::afw::image::Filter::defineAlias ( std::string const &  oldName,
std::string const &  newName,
bool  force = false 
)
static

Define an alias for a filter

Parameters
oldNameold name for Filter
newNamenew name for Filter
forceforce an alias even if newName is already in use

Definition at line 282 of file Filter.cc.

286 {
287  if (!_nameMap) {
288  _initRegistry();
289  }
290 
291  // Lookup oldName
292  NameMap::iterator keyVal = _nameMap->find(oldName);
293  if (keyVal == _nameMap->end()) {
294  throw LSST_EXCEPT(pexEx::NotFoundError, "Unable to find filter " + oldName);
295  }
296  int const id = keyVal->second;
297 
298  // Lookup oldName in aliasMap
299  AliasMap::iterator aliasKeyVal = _aliasMap->find(newName);
300  if (aliasKeyVal != _aliasMap->end()) {
301  if (aliasKeyVal->second == oldName) {
302  return id; // OK, same value as before
303  }
304 
305  if (!force) {
306  throw LSST_EXCEPT(pexEx::NotFoundError, "Filter " + newName + " is already defined");
307  }
308  _aliasMap->erase(aliasKeyVal);
309  }
310 
311  _aliasMap->insert(std::make_pair(newName, oldName));
312 
313  return id;
314 }
static NameMap * _nameMap
Definition: Filter.h:172
static void _initRegistry()
Definition: Filter.cc:213
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
int id
Definition: CR.cc:151
static AliasMap * _aliasMap
Definition: Filter.h:170
FilterProperty const & lsst::afw::image::Filter::getFilterProperty ( ) const

Return a Filter's FilterProperty

Definition at line 365 of file Filter.cc.

365  {
366  //
367  // Map name to its ID and back to resolve aliases
368  //
369  int const id = _lookup(_name, true);
370  std::string const& name = (id == UNKNOWN) ? _name : _lookup(id);
371 
372  return FilterProperty::lookup(name);
373 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
static int _lookup(std::string const &name, bool const force=false)
Definition: Filter.cc:319
static FilterProperty const & lookup(std::string const &name)
Definition: Filter.cc:124
std::string _name
Definition: Filter.h:167
int lsst::afw::image::Filter::getId ( ) const
inline

Return a Filter's integral id

Definition at line 136 of file Filter.h.

136 { return _id; }
std::string const& lsst::afw::image::Filter::getName ( ) const
inline

Return a Filter's name

Definition at line 140 of file Filter.h.

140 { return _name; }
std::string _name
Definition: Filter.h:167
std::vector< std::string > lsst::afw::image::Filter::getNames ( )
static

Return a list of known filters

Definition at line 184 of file Filter.cc.

185 {
186  if (!_nameMap) {
187  _initRegistry();
188  }
189 
190  std::vector<std::string> names;
191 
192  for (NameMap::const_iterator ptr = _nameMap->begin(), end = _nameMap->end(); ptr != end; ++ptr) {
193  if (ptr->first != unknownFilter) {
194  names.push_back(ptr->first);
195  }
196  }
197  std::sort(names.begin(), names.end());
198 
199  return names;
200 }
static NameMap * _nameMap
Definition: Filter.h:172
static void _initRegistry()
Definition: Filter.cc:213
bool lsst::afw::image::Filter::operator!= ( Filter const &  rhs) const
inline

Definition at line 131 of file Filter.h.

131 { return !(*this == rhs); }
bool lsst::afw::image::Filter::operator== ( Filter const &  rhs) const

Are two filters identical?

Definition at line 205 of file Filter.cc.

205  {
206  return _id != UNKNOWN && _id == rhs._id;
207 }
static void lsst::afw::image::Filter::reset ( )
inlinestatic

Clear all definitions

Definition at line 146 of file Filter.h.

146 { _initRegistry(); }
static void _initRegistry()
Definition: Filter.cc:213

Member Data Documentation

Filter::AliasMap * lsst::afw::image::Filter::_aliasMap = NULL
staticprivate

Definition at line 170 of file Filter.h.

int lsst::afw::image::Filter::_id
private

Definition at line 166 of file Filter.h.

int lsst::afw::image::Filter::_id0 = Filter::UNKNOWN
staticprivate

Definition at line 169 of file Filter.h.

Filter::IdMap * lsst::afw::image::Filter::_idMap = NULL
staticprivate

Definition at line 171 of file Filter.h.

std::string lsst::afw::image::Filter::_name
private

Definition at line 167 of file Filter.h.

Filter::NameMap * lsst::afw::image::Filter::_nameMap = NULL
staticprivate

Definition at line 172 of file Filter.h.


The documentation for this class was generated from the following files: