39using namespace std::string_literals;
46 static std::regex const unsafeCharacters(
"\\W"s);
56 return FilterLabel(hasBand, band, hasPhysical, physical);
61 : _hasBand(hasBand), _hasPhysical(hasPhysical), _band(band), _physical(physical) {
63 if (!hasBand && !hasPhysical) {
109 if (_hasBand != rhs._hasBand) {
112 if (_hasBand && _band != rhs._band) {
115 if (_hasPhysical != rhs._hasPhysical) {
118 if (_hasPhysical && _physical != rhs._physical) {
130 _hasPhysical ? _physical :
""s);
142 if (comma) buffer +=
", "s;
147 if (comma) buffer +=
", "s;
175 schema.addField<table::Flag>(schema.join(name,
"exists"),
"Existence flag for "s + name);
177 return OptionalString(existsKey, valueKey);
180 OptionalString() noexcept : _exists(), _value() {}
181 OptionalString(table::Key<table::Flag>
const &exists, table::Key<std::string>
const &value) noexcept
182 : _exists(exists), _value(value) {}
186 bool exists = record.get(_exists);
190 void set(table::BaseRecord &record, std::pair<bool, std::string>
const &value)
const override {
192 record.set(_exists,
value.first);
193 record.set(_value,
value.first ?
value.second :
""s);
196 bool operator==(OptionalString
const &other)
const noexcept {
197 return _exists == other._exists && _value == other._value;
199 bool operator!=(OptionalString
const &other)
const noexcept {
return !(*
this == other); }
201 bool isValid() const noexcept {
return _exists.isValid() && _value.isValid(); }
203 table::Key<table::Flag> getExists() const noexcept {
return _exists; }
204 table::Key<std::string> getValue() const noexcept {
return _value; }
207 table::Key<table::Flag> _exists;
208 table::Key<std::string> _value;
211struct PersistenceHelper {
212 table::Schema schema;
214 OptionalString physical;
216 static PersistenceHelper
const &get() {
217 static PersistenceHelper
const instance;
224 band(OptionalString::addFields(schema,
"band",
"Name of the band.", 32)),
225 physical(OptionalString::addFields(schema,
"physical",
"Name of the physical filter.", 32)) {}
228std::string _getPersistenceName() noexcept {
return "FilterLabel"s; }
236 PersistenceHelper
const &keys = PersistenceHelper::get();
241 record->set(keys.physical,
std::make_pair(_hasPhysical, _physical));
249 auto const &keys = PersistenceHelper::get();
256 new FilterLabel(record.
get(keys.band.getExists()), record.
get(keys.band.getValue()),
257 record.
get(keys.physical.getExists()), record.
get(keys.physical.getValue())));
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
Factory(std::string const &name)
std::shared_ptr< table::io::Persistable > read(table::io::InputArchive const &archive, table::io::CatalogVector const &catalogs) const override
Construct a new object from the given InputArchive and vector of catalogs.
A group of labels for a filter in an exposure or coadd.
std::string getBandLabel() const
Return the band label.
std::string getPersistenceName() const noexcept override
Return the unique name used to persist this object and look up its factory.
bool hasBandLabel() const noexcept
Return whether the filter label names a band.
static FilterLabel fromBand(std::string const &band)
Construct a FilterLabel from specific inputs.
std::string getPythonModule() const noexcept override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
bool hasPhysicalLabel() const noexcept
Return whether the filter label names a physical filter.
void write(table::io::OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
std::string toString() const override
Return a string representation of this object.
std::size_t hash_value() const noexcept override
Return a hash of this object.
std::shared_ptr< Storable > cloneStorable() const override
Create a new object that is a copy of this one.
std::string getPhysicalLabel() const
Return the physical filter label.
bool operator==(FilterLabel const &rhs) const noexcept
Filter labels compare equal if their components are equal.
static FilterLabel fromBandPhysical(std::string const &band, std::string const &physical)
Construct a FilterLabel from specific inputs.
FilterLabel(FilterLabel const &)
static FilterLabel fromPhysical(std::string const &physical)
Construct a FilterLabel from specific inputs.
Base class for all records.
Field< T >::Value get(Key< T > const &key) const
Return the value of a field for the given key.
Schema getSchema() const
Return the Schema that holds this record's fields and keys.
Convenience base class that combines the OutputFunctorKey and InputFunctorKey.
A class used as a handle to a particular field in a table.
Defines the fields and offsets for a table.
A vector of catalogs used by Persistable.
An object passed to Persistable::write to allow it to persist itself.
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
static std::shared_ptr< T > dynamicCast(std::shared_ptr< Persistable > const &ptr)
Dynamically cast a shared_ptr.
A base class for factory classes used to reconstruct objects from records.
PersistableFactory(std::string const &name)
Constructor for the factory.
Reports errors in the logical structure of the program.
bool operator==(const String &lhs, const String &rhs)
FilterLabel makeTestFilterLabel(bool hasBand, std::string const &band, bool hasPhysical, std::string const &physical)
std::string getDatabaseFilterLabel(std::string const &filterLabel)
Remap special characters, etc.
CatalogT< BaseRecord > BaseCatalog
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
T regex_replace(T... args)