Documentation
¶
Overview ¶
Package ntup provides a way to create, open and iterate over n-tuple data.
Index ¶
- Variables
- type Descriptor
- type Ntuple
- func (nt *Ntuple) Cols() []Descriptor
- func (nt *Ntuple) DB() *sql.DB
- func (nt *Ntuple) Name() string
- func (nt *Ntuple) Scan(query string, f interface{}) error
- func (nt *Ntuple) ScanH1D(query string, h *hbook.H1D) (*hbook.H1D, error)
- func (nt *Ntuple) ScanH2D(query string, h *hbook.H2D) (*hbook.H2D, error)
Constants ¶
This section is empty.
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") )
Functions ¶
This section is empty.
Types ¶
type Descriptor ¶
type Descriptor interface { Name() string // the column name Type() reflect.Type // the column type }
Descriptor describes a column
type Ntuple ¶
type Ntuple struct {
// contains filtered or unexported fields
}
Ntuple provides read/write access to row-wise n-tuple data.
func Create ¶
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 ¶
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 ¶
func (nt *Ntuple) Cols() []Descriptor
Cols returns the columns' descriptors of this n-tuple. Modifying it directly leads to undefined behaviour.
func (*Ntuple) Scan ¶
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 ¶
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 ¶
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.