lsst.afw  14.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
fits.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008-2016 AURA/LSST.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <https://www.lsstcorp.org/LegalNotices/>.
21  */
22 
23 #include <pybind11/pybind11.h>
24 //#include <pybind11/operators.h>
25 //#include <pybind11/stl.h>
26 
27 #include "lsst/pex/exceptions/Exception.h"
28 #include "lsst/pex/exceptions/Runtime.h"
29 #include "lsst/pex/exceptions/python/Exception.h"
30 
31 #include "lsst/afw/fits.h"
32 
33 namespace py = pybind11;
34 
35 using namespace lsst::afw::fits;
36 
38  py::module mod("_fits", "Python wrapper for afw _fits library");
39 
40  py::class_<MemFileManager> clsMemFileManager(mod, "MemFileManager");
41 
42  lsst::pex::exceptions::python::declareException<FitsError, lsst::pex::exceptions::IoError>(
43  mod, "FitsError", "IoError");
44  // lsst::pex::exceptions::python::declareException<FitsTypeError, FitsError>(mod, "FitsTypeError",
45  // "FitsError");
46 
47  clsMemFileManager.def(py::init<>());
48  clsMemFileManager.def(py::init<size_t>());
49 
50  /* TODO: We should really revisit persistence and pickling as this is quite ugly.
51  * But it is what Swig did (sort of, it used the cdata.i extension), so I reckon this
52  * is cleaner because it does not expose casting to the Python side. */
53  clsMemFileManager.def("getLength", &MemFileManager::getLength);
54  clsMemFileManager.def("getData", [](MemFileManager &m) {
55  return py::bytes(static_cast<char *>(m.getData()), m.getLength());
56  });
57  clsMemFileManager.def("setData", [](MemFileManager &m, py::bytes const &d, size_t size) {
58  memcpy(m.getData(), PyBytes_AsString(d.ptr()), size);
59  });
60 
61  /* Module level */
62 
63  /* Member types and enums */
64 
65  /* Constructors */
66 
67  /* Operators */
68 
69  /* Members */
70 
71  return mod.ptr();
72 }
std::size_t getLength() const
Return the buffer length.
Definition: fits.h:173
PYBIND11_PLUGIN(_cameraPoint)
Definition: cameraPoint.cc:35
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:100
void * getData() const
Return the buffer.
Definition: fits.h:170