source: sasview/src/sas/models/c_extension/c_smearer/smearer2d_helper_module.cpp @ 9701348

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 9701348 was 79492222, checked in by krzywon, 10 years ago

Changed the file and folder names to remove all SANS references.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/**
2  Smearer module to perform point and slit smearing calculations
3
4        This software was developed by the University of Tennessee as part of the
5        Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
6        project funded by the US National Science Foundation.
7
8        See the license text in license.txt
9
10        copyright 2009, University of Tennessee
11 */
12#include <Python.h>
13#include <stdio.h>
14#include <smearer2d_helper.hh>
15
16// Utilities
17#define INVECTOR(obj,buf,len)                                                                           \
18    do { \
19        int err = PyObject_AsReadBuffer(obj, (const void **)(&buf), &len); \
20        if (err < 0) return NULL; \
21        len /= sizeof(*buf); \
22    } while (0)
23
24#define OUTVECTOR(obj,buf,len) \
25    do { \
26        int err = PyObject_AsWriteBuffer(obj, (void **)(&buf), &len); \
27        if (err < 0) return NULL; \
28        len /= sizeof(*buf); \
29    } while (0)
30
31
32/**
33 * Delete a Smearer2d object
34 */
35void del_smearer2d_helper(void *ptr){
36        Smearer_helper* smearer2d_helper = static_cast<Smearer_helper *>(ptr);
37        delete smearer2d_helper;
38        return;
39}
40
41/**
42 * Create a QSmearer as a python object by supplying a q array
43 */
44PyObject * new_Smearer_helper(PyObject *, PyObject *args) {
45        PyObject *qx_values_obj;
46        PyObject *qy_values_obj;
47        PyObject *dqx_values_obj;
48        PyObject *dqy_values_obj;
49        Py_ssize_t n_q;
50        //PyObject rlimit_obj;
51        //PyObject npoints_obj;
52        //PyObject nrbins_obj;
53        //PyObject nphibins_obj;
54        double* qx_values;
55        double* qy_values;
56        double* dqx_values;
57        double* dqy_values;
58        double rlimit;
59        int npoints;
60        int nrbins;
61        int nphibins;
62
63
64        if (!PyArg_ParseTuple(args, "OOOOdiii", &qx_values_obj, &qy_values_obj, &dqx_values_obj, &dqy_values_obj, &rlimit, &nrbins, &nphibins, &npoints)) return NULL;
65        OUTVECTOR(qx_values_obj, qx_values, n_q);
66        OUTVECTOR(qy_values_obj, qy_values, n_q);
67        OUTVECTOR(dqx_values_obj, dqx_values, n_q);
68        OUTVECTOR(dqy_values_obj, dqy_values, n_q);
69        Smearer_helper* smearer2d_helper = new Smearer_helper(npoints,qx_values,qy_values,dqx_values,dqy_values, rlimit, nrbins, nphibins);
70        return PyCObject_FromVoidPtr(smearer2d_helper, del_smearer2d_helper);
71}
72
73/**
74 * Smear the given input according to a given smearer object
75 */
76PyObject * smear2d_input(PyObject *, PyObject *args) {
77        PyObject *weights_obj;
78        Py_ssize_t w_out;
79        double *weights;
80        PyObject *qx_out_obj;
81        Py_ssize_t n_out;
82        double *qx_out;
83        PyObject *qy_out_obj;
84        //Py_ssize_t n_out;
85        double *qy_out;
86        PyObject *smear_obj;
87
88        if (!PyArg_ParseTuple(args, "OOOO",  &smear_obj, &weights_obj, &qx_out_obj, &qy_out_obj)) return NULL;
89        OUTVECTOR(weights_obj, weights, w_out);
90        OUTVECTOR(qx_out_obj, qx_out, n_out);
91        OUTVECTOR(qy_out_obj, qy_out, n_out);
92
93        // Sanity check
94        //if(n_in!=n_out) return Py_BuildValue("i",-1);
95
96        // Set the array pointers
97        void *temp = PyCObject_AsVoidPtr(smear_obj);
98        Smearer_helper* s = static_cast<Smearer_helper *>(temp);
99
100        s->smear2d(weights, qx_out, qy_out);
101        //return PyCObject_FromVoidPtr(s, del_smearer2d_helper);
102        return Py_BuildValue("i",1);
103}
104
105
106/**
107 * Define module methods
108 */
109static PyMethodDef module_methods[] = {
110        {"new_Smearer_helper", (PyCFunction)new_Smearer_helper, METH_VARARGS,
111                  "Create a new Q Smearer object"},
112        {"smearer2d_helper",(PyCFunction)smear2d_input, METH_VARARGS,
113                  "Smear the given input array"},
114    {NULL}
115};
116
117
118#ifndef PyMODINIT_FUNC  /* declarations for DLL import/export */
119#define PyMODINIT_FUNC void
120#endif
121PyMODINIT_FUNC
122initsmearer2d_helper(void)
123{
124    PyObject* m;
125
126    m = Py_InitModule3("smearer2d_helper", module_methods,
127                       "Smearer2d_helper module");
128}
Note: See TracBrowser for help on using the repository browser.