diff --git a/api/piquant/configuration.go b/api/piquant/configuration.go index 390fa196..94eb2f76 100644 --- a/api/piquant/configuration.go +++ b/api/piquant/configuration.go @@ -20,6 +20,9 @@ package piquant import ( "context" + "fmt" + "strconv" + "strings" "github.com/pixlise/core/v4/api/dbCollections" "github.com/pixlise/core/v4/api/filepaths" @@ -79,3 +82,29 @@ func GetDetectorConfig(name string, db *mongo.Database) (*protos.DetectorConfig, return &cfg, nil } + +func ReadFieldFromPIQUANTConfigMSA(msaContents string, fieldName string) (float32, error) { + piquantCfgLines := strings.Split(msaContents, "\n") + for _, line := range piquantCfgLines { + idx := strings.Index(line, fieldName) + if idx >= 0 { + line := line[idx+len(fieldName):] + idx = strings.Index(line, ":") + + if idx >= 0 { + line = line[idx+1:] + line = strings.TrimLeft(line, " ") + + // Now snip off anything after it + idx = strings.Index(line, " ") + if idx >= 0 { + line = line[0:idx] + val, err := strconv.ParseFloat(line, 32) + return float32(val), err + } + } + } + } + + return 0, fmt.Errorf("Failed to find field %v", fieldName) +} diff --git a/api/ws/handlers/detector-config.go b/api/ws/handlers/detector-config.go index 370fad30..f380ad68 100644 --- a/api/ws/handlers/detector-config.go +++ b/api/ws/handlers/detector-config.go @@ -2,8 +2,10 @@ package wsHandler import ( "context" + "fmt" "github.com/pixlise/core/v4/api/dbCollections" + "github.com/pixlise/core/v4/api/filepaths" "github.com/pixlise/core/v4/api/piquant" "github.com/pixlise/core/v4/api/ws/wsHelpers" protos "github.com/pixlise/core/v4/generated-protos" @@ -21,9 +23,39 @@ func HandleDetectorConfigReq(req *protos.DetectorConfigReq, hctx wsHelpers.Handl return nil, err } + // Read versions + versions := piquant.GetPiquantConfigVersions(hctx.Svcs, req.Id) + if len(versions) <= 0 { + return nil, fmt.Errorf("DetectorConfig %v has no versions defined", req.Id) + } + + latestVersion := versions[len(versions)-1] + + // Read PIQUANT config file + piquantCfg, err := piquant.GetPIQUANTConfig(hctx.Svcs, req.Id, latestVersion) + if err != nil { + return nil, err + } + + // Retrieve elevAngle + cfgPath := filepaths.GetDetectorConfigPath(req.Id, latestVersion, piquantCfg.ConfigFile) + piquantCfgFile, err := hctx.Svcs.FS.ReadObject(hctx.Svcs.Config.ConfigBucket, cfgPath) + if err != nil { + return nil, err + } + + // Find the value + piquantCfgFileStr := string(piquantCfgFile) + angle, err := piquant.ReadFieldFromPIQUANTConfigMSA(piquantCfgFileStr, "#ELEVANGLE") + if err != nil { + return nil, fmt.Errorf("Failed to read ELEVANGLE from Piquant config file: %v", cfgPath) + } + + cfg.ElevAngle = angle + return &protos.DetectorConfigResp{ Config: cfg, - PiquantConfigVersions: piquant.GetPiquantConfigVersions(hctx.Svcs, req.Id), + PiquantConfigVersions: versions, }, nil } diff --git a/data-formats b/data-formats index 2de699e7..19afaa02 160000 --- a/data-formats +++ b/data-formats @@ -1 +1 @@ -Subproject commit 2de699e7ac2f76a44b613787d990a79ef2113448 +Subproject commit 19afaa0253a5c3347605de665393bf92d9512089 diff --git a/generated-protos/detector-config.pb.go b/generated-protos/detector-config.pb.go index 5d5b19c5..edc9caac 100644 --- a/generated-protos/detector-config.pb.go +++ b/generated-protos/detector-config.pb.go @@ -35,6 +35,7 @@ type DetectorConfig struct { TubeElement int32 `protobuf:"varint,8,opt,name=tubeElement,proto3" json:"tubeElement,omitempty"` DefaultParams string `protobuf:"bytes,9,opt,name=defaultParams,proto3" json:"defaultParams,omitempty"` MmBeamRadius float32 `protobuf:"fixed32,10,opt,name=mmBeamRadius,proto3" json:"mmBeamRadius,omitempty"` + ElevAngle float32 `protobuf:"fixed32,11,opt,name=elevAngle,proto3" json:"elevAngle,omitempty"` } func (x *DetectorConfig) Reset() { @@ -139,11 +140,18 @@ func (x *DetectorConfig) GetMmBeamRadius() float32 { return 0 } +func (x *DetectorConfig) GetElevAngle() float32 { + if x != nil { + return x.ElevAngle + } + return 0 +} + var File_detector_config_proto protoreflect.FileDescriptor var file_detector_config_proto_rawDesc = []byte{ 0x0a, 0x15, 0x64, 0x65, 0x74, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x2d, 0x63, 0x6f, 0x6e, 0x66, 0x69, - 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xf0, 0x02, 0x0a, 0x0e, 0x44, 0x65, 0x74, 0x65, + 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x8e, 0x03, 0x0a, 0x0e, 0x44, 0x65, 0x74, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x6d, 0x69, 0x6e, 0x45, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, @@ -166,8 +174,10 @@ var file_detector_config_proto_rawDesc = []byte{ 0x73, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x22, 0x0a, 0x0c, 0x6d, 0x6d, 0x42, 0x65, 0x61, 0x6d, 0x52, 0x61, 0x64, 0x69, 0x75, 0x73, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x02, 0x52, 0x0c, 0x6d, 0x6d, - 0x42, 0x65, 0x61, 0x6d, 0x52, 0x61, 0x64, 0x69, 0x75, 0x73, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x3b, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x42, 0x65, 0x61, 0x6d, 0x52, 0x61, 0x64, 0x69, 0x75, 0x73, 0x12, 0x1c, 0x0a, 0x09, 0x65, 0x6c, + 0x65, 0x76, 0x41, 0x6e, 0x67, 0x6c, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x02, 0x52, 0x09, 0x65, + 0x6c, 0x65, 0x76, 0x41, 0x6e, 0x67, 0x6c, 0x65, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x3b, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/internal/cmd-line-tools/api-integration-test/testDetectorConfig.go b/internal/cmd-line-tools/api-integration-test/testDetectorConfig.go index 5b9b0e3a..b339f59c 100644 --- a/internal/cmd-line-tools/api-integration-test/testDetectorConfig.go +++ b/internal/cmd-line-tools/api-integration-test/testDetectorConfig.go @@ -67,7 +67,8 @@ func testDetectorConfig(apiHost string) { "xrfeVResolution": 230, "windowElement": 14, "tubeElement": 45, - "mmBeamRadius": 0.06 + "mmBeamRadius": 0.06, + "elevAngle": 70 }, "piquantConfigVersions": [ "v5",