-
Notifications
You must be signed in to change notification settings - Fork 35
/
pdt.go
76 lines (64 loc) · 1.41 KB
/
pdt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2017 The go-hep Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package heppdt
import (
"bytes"
"io"
)
var defaultTable Table
// Table represents a particle data table.
type Table struct {
name string
pdt map[PID]*Particle
pid map[string]PID
}
// New returns a new particle data table, initialized from r
func New(r io.Reader, n string) (Table, error) {
t := Table{
name: n,
pdt: make(map[PID]*Particle),
pid: make(map[string]PID),
}
err := parse(r, &t)
return t, err
}
// Name returns the name of this particle data table
func (t *Table) Name() string {
return t.name
}
// Len returns the size of the particle data table
func (t *Table) Len() int {
return len(t.pdt)
}
// PDT returns the particle data table
func (t *Table) PDT() map[PID]*Particle {
return t.pdt
}
// ParticleByID returns the particle information via particle ID
func (t *Table) ParticleByID(pid PID) *Particle {
p, ok := t.pdt[pid]
if !ok {
return nil
}
return p
}
// ParticleByName returns the particle information via particle name
func (t *Table) ParticleByName(n string) *Particle {
pid, ok := t.pid[n]
if !ok {
return nil
}
p, ok := t.pdt[pid]
if !ok {
return nil
}
return p
}
func init() {
var err error
defaultTable, err = New(bytes.NewBufferString(tabledata), "particle.tbl")
if err != nil {
panic(err)
}
}