コード例 #1
0
def test_pythonic_read_write(evt):
    oss = hep.stringstream()
    with hep.WriterAscii(oss) as f:
        f.write(evt)

    with hep.ReaderAscii(oss) as f:
        for i, evt2 in enumerate(f):
            assert i == 0
            assert evt.particles == evt2.particles
            assert evt.vertices == evt2.vertices
            assert evt == evt2
コード例 #2
0
ファイル: test_basic.py プロジェクト: HDembinski/pyhepmc
def test_pythonic_read_write():
    evt1 = prepare_event()

    oss = hep.stringstream()
    with hep.open(oss, "w") as f:
        f.write(evt1)

    evt2 = None
    with hep.open(oss) as f:
        evt2 = f.read()

    assert evt1.particles == evt2.particles
    assert evt1.vertices == evt2.vertices
    assert evt1 == evt2
コード例 #3
0
def test_read_write(evt):
    oss = hep.stringstream()
    with hep.WriterAscii(oss) as f:
        f.write_event(evt)

    evt2 = hep.GenEvent()
    assert evt != evt2
    with hep.ReaderAscii(oss) as f:
        f.read_event(evt2)

    assert evt.event_number == evt2.event_number
    assert evt.momentum_unit == evt2.momentum_unit
    assert evt.length_unit == evt2.length_unit
    assert evt.particles == evt2.particles
    assert evt.vertices == evt2.vertices
    assert evt == evt2
コード例 #4
0
def test_read_write_stream():
    evt1 = prepare_event()

    oss = hep.stringstream()
    with hep.WriterAscii(oss) as f:
        f.write_event(evt1)

    assert str(oss) == """HepMC::Version 3.01.00
HepMC::Asciiv3-START_EVENT_LISTING
E 1 4 8
U GEV MM
W 1.0000000000000000000000e+00
P 1 0 2212 0.0000000000000000e+00 0.0000000000000000e+00 7.0000000000000000e+03 7.0000000000000000e+03 9.3799999999999994e-01 1
P 2 0 2212 0.0000000000000000e+00 0.0000000000000000e+00 -7.0000000000000000e+03 7.0000000000000000e+03 9.3799999999999994e-01 2
V -1 0 [1] @ 1.0000000000000000e+00 1.0000000000000000e+00 1.0000000000000000e+00 1.0000000000000000e+00
P 3 -1 1 7.5000000000000000e-01 -1.5690000000000000e+00 3.2191000000000003e+01 3.2238000000000000e+01 0.0000000000000000e+00 3
V -2 0 [2] @ 2.0000000000000000e+00 2.0000000000000000e+00 2.0000000000000000e+00 2.0000000000000000e+00
P 4 -2 -2 -3.0470000000000002e+00 -1.9000000000000000e+01 -5.4628999999999998e+01 5.7920000000000002e+01 0.0000000000000000e+00 4
V -3 0 [3,4] @ 3.0000000000000000e+00 3.0000000000000000e+00 3.0000000000000000e+00 3.0000000000000000e+00
P 5 -3 -24 1.5169999999999999e+00 -2.0680000000000000e+01 -2.0605000000000000e+01 8.5924999999999997e+01 8.0799000000000007e+01 5
P 6 -3 22 -3.8130000000000002e+00 1.1300000000000000e-01 -1.8330000000000000e+00 4.2329999999999997e+00 0.0000000000000000e+00 6
V -4 0 [5] @ 4.0000000000000000e+00 4.0000000000000000e+00 4.0000000000000000e+00 4.0000000000000000e+00
P 7 -4 1 -2.4449999999999998e+00 2.8815999999999999e+01 6.0819999999999999e+00 2.9552000000000000e+01 1.0000000000000000e-02 7
P 8 -4 -2 3.9620000000000002e+00 -4.9497999999999998e+01 -2.6687000000000001e+01 5.6372999999999998e+01 6.0000000000000001e-03 8
HepMC::Asciiv3-END_EVENT_LISTING

"""

    evt2 = hep.GenEvent()
    assert evt1 != evt2
    with hep.ReaderAscii(oss) as f:
        f.read_event(evt2)

    assert evt1.event_number == evt2.event_number
    assert evt1.momentum_unit == evt2.momentum_unit
    assert evt1.length_unit == evt2.length_unit
    assert evt1.particles == evt2.particles
    assert evt1.vertices == evt2.vertices
    assert evt1 == evt2
コード例 #5
0
ファイル: test_basic.py プロジェクト: HDembinski/pyhepmc
def test_read_empty_stream():
    oss = hep.stringstream()
    with hep.ReaderAscii(oss) as f:
        evt = hep.GenEvent()
        ok = f.read_event(evt)
        assert ok == True  # reading empty stream is ok in HepMC