TapeIndex

class endf_parserpy.TapeIndex(materials, tpid_line, tpid_offset, tpid_length, source=None, source_size=None, source_mtime_ns=None)[source]

A structural index over the materials of an ENDF tape.

Build one with from_file() (exact on-disk byte offsets) or from_lines(). The index supports len(), iteration and integer position indexing, and provides by_mat() and by_za() secondary lookups. It is recipe-free and picklable.

materials

The materials, in tape order.

Type:

list[MaterialIndexEntry]

tpid_line

The tape head (TPID) record.

Type:

str

tpid_offset, tpid_length

Byte location of the TPID record.

Type:

int

source

Path of the indexed file, if built with from_file().

Type:

str or None

source_size, source_mtime_ns

Size and modification time of the source file at index time; usable to detect that the file changed after indexing.

Type:

int or None

by_mat(mat)[source]

Return the positions of all materials with this MAT number.

by_za(za)[source]

Return the positions of all materials with this ZA identifier.

classmethod from_file(path, *, chunk_bytes=16777216)[source]

Build an index of the ENDF tape stored at path.

The tape is read in blocks of about chunk_bytes, so peak memory during indexing stays a small multiple of chunk_bytes regardless of the tape size.

classmethod from_lines(lines, source=None)[source]

Build an index from an iterable of ENDF tape lines.

The lines are consumed lazily. Byte offsets are computed assuming a single "\n" terminates each line; they are therefore only exact for a file written that way. Use from_file() when exact on-disk offsets are required.