23 #ifndef LSST_MEAS_BASE_FlagHandler_h_INCLUDED
24 #define LSST_MEAS_BASE_FlagHandler_h_INCLUDED
28 #include "lsst/afw/table/Schema.h"
29 #include "lsst/afw/table/BaseRecord.h"
32 namespace lsst {
namespace meas {
namespace base {
88 return _vector[index];
94 for (std::size_t i = 0; i <
size(); i++) {
95 if (_vector[i].name == name)
return _vector[i];
109 for (std::size_t i = 0; i <
size(); i++) {
110 if (_vector[i].name == name)
return true;
126 _vector.push_back(flagDef);
127 return _vector.back();
133 std::size_t
size()
const {
return _vector.size(); }
136 mutable std::vector<FlagDefinition> _vector;
190 static std::string name =
"flag";
210 afw::table::Schema & schema,
211 std::string
const & prefix,
229 afw::table::SubSchema
const & s,
237 for (
unsigned int i=0; i < _vector.size(); i++) {
238 if (_vector[i].first == flagName && _vector[i].second.isValid()) {
248 if (i < _vector.size() && _vector[i].second.isValid()) {
249 return _vector[i].first;
256 bool getValue(afw::table::BaseRecord
const & record, std::size_t i)
const {
257 if (i < _vector.size() && _vector[i].second.isValid()) {
258 return record.get(_vector[i].second);
265 bool getValue(afw::table::BaseRecord
const & record, std::string
const & flagName)
const {
266 for (std::size_t i = 0; i < _vector.size(); i++) {
267 if (_vector[i].first == flagName && _vector[i].second.isValid()) {
268 return record.get(_vector[i].second);
276 void setValue(afw::table::BaseRecord & record, std::size_t i,
bool value)
const {
277 if (i < _vector.size() && _vector[i].second.isValid()) {
278 record.set(_vector[i].second, value);
286 void setValue(afw::table::BaseRecord & record, std::string
const & flagName,
bool value)
const {
287 for (std::size_t i = 0; i < _vector.size(); i++) {
288 if (_vector[i].first == flagName && _vector[i].second.isValid()) {
289 record.set(_vector[i].second, value);
316 typedef std::vector< std::pair<std::string, afw::table::Key<afw::table::Flag> > > Vector;
322 #endif // !LSST_MEAS_BASE_FlagHandler_h_INCLUDED
std::string getFlagName(std::size_t i) const
Return the value of the flag name corresponding to the given flag index.
FlagDefinition getDefinition(std::size_t index) const
get a reference to the FlagDefinition with specified index.
FlagDefinition(std::string const &name, std::string const &doc, std::size_t number=number_undefined)
void setValue(afw::table::BaseRecord &record, std::string const &flagName, bool value) const
Set the flag field corresponding to the given flag name.
FlagDefinitionList()
initialize a FlagDefinition list with no entries.
unsigned int getFlagNumber(std::string const &flagName) const
Return the index of a flag with the given flag name.
bool getValue(afw::table::BaseRecord const &record, std::size_t i) const
Return the value of the flag field corresponding to the given flag index.
Simple class used to define and document flags The name and doc constitute the identity of the FlagDe...
bool hasDefinition(std::string const &name) const
See if there is a FlagDefinition with specified name.
Exception to be thrown when a measurement algorithm experiences a known failure mode.
FlagDefinition operator[](std::size_t index) const
get a reference to the FlagDefinition with specified array index
bool operator!=(FlagDefinition const &other) const
Exception to be thrown when a measurement algorithm experiences a fatal error.
FlagDefinition addFailureFlag(std::string const &doc="General Failure Flag")
Add a Flag Defintion to act as a "General" failure flag This flag will be set if a Measurement error ...
bool getValue(afw::table::BaseRecord const &record, std::string const &flagName) const
Return the value of the flag field with the given flag name.
static constexpr std::size_t number_undefined
Utility class for handling flag fields that indicate the failure modes of an algorithm.
std::size_t failureFlagNumber
FlagHandler()
Each error should have a corresponding static FlagDefinition object.
static FlagDefinitionList const & getEmptyList()
FlagDefinitionList(std::initializer_list< FlagDefinition > const &list)
initialize a FlagDefinition list from initializer_list.
FlagDefinition add(std::string const &name, std::string const &doc)
Add a new FlagDefinition to this list.
void setValue(afw::table::BaseRecord &record, std::size_t i, bool value) const
Set the flag field corresponding to the given flag index.
bool operator==(FlagDefinition const &other) const
void handleFailure(afw::table::BaseRecord &record, MeasurementError const *error=nullptr) const
Handle an expected or unexpected Exception thrown by a measurement algorithm.
static FlagHandler addFields(afw::table::Schema &schema, std::string const &prefix, FlagDefinitionList const &flagDefs, FlagDefinitionList const &exclDefs=FlagDefinitionList::getEmptyList())
Add Flag fields to a schema, creating a FlagHandler object to manage them.
static std::string const & getFailureFlagName()
Define the universal name of the general failure flag.
vector-type utility class to build a collection of FlagDefinitions
std::size_t size() const
return the current size (number of defined elements) of the collection
FlagDefinition getDefinition(std::string const &name) const
get a reference to the FlagDefinition with specified name.
std::size_t getFailureFlagNumber() const
Get the index of the General Failure flag, if one is defined.