From 35fa0480107914f7fc241ae1338053b180a5627e Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 8 Dec 2017 11:26:02 +0300 Subject: [PATCH] Fixed Coal lazy execution (workaround for couroutine bug) --- .../inr/numass/control/cryotemp/PKT8Device.kt | 8 ++++---- .../inr/numass/control/magnet/LambdaMagnet.kt | 16 ++++++++-------- .../kotlin/inr/numass/control/msp/MspDevice.kt | 16 ++++++++-------- .../inr/numass/control/readvac/CM32Device.kt | 8 ++++---- .../numass/control/readvac/MKSBaratronDevice.kt | 4 ++-- .../inr/numass/control/readvac/MKSVacDevice.kt | 6 +++--- .../numass/control/readvac/MeradatVacDevice.kt | 6 +++--- .../numass/scripts/underflow/Underflow.groovy | 2 +- .../inr/numass/tasks/NumassFitScanSummaryTask.kt | 2 +- .../main/kotlin/inr/numass/tasks/NumassTasks.kt | 5 ++++- 10 files changed, 38 insertions(+), 35 deletions(-) diff --git a/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Device.kt b/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Device.kt index 9ba9213c..5d8d048c 100644 --- a/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Device.kt +++ b/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Device.kt @@ -130,7 +130,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, logger.info("Setting dynamic range to " + it.intValue()) val response = sendAndWait("g" + it.intValue()).trim { it <= ' ' } if (response.contains("=")) { - updateState(PGA, Integer.parseInt(response.substring(4))) + updateLogicalState(PGA, Integer.parseInt(response.substring(4))) } else { logger.error("Setting pga failed with message: " + response) } @@ -175,7 +175,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, } if (response.contains("=")) { - updateState(ABUF, Integer.parseInt(response.substring(14))) + updateLogicalState(ABUF, Integer.parseInt(response.substring(14))) // getLogger().info("successfully set buffer size to {}", this.abuf); } else { logger.error("Setting averaging buffer failed with message: " + response) @@ -242,7 +242,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, } if (response.contains("=")) { - updateState(SPS, Integer.parseInt(response.substring(4))) + updateLogicalState(SPS, Integer.parseInt(response.substring(4))) } else { logger.error("Setting sps failed with message: " + response) } @@ -303,7 +303,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, //add weak stop listener stopListener = controller.onPhrase("[Ss]topped\\s*") { afterPause() - updateState(Sensor.MEASURING_STATE, false) + updateLogicalState(Sensor.MEASURING_STATE, false) } //add weak measurement listener diff --git a/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/LambdaMagnet.kt b/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/LambdaMagnet.kt index 70c1afb0..7f7ee9f9 100644 --- a/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/LambdaMagnet.kt +++ b/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/LambdaMagnet.kt @@ -164,7 +164,7 @@ open class LambdaMagnet(context: Context, meta: Meta, private val controller: La // val out: Boolean = "ON" == talk("OUT?") // // val measuredCurrent = s2d(getParameter("MC")) -// updateState("current", measuredCurrent) +// updateLogicalState("current", measuredCurrent) // val setCurrent = s2d(getParameter("PC")) // val measuredVoltage = s2d(getParameter("MV")) // val setVoltage = s2d(getParameter("PV")) @@ -217,11 +217,11 @@ open class LambdaMagnet(context: Context, meta: Meta, private val controller: La private fun update(key: String, value: String) { when (key) { - "OUT" -> updateState("output", value == "ON") - "MC" -> updateState("current", s2d(value)) - "PC" -> updateState("targetCurrent", s2d(value)) - "MV" -> updateState("voltage", s2d(value)) - "PV" -> updateState("targetVoltage", s2d(value)) + "OUT" -> updateLogicalState("output", value == "ON") + "MC" -> updateLogicalState("current", s2d(value)) + "PC" -> updateLogicalState("targetCurrent", s2d(value)) + "MV" -> updateLogicalState("voltage", s2d(value)) + "PV" -> updateLogicalState("targetVoltage", s2d(value)) } } @@ -288,7 +288,7 @@ open class LambdaMagnet(context: Context, meta: Meta, private val controller: La updateTask = scheduler.scheduleWithFixedDelay(call, 0, delay.toLong(), TimeUnit.MILLISECONDS) listener?.updateTaskStateChanged(getName(), true) - setLogicalState("updating", Value.of(true)) + updateLogicalState("updating", Value.of(true)) } @Throws(PortException::class) @@ -340,7 +340,7 @@ open class LambdaMagnet(context: Context, meta: Meta, private val controller: La listener?.monitorTaskStateChanged(getName(), false) monitorTask = null } - setLogicalState("output", Value.of(false)) + updateLogicalState("output", Value.of(false)) } override fun getName(): String { diff --git a/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDevice.kt b/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDevice.kt index 4b48aa99..1913dd24 100644 --- a/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDevice.kt +++ b/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDevice.kt @@ -82,8 +82,8 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta connection.weakOnError(this::notifyError) onResponse("FilamentStatus"){ val status = it[0, 2] - updateState("filamentOn", status == "ON") - updateState("filamentStatus", status) + updateLogicalState("filamentOn", status == "ON") + updateLogicalState("filamentStatus", status) } logger.info("Connected to MKS mass-spectrometer on {}", connection.port); } @@ -111,8 +111,8 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta // all possible async messages "FilamentStatus" -> { val status = response[0, 2] - updateState("filamentOn", status == "ON") - updateState("filamentStatus", status) + updateLogicalState("filamentOn", status == "ON") + updateLogicalState("filamentStatus", status) } } if (measurementDelegate != null) { @@ -197,7 +197,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta response = commandAndWait("Select", sensorName) if (response.isOK) { - updateState("selected", true) + updateLogicalState("selected", true) // selected = true; } else { notifyError(response.errorDescription(), null) @@ -208,13 +208,13 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta if (response.isOK) { // controlled = true; // invalidateState("controlled"); - updateState("controlled", true) + updateLogicalState("controlled", true) } else { notifyError(response.errorDescription(), null) return false } // connected = true; - updateState(PortSensor.CONNECTED_STATE, true) + updateLogicalState(PortSensor.CONNECTED_STATE, true) return true } else { connection.close() @@ -274,7 +274,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta private fun selectFilament(filament: Int) { val response = commandAndWait("FilamentSelect", filament) if (response.isOK) { - updateState("filament", response[1, 1]) + updateLogicalState("filament", response[1, 1]) } else { logger.error("Failed to set filament with error: {}", response.errorDescription()) } diff --git a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/CM32Device.kt b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/CM32Device.kt index 5ba26616..27fbb7e5 100644 --- a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/CM32Device.kt +++ b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/CM32Device.kt @@ -52,19 +52,19 @@ class CM32Device(context: Context, meta: Meta) : PortSensor(context, met if (answer.isEmpty()) { this.updateMessage("No signal") - updateState(PortSensor.CONNECTED_STATE, false) + updateLogicalState(PortSensor.CONNECTED_STATE, false) return null } else if (!answer.contains("PM1:mbar")) { this.updateMessage("Wrong answer: " + answer) - updateState(PortSensor.CONNECTED_STATE, false) + updateLogicalState(PortSensor.CONNECTED_STATE, false) return null } else if (answer.substring(14, 17) == "OFF") { this.updateMessage("Off") - updateState(PortSensor.CONNECTED_STATE, true) + updateLogicalState(PortSensor.CONNECTED_STATE, true) return null } else { this.updateMessage("OK") - updateState(PortSensor.CONNECTED_STATE, true) + updateLogicalState(PortSensor.CONNECTED_STATE, true) return java.lang.Double.parseDouble(answer.substring(14, 17) + answer.substring(19, 23)) } } diff --git a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSBaratronDevice.kt b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSBaratronDevice.kt index c20ec6a2..ad6ccb42 100644 --- a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSBaratronDevice.kt +++ b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSBaratronDevice.kt @@ -51,11 +51,11 @@ class MKSBaratronDevice(context: Context, meta: Meta) : PortSensor(conte val answer = sendAndWait("AV" + channel + "\r") if (answer == null || answer.isEmpty()) { // invalidateState("connection"); - updateState(PortSensor.CONNECTED_STATE, false) + updateLogicalState(PortSensor.CONNECTED_STATE, false) this.updateMessage("No connection") return null } else { - updateState(PortSensor.CONNECTED_STATE, true) + updateLogicalState(PortSensor.CONNECTED_STATE, true) } val res = java.lang.Double.parseDouble(answer) if (res <= 0) { diff --git a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSVacDevice.kt b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSVacDevice.kt index 39bea920..756a1ab8 100644 --- a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSVacDevice.kt +++ b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSVacDevice.kt @@ -88,7 +88,7 @@ class MKSVacDevice(context: Context, meta: Meta) : PortSensor(context, m @Throws(ControlException::class) override fun shutdown() { if (isConnected) { - setState("power",false) + setState("power", false) } super.shutdown() } @@ -138,14 +138,14 @@ class MKSVacDevice(context: Context, meta: Meta) : PortSensor(context, m val channel = meta.getInt("channel", 5) val answer = talk("PR$channel?") if (answer == null || answer.isEmpty()) { - updateState(PortSensor.CONNECTED_STATE, false) + updateLogicalState(PortSensor.CONNECTED_STATE, false) this.updateMessage("No connection") return null } val res = parseDouble(answer) return if (res <= 0) { this.updateMessage("No power") - invalidateState("power") + updateLogicalState("power", false) null } else { this.updateMessage("OK") diff --git a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MeradatVacDevice.kt b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MeradatVacDevice.kt index 27dbc50e..e6341011 100644 --- a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MeradatVacDevice.kt +++ b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MeradatVacDevice.kt @@ -61,7 +61,7 @@ class MeradatVacDevice(context: Context, meta: Meta) : PortSensor(contex if (answer.isEmpty()) { this.updateMessage("No signal") - updateState(PortSensor.CONNECTED_STATE, false) + updateLogicalState(PortSensor.CONNECTED_STATE, false) return null } else { val match = response.matcher(answer) @@ -75,11 +75,11 @@ class MeradatVacDevice(context: Context, meta: Meta) : PortSensor(contex var res = BigDecimal.valueOf(base * Math.pow(10.0, exp.toDouble())) res = res.setScale(4, RoundingMode.CEILING) this.updateMessage("OK") - updateState(PortSensor.CONNECTED_STATE, true) + updateLogicalState(PortSensor.CONNECTED_STATE, true) return res.toDouble() } else { this.updateMessage("Wrong answer: " + answer) - updateState(PortSensor.CONNECTED_STATE, false) + updateLogicalState(PortSensor.CONNECTED_STATE, false) return null } } diff --git a/numass-main/src/main/groovy/inr/numass/scripts/underflow/Underflow.groovy b/numass-main/src/main/groovy/inr/numass/scripts/underflow/Underflow.groovy index d2c90a1c..5caedf47 100644 --- a/numass-main/src/main/groovy/inr/numass/scripts/underflow/Underflow.groovy +++ b/numass-main/src/main/groovy/inr/numass/scripts/underflow/Underflow.groovy @@ -52,7 +52,7 @@ shell.eval { if (meta.hasValue("subtract.reference")) { String referenceVoltage = meta["subtract.reference"] println "subtracting reference point ${referenceVoltage}" - def referencePoint = spectra.compute(referenceVoltage) + def referencePoint = spectra.get(referenceVoltage) spectraMap = spectra .findAll { it.name != referenceVoltage } .collectEntries { diff --git a/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanSummaryTask.kt b/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanSummaryTask.kt index 9fe903be..b86eb20c 100644 --- a/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanSummaryTask.kt +++ b/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanSummaryTask.kt @@ -30,7 +30,7 @@ class NumassFitScanSummaryTask : AbstractTask() { val builder = DataSet.builder(Table::class.java) val action = FitSummaryAction() val input = data.checked(FitResult::class.java) - input.nodeStream().filter { it -> it.dataSize(false) > 0 }.forEach { node -> builder.putData(node.name, action.run(model.context, node, model.getMeta()).data) } + input.nodeStream().filter { it -> it.getSize(false) > 0 }.forEach { node -> builder.putData(node.name, action.run(model.context, node, model.getMeta()).data) } return builder.build() } diff --git a/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt b/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt index 915a74fd..a2a85944 100644 --- a/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt +++ b/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt @@ -43,7 +43,10 @@ val selectTask = task("select") { configure(meta.getMetaOrEmpty("data")) } transform { data -> - CustomDataFilter(meta).filter(data.checked(NumassSet::class.java)) + logger.info("Starting selection from data node with size ${data.size}") + CustomDataFilter(meta).filter(data.checked(NumassSet::class.java)).also { + logger.info("Selected ${it.size} elements") + } } }