diff --git a/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Channel.kt b/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Channel.kt index c438444d..4b349685 100644 --- a/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Channel.kt +++ b/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Channel.kt @@ -32,10 +32,10 @@ internal fun createChannel(meta: Meta): PKT8Channel { if (meta.hasValue("coefs")) { when (transformationType) { "default", "hyperbolic" -> { - val coefs = meta.getValue("coefs").getList() + val coefs = meta.getValue("coefs").list val r0 = meta.getDouble("r0", 1000.0) return PKT8Channel(meta) { r -> - coefs?.indices?.sumByDouble { coefs[it].getDouble() * Math.pow(r0 / r, it.toDouble()) } ?: -1.0 + coefs.indices.sumByDouble { coefs[it].double * Math.pow(r0 / r, it.toDouble()) } } } else -> throw RuntimeException("Unknown transformation type") 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 1b530c78..e23141d6 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 @@ -21,6 +21,7 @@ import hep.dataforge.context.Context import hep.dataforge.control.collectors.RegularPointCollector import hep.dataforge.control.connections.Roles import hep.dataforge.control.devices.PortSensor +import hep.dataforge.control.devices.Sensor import hep.dataforge.control.ports.GenericPortController import hep.dataforge.control.ports.Port import hep.dataforge.control.ports.PortFactory @@ -261,7 +262,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, meta) { connection.also { it.onPhrase("[Ss]topped\\s*", this) { - notifyMeasurementState(MeasurementState.STOPPED) + notifyMeasurementState(Sensor.MeasurementState.STOPPED) } //add weak measurement listener @@ -275,7 +276,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, meta) { //send start signal it.send("s") - notifyMeasurementState(MeasurementState.IN_PROGRESS) + notifyMeasurementState(Sensor.MeasurementState.IN_PROGRESS) } } @@ -286,7 +287,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, meta) { val response = sendAndWait("p").trim() // Должно быть именно с большой буквы!!! if ("Stopped" == response || "stopped" == response) { - notifyMeasurementState(MeasurementState.STOPPED) + notifyMeasurementState(Sensor.MeasurementState.STOPPED) } } catch (ex: Exception) { notifyError("Failed to stop measurement", ex) diff --git a/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Display.kt b/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Display.kt index bd11c591..d9913ab2 100644 --- a/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Display.kt +++ b/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Display.kt @@ -120,13 +120,12 @@ class PKT8Display : DeviceDisplayFX(), PKT8ValueListener { sortBy { it.channel } } } - } - column("Sensor", PKT8Reading::channel); - column("Resistance", PKT8Reading::rawValue).cellFormat { + readonlyColumn("Sensor", PKT8Reading::channel); + readonlyColumn("Resistance", PKT8Reading::rawValue).cellFormat { text = String.format("%.2f", it) } - column("Temperature", PKT8Reading::temperature).cellFormat { + readonlyColumn("Temperature", PKT8Reading::temperature).cellFormat { text = String.format("%.2f", it) } } diff --git a/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8VirtualPort.kt b/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8VirtualPort.kt index b07c0897..962214b3 100644 --- a/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8VirtualPort.kt +++ b/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8VirtualPort.kt @@ -9,7 +9,7 @@ import hep.dataforge.control.ports.VirtualPort import hep.dataforge.meta.Meta import hep.dataforge.meta.MetaUtils import hep.dataforge.meta.Metoid -import hep.dataforge.values.Value +import hep.dataforge.values.asValue import java.time.Duration import java.util.* import java.util.function.Supplier @@ -29,7 +29,7 @@ class PKT8VirtualPort(private val portName: String, meta: Meta) : VirtualPort(me "s" -> { val letters = arrayOf("a", "b", "c", "d", "e", "f", "g", "h") for (letter in letters) { - val channelMeta = MetaUtils.findNodeByValue(meta, "channel", "letter", Value.parseValue(letter)).orElse(Meta.empty()) + val channelMeta = MetaUtils.findNodeByValue(meta, "channel", "letter", letter.asValue()).orElse(Meta.empty()) val average: Double val sigma: Double diff --git a/numass-control/dante/src/main/kotlin/inr/numass/control/dante/DanteClient.kt b/numass-control/dante/src/main/kotlin/inr/numass/control/dante/DanteClient.kt index b17c919e..b8140e59 100644 --- a/numass-control/dante/src/main/kotlin/inr/numass/control/dante/DanteClient.kt +++ b/numass-control/dante/src/main/kotlin/inr/numass/control/dante/DanteClient.kt @@ -288,7 +288,7 @@ class DanteClient(val ip: String, chainLength: Int) : AutoCloseable { val en_fil_flattop = meta.getInt("energy_filter.flat_top") val fast_peak_time = meta.getInt("fast_filter.peaking_time") val fast_flattop = meta.getInt("fast_filter.flat_top") - val recovery_time = meta.getValue("recovery_time").getLong() + val recovery_time = meta.getValue("recovery_time").long val zero_peak_rate = meta.getInt("zero_peak_rate") val inverted_input = meta.getInt("inverted_input", 0) 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 f3cb0506..f3c71d36 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 @@ -83,44 +83,45 @@ class LambdaMagnet(private val controller: LambdaPortController, meta: Meta) : A val target = valueState("target") //output values of current and voltage - private var outCurrent by valueState("outCurrent", getter = { s2d(controller.getParameter(address, "PC")) }) { _, value -> + private var outCurrent by valueState("outCurrent", getter = { s2d(controller.getParameter(address, "PC")) }) { value -> setCurrent(value.double) - return@valueState value + update(value) }.doubleDelegate - private var outVoltage = valueState("outVoltage", getter = { s2d(controller.getParameter(address, "PV")) }) { _, value -> + private var outVoltage = valueState("outVoltage", getter = { s2d(controller.getParameter(address, "PV")) }) { value -> if (!controller.setParameter(address, "PV", value.double)) { notifyError("Can't set the target voltage") } - return@valueState value + update(value) }.doubleDelegate - val output = valueState("output", getter = { controller.talk(address, "OUT?") == "OK" }) { _, value -> + val output = valueState("output", getter = { controller.talk(address, "OUT?") == "OK" }) {value -> setOutputMode(value.boolean) if (!value.boolean) { status = MagnetStatus.OFF } + update(value) } - val monitoring = valueState("monitoring", getter = { monitorTask != null }) { _, value -> + val monitoring = valueState("monitoring", getter = { monitorTask != null }) { value -> if (value.boolean) { startMonitorTask() } else { stopMonitorTask() } - return@valueState value + update(value) } /** * */ - val updating = valueState("updating", getter = { updateTask != null }) { _, value -> + val updating = valueState("updating", getter = { updateTask != null }) { value -> if (value.boolean) { startUpdateTask() } else { stopUpdateTask() } - return@valueState value + update(value) } diff --git a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/ConsoleVac.kt b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/ConsoleVac.kt index 4307770e..27624611 100644 --- a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/ConsoleVac.kt +++ b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/ConsoleVac.kt @@ -16,7 +16,7 @@ import java.time.Instant object ConsoleVac { private fun Sensor.read(): Double { this.measure() - return runBlocking { resultState.future.await().getDouble(RESULT_VALUE)} + return runBlocking { resultState.read().getDouble(RESULT_VALUE)} } @Throws(Exception::class) 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 282beb10..81e1452f 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 @@ -67,7 +67,7 @@ class MKSVacDevice(context: Context, meta: Meta) : PortSensor(context, meta) { @Throws(ControlException::class) override fun shutdown() { - if (connected) { + if (connected.booleanValue) { power = false } super.shutdown() diff --git a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacCollectorDevice.kt b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacCollectorDevice.kt index 71c4cc8d..bc5ef7ce 100644 --- a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacCollectorDevice.kt +++ b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacCollectorDevice.kt @@ -25,6 +25,7 @@ import hep.dataforge.storage.commons.LoaderFactory import hep.dataforge.storage.commons.StorageConnection import hep.dataforge.tables.TableFormatBuilder import hep.dataforge.utils.DateTimeUtils +import hep.dataforge.values.Value import hep.dataforge.values.ValueMap import hep.dataforge.values.ValueType import hep.dataforge.values.Values @@ -141,7 +142,7 @@ class VacCollectorDevice(context: Context, meta: Meta, val sensors: Collection p.putValue(n.toUnescaped(), null) } + deviceNames.forEach { n -> p.putValue(n.toUnescaped(), Value.NULL) } return p.build() } diff --git a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacCollectorDisplay.kt b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacCollectorDisplay.kt index abfa476e..67202a52 100644 --- a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacCollectorDisplay.kt +++ b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacCollectorDisplay.kt @@ -91,7 +91,7 @@ class VacCollectorDisplay : DeviceDisplayFX() { isSelected = false LogFragment().apply { addLogHandler(device.logger) - bindWindow(selectedProperty()) + bindWindow(this@togglebutton, selectedProperty()) } } } diff --git a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacDeviceFactory.kt b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacDeviceFactory.kt index 20b1d7c8..dc6ce782 100644 --- a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacDeviceFactory.kt +++ b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacDeviceFactory.kt @@ -11,9 +11,7 @@ import java.util.stream.Collectors * Created by darksnake on 16-May-17. */ class VacDeviceFactory : DeviceFactory { - override fun getType(): String { - return "numass.vac" - } + override val type: String = "numass.vac" private fun buildSensor(context: Context, sensorConfig: Meta): Sensor { return when (sensorConfig.getString("sensorType", "")) { diff --git a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacDisplay.kt b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacDisplay.kt index 21a4597a..8f130379 100644 --- a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacDisplay.kt +++ b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacDisplay.kt @@ -115,7 +115,7 @@ open class VacDisplay : DeviceDisplayFX() { } right { switch { - bindBooleanToState(CONNECTED_STATE, selectedProperty()); + booleanStateProperty(CONNECTED_STATE).bindBidirectional(selectedProperty()) selectedProperty().addListener { _, _, newValue -> if (!newValue) { value = "---" @@ -162,7 +162,7 @@ open class VacDisplay : DeviceDisplayFX() { vgrow = Priority.ALWAYS switch("Power") { alignment = Pos.CENTER - bindBooleanToState("power", selectedProperty()) + booleanStateProperty("power").bindBidirectional(selectedProperty()) } } } diff --git a/numass-main/src/main/groovy/inr/numass/scripts/times/AnalyzePoint.groovy b/numass-main/src/main/groovy/inr/numass/scripts/times/AnalyzePoint.groovy index a106310f..1f95f56c 100644 --- a/numass-main/src/main/groovy/inr/numass/scripts/times/AnalyzePoint.groovy +++ b/numass-main/src/main/groovy/inr/numass/scripts/times/AnalyzePoint.groovy @@ -12,6 +12,7 @@ import inr.numass.actions.TimeAnalyzerAction import inr.numass.data.NumassDataUtils import inr.numass.data.api.NumassPoint import inr.numass.data.api.NumassSet +import inr.numass.data.api.SimpleNumassPoint import inr.numass.data.storage.NumassStorageFactory /** @@ -48,7 +49,7 @@ new GrindShell(ctx).eval { def builder = DataSet.builder(NumassPoint) hvs.each { hv -> - builder.putStatic("point_${hv as int}", new inr.numass.data.api.SimpleNumassPoint.SimpleNumassPoint(hv, all.points.filter { + builder.putStatic("point_${hv as int}", new SimpleNumassPoint(hv, all.points.filter { it.voltage == hv }.collect())); } diff --git a/numass-main/src/main/groovy/inr/numass/scripts/times/TestAnalyzer.groovy b/numass-main/src/main/groovy/inr/numass/scripts/times/TestAnalyzer.groovy index 1caadc4d..ca60ae0e 100644 --- a/numass-main/src/main/groovy/inr/numass/scripts/times/TestAnalyzer.groovy +++ b/numass-main/src/main/groovy/inr/numass/scripts/times/TestAnalyzer.groovy @@ -8,6 +8,7 @@ import hep.dataforge.meta.Meta import inr.numass.NumassPlugin import inr.numass.actions.TimeAnalyzerAction import inr.numass.data.GeneratorKt +import inr.numass.data.api.SimpleNumassPoint import org.apache.commons.math3.random.JDKRandomGenerator import java.time.Instant @@ -17,7 +18,7 @@ import java.time.Instant */ -Context ctx = Global.instance() +Context ctx = Global.INSTANCE ctx.getPluginManager().load(FXPlotManager) ctx.getPluginManager().load(NumassPlugin.class) @@ -35,7 +36,7 @@ new GrindShell(ctx).eval { GeneratorKt.generateBlock(Instant.now().plusNanos(it * length), length, chain) } - def point = new inr.numass.data.api.SimpleNumassPoint.SimpleNumassPoint(10000, blocks) + def point = new SimpleNumassPoint(10000, blocks) def meta = Meta.empty()//Grind.buildMeta(plotHist: false) diff --git a/numass-main/src/main/java/inr/numass/actions/MonitorCorrectAction.java b/numass-main/src/main/java/inr/numass/actions/MonitorCorrectAction.java index 322ff89d..723d7061 100644 --- a/numass-main/src/main/java/inr/numass/actions/MonitorCorrectAction.java +++ b/numass-main/src/main/java/inr/numass/actions/MonitorCorrectAction.java @@ -23,7 +23,7 @@ import hep.dataforge.meta.Laminate; import hep.dataforge.meta.Meta; import hep.dataforge.tables.ListTable; import hep.dataforge.tables.Table; -import hep.dataforge.values.Value; +import hep.dataforge.values.ValueFactory; import hep.dataforge.values.ValueMap; import hep.dataforge.values.Values; import inr.numass.NumassUtils; @@ -93,17 +93,17 @@ public class MonitorCorrectAction extends OneToOneAction { double err = Math.sqrt(corrErr * corrErr + pointErr * pointErr) * getCR(dp); if (dp.getNames().contains("Monitor")) { - pb.putValue("Monitor", Value.of(dp.getValue("Monitor").getDouble() / corrFactor)); + pb.putValue("Monitor", ValueFactory.of(dp.getValue("Monitor").getDouble() / corrFactor)); } else { pb.putValue("Monitor", corrFactor); } - pb.putValue(NumassAnalyzer.COUNT_RATE_KEY, Value.of(dp.getValue(NumassAnalyzer.COUNT_RATE_KEY).getDouble() / corrFactor)); - pb.putValue(NumassAnalyzer.COUNT_RATE_ERROR_KEY, Value.of(err)); + pb.putValue(NumassAnalyzer.COUNT_RATE_KEY, ValueFactory.of(dp.getValue(NumassAnalyzer.COUNT_RATE_KEY).getDouble() / corrFactor)); + pb.putValue(NumassAnalyzer.COUNT_RATE_ERROR_KEY, ValueFactory.of(err)); } else { double corrFactor = dp.getValue(NumassAnalyzer.COUNT_RATE_KEY).getDouble() / norm; if (dp.getNames().contains("Monitor")) { - pb.putValue("Monitor", Value.of(dp.getValue("Monitor").getDouble() / corrFactor)); + pb.putValue("Monitor", ValueFactory.of(dp.getValue("Monitor").getDouble() / corrFactor)); } else { pb.putValue("Monitor", corrFactor); } @@ -127,7 +127,7 @@ public class MonitorCorrectAction extends OneToOneAction { // } else { // format = DataFormat.of(parnames); // } - Table res = new ListTable(dataList); + Table res = ListTable.infer(dataList); context.getIo().output(name, getName()).push(NumassUtils.INSTANCE.wrap(res, meta), Meta.empty()); @@ -192,7 +192,7 @@ public class MonitorCorrectAction extends OneToOneAction { private void printMonitorData(Context context, Meta meta) { if (!monitorPoints.isEmpty()) { String monitorFileName = meta.getString("monitorFile", "monitor"); - ListTable data = new ListTable(monitorPoints); + ListTable data = ListTable.infer(monitorPoints); context.getIo().output(monitorFileName, getName()).push(NumassUtils.INSTANCE.wrap(data, meta), Meta.empty()); // ColumnedDataWriter.writeTable(stream, TableTransform.sort(data, "Timestamp", true), "Monitor points", monitorNames); diff --git a/numass-main/src/main/kotlin/inr/numass/NumassUtils.kt b/numass-main/src/main/kotlin/inr/numass/NumassUtils.kt index c8ff6406..9c56f76a 100644 --- a/numass-main/src/main/kotlin/inr/numass/NumassUtils.kt +++ b/numass-main/src/main/kotlin/inr/numass/NumassUtils.kt @@ -32,13 +32,13 @@ import hep.dataforge.plots.jfreechart.JFreeChartFrame import hep.dataforge.tables.ListTable import hep.dataforge.tables.Table import hep.dataforge.values.ValueMap -import hep.dataforge.values.ValueType import hep.dataforge.values.Values import inr.numass.data.analyzers.NumassAnalyzer import inr.numass.data.api.NumassPoint import inr.numass.data.api.NumassSet import inr.numass.models.FSS import inr.numass.utils.ExpressionUtils +import kotlinx.coroutines.experimental.runBlocking import org.apache.commons.math3.analysis.UnivariateFunction import org.jfree.chart.plot.IntervalMarker import org.jfree.chart.ui.RectangleInsets @@ -156,7 +156,9 @@ object NumassUtils { val pointName = "point_" + point.meta.getInt("external_meta.point_index", point.hashCode()) builder.putData(pointName, point, pointMeta) } - set.hvData.ifPresent { hv -> builder.putData("hv", hv, Meta.empty()) } + runBlocking { + set.hvData.await()?.let { hv -> builder.putData("hv", hv, Meta.empty()) } + } return builder.build() } @@ -251,14 +253,7 @@ fun Values.unbox(): Map { val res = HashMap() for (field in this.names) { val value = this.getValue(field) - val obj: Any? = when (value.type) { - ValueType.BOOLEAN -> value.boolean - ValueType.NUMBER -> value.double - ValueType.STRING -> value.string - ValueType.TIME -> value.time - ValueType.NULL -> null - } - res.put(field, obj) + res.put(field, value.value) } return res } diff --git a/numass-main/src/main/kotlin/inr/numass/actions/SummaryAction.kt b/numass-main/src/main/kotlin/inr/numass/actions/SummaryAction.kt index 64d19436..92a6bd38 100644 --- a/numass-main/src/main/kotlin/inr/numass/actions/SummaryAction.kt +++ b/numass-main/src/main/kotlin/inr/numass/actions/SummaryAction.kt @@ -29,8 +29,10 @@ import hep.dataforge.tables.MetaTableFormat import hep.dataforge.tables.Table import hep.dataforge.values.Value import hep.dataforge.values.ValueMap +import hep.dataforge.values.asValue import inr.numass.NumassUtils import java.util.* +import kotlin.collections.ArrayList /** * @author Darksnake @@ -59,13 +61,13 @@ object SummaryAction : ManyToOneAction() { } else { throw RuntimeException("Infering parnames not suppoerted") } - val names = arrayOfNulls(2 * parNames.size + 2) - names[0] = "file" - for (i in parNames.indices) { - names[2 * i + 1] = parNames[i] - names[2 * i + 2] = parNames[i] + "Err" + val names = ArrayList() + names.add("file") + parNames.forEach { + names.add(it) + names.add("${it}_Err") } - names[names.size - 1] = "chi2" + names.add("chi2") val res = ListTable.Builder(MetaTableFormat.forNames(names)) @@ -75,24 +77,24 @@ object SummaryAction : ManyToOneAction() { Arrays.fill(av, 0.0) input.forEach { key: String, value: FitState -> - val values = arrayOfNulls(names.size) - values[0] = Value.parseValue(key) - for (i in parNames.indices) { - val `val` = Value.of(value.parameters.getDouble(parNames[i])) - values[2 * i + 1] = `val` - val err = Value.of(value.parameters.getError(parNames[i])) - values[2 * i + 2] = err - val weight = 1.0 / err.getDouble() / err.getDouble() - av[i] += `val`.getDouble() * weight + val values = ArrayList() + values.add(key.asValue()) + parNames.forEachIndexed { i, it -> + val `val` = Value.of(value.parameters.getDouble(it)) + values.add(`val`) + val err = Value.of(value.parameters.getError(it)) + values.add(err) + val weight = 1.0 / err.double / err.double + av[i] += `val`.double * weight weights[i] += weight } values[values.size - 1] = Value.of(value.chi2) - val point = ValueMap.of(names, *values) + val point = ValueMap.of(names.toTypedArray(), values) res.row(point) } val averageValues = arrayOfNulls(names.size) - averageValues[0] = Value.parseValue("average") + averageValues[0] = "average".asValue() averageValues[averageValues.size - 1] = Value.of(0) for (i in parNames.indices) { @@ -100,7 +102,7 @@ object SummaryAction : ManyToOneAction() { averageValues[2 * i + 2] = Value.of(1 / Math.sqrt(weights[i])) } - res.row(ValueMap.of(names, *averageValues)) + res.row(ValueMap.of(names.toTypedArray(), averageValues)) return res.build() } diff --git a/numass-main/src/main/kotlin/inr/numass/data/Generator.kt b/numass-main/src/main/kotlin/inr/numass/data/Generator.kt index 5ca8f7c8..c6b63c24 100644 --- a/numass-main/src/main/kotlin/inr/numass/data/Generator.kt +++ b/numass-main/src/main/kotlin/inr/numass/data/Generator.kt @@ -60,8 +60,8 @@ fun generateEvents( val channels = DoubleArray(spectrum.size()) val values = DoubleArray(spectrum.size()) for (i in 0 until spectrum.size()) { - channels[i] = spectrum.get(CHANNEL_KEY, i).getDouble() - values[i] = spectrum.get(COUNT_RATE_KEY, i).getDouble() + channels[i] = spectrum.get(CHANNEL_KEY, i).double + values[i] = spectrum.get(COUNT_RATE_KEY, i).double } val distribution = EnumeratedRealDistribution(channels, values) diff --git a/numass-main/src/main/kotlin/inr/numass/scripts/DifferentialSpectrum.kt b/numass-main/src/main/kotlin/inr/numass/scripts/DifferentialSpectrum.kt index 5105f32b..e7296e24 100644 --- a/numass-main/src/main/kotlin/inr/numass/scripts/DifferentialSpectrum.kt +++ b/numass-main/src/main/kotlin/inr/numass/scripts/DifferentialSpectrum.kt @@ -81,7 +81,7 @@ fun main(args: Array) { val res = subtractAmplitudeSpectrum(spectrum1, spectrum0) - val norm = res.getColumn(COUNT_RATE_KEY).stream().mapToDouble { it.getDouble() }.sum() + val norm = res.getColumn(COUNT_RATE_KEY).stream().mapToDouble { it.double }.sum() integralFrame.add(DataPlot.plot("point_$hv", AMPLITUDE_ADAPTER, spectrum0)) diff --git a/numass-main/src/main/kotlin/inr/numass/scripts/timeanalysis/AnalyzePoint.kt b/numass-main/src/main/kotlin/inr/numass/scripts/timeanalysis/AnalyzePoint.kt index 7fa73f24..ec907543 100644 --- a/numass-main/src/main/kotlin/inr/numass/scripts/timeanalysis/AnalyzePoint.kt +++ b/numass-main/src/main/kotlin/inr/numass/scripts/timeanalysis/AnalyzePoint.kt @@ -11,7 +11,6 @@ import inr.numass.data.api.NumassPoint import inr.numass.data.api.NumassSet import inr.numass.data.api.SimpleNumassPoint import inr.numass.data.storage.NumassStorageFactory -import java.util.stream.Collectors fun main(args: Array) { @@ -52,7 +51,7 @@ fun main(args: Array) { SimpleNumassPoint( all.points.filter { it.voltage == hv - }.collect(Collectors.toList()), + }.toList(), hv ) ) diff --git a/numass-main/src/main/kotlin/inr/numass/scripts/tristan/AnalyzeTristan.kt b/numass-main/src/main/kotlin/inr/numass/scripts/tristan/AnalyzeTristan.kt index 6d35c302..d6af2ecc 100644 --- a/numass-main/src/main/kotlin/inr/numass/scripts/tristan/AnalyzeTristan.kt +++ b/numass-main/src/main/kotlin/inr/numass/scripts/tristan/AnalyzeTristan.kt @@ -11,14 +11,14 @@ fun main(args: Array) { val point = ProtoNumassPoint.readFile(file) point.plotAmplitudeSpectrum() - point.blocks.filter { it.channel == 0 }.findFirst().ifPresent { + point.blocks.filter { it.channel == 0 }.firstOrNull()?.let { it.plotAmplitudeSpectrum(plotName = "0") { "title" to "pixel 0" "binning" to 50 } } - point.blocks.filter { it.channel == 4 }.findFirst().ifPresent { + point.blocks.filter { it.channel == 4 }.firstOrNull()?.let { it.plotAmplitudeSpectrum(plotName = "4") { "title" to "pixel 4" "binning" to 50 diff --git a/numass-main/src/main/kotlin/inr/numass/scripts/tristan/ProtoPoint.kt b/numass-main/src/main/kotlin/inr/numass/scripts/tristan/ProtoPoint.kt index 4ab0370f..2e546418 100644 --- a/numass-main/src/main/kotlin/inr/numass/scripts/tristan/ProtoPoint.kt +++ b/numass-main/src/main/kotlin/inr/numass/scripts/tristan/ProtoPoint.kt @@ -35,7 +35,7 @@ fun main(args: Array) { } } - val point: NumassPoint = set.points.filter { it.index == 18 }.findFirst().get() + val point: NumassPoint = set.points.first { it.index == 18 } (0..99).forEach { bin -> val times = point.events.filter { it.amp > 0 }.map { it.timeOffset }.toList() val count = times.filter { it > bin.toDouble() / 10 * 1e9 && it < (bin + 1).toDouble() / 10 * 1e9 }.count() diff --git a/numass-main/src/main/kotlin/inr/numass/subthreshold/Threshold.kt b/numass-main/src/main/kotlin/inr/numass/subthreshold/Threshold.kt index 30464556..7c5178b8 100644 --- a/numass-main/src/main/kotlin/inr/numass/subthreshold/Threshold.kt +++ b/numass-main/src/main/kotlin/inr/numass/subthreshold/Threshold.kt @@ -97,7 +97,7 @@ object Threshold { private fun norm(spectrum: Table, xLow: Int, upper: Int): Double { return spectrum.rows.filter { row -> row.getInt(CHANNEL_KEY) in (xLow + 1)..(upper - 1) - }.mapToDouble { it.getValue(COUNT_RATE_KEY).getDouble() }.sum() + }.mapToDouble { it.getValue(COUNT_RATE_KEY).double }.sum() } private val expPointNames = arrayOf("U", "amp", "expConst", "correction"); 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 3c28406a..33bdd272 100644 --- a/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanSummaryTask.kt +++ b/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanSummaryTask.kt @@ -60,7 +60,7 @@ object NumassFitScanSummaryTask : AbstractTask() { } builder.row( - Math.sqrt(pars.getValue("msterile2").getDouble()), + Math.sqrt(pars.getValue("msterile2").double), pars.getValue("U2"), pars.getError("U2"), limit, diff --git a/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanTask.kt b/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanTask.kt index 77af7a4e..0d252fc5 100644 --- a/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanTask.kt +++ b/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanTask.kt @@ -14,9 +14,9 @@ import hep.dataforge.stat.fit.FitResult import hep.dataforge.tables.Table import hep.dataforge.values.ListValue import hep.dataforge.values.Value +import hep.dataforge.values.asValue import hep.dataforge.workspace.tasks.AbstractTask import hep.dataforge.workspace.tasks.TaskModel -import java.util.stream.Collectors /** * @author Alexander Nozik @@ -30,12 +30,11 @@ object NumassFitScanTask : AbstractTask() { val scanValues: Value = if (config.hasValue("masses")) { ListValue(config.getValue("masses") - .list.stream() - .map { it -> Math.pow(it.double * 1000, 2.0) } - .collect(Collectors.toList()) + .list + .map { it -> Math.pow(it.double * 1000, 2.0).asValue() } ) } else { - config.getValue("hep/dataforge/values", Value.parseValue("[2.5e5, 1e6, 2.25e6, 4e6, 6.25e6, 9e6]")) + config.getValue("hep/dataforge/values", listOf(2.5e5, 1e6, 2.25e6, 4e6, 6.25e6, 9e6)) } val action = FitAction() 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 cd0a9010..06441630 100644 --- a/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt +++ b/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt @@ -64,7 +64,7 @@ val monitorTableTask = task("monitor") { val res = ListTable.Builder("timestamp", "count", "cr", "crErr") .rows( data.values.stream().parallel() - .flatMap { it.points } + .flatMap { it.points.stream() } .filter { it.voltage == monitorVoltage } .map { it -> analyzer.analyzePoint(it, analyzerMeta) } ).build() @@ -259,7 +259,7 @@ val plotFitTask = task("plotFit") { // ensuring all data points are calculated explicitly StreamSupport.stream(data.spliterator(), false) - .map { dp -> Adapters.getXValue(adapter, dp).getDouble() }.sorted().forEach { fit.calculateIn(it) } + .map { dp -> Adapters.getXValue(adapter, dp).double }.sorted().forEach { fit.calculateIn(it) } frame.add(DataPlot.plot("data", adapter, data)) diff --git a/numass-server/src/main/java/inr/numass/server/NumassRootHandler.java b/numass-server/src/main/java/inr/numass/server/NumassRootHandler.java index b7991305..010ec153 100644 --- a/numass-server/src/main/java/inr/numass/server/NumassRootHandler.java +++ b/numass-server/src/main/java/inr/numass/server/NumassRootHandler.java @@ -6,6 +6,7 @@ package inr.numass.server; import freemarker.template.Template; +import hep.dataforge.io.JSONMetaWriter; import hep.dataforge.server.ServerManager; import hep.dataforge.server.ServletUtils; import hep.dataforge.storage.api.Loader; @@ -27,7 +28,7 @@ import static inr.numass.server.HandlerUtils.renderStates; @SuppressWarnings("unchecked") public class NumassRootHandler implements Handler { - private final JSONMetaWriter writer = new JSONMetaWriter(); + private final JSONMetaWriter writer = JSONMetaWriter.INSTANCE; NumassServer server; ServerManager manager; diff --git a/numass-server/src/main/java/inr/numass/server/NumassRun.java b/numass-server/src/main/java/inr/numass/server/NumassRun.java index 45e485f4..43c767cd 100644 --- a/numass-server/src/main/java/inr/numass/server/NumassRun.java +++ b/numass-server/src/main/java/inr/numass/server/NumassRun.java @@ -26,6 +26,7 @@ import hep.dataforge.storage.api.StateLoader; import hep.dataforge.storage.api.Storage; import hep.dataforge.storage.commons.LoaderFactory; import hep.dataforge.values.Value; +import hep.dataforge.values.ValueFactory; import inr.numass.data.storage.NumassStorage; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -86,7 +87,7 @@ public class NumassRun implements Metoid, Responder { } public void setState(String name, Object value) throws StorageException { - states.push(name, Value.of(value)); + states.push(name, ValueFactory.of(value)); } public boolean hasState(String name) { diff --git a/numass-test/src/main/groovy/inr/numass/scripts/TestClient.groovy b/numass-test/src/main/groovy/inr/numass/scripts/TestClient.groovy index 0bec4e33..f867fd6e 100644 --- a/numass-test/src/main/groovy/inr/numass/scripts/TestClient.groovy +++ b/numass-test/src/main/groovy/inr/numass/scripts/TestClient.groovy @@ -15,13 +15,11 @@ */ package inr.numass.scripts -import hep.dataforge.io.MetaStreamWriter import hep.dataforge.storage.commons.StorageManager new StorageManager().startGlobal(); -MetaStreamWriter parser = new JSONMetaWriter(); - + println "Starting Numass test client..." String line = ""; diff --git a/numass-test/src/main/groovy/inr/numass/scripts/TestFileTransfer.groovy b/numass-test/src/main/groovy/inr/numass/scripts/TestFileTransfer.groovy index 15560341..a3a51f1f 100644 --- a/numass-test/src/main/groovy/inr/numass/scripts/TestFileTransfer.groovy +++ b/numass-test/src/main/groovy/inr/numass/scripts/TestFileTransfer.groovy @@ -6,6 +6,7 @@ package inr.numass.scripts +import hep.dataforge.io.JSONMetaWriter import hep.dataforge.io.MetaStreamWriter import hep.dataforge.meta.Meta import hep.dataforge.storage.commons.StorageManager @@ -15,21 +16,21 @@ new StorageManager().startGlobal(); new NumassClient("127.0.0.1",8335).withCloseable{ - MetaStreamWriter parser = new JSONMetaWriter(); + MetaStreamWriter writer = JSONMetaWriter.INSTANCE Meta startRun = it.startRun("test") - println parser.writeString(startRun); + println writer.writeString(startRun); Meta run = it.getCurrentRun(); - println parser.writeString(run); + println writer.writeString(run); Meta response = it.sendNumassData("C:\\Users\\darksnake\\Dropbox\\PlayGround\\data-test\\zip\\20150703143643_1.nm.zip"); - println parser.writeString(response); + println writer.writeString(response); response = it.sendNumassData("C:\\Users\\darksnake\\Dropbox\\PlayGround\\data-test\\20150703144707_2"); - println parser.writeString(response); + println writer.writeString(response); } \ No newline at end of file diff --git a/numass-test/src/main/groovy/inr/numass/scripts/TestNotes.groovy b/numass-test/src/main/groovy/inr/numass/scripts/TestNotes.groovy index 1d50a9ec..5d436346 100644 --- a/numass-test/src/main/groovy/inr/numass/scripts/TestNotes.groovy +++ b/numass-test/src/main/groovy/inr/numass/scripts/TestNotes.groovy @@ -6,12 +6,9 @@ package inr.numass.scripts -import hep.dataforge.io.MetaStreamWriter import hep.dataforge.storage.commons.StorageManager import inr.numass.client.NumassClient new StorageManager().startGlobal(); -MetaStreamWriter parser = new JSONMetaWriter(); - NumassClient.runComand("127.0.0.1", 8336, "addNote", "This is my note with html"); diff --git a/numass-test/src/main/groovy/inr/numass/scripts/TestRemoteClient.groovy b/numass-test/src/main/groovy/inr/numass/scripts/TestRemoteClient.groovy index f7014221..85301b99 100644 --- a/numass-test/src/main/groovy/inr/numass/scripts/TestRemoteClient.groovy +++ b/numass-test/src/main/groovy/inr/numass/scripts/TestRemoteClient.groovy @@ -15,15 +15,11 @@ */ package inr.numass.scripts -import hep.dataforge.io.MetaStreamWriter import hep.dataforge.storage.commons.StorageManager import inr.numass.client.NumassClient new StorageManager().startGlobal(); - - -MetaStreamWriter parser = new JSONMetaWriter(); println "Starting Numass test client..." diff --git a/numass-test/src/main/groovy/inr/numass/scripts/TestStateChange.groovy b/numass-test/src/main/groovy/inr/numass/scripts/TestStateChange.groovy index 09257c5f..109e5039 100644 --- a/numass-test/src/main/groovy/inr/numass/scripts/TestStateChange.groovy +++ b/numass-test/src/main/groovy/inr/numass/scripts/TestStateChange.groovy @@ -6,6 +6,7 @@ package inr.numass.scripts +import hep.dataforge.io.JSONMetaWriter import hep.dataforge.io.MetaStreamWriter import hep.dataforge.meta.Meta import hep.dataforge.storage.commons.StorageManager @@ -15,15 +16,15 @@ new StorageManager().startGlobal(); new NumassClient("127.0.0.1",8335).withCloseable{ - MetaStreamWriter parser = new JSONMetaWriter(); + MetaStreamWriter writer = JSONMetaWriter.INSTANCE Meta startRun = it.startRun("test") - println parser.writeString(startRun); + println writer.writeString(startRun); Meta set1 = it.setState("myState", 112); - println parser.writeString(set1); + println writer.writeString(set1); Meta set2 = it.setState("otherState.property", ["a", "b", "c"]) diff --git a/numass-test/src/main/groovy/inr/numass/scripts/TestStorageAccess.groovy b/numass-test/src/main/groovy/inr/numass/scripts/TestStorageAccess.groovy index 503f9560..3454fcdc 100644 --- a/numass-test/src/main/groovy/inr/numass/scripts/TestStorageAccess.groovy +++ b/numass-test/src/main/groovy/inr/numass/scripts/TestStorageAccess.groovy @@ -6,6 +6,7 @@ package inr.numass.scripts +import hep.dataforge.io.JSONMetaWriter import hep.dataforge.io.MetaStreamWriter import hep.dataforge.io.envelopes.Envelope import hep.dataforge.meta.Meta @@ -19,11 +20,11 @@ new StorageManager().startGlobal(); new NumassClient("127.0.0.1",8335).withCloseable{ - MetaStreamWriter parser = new JSONMetaWriter(); + MetaStreamWriter writer = JSONMetaWriter.INSTANCE Meta startRun = it.startRun("test") - println parser.writeString(startRun); + println writer.writeString(startRun); MetaBuilder target = new MetaBuilder("target") @@ -50,6 +51,6 @@ new NumassClient("127.0.0.1",8335).withCloseable{ def response = it.respond(bin); - println parser.writeString(response.getMeta()); + println writer.writeString(response.getMeta()); } \ No newline at end of file diff --git a/numass-web/src/main/kotlin/inr/numass/server/Interceptors.kt b/numass-web/src/main/kotlin/inr/numass/server/Interceptors.kt index 5a38f541..673d39c6 100644 --- a/numass-web/src/main/kotlin/inr/numass/server/Interceptors.kt +++ b/numass-web/src/main/kotlin/inr/numass/server/Interceptors.kt @@ -1,11 +1,13 @@ package inr.numass.server import hep.dataforge.control.DeviceManager +import hep.dataforge.io.JSONMetaWriter +import hep.dataforge.kodex.KMetaBuilder +import hep.dataforge.kodex.buildMeta +import hep.dataforge.meta.Meta import hep.dataforge.providers.Path import hep.dataforge.server.InterceptorFactory import hep.dataforge.server.ServerInterceptor -import hep.dataforge.server.asJson -import hep.dataforge.server.jsonObject import hep.dataforge.storage.api.TableLoader import hep.dataforge.storage.commons.StorageManager import hep.dataforge.values.Value @@ -16,19 +18,26 @@ import io.ktor.response.respondText import io.ktor.routing.get +private fun Meta.render() = JSONMetaWriter.writeString(this) + private suspend fun ApplicationCall.error(type: String, message: String) { this.respondText(ContentType("application", "json")) { - jsonObject { - add("status", "ERROR") - add("type", type) - add("message", message) + buildMeta { + "status" to "ERROR" + "type" to type + "message" to message }.render() } } -private suspend fun ApplicationCall.json(json: suspend JsonObjectBuilder.() -> Unit) { +private suspend fun ApplicationCall.json(json: suspend KMetaBuilder.() -> Unit) { this.respondText(ContentType("application", "json")) { - jsonObject(json).add("status", "OK").render() + buildMeta { + run { + json.invoke(this) + } + "status" to "OK" + }.render() } } @@ -92,7 +101,7 @@ val deviceInterceptor = InterceptorFactory { context, meta -> get("listDevices") { call.json { val devices = jsonArray(); - for (name in deviceManager.getDeviceNames()) { + for (name in deviceManager.deviceNames) { val device = deviceManager.optDevice(name).get(); devices.add(jsonObject { add("name", name.toUnescaped()) @@ -116,7 +125,7 @@ val deviceInterceptor = InterceptorFactory { context, meta -> add("getMeta", device.meta.asJson()) add("state", jsonObject { device.states.forEach { - add(it.name,it.toString()) + add(it.name, it.toString()) } }) } diff --git a/settings.gradle b/settings.gradle index 2c054f6b..1d5c50b2 100644 --- a/settings.gradle +++ b/settings.gradle @@ -14,7 +14,7 @@ include ":numass-core" include ":numass-client" include ":numass-server" include ":numass-server" -include ":numass-web" +//include ":numass-web" include ":numass-test" // include ":numass-viewer"