LSST Applications g02d81e74bb+86cf3d8bc9,g180d380827+7a4e862ed4,g2079a07aa2+86d27d4dc4,g2305ad1205+e1ca1c66fa,g29320951ab+012e1474a1,g295015adf3+341ea1ce94,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g33d1c0ed96+0e5473021a,g3a166c0a6a+0e5473021a,g3ddfee87b4+c429d67c83,g48712c4677+f88676dd22,g487adcacf7+27e1e21933,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+b41db86c35,g5a732f18d5+53520f316c,g64a986408d+86cf3d8bc9,g858d7b2824+86cf3d8bc9,g8a8a8dda67+585e252eca,g99cad8db69+84912a7fdc,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+a2b54eae19,gb0e22166c9+60f28cb32d,gba4ed39666+c2a2e4ac27,gbb8dafda3b+6681f309db,gc120e1dc64+f0fcc2f6d8,gc28159a63d+0e5473021a,gcf0d15dbbd+c429d67c83,gdaeeff99f8+f9a426f77a,ge6526c86ff+0433e6603d,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gff1a9f87cc+86cf3d8bc9,w.2024.17
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
lsst::meas::base::FlagHandler Class Reference

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

#include <FlagHandler.h>

Public Member Functions

 FlagHandler ()
 Each error should have a corresponding static FlagDefinition object.
 
 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.
 
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.
 
void handleFailure (afw::table::BaseRecord &record, MeasurementError const *error=nullptr) const
 Handle an expected or unexpected Exception thrown by a measurement algorithm.
 

Static Public Member 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.
 

Public Attributes

std::size_t failureFlagNumber
 

Detailed Description

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

The typical pattern for using FlagHandler within an Algorithm is:

See PsfFluxAlgorithm for a complete example.

Definition at line 149 of file FlagHandler.h.

Constructor & Destructor Documentation

◆ FlagHandler() [1/2]

lsst::meas::base::FlagHandler::FlagHandler ( )
inline

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.

Definition at line 177 of file FlagHandler.h.

◆ FlagHandler() [2/2]

lsst::meas::base::FlagHandler::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.

Parameters
[in]ASubSchema object that holds the fields to extract and their namespace. Obtainable from the arguments to addFields() as "schema[prefix]".
[in]flagDefsReference to a FlagDefinitionList
[in]exclDefsoptional FlagDefinitionList of flags to exclude

As with addFields(), pointers must be valid only for the duration of this constructor call.

Definition at line 68 of file FlagHandler.cc.

71 _vector.reserve(flagDefs.size());
72 for (std::size_t i = 0; i < flagDefs.size(); i++) {
73 FlagDefinition const& flagDef = flagDefs[i];
74 if (exclDefs.hasDefinition(flagDef.name)) {
75 afw::table::Key<afw::table::Flag> key;
76 _vector.push_back(std::make_pair(flagDef.name, key));
77 } else {
78 _vector.push_back(std::make_pair(flagDef.name, s[flagDef.name]));
79 if (flagDef.name == FlagHandler::getFailureFlagName()) {
81 }
82 }
83 }
84}
static std::string const & getFailureFlagName()
Define the universal name of the general failure flag.
T make_pair(T... args)
T push_back(T... args)
T reserve(T... args)

Member Function Documentation

◆ addFields()

FlagHandler lsst::meas::base::FlagHandler::addFields ( afw::table::Schema & schema,
std::string const & prefix,
FlagDefinitionList const & flagDefs,
FlagDefinitionList const & exclDefs = FlagDefinitionList::getEmptyList() )
static

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.

Parameters
[out]schemaSchema to which fields should be added.
[in]prefixString 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]flagDefsReference to a FlagDefinitionList
[in]exclDefsoptional FlagDefinitionList of flags to exclude

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})

Definition at line 47 of file FlagHandler.cc.

48 {
50 r._vector.reserve(flagDefs.size());
51 for (std::size_t i = 0; i < flagDefs.size(); i++) {
52 FlagDefinition const& flagDef = flagDefs[i];
53 if (exclDefs.hasDefinition(flagDef.name)) {
54 afw::table::Key<afw::table::Flag> key;
55 r._vector.push_back(std::make_pair(flagDef.name, key));
56 } else {
57 afw::table::Key<afw::table::Flag> key(
58 schema.addField<afw::table::Flag>(schema.join(prefix, flagDef.name), flagDef.doc));
59 r._vector.push_back(std::make_pair(flagDef.name, key));
60 if (flagDef.name == FlagHandler::getFailureFlagName()) {
61 r.failureFlagNumber = i;
62 }
63 }
64 }
65 return r;
66}
std::string prefix
FlagHandler()
Each error should have a corresponding static FlagDefinition object.

◆ getFailureFlagName()

static std::string const & lsst::meas::base::FlagHandler::getFailureFlagName ( )
inlinestatic

Define the universal name of the general failure flag.

Definition at line 182 of file FlagHandler.h.

182 {
183 static std::string name = "flag";
184 return name;
185 }
table::Key< std::string > name
Definition Amplifier.cc:116

◆ getFailureFlagNumber()

std::size_t lsst::meas::base::FlagHandler::getFailureFlagNumber ( ) const
inline

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

Definition at line 287 of file FlagHandler.h.

287{ return failureFlagNumber; }

◆ getFlagName()

std::string lsst::meas::base::FlagHandler::getFlagName ( std::size_t i) const
inline

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

Definition at line 234 of file FlagHandler.h.

234 {
235 if (i < _vector.size() && _vector[i].second.isValid()) {
236 return _vector[i].first;
237 }
238 throw FatalAlgorithmError("No legal FlagHandler entry number " + std::to_string(i));
239 }
T size(T... args)
T to_string(T... args)

◆ getFlagNumber()

unsigned int lsst::meas::base::FlagHandler::getFlagNumber ( std::string const & flagName) const
inline

Return the index of a flag with the given flag name.

Definition at line 223 of file FlagHandler.h.

223 {
224 for (unsigned int i = 0; i < _vector.size(); i++) {
225 if (_vector[i].first == flagName && _vector[i].second.isValid()) {
226 return i;
227 }
228 }
229 throw FatalAlgorithmError("No FlagHandler entry for " + flagName);
230 }

◆ getValue() [1/2]

bool lsst::meas::base::FlagHandler::getValue ( afw::table::BaseRecord const & record,
std::size_t i ) const
inline

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

Definition at line 243 of file FlagHandler.h.

243 {
244 if (i < _vector.size() && _vector[i].second.isValid()) {
245 return record.get(_vector[i].second);
246 }
247 throw FatalAlgorithmError("No legal FlagHandler entry number " + std::to_string(i));
248 }

◆ getValue() [2/2]

bool lsst::meas::base::FlagHandler::getValue ( afw::table::BaseRecord const & record,
std::string const & flagName ) const
inline

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

Definition at line 252 of file FlagHandler.h.

252 {
253 for (std::size_t i = 0; i < _vector.size(); i++) {
254 if (_vector[i].first == flagName && _vector[i].second.isValid()) {
255 return record.get(_vector[i].second);
256 }
257 }
258 throw FatalAlgorithmError("No FlagHandler entry for " + flagName);
259 }

◆ handleFailure()

void lsst::meas::base::FlagHandler::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).

Definition at line 86 of file FlagHandler.cc.

86 {
87 std::size_t const numFlags = _vector.size();
89 record.set(_vector[failureFlagNumber].second, true);
90 }
91 if (error && error->getFlagBit() != FlagDefinition::number_undefined) {
92 assert(numFlags > error->getFlagBit()); // We need the particular flag
93 record.set(_vector[error->getFlagBit()].second, true);
94 }
95}

◆ setValue() [1/2]

void lsst::meas::base::FlagHandler::setValue ( afw::table::BaseRecord & record,
std::size_t i,
bool value ) const
inline

Set the flag field corresponding to the given flag index.

Definition at line 263 of file FlagHandler.h.

263 {
264 if (i < _vector.size() && _vector[i].second.isValid()) {
265 record.set(_vector[i].second, value);
266 return;
267 }
268 throw FatalAlgorithmError("No legal FlagHandler entry number " + std::to_string(i));
269 }

◆ setValue() [2/2]

void lsst::meas::base::FlagHandler::setValue ( afw::table::BaseRecord & record,
std::string const & flagName,
bool value ) const
inline

Set the flag field corresponding to the given flag name.

Definition at line 273 of file FlagHandler.h.

273 {
274 for (std::size_t i = 0; i < _vector.size(); i++) {
275 if (_vector[i].first == flagName && _vector[i].second.isValid()) {
276 record.set(_vector[i].second, value);
277 return;
278 }
279 }
280 throw FatalAlgorithmError("No FlagHandler entry for " + flagName);
281 }

Member Data Documentation

◆ failureFlagNumber

std::size_t lsst::meas::base::FlagHandler::failureFlagNumber

Definition at line 298 of file FlagHandler.h.


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