LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
KernelPersistenceHelper.cc
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 #include "lsst/pex/exceptions.h"
26 #include "lsst/afw/math/Kernel.h"
28 
29 namespace lsst { namespace afw { namespace math {
30 
32  schema(),
33  dimensions(
34  afw::table::PointKey<int>::addFields(
35  schema, "dimensions", "dimensions of a Kernel's images", "pixels"
36  )
37  ),
38  center(
39  afw::table::PointKey<int>::addFields(schema, "center", "center point in a Kernel image", "pixels")
40  )
41 {
42  if (nSpatialFunctions > 0) {
44  "spatialfunctions", "archive IDs for the Kernel's spatial functions", nSpatialFunctions
45  );
46  }
47 }
48 
50  schema(schema_),
51  dimensions(schema["dimensions"]),
52  center(schema["center"])
53 {
54  try {
55  spatialFunctions = schema["spatialfunctions"];
56  } catch (...) {}
57 }
58 
60  afw::table::io::OutputArchiveHandle & handle,
61  Kernel const & kernel
62 ) const {
63  afw::table::BaseCatalog catalog = handle.makeCatalog(schema);
64  PTR(afw::table::BaseRecord) record = catalog.addNew();
65  record->set(dimensions, geom::Point2I(kernel.getDimensions()));
66  record->set(center, kernel.getCtr());
67  if (spatialFunctions.isValid()) {
68  writeSpatialFunctions(handle, *record, kernel._spatialFunctionList);
69  }
70  handle.saveCatalog(catalog);
71  return record;
72 }
73 
76  afw::table::BaseRecord & record,
77  std::vector<PTR(Kernel::SpatialFunction)> const & spatialFunctionList
78 ) const {
79  ndarray::Array<int,1,1> array = record[spatialFunctions];
80  for (std::size_t n = 0; n < spatialFunctionList.size(); ++n) {
81  array[n] = handle.put(spatialFunctionList[n]);
82  }
83 }
84 
85 std::vector<PTR(Kernel::SpatialFunction)> Kernel::PersistenceHelper::readSpatialFunctions(
86  afw::table::io::InputArchive const & archive,
87  afw::table::BaseRecord const & record
88 ) const {
89  ndarray::Array<int const,1,1> array = record[spatialFunctions];
90  std::vector<PTR(Kernel::SpatialFunction)> spatialFunctionList(array.getSize<0>());
91  for (std::size_t n = 0; n < spatialFunctionList.size(); ++n) {
92  spatialFunctionList[n] = archive.get<SpatialFunction>(array[n]);
93  LSST_ARCHIVE_ASSERT(array[n] == 0 || (spatialFunctionList[n]));
94  }
95  return spatialFunctionList;
96 }
97 
98 }}} // namespace lsst::afw::math
Defines the fields and offsets for a table.
Definition: Schema.h:46
Declare the Kernel class and subclasses.
int put(Persistable const *obj, bool permissive=false)
Save a nested Persistable to the same archive.
An object passed to Persistable::write to allow it to persist itself.
A custom container class for records, based on std::vector.
Definition: Catalog.h:94
afw::table::Schema schema
Definition: GaussianPsf.cc:41
Include files required for standard LSST Exception handling.
#define PTR(...)
Definition: base.h:41
Key< T > addField(Field< T > const &field, bool doReplace=false)
Add a new field to the Schema, and return the associated Key.
int getSize() const
Return the size of a specific dimension.
Definition: ArrayBase.h:126
std::map< Citizen const *, CitizenInfo > table
Definition: Citizen.h:93
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:42
afw::table::Key< afw::table::Array< int > > spatialFunctions
std::vector< SpatialFunctionPtr > readSpatialFunctions(afw::table::io::InputArchive const &archive, afw::table::BaseRecord const &record) const
Tag types used to declare specialized field types.
Definition: misc.h:35
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
Definition: Persistable.h:47
Base class for all records.
Definition: BaseRecord.h:27
boost::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
Definition: Catalog.h:469
void writeSpatialFunctions(afw::table::io::OutputArchiveHandle &handle, afw::table::BaseRecord &record, std::vector< SpatialFunctionPtr > const &spatialFunctionList) const
boost::shared_ptr< Persistable > get(int id) const
Load the Persistable with the given ID and return it.
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:28
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:134