lsst.afw  13.0-92-g8ecf155+1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
55  std::shared_ptr<SimpleTable const> getTable() const {
56  return std::static_pointer_cast<SimpleTable const>(BaseRecord::getTable());
57  }
58 
60  RecordId getId() const;
62  void setId(RecordId id);
63 
64  IcrsCoord getCoord() const;
65  void setCoord(IcrsCoord const& coord);
66  void setCoord(Coord const& coord);
67 
68  Angle getRa() const;
69  void setRa(Angle ra);
70 
71  Angle getDec() const;
72  void setDec(Angle dec);
74 
75 protected:
76  friend class SimpleTable;
77 
78  explicit SimpleRecord(std::shared_ptr<SimpleTable> const& table);
79 };
80 
86 class SimpleTable : public BaseTable {
87 public:
92 
103  static std::shared_ptr<SimpleTable> make(Schema const& schema,
104  std::shared_ptr<IdFactory> const& idFactory);
105 
113  static std::shared_ptr<SimpleTable> make(Schema const& schema) {
114  return make(schema, IdFactory::makeSimple());
115  }
116 
125  Schema r = getMinimalSchema().schema;
126  r.disconnectAliases();
127  return r;
128  }
129 
136  static bool checkSchema(Schema const& other) { return other.contains(getMinimalSchema().schema); }
137 
139  std::shared_ptr<IdFactory> getIdFactory() { return _idFactory; }
140 
142  std::shared_ptr<IdFactory const> getIdFactory() const { return _idFactory; }
143 
145  void setIdFactory(std::shared_ptr<IdFactory> f) { _idFactory = f; }
146 
148 
153  static Key<RecordId> getIdKey() { return getMinimalSchema().id; }
156  static CoordKey getCoordKey() { return getMinimalSchema().coord; }
158 
160  std::shared_ptr<SimpleTable> clone() const { return std::static_pointer_cast<SimpleTable>(_clone()); }
161 
163  std::shared_ptr<SimpleRecord> makeRecord() {
164  return std::static_pointer_cast<SimpleRecord>(_makeRecord());
165  }
166 
168  std::shared_ptr<SimpleRecord> copyRecord(BaseRecord const& other) {
169  return std::static_pointer_cast<SimpleRecord>(BaseTable::copyRecord(other));
170  }
171 
173  std::shared_ptr<SimpleRecord> copyRecord(BaseRecord const& other, SchemaMapper const& mapper) {
174  return std::static_pointer_cast<SimpleRecord>(BaseTable::copyRecord(other, mapper));
175  }
176 
177 protected:
178  SimpleTable(Schema const& schema, std::shared_ptr<IdFactory> const& idFactory);
179 
180  explicit SimpleTable(SimpleTable const& other);
181 
182  std::shared_ptr<BaseTable> _clone() const override;
183 
184  std::shared_ptr<BaseRecord> _makeRecord() override;
185 
186 private:
187  // Struct that holds the minimal schema and the special keys we've added to it.
188  struct MinimalSchema {
189  Schema schema;
190  Key<RecordId> id;
191  CoordKey coord;
192 
193  MinimalSchema();
194  };
195 
196  // Return the singleton minimal schema.
197  static MinimalSchema& getMinimalSchema();
198 
199  friend class io::FitsWriter;
200 
201  // Return a writer object that knows how to save in FITS format. See also FitsWriter.
202  std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile, int flags) const override;
203 
204  std::shared_ptr<IdFactory> _idFactory; // generates IDs for new records
205 };
206 
207 inline RecordId SimpleRecord::getId() const { return get(SimpleTable::getIdKey()); }
209 
211 inline void SimpleRecord::setCoord(IcrsCoord const& coord) { set(SimpleTable::getCoordKey(), coord); }
212 inline void SimpleRecord::setCoord(Coord const& coord) { SimpleTable::getCoordKey().set(*this, coord); }
213 
214 inline Angle SimpleRecord::getRa() const { return get(SimpleTable::getCoordKey().getRa()); }
216 
217 inline Angle SimpleRecord::getDec() const { return get(SimpleTable::getCoordKey().getDec()); }
219 }
220 }
221 } // namespace lsst::afw::table
222 
223 #endif // !AFW_TABLE_Simple_h_INCLUDED
std::int64_t RecordId
Type used for unique IDs for records.
Definition: misc.h:22
Defines the fields and offsets for a table.
Definition: Schema.h:46
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:215
static Schema makeMinimalSchema()
Return a minimal schema for Simple tables and records.
Definition: Simple.h:124
static bool checkSchema(Schema const &other)
Return true if the given schema is a valid SimpleTable schema.
Definition: Simple.h:136
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:21
Angle getRa() const
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:214
SortedCatalogT< Record const > ConstCatalog
Definition: Simple.h:91
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:173
static Key< RecordId > getIdKey()
Get keys for standard fields shared by all references.
Definition: Simple.h:154
void disconnectAliases()
Sever the connection between this schema and any others with which it shares aliases.
std::shared_ptr< SimpleTable const > getTable() const
Definition: Simple.h:55
SimpleTable(Schema const &schema, std::shared_ptr< IdFactory > const &idFactory)
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:199
std::shared_ptr< BaseTable > _clone() const override
Clone implementation with noncovariant return types.
std::shared_ptr< BaseRecord > copyRecord(BaseRecord const &input)
Deep-copy a record, requiring that it have the same schema as this table.
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:145
SortedCatalogT< Record > Catalog
Definition: Simple.h:90
std::shared_ptr< BaseRecord > _makeRecord() override
Default-construct an associated record (protected implementation).
Angle getDec() const
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:217
Table class that must contain a unique ID field and a celestial coordinate field. ...
Definition: Simple.h:86
A class representing an angle.
Definition: Angle.h:102
std::shared_ptr< SimpleTable > clone() const
Return a polymorphic deep copy of the table.
Definition: Simple.h:160
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:168
std::shared_ptr< BaseTable const > getTable() const
Return the table this record is associated with.
Definition: BaseRecord.h:55
static std::shared_ptr< IdFactory > makeSimple()
Return a simple IdFactory that simply counts from 1.
Key< geom::Angle > getDec() const
Return a constituent Key.
Definition: aggregates.h:163
virtual void set(BaseRecord &record, coord::IcrsCoord const &value) const
Set an IcrsCoord in the given record.
IcrsCoord getCoord() const
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:210
RecordId getId() const
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:207
void setDec(Angle dec)
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:218
ColumnViewT< SimpleRecord > ColumnView
Definition: Simple.h:51
ColumnViewT< SimpleRecord > ColumnView
Definition: Simple.h:89
SimpleRecord(std::shared_ptr< SimpleTable > const &table)
SortedCatalogT< SimpleRecord > Catalog
Definition: Simple.h:52
Base class for all records.
Definition: BaseRecord.h:29
int contains(Schema const &other, int flags=EQUAL_KEYS) const
Test whether the given schema is a subset of this.
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
Definition: BaseRecord.h:136
std::shared_ptr< SimpleRecord > makeRecord()
Default-construct an associated record.
Definition: Simple.h:163
std::shared_ptr< IdFactory const > getIdFactory() const
Return the object that generates IDs for the table (may be null).
Definition: Simple.h:142
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:208
This is the base class for spherical coordinates.
Definition: Coord.h:63
void setCoord(IcrsCoord const &coord)
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:211
static CoordKey getCoordKey()
Key for the celestial coordinates.
Definition: Simple.h:156
std::shared_ptr< IdFactory > getIdFactory()
Return the object that generates IDs for the table (may be null).
Definition: Simple.h:139
A class to handle Icrs coordinates (inherits from Coord)
Definition: Coord.h:288
Key< geom::Angle > getRa() const
Return a constituent Key.
Definition: aggregates.h:162
SortedCatalogT< SimpleRecord const > ConstCatalog
Definition: Simple.h:53
Base class for all tables.
Definition: BaseTable.h:44
afw::table::Schema schema
Definition: GaussianPsf.cc:43
static std::shared_ptr< SimpleTable > make(Schema const &schema, std::shared_ptr< IdFactory > const &idFactory)
Construct a new table.
A FunctorKey used to get or set celestial coordinates from a pair of Angle keys.
Definition: aggregates.h:115
static std::shared_ptr< SimpleTable > make(Schema const &schema)
Construct a new table.
Definition: Simple.h:113