Skip to content
Snippets Groups Projects
Commit e2fa2574 authored by Kipp Cannon's avatar Kipp Cannon
Browse files

snglinspiraltable: performance

- move performance-critical methods to the C layer
parent 7bfa6e0e
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,7 @@
#include <Python.h>
#include <numpy/ndarrayobject.h>
#include <structmember.h>
#include <lal/Date.h>
#include <lal/TimeSeries.h>
#include <lal/Units.h>
......@@ -39,6 +40,9 @@
#include <snglinspiralrowtype.h>
static PyObject *LIGOTimeGPSType = NULL;
/*
* ============================================================================
*
......@@ -165,6 +169,63 @@ static int pylal_inline_string_set(PyObject *obj, PyObject *val, void *data)
}
static PyObject *end_get(PyObject *obj, void *null)
{
return PyObject_CallFunction(LIGOTimeGPSType, "ii", ((gstlal_GSTLALSnglInspiral *) obj)->row.end.gpsSeconds, ((gstlal_GSTLALSnglInspiral *) obj)->row.end.gpsNanoSeconds);
}
static int end_set(PyObject *obj, PyObject *val, void *null)
{
int end_time, end_time_ns;
PyObject *converted = PyObject_CallFunctionObjArgs(LIGOTimeGPSType, val, NULL);
PyObject *attr = NULL;;
if(!converted)
goto error;
attr = PyObject_GetAttrString(converted, "gpsSeconds");
if(!attr)
goto error;
end_time = PyInt_AsLong(attr);
Py_DECREF(attr);
attr = PyObject_GetAttrString(converted, "gpsNanoSeconds");
if(!attr)
goto error;
end_time_ns = PyInt_AsLong(attr);
Py_DECREF(attr);
Py_DECREF(converted);
XLALGPSSet(&((gstlal_GSTLALSnglInspiral *) obj)->row.end, end_time, end_time_ns);
return 0;
error:
Py_XDECREF(converted);
Py_XDECREF(attr);
return -1;
}
static PyObject *template_id_get(PyObject *obj, void *null)
{
return PyInt_FromLong(((gstlal_GSTLALSnglInspiral *) obj)->row.Gamma[0]);
}
static int template_id_set(PyObject *obj, PyObject *val, void *null)
{
int template_id = PyInt_AsLong(val);
if(template_id == -1 && PyErr_Occurred())
return -1;
((gstlal_GSTLALSnglInspiral *) obj)->row.Gamma[0] = template_id;
return 0;
}
static PyObject *snr_component_get(PyObject *obj, void *data)
{
COMPLEX8TimeSeries *snr = ((gstlal_GSTLALSnglInspiral *) obj)->snr;
......@@ -209,6 +270,8 @@ static struct PyGetSetDef getset[] = {
{"ifo", pylal_inline_string_get, pylal_inline_string_set, "ifo", &(struct pylal_inline_string_description) {offsetof(gstlal_GSTLALSnglInspiral, row.ifo), LIGOMETA_IFO_MAX}},
{"search", pylal_inline_string_get, pylal_inline_string_set, "search", &(struct pylal_inline_string_description) {offsetof(gstlal_GSTLALSnglInspiral, row.search), LIGOMETA_SEARCH_MAX}},
{"channel", pylal_inline_string_get, pylal_inline_string_set, "channel", &(struct pylal_inline_string_description) {offsetof(gstlal_GSTLALSnglInspiral, row.channel), LIGOMETA_CHANNEL_MAX}},
{"end", end_get, end_set, "end", NULL},
{"template_id", template_id_get, template_id_set, "template_id", NULL},
{"_snr_name", snr_component_get, NULL, ".snr.name", "_snr_name"},
{"_snr_epoch_gpsSeconds", snr_component_get, NULL, ".snr.epoch.gpsSeconds", "_snr_epoch_gpsSeconds"},
{"_snr_epoch_gpsNanoSeconds", snr_component_get, NULL, ".snr.epoch.gpsNanoSeconds", "_snr_epoch_gpsNanoSeconds"},
......@@ -381,6 +444,21 @@ PyMODINIT_FUNC init_snglinspiraltable(void)
import_array();
/* LIGOTimeGPS */
{
PyObject *lal = PyImport_ImportModule("lal");
if(!lal)
return;
LIGOTimeGPSType = PyDict_GetItemString(PyModule_GetDict(lal), "LIGOTimeGPS");
if(!LIGOTimeGPSType) {
Py_DECREF(lal);
return;
}
Py_INCREF(LIGOTimeGPSType);
Py_DECREF(lal);
}
/* SnglInspiralTable */
if(PyType_Ready(&gstlal_GSTLALSnglInspiral_Type) < 0)
return;
......
......@@ -30,7 +30,6 @@ class GSTLALSnglInspiral(_snglinspiraltable.GSTLALSnglInspiral):
process_id_type = ilwd.get_ilwdchar_class("process", "process_id")
event_id_type = ilwd.get_ilwdchar_class("sngl_inspiral", "event_id")
end = lsctables.gpsproperty("end_time", "end_time_ns")
spin1 = lsctables.SnglInspiral.spin1
spin2 = lsctables.SnglInspiral.spin2
......@@ -83,16 +82,3 @@ class GSTLALSnglInspiral(_snglinspiraltable.GSTLALSnglInspiral):
@snr_time_series.deleter
def snr_time_series(self):
self._snr_time_series_deleter()
#
# simulate template_id column
# FIXME: add a proper column for this
#
@property
def template_id(self):
return int(self.Gamma0)
@template_id.setter
def template_id(self, template_id):
self.Gamma0 = float(template_id)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment