LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
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(schema.addField< afw::table::Point<int> >("dimensions", "dimensions of a Kernel's images")),
34  center(schema.addField< afw::table::Point<int> >("center", "center point in a Kernel image"))
35 {
36  if (nSpatialFunctions > 0) {
38  "spatialfunctions", "archive IDs for the Kernel's spatial functions", nSpatialFunctions
39  );
40  }
41 }
42 
44  schema(schema_),
45  dimensions(schema["dimensions"]),
46  center(schema["center"])
47 {
48  try {
49  spatialFunctions = schema["spatialfunctions"];
50  } catch (...) {}
51 }
52 
54  afw::table::io::OutputArchiveHandle & handle,
55  Kernel const & kernel
56 ) const {
57  afw::table::BaseCatalog catalog = handle.makeCatalog(schema);
58  PTR(afw::table::BaseRecord) record = catalog.addNew();
59  record->set(dimensions, geom::Point2I(kernel.getDimensions()));
60  record->set(center, kernel.getCtr());
61  if (spatialFunctions.isValid()) {
62  writeSpatialFunctions(handle, *record, kernel._spatialFunctionList);
63  }
64  handle.saveCatalog(catalog);
65  return record;
66 }
67 
70  afw::table::BaseRecord & record,
71  std::vector<PTR(Kernel::SpatialFunction)> const & spatialFunctionList
72 ) const {
73  ndarray::Array<int,1,1> array = record[spatialFunctions];
74  for (std::size_t n = 0; n < spatialFunctionList.size(); ++n) {
75  array[n] = handle.put(spatialFunctionList[n]);
76  }
77 }
78 
79 std::vector<PTR(Kernel::SpatialFunction)> Kernel::PersistenceHelper::readSpatialFunctions(
80  afw::table::io::InputArchive const & archive,
81  afw::table::BaseRecord const & record
82 ) const {
83  ndarray::Array<int const,1,1> array = record[spatialFunctions];
84  std::vector<PTR(Kernel::SpatialFunction)> spatialFunctionList(array.getSize<0>());
85  for (std::size_t n = 0; n < spatialFunctionList.size(); ++n) {
86  spatialFunctionList[n] = archive.get<SpatialFunction>(array[n]);
87  LSST_ARCHIVE_ASSERT(array[n] == 0 || (spatialFunctionList[n]));
88  }
89  return spatialFunctionList;
90 }
91 
92 }}} // namespace lsst::afw::math
Defines the fields and offsets for a table.
Definition: Schema.h:46
Declare the Kernel class and subclasses.
An object passed to Persistable::write to allow it to persist itself.
int put(Persistable const *obj, bool permissive=false)
Save a nested Persistable to the same archive.
A custom container class for records, based on std::vector.
Definition: Catalog.h:94
afw::table::Key< afw::table::Point< int > > dimensions
afw::table::Key< afw::table::Array< int > > spatialFunctions
#define PTR(...)
Definition: base.h:41
int getSize() const
Return the size of a specific dimension.
Definition: ArrayBase.h:126
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
boost::shared_ptr< Persistable > get(int id) const
Load the Persistable with the given ID and return it.
tbl::Schema schema
Definition: CoaddPsf.cc:324
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
std::vector< SpatialFunctionPtr > readSpatialFunctions(afw::table::io::InputArchive const &archive, afw::table::BaseRecord const &record) const
Key< T > addField(Field< T > const &field, bool doReplace=false)
Add a new field to the Schema, and return the associated Key.
Base class for all records.
Definition: BaseRecord.h:27
void writeSpatialFunctions(afw::table::io::OutputArchiveHandle &handle, afw::table::BaseRecord &record, std::vector< SpatialFunctionPtr > const &spatialFunctionList) const
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
Definition: Persistable.h:47
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:28
std::map< Citizen const *, CitizenInfo > table
Definition: Citizen.h:93
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:134
dictionary Point
Definition: __init__.py:38
Include files required for standard LSST Exception handling.