Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iter all events #214

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/eventio/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__(self, path, zcat=True):
self.read_process = None
self.zstd = False
self.next = None
self.peek_error = None

if not is_eventio(path):
raise ValueError('File {} is not an eventio file'.format(path))
Expand Down Expand Up @@ -125,7 +126,12 @@ def __next__(self):

def peek(self):
if self.next is None:
self.next = next(self)
try:
self.next = next(self)
except (StopIteration, EOFError, IOError) as e:
self.peek_error = e
self.next = None
maxnoe marked this conversation as resolved.
Show resolved Hide resolved

return self.next

def seek(self, position, whence=0):
Expand Down Expand Up @@ -157,7 +163,7 @@ def check_size_or_raise(data, expected_length, zero_ok=True):
else:
raise EOFError('File seems to be truncated')

if length < expected_length:
elif length < expected_length:
raise EOFError('File seems to be truncated')


Expand All @@ -182,12 +188,6 @@ def read_header(byte_stream, offset, toplevel=False):
'''

header_bytes = byte_stream.read(constants.OBJECT_HEADER_SIZE)
check_size_or_raise(
header_bytes,
constants.OBJECT_HEADER_SIZE,
zero_ok=False,
)

header = parse_header_bytes(header_bytes, toplevel=toplevel)

if header.extended:
Expand Down
5 changes: 5 additions & 0 deletions src/eventio/header.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ cpdef ObjectHeader parse_header_bytes(const uint8_t[:] header_bytes, bint toplev
cdef bint only_subobjects
cdef uint64_t length

if len(header_bytes) != OBJECT_HEADER_SIZE:
# for backwards compatibility, we raise the same error as before.
# more appropriate for this free function would be something like
# raise ValueError("header_bytes size must be 12")
raise EOFError('File seems to be truncated')

type_int = unpack_uint32(header_bytes[0:4])
type_, version, user, extended = parse_type_field(type_int)
Expand Down
4 changes: 1 addition & 3 deletions src/eventio/simtel/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1461,10 +1461,8 @@ def __str__(self):
)

def parse(self):
''' '''
assert_version_in(self, (1, 2))
''''''
self.seek(0)

d = MCEvent.parse_mc_event(self.read(), self.header.version)
d['event_id'] = self.header.id
return d
Expand Down
6 changes: 6 additions & 0 deletions src/eventio/simtel/parsing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ cpdef dict parse_mc_event(
const uint8_t[:] data,
uint32_t version
):
if version > 2:
raise NotImplementedError(
'Unsupported version of MCEvent:'
' only versions up to 2 supported,'
f' got: {version} '
)

cdef uint64_t pos = 0
cdef float xcore, ycore, aweight
Expand Down
Loading
Loading