LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
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);
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 
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.
#define PTR(...)
Definition: base.h:41
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::Key< afw::table::Point< int > > dimensions
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::Key< afw::table::Array< int > > spatialFunctions
Include files required for standard LSST Exception handling.
std::vector< SpatialFunctionPtr > readSpatialFunctions(afw::table::io::InputArchive const &archive, afw::table::BaseRecord const &record) const
tbl::Schema schema
Definition: CoaddPsf.cc:324
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
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
Definition: Persistable.h:47
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
dictionary Point
Definition: __init__.py:38
afw::table::SourceRecord * record