LSST Applications g070148d5b3+33e5256705,g0d53e28543+25c8b88941,g0da5cf3356+2dd1178308,g1081da9e2a+62d12e78cb,g17e5ecfddb+7e422d6136,g1c76d35bf8+ede3a706f7,g295839609d+225697d880,g2e2c1a68ba+cc1f6f037e,g2ffcdf413f+853cd4dcde,g38293774b4+62d12e78cb,g3b44f30a73+d953f1ac34,g48ccf36440+885b902d19,g4b2f1765b6+7dedbde6d2,g5320a0a9f6+0c5d6105b6,g56b687f8c9+ede3a706f7,g5c4744a4d9+ef6ac23297,g5ffd174ac0+0c5d6105b6,g6075d09f38+66af417445,g667d525e37+2ced63db88,g670421136f+2ced63db88,g71f27ac40c+2ced63db88,g774830318a+463cbe8d1f,g7876bc68e5+1d137996f1,g7985c39107+62d12e78cb,g7fdac2220c+0fd8241c05,g96f01af41f+368e6903a7,g9ca82378b8+2ced63db88,g9d27549199+ef6ac23297,gabe93b2c52+e3573e3735,gb065e2a02a+3dfbe639da,gbc3249ced9+0c5d6105b6,gbec6a3398f+0c5d6105b6,gc9534b9d65+35b9f25267,gd01420fc67+0c5d6105b6,geee7ff78d7+a14128c129,gf63283c776+ede3a706f7,gfed783d017+0c5d6105b6,w.2022.47
LSST Data Management Base Package
Loading...
Searching...
No Matches
slots.cc
Go to the documentation of this file.
3
4namespace lsst {
5namespace afw {
6namespace table {
7
8namespace {
9
10// Return true if 'a' starts with 'b'
11bool 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
18class MeasFieldNameGetter {
19public:
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"];
46 }
47 try {
48 _flagKey = s["flag"];
50 }
51}
52
53namespace {
54
55CentroidSlotDefinition::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);
77 }
78 try {
79 _flagKey = s["flag"];
81 }
82}
83
84namespace {
85
86ShapeSlotDefinition::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);
109 }
110 try {
111 _flagKey = s["flag"];
113 }
114}
115
117 defPsfFlux.setKeys(alias, schema);
118 defApFlux.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") {
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
A class used as a handle to a particular field in a table.
Definition: Key.h:53
Defines the fields and offsets for a table.
Definition: Schema.h:51
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:367
std::string const & getPrefix() const
Return the prefix that defines this SubSchema relative to its parent Schema.
Definition: Schema.h:420
Reports attempts to access elements using an invalid key.
Definition: Runtime.h:151
T empty(T... args)
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