{# USES_VARIABLES {N, count, _clock_t, _source_start, _source_stop} #}
import numpy as _numpy

{#  Get the name of the array that stores these events (e.g. the spikespace array) #}
{% set _eventspace = get_array_name(eventspace_variable) %}

_n_events = {{_eventspace}}[-1]
if _n_events > 0:
    _events = {{_eventspace}}[:_n_events]
    # Take subgroups into account
    if _source_start!=0 or _source_stop!={{N}}:
        _events = _events[(_events >= _source_start) & (_events < _source_stop)]
    _n_events = len(_events)
    if _n_events > 0:
        _vectorisation_idx = 1
        {{scalar_code|autoindent}}
        _curlen = {{N}}
        _newlen = _curlen + _n_events
        _owner.resize(_newlen)
        {{N}} = _newlen
        _vectorisation_idx = _n_events
        _idx = _events
        {{vector_code|autoindent}}
        {% for varname, var in record_variables.items() %}
        {% set dynamic_varname = get_array_name(var, access_data=False) %}
        {{dynamic_varname}}[_curlen:_newlen] = _to_record_{{varname}}
        {% endfor %}
        {{count}}[_events - _source_start] += 1
