lsst.afw  20.0.0-13-gad96b2d30+614f89f815
FilterLabel.h
Go to the documentation of this file.
1 /*
2  * This file is part of afw.
3  *
4  * Developed for the LSST Data Management System.
5  * This product includes software developed by the LSST Project
6  * (https://www.lsst.org).
7  * See the COPYRIGHT file at the top-level directory of this distribution
8  * for details of code ownership.
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 GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef LSST_AFW_IMAGE_FILTERLABEL_H
25 #define LSST_AFW_IMAGE_FILTERLABEL_H
26 
27 #include <memory>
28 #include <string>
29 
30 #include "lsst/afw/table/io/Persistable.h" // Needed for PersistableFacade
32 
33 namespace lsst {
34 namespace afw {
35 namespace image {
36 
37 #ifndef DOXYGEN
38 class FilterLabel;
39 namespace impl {
40 // Needed for some esoteric tests; do not use elsewhere!
41 FilterLabel makeTestFilterLabel(bool, std::string const &, bool, std::string const &);
42 } // namespace impl
43 #endif
44 
55 class FilterLabel final : public table::io::PersistableFacade<FilterLabel>, public typehandling::Storable {
56 public:
63  static FilterLabel fromBand(std::string const &band);
68  FilterLabel(FilterLabel &&) noexcept;
69  FilterLabel &operator=(FilterLabel const &); // Only way to modify a FilterLabel
70  FilterLabel &operator=(FilterLabel &&) noexcept;
71  ~FilterLabel() noexcept;
72 
74  bool hasBandLabel() const noexcept;
75 
82  std::string getBandLabel() const;
83 
85  bool hasPhysicalLabel() const noexcept;
86 
93  std::string getPhysicalLabel() const;
94 
104  bool operator==(FilterLabel const &rhs) const noexcept;
105  bool operator!=(FilterLabel const &rhs) const noexcept { return !(*this == rhs); }
108  // Storable support
109 
111  std::size_t hash_value() const noexcept override;
113  std::string toString() const override;
115  std::shared_ptr<Storable> cloneStorable() const override;
116  bool equals(Storable const &other) const noexcept override { return singleClassEquals(*this, other); }
117 
118  // Persistable support
119 
121  bool isPersistable() const noexcept override { return true; }
122 
123 protected:
124  // Persistable support
125 
126  std::string getPersistenceName() const noexcept override;
127  std::string getPythonModule() const noexcept override;
128  void write(table::io::OutputArchiveHandle &handle) const override;
129 
130 private:
131  FilterLabel(bool hasBand, std::string const &band, bool hasPhysical, std::string const &physical);
132 #ifndef DOXYGEN
133  // Needed for some esoteric tests; do not use elsewhere!
134  friend FilterLabel impl::makeTestFilterLabel(bool, std::string const &, bool, std::string const &);
135 #endif
136 
137  // A separate boolean leads to easier implementations (at the cost of more
138  // memory) than a unique_ptr<string>.
139  // _band and _physical are part of the object state iff _hasBand and _hasPhysical, respectively
140  bool _hasBand, _hasPhysical;
141  std::string _band, _physical;
142 
143  // Persistable support
144 
145  class Factory;
146  static Factory factory;
147 };
148 
155 
156 } // namespace image
157 } // namespace afw
158 } // namespace lsst
159 
160 namespace std {
161 template <>
162 struct hash<lsst::afw::image::FilterLabel> {
165  size_t operator()(argument_type const &obj) const noexcept { return obj.hash_value(); }
166 };
167 } // namespace std
168 
169 #endif
lsst::afw::image::FilterLabel::hasPhysicalLabel
bool hasPhysicalLabel() const noexcept
Return whether the filter label names a physical filter.
Definition: FilterLabel.cc:91
lsst::afw::image
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
Definition: imageAlgorithm.dox:1
lsst::afw::image::FilterLabel::fromPhysical
static FilterLabel fromPhysical(std::string const &physical)
Construct a FilterLabel from specific inputs.
Definition: FilterLabel.cc:69
std::string
STL class.
lsst::afw::image::FilterLabel::write
void write(table::io::OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
Definition: FilterLabel.cc:230
std::hash< lsst::afw::image::FilterLabel >::operator()
size_t operator()(argument_type const &obj) const noexcept
Definition: FilterLabel.h:165
lsst::afw::image::FilterLabel::equals
bool equals(Storable const &other) const noexcept override
Definition: FilterLabel.h:116
lsst::afw::image::FilterLabel::getPhysicalLabel
std::string getPhysicalLabel() const
Return the physical filter label.
Definition: FilterLabel.cc:93
lsst::afw::typehandling::Storable
Interface supporting iteration over heterogenous containers.
Definition: Storable.h:58
lsst::afw::image::FilterLabel::getPersistenceName
std::string getPersistenceName() const noexcept override
Return the unique name used to persist this object and look up its factory.
Definition: FilterLabel.cc:227
Persistable.h
lsst::afw::image::FilterLabel::FilterLabel
FilterLabel(FilterLabel const &)
lsst::afw::image::getDatabaseFilterLabel
std::string getDatabaseFilterLabel(std::string const &filterLabel)
Remap special characters, etc.
Definition: FilterLabel.cc:45
physical
OptionalString physical
Definition: FilterLabel.cc:209
lsst::afw::image::FilterLabel::cloneStorable
std::shared_ptr< Storable > cloneStorable() const override
Create a new object that is a copy of this one.
Definition: FilterLabel.cc:151
other
ItemVariant const * other
Definition: Schema.cc:56
Storable.h
lsst::afw::image::FilterLabel::hasBandLabel
bool hasBandLabel() const noexcept
Return whether the filter label names a band.
Definition: FilterLabel.cc:80
lsst::afw::image::FilterLabel
A group of labels for a filter in an exposure or coadd.
Definition: FilterLabel.h:55
lsst
A base class for image defects.
lsst::afw::image::FilterLabel::getPythonModule
std::string getPythonModule() const noexcept override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
Definition: FilterLabel.cc:228
lsst::afw::image::impl::makeTestFilterLabel
FilterLabel makeTestFilterLabel(bool hasBand, std::string const &band, bool hasPhysical, std::string const &physical)
Definition: FilterLabel.cc:53
lsst::afw::image::FilterLabel::fromBandPhysical
static FilterLabel fromBandPhysical(std::string const &band, std::string const &physical)
Construct a FilterLabel from specific inputs.
Definition: FilterLabel.cc:63
lsst::afw::image::FilterLabel::getBandLabel
std::string getBandLabel() const
Return the band label.
Definition: FilterLabel.cc:82
lsst::afw::image::FilterLabel::isPersistable
bool isPersistable() const noexcept override
All filter labels are always persistable.
Definition: FilterLabel.h:121
lsst::afw::image::FilterLabel::hash_value
std::size_t hash_value() const noexcept override
Return a hash of this object.
Definition: FilterLabel.cc:121
lsst::afw::image.slicing.Factory
Factory
Definition: slicing.py:252
std
STL namespace.
lsst::afw::table::io::PersistableFacade
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:176
lsst::afw::image::FilterLabel::toString
std::string toString() const override
Return a string representation of this object.
Definition: FilterLabel.cc:132
band
OptionalString band
Definition: FilterLabel.cc:208
lsst::afw::image::FilterLabel::fromBand
static FilterLabel fromBand(std::string const &band)
Construct a FilterLabel from specific inputs.
Definition: FilterLabel.cc:67
std::size_t
lsst::afw::table::io::Persistable::OutputArchiveHandle
io::OutputArchiveHandle OutputArchiveHandle
Definition: Persistable.h:108
lsst::afw::typehandling::Storable::singleClassEquals
static bool singleClassEquals(T const &lhs, Storable const &rhs)
Test if a Storable is of a particular class and equal to another object.
Definition: Storable.h:151
std::hash
lsst::afw::image::FilterLabel::FilterLabel
FilterLabel(FilterLabel &&) noexcept