Documentation
¶
Overview ¶
Package rootio provides a pure-go read-access to ROOT files. rootio might, with time, provide write-access too.
A typical usage is as follows:
f, err := rootio.Open("ntup.root")
if err != nil {
log.Fatal(err)
}
defer f.Close()
obj, err := f.Get("tree")
if err != nil {
log.Fatal(err)
}
tree := obj.(rootio.Tree)
fmt.Printf("entries= %v\n", tree.Entries())
More complete examples on how to iterate over the content of a Tree can be found in the examples attached to rootio.TreeScanner and rootio.Scanner: https://godoc.org/go-hep.org/x/hep/rootio#pkg-examples
Another possibility is to look at: https://godoc.org/go-hep.org/x/hep/rootio/cmd/root-ls, a command that inspects the content of ROOT files.
Index ¶
- Variables
- type Array
- type ArrayD
- type ArrayF
- type ArrayI
- type ArrayL64
- type Axis
- type Basket
- type Branch
- type Class
- type ClassFactory
- type Collection
- type Directory
- type FactoryFct
- type File
- func (f *File) Class() string
- func (f *File) Close() error
- func (f *File) Get(namecycle string) (Object, error)
- func (f *File) Keys() []Key
- func (f *File) Map()
- func (f *File) Name() string
- func (f *File) Read(p []byte) (int, error)
- func (f *File) ReadAt(p []byte, off int64) (int, error)
- func (f *File) Seek(offset int64, whence int) (int64, error)
- func (f *File) StreamerInfo() []StreamerInfo
- func (f *File) Tell() int64
- func (f *File) Title() string
- func (f *File) Version() int
- type Graph
- type GraphErrors
- type H1
- type H1D
- func (h *H1D) Array() ArrayD
- func (*H1D) Class() string
- func (h *H1D) Entries() float64
- func (h *H1D) MarshalYODA() ([]byte, error)
- func (h *H1D) NbinsX() int
- func (h *H1D) Rank() int
- func (h *H1D) SumW() float64
- func (h *H1D) SumW2() float64
- func (h *H1D) SumW2s() []float64
- func (h *H1D) SumWX() float64
- func (h *H1D) SumWX2() float64
- func (h *H1D) UnmarshalROOT(r *RBuffer) error
- func (h *H1D) XAxis() Axis
- func (h *H1D) XBinCenter(i int) float64
- func (h *H1D) XBinContent(i int) float64
- func (h *H1D) XBinError(i int) float64
- func (h *H1D) XBinLowEdge(i int) float64
- func (h *H1D) XBinWidth(i int) float64
- type H1F
- func (h *H1F) Array() ArrayF
- func (*H1F) Class() string
- func (h *H1F) Entries() float64
- func (h *H1F) MarshalYODA() ([]byte, error)
- func (h *H1F) NbinsX() int
- func (h *H1F) Rank() int
- func (h *H1F) SumW() float64
- func (h *H1F) SumW2() float64
- func (h *H1F) SumW2s() []float64
- func (h *H1F) SumWX() float64
- func (h *H1F) SumWX2() float64
- func (h *H1F) UnmarshalROOT(r *RBuffer) error
- func (h *H1F) XAxis() Axis
- func (h *H1F) XBinCenter(i int) float64
- func (h *H1F) XBinContent(i int) float64
- func (h *H1F) XBinError(i int) float64
- func (h *H1F) XBinLowEdge(i int) float64
- func (h *H1F) XBinWidth(i int) float64
- type H1I
- func (h *H1I) Array() ArrayI
- func (*H1I) Class() string
- func (h *H1I) Entries() float64
- func (h *H1I) MarshalYODA() ([]byte, error)
- func (h *H1I) NbinsX() int
- func (h *H1I) Rank() int
- func (h *H1I) SumW() float64
- func (h *H1I) SumW2() float64
- func (h *H1I) SumW2s() []float64
- func (h *H1I) SumWX() float64
- func (h *H1I) SumWX2() float64
- func (h *H1I) UnmarshalROOT(r *RBuffer) error
- func (h *H1I) XAxis() Axis
- func (h *H1I) XBinCenter(i int) float64
- func (h *H1I) XBinContent(i int) float64
- func (h *H1I) XBinError(i int) float64
- func (h *H1I) XBinLowEdge(i int) float64
- func (h *H1I) XBinWidth(i int) float64
- type H2
- type H2D
- func (h *H2D) Array() ArrayD
- func (*H2D) Class() string
- func (h *H2D) MarshalYODA() ([]byte, error)
- func (h *H2D) NbinsX() int
- func (h *H2D) NbinsY() int
- func (h *H2D) Rank() int
- func (h *H2D) SumWXY() float64
- func (h *H2D) SumWY() float64
- func (h *H2D) SumWY2() float64
- func (h *H2D) UnmarshalROOT(r *RBuffer) error
- func (h *H2D) XAxis() Axis
- func (h *H2D) XBinCenter(i int) float64
- func (h *H2D) XBinContent(i int) float64
- func (h *H2D) XBinError(i int) float64
- func (h *H2D) XBinLowEdge(i int) float64
- func (h *H2D) XBinWidth(i int) float64
- func (h *H2D) YAxis() Axis
- func (h *H2D) YBinCenter(i int) float64
- func (h *H2D) YBinContent(i int) float64
- func (h *H2D) YBinError(i int) float64
- func (h *H2D) YBinLowEdge(i int) float64
- func (h *H2D) YBinWidth(i int) float64
- type H2F
- func (h *H2F) Array() ArrayF
- func (*H2F) Class() string
- func (h *H2F) MarshalYODA() ([]byte, error)
- func (h *H2F) NbinsX() int
- func (h *H2F) NbinsY() int
- func (h *H2F) Rank() int
- func (h *H2F) SumWXY() float64
- func (h *H2F) SumWY() float64
- func (h *H2F) SumWY2() float64
- func (h *H2F) UnmarshalROOT(r *RBuffer) error
- func (h *H2F) XAxis() Axis
- func (h *H2F) XBinCenter(i int) float64
- func (h *H2F) XBinContent(i int) float64
- func (h *H2F) XBinError(i int) float64
- func (h *H2F) XBinLowEdge(i int) float64
- func (h *H2F) XBinWidth(i int) float64
- func (h *H2F) YAxis() Axis
- func (h *H2F) YBinCenter(i int) float64
- func (h *H2F) YBinContent(i int) float64
- func (h *H2F) YBinError(i int) float64
- func (h *H2F) YBinLowEdge(i int) float64
- func (h *H2F) YBinWidth(i int) float64
- type H2I
- func (h *H2I) Array() ArrayI
- func (*H2I) Class() string
- func (h *H2I) MarshalYODA() ([]byte, error)
- func (h *H2I) NbinsX() int
- func (h *H2I) NbinsY() int
- func (h *H2I) Rank() int
- func (h *H2I) SumWXY() float64
- func (h *H2I) SumWY() float64
- func (h *H2I) SumWY2() float64
- func (h *H2I) UnmarshalROOT(r *RBuffer) error
- func (h *H2I) XAxis() Axis
- func (h *H2I) XBinCenter(i int) float64
- func (h *H2I) XBinContent(i int) float64
- func (h *H2I) XBinError(i int) float64
- func (h *H2I) XBinLowEdge(i int) float64
- func (h *H2I) XBinWidth(i int) float64
- func (h *H2I) YAxis() Axis
- func (h *H2I) YBinCenter(i int) float64
- func (h *H2I) YBinContent(i int) float64
- func (h *H2I) YBinError(i int) float64
- func (h *H2I) YBinLowEdge(i int) float64
- func (h *H2I) YBinWidth(i int) float64
- type Key
- type Leaf
- type LeafB
- func (leaf *LeafB) ArrayDim() int
- func (leaf *LeafB) Branch() Branch
- func (leaf *LeafB) Class() string
- func (leaf *LeafB) HasRange() bool
- func (leaf *LeafB) IsUnsigned() bool
- func (*LeafB) Kind() reflect.Kind
- func (leaf *LeafB) LeafCount() Leaf
- func (leaf *LeafB) Len() int
- func (leaf *LeafB) LenType() int
- func (leaf *LeafB) MaxIndex() []int
- func (leaf *LeafB) Maximum() int8
- func (leaf *LeafB) Minimum() int8
- func (leaf *LeafB) Name() string
- func (leaf *LeafB) Offset() int
- func (leaf *LeafB) Title() string
- func (*LeafB) Type() reflect.Type
- func (leaf *LeafB) TypeName() string
- func (leaf *LeafB) UnmarshalROOT(r *RBuffer) error
- func (leaf *LeafB) Value(i int) interface{}
- type LeafC
- func (leaf *LeafC) ArrayDim() int
- func (leaf *LeafC) Branch() Branch
- func (leaf *LeafC) Class() string
- func (leaf *LeafC) HasRange() bool
- func (leaf *LeafC) IsUnsigned() bool
- func (*LeafC) Kind() reflect.Kind
- func (leaf *LeafC) LeafCount() Leaf
- func (leaf *LeafC) Len() int
- func (leaf *LeafC) LenType() int
- func (leaf *LeafC) MaxIndex() []int
- func (leaf *LeafC) Maximum() int32
- func (leaf *LeafC) Minimum() int32
- func (leaf *LeafC) Name() string
- func (leaf *LeafC) Offset() int
- func (leaf *LeafC) Title() string
- func (*LeafC) Type() reflect.Type
- func (leaf *LeafC) TypeName() string
- func (leaf *LeafC) UnmarshalROOT(r *RBuffer) error
- func (leaf *LeafC) Value(i int) interface{}
- type LeafD
- func (leaf *LeafD) ArrayDim() int
- func (leaf *LeafD) Branch() Branch
- func (leaf *LeafD) Class() string
- func (leaf *LeafD) HasRange() bool
- func (leaf *LeafD) IsUnsigned() bool
- func (*LeafD) Kind() reflect.Kind
- func (leaf *LeafD) LeafCount() Leaf
- func (leaf *LeafD) Len() int
- func (leaf *LeafD) LenType() int
- func (leaf *LeafD) MaxIndex() []int
- func (leaf *LeafD) Maximum() float64
- func (leaf *LeafD) Minimum() float64
- func (leaf *LeafD) Name() string
- func (leaf *LeafD) Offset() int
- func (leaf *LeafD) Title() string
- func (*LeafD) Type() reflect.Type
- func (leaf *LeafD) TypeName() string
- func (leaf *LeafD) UnmarshalROOT(r *RBuffer) error
- func (leaf *LeafD) Value(i int) interface{}
- type LeafF
- func (leaf *LeafF) ArrayDim() int
- func (leaf *LeafF) Branch() Branch
- func (leaf *LeafF) Class() string
- func (leaf *LeafF) HasRange() bool
- func (leaf *LeafF) IsUnsigned() bool
- func (*LeafF) Kind() reflect.Kind
- func (leaf *LeafF) LeafCount() Leaf
- func (leaf *LeafF) Len() int
- func (leaf *LeafF) LenType() int
- func (leaf *LeafF) MaxIndex() []int
- func (leaf *LeafF) Maximum() float32
- func (leaf *LeafF) Minimum() float32
- func (leaf *LeafF) Name() string
- func (leaf *LeafF) Offset() int
- func (leaf *LeafF) Title() string
- func (*LeafF) Type() reflect.Type
- func (leaf *LeafF) TypeName() string
- func (leaf *LeafF) UnmarshalROOT(r *RBuffer) error
- func (leaf *LeafF) Value(i int) interface{}
- type LeafI
- func (leaf *LeafI) ArrayDim() int
- func (leaf *LeafI) Branch() Branch
- func (leaf *LeafI) Class() string
- func (leaf *LeafI) HasRange() bool
- func (leaf *LeafI) IsUnsigned() bool
- func (*LeafI) Kind() reflect.Kind
- func (leaf *LeafI) LeafCount() Leaf
- func (leaf *LeafI) Len() int
- func (leaf *LeafI) LenType() int
- func (leaf *LeafI) MaxIndex() []int
- func (leaf *LeafI) Maximum() int32
- func (leaf *LeafI) Minimum() int32
- func (leaf *LeafI) Name() string
- func (leaf *LeafI) Offset() int
- func (leaf *LeafI) Title() string
- func (*LeafI) Type() reflect.Type
- func (leaf *LeafI) TypeName() string
- func (leaf *LeafI) UnmarshalROOT(r *RBuffer) error
- func (leaf *LeafI) Value(i int) interface{}
- type LeafL
- func (leaf *LeafL) ArrayDim() int
- func (leaf *LeafL) Branch() Branch
- func (leaf *LeafL) Class() string
- func (leaf *LeafL) HasRange() bool
- func (leaf *LeafL) IsUnsigned() bool
- func (*LeafL) Kind() reflect.Kind
- func (leaf *LeafL) LeafCount() Leaf
- func (leaf *LeafL) Len() int
- func (leaf *LeafL) LenType() int
- func (leaf *LeafL) MaxIndex() []int
- func (leaf *LeafL) Maximum() int64
- func (leaf *LeafL) Minimum() int64
- func (leaf *LeafL) Name() string
- func (leaf *LeafL) Offset() int
- func (leaf *LeafL) Title() string
- func (*LeafL) Type() reflect.Type
- func (leaf *LeafL) TypeName() string
- func (leaf *LeafL) UnmarshalROOT(r *RBuffer) error
- func (leaf *LeafL) Value(i int) interface{}
- type LeafO
- func (leaf *LeafO) ArrayDim() int
- func (leaf *LeafO) Branch() Branch
- func (leaf *LeafO) Class() string
- func (leaf *LeafO) HasRange() bool
- func (leaf *LeafO) IsUnsigned() bool
- func (*LeafO) Kind() reflect.Kind
- func (leaf *LeafO) LeafCount() Leaf
- func (leaf *LeafO) Len() int
- func (leaf *LeafO) LenType() int
- func (leaf *LeafO) MaxIndex() []int
- func (leaf *LeafO) Maximum() bool
- func (leaf *LeafO) Minimum() bool
- func (leaf *LeafO) Name() string
- func (leaf *LeafO) Offset() int
- func (leaf *LeafO) Title() string
- func (*LeafO) Type() reflect.Type
- func (leaf *LeafO) TypeName() string
- func (leaf *LeafO) UnmarshalROOT(r *RBuffer) error
- func (leaf *LeafO) Value(i int) interface{}
- type LeafS
- func (leaf *LeafS) ArrayDim() int
- func (leaf *LeafS) Branch() Branch
- func (leaf *LeafS) Class() string
- func (leaf *LeafS) HasRange() bool
- func (leaf *LeafS) IsUnsigned() bool
- func (*LeafS) Kind() reflect.Kind
- func (leaf *LeafS) LeafCount() Leaf
- func (leaf *LeafS) Len() int
- func (leaf *LeafS) LenType() int
- func (leaf *LeafS) MaxIndex() []int
- func (leaf *LeafS) Maximum() int16
- func (leaf *LeafS) Minimum() int16
- func (leaf *LeafS) Name() string
- func (leaf *LeafS) Offset() int
- func (leaf *LeafS) Title() string
- func (*LeafS) Type() reflect.Type
- func (leaf *LeafS) TypeName() string
- func (leaf *LeafS) UnmarshalROOT(r *RBuffer) error
- func (leaf *LeafS) Value(i int) interface{}
- type List
- type Member
- type Named
- type ObjArray
- type Object
- type RBuffer
- func (r *RBuffer) CheckByteCount(pos, count int32, start int64, class string)
- func (r *RBuffer) Err() error
- func (r *RBuffer) Len() int64
- func (r *RBuffer) Pos() int64
- func (r *RBuffer) ReadBool() bool
- func (r *RBuffer) ReadCString(n int) string
- func (r *RBuffer) ReadF32() float32
- func (r *RBuffer) ReadF64() float64
- func (r *RBuffer) ReadFastArrayBool(n int) []bool
- func (r *RBuffer) ReadFastArrayF32(n int) []float32
- func (r *RBuffer) ReadFastArrayF64(n int) []float64
- func (r *RBuffer) ReadFastArrayI8(n int) []int8
- func (r *RBuffer) ReadFastArrayI16(n int) []int16
- func (r *RBuffer) ReadFastArrayI32(n int) []int32
- func (r *RBuffer) ReadFastArrayI64(n int) []int64
- func (r *RBuffer) ReadFastArrayString(n int) []string
- func (r *RBuffer) ReadFastArrayU8(n int) []uint8
- func (r *RBuffer) ReadFastArrayU16(n int) []uint16
- func (r *RBuffer) ReadFastArrayU32(n int) []uint32
- func (r *RBuffer) ReadFastArrayU64(n int) []uint64
- func (r *RBuffer) ReadI8() int8
- func (r *RBuffer) ReadI16() int16
- func (r *RBuffer) ReadI32() int32
- func (r *RBuffer) ReadI64() int64
- func (r *RBuffer) ReadObject(class string) Object
- func (r *RBuffer) ReadObjectAny() (obj Object)
- func (r *RBuffer) ReadStaticArrayI32() []int32
- func (r *RBuffer) ReadString() string
- func (r *RBuffer) ReadU8() uint8
- func (r *RBuffer) ReadU16() uint16
- func (r *RBuffer) ReadU32() uint32
- func (r *RBuffer) ReadU64() uint64
- func (r *RBuffer) ReadVersion() (vers int16, pos, n int32)
- func (r *RBuffer) SkipObject()
- func (r *RBuffer) SkipVersion(class string)
- type ROOTMarshaler
- type ROOTUnmarshaler
- type RStreamer
- type Reader
- type ScanVar
- type Scanner
- type SeqCollection
- type SetFiler
- type StreamerElement
- type StreamerInfo
- type Tree
- type TreeScanner
- type Writer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Factory = factory{ // contains filtered or unexported fields }
Functions ¶
This section is empty.
Types ¶
type Array ¶
type Array interface {
Len() int // number of array elements
Get(i int) interface{}
Set(i int, v interface{})
}
Array describes ROOT abstract array type.
type ArrayD ¶
type ArrayD struct {
Data []float64
}
ArrayD implements ROOT TArrayD
func (*ArrayD) UnmarshalROOT ¶
type ArrayF ¶
type ArrayF struct {
Data []float32
}
ArrayF implements ROOT TArrayF
func (*ArrayF) UnmarshalROOT ¶
type ArrayI ¶
type ArrayI struct {
Data []int32
}
ArrayI implements ROOT TArrayI
func (*ArrayI) UnmarshalROOT ¶
type ArrayL64 ¶
type ArrayL64 struct {
Data []int64
}
ArrayL64 implements ROOT TArrayL64
func (*ArrayL64) UnmarshalROOT ¶
type Axis ¶
type Axis interface {
Named
XMin() float64
XMax() float64
NBins() int
XBins() []float64
BinCenter(int) float64
BinLowEdge(int) float64
BinWidth(int) float64
}
Axis describes a ROOT TAxis.
type Basket ¶
type Basket struct {
// contains filtered or unexported fields
}
func (*Basket) UnmarshalROOT ¶
type Branch ¶
type Branch interface {
Named
Branches() []Branch
Leaves() []Leaf
// contains filtered or unexported methods
}
Branch describes a branch of a ROOT Tree.
type Class ¶
type Class interface {
// GetCheckSum gets the check sum for this ROOT class
CheckSum() int
// Members returns the list of members for this ROOT class
Members() []Member
// Version returns the version number for this ROOT class
Version() int
// ClassName returns the ROOT class name for this ROOT class
ClassName() string
}
Class represents a ROOT class. Class instances are created by a ClassFactory.
type ClassFactory ¶
ClassFactory creates ROOT classes
type Collection ¶
type Collection interface {
Object
// Name returns the name of the collection.
Name() string
// Last returns the last element index
Last() int
// At returns the element at index i
At(i int) Object
// Len returns the number of elements in the collection
Len() int
}
Collection is a collection of ROOT Objects.
type Directory ¶
type Directory interface {
// Get returns the object identified by namecycle
// namecycle has the format name;cycle
// name = * is illegal, cycle = * is illegal
// cycle = "" or cycle = 9999 ==> apply to a memory object
//
// examples:
// foo : get object named foo in memory
// if object is not in memory, try with highest cycle from file
// foo;1 : get cycle 1 of foo on file
Get(namecycle string) (Object, error)
Keys() []Key
}
Directory describes a ROOT directory structure in memory.
type FactoryFct ¶
FactoryFct creates new values of a given type.
type File ¶
type File struct {
// contains filtered or unexported fields
}
A ROOT file is a suite of consecutive data records (TKey's) with the following format (see also the TKey class). If the key is located past the 32 bit file limit (> 2 GB) then some fields will be 8 instead of 4 bytes:
1->4 Nbytes = Length of compressed object (in bytes) 5->6 Version = TKey version identifier 7->10 ObjLen = Length of uncompressed object 11->14 Datime = Date and time when object was written to file 15->16 KeyLen = Length of the key structure (in bytes) 17->18 Cycle = Cycle of key 19->22 [19->26] SeekKey = Pointer to record itself (consistency check) 23->26 [27->34] SeekPdir = Pointer to directory header 27->27 [35->35] lname = Number of bytes in the class name 28->.. [36->..] ClassName = Object Class Name ..->.. lname = Number of bytes in the object name ..->.. Name = lName bytes with the name of the object ..->.. lTitle = Number of bytes in the object title ..->.. Title = Title of the object -----> DATA = Data bytes associated to the object
The first data record starts at byte fBEGIN (currently set to kBEGIN). Bytes 1->kBEGIN contain the file description, when fVersion >= 1000000 it is a large file (> 2 GB) and the offsets will be 8 bytes long and fUnits will be set to 8:
1->4 "root" = Root file identifier 5->8 fVersion = File format version 9->12 fBEGIN = Pointer to first data record 13->16 [13->20] fEND = Pointer to first free word at the EOF 17->20 [21->28] fSeekFree = Pointer to FREE data record 21->24 [29->32] fNbytesFree = Number of bytes in FREE data record 25->28 [33->36] nfree = Number of free data records 29->32 [37->40] fNbytesName = Number of bytes in TNamed at creation time 33->33 [41->41] fUnits = Number of bytes for file pointers 34->37 [42->45] fCompress = Compression level and algorithm 38->41 [46->53] fSeekInfo = Pointer to TStreamerInfo record 42->45 [54->57] fNbytesInfo = Number of bytes in TStreamerInfo record 46->63 [58->75] fUUID = Universal Unique ID
func Open ¶
Open opens the named ROOT file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode os.O_RDONLY.
func (*File) Close ¶
Close closes the File, rendering it unusable for I/O. It returns an error, if any.
func (*File) Get ¶
Get returns the object identified by namecycle
namecycle has the format name;cycle
name = * is illegal, cycle = * is illegal
cycle = "" or cycle = 9999 ==> apply to a memory object
examples:
foo : get object named foo in memory
if object is not in memory, try with highest cycle from file
foo;1 : get cycle 1 of foo on file
func (*File) StreamerInfo ¶
func (f *File) StreamerInfo() []StreamerInfo
StreamerInfo returns the list of StreamerInfos of this file.
type Graph ¶
Graph describes a ROOT TGraph
Example ¶
package main
import (
"fmt"
"log"
"go-hep.org/x/hep/rootio"
)
func main() {
f, err := rootio.Open("testdata/graphs.root")
if err != nil {
log.Fatal(err)
}
defer f.Close()
obj, err := f.Get("tg")
if err != nil {
log.Fatal(err)
}
g := obj.(rootio.Graph)
fmt.Printf("name: %q\n", g.Name())
fmt.Printf("title: %q\n", g.Title())
fmt.Printf("#pts: %d\n", g.Len())
for i := 0; i < g.Len(); i++ {
x, y := g.XY(i)
fmt.Printf("(x,y)[%d] = (%+e, %+e)\n", i, x, y)
}
}
Output: name: "tg" title: "graph without errors" #pts: 4 (x,y)[0] = (+1.000000e+00, +2.000000e+00) (x,y)[1] = (+2.000000e+00, +4.000000e+00) (x,y)[2] = (+3.000000e+00, +6.000000e+00) (x,y)[3] = (+4.000000e+00, +8.000000e+00)
type GraphErrors ¶
type GraphErrors interface {
Graph
// XError returns two error values for X data.
XError(i int) (float64, float64)
// YError returns two error values for Y data.
YError(i int) (float64, float64)
}
GraphErrors describes a ROOT TGraphErrors
Example ¶
package main
import (
"fmt"
"log"
"go-hep.org/x/hep/rootio"
)
func main() {
f, err := rootio.Open("testdata/graphs.root")
if err != nil {
log.Fatal(err)
}
defer f.Close()
obj, err := f.Get("tge")
if err != nil {
log.Fatal(err)
}
g := obj.(rootio.GraphErrors)
fmt.Printf("name: %q\n", g.Name())
fmt.Printf("title: %q\n", g.Title())
fmt.Printf("#pts: %d\n", g.Len())
for i := 0; i < g.Len(); i++ {
x, y := g.XY(i)
xlo, xhi := g.XError(i)
ylo, yhi := g.YError(i)
fmt.Printf("(x,y)[%d] = (%+e +/- [%+e, %+e], %+e +/- [%+e, %+e])\n", i, x, xlo, xhi, y, ylo, yhi)
}
}
Output: name: "tge" title: "graph with errors" #pts: 4 (x,y)[0] = (+1.000000e+00 +/- [+1.000000e-01, +1.000000e-01], +2.000000e+00 +/- [+2.000000e-01, +2.000000e-01]) (x,y)[1] = (+2.000000e+00 +/- [+2.000000e-01, +2.000000e-01], +4.000000e+00 +/- [+4.000000e-01, +4.000000e-01]) (x,y)[2] = (+3.000000e+00 +/- [+3.000000e-01, +3.000000e-01], +6.000000e+00 +/- [+6.000000e-01, +6.000000e-01]) (x,y)[3] = (+4.000000e+00 +/- [+4.000000e-01, +4.000000e-01], +8.000000e+00 +/- [+8.000000e-01, +8.000000e-01])
Example (AsymmErrors) ¶
package main
import (
"fmt"
"log"
"go-hep.org/x/hep/rootio"
)
func main() {
f, err := rootio.Open("testdata/graphs.root")
if err != nil {
log.Fatal(err)
}
defer f.Close()
obj, err := f.Get("tgae")
if err != nil {
log.Fatal(err)
}
g := obj.(rootio.GraphErrors)
fmt.Printf("name: %q\n", g.Name())
fmt.Printf("title: %q\n", g.Title())
fmt.Printf("#pts: %d\n", g.Len())
for i := 0; i < g.Len(); i++ {
x, y := g.XY(i)
xlo, xhi := g.XError(i)
ylo, yhi := g.YError(i)
fmt.Printf("(x,y)[%d] = (%+e +/- [%+e, %+e], %+e +/- [%+e, %+e])\n", i, x, xlo, xhi, y, ylo, yhi)
}
}
Output: name: "tgae" title: "graph with asymmetric errors" #pts: 4 (x,y)[0] = (+1.000000e+00 +/- [+1.000000e-01, +2.000000e-01], +2.000000e+00 +/- [+3.000000e-01, +4.000000e-01]) (x,y)[1] = (+2.000000e+00 +/- [+2.000000e-01, +4.000000e-01], +4.000000e+00 +/- [+6.000000e-01, +8.000000e-01]) (x,y)[2] = (+3.000000e+00 +/- [+3.000000e-01, +6.000000e-01], +6.000000e+00 +/- [+9.000000e-01, +1.200000e+00]) (x,y)[3] = (+4.000000e+00 +/- [+4.000000e-01, +8.000000e-01], +8.000000e+00 +/- [+1.200000e+00, +1.600000e+00])
type H1 ¶
type H1 interface {
Named
// Entries returns the number of entries for this histogram.
Entries() float64
// SumW returns the total sum of weights
SumW() float64
// SumW2 returns the total sum of squares of weights
SumW2() float64
// SumWX returns the total sum of weights*x
SumWX() float64
// SumWX2 returns the total sum of weights*x*x
SumWX2() float64
// SumW2s returns the array of sum of squares of weights
SumW2s() []float64
// contains filtered or unexported methods
}
H1 is a 1-dim ROOT histogram
type H1D ¶
type H1D struct {
// contains filtered or unexported fields
}
H1D implements ROOT TH1D
func (*H1D) Entries ¶
func (h *H1D) Entries() float64
Entries returns the number of entries for this histogram.
func (*H1D) MarshalYODA ¶
MarshalYODA implements the YODAMarshaler interface.
func (*H1D) SumW2s ¶
func (h *H1D) SumW2s() []float64
SumW2s returns the array of sum of squares of weights
func (*H1D) UnmarshalROOT ¶
func (*H1D) XBinCenter ¶
XBinCenter returns the bin center value in X.
func (*H1D) XBinContent ¶
XBinContent returns the bin content value in X.
func (*H1D) XBinLowEdge ¶
XBinLowEdge returns the bin lower edge value in X.
type H1F ¶
type H1F struct {
// contains filtered or unexported fields
}
H1F implements ROOT TH1F
func (*H1F) Entries ¶
func (h *H1F) Entries() float64
Entries returns the number of entries for this histogram.
func (*H1F) MarshalYODA ¶
MarshalYODA implements the YODAMarshaler interface.
func (*H1F) SumW2s ¶
func (h *H1F) SumW2s() []float64
SumW2s returns the array of sum of squares of weights
func (*H1F) UnmarshalROOT ¶
func (*H1F) XBinCenter ¶
XBinCenter returns the bin center value in X.
func (*H1F) XBinContent ¶
XBinContent returns the bin content value in X.
func (*H1F) XBinLowEdge ¶
XBinLowEdge returns the bin lower edge value in X.
type H1I ¶
type H1I struct {
// contains filtered or unexported fields
}
H1I implements ROOT TH1I
func (*H1I) Entries ¶
func (h *H1I) Entries() float64
Entries returns the number of entries for this histogram.
func (*H1I) MarshalYODA ¶
MarshalYODA implements the YODAMarshaler interface.
func (*H1I) SumW2s ¶
func (h *H1I) SumW2s() []float64
SumW2s returns the array of sum of squares of weights
func (*H1I) UnmarshalROOT ¶
func (*H1I) XBinCenter ¶
XBinCenter returns the bin center value in X.
func (*H1I) XBinContent ¶
XBinContent returns the bin content value in X.
func (*H1I) XBinLowEdge ¶
XBinLowEdge returns the bin lower edge value in X.
type H2 ¶
type H2 interface {
Named
// Entries returns the number of entries for this histogram.
Entries() float64
// SumW returns the total sum of weights
SumW() float64
// SumW2 returns the total sum of squares of weights
SumW2() float64
// SumWX returns the total sum of weights*x
SumWX() float64
// SumWX2 returns the total sum of weights*x*x
SumWX2() float64
// SumW2s returns the array of sum of squares of weights
SumW2s() []float64
// SumWY returns the total sum of weights*y
SumWY() float64
// SumWY2 returns the total sum of weights*y*y
SumWY2() float64
// SumWXY returns the total sum of weights*x*y
SumWXY() float64
// contains filtered or unexported methods
}
H2 is a 2-dim ROOT histogram
type H2D ¶
type H2D struct {
// contains filtered or unexported fields
}
H2D implements ROOT TH2D
func (*H2D) MarshalYODA ¶
func (*H2D) UnmarshalROOT ¶
func (*H2D) XBinCenter ¶
XBinCenter returns the bin center value in X.
func (*H2D) XBinContent ¶
XBinContent returns the bin content value in X.
func (*H2D) XBinLowEdge ¶
XBinLowEdge returns the bin lower edge value in X.
func (*H2D) YBinCenter ¶
YBinCenter returns the bin center value in Y.
func (*H2D) YBinContent ¶
YBinContent returns the bin content value in Y.
func (*H2D) YBinLowEdge ¶
YBinLowEdge returns the bin lower edge value in Y.
type H2F ¶
type H2F struct {
// contains filtered or unexported fields
}
H2F implements ROOT TH2F
func (*H2F) MarshalYODA ¶
func (*H2F) UnmarshalROOT ¶
func (*H2F) XBinCenter ¶
XBinCenter returns the bin center value in X.
func (*H2F) XBinContent ¶
XBinContent returns the bin content value in X.
func (*H2F) XBinLowEdge ¶
XBinLowEdge returns the bin lower edge value in X.
func (*H2F) YBinCenter ¶
YBinCenter returns the bin center value in Y.
func (*H2F) YBinContent ¶
YBinContent returns the bin content value in Y.
func (*H2F) YBinLowEdge ¶
YBinLowEdge returns the bin lower edge value in Y.
type H2I ¶
type H2I struct {
// contains filtered or unexported fields
}
H2I implements ROOT TH2I
func (*H2I) MarshalYODA ¶
func (*H2I) UnmarshalROOT ¶
func (*H2I) XBinCenter ¶
XBinCenter returns the bin center value in X.
func (*H2I) XBinContent ¶
XBinContent returns the bin content value in X.
func (*H2I) XBinLowEdge ¶
XBinLowEdge returns the bin lower edge value in X.
func (*H2I) YBinCenter ¶
YBinCenter returns the bin center value in Y.
func (*H2I) YBinContent ¶
YBinContent returns the bin content value in Y.
func (*H2I) YBinLowEdge ¶
YBinLowEdge returns the bin lower edge value in Y.
type Key ¶
type Key struct {
// contains filtered or unexported fields
}
Key is a key (a label) in a ROOT file
The Key class includes functions to book space on a file, to create I/O buffers, to fill these buffers to compress/uncompress data buffers. Before saving (making persistent) an object on a file, a key must be created. The key structure contains all the information to uniquely identify a persistent object on a file. The Key class is used by ROOT: - to write an object in the Current Directory - to write a new ntuple buffer
func (*Key) UnmarshalROOT ¶
UnmarshalROOT decodes the content of data into the Key
type Leaf ¶
type Leaf interface {
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 ¶
type LeafB struct {
// contains filtered or unexported fields
}
LeafB implements ROOT TLeafB
func (*LeafB) IsUnsigned ¶
func (leaf *LeafB) IsUnsigned() bool
func (*LeafB) UnmarshalROOT ¶
type LeafC ¶
type LeafC struct {
// contains filtered or unexported fields
}
LeafC implements ROOT TLeafC
func (*LeafC) IsUnsigned ¶
func (leaf *LeafC) IsUnsigned() bool
func (*LeafC) UnmarshalROOT ¶
type LeafD ¶
type LeafD struct {
// contains filtered or unexported fields
}
LeafD implements ROOT TLeafD
func (*LeafD) IsUnsigned ¶
func (leaf *LeafD) IsUnsigned() bool
func (*LeafD) UnmarshalROOT ¶
type LeafF ¶
type LeafF struct {
// contains filtered or unexported fields
}
LeafF implements ROOT TLeafF
func (*LeafF) IsUnsigned ¶
func (leaf *LeafF) IsUnsigned() bool
func (*LeafF) UnmarshalROOT ¶
type LeafI ¶
type LeafI struct {
// contains filtered or unexported fields
}
LeafI implements ROOT TLeafI
func (*LeafI) IsUnsigned ¶
func (leaf *LeafI) IsUnsigned() bool
func (*LeafI) UnmarshalROOT ¶
type LeafL ¶
type LeafL struct {
// contains filtered or unexported fields
}
LeafL implements ROOT TLeafL
func (*LeafL) IsUnsigned ¶
func (leaf *LeafL) IsUnsigned() bool
func (*LeafL) UnmarshalROOT ¶
type LeafO ¶
type LeafO struct {
// contains filtered or unexported fields
}
LeafO implements ROOT TLeafO
func (*LeafO) IsUnsigned ¶
func (leaf *LeafO) IsUnsigned() bool
func (*LeafO) UnmarshalROOT ¶
type LeafS ¶
type LeafS struct {
// contains filtered or unexported fields
}
LeafS implements ROOT TLeafS
func (*LeafS) IsUnsigned ¶
func (leaf *LeafS) IsUnsigned() bool
func (*LeafS) UnmarshalROOT ¶
type Member ¶
type Member interface {
// GetArrayDim returns the dimension of the array (if any)
ArrayDim() int
// GetComment returns the comment associated with this member
Comment() string
// Name returns the name of this member
Name() string
// Type returns the class of this member
Type() Class
// GetValue returns the value of this member
Value(o Object) reflect.Value
}
Member represents a single member of a ROOT class
type Named ¶
type Named interface {
Object
// Name returns the name of this ROOT object
Name() string
// Title returns the title of this ROOT object
Title() string
}
Named represents a ROOT TNamed object
type ObjArray ¶
type ObjArray interface {
SeqCollection
LowerBound() int
}
ObjArray is an array of ROOT Objects.
type Object ¶
type Object interface {
// Class returns the ROOT class of this object
Class() string
}
Object represents a ROOT object
type RBuffer ¶
type RBuffer struct {
// contains filtered or unexported fields
}
RBuffer is a read-only ROOT buffer for streaming.
func (*RBuffer) CheckByteCount ¶
func (*RBuffer) ReadCString ¶
func (*RBuffer) ReadFastArrayBool ¶
func (*RBuffer) ReadFastArrayF32 ¶
func (*RBuffer) ReadFastArrayF64 ¶
func (*RBuffer) ReadFastArrayI8 ¶
func (*RBuffer) ReadFastArrayI16 ¶
func (*RBuffer) ReadFastArrayI32 ¶
func (*RBuffer) ReadFastArrayI64 ¶
func (*RBuffer) ReadFastArrayString ¶
func (*RBuffer) ReadFastArrayU8 ¶
func (*RBuffer) ReadFastArrayU16 ¶
func (*RBuffer) ReadFastArrayU32 ¶
func (*RBuffer) ReadFastArrayU64 ¶
func (*RBuffer) ReadObject ¶
func (*RBuffer) ReadObjectAny ¶
func (*RBuffer) ReadStaticArrayI32 ¶
func (*RBuffer) ReadString ¶
func (*RBuffer) ReadVersion ¶
func (*RBuffer) SkipObject ¶
func (r *RBuffer) SkipObject()
func (*RBuffer) SkipVersion ¶
type ROOTMarshaler ¶
ROOTMarshaler is the interface implemented by an object that can marshal itself into a ROOT buffer
type ROOTUnmarshaler ¶
ROOTUnmarshaler is the interface implemented by an object that can unmarshal itself from a ROOT buffer
type ScanVar ¶
type ScanVar struct {
Name string // name of the branch 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 ¶
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.
Example (WithStruct) ¶
package main
import (
"fmt"
"io"
"log"
"go-hep.org/x/hep/rootio"
)
func main() {
log.SetPrefix("rootio: ")
log.SetFlags(0)
f, err := rootio.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.(rootio.Tree)
type Data struct {
I64 int64 `rootio:"Int64"`
F64 float64 `rootio:"Float64"`
Str string `rootio:"Str"`
ArrF64 [10]float64 `rootio:"ArrayFloat64"`
N int32 `rootio:"N"`
SliF64 []float64 `rootio:"SliceFloat64"`
}
var data Data
sc, err := rootio.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]}
Example (WithVars) ¶
package main
import (
"fmt"
"io"
"log"
"go-hep.org/x/hep/rootio"
)
func main() {
log.SetPrefix("rootio: ")
log.SetFlags(0)
f, err := rootio.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.(rootio.Tree)
var (
i64 int64
f64 float64
str string
arr [10]float64
n int32
sli []float64
)
scanVars := []rootio.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 := rootio.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 ¶
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 ¶
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 ¶
Close closes the Scanner, preventing further iteration. Close is idempotent and does not affect the result of Err.
func (*Scanner) Next ¶
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.
type SeqCollection ¶
type SeqCollection interface {
Collection
}
SeqCollection is a sequential collection of ROOT Objects.
type SetFiler ¶
type SetFiler interface {
SetFile(f *File)
}
SetFiler is a simple interface to establish File ownership.
type StreamerElement ¶
type StreamerElement interface {
Named
ArrayDim() int
ArrayLen() int
Type() int
Offset() uintptr
Size() uintptr
TypeName() string
}
StreamerElement describes a ROOT StreamerElement
type StreamerInfo ¶
type StreamerInfo interface {
Named
CheckSum() int
ClassVersion() int
Elements() []StreamerElement
}
StreamerInfo describes a ROOT Streamer.
type Tree ¶
type Tree interface {
Named
Entries() int64
TotBytes() int64
ZipBytes() int64
Branch(name string) Branch
Branches() []Branch
Leaves() []Leaf
// contains filtered or unexported methods
}
Tree is a collection of branches of data.
type TreeScanner ¶
type TreeScanner struct {
// contains filtered or unexported fields
}
TreeScanner scans, selects and iterates over Tree entries.
Example ¶
package main
import (
"fmt"
"io"
"log"
"go-hep.org/x/hep/rootio"
)
func main() {
log.SetPrefix("rootio: ")
log.SetFlags(0)
f, err := rootio.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.(rootio.Tree)
type Data struct {
I64 int64 `rootio:"Int64"`
F64 float64 `rootio:"Float64"`
Str string `rootio:"Str"`
ArrF64 [10]float64 `rootio:"ArrayFloat64"`
N int32 `rootio:"N"`
SliF64 []float64 `rootio:"SliceFloat64"`
}
sc, err := rootio.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]}
Example (WithVars) ¶
package main
import (
"fmt"
"io"
"log"
"go-hep.org/x/hep/rootio"
)
func main() {
log.SetPrefix("rootio: ")
log.SetFlags(0)
f, err := rootio.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.(rootio.Tree)
scanVars := []rootio.ScanVar{
{Name: "Int64"},
{Name: "Float64"},
{Name: "Str"},
{Name: "ArrayFloat64"},
{Name: "N"},
{Name: "SliceFloat64"},
}
sc, err := rootio.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 ¶
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 ¶
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 ¶
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 ¶
func (s *TreeScanner) Entry() int64
Entry returns the entry number of the last read row.
func (*TreeScanner) Err ¶
func (s *TreeScanner) Err() error
Err returns the error, if any, that was encountered during iteration.
func (*TreeScanner) Next ¶
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 ¶
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 ¶
func (s *TreeScanner) SeekEntry(i int64) error
SeekEntry points the scanner to the i-th entry, ready to call Next.
Source Files
¶
- array_gen.go
- attaxis.go
- attfill.go
- attline.go
- attmarker.go
- axis.go
- basket.go
- branch.go
- consts.go
- dir.go
- dobj.go
- doc.go
- factory.go
- file.go
- graph.go
- h1_gen.go
- h2_gen.go
- hist.go
- ioseek.go
- key.go
- leaf.go
- leaf_gen.go
- list.go
- named.go
- objarray.go
- object.go
- objstring.go
- rbuffer.go
- read_streamers.go
- rootio.go
- scanner.go
- streamers.go
- tree.go
- utils.go
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
root-diff
command
root-diff compares the content of 2 ROOT files, including the content of their Trees (for all entries), if any.
|
root-diff compares the content of 2 ROOT files, including the content of their Trees (for all entries), if any. |
|
root-dump
command
root-dump dumps the content of a ROOT file, including the content of the Trees (for all entries), if any.
|
root-dump dumps the content of a ROOT file, including the content of the Trees (for all entries), if any. |
|
root-gen-datareader
command
Command root-gen-datareader generates a Go struct to easily read the event data type stored inside a Tree.
|
Command root-gen-datareader generates a Go struct to easily read the event data type stored inside a Tree. |
|
root-ls
command
root-ls lists the content of a ROOT file.
|
root-ls lists the content of a ROOT file. |
|
root-print
command
root-print prints ROOT files contents to PDF, PNG, ...
|
root-print prints ROOT files contents to PDF, PNG, ... |
|
root-srv
command
|
|
|
root-srv/server
Package server encapsulates the creation of the web server for root-srv.
|
Package server encapsulates the creation of the web server for root-srv. |