Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@h-mayorquin
Copy link
Contributor

This is a continuation of #1763

On the main branch, the NEV header reading functionality uses a two-stage mapping system that separates the definition of extended header types from their specification-specific usage. The system first defines all possible extended header types in a general _nev_ext_header_types function that returns a nested dictionary where packet IDs map to variant letters ("a", "b", "c"), which then map to actual data type definitions:

def _nev_ext_header_types(self):

For example, b"NEUEVWAV" maps to both "a" (for v2.1 with a 10-byte unused field) and "b" (for v2.2+ with a spike_width field and an 8-byte unused field). Each specification-specific function (_read_nev_header_spec_v21, _read_nev_header_spec_v22, _read_nev_header_spec_v30_ptp) then builds its own mapping dictionary that assigns these variant letters to packet IDs, effectively filtering which variants apply to that specification:

def _read_nev_header_spec_v21(self):
"""
Extract nev header information from a 2.1 .nev file
"""
ext_header_variants = {
b"NEUEVWAV": "a",
b"ARRAYNME": "a",
b"ECOMMENT": "a",
b"CCOMMENT": "a",
b"MAPFILE": "a",
b"NSASEXEV": "a",
}
return self._read_nev_header(ext_header_variants)

I think that this dynamic lookup is both inefficient and hard to read. It is inefficient because every spec function needs to read all the spec for all the extended data types anyway and is hard-to-read because that is done implicitly and couples dicts in two different places dynamically. We can do better.

Instead, in this PR I replaced that approach with a declarative module-level dictionary (NEV_EXT_HEADER_TYPES_BY_SPEC) that directly maps specifications to their complete header type definitions without the intermediate variant letters. I consolidated the three specification-specific header functions into a single _read_nev_header function that takes the specification as a parameter and performs a direct dictionary lookup. This continues the work from #1763, which removed some arbitrary spec references (a, b, etc) but left others embedded in function internals. The new structure separates data from execution, allowing direct resolution of extended data types instead of dynamic lookup, and improves maintainability because of "explicit is better than implicit" reasons.

@h-mayorquin h-mayorquin marked this pull request as ready for review September 9, 2025 01:11
@h-mayorquin h-mayorquin changed the title Improve nev header reading Blackrock: improve nev header reading Sep 9, 2025
@zm711
Copy link
Contributor

zm711 commented Sep 15, 2025

@h-mayorquin, after merging #1769, I think I generated conflicts for you in case you want to patch those now.

@h-mayorquin
Copy link
Contributor Author

@h-mayorquin, after merging #1769, I think I generated conflicts for you in case you want to patch those now.

Fixed.

@zm711 zm711 added this to the 0.14.3 milestone Sep 19, 2025
@h-mayorquin h-mayorquin self-assigned this Sep 26, 2025
@samuelgarcia
Copy link
Contributor

Total approval on my side.
We can merge I think.

@h-mayorquin h-mayorquin merged commit cd8fd4b into NeuralEnsemble:master Oct 7, 2025
3 checks passed
@h-mayorquin h-mayorquin deleted the refactor_nev_header_reading branch October 7, 2025 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants