package rarrow
import "go-hep.org/x/hep/groot/rarrow"
Package rarrow handles conversion between ROOT and ARROW data models.
Index ¶
- func NewFlatTreeWriter(dir riofs.Directory, name string, schema *arrow.Schema, opts ...rtree.WriteOption) (*flatTreeWriter, error)
- func NewTable(t rtree.Tree, opts ...Option) array.Table
- func SchemaFrom(t rtree.Tree) *arrow.Schema
- type Option
- func WithAllocator(mem memory.Allocator) Option
- func WithChunk(nentries int64) Option
- func WithEnd(entry int64) Option
- func WithStart(entry int64) Option
- type Record
- func NewRecord(t rtree.Tree, opts ...Option) *Record
- func (rec *Record) Column(i int) array.Interface
- func (rec *Record) ColumnName(i int) string
- func (rec *Record) Columns() []array.Interface
- func (rec *Record) NewSlice(i, j int64) array.Record
- func (rec *Record) NumCols() int64
- func (rec *Record) NumRows() int64
- func (rec *Record) Release()
- func (rec *Record) Retain()
- func (rec *Record) Schema() *arrow.Schema
- type RecordReader
Examples ¶
- RecordReader
- RecordReader (AllTree)
- RecordReader (WithChain)
- RecordReader (WithChunk)
- RecordReader (WithEnd)
- RecordReader (WithStart)
- RecordReader (WithStartEnd)
Functions ¶
func NewFlatTreeWriter ¶
func NewFlatTreeWriter(dir riofs.Directory, name string, schema *arrow.Schema, opts ...rtree.WriteOption) (*flatTreeWriter, error)
NewFlatTreeWriter creates an arrio.Writer that writes ARROW data as a ROOT flat-tree under the provided dir directory.
func NewTable ¶
NewTable creates a new in-memory Arrow Table from the provided ROOT Tree.
func SchemaFrom ¶
SchemaFrom returns an Arrow schema from the provided ROOT tree.
Types ¶
type Option ¶
type Option func(*config)
Option allows to configure how Records and Tables are constructed from input ROOT Trees.
func WithAllocator ¶
WithAllocator configures an Arrow value to use the specified memory allocator instead of the default Go one.
func WithChunk ¶
WithChunk specifies the number of entries to populate Records with.
The default is to populate Records with the whole set of entries the input ROOT Tree contains.
func WithEnd ¶
WithEnd specifies the last entry (excluded) to read from the input ROOT Tree.
The default (-1) is to read all the entries of the input ROOT Tree.
func WithStart ¶
WithStart specifies the first entry to read from the input ROOT Tree.
type Record ¶
type Record struct {
// contains filtered or unexported fields
}
Record is an in-memory Arrow Record backed by a ROOT Tree.
func NewRecord ¶
NewRecord creates a new in-memory Arrow Record from the provided ROOT Tree.
func (*Record) Column ¶
func (*Record) ColumnName ¶
func (*Record) Columns ¶
func (*Record) NewSlice ¶
NewSlice constructs a zero-copy slice of the record with the indicated indices i and j, corresponding to array[i:j]. The returned record must be Release()'d after use.
NewSlice panics if the slice is outside the valid range of the record array. NewSlice panics if j < i.
func (*Record) NumCols ¶
func (*Record) NumRows ¶
func (*Record) Release ¶
func (rec *Record) Release()
Release decreases the reference count by 1. When the reference count goes to zero, the memory is freed. Release may be called simultaneously from multiple goroutines.
func (*Record) Retain ¶
func (rec *Record) Retain()
Retain increases the reference count by 1. Retain may be called simultaneously from multiple goroutines.
func (*Record) Schema ¶
func (rec *Record) Schema() *arrow.Schema
type RecordReader ¶
type RecordReader struct {
// contains filtered or unexported fields
}
RecordReader is an ARROW RecordReader for ROOT Trees.
RecordReader does not materialize more than one record at a time.
The number of rows (or entries, in ROOT speak) that record loads can be configured
at creation time with the WithChunk function.
The default is one entry per record.
One can pass -1 to WithChunk to create a record with all entries of the Tree or Chain.
Code:play
Output: Code:play
Output: Code:play
Output: Code:play
Output: Code:play
Output: Code:play
Output: Code:play
Output:Example¶
package main
import (
"fmt"
"log"
"go-hep.org/x/hep/groot"
"go-hep.org/x/hep/groot/rarrow"
"go-hep.org/x/hep/groot/riofs"
"go-hep.org/x/hep/groot/rtree"
)
func main() {
f, err := groot.Open("../testdata/simple.root")
if err != nil {
log.Fatal(err)
}
defer f.Close()
o, err := riofs.Dir(f).Get("tree")
if err != nil {
log.Fatal(err)
}
tree := o.(rtree.Tree)
rr := rarrow.NewRecordReader(tree)
defer rr.Release()
recs := 0
for rr.Next() {
rec := rr.Record()
for i, col := range rec.Columns() {
fmt.Printf("rec[%d][%s]: %v\n", recs, rec.Schema().Field(i).Name, col)
}
recs++
}
}
rec[0][one]: [1]
rec[0][two]: [1.1]
rec[0][three]: ["uno"]
rec[1][one]: [2]
rec[1][two]: [2.2]
rec[1][three]: ["dos"]
rec[2][one]: [3]
rec[2][two]: [3.3]
rec[2][three]: ["tres"]
rec[3][one]: [4]
rec[3][two]: [4.4]
rec[3][three]: ["quatro"]
Example (AllTree)¶
package main
import (
"fmt"
"log"
"go-hep.org/x/hep/groot"
"go-hep.org/x/hep/groot/rarrow"
"go-hep.org/x/hep/groot/riofs"
"go-hep.org/x/hep/groot/rtree"
)
func main() {
f, err := groot.Open("../testdata/simple.root")
if err != nil {
log.Fatal(err)
}
defer f.Close()
o, err := riofs.Dir(f).Get("tree")
if err != nil {
log.Fatal(err)
}
tree := o.(rtree.Tree)
rr := rarrow.NewRecordReader(tree, rarrow.WithChunk(-1))
defer rr.Release()
recs := 0
for rr.Next() {
rec := rr.Record()
for i, col := range rec.Columns() {
fmt.Printf("rec[%d][%s]: %v\n", recs, rec.Schema().Field(i).Name, col)
}
recs++
}
}
rec[0][one]: [1 2 3 4]
rec[0][two]: [1.1 2.2 3.3 4.4]
rec[0][three]: ["uno" "dos" "tres" "quatro"]
Example (WithChain)¶
package main
import (
"fmt"
"log"
"go-hep.org/x/hep/groot/rarrow"
"go-hep.org/x/hep/groot/rtree"
)
func main() {
chain, closer, err := rtree.ChainOf("tree", "../testdata/chain.1.root", "../testdata/chain.2.root")
if err != nil {
log.Fatal(err)
}
defer func() {
err = closer()
if err != nil {
log.Fatalf("could not close chain: %+v", err)
}
}()
rr := rarrow.NewRecordReader(chain, rarrow.WithStart(10), rarrow.WithEnd(20))
defer rr.Release()
recs := 0
for rr.Next() {
rec := rr.Record()
for i, col := range rec.Columns() {
fmt.Printf("rec[%d][%s]: %v\n", recs, rec.Schema().Field(i).Name, col)
}
recs++
}
}
rec[0][evt]: {["beg-010"] [10] [[10 10 10 10 10 10 10 10 10 10]] [0] [[]] ["std-010"] [[]] [[]] ["end-010"]}
rec[1][evt]: {["beg-011"] [11] [[11 11 11 11 11 11 11 11 11 11]] [1] [[11]] ["std-011"] [[11]] [["vec-011"]] ["end-011"]}
rec[2][evt]: {["beg-012"] [12] [[12 12 12 12 12 12 12 12 12 12]] [2] [[12 12]] ["std-012"] [[12 12]] [["vec-012" "vec-012"]] ["end-012"]}
rec[3][evt]: {["beg-013"] [13] [[13 13 13 13 13 13 13 13 13 13]] [3] [[13 13 13]] ["std-013"] [[13 13 13]] [["vec-013" "vec-013" "vec-013"]] ["end-013"]}
rec[4][evt]: {["beg-014"] [14] [[14 14 14 14 14 14 14 14 14 14]] [4] [[14 14 14 14]] ["std-014"] [[14 14 14 14]] [["vec-014" "vec-014" "vec-014" "vec-014"]] ["end-014"]}
rec[5][evt]: {["beg-015"] [15] [[15 15 15 15 15 15 15 15 15 15]] [5] [[15 15 15 15 15]] ["std-015"] [[15 15 15 15 15]] [["vec-015" "vec-015" "vec-015" "vec-015" "vec-015"]] ["end-015"]}
rec[6][evt]: {["beg-016"] [16] [[16 16 16 16 16 16 16 16 16 16]] [6] [[16 16 16 16 16 16]] ["std-016"] [[16 16 16 16 16 16]] [["vec-016" "vec-016" "vec-016" "vec-016" "vec-016" "vec-016"]] ["end-016"]}
rec[7][evt]: {["beg-017"] [17] [[17 17 17 17 17 17 17 17 17 17]] [7] [[17 17 17 17 17 17 17]] ["std-017"] [[17 17 17 17 17 17 17]] [["vec-017" "vec-017" "vec-017" "vec-017" "vec-017" "vec-017" "vec-017"]] ["end-017"]}
rec[8][evt]: {["beg-018"] [18] [[18 18 18 18 18 18 18 18 18 18]] [8] [[18 18 18 18 18 18 18 18]] ["std-018"] [[18 18 18 18 18 18 18 18]] [["vec-018" "vec-018" "vec-018" "vec-018" "vec-018" "vec-018" "vec-018" "vec-018"]] ["end-018"]}
rec[9][evt]: {["beg-019"] [19] [[19 19 19 19 19 19 19 19 19 19]] [9] [[19 19 19 19 19 19 19 19 19]] ["std-019"] [[19 19 19 19 19 19 19 19 19]] [["vec-019" "vec-019" "vec-019" "vec-019" "vec-019" "vec-019" "vec-019" "vec-019" "vec-019"]] ["end-019"]}
Example (WithChunk)¶
package main
import (
"fmt"
"log"
"go-hep.org/x/hep/groot"
"go-hep.org/x/hep/groot/rarrow"
"go-hep.org/x/hep/groot/riofs"
"go-hep.org/x/hep/groot/rtree"
)
func main() {
f, err := groot.Open("../testdata/simple.root")
if err != nil {
log.Fatal(err)
}
defer f.Close()
o, err := riofs.Dir(f).Get("tree")
if err != nil {
log.Fatal(err)
}
tree := o.(rtree.Tree)
rr := rarrow.NewRecordReader(tree, rarrow.WithChunk(3))
defer rr.Release()
recs := 0
for rr.Next() {
rec := rr.Record()
for i, col := range rec.Columns() {
fmt.Printf("rec[%d][%s]: %v\n", recs, rec.Schema().Field(i).Name, col)
}
recs++
}
}
rec[0][one]: [1 2 3]
rec[0][two]: [1.1 2.2 3.3]
rec[0][three]: ["uno" "dos" "tres"]
rec[1][one]: [4]
rec[1][two]: [4.4]
rec[1][three]: ["quatro"]
Example (WithEnd)¶
package main
import (
"fmt"
"log"
"go-hep.org/x/hep/groot"
"go-hep.org/x/hep/groot/rarrow"
"go-hep.org/x/hep/groot/riofs"
"go-hep.org/x/hep/groot/rtree"
)
func main() {
f, err := groot.Open("../testdata/simple.root")
if err != nil {
log.Fatal(err)
}
defer f.Close()
o, err := riofs.Dir(f).Get("tree")
if err != nil {
log.Fatal(err)
}
tree := o.(rtree.Tree)
rr := rarrow.NewRecordReader(tree, rarrow.WithEnd(2))
defer rr.Release()
recs := 0
for rr.Next() {
rec := rr.Record()
for i, col := range rec.Columns() {
fmt.Printf("rec[%d][%s]: %v\n", recs, rec.Schema().Field(i).Name, col)
}
recs++
}
}
rec[0][one]: [1]
rec[0][two]: [1.1]
rec[0][three]: ["uno"]
rec[1][one]: [2]
rec[1][two]: [2.2]
rec[1][three]: ["dos"]
Example (WithStart)¶
package main
import (
"fmt"
"log"
"go-hep.org/x/hep/groot"
"go-hep.org/x/hep/groot/rarrow"
"go-hep.org/x/hep/groot/riofs"
"go-hep.org/x/hep/groot/rtree"
)
func main() {
f, err := groot.Open("../testdata/simple.root")
if err != nil {
log.Fatal(err)
}
defer f.Close()
o, err := riofs.Dir(f).Get("tree")
if err != nil {
log.Fatal(err)
}
tree := o.(rtree.Tree)
rr := rarrow.NewRecordReader(tree, rarrow.WithStart(1))
defer rr.Release()
recs := 0
for rr.Next() {
rec := rr.Record()
for i, col := range rec.Columns() {
fmt.Printf("rec[%d][%s]: %v\n", recs, rec.Schema().Field(i).Name, col)
}
recs++
}
}
rec[0][one]: [2]
rec[0][two]: [2.2]
rec[0][three]: ["dos"]
rec[1][one]: [3]
rec[1][two]: [3.3]
rec[1][three]: ["tres"]
rec[2][one]: [4]
rec[2][two]: [4.4]
rec[2][three]: ["quatro"]
Example (WithStartEnd)¶
package main
import (
"fmt"
"log"
"go-hep.org/x/hep/groot"
"go-hep.org/x/hep/groot/rarrow"
"go-hep.org/x/hep/groot/riofs"
"go-hep.org/x/hep/groot/rtree"
)
func main() {
f, err := groot.Open("../testdata/simple.root")
if err != nil {
log.Fatal(err)
}
defer f.Close()
o, err := riofs.Dir(f).Get("tree")
if err != nil {
log.Fatal(err)
}
tree := o.(rtree.Tree)
rr := rarrow.NewRecordReader(tree, rarrow.WithStart(1), rarrow.WithEnd(2))
defer rr.Release()
recs := 0
for rr.Next() {
rec := rr.Record()
for i, col := range rec.Columns() {
fmt.Printf("rec[%d][%s]: %v\n", recs, rec.Schema().Field(i).Name, col)
}
recs++
}
}
rec[0][one]: [2]
rec[0][two]: [2.2]
rec[0][three]: ["dos"]
func NewRecordReader ¶
func NewRecordReader(tree rtree.Tree, opts ...Option) *RecordReader
NewRecordReader creates a new ARROW RecordReader from the provided ROOT Tree.
func (*RecordReader) Next ¶
func (r *RecordReader) Next() bool
func (*RecordReader) Record ¶
func (r *RecordReader) Record() array.Record
func (*RecordReader) Release ¶
func (r *RecordReader) Release()
Release decreases the reference count by 1. When the reference count goes to zero, the memory is freed. Release may be called simultaneously from multiple goroutines.
func (*RecordReader) Retain ¶
func (r *RecordReader) Retain()
Retain increases the reference count by 1. Retain may be called simultaneously from multiple goroutines.
func (*RecordReader) Schema ¶
func (r *RecordReader) Schema() *arrow.Schema
Source Files ¶
option.go rarrow.go reader.go table.go tree_writer.go
- Version
- v0.36.0 (latest)
- Published
- Nov 15, 2024
- Platform
- linux/amd64
- Imports
- 11 packages
- Last checked
- 4 days ago –
Tools for package owners.