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.
File layout ¶
ROOT files are a suite of consecutive data records. Each data record consists of a header part, called a TKey, and a payload whose content, length and meaning are described by the header. The current ROOT file format encodes all data in big endian.
ROOT files initially only supported 32b addressing. Large files support (>4Gb) was added later on by migrating to a 64b addressing.
The on-disk binary layout of a ROOT file header looks like this:
Type | Record Name | Description =================+=============+=========================================== [4]byte | "root" | Root file identifier int32 | fVersion | File format version int32 | fBEGIN | Pointer to first data record int32 [int64] | fEND | Pointer to first free word at the EOF int32 [int64] | fSeekFree | Pointer to FREE data record int32 | fNbytesFree | Number of bytes in FREE data record int32 | nfree | Number of free data records int32 | fNbytesName | Number of bytes in TNamed at creation time byte | fUnits | Number of bytes for file pointers int32 | fCompress | Compression level and algorithm int32 [int64] | fSeekInfo | Pointer to TStreamerInfo record int32 | fNbytesInfo | Number of bytes in TStreamerInfo record [18]byte | fUUID | Universal Unique ID =================+=============+===========================================
This is followed by a sequence of data records, starting at the fBEGIN offset from the beginning of the file.
The on-disk binary layout of a data record is:
Type | Member Name | Description ===============+=============+=========================================== int32 | Nbytes | Length of compressed object (in bytes) int16 | Version | TKey version identifier int32 | ObjLen | Length of uncompressed object int32 | Datime | Date and time when object was written to file int16 | KeyLen | Length of the key structure (in bytes) int16 | Cycle | Cycle of key int32 [int64] | SeekKey | Pointer to record itself (consistency check) int32 [int64] | SeekPdir | Pointer to directory header byte | lname | Number of bytes in the class name []byte | ClassName | Object Class Name byte | lname | Number of bytes in the object name []byte | Name | Name of the object byte | lTitle | Number of bytes in the object title []byte | Title | Title of the object []byte | DATA | Data bytes associated to the object ===============+=============+===========================================
The high-level on-disk representation of a ROOT file is thus:
+===============+ -- 0 | | | File Header | | | +===============+ -- fBEGIN offset | | | Record Header | -->-+ | | | +---------------+ | | | | | Record Data | | Reference to next Record | Payload | | | | | +===============+ <---+ | | | Record Header | -->-+ | | | +---------------+ | | | | | Record Data | | Reference to next Record | Payload | | | | | +===============+ <---+ | | ... | | +===============+ -- fSeekInfo | | | Record Header | -->-+ | | | +---------------+ | | | | | Record Data | | Reference to next Record | Payload | | | | | +===============+ <---+ -- fEND offset
Data records payloads and how to deserialize them are described by a TStreamerInfo. The list of all TStreamerInfos that are used to interpret the content of a ROOT file is stored at the end of that ROOT file, at offset fSeekInfo.
Data records ¶
Data records' payloads may be compressed. Detecting whether a payload is compressed is usually done by comparing the object length (ObjLen) field of the record header with the length of the compressed object (Nbytes) field. If they differ after having subtracted the record header length, then the payload has been compressed.
A record data payload is itself split into multiple chunks of maximum size 16*1024*1024 bytes. Each chunk consists of:
- the chunk header,
- the chunk compressed payload.
The chunk header:
- 3 bytes to identify the compression algorithm and version,
- 3 bytes to identify the deflated buffer size,
- 3 bytes to identify the inflated buffer size.
Streamer informations ¶
Streamers describe how a given type, for a given version of that type, is written on disk. In C++/ROOT, a streamer is represented as a TStreamerInfo class that can give metadata about the type it's describing (version, name). When reading a file, all the streamer infos are read back in memory, from disk, by reading the data record at offset fSeekInfo. A streamer info is actually a list of streamer elements, one for each field and, in C++, base class (in Go, this is emulated as an embedded field.)
Index ¶
- Variables
- func NewObjString(s string) *tobjstring
- type Array
- type ArrayD
- type ArrayF
- type ArrayI
- type ArrayL64
- func (arr *ArrayL64) At(i int) int64
- func (*ArrayL64) Class() string
- func (arr *ArrayL64) Get(i int) interface{}
- func (arr *ArrayL64) Len() int
- func (arr *ArrayL64) MarshalROOT(w *WBuffer) (int, error)
- func (arr *ArrayL64) Set(i int, v interface{})
- func (arr *ArrayL64) UnmarshalROOT(r *RBuffer) error
- type Axis
- type Basket
- type Branch
- type Class
- type ClassFactory
- type Collection
- type Directory
- type Double32
- 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) Name() string
- func (f *File) Put(name string, v Object) error
- 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) Stat() (os.FileInfo, error)
- func (f *File) StreamerInfo(name string) (StreamerInfo, error)
- func (f *File) StreamerInfos() []StreamerInfo
- func (f *File) Tell() int64
- func (f *File) Title() string
- func (f *File) Version() int
- type FileOption
- type Float16
- 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) MarshalROOT(w *WBuffer) (int, error)
- 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) UnmarshalYODA(raw []byte) 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) MarshalROOT(w *WBuffer) (int, error)
- 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) UnmarshalYODA(raw []byte) 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) MarshalROOT(w *WBuffer) (int, error)
- 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) UnmarshalYODA(raw []byte) 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) MarshalROOT(w *WBuffer) (int, error)
- 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) UnmarshalYODA(raw []byte) 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) MarshalROOT(w *WBuffer) (int, error)
- 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) UnmarshalYODA(raw []byte) 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) MarshalROOT(w *WBuffer) (int, error)
- 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) UnmarshalYODA(raw []byte) 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
- func (k *Key) Bytes() ([]byte, error)
- func (*Key) Class() string
- func (k *Key) ClassName() string
- func (k *Key) Cycle() int
- func (k *Key) MarshalROOT(w *WBuffer) (int, error)
- func (k *Key) Name() string
- func (k *Key) Object() (Object, error)
- func (k *Key) Title() string
- func (k *Key) UnmarshalROOT(r *RBuffer) error
- func (k *Key) Value() interface{}
- 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) MarshalROOT(w *WBuffer) (int, error)
- 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) MarshalROOT(w *WBuffer) (int, error)
- 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) MarshalROOT(w *WBuffer) (int, error)
- 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) MarshalROOT(w *WBuffer) (int, error)
- 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) MarshalROOT(w *WBuffer) (int, error)
- 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) MarshalROOT(w *WBuffer) (int, error)
- 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) MarshalROOT(w *WBuffer) (int, error)
- 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) MarshalROOT(w *WBuffer) (int, error)
- 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 ObjString
- 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) ReadFastArrayI16(n int) []int16
- func (r *RBuffer) ReadFastArrayI32(n int) []int32
- func (r *RBuffer) ReadFastArrayI64(n int) []int64
- func (r *RBuffer) ReadFastArrayI8(n int) []int8
- func (r *RBuffer) ReadFastArrayString(n int) []string
- func (r *RBuffer) ReadFastArrayU16(n int) []uint16
- func (r *RBuffer) ReadFastArrayU32(n int) []uint32
- func (r *RBuffer) ReadFastArrayU64(n int) []uint64
- func (r *RBuffer) ReadFastArrayU8(n int) []uint8
- func (r *RBuffer) ReadI16() int16
- func (r *RBuffer) ReadI32() int32
- func (r *RBuffer) ReadI64() int64
- func (r *RBuffer) ReadI8() int8
- 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) ReadU16() uint16
- func (r *RBuffer) ReadU32() uint32
- func (r *RBuffer) ReadU64() uint64
- func (r *RBuffer) ReadU8() uint8
- func (r *RBuffer) ReadVersion() (vers int16, pos, n int32)
- func (r *RBuffer) SkipObject()
- func (r *RBuffer) SkipVersion(class string)
- func (r *RBuffer) StreamerInfo(name string) (StreamerInfo, error)
- type ROOTMarshaler
- type ROOTUnmarshaler
- type RStreamer
- type Reader
- type ScanVar
- type Scanner
- type SeqCollection
- type SetFiler
- type StreamerElement
- type StreamerInfo
- type StreamerInfoContext
- type Tree
- type TreeScanner
- type WBuffer
- func (w *WBuffer) Pos() int64
- func (w *WBuffer) SetByteCount(beg int64, class string) (int, error)
- func (w *WBuffer) WriteBool(v bool)
- func (w *WBuffer) WriteCString(v string)
- func (w *WBuffer) WriteClass(beg int64, obj Object) (uint32, error)
- func (w *WBuffer) WriteF32(v float32)
- func (w *WBuffer) WriteF64(v float64)
- func (w *WBuffer) WriteFastArrayBool(v []bool)
- func (w *WBuffer) WriteFastArrayF32(v []float32)
- func (w *WBuffer) WriteFastArrayF64(v []float64)
- func (w *WBuffer) WriteFastArrayI16(v []int16)
- func (w *WBuffer) WriteFastArrayI32(v []int32)
- func (w *WBuffer) WriteFastArrayI64(v []int64)
- func (w *WBuffer) WriteFastArrayI8(v []int8)
- func (w *WBuffer) WriteFastArrayU16(v []uint16)
- func (w *WBuffer) WriteFastArrayU32(v []uint32)
- func (w *WBuffer) WriteFastArrayU64(v []uint64)
- func (w *WBuffer) WriteFastArrayU8(v []uint8)
- func (w *WBuffer) WriteI16(v int16)
- func (w *WBuffer) WriteI32(v int32)
- func (w *WBuffer) WriteI64(v int64)
- func (w *WBuffer) WriteI8(v int8)
- func (w *WBuffer) WriteObjectAny(obj Object) error
- func (w *WBuffer) WriteStaticArrayI32(v []int32)
- func (w *WBuffer) WriteString(v string)
- func (w *WBuffer) WriteU16(v uint16)
- func (w *WBuffer) WriteU32(v uint32)
- func (w *WBuffer) WriteU64(v uint64)
- func (w *WBuffer) WriteU8(v uint8)
- func (w *WBuffer) WriteVersion(vers int16)
- type Writer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Factory = factory{ // contains filtered or unexported fields }
Functions ¶
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 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
}
type Branch ¶
type Branch interface { 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 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) // Put puts the object v under the key with the given name. Put(name string, v Object) error // Keys returns the list of keys being held by this directory. Keys() []Key }
Directory describes a ROOT directory structure in memory.
type Double32 ¶
type Double32 float64
Double32 is a float64 in memory, written as a float32 to disk.
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 Create ¶
func Create(name string, opts ...FileOption) (*File, error)
Create creates the named ROOT file for writing.
Example ¶
package main import ( "fmt" "log" "os" "go-hep.org/x/hep/rootio" ) func main() { const fname = "objstring.root" defer os.Remove(fname) w, err := rootio.Create(fname) if err != nil { log.Fatal(err) } defer w.Close() var ( k = "my-objstring" v = rootio.NewObjString("Hello World from Go-HEP!") ) err = w.Put(k, v) if err != nil { log.Fatal(err) } fmt.Printf("wkeys: %d\n", len(w.Keys())) err = w.Close() if err != nil { log.Fatalf("could not close file: %v", err) } r, err := rootio.Open(fname) if err != nil { log.Fatalf("could not open file: %v", err) } defer r.Close() fmt.Printf("rkeys: %d\n", len(r.Keys())) for _, k := range r.Keys() { fmt.Printf("key: name=%q, type=%q\n", k.Name(), k.ClassName()) } obj, err := r.Get(k) if err != nil { log.Fatal(err) } rv := obj.(rootio.ObjString) fmt.Printf("objstring=%q\n", rv) }
Output: wkeys: 1 rkeys: 1 key: name="my-objstring", type="TObjString" objstring="Hello World from Go-HEP!"
Example (Empty) ¶
package main import ( "fmt" "log" "os" "go-hep.org/x/hep/rootio" ) func main() { const fname = "empty.root" defer os.Remove(fname) w, err := rootio.Create(fname) if err != nil { log.Fatal(err) } defer w.Close() // empty file. close it. err = w.Close() if err != nil { log.Fatalf("could not close empty file: %v", err) } // read back. r, err := rootio.Open(fname) if err != nil { log.Fatalf("could not open empty file: %v", err) } defer r.Close() fmt.Printf("file: %q\n", r.Name()) sinfos := r.StreamerInfos() fmt.Printf("streamer infos: %d\n", len(sinfos)) }
Output: file: "empty.root" streamer infos: 0
Example (Graph) ¶
package main import ( "fmt" "log" "os" "go-hep.org/x/hep/hbook" "go-hep.org/x/hep/hbook/rootcnv" "go-hep.org/x/hep/rootio" ) func main() { const fname = "graph_example.root" defer os.Remove(fname) f, err := rootio.Create(fname) if err != nil { log.Fatal(err) } defer f.Close() hg := hbook.NewS2D(hbook.Point2D{X: 1, Y: 1}, hbook.Point2D{X: 2, Y: 1.5}, hbook.Point2D{X: -1, Y: +2}) fmt.Printf("original graph:\n") for i, pt := range hg.Points() { fmt.Printf("pt[%d]=%+v\n", i, pt) } rg := rootio.NewGraphFrom(hg) err = f.Put("gr", rg) if err != nil { log.Fatal(err) } err = f.Close() if err != nil { log.Fatalf("error closing ROOT file: %v", err) } r, err := rootio.Open(fname) if err != nil { log.Fatal(err) } defer r.Close() robj, err := r.Get("gr") if err != nil { log.Fatal(err) } hr, err := rootcnv.S2D(robj.(rootio.Graph)) if err != nil { log.Fatal(err) } fmt.Printf("\ngraph read back:\n") for i, pt := range hr.Points() { fmt.Printf("pt[%d]=%+v\n", i, pt) } }
Output: original graph: pt[0]={X:1 Y:1 ErrX:{Min:0 Max:0} ErrY:{Min:0 Max:0}} pt[1]={X:2 Y:1.5 ErrX:{Min:0 Max:0} ErrY:{Min:0 Max:0}} pt[2]={X:-1 Y:2 ErrX:{Min:0 Max:0} ErrY:{Min:0 Max:0}} graph read back: pt[0]={X:1 Y:1 ErrX:{Min:0 Max:0} ErrY:{Min:0 Max:0}} pt[1]={X:2 Y:1.5 ErrX:{Min:0 Max:0} ErrY:{Min:0 Max:0}} pt[2]={X:-1 Y:2 ErrX:{Min:0 Max:0} ErrY:{Min:0 Max:0}}
Example (GraphAsymmErrors) ¶
package main import ( "fmt" "log" "os" "go-hep.org/x/hep/hbook" "go-hep.org/x/hep/hbook/rootcnv" "go-hep.org/x/hep/rootio" ) func main() { const fname = "graphasymmerr_example.root" defer os.Remove(fname) f, err := rootio.Create(fname) if err != nil { log.Fatal(err) } defer f.Close() hg := hbook.NewS2D( hbook.Point2D{X: 1, Y: 1, ErrX: hbook.Range{Min: 1, Max: 2}, ErrY: hbook.Range{Min: 3, Max: 4}}, hbook.Point2D{X: 2, Y: 1.5, ErrX: hbook.Range{Min: 1, Max: 2}, ErrY: hbook.Range{Min: 3, Max: 4}}, hbook.Point2D{X: -1, Y: +2, ErrX: hbook.Range{Min: 1, Max: 2}, ErrY: hbook.Range{Min: 3, Max: 4}}, ) fmt.Printf("original graph:\n") for i, pt := range hg.Points() { fmt.Printf("pt[%d]=%+v\n", i, pt) } rg := rootio.NewGraphAsymmErrorsFrom(hg) err = f.Put("gr", rg) if err != nil { log.Fatal(err) } err = f.Close() if err != nil { log.Fatalf("error closing ROOT file: %v", err) } r, err := rootio.Open(fname) if err != nil { log.Fatal(err) } defer r.Close() robj, err := r.Get("gr") if err != nil { log.Fatal(err) } hr, err := rootcnv.S2D(robj.(rootio.GraphErrors)) if err != nil { log.Fatal(err) } fmt.Printf("\ngraph read back:\n") for i, pt := range hr.Points() { fmt.Printf("pt[%d]=%+v\n", i, pt) } }
Output: original graph: pt[0]={X:1 Y:1 ErrX:{Min:1 Max:2} ErrY:{Min:3 Max:4}} pt[1]={X:2 Y:1.5 ErrX:{Min:1 Max:2} ErrY:{Min:3 Max:4}} pt[2]={X:-1 Y:2 ErrX:{Min:1 Max:2} ErrY:{Min:3 Max:4}} graph read back: pt[0]={X:1 Y:1 ErrX:{Min:1 Max:2} ErrY:{Min:3 Max:4}} pt[1]={X:2 Y:1.5 ErrX:{Min:1 Max:2} ErrY:{Min:3 Max:4}} pt[2]={X:-1 Y:2 ErrX:{Min:1 Max:2} ErrY:{Min:3 Max:4}}
Example (GraphErrors) ¶
package main import ( "fmt" "log" "os" "go-hep.org/x/hep/hbook" "go-hep.org/x/hep/hbook/rootcnv" "go-hep.org/x/hep/rootio" ) func main() { const fname = "grapherr_example.root" defer os.Remove(fname) f, err := rootio.Create(fname) if err != nil { log.Fatal(err) } defer f.Close() hg := hbook.NewS2D( hbook.Point2D{X: 1, Y: 1, ErrX: hbook.Range{Min: 2, Max: 2}, ErrY: hbook.Range{Min: 3, Max: 3}}, hbook.Point2D{X: 2, Y: 1.5, ErrX: hbook.Range{Min: 2, Max: 2}, ErrY: hbook.Range{Min: 3, Max: 3}}, hbook.Point2D{X: -1, Y: +2, ErrX: hbook.Range{Min: 2, Max: 2}, ErrY: hbook.Range{Min: 3, Max: 3}}, ) fmt.Printf("original graph:\n") for i, pt := range hg.Points() { fmt.Printf("pt[%d]=%+v\n", i, pt) } rg := rootio.NewGraphErrorsFrom(hg) err = f.Put("gr", rg) if err != nil { log.Fatal(err) } err = f.Close() if err != nil { log.Fatalf("error closing ROOT file: %v", err) } r, err := rootio.Open(fname) if err != nil { log.Fatal(err) } defer r.Close() robj, err := r.Get("gr") if err != nil { log.Fatal(err) } hr, err := rootcnv.S2D(robj.(rootio.GraphErrors)) if err != nil { log.Fatal(err) } fmt.Printf("\ngraph read back:\n") for i, pt := range hr.Points() { fmt.Printf("pt[%d]=%+v\n", i, pt) } }
Output: original graph: pt[0]={X:1 Y:1 ErrX:{Min:2 Max:2} ErrY:{Min:3 Max:3}} pt[1]={X:2 Y:1.5 ErrX:{Min:2 Max:2} ErrY:{Min:3 Max:3}} pt[2]={X:-1 Y:2 ErrX:{Min:2 Max:2} ErrY:{Min:3 Max:3}} graph read back: pt[0]={X:1 Y:1 ErrX:{Min:2 Max:2} ErrY:{Min:3 Max:3}} pt[1]={X:2 Y:1.5 ErrX:{Min:2 Max:2} ErrY:{Min:3 Max:3}} pt[2]={X:-1 Y:2 ErrX:{Min:2 Max:2} ErrY:{Min:3 Max:3}}
Example (Histo1D) ¶
package main import ( "fmt" "log" "os" "go-hep.org/x/hep/hbook" "go-hep.org/x/hep/hbook/rootcnv" "go-hep.org/x/hep/rootio" "golang.org/x/exp/rand" "gonum.org/v1/gonum/stat/distuv" ) func main() { const fname = "h1d_example.root" defer os.Remove(fname) f, err := rootio.Create(fname) if err != nil { log.Fatal(err) } defer f.Close() const npoints = 10000 // Create a normal distribution. dist := distuv.Normal{ Mu: 0, Sigma: 1, Src: rand.New(rand.NewSource(0)), } // Draw some random values from the standard // normal distribution. h := hbook.NewH1D(20, -4, +4) for i := 0; i < npoints; i++ { v := dist.Rand() h.Fill(v, 1) } h.Fill(-10, 1) // fill underflow h.Fill(-20, 2) h.Fill(+10, 3) // fill overflow fmt.Printf("original histo:\n") fmt.Printf("w-mean: %.7f\n", h.XMean()) fmt.Printf("w-rms: %.7f\n", h.XRMS()) hroot := rootio.NewH1DFrom(h) err = f.Put("h1", hroot) if err != nil { log.Fatal(err) } err = f.Close() if err != nil { log.Fatalf("error closing ROOT file: %v", err) } r, err := rootio.Open(fname) if err != nil { log.Fatal(err) } defer r.Close() robj, err := r.Get("h1") if err != nil { log.Fatal(err) } hr, err := rootcnv.H1D(robj.(rootio.H1)) if err != nil { log.Fatal(err) } fmt.Printf("\nhisto read back:\n") fmt.Printf("r-mean: %.7f\n", hr.XMean()) fmt.Printf("r-rms: %.7f\n", hr.XRMS()) }
Output: original histo: w-mean: 0.0023919 w-rms: 1.0628679 histo read back: r-mean: 0.0023919 r-rms: 1.0628679
Example (Histo2D) ¶
package main import ( "fmt" "log" "os" "go-hep.org/x/hep/hbook" "go-hep.org/x/hep/hbook/rootcnv" "go-hep.org/x/hep/rootio" "golang.org/x/exp/rand" "gonum.org/v1/gonum/stat/distuv" ) func main() { const fname = "h2d_example.root" defer os.Remove(fname) f, err := rootio.Create(fname) if err != nil { log.Fatal(err) } defer f.Close() const npoints = 1000 // Create a normal distribution. dist := distuv.Normal{ Mu: 0, Sigma: 1, Src: rand.New(rand.NewSource(0)), } // Draw some random values from the standard // normal distribution. h := hbook.NewH2D(5, -4, +4, 6, -4, +4) for i := 0; i < npoints; i++ { x := dist.Rand() y := dist.Rand() h.Fill(x, y, 1) } h.Fill(-10, -10, 1) // fill underflow h.Fill(-10, +10, 1) h.Fill(+10, -10, 1) h.Fill(+10, +10, 3) // fill overflow fmt.Printf("original histo:\n") fmt.Printf("w-mean-x: %+.6f\n", h.XMean()) fmt.Printf("w-rms-x: %+.6f\n", h.XRMS()) fmt.Printf("w-mean-y: %+.6f\n", h.YMean()) fmt.Printf("w-rms-y: %+.6f\n", h.YRMS()) hroot := rootio.NewH2DFrom(h) err = f.Put("h2", hroot) if err != nil { log.Fatal(err) } err = f.Close() if err != nil { log.Fatalf("error closing ROOT file: %v", err) } r, err := rootio.Open(fname) if err != nil { log.Fatal(err) } defer r.Close() robj, err := r.Get("h2") if err != nil { log.Fatal(err) } hr, err := rootcnv.H2D(robj.(rootio.H2)) if err != nil { log.Fatal(err) } fmt.Printf("\nhisto read back:\n") fmt.Printf("w-mean-x: %+.6f\n", hr.XMean()) fmt.Printf("w-rms-x: %+.6f\n", hr.XRMS()) fmt.Printf("w-mean-y: %+.6f\n", hr.YMean()) fmt.Printf("w-rms-y: %+.6f\n", hr.YRMS()) }
Output: original histo: w-mean-x: +0.046442 w-rms-x: +1.231044 w-mean-y: -0.018977 w-rms-y: +1.253143 histo read back: w-mean-x: +0.046442 w-rms-x: +1.231044 w-mean-y: -0.018977 w-rms-y: +1.253143
Example (WithZlib) ¶
package main import ( "compress/flate" "fmt" "log" "os" "go-hep.org/x/hep/rootio" ) func main() { const fname = "objstring-zlib.root" defer os.Remove(fname) w, err := rootio.Create(fname, rootio.WithZlib(flate.BestCompression)) if err != nil { log.Fatal(err) } defer w.Close() var ( k = "my-objstring" v = rootio.NewObjString("Hello World from Go-HEP!") ) err = w.Put(k, v) if err != nil { log.Fatal(err) } err = w.Close() if err != nil { log.Fatalf("could not close writable file: %v", err) } r, err := rootio.Open(fname) if err != nil { log.Fatalf("could not open file: %v", err) } defer r.Close() for _, k := range r.Keys() { fmt.Printf("key: name=%q, type=%q\n", k.Name(), k.ClassName()) } obj, err := r.Get(k) if err != nil { log.Fatalf("could not get key %q: %v", k, err) } rv := obj.(rootio.ObjString) fmt.Printf("objstring=%q\n", rv) }
Output: key: name="my-objstring", type="TObjString" objstring="Hello World from Go-HEP!"
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) Put ¶
Put puts the object v under the key with the given name.
func (*File) ReadAt ¶
ReadAt implements io.ReaderAt
func (*File) Seek ¶
Seek implements io.Seeker
func (*File) Stat ¶
Stat returns the os.FileInfo structure describing this file.
func (*File) StreamerInfo ¶
func (f *File) StreamerInfo(name string) (StreamerInfo, error)
StreamerInfo returns the StreamerInfo with name of this file and an error if any.
func (*File) StreamerInfos ¶
func (f *File) StreamerInfos() []StreamerInfo
StreamerInfos returns the list of StreamerInfos of this file.
type FileOption ¶ added in v0.15.0
FileOption configures internal states of a ROOT file.
func WithLZ4 ¶ added in v0.15.0
func WithLZ4(level int) FileOption
WithLZ4 configures a ROOT file to use LZ4 as a compression mechanism.
func WithLZMA ¶ added in v0.15.0
func WithLZMA(level int) FileOption
WithLZMA configures a ROOT file to use LZMA as a compression mechanism.
func WithZlib ¶ added in v0.15.0
func WithZlib(level int) FileOption
WithZlib configures a ROOT file to use zlib as a compression mechanism.
func WithoutCompression ¶ added in v0.15.0
func WithoutCompression() FileOption
WithoutCompression configures a ROOT file to not use any compression mechanism.
type Float16 ¶
type Float16 float32
Float16 is a float32 in memory, written with a truncated mantissa.
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])
func NewGraphAsymmErrorsFrom ¶ added in v0.15.0
func NewGraphAsymmErrorsFrom(s2 *hbook.S2D) GraphErrors
NewGraphAsymmErrorsFrom creates a new GraphAsymErrors from 2-dim hbook data points.
func NewGraphErrorsFrom ¶ added in v0.15.0
func NewGraphErrorsFrom(s2 *hbook.S2D) GraphErrors
NewGraphErrorsFrom creates a new GraphErrors from 2-dim hbook data points.
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 NewH1DFrom ¶ added in v0.15.0
NewH1DFrom creates a new 1-dim histogram from hbook.
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) Rank ¶
Rank returns the number of dimensions of this histogram.
func (*H1D) SumW2s ¶
func (h *H1D) SumW2s() []float64
SumW2s returns the array of sum of squares of weights
func (*H1D) UnmarshalYODA ¶ added in v0.15.0
UnmarshalYODA implements the YODAUnmarshaler interface.
func (*H1D) XBinCenter ¶
XBinCenter returns the bin center value in X.
func (*H1D) XBinContent ¶
XBinContent returns the bin content value in X.
func (*H1D) XBinError ¶
XBinError returns the bin error 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 NewH1FFrom ¶ added in v0.15.0
NewH1FFrom creates a new 1-dim histogram from hbook.
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) Rank ¶
Rank returns the number of dimensions of this histogram.
func (*H1F) SumW2s ¶
func (h *H1F) SumW2s() []float64
SumW2s returns the array of sum of squares of weights
func (*H1F) UnmarshalYODA ¶ added in v0.15.0
UnmarshalYODA implements the YODAUnmarshaler interface.
func (*H1F) XBinCenter ¶
XBinCenter returns the bin center value in X.
func (*H1F) XBinContent ¶
XBinContent returns the bin content value in X.
func (*H1F) XBinError ¶
XBinError returns the bin error 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 NewH1IFrom ¶ added in v0.15.0
NewH1IFrom creates a new 1-dim histogram from hbook.
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) Rank ¶
Rank returns the number of dimensions of this histogram.
func (*H1I) SumW2s ¶
func (h *H1I) SumW2s() []float64
SumW2s returns the array of sum of squares of weights
func (*H1I) UnmarshalYODA ¶ added in v0.15.0
UnmarshalYODA implements the YODAUnmarshaler interface.
func (*H1I) XBinCenter ¶
XBinCenter returns the bin center value in X.
func (*H1I) XBinContent ¶
XBinContent returns the bin content value in X.
func (*H1I) XBinError ¶
XBinError returns the bin error 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 NewH2DFrom ¶ added in v0.15.0
NewH2DFrom creates a new H2D from hbook 2-dim histogram.
func (*H2D) MarshalYODA ¶
MarshalYODA implements the YODAMarshaler interface.
func (*H2D) Rank ¶
Rank returns the number of dimensions of this histogram.
func (*H2D) UnmarshalYODA ¶ added in v0.15.0
UnmarshalYODA implements the YODAUnmarshaler interface.
func (*H2D) XBinCenter ¶
XBinCenter returns the bin center value in X.
func (*H2D) XBinContent ¶
XBinContent returns the bin content value in X.
func (*H2D) XBinError ¶
XBinError returns the bin error in X.
func (*H2D) XBinLowEdge ¶
XBinLowEdge returns the bin lower edge value in X.
func (*H2D) XBinWidth ¶
XBinWidth returns the bin width 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) YBinError ¶
YBinError returns the bin error 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 NewH2FFrom ¶ added in v0.15.0
NewH2FFrom creates a new H2F from hbook 2-dim histogram.
func (*H2F) MarshalYODA ¶
MarshalYODA implements the YODAMarshaler interface.
func (*H2F) Rank ¶
Rank returns the number of dimensions of this histogram.
func (*H2F) UnmarshalYODA ¶ added in v0.15.0
UnmarshalYODA implements the YODAUnmarshaler interface.
func (*H2F) XBinCenter ¶
XBinCenter returns the bin center value in X.
func (*H2F) XBinContent ¶
XBinContent returns the bin content value in X.
func (*H2F) XBinError ¶
XBinError returns the bin error in X.
func (*H2F) XBinLowEdge ¶
XBinLowEdge returns the bin lower edge value in X.
func (*H2F) XBinWidth ¶
XBinWidth returns the bin width 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) YBinError ¶
YBinError returns the bin error 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 NewH2IFrom ¶ added in v0.15.0
NewH2IFrom creates a new H2I from hbook 2-dim histogram.
func (*H2I) MarshalYODA ¶
MarshalYODA implements the YODAMarshaler interface.
func (*H2I) Rank ¶
Rank returns the number of dimensions of this histogram.
func (*H2I) UnmarshalYODA ¶ added in v0.15.0
UnmarshalYODA implements the YODAUnmarshaler interface.
func (*H2I) XBinCenter ¶
XBinCenter returns the bin center value in X.
func (*H2I) XBinContent ¶
XBinContent returns the bin content value in X.
func (*H2I) XBinError ¶
XBinError returns the bin error in X.
func (*H2I) XBinLowEdge ¶
XBinLowEdge returns the bin lower edge value in X.
func (*H2I) XBinWidth ¶
XBinWidth returns the bin width 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) YBinError ¶
YBinError returns the bin error 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) Bytes ¶
Bytes returns the buffer of bytes corresponding to the Key's value
func (*Key) MarshalROOT ¶
MarshalROOT encodes the key to the provided buffer.
func (*Key) Object ¶
Object returns the (ROOT) object corresponding to the Key's value.
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) Maximum ¶
Maximum returns the maximum value of the leaf.
func (*LeafB) Minimum ¶
Minimum returns the minimum value of the leaf.
type LeafC ¶
type LeafC struct {
// contains filtered or unexported fields
}
LeafC implements ROOT TLeafC
func (*LeafC) Maximum ¶
Maximum returns the maximum value of the leaf.
func (*LeafC) Minimum ¶
Minimum returns the minimum value of the leaf.
type LeafD ¶
type LeafD struct {
// contains filtered or unexported fields
}
LeafD implements ROOT TLeafD
func (*LeafD) Maximum ¶
Maximum returns the maximum value of the leaf.
func (*LeafD) Minimum ¶
Minimum returns the minimum value of the leaf.
type LeafF ¶
type LeafF struct {
// contains filtered or unexported fields
}
LeafF implements ROOT TLeafF
func (*LeafF) Maximum ¶
Maximum returns the maximum value of the leaf.
func (*LeafF) Minimum ¶
Minimum returns the minimum value of the leaf.
type LeafI ¶
type LeafI struct {
// contains filtered or unexported fields
}
LeafI implements ROOT TLeafI
func (*LeafI) Maximum ¶
Maximum returns the maximum value of the leaf.
func (*LeafI) Minimum ¶
Minimum returns the minimum value of the leaf.
type LeafL ¶
type LeafL struct {
// contains filtered or unexported fields
}
LeafL implements ROOT TLeafL
func (*LeafL) Maximum ¶
Maximum returns the maximum value of the leaf.
func (*LeafL) Minimum ¶
Minimum returns the minimum value of the leaf.
type LeafO ¶
type LeafO struct {
// contains filtered or unexported fields
}
LeafO implements ROOT TLeafO
func (*LeafO) Maximum ¶
Maximum returns the maximum value of the leaf.
func (*LeafO) Minimum ¶
Minimum returns the minimum value of the leaf.
type LeafS ¶
type LeafS struct {
// contains filtered or unexported fields
}
LeafS implements ROOT TLeafS
func (*LeafS) Maximum ¶
Maximum returns the maximum value of the leaf.
func (*LeafS) Minimum ¶
Minimum returns the minimum value of the leaf.
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 ObjString ¶
type ObjString interface { Name() string String() string // contains filtered or unexported methods }
ObjString is a ROOT string that implements ROOT TObject.
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 NewRBuffer ¶
func NewRBuffer(data []byte, refs map[int64]interface{}, offset uint32, ctx StreamerInfoContext) *RBuffer
func (*RBuffer) CheckByteCount ¶
func (*RBuffer) StreamerInfo ¶
func (r *RBuffer) StreamerInfo(name string) (StreamerInfo, error)
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 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 ¶
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) Entry ¶
Entry returns the entry number of the last read row.
func (*Scanner) Err ¶
Err returns the error, if any, that was encountered during iteration.
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.
func (*Scanner) Scan ¶
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.
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 StreamerInfoContext ¶
type StreamerInfoContext interface {
StreamerInfo(name string) (StreamerInfo, error)
}
type Tree ¶
type Tree interface { Named Entries() int64 TotBytes() int64 ZipBytes() int64 Branch(name string) Branch Branches() []Branch Leaf(name string) Leaf Leaves() []Leaf // contains filtered or unexported methods }
Tree is a collection of branches of data.
func Chain ¶
Chain returns a tchain that is the concatenation of all the input Trees.
Example ¶
ExampleChain shows how to create a chain made of 2 trees.
package main import ( "fmt" "log" "go-hep.org/x/hep/rootio" ) func main() { const name = "tree" f1, err := rootio.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.(rootio.Tree) f2, err := rootio.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.(rootio.Tree) chain := rootio.Chain(t1, t2) type Data struct { Event struct { Beg string `rootio:"Beg"` F64 float64 `rootio:"F64"` ArrF64 [10]float64 `rootio:"ArrayF64"` N int32 `rootio:"N"` SliF64 []float64 `rootio:"SliceF64"` StdStr string `rootio:"StdStr"` StlVecF64 []float64 `rootio:"StlVecF64"` StlVecStr []string `rootio:"StlVecStr"` End string `rootio:"End"` } `rootio:"evt"` } sc, err := rootio.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 ¶
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.
Example ¶
ExampleChainOf shows how to create a chain made of trees from 2 files.
package main import ( "fmt" "log" "go-hep.org/x/hep/rootio" ) func main() { const name = "tree" chain, closer, err := rootio.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 `rootio:"Beg"` F64 float64 `rootio:"F64"` ArrF64 [10]float64 `rootio:"ArrayF64"` N int32 `rootio:"N"` SliF64 []float64 `rootio:"SliceF64"` StdStr string `rootio:"StdStr"` StlVecF64 []float64 `rootio:"StlVecF64"` StlVecStr []string `rootio:"StlVecStr"` End string `rootio:"End"` } `rootio:"evt"` } sc, err := rootio.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 ¶
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
- compress.go
- consts.go
- datatypes.go
- dir.go
- dobj.go
- doc.go
- factory.go
- file.go
- fileplugin.go
- graph.go
- h1_gen.go
- h2_gen.go
- hist.go
- key.go
- leaf.go
- leaf_gen.go
- list.go
- memfile.go
- named.go
- objarray.go
- object.go
- objstring.go
- rbuffer.go
- read_streamers.go
- rootio.go
- scanner.go
- sizeof.go
- streamers.go
- tchain.go
- time.go
- tree.go
- utils.go
- uuid.go
- wbuffer.go
- wrapper.go
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
root-cp
root-cp selects and copies keys from a ROOT file to another ROOT file.
|
root-cp selects and copies keys from a ROOT file to another ROOT file. |
root-diff
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
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-fuse
Command root-fuse mounts the contents of a ROOT file as a local directory.
|
Command root-fuse mounts the contents of a ROOT file as a local directory. |
root-gen-datareader
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
root-ls lists the content of a ROOT file.
|
root-ls lists the content of a ROOT file. |
root-print
root-print prints ROOT files contents to PDF, PNG, ...
|
root-print prints ROOT files contents to PDF, PNG, ... |
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. |
internal
|
|
rstreamers
Package rstreamers provides the StreamerInfo definitions for a bunch of core ROOT classes, to setup the bootstrap procedure of being able to create streamers from the Go side.
|
Package rstreamers provides the StreamerInfo definitions for a bunch of core ROOT classes, to setup the bootstrap procedure of being able to create streamers from the Go side. |