LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
LSST Data Management Base Package
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
table::Key< int > b
table::Key< int > a
table::Schema schema
Definition: python.h:134
CovarianceMatrixKey< float, 2 > ErrKey
Key type used to access the slot uncertainty.
Definition: slots.h:125
Point2DKey MeasKey
Key type used to access the slot measurement.
Definition: slots.h:124
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
Key< double > MeasKey
Key type used to access the slot measurement.
Definition: slots.h:77
Key< double > ErrKey
Key type used to access the slot uncertainty.
Definition: slots.h:78
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
Key specialization for Flag.
Definition: Flag.h:94
Defines the fields and offsets for a table.
Definition: Schema.h:50
CovarianceMatrixKey< float, 3 > ErrKey
Key type used to access the slot uncertainty.
Definition: slots.h:172
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
QuadrupoleKey MeasKey
Key type used to access the slot measurement.
Definition: slots.h:171
A proxy type for name lookups in a Schema.
Definition: Schema.h:357
std::string const & getPrefix() const
Return the prefix that defines this SubSchema relative to its parent Schema.
Definition: Schema.h:410
Reports attempts to access elements using an invalid key.
Definition: Runtime.h:151
T empty(T... args)
A base class for image defects.
T push_back(T... args)
bool defined
Definition: slots.cc:27
SubSchema replaced
Definition: slots.cc:26
CentroidSlotDefinition defCentroid
Definition: slots.h:225
FluxSlotDefinition defModelFlux
Definition: slots.h:223
SlotSuite(Schema const &schema)
Initialize the slots.
Definition: slots.cc:126
FluxSlotDefinition defCalibFlux
Definition: slots.h:224
FluxSlotDefinition defApFlux
Definition: slots.h:221
FluxSlotDefinition defPsfFlux
Definition: slots.h:220
ShapeSlotDefinition defShape
Definition: slots.h:226
FluxSlotDefinition defGaussianFlux
Definition: slots.h:222
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