lsst.afw  15.0-18-g5f205baaa
Simple.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008, 2009, 2010, 2011 LSST Corporation.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 #ifndef AFW_TABLE_Simple_h_INCLUDED
24 #define AFW_TABLE_Simple_h_INCLUDED
25 
29 #include "lsst/afw/table/Catalog.h"
33 
34 namespace lsst {
35 namespace afw {
36 namespace table {
37 
38 class SimpleRecord;
39 class SimpleTable;
40 
48 class SimpleRecord : public BaseRecord {
49 public:
50  typedef SimpleTable Table;
54 
57  }
58 
60  RecordId getId() const;
62  void setId(RecordId id);
63 
64  SpherePoint getCoord() const;
65  void setCoord(SpherePoint const& coord);
66 
67  Angle getRa() const;
68  void setRa(Angle ra);
69 
70  Angle getDec() const;
71  void setDec(Angle dec);
73 
74  SimpleRecord(const SimpleRecord&) = delete;
75  SimpleRecord& operator=(const SimpleRecord&) = delete;
76  SimpleRecord(SimpleRecord&&) = delete;
77  SimpleRecord& operator=(SimpleRecord&&) = delete;
78  ~SimpleRecord();
79 
80 protected:
81  friend class SimpleTable;
82 
83  explicit SimpleRecord(std::shared_ptr<SimpleTable> const& table);
84 };
85 
91 class SimpleTable : public BaseTable {
92 public:
97 
108  static std::shared_ptr<SimpleTable> make(Schema const& schema,
110 
119  return make(schema, IdFactory::makeSimple());
120  }
121 
130  Schema r = getMinimalSchema().schema;
131  r.disconnectAliases();
132  return r;
133  }
134 
141  static bool checkSchema(Schema const& other) { return other.contains(getMinimalSchema().schema); }
142 
144  std::shared_ptr<IdFactory> getIdFactory() { return _idFactory; }
145 
147  std::shared_ptr<IdFactory const> getIdFactory() const { return _idFactory; }
148 
150  void setIdFactory(std::shared_ptr<IdFactory> f) { _idFactory = f; }
151 
153 
158  static Key<RecordId> getIdKey() { return getMinimalSchema().id; }
161  static CoordKey getCoordKey() { return getMinimalSchema().coord; }
163 
166 
169  return std::static_pointer_cast<SimpleRecord>(_makeRecord());
170  }
171 
175  }
176 
180  }
181 
182  SimpleTable& operator=(SimpleTable const&) = delete;
183  SimpleTable& operator=(SimpleTable&&) = delete;
184  ~SimpleTable();
185 
186 protected:
188 
189  explicit SimpleTable(SimpleTable const& other);
190  explicit SimpleTable(SimpleTable && other);
191 
192  std::shared_ptr<BaseTable> _clone() const override;
193 
194  std::shared_ptr<BaseRecord> _makeRecord() override;
195 
196 private:
197  // Struct that holds the minimal schema and the special keys we've added to it.
198  struct MinimalSchema {
199  Schema schema;
200  Key<RecordId> id;
201  CoordKey coord;
202 
203  MinimalSchema();
204  };
205 
206  // Return the singleton minimal schema.
207  static MinimalSchema& getMinimalSchema();
208 
209  friend class io::FitsWriter;
210 
211  // Return a writer object that knows how to save in FITS format. See also FitsWriter.
212  std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile, int flags) const override;
213 
214  std::shared_ptr<IdFactory> _idFactory; // generates IDs for new records
215 };
216 
217 inline RecordId SimpleRecord::getId() const { return get(SimpleTable::getIdKey()); }
218 inline void SimpleRecord::setId(RecordId id) { set(SimpleTable::getIdKey(), id); }
219 
221 inline void SimpleRecord::setCoord(SpherePoint const& coord) { set(SimpleTable::getCoordKey(), coord); }
222 
223 inline Angle SimpleRecord::getRa() const { return get(SimpleTable::getCoordKey().getRa()); }
224 inline void SimpleRecord::setRa(Angle ra) { set(SimpleTable::getCoordKey().getRa(), ra); }
225 
226 inline Angle SimpleRecord::getDec() const { return get(SimpleTable::getCoordKey().getDec()); }
228 }
229 }
230 } // namespace lsst::afw::table
231 
232 #endif // !AFW_TABLE_Simple_h_INCLUDED
Defines the fields and offsets for a table.
Definition: Schema.h:47
double dec
Definition: Match.cc:41
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:59
Writer object for FITS binary tables.
Definition: FitsWriter.h:25
void setRa(Angle ra)
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:224
static Schema makeMinimalSchema()
Return a minimal schema for Simple tables and records.
Definition: Simple.h:129
RecordId getId() const
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:217
static bool checkSchema(Schema const &other)
Return true if the given schema is a valid SimpleTable schema.
Definition: Simple.h:141
afw::table::Schema schema
Definition: GaussianPsf.cc:43
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:21
SortedCatalogT< Record const > ConstCatalog
Definition: Simple.h:96
std::shared_ptr< SimpleRecord > copyRecord(BaseRecord const &other, SchemaMapper const &mapper)
Deep-copy a record, requiring that it have the same schema as this table.
Definition: Simple.h:178
static Key< RecordId > getIdKey()
Get keys for standard fields shared by all references.
Definition: Simple.h:159
void disconnectAliases()
Sever the connection between this schema and any others with which it shares aliases.
Definition: Schema.cc:719
ItemVariant const * other
Definition: Schema.cc:55
SchemaMapper * mapper
Definition: SchemaMapper.cc:78
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:298
std::shared_ptr< BaseRecord > copyRecord(BaseRecord const &input)
Deep-copy a record, requiring that it have the same schema as this table.
Definition: BaseTable.cc:125
Angle getRa() const
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:223
void setIdFactory(std::shared_ptr< IdFactory > f)
Switch to a new IdFactory – object that generates IDs for the table (may be null).
Definition: Simple.h:150
SortedCatalogT< Record > Catalog
Definition: Simple.h:95
SpherePoint getCoord() const
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:220
Table class that must contain a unique ID field and a celestial coordinate field. ...
Definition: Simple.h:91
A class representing an angle.
Definition: Angle.h:102
A base class for image defects.
Custom catalog class for record/table subclasses that are guaranteed to have an ID, and should generally be sorted by that ID.
Definition: fwd.h:63
std::shared_ptr< SimpleRecord > copyRecord(BaseRecord const &other)
Deep-copy a record, requiring that it have the same schema as this table.
Definition: Simple.h:173
int contains(Schema const &other, int flags=EQUAL_KEYS) const
Test whether the given schema is a subset of this.
Definition: Schema.cc:677
std::shared_ptr< IdFactory const > getIdFactory() const
Return the object that generates IDs for the table (may be null).
Definition: Simple.h:147
void setCoord(SpherePoint const &coord)
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:221
void setDec(Angle dec)
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:227
T static_pointer_cast(T... args)
ColumnViewT< SimpleRecord > ColumnView
Definition: Simple.h:51
ColumnViewT< SimpleRecord > ColumnView
Definition: Simple.h:94
SimpleRecord & operator=(const SimpleRecord &)=delete
Key< geom::Angle > getDec() const
Return a constituent Key.
Definition: aggregates.h:256
std::shared_ptr< BaseTable const > getTable() const
Return the table this record is associated with.
Definition: BaseRecord.h:57
std::shared_ptr< SimpleTable const > getTable() const
Definition: Simple.h:55
SortedCatalogT< SimpleRecord > Catalog
Definition: Simple.h:52
Base class for all records.
Definition: BaseRecord.h:31
std::shared_ptr< SimpleTable > clone() const
Return a polymorphic deep copy of the table.
Definition: Simple.h:165
A class used as a handle to a particular field in a table.
Definition: fwd.h:45
std::shared_ptr< SimpleRecord > makeRecord()
Default-construct an associated record.
Definition: Simple.h:168
static std::shared_ptr< IdFactory > makeSimple()
Return a simple IdFactory that simply counts from 1.
Definition: IdFactory.cc:70
friend class SimpleTable
Definition: Simple.h:81
Record class that must contain a unique ID field and a celestial coordinate field.
Definition: Simple.h:48
void setId(RecordId id)
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:218
Angle getDec() const
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:226
Key< geom::Angle > getRa() const
Return a constituent Key.
Definition: aggregates.h:255
static CoordKey getCoordKey()
Key for the celestial coordinates.
Definition: Simple.h:161
std::shared_ptr< IdFactory > getIdFactory()
Return the object that generates IDs for the table (may be null).
Definition: Simple.h:144
SortedCatalogT< SimpleRecord const > ConstCatalog
Definition: Simple.h:53
Base class for all tables.
Definition: BaseTable.h:44
SimpleRecord(const SimpleRecord &)=delete
A FunctorKey used to get or set celestial coordinates from a pair of Angle keys.
Definition: aggregates.h:205
static std::shared_ptr< SimpleTable > make(Schema const &schema)
Construct a new table.
Definition: Simple.h:118