hep: go-hep.org/x/hep/groot/rarrow Index | Examples | Files

package rarrow

import "go-hep.org/x/hep/groot/rarrow"

Package rarrow handles conversion between ROOT and ARROW data models.

Index

Examples

Package Files

option.go rarrow.go reader.go table.go

func NewTable Uses

func NewTable(t rtree.Tree, opts ...Option) array.Table

NewTable creates a new in-memory Arrow Table from the provided ROOT Tree.

func SchemaFrom Uses

func SchemaFrom(t rtree.Tree) *arrow.Schema

SchemaFrom returns an Arrow schema from the provided ROOT tree.

type Option Uses

type Option func(*config)

Option allows to configure how Records and Tables are constructed from input ROOT Trees.

func WithAllocator Uses

func WithAllocator(mem memory.Allocator) Option

WithAllocator configures an Arrow value to use the specified memory allocator instead of the default Go one.

func WithChunk Uses

func WithChunk(nentries int64) Option

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 Uses

func WithEnd(entry int64) Option

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 Uses

func WithStart(entry int64) Option

WithStart specifies the first entry to read from the input ROOT Tree.

type Record Uses

type Record struct {
    // contains filtered or unexported fields
}

Record is an in-memory Arrow Record backed by a ROOT Tree.

func NewRecord Uses

func NewRecord(t rtree.Tree, opts ...Option) *Record

NewRecord creates a new in-memory Arrow Record from the provided ROOT Tree.

func (*Record) Column Uses

func (rec *Record) Column(i int) array.Interface

func (*Record) ColumnName Uses

func (rec *Record) ColumnName(i int) string

func (*Record) Columns Uses

func (rec *Record) Columns() []array.Interface

func (*Record) NewSlice Uses

func (rec *Record) NewSlice(i, j int64) array.Record

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 Uses

func (rec *Record) NumCols() int64

func (*Record) NumRows Uses

func (rec *Record) NumRows() int64

func (*Record) Release Uses

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 Uses

func (rec *Record) Retain()

Retain increases the reference count by 1. Retain may be called simultaneously from multiple goroutines.

func (*Record) Schema Uses

func (rec *Record) Schema() *arrow.Schema

type RecordReader Uses

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:

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++
}

Output:

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"]

Code:

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++
}

Output:

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"]

Code:

chain, closer, err := rtree.ChainOf("tree", "../testdata/chain.1.root", "../testdata/chain.2.root")
if err != nil {
    log.Fatal(err)
}
defer closer()

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++
}

Output:

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"]}

Code:

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++
}

Output:

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"]

Code:

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++
}

Output:

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"]

Code:

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++
}

Output:

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"]

Code:

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++
}

Output:

rec[0][one]: [2]
rec[0][two]: [2.2]
rec[0][three]: ["dos"]

func NewRecordReader Uses

func NewRecordReader(tree rtree.Tree, opts ...Option) *RecordReader

NewRecordReader creates a new ARROW RecordReader from the provided ROOT Tree.

func (*RecordReader) Next Uses

func (r *RecordReader) Next() bool

func (*RecordReader) Record Uses

func (r *RecordReader) Record() array.Record

func (*RecordReader) Release Uses

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 Uses

func (r *RecordReader) Retain()

Retain increases the reference count by 1. Retain may be called simultaneously from multiple goroutines.

func (*RecordReader) Schema Uses

func (r *RecordReader) Schema() *arrow.Schema

Package rarrow imports 7 packages (graph) and is imported by 1 packages. Updated 2019-05-31. Refresh now. Tools for package owners.