Skip to content

Bug in dataset.iterate() with the pyroot backend #128

Description

@fschlueter

When you aggregate all waveforms via dataset.iterate using the pyroot backend. E.g.:

dataset = Dataset(data_path=sys.argv[1], backend="pyroot")
dataset.setEntries((0, dataset.N()))
wfs = []
for ev, wf in dataset.iterate():
    wfs.append(wf)

All events in wfs have the exact same waveforms. This is some reference bug where wfs contains the reference to something in memory which is updated to the last event at the end of the for loop.

When printing the wf during the for-loop they are different. Using wfs.append(wf.copy()) also fixes the problem.

I already create a PR which extends the unit tests to be sensitive to this bug (and test that it is not a feature of my system) and surely they are failing (see #127).

MWE:

import sys
import numpy as np
from mattak.Dataset import Dataset

dataset = Dataset(data_path=sys.argv[1], backend="pyroot")
dataset.setEntries((0, dataset.N()))
wfs = []
for ev, wf in dataset.iterate():
    if ev.triggerType != "FORCE":
        continue
    wfs.append(wf)  # <--- printing here shows they are different. using wf.copy fixes it.

wfs = np.array(wfs)
print(np.allclose(wfs[0], wfs[1]))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions