-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathunits.go
71 lines (61 loc) · 1.52 KB
/
units.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
// 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 hepmc
import (
"fmt"
)
// MomentumUnit describes the units of momentum quantities (MeV or GeV)
type MomentumUnit int
// LengthUnit describes the units of length quantities (mm or cm)
type LengthUnit int
const (
// MEV is a Momentum in MeV (default)
MEV MomentumUnit = iota
// GEV is a Momentum in GeV
GEV
)
const (
// MM is a Length in mm (default)
MM LengthUnit = iota
// CM is a Length in cm
CM
)
func (mu MomentumUnit) String() string {
switch mu {
case MEV:
return "MEV"
case GEV:
return "GEV"
}
panic(fmt.Errorf("hepmc.units: invalid MomentumUnit value (%d)", int(mu)))
}
// MomentumUnitFromString creates a MomentumUnit value from its string representation
func MomentumUnitFromString(s string) (MomentumUnit, error) {
switch s {
case "MEV":
return MEV, nil
case "GEV":
return GEV, nil
}
return -1, fmt.Errorf("hepmc.units: invalid MomentumUnit string-value (%s)", s)
}
func (lu LengthUnit) String() string {
switch lu {
case MM:
return "MM"
case CM:
return "CM"
}
panic(fmt.Errorf("hepmc.units: invalid LengthUnit value (%d)", int(lu)))
}
// LengthUnitFromString creates a LengthUnit value from its string representation
func LengthUnitFromString(s string) (LengthUnit, error) {
switch s {
case "MM":
return MM, nil
case "CM":
return CM, nil
}
return -1, fmt.Errorf("hepmc.units: invalid LengthUnit string-value (%s)", s)
}