29 namespace lsst {
namespace afw {
namespace detection {
43 class PeakRecordImpl :
public PeakRecord {
46 explicit PeakRecordImpl(
PTR(PeakTable)
const & table) : PeakRecord(table) {}
50 class PeakTableImpl :
public PeakTable {
53 explicit PeakTableImpl(afw::table::Schema
const &
schema,
PTR(afw::table::IdFactory)
const & idFactory) :
54 PeakTable(schema, idFactory)
57 PeakTableImpl(PeakTableImpl
const & other) : PeakTable(other) {}
61 virtual PTR(afw::table::BaseTable) _clone()
const {
62 return boost::make_shared<PeakTableImpl>(*this);
65 virtual PTR(afw::table::BaseRecord) _makeRecord() {
66 PTR(PeakRecord) record = boost::make_shared<PeakRecordImpl>(getSelf<PeakTableImpl>());
67 if (getIdFactory()) record->setId((*getIdFactory())());
84 class PeakFitsWriter :
public afw::table::io::FitsWriter {
87 explicit PeakFitsWriter(Fits * fits,
int flags) : afw::table::io::FitsWriter(fits, flags) {}
91 virtual void _writeTable(
CONST_PTR(afw::table::BaseTable)
const & table, std::size_t nRows);
95 void PeakFitsWriter::_writeTable(
CONST_PTR(afw::table::BaseTable)
const & t, std::size_t nRows) {
96 CONST_PTR(PeakTable) table = boost::dynamic_pointer_cast<PeakTable const>(t);
99 lsst::pex::exceptions::LogicError,
100 "Cannot use a PeakFitsWriter on a non-Peak table."
104 _fits->writeKey(
"AFW_TYPE",
"PEAK",
"Tells lsst::afw to load this as a Peak table.");
118 class PeakFitsReader :
public afw::table::io::FitsReader {
121 PeakFitsReader() : afw::table::io::FitsReader(
"PEAK") {}
123 virtual PTR(afw::table::BaseTable) makeTable(
124 afw::table::io::FitsSchemaInputMapper & mapper,
129 PTR(PeakTable) table = PeakTable::make(mapper.finalize());
130 table->setMetadata(metadata);
137 static PeakFitsReader const peakFitsReader;
155 afw::
table::Schema const & schema,
158 typedef std::list< boost::weak_ptr<PeakTable> > CachedTableList;
159 static CachedTableList cache;
160 if (!checkSchema(schema)) {
162 lsst::pex::exceptions::InvalidParameterError,
163 "Schema for Peak must contain at least the keys defined by makeMinimalSchema()."
169 CachedTableList::iterator
iter = cache.begin();
170 while (iter != cache.end()) {
173 iter = cache.erase(iter);
179 if (iter != cache.begin()) {
180 cache.splice(cache.begin(), cache,
iter);
188 PTR(
PeakTable) newTable = boost::make_shared<PeakTableImpl>(
191 cache.push_front(newTable);
196 afw::
table::BaseTable(schema), _idFactory(idFactory) {}
199 afw::
table::BaseTable(other),
200 _idFactory(other._idFactory ? other._idFactory->clone() : other._idFactory) {}
204 fx = schema.
addField<
float>(
"f_x",
"subpixel column position",
"pixels");
205 fy = schema.
addField<
float>(
"f_y",
"subpixel row position",
"pixels");
206 ix = schema.
addField<
int>(
"i_x",
"column position of highest pixel",
"pixels");
207 iy = schema.
addField<
int>(
"i_y",
"row position of highest pixel",
"pixels");
208 peakValue = schema.
addField<
float>(
"peakValue",
"value of [smoothed] image at peak position",
"dn");
219 return boost::make_shared<PeakFitsWriter>(fitsfile, flags);
227 template class CatalogT<afw::detection::PeakRecord>;
228 template class CatalogT<afw::detection::PeakRecord const>;
daf::base::Citizen & getCitizen()
Get the Citizen corresponding to this Schema (SchemaImpl is what inherits from Citizen).
Defines the fields and offsets for a table.
afw::table::Key< float > peakValue
Writer object for FITS binary tables.
PeakTable(afw::table::Schema const &schema, boost::shared_ptr< afw::table::IdFactory > const &idFactory)
std::ostream & operator<<(std::ostream &os, PeakRecord const &record)
afw::table::Key< int > ix
afw::table::Key< float > fy
virtual boost::shared_ptr< afw::table::io::FitsWriter > makeFitsWriter(fits::Fits *fitsfile, int flags) const
Class for storing ordered metadata with comments.
afw::table::Schema schema
Table class for Peaks in Footprints.
static boost::shared_ptr< IdFactory > makeSimple()
Return a simple IdFactory that simply counts from 1.
Key< T > addField(Field< T > const &field, bool doReplace=false)
Add a new field to the Schema, and return the associated Key.
std::map< Citizen const *, CitizenInfo > table
afw::table::Key< float > fx
int getIy() const
Convenience accessors for the keys in the minimal schema.
void markPersistent(void)
Mark a Citizen as persistent and not destroyed until process end.
int getIx() const
Convenience accessors for the keys in the minimal schema.
if(width!=gim.getWidth()||height!=gim.getHeight()||x0!=gim.getX0()||y0!=gim.getY0())
afw::table::Key< int > iy
A polymorphic functor base class for generating record IDs for a table.
#define LSST_EXCEPT(type,...)
float getFy() const
Convenience accessors for the keys in the minimal schema.
float getFx() const
Convenience accessors for the keys in the minimal schema.
virtual void _writeTable(boost::shared_ptr< BaseTable const > const &table, std::size_t nRows)
Write a table and its schema.
Record class that represents a peak in a Footprint.
static MinimalSchema & getMinimalSchema()
boost::int64_t RecordId
Type used for unique IDs for records.
afw::table::RecordId getId() const
Convenience accessors for the keys in the minimal schema.