bpod_core.bpod.threads.EventThread
- class bpod_core.bpod.threads.EventThread
Bases:
ThreadConsumer thread that processes hardware events and builds the trial DataFrame.
Runs for the duration of one trial.
ReadThreadfeeds rawRawEventitems intoqueue;EventThreaddrains that queue, advances the FSM state, and records every event — inputs, state transitions, and output actions — into an internal buffer.When the trial ends (
STOP_SENTINELreceived), the buffer is converted to apolars.LazyFrameand pushed onto data_queue for the caller to collect viaget_data().Buffer design: events are appended to a pre-allocated NumPy structured array (
_EVENT_DTYPE) that doubles in size when full. The buffer is only written at index_n_eventsbefore that counter is incremented, so indices0.._n_events-1are immutable once written.Thread safety:
peek_data()may be called from another thread while the trial is running. It copies the buffer view before passing it to Polars, ensuring a consistent snapshot.- __init__(*, trial, fsm, data_queue, event_lookup, action_names, time_reference) None
Initialize the EventThread.
- Parameters:
trial (
int) – Zero-based trial index, used to populate thetrialcolumn.fsm (
StateMachineLookup) – Compiled state machine data for this trial.data_queue (
SimpleQueue[pl.LazyFrame]) – Queue to push the completed trial DataFrame into.event_lookup (
pl.DataFrame) – Pre-built event metadata lookup, see_build_event_lookup().action_names (
listofstr) – Names of all output channels, indexed by action ID.time_reference (
TimeReferences) – Reference values for performance counters.
- Return type:
None
- peek_data(trigger_states=None) LazyFrame
Return a snapshot of events recorded so far as a
polars.LazyFrame.Safe to call from a different thread while the trial is running. The returned DataFrame reflects events up to the moment
_n_eventswas read; one in-flight event may be missed.- Parameters:
trigger_states (
Collectionofstr, optional) – Block until at least one of the given states has been entered. If the trial ends before any of the states have been entered, returns whatever was recorded.- Returns:
A snapshot of the recorded events.
- Return type:
pl.LazyFrame- Raises:
ValueError – If one or several of the trigger states are not part of the state machine.
-
queue:
SimpleQueue[RawEvent] Per-trial event queue shared with
ReadThread.