lsst.afw  14.0-49-g535656444+1
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  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  SimpleRecord(const SimpleRecord&) = delete;
76  SimpleRecord& operator=(const SimpleRecord&) = delete;
77  SimpleRecord(SimpleRecord&&) = delete;
78  SimpleRecord& operator=(SimpleRecord&&) = delete;
79  ~SimpleRecord();
80 
81 protected:
82  friend class SimpleTable;
83 
84  explicit SimpleRecord(std::shared_ptr<SimpleTable> const& table);
85 };
86 
92 class SimpleTable : public BaseTable {
93 public:
98 
109  static std::shared_ptr<SimpleTable> make(Schema const& schema,
111 
120  return make(schema, IdFactory::makeSimple());
121  }
122 
131  Schema r = getMinimalSchema().schema;
132  r.disconnectAliases();
133  return r;
134  }
135 
142  static bool checkSchema(Schema const& other) { return other.contains(getMinimalSchema().schema); }
143 
145  std::shared_ptr<IdFactory> getIdFactory() { return _idFactory; }
146 
148  std::shared_ptr<IdFactory const> getIdFactory() const { return _idFactory; }
149 
151  void setIdFactory(std::shared_ptr<IdFactory> f) { _idFactory = f; }
152 
154 
159  static Key<RecordId> getIdKey() { return getMinimalSchema().id; }
162  static CoordKey getCoordKey() { return getMinimalSchema().coord; }
164 
167 
170  return std::static_pointer_cast<SimpleRecord>(_makeRecord());
171  }
172 
176  }
177 
181  }
182 
183  SimpleTable& operator=(SimpleTable const&) = delete;
184  SimpleTable& operator=(SimpleTable&&) = delete;
185  ~SimpleTable();
186 
187 protected:
189 
190  explicit SimpleTable(SimpleTable const& other);
191  explicit SimpleTable(SimpleTable && other);
192 
193  std::shared_ptr<BaseTable> _clone() const override;
194 
195  std::shared_ptr<BaseRecord> _makeRecord() override;
196 
197 private:
198  // Struct that holds the minimal schema and the special keys we've added to it.
199  struct MinimalSchema {
200  Schema schema;
201  Key<RecordId> id;
202  CoordKey coord;
203 
204  MinimalSchema();
205  };
206 
207  // Return the singleton minimal schema.
208  static MinimalSchema& getMinimalSchema();
209 
210  friend class io::FitsWriter;
211 
212  // Return a writer object that knows how to save in FITS format. See also FitsWriter.
213  std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile, int flags) const override;
214 
215  std::shared_ptr<IdFactory> _idFactory; // generates IDs for new records
216 };
217 
218 inline RecordId SimpleRecord::getId() const { return get(SimpleTable::getIdKey()); }
219 inline void SimpleRecord::setId(RecordId id) { set(SimpleTable::getIdKey(), id); }
220 
222 inline void SimpleRecord::setCoord(IcrsCoord const& coord) { set(SimpleTable::getCoordKey(), coord); }
223 inline void SimpleRecord::setCoord(Coord const& coord) { SimpleTable::getCoordKey().set(*this, coord); }
224 
225 inline Angle SimpleRecord::getRa() const { return get(SimpleTable::getCoordKey().getRa()); }
226 inline void SimpleRecord::setRa(Angle ra) { set(SimpleTable::getCoordKey().getRa(), ra); }
227 
228 inline Angle SimpleRecord::getDec() const { return get(SimpleTable::getCoordKey().getDec()); }
229 inline void SimpleRecord::setDec(Angle dec) { set(SimpleTable::getCoordKey().getDec(), dec); }
230 }
231 }
232 } // namespace lsst::afw::table
233 
234 #endif // !AFW_TABLE_Simple_h_INCLUDED
Defines the fields and offsets for a table.
Definition: Schema.h:47
IcrsCoord getCoord() const
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:221
Writer object for FITS binary tables.
Definition: FitsWriter.h:25
virtual void set(BaseRecord &record, coord::IcrsCoord const &value) const
Set an IcrsCoord in the given record.
void setRa(Angle ra)
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:226
static Schema makeMinimalSchema()
Return a minimal schema for Simple tables and records.
Definition: Simple.h:130
RecordId getId() const
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:218
static bool checkSchema(Schema const &other)
Return true if the given schema is a valid SimpleTable schema.
Definition: Simple.h:142
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:97
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:179
static Key< RecordId > getIdKey()
Get keys for standard fields shared by all references.
Definition: Simple.h:160
void disconnectAliases()
Sever the connection between this schema and any others with which it shares aliases.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:298
Angle getRa() const
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:225
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:151
SortedCatalogT< Record > Catalog
Definition: Simple.h:96
Table class that must contain a unique ID field and a celestial coordinate field. ...
Definition: Simple.h:92
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:174
int contains(Schema const &other, int flags=EQUAL_KEYS) const
Test whether the given schema is a subset of this.
static std::shared_ptr< IdFactory > makeSimple()
Return a simple IdFactory that simply counts from 1.
std::shared_ptr< IdFactory const > getIdFactory() const
Return the object that generates IDs for the table (may be null).
Definition: Simple.h:148
void setDec(Angle dec)
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:229
T static_pointer_cast(T... args)
ColumnViewT< SimpleRecord > ColumnView
Definition: Simple.h:51
ColumnViewT< SimpleRecord > ColumnView
Definition: Simple.h:95
SimpleRecord & operator=(const SimpleRecord &)=delete
Key< geom::Angle > getDec() const
Return a constituent Key.
Definition: aggregates.h:259
std::shared_ptr< BaseTable const > getTable() const
Return the table this record is associated with.
Definition: BaseRecord.h:55
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:29
std::shared_ptr< SimpleTable > clone() const
Return a polymorphic deep copy of the table.
Definition: Simple.h:166
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:169
friend class SimpleTable
Definition: Simple.h:82
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:219
Angle getDec() const
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:228
This is the base class for spherical coordinates.
Definition: Coord.h:63
Key< geom::Angle > getRa() const
Return a constituent Key.
Definition: aggregates.h:258
void setCoord(IcrsCoord const &coord)
Convenience accessors for the keys in the minimal reference schema.
Definition: Simple.h:222
static CoordKey getCoordKey()
Key for the celestial coordinates.
Definition: Simple.h:162
std::shared_ptr< IdFactory > getIdFactory()
Return the object that generates IDs for the table (may be null).
Definition: Simple.h:145
A class to handle Icrs coordinates (inherits from Coord)
Definition: Coord.h:291
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:119