go-hep.org/x/hep@v0.38.1/groot/rtree/rtree.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 rtree contains the interfaces and types to decode, read, concatenate
     6  // and iterate over ROOT Trees.
     7  package rtree // import "go-hep.org/x/hep/groot/rtree"
     8  
     9  import (
    10  	"reflect" // Tree is a collection of branches of data.
    11  
    12  	"go-hep.org/x/hep/groot/rbytes"
    13  	"go-hep.org/x/hep/groot/riofs"
    14  	"go-hep.org/x/hep/groot/root"
    15  )
    16  
    17  // FileOf returns the file hosting the given Tree.
    18  // If the tree is not connected to any ROOT file, nil is returned.
    19  func FileOf(tree Tree) *riofs.File { return tree.(*ttree).f }
    20  
    21  type Tree interface {
    22  	root.Named
    23  
    24  	Entries() int64
    25  	Branch(name string) Branch
    26  	Branches() []Branch
    27  	Leaf(name string) Leaf
    28  	Leaves() []Leaf
    29  }
    30  
    31  // Branch describes a branch of a ROOT Tree.
    32  type Branch interface {
    33  	root.Named
    34  
    35  	Branches() []Branch
    36  	Leaves() []Leaf
    37  	Branch(name string) Branch
    38  	Leaf(name string) Leaf
    39  
    40  	setTree(*ttree)
    41  	getTree() *ttree
    42  	loadEntry(i int64) error
    43  	getReadEntry() int64
    44  	getEntry(i int64)
    45  	setStreamer(s rbytes.StreamerInfo, ctx rbytes.StreamerInfoContext)
    46  	setStreamerElement(s rbytes.StreamerElement, ctx rbytes.StreamerInfoContext)
    47  	GoType() reflect.Type
    48  
    49  	// write interface part
    50  	writeToBuffer(w *rbytes.WBuffer) (int, error)
    51  	write() (int, error)
    52  	flush() error
    53  }
    54  
    55  // Leaf describes branches data types
    56  type Leaf interface {
    57  	root.Named
    58  
    59  	Branch() Branch
    60  	HasRange() bool
    61  	IsUnsigned() bool
    62  	LeafCount() Leaf // returns the leaf count if is variable length
    63  	Len() int        // Len returns the number of fixed length elements
    64  	LenType() int    // LenType returns the number of bytes for this data type
    65  	Shape() []int
    66  	Offset() int
    67  	Kind() reflect.Kind
    68  	Type() reflect.Type
    69  	TypeName() string
    70  
    71  	setBranch(Branch)
    72  	readFromBuffer(r *rbytes.RBuffer) error
    73  	setAddress(ptr any) error
    74  
    75  	// write interface part
    76  	writeToBuffer(w *rbytes.WBuffer) (int, error)
    77  
    78  	canGenerateOffsetArray() bool
    79  	computeOffsetArray(base, nevts int) []int32
    80  }
    81  
    82  // leafCount describes leaves that are used for array length count
    83  type leafCount interface {
    84  	Leaf
    85  	ivalue() int // for leaf-count
    86  	imax() int
    87  }
    88  
    89  func maxI64(a, b int64) int64 {
    90  	if a > b {
    91  		return a
    92  	}
    93  	return b
    94  }
    95  
    96  func minI64(a, b int64) int64 {
    97  	if a < b {
    98  		return a
    99  	}
   100  	return b
   101  }