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

Fix superrun creation #562

Merged
merged 3 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion strax/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ def concat_loader(*args, **kwargs):
# Should we save this data? If not, return.
if (loading_this_data
and not self.context_config['storage_converter']
and not self.context_config['write_superruns']):
and not (self.context_config['write_superruns'] and _is_superrun)):
return
if (loading_this_data
and not self.context_config['write_superruns']
Expand Down
23 changes: 22 additions & 1 deletion tests/test_superruns.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def setUp(self, superrun_name='_superrun_test'):
# Temp directory for storing record data for the tests.
# Will be removed during TearDown.
self.tempdir = tempfile.mkdtemp()
self.tempdir2 = tempfile.mkdtemp() # Required to test writing superruns
# with two storage frontends
self.context = strax.Context(storage=[strax.DataDirectory(self.tempdir,
provide_run_metadata=True,
readonly=False,
Expand Down Expand Up @@ -238,11 +240,30 @@ def test_superruns_and_save_when(self):
assert not self.context.is_stored(self.subrun_ids[0], 'peaks')
assert self.context.is_stored(self.superrun_name, 'peaks_extension')
assert self.context.is_stored(self.subrun_ids[0], 'peaks_extension')


def test_storing_with_second_sf(self):
"""Tests if only superrun is written to new sf if subruns
already exist in different sf.
"""
self.context.storage[0].readonly=True
self.context.storage.append(strax.DataDirectory(self.tempdir2))
self.context.make(self.superrun_name, 'records')
superrun_sf = self.context.storage.pop(1)
# Check if first sf contains superrun, it should not:
assert not self.context.is_stored(self.superrun_name, 'records')

# Now check second sf for which only the superrun should be
# stored:
self.context.storage = [superrun_sf]
assert self.context.is_stored(self.superrun_name, 'records')
for subrun in self.subrun_ids:
assert not self.context.is_stored(subrun, 'records')

def tearDown(self):
if os.path.exists(self.tempdir):
shutil.rmtree(self.tempdir)
if os.path.exists(self.tempdir2):
shutil.rmtree(self.tempdir2)

def _create_subruns(self, n_subruns=3):
self.now = datetime.datetime.now()
Expand Down