Class FlagHandler

Class Documentation

class FlagHandler

Utility class for handling flag fields that indicate the failure modes of an algorithm.

The typical pattern for using FlagHandler within an Algorithm is:

  • Add a FlagHandler object as a data member.

  • Create a FlagDefinitionList to specify the name and doc for each flag Add a “general” failure flag if one is needed (this indicates that some failure occurred). Add specific error flags for each type of error (these indicate a specific failure).

  • Initialize the FlagHandler data member within the Algorithm’s constructor, using the static addFields method to add the flags from the FlagDefinitionList to the schema.

See PsfFluxAlgorithm for a complete example.

Public Functions

FlagHandler()

Each error should have a corresponding static FlagDefinition object. In the Algorithm header file, this will be defined like this:

static FlagDefinition const & FAILURE;
static FlagDefinition const & SOME_OTHER_FAILURE_MODE;
    ...

A static FlagDefinitionList is created in the Algorithm .cc file, like this:

FlagDefinitionList flagDefinitions;
FlagDefinition const FAILURE = flagDefinitions.addFailureFlag();
FlagDefinition const FAILURE_MODE = flagDefinitions.add("flag_mode", "Specific failure flag");
Default constructor for delayed initialization.

This constructor creates an invalid, unusable FlagHandler in the same way a const_iterator default constructor constructs an invalid const_iterator. Its only purpose is to delay construction of the FlagHandler from an Algorithm constructor’s initializer list to the constructor body, which can be necessary when the list of possible flags depends on the algorithm’s configuration. To use this constructor to delay initialization, simply use it in the initializer list, and then assign the result of a call to addFields() to the FlagHandler data member later in the constructor.

FlagHandler(afw::table::SubSchema const &s, FlagDefinitionList const &flagDefs, FlagDefinitionList const &exclDefs = FlagDefinitionList::getEmptyList())

Construct a FlagHandler to manage fields already added to a schema.

This is primarily intended for use by forced measurement algorithms that need to parse the flags of the single-frame measurement algorithms providing their reference parameters.

As with

addFields(), pointers must be valid only for the duration of this constructor call.
Parameters
  • [in] A: SubSchema object that holds the fields to extract and their namespace. Obtainable from the arguments to addFields() as “schema[prefix]”.

  • [in] flagDefs: Reference to a FlagDefinitionList

  • [in] exclDefs: optional FlagDefinitionList of flags to exclude

unsigned int getFlagNumber(std::string const &flagName) const

Return the index of a flag with the given flag name

std::string getFlagName(std::size_t i) const

Return the value of the flag name corresponding to the given flag index.

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.

bool getValue(afw::table::BaseRecord const &record, std::string const &flagName) const

Return the value of the flag field with the given flag name

void setValue(afw::table::BaseRecord &record, std::size_t i, bool value) const

Set the flag field corresponding to the given flag index.

void setValue(afw::table::BaseRecord &record, std::string const &flagName, bool value) const

Set the flag field corresponding to the given flag name.

std::size_t getFailureFlagNumber() const

Get the index of the General Failure flag, if one is defined. This flag is defined by most algorithms, and if defined, is set whenever an error is caught by the FlagHandler. If no General Failure flag is defined, this routine will return FlagDefinition::number_undefined

void handleFailure(afw::table::BaseRecord &record, MeasurementError const *error = nullptr) const

Handle an expected or unexpected Exception thrown by a measurement algorithm.

If the exception is expected, it should inherit from MeasurementError and can be passed here; this allows handleFailure to extract the failure mode enum value from the exception and set the corresponding flag. The general failure flag will be set regardless of whether the “error” argument is nullptr (which happens when an unexpected error occurs).

Public Members

std::size_t failureFlagNumber

Public Static Functions

static std::string const &getFailureFlagName()

Define the universal name of the general failure flag

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.

This is the way FlagHandlers will typically be constructed for new algorithms.

If the set of flags depends on the algorithm configuration, a flag may be excluded from the schema using the optional exclDefs parameter. This can be specified using an initializer_list, as in: _flagHandler =

FlagHandler::addFields(schema, prefix, flagDefs, {NO_PSF})
Parameters
  • [out] schema: Schema to which fields should be added.

  • [in] prefix: String name of the algorithm or algorithm component. Field names will be constructed by using schema.join() on this and the flag name from the FlagDefinition array.

  • [in] flagDefs: Reference to a FlagDefinitionList

  • [in] exclDefs: optional FlagDefinitionList of flags to exclude