go-hep.org/x/hep@v0.38.1/lhef/reader_test.go (about) 1 // Copyright ©2017 The go-hep Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package lhef_test 6 7 import ( 8 "fmt" 9 "io" 10 "os" 11 "testing" 12 13 "go-hep.org/x/hep/lhef" 14 ) 15 16 const r_debug = false 17 const ifname = "testdata/ttbar.lhe" 18 19 func TestLhefReading(t *testing.T) { 20 f, err := os.Open(ifname) 21 if err != nil { 22 t.Error(err) 23 } 24 25 dec, err := lhef.NewDecoder(f) 26 if err != nil { 27 t.Error(err) 28 } 29 30 n := int(dec.Run.NPRUP) 31 if len(dec.Run.XSECUP) != n || cap(dec.Run.XSECUP) != n { 32 t.Errorf("invalid XSECUP len") 33 } 34 if len(dec.Run.XERRUP) != n || cap(dec.Run.XERRUP) != n { 35 t.Errorf("invalid XRERUP len") 36 } 37 if len(dec.Run.XMAXUP) != n || cap(dec.Run.XMAXUP) != n { 38 t.Errorf("invalid XMAXUP len") 39 } 40 if len(dec.Run.LPRUP) != n || cap(dec.Run.LPRUP) != n { 41 t.Errorf("invalid LPRUP len") 42 } 43 44 for i := 0; ; i++ { 45 if r_debug { 46 fmt.Printf("===[%d]===\n", i) 47 } 48 evt, err := dec.Decode() 49 if err == io.EOF { 50 if r_debug { 51 fmt.Printf("** EOF **\n") 52 } 53 break 54 } 55 if err != nil { 56 t.Error(err) 57 } 58 if r_debug { 59 fmt.Printf("evt: %v\n", *evt) 60 } 61 } 62 }