LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
slots.cc
Go to the documentation of this file.
1 #include "lsst/pex/exceptions.h"
2 #include "lsst/afw/table/slots.h"
3 
4 namespace lsst {
5 namespace afw {
6 namespace table {
7 
8 namespace {
9 
10 // Return true if 'a' starts with 'b'
11 bool startsWith(std::string const &a, std::string const b) { return a.compare(0, b.size(), b) == 0; }
12 
13 // helper class that resolves aliases for a slot's main measurement field, while
14 // distiguishing between two cases where the field can't be found:
15 // - if the alias points to an invalid field, we should throw an exception (which is actually
16 // done by the calling setKeys() method, by allowing a lower-level exception to propagate up).
17 // - if the alias simply isn't defined, we should just reset the slot with invalid keys
18 class MeasFieldNameGetter {
19 public:
20  MeasFieldNameGetter(SubSchema const &s, Schema const &schema)
21  : replaced(schema[schema.getAliasMap()->apply(s.getPrefix())]),
22  defined(replaced.getPrefix() !=
23  s.getPrefix()) // slot is defined if applying alias wasn't a no-op
24  {}
25 
26  SubSchema replaced; // a SubSchema that includes alias replacement
27  bool defined; // whether the slot is defined at all
28 };
29 
30 } // namespace
31 
33  SubSchema s = schema["slot"][_name];
34  if (!alias.empty() && !startsWith(alias, s.getPrefix())) return;
35  _measKey = MeasKey();
36  _errKey = ErrKey();
37  _flagKey = Key<Flag>();
38  MeasFieldNameGetter helper(s["instFlux"], schema);
39  if (!helper.defined) {
40  return;
41  }
42  _measKey = helper.replaced;
43  try {
44  _errKey = s["instFluxErr"];
45  } catch (pex::exceptions::NotFoundError &) {
46  }
47  try {
48  _flagKey = s["flag"];
49  } catch (pex::exceptions::NotFoundError &) {
50  }
51 }
52 
53 namespace {
54 
55 CentroidSlotDefinition::ErrKey::NameArray makeCentroidNameArray() {
57  v.push_back("x");
58  v.push_back("y");
59  return v;
60 }
61 
62 } // namespace
63 
65  SubSchema s = schema["slot"][_name];
66  if (!alias.empty() && !startsWith(alias, s.getPrefix())) return;
67  static ErrKey::NameArray names = makeCentroidNameArray();
68  _measKey = MeasKey();
69  _errKey = ErrKey();
70  _flagKey = Key<Flag>();
71  MeasFieldNameGetter helper(s, schema);
72  if (!helper.defined) return;
73  _measKey = helper.replaced;
74  try {
75  _errKey = ErrKey(s, names);
76  } catch (pex::exceptions::NotFoundError &) {
77  }
78  try {
79  _flagKey = s["flag"];
80  } catch (pex::exceptions::NotFoundError &) {
81  }
82 }
83 
84 namespace {
85 
86 ShapeSlotDefinition::ErrKey::NameArray makeShapeNameArray() {
88  v.push_back("xx");
89  v.push_back("yy");
90  v.push_back("xy");
91  return v;
92 }
93 
94 } // namespace
95 
97  SubSchema s = schema["slot"][_name];
98  if (!alias.empty() && !startsWith(alias, s.getPrefix())) return;
99  static ErrKey::NameArray names = makeShapeNameArray();
100  _measKey = MeasKey();
101  _errKey = ErrKey();
102  _flagKey = Key<Flag>();
103  MeasFieldNameGetter helper(s, schema);
104  if (!helper.defined) return;
105  _measKey = helper.replaced;
106  try {
107  _errKey = ErrKey(s, names);
108  } catch (pex::exceptions::NotFoundError &) {
109  }
110  try {
111  _flagKey = s["flag"];
112  } catch (pex::exceptions::NotFoundError &) {
113  }
114 }
115 
117  defPsfFlux.setKeys(alias, schema);
118  defApFlux.setKeys(alias, schema);
120  defModelFlux.setKeys(alias, schema);
121  defCalibFlux.setKeys(alias, schema);
122  defCentroid.setKeys(alias, schema);
123  defShape.setKeys(alias, schema);
124 }
125 
127  : defPsfFlux("PsfFlux"),
128  defApFlux("ApFlux"),
129  defGaussianFlux("GaussianFlux"),
130  defModelFlux("ModelFlux"),
131  defCalibFlux("CalibFlux"),
132  defCentroid("Centroid"),
133  defShape("Shape") {
135  defApFlux.setKeys("", schema);
140  defShape.setKeys("", schema);
141 }
142 } // namespace table
143 } // namespace afw
144 } // namespace lsst
schema
table::Schema schema
Definition: Amplifier.cc:115
defined
bool defined
Definition: slots.cc:27
lsst::afw::table::CentroidSlotDefinition::setKeys
void setKeys(std::string const &alias, Schema const &schema)
Update the cached Keys following an change of aliases in the given Schema.
Definition: slots.cc:64
std::string
STL class.
std::vector< std::string >
lsst.pex::exceptions::NotFoundError
Reports attempts to access elements using an invalid key.
Definition: Runtime.h:151
lsst::afw::table::FluxSlotDefinition::MeasKey
Key< double > MeasKey
Key type used to access the slot measurement.
Definition: slots.h:77
lsst::afw::table::FluxSlotDefinition::setKeys
void setKeys(std::string const &alias, Schema const &schema)
Update the cached Keys following an change of aliases in the given Schema.
Definition: slots.cc:32
lsst::afw::table::SlotSuite::defApFlux
FluxSlotDefinition defApFlux
Definition: slots.h:221
lsst::afw
Definition: imageAlgorithm.dox:1
lsst::afw::table::ShapeSlotDefinition::ErrKey
CovarianceMatrixKey< float, 3 > ErrKey
Key type used to access the slot uncertainty.
Definition: slots.h:172
lsst::afw::table::SlotSuite::defCalibFlux
FluxSlotDefinition defCalibFlux
Definition: slots.h:224
lsst::afw::table::Schema
Defines the fields and offsets for a table.
Definition: Schema.h:50
lsst::afw::table::ShapeSlotDefinition::MeasKey
QuadrupoleKey MeasKey
Key type used to access the slot measurement.
Definition: slots.h:171
lsst::afw::table::FluxSlotDefinition::ErrKey
Key< double > ErrKey
Key type used to access the slot uncertainty.
Definition: slots.h:78
lsst::afw::table::SlotSuite::SlotSuite
SlotSuite(Schema const &schema)
Initialize the slots.
Definition: slots.cc:126
std::vector::push_back
T push_back(T... args)
lsst::afw::table::SlotSuite::defCentroid
CentroidSlotDefinition defCentroid
Definition: slots.h:225
slots.h
lsst::afw::table::SlotSuite::defPsfFlux
FluxSlotDefinition defPsfFlux
Definition: slots.h:220
b
table::Key< int > b
Definition: TransmissionCurve.cc:467
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
lsst::afw::table::SlotDefinition::_name
std::string _name
Definition: slots.h:69
replaced
SubSchema replaced
Definition: slots.cc:26
lsst::afw::table::CentroidSlotDefinition::ErrKey
CovarianceMatrixKey< float, 2 > ErrKey
Key type used to access the slot uncertainty.
Definition: slots.h:125
a
table::Key< int > a
Definition: TransmissionCurve.cc:466
lsst::afw::table::SubSchema
A proxy type for name lookups in a Schema.
Definition: Schema.h:357
lsst::afw::table::CentroidSlotDefinition::MeasKey
Point2DKey MeasKey
Key type used to access the slot measurement.
Definition: slots.h:124
lsst::afw::table::ShapeSlotDefinition::setKeys
void setKeys(std::string const &alias, Schema const &schema)
Update the cached Keys following an change of aliases in the given Schema.
Definition: slots.cc:96
std::string::empty
T empty(T... args)
lsst::afw::table::SlotSuite::handleAliasChange
void handleAliasChange(std::string const &alias, Schema const &schema)
Handle a callback from an AliasMap informing the table that an alias has changed.
Definition: slots.cc:116
lsst::afw::table::SlotSuite::defGaussianFlux
FluxSlotDefinition defGaussianFlux
Definition: slots.h:222
lsst::afw::table::Key< Flag >
Key specialization for Flag.
Definition: Flag.h:94
lsst::afw::table::SlotSuite::defShape
ShapeSlotDefinition defShape
Definition: slots.h:226
lsst::afw::table::SlotSuite::defModelFlux
FluxSlotDefinition defModelFlux
Definition: slots.h:223
lsst::afw::table::SubSchema::getPrefix
std::string const & getPrefix() const
Return the prefix that defines this SubSchema relative to its parent Schema.
Definition: Schema.h:410
exceptions.h