LSSTApplications  19.0.0-10-g920eed2,19.0.0-11-g48a0200+2,19.0.0-18-gfc4e62b+11,19.0.0-2-g3b2f90d+2,19.0.0-2-gd671419+5,19.0.0-20-g5a5a17ab+9,19.0.0-21-g2644856+11,19.0.0-22-gc5dc5b1+6,19.0.0-23-gdc29a50+3,19.0.0-24-g923e380+11,19.0.0-25-g6c8df7140,19.0.0-28-g9b887e2,19.0.0-3-g2b32d65+5,19.0.0-3-g8227491+10,19.0.0-3-g9c54d0d+10,19.0.0-3-gca68e65+6,19.0.0-3-gcfc5f51+5,19.0.0-3-ge110943+9,19.0.0-3-ge74d124,19.0.0-3-gfe04aa6+11,19.0.0-4-g06f5963+5,19.0.0-4-g3d16501+11,19.0.0-4-g4a9c019+5,19.0.0-4-g5a8b323,19.0.0-4-g66397f0+1,19.0.0-4-g8278b9b+1,19.0.0-4-g8557e14,19.0.0-4-g8964aba+11,19.0.0-4-ge404a01+10,19.0.0-5-g40f3a5a,19.0.0-5-g4db63b3,19.0.0-5-gfb03ce7+11,19.0.0-6-gbaebbfb+10,19.0.0-60-gafafd468+11,19.0.0-67-g3ab1e6e,19.0.0-7-g039c0b5+9,19.0.0-7-gbea9075+4,19.0.0-7-gc567de5+11,19.0.0-8-g3a3ce09+6,19.0.0-9-g463f923+10,w.2020.21
LSSTDataManagementBasePackage
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. More...
 
 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. More...
 
unsigned int getFlagNumber (std::string const &flagName) const
 Return the index of a flag with the given flag name. More...
 
std::string getFlagName (std::size_t i) const
 Return the value of the flag name corresponding to the given flag index. More...
 
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. More...
 
bool getValue (afw::table::BaseRecord const &record, std::string const &flagName) const
 Return the value of the flag field with the given flag name. More...
 
void setValue (afw::table::BaseRecord &record, std::size_t i, bool value) const
 Set the flag field corresponding to the given flag index. More...
 
void setValue (afw::table::BaseRecord &record, std::string const &flagName, bool value) const
 Set the flag field corresponding to the given flag name. More...
 
std::size_t getFailureFlagNumber () const
 Get the index of the General Failure flag, if one is defined. More...
 
void handleFailure (afw::table::BaseRecord &record, MeasurementError const *error=nullptr) const
 Handle an expected or unexpected Exception thrown by a measurement algorithm. More...
 

Static Public Member Functions

static std::string const & getFailureFlagName ()
 Define the universal name of the general failure flag. More...
 
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. More...
 

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 148 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 176 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 58 of file FlagHandler.cc.

61  _vector.reserve(flagDefs.size());
62  for (std::size_t i = 0; i < flagDefs.size(); i++) {
63  FlagDefinition const& flagDef = flagDefs[i];
64  if (exclDefs.hasDefinition(flagDef.name)) {
65  afw::table::Key<afw::table::Flag> key;
66  _vector.push_back(std::make_pair(flagDef.name, key));
67  } else {
68  _vector.push_back(std::make_pair(flagDef.name, s[flagDef.name]));
69  if (flagDef.name == FlagHandler::getFailureFlagName()) {
71  }
72  }
73  }
74 }

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 37 of file FlagHandler.cc.

38  {
39  FlagHandler r;
40  r._vector.reserve(flagDefs.size());
41  for (std::size_t i = 0; i < flagDefs.size(); i++) {
42  FlagDefinition const& flagDef = flagDefs[i];
43  if (exclDefs.hasDefinition(flagDef.name)) {
44  afw::table::Key<afw::table::Flag> key;
45  r._vector.push_back(std::make_pair(flagDef.name, key));
46  } else {
47  afw::table::Key<afw::table::Flag> key(
48  schema.addField<afw::table::Flag>(schema.join(prefix, flagDef.name), flagDef.doc));
49  r._vector.push_back(std::make_pair(flagDef.name, key));
50  if (flagDef.name == FlagHandler::getFailureFlagName()) {
51  r.failureFlagNumber = i;
52  }
53  }
54  }
55  return r;
56 }

◆ getFailureFlagName()

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

Define the universal name of the general failure flag.

Definition at line 181 of file FlagHandler.h.

181  {
182  static std::string name = "flag";
183  return name;
184  }

◆ 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 286 of file FlagHandler.h.

286 { 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 233 of file FlagHandler.h.

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

◆ 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 222 of file FlagHandler.h.

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

◆ 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 242 of file FlagHandler.h.

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

◆ 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 251 of file FlagHandler.h.

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

◆ 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 76 of file FlagHandler.cc.

76  {
77  std::size_t const numFlags = _vector.size();
79  record.set(_vector[failureFlagNumber].second, true);
80  }
81  if (error && error->getFlagBit() != FlagDefinition::number_undefined) {
82  assert(numFlags > error->getFlagBit()); // We need the particular flag
83  record.set(_vector[error->getFlagBit()].second, true);
84  }
85 }

◆ 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 262 of file FlagHandler.h.

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

◆ 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 272 of file FlagHandler.h.

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

Member Data Documentation

◆ failureFlagNumber

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

Definition at line 297 of file FlagHandler.h.


The documentation for this class was generated from the following files:
schema
table::Schema schema
Definition: Amplifier.cc:115
std::string
STL class.
lsst::afw::table._match.second
second
Definition: _match.py:78
lsst::log.log.logContinued.error
def error(fmt, *args)
Definition: logContinued.py:210
lsst::meas::base::FlagHandler::FlagHandler
FlagHandler()
Each error should have a corresponding static FlagDefinition object.
Definition: FlagHandler.h:176
std::vector::reserve
T reserve(T... args)
std::vector::size
T size(T... args)
lsst::afw::table._match.first
first
Definition: _match.py:76
lsst::afw::geom.transform.transformContinued.name
string name
Definition: transformContinued.py:32
std::vector::push_back
T push_back(T... args)
lsst::meas::base::FlagHandler::getFailureFlagName
static std::string const & getFailureFlagName()
Define the universal name of the general failure flag.
Definition: FlagHandler.h:181
lsst::meas::base::FlagDefinition::number_undefined
static constexpr std::size_t number_undefined
Definition: FlagHandler.h:41
std::to_string
T to_string(T... args)
key
Key< U > key
Definition: Schema.cc:281
std::size_t
std::make_pair
T make_pair(T... args)
prefix
std::string prefix
Definition: SchemaMapper.cc:79
lsst::meas::base::FlagHandler::failureFlagNumber
std::size_t failureFlagNumber
Definition: FlagHandler.h:297