Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support reading/writing compressed files (#44)
pyiostream is added, which allows C++ code to interact with an iostream that read/writes to a Python file object. The primary use-case is to have transparent compression based on the gzip, bzip2, lzma modules in Python's standard library.
- Loading branch information
1 parent
7560ffc
commit dcf0031
Showing
9 changed files
with
415 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import pyhepmc | ||
from pyhepmc.io import ReaderAscii | ||
from pyhepmc._core import pyiostream | ||
from pathlib import Path | ||
|
||
|
||
fn = str(Path(__file__).parent.parent / "tests" / "pythia6.dat") | ||
|
||
with pyhepmc.open(fn) as f: | ||
evt = f.read() | ||
|
||
with pyhepmc.open("bench.dat", "w") as f: | ||
for _ in range(4000): | ||
f.write(evt) | ||
|
||
|
||
def test_ReaderAscii(benchmark): | ||
def run(): | ||
with ReaderAscii("bench.dat") as r: | ||
while True: | ||
evt = r.read() | ||
if evt is None: | ||
break | ||
|
||
benchmark(run) | ||
|
||
|
||
def test_ReaderAscii_pyiostream(benchmark): | ||
def run(): | ||
with open("bench.dat", "rb") as f: | ||
pis = pyiostream(f, 4096) | ||
with ReaderAscii(pis) as r: | ||
while True: | ||
evt = r.read() | ||
if evt is None: | ||
break | ||
|
||
benchmark(run) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.