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 768bf212..b17c919e 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 @@ -180,6 +180,9 @@ class DanteClient(val ip: String, chainLength: Int) : AutoCloseable { val board = header[1] val packet = header[2] val length = (header[3].positive * 0x100 + header[4].positive * 0x010 + header[5].positive) * 4 + if (length > 8) { + logger.trace("Received long message with header $header") + } val payload = ByteArray(length) DataInputStream(stream).readFully(payload) handle(DanteMessage(command, board.positive, packet.positive, payload)) diff --git a/numass-core/src/main/kotlin/inr/numass/data/NumassDataUtils.kt b/numass-core/src/main/kotlin/inr/numass/data/NumassDataUtils.kt index 5d5ec0e4..066ef189 100644 --- a/numass-core/src/main/kotlin/inr/numass/data/NumassDataUtils.kt +++ b/numass-core/src/main/kotlin/inr/numass/data/NumassDataUtils.kt @@ -23,7 +23,7 @@ object NumassDataUtils { override val points: Stream by lazy { val points = sets.stream().flatMap { it.points } .collect(Collectors.groupingBy { it.voltage }) - points.entries.stream().map { entry -> SimpleNumassPoint(entry.key, entry.value) } + points.entries.stream().map { entry -> SimpleNumassPoint(entry.value, entry.key) } } override val meta: Meta by lazy { diff --git a/numass-core/src/main/kotlin/inr/numass/data/analyzers/TimeAnalyzer.kt b/numass-core/src/main/kotlin/inr/numass/data/analyzers/TimeAnalyzer.kt index 42fbdc26..7de5e732 100644 --- a/numass-core/src/main/kotlin/inr/numass/data/analyzers/TimeAnalyzer.kt +++ b/numass-core/src/main/kotlin/inr/numass/data/analyzers/TimeAnalyzer.kt @@ -83,7 +83,7 @@ class TimeAnalyzer @JvmOverloads constructor(private val processor: SignalProces override fun analyzePoint(point: NumassPoint, config: Meta): Values { //Average count rates, do not sum events - val res = point.blocks + val res = point.blocks.stream() .map { it -> analyze(it, config) } .reduce(null) { v1, v2 -> this.combineBlockResults(v1, v2) } diff --git a/numass-core/src/main/kotlin/inr/numass/data/api/NumassPoint.kt b/numass-core/src/main/kotlin/inr/numass/data/api/NumassPoint.kt index b8e9e862..1426f042 100644 --- a/numass-core/src/main/kotlin/inr/numass/data/api/NumassPoint.kt +++ b/numass-core/src/main/kotlin/inr/numass/data/api/NumassPoint.kt @@ -15,7 +15,7 @@ import java.util.stream.Stream interface NumassPoint : Metoid, NumassBlock { - val blocks: Stream + val blocks: List /** * Get the voltage setting for the point @@ -38,7 +38,7 @@ interface NumassPoint : Metoid, NumassBlock { * @return */ val firstBlock: NumassBlock - get() = blocks.findFirst().orElseThrow { RuntimeException("The point is empty") } + get() = blocks.firstOrNull() ?: throw RuntimeException("The point is empty") /** * Get the starting time from meta or from first block @@ -54,7 +54,7 @@ interface NumassPoint : Metoid, NumassBlock { * @return */ override val length: Duration - get() = Duration.ofNanos(blocks.filter{it.channel == 0}.mapToLong { it -> it.length.toNanos() }.sum()) + get() = Duration.ofNanos(blocks.stream().filter { it.channel == 0 }.mapToLong { it -> it.length.toNanos() }.sum()) /** * Get all events it all blocks as a single sequence @@ -66,7 +66,7 @@ interface NumassPoint : Metoid, NumassBlock { * @return */ override val events: Stream - get() = blocks.flatMap { it.events } + get() = blocks.stream().flatMap { it.events } /** * Get all frames in all blocks as a single sequence @@ -74,7 +74,7 @@ interface NumassPoint : Metoid, NumassBlock { * @return */ override val frames: Stream - get() = blocks.flatMap { it.frames } + get() = blocks.stream().flatMap { it.frames } companion object { diff --git a/numass-core/src/main/kotlin/inr/numass/data/api/SimpleNumassPoint.kt b/numass-core/src/main/kotlin/inr/numass/data/api/SimpleNumassPoint.kt index c1f36f96..4449f642 100644 --- a/numass-core/src/main/kotlin/inr/numass/data/api/SimpleNumassPoint.kt +++ b/numass-core/src/main/kotlin/inr/numass/data/api/SimpleNumassPoint.kt @@ -4,28 +4,18 @@ import hep.dataforge.meta.Meta import hep.dataforge.meta.MetaBuilder import hep.dataforge.meta.MetaHolder -import java.util.stream.Stream - /** * A simple static implementation of NumassPoint * Created by darksnake on 08.07.2017. */ -class SimpleNumassPoint : MetaHolder, NumassPoint { - private val blockList: List +class SimpleNumassPoint(override val blocks: List, meta: Meta) : MetaHolder(meta), NumassPoint { /** * Input blocks must be sorted * @param voltage * @param blocks */ - constructor(voltage: Double, blocks: Collection) : super(MetaBuilder("point").setValue(NumassPoint.HV_KEY, voltage)) { - this.blockList = blocks.sortedBy { it.startTime } - } + constructor(blocks: Collection, voltage: Double) : + this(blocks.sortedBy { it.startTime }, MetaBuilder("point").setValue(NumassPoint.HV_KEY, voltage)) - constructor(meta: Meta, blocks: Collection) : super(meta) { - this.blockList = blocks.sortedBy { it.startTime } - } - - override val blocks: Stream - get() = blockList.stream() } diff --git a/numass-core/src/main/kotlin/inr/numass/data/legacy/NumassDatFile.kt b/numass-core/src/main/kotlin/inr/numass/data/legacy/NumassDatFile.kt index c112006c..6f59b9cc 100644 --- a/numass-core/src/main/kotlin/inr/numass/data/legacy/NumassDatFile.kt +++ b/numass-core/src/main/kotlin/inr/numass/data/legacy/NumassDatFile.kt @@ -168,7 +168,7 @@ constructor(override val name: String, private val path: Path, meta: Meta) : Num .setValue("source", "legacy") - return SimpleNumassPoint(pointMeta, listOf(block)) + return SimpleNumassPoint(listOf(block), pointMeta) } @Throws(IOException::class) diff --git a/numass-core/src/main/kotlin/inr/numass/data/storage/ClassicNumassPoint.kt b/numass-core/src/main/kotlin/inr/numass/data/storage/ClassicNumassPoint.kt index 974bdc6a..07ff693b 100644 --- a/numass-core/src/main/kotlin/inr/numass/data/storage/ClassicNumassPoint.kt +++ b/numass-core/src/main/kotlin/inr/numass/data/storage/ClassicNumassPoint.kt @@ -28,15 +28,14 @@ class ClassicNumassPoint(private val envelope: Envelope) : NumassPoint { override val index: Int = meta.getInt("external_meta.point_index", super.index) - override val blocks: Stream - get() { - val length: Long = if (envelope.meta.hasValue("external_meta.acquisition_time")) { - envelope.meta.getValue("external_meta.acquisition_time").getLong() - } else { - envelope.meta.getValue("acquisition_time").getLong() - } - return Stream.of(ClassicBlock(startTime, Duration.ofSeconds(length))) + override val blocks: List by lazy { + val length: Long = if (envelope.meta.hasValue("external_meta.acquisition_time")) { + envelope.meta.getValue("external_meta.acquisition_time").long + } else { + envelope.meta.getValue("acquisition_time").long } + listOf(ClassicBlock(startTime, Duration.ofSeconds(length))) + } override val startTime: Instant get() = if (meta.hasValue("start_time")) { diff --git a/numass-core/src/main/kotlin/inr/numass/data/storage/ProtoNumassPoint.kt b/numass-core/src/main/kotlin/inr/numass/data/storage/ProtoNumassPoint.kt index f8ab6baa..7e3741ee 100644 --- a/numass-core/src/main/kotlin/inr/numass/data/storage/ProtoNumassPoint.kt +++ b/numass-core/src/main/kotlin/inr/numass/data/storage/ProtoNumassPoint.kt @@ -28,13 +28,14 @@ class ProtoNumassPoint(override val meta: Meta, protoBuilder: () -> NumassProto. val proto: NumassProto.Point by lazy(protoBuilder) - override val blocks: Stream - get() = proto.channelsList.stream() + override val blocks: List by lazy { + proto.channelsList.stream() .flatMap { channel -> channel.blocksList.stream() .map { block -> ProtoBlock(channel.id.toInt(), block, this) } .sorted(Comparator.comparing { it.startTime }) - } + }.toList() + } override val voltage: Double = meta.getDouble("external_meta.HV1_value", super.voltage) @@ -42,7 +43,7 @@ class ProtoNumassPoint(override val meta: Meta, protoBuilder: () -> NumassProto. override val startTime: Instant get() = if (meta.hasValue("start_time")) { - meta.getValue("start_time").getTime() + meta.getValue("start_time").time } else { super.startTime } 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 1f95f56c..a106310f 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,7 +12,6 @@ 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 /** @@ -49,7 +48,7 @@ new GrindShell(ctx).eval { def builder = DataSet.builder(NumassPoint) hvs.each { hv -> - builder.putStatic("point_${hv as int}", new SimpleNumassPoint(hv, all.points.filter { + builder.putStatic("point_${hv as int}", new inr.numass.data.api.SimpleNumassPoint.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 aaff507a..1caadc4d 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,7 +8,6 @@ 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 @@ -36,7 +35,7 @@ new GrindShell(ctx).eval { GeneratorKt.generateBlock(Instant.now().plusNanos(it * length), length, chain) } - def point = new SimpleNumassPoint(10000, blocks) + def point = new inr.numass.data.api.SimpleNumassPoint.SimpleNumassPoint(10000, blocks) def meta = Meta.empty()//Grind.buildMeta(plotHist: false) diff --git a/numass-main/src/main/kotlin/inr/numass/scripts/Bunches.kt b/numass-main/src/main/kotlin/inr/numass/scripts/Bunches.kt index e4df94f3..1ccedf95 100644 --- a/numass-main/src/main/kotlin/inr/numass/scripts/Bunches.kt +++ b/numass-main/src/main/kotlin/inr/numass/scripts/Bunches.kt @@ -26,7 +26,7 @@ fun main(args: Array) { generateBlock(Instant.now().plusNanos(it * length), length, generator) } - val point = SimpleNumassPoint(10000.0, blocks) + val point = SimpleNumassPoint(blocks, 10000.0) val meta = buildMeta { "t0" to 1e7 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 71b83e27..7fa73f24 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 @@ -50,10 +50,10 @@ fun main(args: Array) { putStatic( "point_${hv.toInt()}", SimpleNumassPoint( - hv, all.points.filter { it.voltage == hv - }.collect(Collectors.toList()) + }.collect(Collectors.toList()), + hv ) ) } 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 e4790b66..0062973c 100644 --- a/numass-main/src/main/kotlin/inr/numass/subthreshold/Threshold.kt +++ b/numass-main/src/main/kotlin/inr/numass/subthreshold/Threshold.kt @@ -51,7 +51,7 @@ object Threshold { .flatMap { set -> set.points.toList() } .groupBy { it.voltage } .forEach { key, value -> - val point = SimpleNumassPoint(key, value) + val point = SimpleNumassPoint(value, key) val name = key.toInt().toString() dataBuilder.putStatic(name, point, buildMeta("meta", "voltage" to key)); }