New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DM-9249 Change FlagHandler to remove the enum of flag types #68
Conversation
I would clean up the wording in the first paragraph of the commit. It was a little hard to parse. There is a lot of information in this commit message that might be a better fit in documentation. Perhaps, you give a more concise summary of the work that was done. |
bool getFlag(unsigned int index) const { return _flags[index]; } | ||
|
||
/// Return the flag value associated with the given flag name | ||
bool getFlag(std::string name) const { return _flags[ApertureFluxAlgorithm::getFlagDefinitions().getDefinition(name).number]; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is too long. There are also many other lines below that are beyond the 110 char limit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
include/lsst/meas/base/FlagHandler.h
Outdated
* @brief Add a new FlagDefinition to this list. Return a copy with the | ||
* FlagDefinition.number set corresponding to its index in the list. | ||
*/ | ||
FlagDefinition add(std::string const name, std::string const doc) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these arguments be changed to const ref's?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix. Sorry, my comment on Jira doesn't apply. I misread this review comment
include/lsst/meas/base/FlagHandler.h
Outdated
|
||
/** | ||
* Default constructor for delayed initialization. | ||
* | ||
* This constructor creates an invalid, unusable FlagHandler in the same way an iterator | ||
* default constructor constructs an invalid iterator. Its only purpose is to delay construction | ||
* This constructor creates an invalid, unusable FlagHandler in the same way an const_iterator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"an const_iterator" -> "a const_iterator"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
include/lsst/meas/base/FlagHandler.h
Outdated
private: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removal of blank lines should be put in a separate commit. There are a couple of other examples of this below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/GaussianCentroid.cc
Outdated
for (std::size_t i = 0; i < GaussianCentroidAlgorithm::getFlagDefinitions().size(); i++) { | ||
FlagDefinition const & flag = GaussianCentroidAlgorithm::getFlagDefinitions()[i]; | ||
if (flag == GaussianCentroidAlgorithm::FAILURE) continue; | ||
if (mapper.getInputSchema().getNames().count(name + "_" + flag.name) == 0) continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't you be using the schema.join method to look for the name? Same comment for other transform algorithms below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
mapper.getInputSchema().join(name, flag->name)).key); | ||
for (std::size_t i = 0; i < GaussianCentroidAlgorithm::getFlagDefinitions().size(); i++) { | ||
FlagDefinition const & flag = GaussianCentroidAlgorithm::getFlagDefinitions()[i]; | ||
if (flag == GaussianCentroidAlgorithm::FAILURE) continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this not get added to the mapper? Same comment for other transform algorithms below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied what was in the existing code.
One general comment. I'm not crazy about the need to specify ".number" when setting flags in a record. Maybe this is the price to pay for being consistent everywhere and allowing for some flags to not be added to schemas. |
src/NaiveCentroid.cc
Outdated
} | ||
|
||
|
||
namespace { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why you have an empty namespace here? There is another example of this below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/SdssShape.cc
Outdated
@@ -734,7 +743,8 @@ SdssShapeResult SdssShapeResultKey::get(afw::table::BaseRecord const & record) c | |||
result.flux_xx_Cov = record.get(_flux_xx_Cov); | |||
result.flux_yy_Cov = record.get(_flux_yy_Cov); | |||
result.flux_xy_Cov = record.get(_flux_xy_Cov); | |||
for (int n = 0; n < SdssShapeAlgorithm::N_FLAGS - (_includePsf ? 0 : 1); ++n) { | |||
for (unsigned int n = 0; n < SdssShapeAlgorithm::N_FLAGS; ++n) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and below you are using unsigned int. The rest of the code in these pull requests are using size_t, it would be good to be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
a17aaed
to
b10abc3
Compare
The enum which formerly numbered the available failure flags is replaced with a set of static FlagDefinitions: (e.g., static FlagDefinition const FAILURE; for the general flag). The position of the flag in the FlagHandler list is now the number value of the FlagDefinition (e.g., FAILURE.number). A new class FlagDefinitionList is introduced to specify the FlagDefinitions used to initialize the FlagHandler. Add flags to the FlagDefinitionList using the methods addFailureFlag() and add(name, doc). When done, use the FlagHandler initializer addFields(schema, name, flagDefinitionList). An optional exclusion list exclDefs is provided if some members of the algorithms FlagDefinitionList are not desired. The _flagHandler keeps the same numbering of flags whether or not a flag is excluded -- the FlagDefinition.number is fixed. It is now optional whether a General Failure flag is defined for the flagHandler. Remove the FlagHandler::FAILURE which assumes FAILURE is position 0.
b10abc3
to
4c2df6d
Compare
enum is replaced with static FlagDefinition of the same name
If the index of the flag is required a FlagDefinition.number
If the flag name is required, use FlagDefinition.name
Remove the old style of initializing the FlagHandler using iterator
to a std::array. A new class FlagDefinitionList
is introduced to specify the FlagDefinitions used to initialize the
FlagHandler. Add flags to the FlagDefinitionList using the methods
addFailureFlag() and add(name, doc). When done, use the FlagHandler
initializer addFields(schema, name, flagDefinitionList).
An optional exclusion list exclDefs is provided if some members of
the algorithms FlagDefinitionList are not desired for a particular
configuration. The _flagHandler keeps the same numbering of flags
whether or not a flag is excluded -- the FlagDefinition.number is
fixed. But the flag is not added to the schema if it is excluded.
It is now optional whether a General Failure flag is defined for the
flagHandler. If it is not added to the FlagDefinitionList, the
flagHandler will not perform the function of setting the general
flag when the other flags are set in handleFailure.
Remove the FlagHandler::FAILURE which was used to always identify
the failure flag as number 0. Flags may be added in any order.
Use flagHandler.getFailureFlagNumber() to get the correct index.