diff --git a/gstlal-calibration/bin/gstlal_compute_strain b/gstlal-calibration/bin/gstlal_compute_strain index 38ec1fbd5e13c8dec96db38b587e8a14481ce354..1920c56e1fe25e511fe8a52c39523ced8ae46b49 100755 --- a/gstlal-calibration/bin/gstlal_compute_strain +++ b/gstlal-calibration/bin/gstlal_compute_strain @@ -2857,7 +2857,7 @@ if compute_srcq: mux = pipeparts.mkframecppchannelmux(pipeline, channelmux_input_dict, frame_duration = options.frame_duration, frames_per_file = options.frames_per_file, compression_scheme = int(OutputConfigs["compressionscheme"]), compression_level = int(OutputConfigs["compressionlevel"])) -# Check that all frames are long enough, that they have all of the channels by requring a certain amount of time from start-up, and that frames aren't written for times requested by the wings option +# Check that all frames are long enough, that they have all of the channels by requiring a certain amount of time from start-up, and that frames aren't written for times requested by the wings option def check_complete_frames(pad, info, (output_start, frame_duration, wings_start, wings_end)): if verbose: print("Checking if frames are complete") diff --git a/gstlal-calibration/gst/lal/gstlal_smoothkappas.c b/gstlal-calibration/gst/lal/gstlal_smoothkappas.c index 395aaf791c2a39a6209d9bd2ff11a23f4902b85d..52c182d4c81fb2c64e98ba2bb8ff4bd112394d43 100644 --- a/gstlal-calibration/gst/lal/gstlal_smoothkappas.c +++ b/gstlal-calibration/gst/lal/gstlal_smoothkappas.c @@ -236,7 +236,7 @@ static double get_average(double new_element, double *fifo_array, gint array_siz #define DEFINE_SMOOTH_BUFFER(DTYPE) \ -static GstFlowReturn smooth_buffer_ ## DTYPE(const DTYPE *src, guint64 src_size, DTYPE *dst, guint64 dst_size, double *fifo_array, double *avg_array, double default_kappa, double *current_median, double maximum_offset, gint array_size, gint avg_array_size, int *index_re, int *index_im, int *avg_index_re, int *avg_index_im, int *num_bad_in_avg_re, gboolean gap, gboolean default_to_median, gboolean track_bad_kappa, int waste_samples, int *samples_in_filter) { \ +static GstFlowReturn smooth_buffer_ ## DTYPE(const DTYPE *src, guint64 src_size, DTYPE *dst, guint64 dst_size, double *fifo_array, double *avg_array, double default_kappa, double *current_median, double maximum_offset, gint array_size, gint avg_array_size, int *index_re, int *index_im, int *avg_index_re, int *avg_index_im, int *num_bad_in_avg_re, gboolean gap, gboolean default_to_median, gboolean track_bad_kappa, int *samples_in_filter) { \ guint64 i; \ double new_element; \ DTYPE new_avg; \ @@ -281,7 +281,7 @@ static GstFlowReturn smooth_buffer_ ## DTYPE(const DTYPE *src, guint64 src_size, #define DEFINE_SMOOTH_COMPLEX_BUFFER(DTYPE) \ -static GstFlowReturn smooth_complex_buffer_ ## DTYPE(const DTYPE complex *src, guint64 src_size, DTYPE complex *dst, guint64 dst_size, double *fifo_array_re, double *fifo_array_im, double *avg_array_re, double *avg_array_im, double default_kappa_re, double default_kappa_im, double *current_median_re, double *current_median_im, double maximum_offset_re, double maximum_offset_im, gint array_size, gint avg_array_size, int *index_re, int *index_im, int *avg_index_re, int *avg_index_im, int *num_bad_in_avg_re, int *num_bad_in_avg_im, gboolean gap, gboolean default_to_median, gboolean track_bad_kappa, int waste_samples, int *samples_in_filter) { \ +static GstFlowReturn smooth_complex_buffer_ ## DTYPE(const DTYPE complex *src, guint64 src_size, DTYPE complex *dst, guint64 dst_size, double *fifo_array_re, double *fifo_array_im, double *avg_array_re, double *avg_array_im, double default_kappa_re, double default_kappa_im, double *current_median_re, double *current_median_im, double maximum_offset_re, double maximum_offset_im, gint array_size, gint avg_array_size, int *index_re, int *index_im, int *avg_index_re, int *avg_index_im, int *num_bad_in_avg_re, int *num_bad_in_avg_im, gboolean gap, gboolean default_to_median, gboolean track_bad_kappa, int *samples_in_filter) { \ guint64 i; \ double new_element_re, new_element_im; \ DTYPE complex new_avg; \ @@ -467,6 +467,59 @@ static gboolean start(GstBaseTransform *trans) } +/* + * sink_event() + */ + + +static gboolean sink_event(GstBaseTransform *trans, GstEvent *event) { + GSTLALSmoothKappas *element = GSTLAL_SMOOTHKAPPAS(trans); + gboolean success = TRUE; + GST_DEBUG_OBJECT(element, "Got %s event on sink pad", GST_EVENT_TYPE_NAME(event)); + + guint64 waste_samples = (guint64) (element->filter_latency * (element->array_size + element->avg_array_size - 2)); + if(GST_EVENT_TYPE(event) == GST_EVENT_EOS && waste_samples > 0) { + /* Trick the function by passing it fake input data */ + void *fake = g_malloc(waste_samples * element->unit_size); + void *data = g_malloc(waste_samples * element->unit_size); + GstFlowReturn result; + if(element->data_type == GSTLAL_SMOOTHKAPPAS_F32) { + result = smooth_buffer_float((float *) fake, waste_samples, (float *) data, waste_samples, element->fifo_array_re, element->avg_array_re, element->default_kappa_re, &element->current_median_re, element->maximum_offset_re, element->array_size, element->avg_array_size, &element->index_re, &element->index_im, &element->avg_index_re, &element->avg_index_im, &element->num_bad_in_avg_re, TRUE, element->default_to_median, element->track_bad_kappa, &element->samples_in_filter); + } else if(element->data_type == GSTLAL_SMOOTHKAPPAS_F64) { + result = smooth_buffer_double((double *) fake, waste_samples, (double *) data, waste_samples, element->fifo_array_re, element->avg_array_re, element->default_kappa_re, &element->current_median_re, element->maximum_offset_re, element->array_size, element->avg_array_size, &element->index_re, &element->index_im, &element->avg_index_re, &element->avg_index_im, &element->num_bad_in_avg_re, TRUE, element->default_to_median, element->track_bad_kappa, &element->samples_in_filter); + } else if(element->data_type == GSTLAL_SMOOTHKAPPAS_Z64) { + result = smooth_complex_buffer_float((float complex *) fake, waste_samples, (float complex *) data, waste_samples, element->fifo_array_re, element->fifo_array_im, element->avg_array_re, element->avg_array_im, element->default_kappa_re, element->default_kappa_im, &element->current_median_re, &element->current_median_im, element->maximum_offset_re, element->maximum_offset_im, element->array_size, element->avg_array_size, &element->index_re, &element->index_im, &element->avg_index_re, &element->avg_index_im, &element->num_bad_in_avg_re, &element->num_bad_in_avg_im, TRUE, element->default_to_median, element->track_bad_kappa, &element->samples_in_filter); + } else if(element->data_type == GSTLAL_SMOOTHKAPPAS_Z128) { + result = smooth_complex_buffer_double((double complex *) fake, waste_samples, (double complex *) data, waste_samples, element->fifo_array_re, element->fifo_array_im, element->avg_array_re, element->avg_array_im, element->default_kappa_re, element->default_kappa_im, &element->current_median_re, &element->current_median_im, element->maximum_offset_re, element->maximum_offset_im, element->array_size, element->avg_array_size, &element->index_re, &element->index_im, &element->avg_index_re, &element->avg_index_im, &element->num_bad_in_avg_re, &element->num_bad_in_avg_im, TRUE, element->default_to_median, element->track_bad_kappa, &element->samples_in_filter); + } else { + result = GST_FLOW_ERROR; + success = FALSE; + } + g_free(fake); + fake = NULL; + + if(result == GST_FLOW_OK) { + GstBuffer *buf; + buf = gst_buffer_new_wrapped(data, waste_samples * element->unit_size); + + set_metadata(element, buf, waste_samples); + + /* push buffer downstream */ + GST_DEBUG_OBJECT(element, "pushing final buffer %" GST_BUFFER_BOUNDARIES_FORMAT, GST_BUFFER_BOUNDARIES_ARGS(buf)); + result = gst_pad_push(element->srcpad, buf); + } + if(G_UNLIKELY(result != GST_FLOW_OK)) { + GST_WARNING_OBJECT(element, "push failed: %s", gst_flow_get_name(result)); + success = FALSE; + } + } + + success &= GST_BASE_TRANSFORM_CLASS(gstlal_smoothkappas_parent_class)->sink_event(trans, event); + + return success; +} + + /* * transform_size() */ @@ -569,13 +622,13 @@ static GstFlowReturn transform(GstBaseTransform *trans, GstBuffer *inbuf, GstBuf /* Process data in buffer */ if(element->data_type == GSTLAL_SMOOTHKAPPAS_F32) { - result = smooth_buffer_float((const float *) inmap.data, inmap.size / element->unit_size, (float *) outmap.data, outmap.size / element->unit_size, element->fifo_array_re, element->avg_array_re, element->default_kappa_re, &element->current_median_re, element->maximum_offset_re, element->array_size, element->avg_array_size, &element->index_re, &element->index_im, &element->avg_index_re, &element->avg_index_im, &element->num_bad_in_avg_re, gap, element->default_to_median, element->track_bad_kappa, waste_samples, &element->samples_in_filter); + result = smooth_buffer_float((const float *) inmap.data, inmap.size / element->unit_size, (float *) outmap.data, outmap.size / element->unit_size, element->fifo_array_re, element->avg_array_re, element->default_kappa_re, &element->current_median_re, element->maximum_offset_re, element->array_size, element->avg_array_size, &element->index_re, &element->index_im, &element->avg_index_re, &element->avg_index_im, &element->num_bad_in_avg_re, gap, element->default_to_median, element->track_bad_kappa, &element->samples_in_filter); } else if(element->data_type == GSTLAL_SMOOTHKAPPAS_F64) { - result = smooth_buffer_double((const double *) inmap.data, inmap.size / element->unit_size, (double *) outmap.data, outmap.size / element->unit_size, element->fifo_array_re, element->avg_array_re, element->default_kappa_re, &element->current_median_re, element->maximum_offset_re, element->array_size, element->avg_array_size, &element->index_re, &element->index_im, &element->avg_index_re, &element->avg_index_im, &element->num_bad_in_avg_re, gap, element->default_to_median, element->track_bad_kappa, waste_samples, &element->samples_in_filter); + result = smooth_buffer_double((const double *) inmap.data, inmap.size / element->unit_size, (double *) outmap.data, outmap.size / element->unit_size, element->fifo_array_re, element->avg_array_re, element->default_kappa_re, &element->current_median_re, element->maximum_offset_re, element->array_size, element->avg_array_size, &element->index_re, &element->index_im, &element->avg_index_re, &element->avg_index_im, &element->num_bad_in_avg_re, gap, element->default_to_median, element->track_bad_kappa, &element->samples_in_filter); } else if(element->data_type == GSTLAL_SMOOTHKAPPAS_Z64) { - result = smooth_complex_buffer_float((const float complex *) inmap.data, inmap.size / element->unit_size, (float complex *) outmap.data, outmap.size / element->unit_size, element->fifo_array_re, element->fifo_array_im, element->avg_array_re, element->avg_array_im, element->default_kappa_re, element->default_kappa_im, &element->current_median_re, &element->current_median_im, element->maximum_offset_re, element->maximum_offset_im, element->array_size, element->avg_array_size, &element->index_re, &element->index_im, &element->avg_index_re, &element->avg_index_im, &element->num_bad_in_avg_re, &element->num_bad_in_avg_im, gap, element->default_to_median, element->track_bad_kappa, waste_samples, &element->samples_in_filter); + result = smooth_complex_buffer_float((const float complex *) inmap.data, inmap.size / element->unit_size, (float complex *) outmap.data, outmap.size / element->unit_size, element->fifo_array_re, element->fifo_array_im, element->avg_array_re, element->avg_array_im, element->default_kappa_re, element->default_kappa_im, &element->current_median_re, &element->current_median_im, element->maximum_offset_re, element->maximum_offset_im, element->array_size, element->avg_array_size, &element->index_re, &element->index_im, &element->avg_index_re, &element->avg_index_im, &element->num_bad_in_avg_re, &element->num_bad_in_avg_im, gap, element->default_to_median, element->track_bad_kappa, &element->samples_in_filter); } else if(element->data_type == GSTLAL_SMOOTHKAPPAS_Z128) { - result = smooth_complex_buffer_double((const double complex *) inmap.data, inmap.size / element->unit_size, (double complex *) outmap.data, outmap.size / element->unit_size, element->fifo_array_re, element->fifo_array_im, element->avg_array_re, element->avg_array_im, element->default_kappa_re, element->default_kappa_im, &element->current_median_re, &element->current_median_im, element->maximum_offset_re, element->maximum_offset_im, element->array_size, element->avg_array_size, &element->index_re, &element->index_im, &element->avg_index_re, &element->avg_index_im, &element->num_bad_in_avg_re, &element->num_bad_in_avg_im, gap, element->default_to_median, element->track_bad_kappa, waste_samples, &element->samples_in_filter); + result = smooth_complex_buffer_double((const double complex *) inmap.data, inmap.size / element->unit_size, (double complex *) outmap.data, outmap.size / element->unit_size, element->fifo_array_re, element->fifo_array_im, element->avg_array_re, element->avg_array_im, element->default_kappa_re, element->default_kappa_im, &element->current_median_re, &element->current_median_im, element->maximum_offset_re, element->maximum_offset_im, element->array_size, element->avg_array_size, &element->index_re, &element->index_im, &element->avg_index_re, &element->avg_index_im, &element->num_bad_in_avg_re, &element->num_bad_in_avg_im, gap, element->default_to_median, element->track_bad_kappa, &element->samples_in_filter); } else { g_assert_not_reached(); } @@ -715,6 +768,8 @@ static void get_property(GObject *object, enum property prop_id, GValue *value, static void finalize(GObject *object) { GSTLALSmoothKappas *element = GSTLAL_SMOOTHKAPPAS(object); + gst_object_unref(element->srcpad); + element->srcpad = NULL; g_free(element->fifo_array_re); element->fifo_array_re = NULL; g_free(element->fifo_array_im); @@ -753,6 +808,7 @@ static void gstlal_smoothkappas_class_init(GSTLALSmoothKappasClass *klass) transform_class->get_unit_size = GST_DEBUG_FUNCPTR(get_unit_size); transform_class->set_caps = GST_DEBUG_FUNCPTR(set_caps); transform_class->start = GST_DEBUG_FUNCPTR(start); + transform_class->sink_event = GST_DEBUG_FUNCPTR(sink_event); transform_class->transform_size = GST_DEBUG_FUNCPTR(transform_size); transform_class->transform = GST_DEBUG_FUNCPTR(transform); @@ -883,8 +939,15 @@ static void gstlal_smoothkappas_class_init(GSTLALSmoothKappasClass *klass) */ -static void gstlal_smoothkappas_init(GSTLALSmoothKappas *element) -{ +static void gstlal_smoothkappas_init(GSTLALSmoothKappas *element) { + + /* retrieve (and ref) src pad */ + GstPad *pad = gst_element_get_static_pad(GST_ELEMENT(element), "src"); + GST_PAD_SET_PROXY_CAPS(pad); + GST_PAD_SET_PROXY_ALLOCATION(pad); + GST_PAD_SET_PROXY_SCHEDULING(pad); + element->srcpad = pad; + element->unit_size = 0; element->rate = 0; element->array_size = 0; diff --git a/gstlal-calibration/gst/lal/gstlal_smoothkappas.h b/gstlal-calibration/gst/lal/gstlal_smoothkappas.h index d8ab15b9f450726ce0710f59342547f8f90d1661..2b9f320884c33f078e1963627b88be261901557a 100644 --- a/gstlal-calibration/gst/lal/gstlal_smoothkappas.h +++ b/gstlal-calibration/gst/lal/gstlal_smoothkappas.h @@ -60,6 +60,9 @@ typedef struct _GSTLALSmoothKappasClass GSTLALSmoothKappasClass; struct _GSTLALSmoothKappas { GstBaseTransform element; + /* Pads */ + GstPad *srcpad; + /* stream information */ gint unit_size; gint rate;