Rework and refactor `appsink_new_buffer` and `cluster` in `finalsink.py`
appsink_new_buffer()
and cluster()
in finalsink.py
are difficult to follow, and have caused problems in the past that required patches to fix (see !22 (merged)). It requires lengthy comments explaining the process and assumptions, which shouldn't be necessary with a redesign or refactor.
At a minimum, the different portions of each function could be better encapsulated. It 'pulls' a buffer from postcoh; checks for events; tacitly knows that the first event is metadata and uses it to updates segments; performs initialization if this is the first event/buffer; creates and maintains a cluster window; calls the cluster function; checks if it could upload to gracedb and performs the upload; maintains a set of events between calls for clustering; cleans up; writes snapshot files; and calls calcfap
. And that's just appsink_new_buffer
.
(Further details can be added as needed. This issue is currently just a problem statement. It should be resolved in chunks with multiple MRs with clearly defined scope.)