From 27a73a77e1829ca4d18fa050e43b522727b0d824 Mon Sep 17 00:00:00 2001 From: Sasha Rahlin Date: Tue, 23 Jan 2024 21:59:57 -0600 Subject: [PATCH] Skip empty files in G3Reader Avoid throwing an IO error when an empty G3 file is included in the input filenames by silently moving on to the next file in the list until reaching a non-empty file or the end of the list. Fixes #134. --- core/src/G3Reader.cxx | 2 +- core/tests/fileio.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/src/G3Reader.cxx b/core/src/G3Reader.cxx index db0fceec..718c0d08 100644 --- a/core/src/G3Reader.cxx +++ b/core/src/G3Reader.cxx @@ -80,7 +80,7 @@ void G3Reader::Process(G3FramePtr frame, std::deque &out) if (Py_IsInitialized()) _save = PyEval_SaveThread(); - if (stream_.peek() == EOF) { + while (stream_.peek() == EOF) { if (filename_.size() > 0) { StartFile(filename_.front()); filename_.pop_front(); diff --git a/core/tests/fileio.py b/core/tests/fileio.py index 0b36de3f..72950458 100755 --- a/core/tests/fileio.py +++ b/core/tests/fileio.py @@ -46,7 +46,16 @@ def checkinfo(fr): n += 1 pipe.Add(checkinfo) pipe.Run() +assert n == 10, 'Wrong number of frames read (%d should be %d)' % (n, 10) +# Skip empty files +wr = core.G3Writer("empty.g3") +del wr +n = 0 +pipe = core.G3Pipeline() +pipe.Add(core.G3Reader, filename=["empty.g3", "test.g3", "empty.g3"], track_filename=True) +pipe.Add(checkinfo) +pipe.Run() assert n == 10, 'Wrong number of frames read (%d should be %d)' % (n, 10) # Indexing