hep: go-hep.org/x/hep/hbook/ntup Index | Files | Directories

package ntup

import "go-hep.org/x/hep/hbook/ntup"

Package ntup provides a way to create, open and iterate over n-tuple data.

Index

Package Files

ntuple.go

Variables

var (
    // ErrNotExist is returned when an n-tuple could not be located in a sql.DB
    ErrNotExist = errors.New("hbook/ntup: ntuple does not exist")

    // ErrMissingColDef is returned when some information is missing wrt
    // an n-tuple column definition
    ErrMissingColDef = errors.New("hbook/ntup: expected at least one column definition")
)

type Descriptor Uses

type Descriptor interface {
    Name() string       // the column name
    Type() reflect.Type // the column type
}

Descriptor describes a column

type Ntuple Uses

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

Ntuple provides read/write access to row-wise n-tuple data.

func Create Uses

func Create(db *sql.DB, name string, cols ...interface{}) (*Ntuple, error)

Create creates a new ntuple with the given name inside the given database handle. The n-tuple schema is inferred from the cols argument. cols can be:

- a single struct value (columns are inferred from the names+types of the exported fields)
- a list of builtin values (the columns names are varX where X=[1-len(cols)])
- a list of ntup.Descriptors

e.g.:

nt, err := ntup.Create(db, "nt", struct{X float64 `hbook:"x"`}{})
nt, err := ntup.Create(db, "nt", int64(0), float64(0))

func Open Uses

func Open(db *sql.DB, name string) (*Ntuple, error)

Open inspects the given database handle and tries to return an Ntuple connected to a table with the given name. Open returns ErrNotExist if no such table exists. If name is "", Open will connect to the one-and-only table in the db.

e.g.:

db, err := sql.Open("csv", "file.csv")
nt, err := ntup.Open(db, "ntup")

func (*Ntuple) Cols Uses

func (nt *Ntuple) Cols() []Descriptor

Cols returns the columns' descriptors of this n-tuple. Modifying it directly leads to undefined behaviour.

func (*Ntuple) DB Uses

func (nt *Ntuple) DB() *sql.DB

DB returns the underlying db this n-tuple is connected to.

func (*Ntuple) Name Uses

func (nt *Ntuple) Name() string

Name returns the name of this n-tuple.

func (*Ntuple) Scan Uses

func (nt *Ntuple) Scan(query string, f interface{}) error

Scan executes a query against the ntuple and runs the function f against that context.

e.g.

err = nt.Scan("x,y where z>10", func(x,y float64) error {
  h1.Fill(x, 1)
  h2.Fill(y, 1)
  return nil
})

func (*Ntuple) ScanH1D Uses

func (nt *Ntuple) ScanH1D(query string, h *hbook.H1D) (*hbook.H1D, error)

ScanH1D executes a query against the ntuple and fills the histogram with the results of the query. If h is nil, a (100-bins, xmin, xmax+ULP) histogram is created, where xmin and xmax are inferred from the content of the underlying database.

func (*Ntuple) ScanH2D Uses

func (nt *Ntuple) ScanH2D(query string, h *hbook.H2D) (*hbook.H2D, error)

ScanH2D executes a query against the ntuple and fills the histogram with the results of the query. If h is nil, a (100-bins, xmin, xmax+ULP) (100-bins, ymin, ymax+ULP) 2d-histogram is created, where xmin, xmax and ymin,ymax are inferred from the content of the underlying database.

Directories

PathSynopsis
ntcsvPackage ntcsv provides a convenient access to CSV files as n-tuple data.

Package ntup imports 9 packages (graph) and is imported by 1 packages. Updated 2018-08-02. Refresh now. Tools for package owners.