go-hep.org/x/hep@v0.38.1/hbook/ntup/ntroot/example_test.go (about) 1 // Copyright ©2020 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 ntroot_test 6 7 import ( 8 "fmt" 9 "log" 10 11 "go-hep.org/x/hep/hbook/ntup/ntroot" 12 ) 13 14 func ExampleOpen() { 15 nt, err := ntroot.Open("../../../groot/testdata/simple.root", "tree") 16 if err != nil { 17 log.Fatalf("could not open n-tuple: %+v", err) 18 } 19 defer func() { 20 err = nt.DB().Close() 21 if err != nil { 22 log.Fatal(err) 23 } 24 }() 25 26 err = nt.Scan( 27 "(one, two, three)", 28 func(i int32, f float32, s string) error { 29 fmt.Printf("row=(%v, %v, %q)\n", i, f, s) 30 return nil 31 }, 32 ) 33 34 if err != nil { 35 log.Fatalf("could not scan n-tuple: %+v", err) 36 } 37 38 // Output: 39 // row=(1, 1.1, "uno") 40 // row=(2, 2.2, "dos") 41 // row=(3, 3.3, "tres") 42 // row=(4, 4.4, "quatro") 43 }