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

package rtree

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

Package rtree contains the interfaces and types to decode, read, concatenate and iterate over ROOT Trees.

Index

Examples

Package Files

basket.go branch.go leaf.go leaf_gen.go read_streamers.go rtree.go scanner.go tchain.go tree.go wrapper.go

func FileOf Uses

func FileOf(tree Tree) *riofs.File

FileOf returns the file hosting the given Tree. If the tree is not connected to any ROOT file, nil is returned.

type Basket Uses

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

func (*Basket) Class Uses

func (b *Basket) Class() string

func (*Basket) Name Uses

func (b *Basket) Name() string

func (*Basket) Title Uses

func (b *Basket) Title() string

func (*Basket) UnmarshalROOT Uses

func (b *Basket) UnmarshalROOT(r *rbytes.RBuffer) error

type Branch Uses

type Branch interface {
    root.Named

    Branches() []Branch
    Leaves() []Leaf
    Branch(name string) Branch
    Leaf(name string) Leaf

    GoType() reflect.Type
    // contains filtered or unexported methods
}

Branch describes a branch of a ROOT Tree.

type Leaf Uses

type Leaf interface {
    root.Named

    ArrayDim() int
    Branch() Branch
    HasRange() bool
    IsUnsigned() bool
    LeafCount() Leaf // returns the leaf count if is variable length
    Len() int        // Len returns the number of fixed length elements
    LenType() int    // LenType returns the number of bytes for this data type
    MaxIndex() []int
    Offset() int
    Kind() reflect.Kind
    Type() reflect.Type
    Value(int) interface{}
    TypeName() string
    // contains filtered or unexported methods
}

Leaf describes branches data types

type LeafB Uses

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

LeafB implements ROOT TLeafB

func (*LeafB) ArrayDim Uses

func (leaf *LeafB) ArrayDim() int

func (*LeafB) Branch Uses

func (leaf *LeafB) Branch() Branch

func (*LeafB) Class Uses

func (leaf *LeafB) Class() string

Class returns the ROOT class name.

func (*LeafB) HasRange Uses

func (leaf *LeafB) HasRange() bool

func (*LeafB) IsUnsigned Uses

func (leaf *LeafB) IsUnsigned() bool

func (*LeafB) Kind Uses

func (*LeafB) Kind() reflect.Kind

Kind returns the leaf's kind.

func (*LeafB) LeafCount Uses

func (leaf *LeafB) LeafCount() Leaf

func (*LeafB) Len Uses

func (leaf *LeafB) Len() int

func (*LeafB) LenType Uses

func (leaf *LeafB) LenType() int

func (*LeafB) MarshalROOT Uses

func (leaf *LeafB) MarshalROOT(w *rbytes.WBuffer) (int, error)

func (*LeafB) MaxIndex Uses

func (leaf *LeafB) MaxIndex() []int

func (*LeafB) Maximum Uses

func (leaf *LeafB) Maximum() int8

Maximum returns the maximum value of the leaf.

func (*LeafB) Minimum Uses

func (leaf *LeafB) Minimum() int8

Minimum returns the minimum value of the leaf.

func (*LeafB) Name Uses

func (leaf *LeafB) Name() string

Name returns the name of the instance

func (*LeafB) Offset Uses

func (leaf *LeafB) Offset() int

func (*LeafB) Title Uses

func (leaf *LeafB) Title() string

Title returns the title of the instance

func (*LeafB) Type Uses

func (*LeafB) Type() reflect.Type

Type returns the leaf's type.

func (*LeafB) TypeName Uses

func (leaf *LeafB) TypeName() string

func (*LeafB) UnmarshalROOT Uses

func (leaf *LeafB) UnmarshalROOT(r *rbytes.RBuffer) error

func (*LeafB) Value Uses

func (leaf *LeafB) Value(i int) interface{}

Value returns the leaf value at index i.

type LeafC Uses

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

LeafC implements ROOT TLeafC

func (*LeafC) ArrayDim Uses

func (leaf *LeafC) ArrayDim() int

func (*LeafC) Branch Uses

func (leaf *LeafC) Branch() Branch

func (*LeafC) Class Uses

func (leaf *LeafC) Class() string

Class returns the ROOT class name.

func (*LeafC) HasRange Uses

func (leaf *LeafC) HasRange() bool

func (*LeafC) IsUnsigned Uses

func (leaf *LeafC) IsUnsigned() bool

func (*LeafC) Kind Uses

func (*LeafC) Kind() reflect.Kind

Kind returns the leaf's kind.

func (*LeafC) LeafCount Uses

func (leaf *LeafC) LeafCount() Leaf

func (*LeafC) Len Uses

func (leaf *LeafC) Len() int

func (*LeafC) LenType Uses

func (leaf *LeafC) LenType() int

func (*LeafC) MarshalROOT Uses

func (leaf *LeafC) MarshalROOT(w *rbytes.WBuffer) (int, error)

func (*LeafC) MaxIndex Uses

func (leaf *LeafC) MaxIndex() []int

func (*LeafC) Maximum Uses

func (leaf *LeafC) Maximum() int32

Maximum returns the maximum value of the leaf.

func (*LeafC) Minimum Uses

func (leaf *LeafC) Minimum() int32

Minimum returns the minimum value of the leaf.

func (*LeafC) Name Uses

func (leaf *LeafC) Name() string

Name returns the name of the instance

func (*LeafC) Offset Uses

func (leaf *LeafC) Offset() int

func (*LeafC) Title Uses

func (leaf *LeafC) Title() string

Title returns the title of the instance

func (*LeafC) Type Uses

func (*LeafC) Type() reflect.Type

Type returns the leaf's type.

func (*LeafC) TypeName Uses

func (leaf *LeafC) TypeName() string

func (*LeafC) UnmarshalROOT Uses

func (leaf *LeafC) UnmarshalROOT(r *rbytes.RBuffer) error

func (*LeafC) Value Uses

func (leaf *LeafC) Value(i int) interface{}

Value returns the leaf value at index i.

type LeafD Uses

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

LeafD implements ROOT TLeafD

func (*LeafD) ArrayDim Uses

func (leaf *LeafD) ArrayDim() int

func (*LeafD) Branch Uses

func (leaf *LeafD) Branch() Branch

func (*LeafD) Class Uses

func (leaf *LeafD) Class() string

Class returns the ROOT class name.

func (*LeafD) HasRange Uses

func (leaf *LeafD) HasRange() bool

func (*LeafD) IsUnsigned Uses

func (leaf *LeafD) IsUnsigned() bool

func (*LeafD) Kind Uses

func (*LeafD) Kind() reflect.Kind

Kind returns the leaf's kind.

func (*LeafD) LeafCount Uses

func (leaf *LeafD) LeafCount() Leaf

func (*LeafD) Len Uses

func (leaf *LeafD) Len() int

func (*LeafD) LenType Uses

func (leaf *LeafD) LenType() int

func (*LeafD) MarshalROOT Uses

func (leaf *LeafD) MarshalROOT(w *rbytes.WBuffer) (int, error)

func (*LeafD) MaxIndex Uses

func (leaf *LeafD) MaxIndex() []int

func (*LeafD) Maximum Uses

func (leaf *LeafD) Maximum() float64

Maximum returns the maximum value of the leaf.

func (*LeafD) Minimum Uses

func (leaf *LeafD) Minimum() float64

Minimum returns the minimum value of the leaf.

func (*LeafD) Name Uses

func (leaf *LeafD) Name() string

Name returns the name of the instance

func (*LeafD) Offset Uses

func (leaf *LeafD) Offset() int

func (*LeafD) Title Uses

func (leaf *LeafD) Title() string

Title returns the title of the instance

func (*LeafD) Type Uses

func (*LeafD) Type() reflect.Type

Type returns the leaf's type.

func (*LeafD) TypeName Uses

func (leaf *LeafD) TypeName() string

func (*LeafD) UnmarshalROOT Uses

func (leaf *LeafD) UnmarshalROOT(r *rbytes.RBuffer) error

func (*LeafD) Value Uses

func (leaf *LeafD) Value(i int) interface{}

Value returns the leaf value at index i.

type LeafF Uses

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

LeafF implements ROOT TLeafF

func (*LeafF) ArrayDim Uses

func (leaf *LeafF) ArrayDim() int

func (*LeafF) Branch Uses

func (leaf *LeafF) Branch() Branch

func (*LeafF) Class Uses

func (leaf *LeafF) Class() string

Class returns the ROOT class name.

func (*LeafF) HasRange Uses

func (leaf *LeafF) HasRange() bool

func (*LeafF) IsUnsigned Uses

func (leaf *LeafF) IsUnsigned() bool

func (*LeafF) Kind Uses

func (*LeafF) Kind() reflect.Kind

Kind returns the leaf's kind.

func (*LeafF) LeafCount Uses

func (leaf *LeafF) LeafCount() Leaf

func (*LeafF) Len Uses

func (leaf *LeafF) Len() int

func (*LeafF) LenType Uses

func (leaf *LeafF) LenType() int

func (*LeafF) MarshalROOT Uses

func (leaf *LeafF) MarshalROOT(w *rbytes.WBuffer) (int, error)

func (*LeafF) MaxIndex Uses

func (leaf *LeafF) MaxIndex() []int

func (*LeafF) Maximum Uses

func (leaf *LeafF) Maximum() float32

Maximum returns the maximum value of the leaf.

func (*LeafF) Minimum Uses

func (leaf *LeafF) Minimum() float32

Minimum returns the minimum value of the leaf.

func (*LeafF) Name Uses

func (leaf *LeafF) Name() string

Name returns the name of the instance

func (*LeafF) Offset Uses

func (leaf *LeafF) Offset() int

func (*LeafF) Title Uses

func (leaf *LeafF) Title() string

Title returns the title of the instance

func (*LeafF) Type Uses

func (*LeafF) Type() reflect.Type

Type returns the leaf's type.

func (*LeafF) TypeName Uses

func (leaf *LeafF) TypeName() string

func (*LeafF) UnmarshalROOT Uses

func (leaf *LeafF) UnmarshalROOT(r *rbytes.RBuffer) error

func (*LeafF) Value Uses

func (leaf *LeafF) Value(i int) interface{}

Value returns the leaf value at index i.

type LeafI Uses

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

LeafI implements ROOT TLeafI

func (*LeafI) ArrayDim Uses

func (leaf *LeafI) ArrayDim() int

func (*LeafI) Branch Uses

func (leaf *LeafI) Branch() Branch

func (*LeafI) Class Uses

func (leaf *LeafI) Class() string

Class returns the ROOT class name.

func (*LeafI) HasRange Uses

func (leaf *LeafI) HasRange() bool

func (*LeafI) IsUnsigned Uses

func (leaf *LeafI) IsUnsigned() bool

func (*LeafI) Kind Uses

func (*LeafI) Kind() reflect.Kind

Kind returns the leaf's kind.

func (*LeafI) LeafCount Uses

func (leaf *LeafI) LeafCount() Leaf

func (*LeafI) Len Uses

func (leaf *LeafI) Len() int

func (*LeafI) LenType Uses

func (leaf *LeafI) LenType() int

func (*LeafI) MarshalROOT Uses

func (leaf *LeafI) MarshalROOT(w *rbytes.WBuffer) (int, error)

func (*LeafI) MaxIndex Uses

func (leaf *LeafI) MaxIndex() []int

func (*LeafI) Maximum Uses

func (leaf *LeafI) Maximum() int32

Maximum returns the maximum value of the leaf.

func (*LeafI) Minimum Uses

func (leaf *LeafI) Minimum() int32

Minimum returns the minimum value of the leaf.

func (*LeafI) Name Uses

func (leaf *LeafI) Name() string

Name returns the name of the instance

func (*LeafI) Offset Uses

func (leaf *LeafI) Offset() int

func (*LeafI) Title Uses

func (leaf *LeafI) Title() string

Title returns the title of the instance

func (*LeafI) Type Uses

func (*LeafI) Type() reflect.Type

Type returns the leaf's type.

func (*LeafI) TypeName Uses

func (leaf *LeafI) TypeName() string

func (*LeafI) UnmarshalROOT Uses

func (leaf *LeafI) UnmarshalROOT(r *rbytes.RBuffer) error

func (*LeafI) Value Uses

func (leaf *LeafI) Value(i int) interface{}

Value returns the leaf value at index i.

type LeafL Uses

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

LeafL implements ROOT TLeafL

func (*LeafL) ArrayDim Uses

func (leaf *LeafL) ArrayDim() int

func (*LeafL) Branch Uses

func (leaf *LeafL) Branch() Branch

func (*LeafL) Class Uses

func (leaf *LeafL) Class() string

Class returns the ROOT class name.

func (*LeafL) HasRange Uses

func (leaf *LeafL) HasRange() bool

func (*LeafL) IsUnsigned Uses

func (leaf *LeafL) IsUnsigned() bool

func (*LeafL) Kind Uses

func (*LeafL) Kind() reflect.Kind

Kind returns the leaf's kind.

func (*LeafL) LeafCount Uses

func (leaf *LeafL) LeafCount() Leaf

func (*LeafL) Len Uses

func (leaf *LeafL) Len() int

func (*LeafL) LenType Uses

func (leaf *LeafL) LenType() int

func (*LeafL) MarshalROOT Uses

func (leaf *LeafL) MarshalROOT(w *rbytes.WBuffer) (int, error)

func (*LeafL) MaxIndex Uses

func (leaf *LeafL) MaxIndex() []int

func (*LeafL) Maximum Uses

func (leaf *LeafL) Maximum() int64

Maximum returns the maximum value of the leaf.

func (*LeafL) Minimum Uses

func (leaf *LeafL) Minimum() int64

Minimum returns the minimum value of the leaf.

func (*LeafL) Name Uses

func (leaf *LeafL) Name() string

Name returns the name of the instance

func (*LeafL) Offset Uses

func (leaf *LeafL) Offset() int

func (*LeafL) Title Uses

func (leaf *LeafL) Title() string

Title returns the title of the instance

func (*LeafL) Type Uses

func (*LeafL) Type() reflect.Type

Type returns the leaf's type.

func (*LeafL) TypeName Uses

func (leaf *LeafL) TypeName() string

func (*LeafL) UnmarshalROOT Uses

func (leaf *LeafL) UnmarshalROOT(r *rbytes.RBuffer) error

func (*LeafL) Value Uses

func (leaf *LeafL) Value(i int) interface{}

Value returns the leaf value at index i.

type LeafO Uses

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

LeafO implements ROOT TLeafO

func (*LeafO) ArrayDim Uses

func (leaf *LeafO) ArrayDim() int

func (*LeafO) Branch Uses

func (leaf *LeafO) Branch() Branch

func (*LeafO) Class Uses

func (leaf *LeafO) Class() string

Class returns the ROOT class name.

func (*LeafO) HasRange Uses

func (leaf *LeafO) HasRange() bool

func (*LeafO) IsUnsigned Uses

func (leaf *LeafO) IsUnsigned() bool

func (*LeafO) Kind Uses

func (*LeafO) Kind() reflect.Kind

Kind returns the leaf's kind.

func (*LeafO) LeafCount Uses

func (leaf *LeafO) LeafCount() Leaf

func (*LeafO) Len Uses

func (leaf *LeafO) Len() int

func (*LeafO) LenType Uses

func (leaf *LeafO) LenType() int

func (*LeafO) MarshalROOT Uses

func (leaf *LeafO) MarshalROOT(w *rbytes.WBuffer) (int, error)

func (*LeafO) MaxIndex Uses

func (leaf *LeafO) MaxIndex() []int

func (*LeafO) Maximum Uses

func (leaf *LeafO) Maximum() bool

Maximum returns the maximum value of the leaf.

func (*LeafO) Minimum Uses

func (leaf *LeafO) Minimum() bool

Minimum returns the minimum value of the leaf.

func (*LeafO) Name Uses

func (leaf *LeafO) Name() string

Name returns the name of the instance

func (*LeafO) Offset Uses

func (leaf *LeafO) Offset() int

func (*LeafO) Title Uses

func (leaf *LeafO) Title() string

Title returns the title of the instance

func (*LeafO) Type Uses

func (*LeafO) Type() reflect.Type

Type returns the leaf's type.

func (*LeafO) TypeName Uses

func (leaf *LeafO) TypeName() string

func (*LeafO) UnmarshalROOT Uses

func (leaf *LeafO) UnmarshalROOT(r *rbytes.RBuffer) error

func (*LeafO) Value Uses

func (leaf *LeafO) Value(i int) interface{}

Value returns the leaf value at index i.

type LeafS Uses

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

LeafS implements ROOT TLeafS

func (*LeafS) ArrayDim Uses

func (leaf *LeafS) ArrayDim() int

func (*LeafS) Branch Uses

func (leaf *LeafS) Branch() Branch

func (*LeafS) Class Uses

func (leaf *LeafS) Class() string

Class returns the ROOT class name.

func (*LeafS) HasRange Uses

func (leaf *LeafS) HasRange() bool

func (*LeafS) IsUnsigned Uses

func (leaf *LeafS) IsUnsigned() bool

func (*LeafS) Kind Uses

func (*LeafS) Kind() reflect.Kind

Kind returns the leaf's kind.

func (*LeafS) LeafCount Uses

func (leaf *LeafS) LeafCount() Leaf

func (*LeafS) Len Uses

func (leaf *LeafS) Len() int

func (*LeafS) LenType Uses

func (leaf *LeafS) LenType() int

func (*LeafS) MarshalROOT Uses

func (leaf *LeafS) MarshalROOT(w *rbytes.WBuffer) (int, error)

func (*LeafS) MaxIndex Uses

func (leaf *LeafS) MaxIndex() []int

func (*LeafS) Maximum Uses

func (leaf *LeafS) Maximum() int16

Maximum returns the maximum value of the leaf.

func (*LeafS) Minimum Uses

func (leaf *LeafS) Minimum() int16

Minimum returns the minimum value of the leaf.

func (*LeafS) Name Uses

func (leaf *LeafS) Name() string

Name returns the name of the instance

func (*LeafS) Offset Uses

func (leaf *LeafS) Offset() int

func (*LeafS) Title Uses

func (leaf *LeafS) Title() string

Title returns the title of the instance

func (*LeafS) Type Uses

func (*LeafS) Type() reflect.Type

Type returns the leaf's type.

func (*LeafS) TypeName Uses

func (leaf *LeafS) TypeName() string

func (*LeafS) UnmarshalROOT Uses

func (leaf *LeafS) UnmarshalROOT(r *rbytes.RBuffer) error

func (*LeafS) Value Uses

func (leaf *LeafS) Value(i int) interface{}

Value returns the leaf value at index i.

type ScanVar Uses

type ScanVar struct {
    Name  string      // name of the branch to read
    Leaf  string      // name of the leaf to read
    Value interface{} // pointer to the value to fill
}

ScanVar describes a variable to be read out of a tree during a scan.

type Scanner Uses

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

Scanner scans, selects and iterates over Tree entries. Scanner is bound to values the user provides, Scanner will then read data into these values during the tree scan.

Code:

log.SetPrefix("groot: ")
log.SetFlags(0)

f, err := riofs.Open("../testdata/small-flat-tree.root")
if err != nil {
    log.Fatal(err)
}
defer f.Close()

obj, err := f.Get("tree")
if err != nil {
    log.Fatal(err)
}

tree := obj.(rtree.Tree)

type Data struct {
    I64    int64       `groot:"Int64"`
    F64    float64     `groot:"Float64"`
    Str    string      `groot:"Str"`
    ArrF64 [10]float64 `groot:"ArrayFloat64"`
    N      int32       `groot:"N"`
    SliF64 []float64   `groot:"SliceFloat64"`
}

var data Data
sc, err := rtree.NewScanner(tree, &data)
if err != nil {
    log.Fatal(err)
}
defer sc.Close()

for sc.Next() {
    err := sc.Scan()
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("entry[%d]: %+v\n", sc.Entry(), data)
    if sc.Entry() == 9 {
        break
    }
}

if err := sc.Err(); err != nil && err != io.EOF {
    log.Fatal(err)
}

Output:

entry[0]: {I64:0 F64:0 Str:evt-000 ArrF64:[0 0 0 0 0 0 0 0 0 0] N:0 SliF64:[]}
entry[1]: {I64:1 F64:1 Str:evt-001 ArrF64:[1 1 1 1 1 1 1 1 1 1] N:1 SliF64:[1]}
entry[2]: {I64:2 F64:2 Str:evt-002 ArrF64:[2 2 2 2 2 2 2 2 2 2] N:2 SliF64:[2 2]}
entry[3]: {I64:3 F64:3 Str:evt-003 ArrF64:[3 3 3 3 3 3 3 3 3 3] N:3 SliF64:[3 3 3]}
entry[4]: {I64:4 F64:4 Str:evt-004 ArrF64:[4 4 4 4 4 4 4 4 4 4] N:4 SliF64:[4 4 4 4]}
entry[5]: {I64:5 F64:5 Str:evt-005 ArrF64:[5 5 5 5 5 5 5 5 5 5] N:5 SliF64:[5 5 5 5 5]}
entry[6]: {I64:6 F64:6 Str:evt-006 ArrF64:[6 6 6 6 6 6 6 6 6 6] N:6 SliF64:[6 6 6 6 6 6]}
entry[7]: {I64:7 F64:7 Str:evt-007 ArrF64:[7 7 7 7 7 7 7 7 7 7] N:7 SliF64:[7 7 7 7 7 7 7]}
entry[8]: {I64:8 F64:8 Str:evt-008 ArrF64:[8 8 8 8 8 8 8 8 8 8] N:8 SliF64:[8 8 8 8 8 8 8 8]}
entry[9]: {I64:9 F64:9 Str:evt-009 ArrF64:[9 9 9 9 9 9 9 9 9 9] N:9 SliF64:[9 9 9 9 9 9 9 9 9]}

Code:

log.SetPrefix("groot: ")
log.SetFlags(0)

f, err := riofs.Open("../testdata/small-flat-tree.root")
if err != nil {
    log.Fatal(err)
}
defer f.Close()

obj, err := f.Get("tree")
if err != nil {
    log.Fatal(err)
}

tree := obj.(rtree.Tree)

var (
    i64 int64
    f64 float64
    str string
    arr [10]float64
    n   int32
    sli []float64
)
scanVars := []rtree.ScanVar{
    {Name: "Int64", Value: &i64},
    {Name: "Float64", Value: &f64},
    {Name: "Str", Value: &str},
    {Name: "ArrayFloat64", Value: &arr},
    {Name: "N", Value: &n},
    {Name: "SliceFloat64", Value: &sli},
}
sc, err := rtree.NewScannerVars(tree, scanVars...)
if err != nil {
    log.Fatal(err)
}
defer sc.Close()

for sc.Next() {
    err := sc.Scan()
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf(
        "entry[%d]: i64=%v f64=%v str=%q arr=%v n=%d sli=%v\n",
        sc.Entry(),
        i64, f64, str, arr, n, sli,
    )
    if sc.Entry() == 9 {
        break
    }
}

if err := sc.Err(); err != nil && err != io.EOF {
    log.Fatal(err)
}

Output:

entry[0]: i64=0 f64=0 str="evt-000" arr=[0 0 0 0 0 0 0 0 0 0] n=0 sli=[]
entry[1]: i64=1 f64=1 str="evt-001" arr=[1 1 1 1 1 1 1 1 1 1] n=1 sli=[1]
entry[2]: i64=2 f64=2 str="evt-002" arr=[2 2 2 2 2 2 2 2 2 2] n=2 sli=[2 2]
entry[3]: i64=3 f64=3 str="evt-003" arr=[3 3 3 3 3 3 3 3 3 3] n=3 sli=[3 3 3]
entry[4]: i64=4 f64=4 str="evt-004" arr=[4 4 4 4 4 4 4 4 4 4] n=4 sli=[4 4 4 4]
entry[5]: i64=5 f64=5 str="evt-005" arr=[5 5 5 5 5 5 5 5 5 5] n=5 sli=[5 5 5 5 5]
entry[6]: i64=6 f64=6 str="evt-006" arr=[6 6 6 6 6 6 6 6 6 6] n=6 sli=[6 6 6 6 6 6]
entry[7]: i64=7 f64=7 str="evt-007" arr=[7 7 7 7 7 7 7 7 7 7] n=7 sli=[7 7 7 7 7 7 7]
entry[8]: i64=8 f64=8 str="evt-008" arr=[8 8 8 8 8 8 8 8 8 8] n=8 sli=[8 8 8 8 8 8 8 8]
entry[9]: i64=9 f64=9 str="evt-009" arr=[9 9 9 9 9 9 9 9 9 9] n=9 sli=[9 9 9 9 9 9 9 9 9]

func NewScanner Uses

func NewScanner(t Tree, ptr interface{}) (*Scanner, error)

NewScanner creates a new Scanner bound to a (pointer to a) struct value. Scanner will read the branches' data during Scan() and load them into the fields of the struct value.

func NewScannerVars Uses

func NewScannerVars(t Tree, vars ...ScanVar) (*Scanner, error)

NewScannerVars creates a new Scanner from a list of pairs (branch-name, target-address). Scanner will read the branches' data during Scan() and load them into these target-addresses.

func (*Scanner) Close Uses

func (s *Scanner) Close() error

Close closes the Scanner, preventing further iteration. Close is idempotent and does not affect the result of Err.

func (*Scanner) Entry Uses

func (s *Scanner) Entry() int64

Entry returns the entry number of the last read row.

func (*Scanner) Err Uses

func (s *Scanner) Err() error

Err returns the error, if any, that was encountered during iteration.

func (*Scanner) Next Uses

func (s *Scanner) Next() bool

Next prepares the next result row for reading with the Scan method. It returns true on success, false if there is no next result row. Every call to Scan, even the first one, must be preceded by a call to Next.

func (*Scanner) Scan Uses

func (s *Scanner) Scan() error

Scan copies data loaded from the underlying Tree into the values the Scanner is bound to. The values bound to the Scanner are valid until the next call to Scan.

func (*Scanner) SeekEntry Uses

func (s *Scanner) SeekEntry(i int64) error

SeekEntry points the scanner to the i-th entry, ready to call Next.

type Tree Uses

type Tree interface {
    root.Named

    Entries() int64
    TotBytes() int64
    ZipBytes() int64
    Branch(name string) Branch
    Branches() []Branch
    Leaf(name string) Leaf
    Leaves() []Leaf
    // contains filtered or unexported methods
}

func Chain Uses

func Chain(trees ...Tree) Tree

Chain returns a tchain that is the concatenation of all the input Trees.

ExampleChain shows how to create a chain made of 2 trees.

Code:

const name = "tree"

f1, err := groot.Open("../testdata/chain.1.root")
if err != nil {
    log.Fatal(err)
}
defer f1.Close()

o1, err := f1.Get(name)
if err != nil {
    log.Fatal(err)
}
t1 := o1.(rtree.Tree)

f2, err := groot.Open("../testdata/chain.2.root")
if err != nil {
    log.Fatal(err)
}
defer f2.Close()

o2, err := f2.Get(name)
if err != nil {
    log.Fatal(err)
}
t2 := o2.(rtree.Tree)

chain := rtree.Chain(t1, t2)

type Data struct {
    Event struct {
        Beg       string      `groot:"Beg"`
        F64       float64     `groot:"F64"`
        ArrF64    [10]float64 `groot:"ArrayF64"`
        N         int32       `groot:"N"`
        SliF64    []float64   `groot:"SliceF64"`
        StdStr    string      `groot:"StdStr"`
        StlVecF64 []float64   `groot:"StlVecF64"`
        StlVecStr []string    `groot:"StlVecStr"`
        End       string      `groot:"End"`
    } `groot:"evt"`
}

sc, err := rtree.NewTreeScanner(chain, &Data{})
if err != nil {
    log.Fatal(err)
}
defer sc.Close()

for sc.Next() {
    var data Data
    err := sc.Scan(&data)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("entry[%02d]: beg=%q f64=%v\n", sc.Entry(), data.Event.Beg, data.Event.F64)
}

if err := sc.Err(); err != nil {
    log.Fatalf("error during scan: %v", err)
}

Output:

entry[00]: beg="beg-000" f64=0
entry[01]: beg="beg-001" f64=1
entry[02]: beg="beg-002" f64=2
entry[03]: beg="beg-003" f64=3
entry[04]: beg="beg-004" f64=4
entry[05]: beg="beg-005" f64=5
entry[06]: beg="beg-006" f64=6
entry[07]: beg="beg-007" f64=7
entry[08]: beg="beg-008" f64=8
entry[09]: beg="beg-009" f64=9
entry[10]: beg="beg-010" f64=10
entry[11]: beg="beg-011" f64=11
entry[12]: beg="beg-012" f64=12
entry[13]: beg="beg-013" f64=13
entry[14]: beg="beg-014" f64=14
entry[15]: beg="beg-015" f64=15
entry[16]: beg="beg-016" f64=16
entry[17]: beg="beg-017" f64=17
entry[18]: beg="beg-018" f64=18
entry[19]: beg="beg-019" f64=19

func ChainOf Uses

func ChainOf(name string, files ...string) (Tree, func() error, error)

ChainOf returns a Tree, a close function and an error if any. The tree is the logical concatenation of all the name trees located in the input named files. The close function allows to close all the open named files.

ExampleChainOf shows how to create a chain made of trees from 2 files.

Code:

const name = "tree"

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

type Data struct {
    Event struct {
        Beg       string      `groot:"Beg"`
        F64       float64     `groot:"F64"`
        ArrF64    [10]float64 `groot:"ArrayF64"`
        N         int32       `groot:"N"`
        SliF64    []float64   `groot:"SliceF64"`
        StdStr    string      `groot:"StdStr"`
        StlVecF64 []float64   `groot:"StlVecF64"`
        StlVecStr []string    `groot:"StlVecStr"`
        End       string      `groot:"End"`
    } `groot:"evt"`
}

sc, err := rtree.NewTreeScanner(chain, &Data{})
if err != nil {
    log.Fatal(err)
}
defer sc.Close()

for sc.Next() {
    var data Data
    err := sc.Scan(&data)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("entry[%02d]: beg=%q f64=%v\n", sc.Entry(), data.Event.Beg, data.Event.F64)
}

if err := sc.Err(); err != nil {
    log.Fatalf("error during scan: %v", err)
}

Output:

entry[00]: beg="beg-000" f64=0
entry[01]: beg="beg-001" f64=1
entry[02]: beg="beg-002" f64=2
entry[03]: beg="beg-003" f64=3
entry[04]: beg="beg-004" f64=4
entry[05]: beg="beg-005" f64=5
entry[06]: beg="beg-006" f64=6
entry[07]: beg="beg-007" f64=7
entry[08]: beg="beg-008" f64=8
entry[09]: beg="beg-009" f64=9
entry[10]: beg="beg-010" f64=10
entry[11]: beg="beg-011" f64=11
entry[12]: beg="beg-012" f64=12
entry[13]: beg="beg-013" f64=13
entry[14]: beg="beg-014" f64=14
entry[15]: beg="beg-015" f64=15
entry[16]: beg="beg-016" f64=16
entry[17]: beg="beg-017" f64=17
entry[18]: beg="beg-018" f64=18
entry[19]: beg="beg-019" f64=19

type TreeScanner Uses

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

TreeScanner scans, selects and iterates over Tree entries.

Code:

log.SetPrefix("groot: ")
log.SetFlags(0)

f, err := riofs.Open("../testdata/small-flat-tree.root")
if err != nil {
    log.Fatal(err)
}
defer f.Close()

obj, err := f.Get("tree")
if err != nil {
    log.Fatal(err)
}

tree := obj.(rtree.Tree)

type Data struct {
    I64    int64       `groot:"Int64"`
    F64    float64     `groot:"Float64"`
    Str    string      `groot:"Str"`
    ArrF64 [10]float64 `groot:"ArrayFloat64"`
    N      int32       `groot:"N"`
    SliF64 []float64   `groot:"SliceFloat64"`
}

sc, err := rtree.NewTreeScanner(tree, &Data{})
if err != nil {
    log.Fatal(err)
}
defer sc.Close()

for sc.Next() {
    var data Data
    err := sc.Scan(&data)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("entry[%d]: %+v\n", sc.Entry(), data)
    if sc.Entry() == 9 {
        break
    }
}

if err := sc.Err(); err != nil && err != io.EOF {
    log.Fatal(err)
}

Output:

entry[0]: {I64:0 F64:0 Str:evt-000 ArrF64:[0 0 0 0 0 0 0 0 0 0] N:0 SliF64:[]}
entry[1]: {I64:1 F64:1 Str:evt-001 ArrF64:[1 1 1 1 1 1 1 1 1 1] N:1 SliF64:[1]}
entry[2]: {I64:2 F64:2 Str:evt-002 ArrF64:[2 2 2 2 2 2 2 2 2 2] N:2 SliF64:[2 2]}
entry[3]: {I64:3 F64:3 Str:evt-003 ArrF64:[3 3 3 3 3 3 3 3 3 3] N:3 SliF64:[3 3 3]}
entry[4]: {I64:4 F64:4 Str:evt-004 ArrF64:[4 4 4 4 4 4 4 4 4 4] N:4 SliF64:[4 4 4 4]}
entry[5]: {I64:5 F64:5 Str:evt-005 ArrF64:[5 5 5 5 5 5 5 5 5 5] N:5 SliF64:[5 5 5 5 5]}
entry[6]: {I64:6 F64:6 Str:evt-006 ArrF64:[6 6 6 6 6 6 6 6 6 6] N:6 SliF64:[6 6 6 6 6 6]}
entry[7]: {I64:7 F64:7 Str:evt-007 ArrF64:[7 7 7 7 7 7 7 7 7 7] N:7 SliF64:[7 7 7 7 7 7 7]}
entry[8]: {I64:8 F64:8 Str:evt-008 ArrF64:[8 8 8 8 8 8 8 8 8 8] N:8 SliF64:[8 8 8 8 8 8 8 8]}
entry[9]: {I64:9 F64:9 Str:evt-009 ArrF64:[9 9 9 9 9 9 9 9 9 9] N:9 SliF64:[9 9 9 9 9 9 9 9 9]}

Code:

log.SetPrefix("groot: ")
log.SetFlags(0)

f, err := riofs.Open("../testdata/small-flat-tree.root")
if err != nil {
    log.Fatal(err)
}
defer f.Close()

obj, err := f.Get("tree")
if err != nil {
    log.Fatal(err)
}

tree := obj.(rtree.Tree)

scanVars := []rtree.ScanVar{
    {Name: "Int64"},
    {Name: "Float64"},
    {Name: "Str"},
    {Name: "ArrayFloat64"},
    {Name: "N"},
    {Name: "SliceFloat64"},
}
sc, err := rtree.NewTreeScannerVars(tree, scanVars...)
if err != nil {
    log.Fatal(err)
}
defer sc.Close()

for sc.Next() {
    var (
        i64 int64
        f64 float64
        str string
        arr [10]float64
        n   int32
        sli []float64
    )
    err := sc.Scan(&i64, &f64, &str, &arr, &n, &sli)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf(
        "entry[%d]: i64=%v f64=%v str=%q arr=%v n=%d sli=%v\n",
        sc.Entry(),
        i64, f64, str, arr, n, sli,
    )
    if sc.Entry() == 9 {
        break
    }
}

if err := sc.Err(); err != nil && err != io.EOF {
    log.Fatal(err)
}

Output:

entry[0]: i64=0 f64=0 str="evt-000" arr=[0 0 0 0 0 0 0 0 0 0] n=0 sli=[]
entry[1]: i64=1 f64=1 str="evt-001" arr=[1 1 1 1 1 1 1 1 1 1] n=1 sli=[1]
entry[2]: i64=2 f64=2 str="evt-002" arr=[2 2 2 2 2 2 2 2 2 2] n=2 sli=[2 2]
entry[3]: i64=3 f64=3 str="evt-003" arr=[3 3 3 3 3 3 3 3 3 3] n=3 sli=[3 3 3]
entry[4]: i64=4 f64=4 str="evt-004" arr=[4 4 4 4 4 4 4 4 4 4] n=4 sli=[4 4 4 4]
entry[5]: i64=5 f64=5 str="evt-005" arr=[5 5 5 5 5 5 5 5 5 5] n=5 sli=[5 5 5 5 5]
entry[6]: i64=6 f64=6 str="evt-006" arr=[6 6 6 6 6 6 6 6 6 6] n=6 sli=[6 6 6 6 6 6]
entry[7]: i64=7 f64=7 str="evt-007" arr=[7 7 7 7 7 7 7 7 7 7] n=7 sli=[7 7 7 7 7 7 7]
entry[8]: i64=8 f64=8 str="evt-008" arr=[8 8 8 8 8 8 8 8 8 8] n=8 sli=[8 8 8 8 8 8 8 8]
entry[9]: i64=9 f64=9 str="evt-009" arr=[9 9 9 9 9 9 9 9 9 9] n=9 sli=[9 9 9 9 9 9 9 9 9]

func NewTreeScanner Uses

func NewTreeScanner(t Tree, ptr interface{}) (*TreeScanner, error)

NewTreeScanner creates a new Scanner connecting the pointer to some user provided type to the given Tree.

func NewTreeScannerVars Uses

func NewTreeScannerVars(t Tree, vars ...ScanVar) (*TreeScanner, error)

NewTreeScannerVars creates a new Scanner from a list of branches. It will return an error if the provided type does not match the type stored in the corresponding branch.

func (*TreeScanner) Close Uses

func (s *TreeScanner) Close() error

Close closes the TreeScanner, preventing further iteration. Close is idempotent and does not affect the result of Err.

func (*TreeScanner) Entry Uses

func (s *TreeScanner) Entry() int64

Entry returns the entry number of the last read row.

func (*TreeScanner) Err Uses

func (s *TreeScanner) Err() error

Err returns the error, if any, that was encountered during iteration.

func (*TreeScanner) Next Uses

func (s *TreeScanner) Next() bool

Next prepares the next result row for reading with the Scan method. It returns true on success, false if there is no next result row. Every call to Scan, even the first one, must be preceded by a call to Next.

func (*TreeScanner) Scan Uses

func (s *TreeScanner) Scan(args ...interface{}) (err error)

Scan copies data loaded from the underlying Tree into the values pointed at by args.

func (*TreeScanner) SeekEntry Uses

func (s *TreeScanner) SeekEntry(i int64) error

SeekEntry points the scanner to the i-th entry, ready to call Next.

Package rtree imports 12 packages (graph) and is imported by 13 packages. Updated 2019-05-17. Refresh now. Tools for package owners.