24 struct ProcessSchema {
26 void operator()(SchemaItem<T>
const& item)
const {
30 if (!item.field.getDoc().empty()) {
34 fits->writeColumnKey(
"TDOC", n, item.field.getDoc());
39 void operator()(SchemaItem<std::string>
const& item)
const {
41 int n =
fits->addColumn<
std::string>(
name, item.field.getElementCount(), item.field.getDoc());
42 if (!item.field.getDoc().empty()) {
43 fits->writeColumnKey(
"TDOC", n, item.field.getDoc());
48 void operator()(SchemaItem<Flag>
const& item)
const {
51 if (!item.field.getDoc().empty()) {
55 fits->writeColumnKey(
"TFDOC",
nFlags, item.field.getDoc());
61 static void apply(Fits&
fits, Schema
const&
schema) {
62 ProcessSchema f = {&
fits, 0};
67 void specialize(SchemaItem<T>
const& item,
int n)
const {
68 if (!item.field.getUnits().empty()) fits->writeColumnKey(
"TUNIT", n, item.field.getUnits());
69 fits->writeColumnKey(
"TCCLS", n,
"Scalar",
"Field template used by lsst.afw.table");
72 void specialize(SchemaItem<lsst::geom::Angle>
const& item,
int n)
const {
75 fits->writeColumnKey(
"TUNIT", n,
"rad");
76 fits->writeColumnKey(
"TCCLS", n,
"Angle",
"Field template used by lsst.afw.table");
80 void specialize(SchemaItem<Array<T> >
const& item,
int n)
const {
81 if (!item.field.getUnits().empty()) fits->writeColumnKey(
"TUNIT", n, item.field.getUnits());
82 fits->writeColumnKey(
"TCCLS", n,
"Array",
"Field template used by lsst.afw.table");
85 void specialize(SchemaItem<std::string>
const& item,
int n)
const {
86 if (!item.field.getUnits().empty()) fits->writeColumnKey(
"TUNIT", n, item.field.getUnits());
87 fits->writeColumnKey(
"TCCLS", n,
"String",
"Field template used by lsst.afw.table");
94 void writeAliasMap(Fits& fits, AliasMap
const& aliases) {
96 fits.writeKey(
"ALIAS", i->first +
":" + i->second);
104 Schema schema = table->getSchema();
105 _fits->createTable();
109 int n = _fits->addColumn<
bool>(
"flags",
nFlags,
"bits for all Flag fields; see also TFLAGn");
110 _fits->writeKey(
"FLAGCOL", n + 1,
"Column number for the bitflags.");
112 ProcessSchema::apply(*_fits, schema);
117 metadata = std::make_shared<daf::base::PropertyList>();
120 _fits->writeMetadata(*metadata);
122 metadata->remove(
"AFW_TABLE_VERSION");
124 _fits->addRows(nRows);
125 _processor = std::make_shared<ProcessRecords>(_fits,
schema,
nFlags, _row);
137 template <
typename T>
139 fits->writeTableArray(
row,
col, item.
key.getElementCount(), record->getElement(item.
key));
143 template <
typename T>
145 if (item.key.isVariableLength()) {
146 ndarray::Array<T const, 1, 1> array = record->get(item.key);
147 fits->writeTableArray(
row,
col, array.template getSize<0>(), array.getData());
149 fits->writeTableArray(
row,
col, item.key.getElementCount(), record->getElement(item.key));
156 fits->writeTableScalar(
row,
col, record->get(item.
key));
161 flags[bit] = record->get(item.
key);
166 :
row(row_),
col(0), bit(0),
nFlags(nFlags_), fits(fits_), schema(schema_) {
175 schema.forEach(*
this);
191 _processor->apply(&record);
Defines the fields and offsets for a table.
#define LSST_FITS_CHECK_STATUS(fitsObj,...)
Throw a FitsError exception if the status of the given Fits object is nonzero.
std::unique_ptr< bool[]> flags
void operator()(SchemaItem< std::string > const &item) const
BaseRecord const * record
A base class for image defects.
void apply(BaseRecord const *r)
Tag types used to declare specialized field types.
int getFlagFieldCount() const
The number of Flag fields.
void operator()(SchemaItem< T > const &item) const
ProcessRecords(Fits *fits_, Schema const &schema_, int nFlags_, std::size_t const &row_)
virtual void _writeTable(std::shared_ptr< BaseTable const > const &table, std::size_t nRows)
Write a table and its schema.
void operator()(SchemaItem< Array< T > > const &item) const
std::shared_ptr< AliasMap > getAliasMap() const
Return the map of aliases.
Base class for all records.
virtual void _writeRecord(BaseRecord const &source)
Write an individual record.
FieldBase< T >::Element Element
Type used to store field data in the table (a field may have multiple elements).
std::map< std::string, std::string >::const_iterator Iterator
An iterator over alias->target pairs.
void operator()(SchemaItem< Flag > const &item) const
A simple pair-like struct for mapping a Field (name and description) with a Key (used for actual data...