diff --git a/build.gradle b/build.gradle index 076e1a70..c8728c37 100644 --- a/build.gradle +++ b/build.gradle @@ -1,9 +1,9 @@ buildscript { - ext.kotlin_version = "1.2.31" + ext.kotlin_version = "1.2.40" repositories { jcenter() maven { - url "https://dl.bintray.com/kotlin/kotlin-eap" + url = "https://dl.bintray.com/kotlin/kotlin-eap" } } @@ -12,7 +12,7 @@ buildscript { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } -allprojects{ +allprojects { apply plugin: 'idea' apply plugin: 'java' apply plugin: "kotlin" @@ -25,12 +25,12 @@ allprojects{ repositories { jcenter() mavenCentral() - //maven { url "https://jitpack.io" } - maven { url "http://dl.bintray.com/kotlin/ktor" } - maven { url "https://dl.bintray.com/kotlin/kotlinx" } + maven { url = "https://jitpack.io" } + maven { url = "http://dl.bintray.com/kotlin/ktor" } + maven { url = "https://dl.bintray.com/kotlin/kotlinx" } } - dependencies{ + dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" testCompile group: 'junit', name: 'junit', version: '4.+' @@ -45,7 +45,7 @@ allprojects{ } } - compileTestKotlin{ + compileTestKotlin { kotlinOptions { jvmTarget = "1.8" javaParameters = true 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 22fc89fd..998d6fc3 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 @@ -102,7 +102,7 @@ class DanteClient(val ip: String, chainLength: Int) : AutoCloseable { */ private data class BoardState(val num: Int, var meta: Meta? = null) - private val boards = (0..chainLength).map { BoardState(it) } + private val boards = (0 until chainLength).map { BoardState(it) } fun open() { diff --git a/numass-control/dante/src/main/kotlin/inr/numass/control/dante/DanteTest.kt b/numass-control/dante/src/main/kotlin/inr/numass/control/dante/DanteTest.kt index 32507db5..bb5592ca 100644 --- a/numass-control/dante/src/main/kotlin/inr/numass/control/dante/DanteTest.kt +++ b/numass-control/dante/src/main/kotlin/inr/numass/control/dante/DanteTest.kt @@ -33,7 +33,7 @@ import inr.numass.data.channel import kotlinx.coroutines.experimental.runBlocking fun main(args: Array) { - val client = DanteClient("192.168.111.120", 7) + val client = DanteClient("192.168.111.120", 8) client.open() val meta = buildMeta { "gain" to 1.0 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 06a461b5..5d5ec0e4 100644 --- a/numass-core/src/main/kotlin/inr/numass/data/NumassDataUtils.kt +++ b/numass-core/src/main/kotlin/inr/numass/data/NumassDataUtils.kt @@ -1,7 +1,6 @@ package inr.numass.data import hep.dataforge.io.envelopes.Envelope -import hep.dataforge.kodex.nullable import hep.dataforge.meta.Meta import hep.dataforge.meta.MetaBuilder import inr.numass.data.api.* @@ -63,16 +62,16 @@ val Envelope.dataStream: InputStream this.data.stream } -val NumassBlock.channel: Int? +val NumassBlock.channel: Int get() = if (this is ProtoBlock) { this.channel } else { - this.meta.optValue("channel").map { it.getInt() }.nullable + 0 } fun NumassBlock.transformChain(transform: (NumassEvent, NumassEvent) -> Pair?): NumassBlock { - return SimpleBlock(this.startTime, this.length, this.meta) { owner -> + return SimpleBlock(this.startTime, this.length) { owner -> this.events.asSequence() .sortedBy { it.timeOffset } .zipWithNext(transform) @@ -82,7 +81,7 @@ fun NumassBlock.transformChain(transform: (NumassEvent, NumassEvent) -> Pair Boolean): NumassBlock { - return SimpleBlock(this.startTime, this.length, this.meta) { owner -> + return SimpleBlock(this.startTime, this.length) { owner -> this.events.asSequence() .sortedBy { it.timeOffset } .zipWithNext().filter { condition.invoke(it.first, it.second) }.map { it.second }.asIterable() @@ -90,13 +89,13 @@ fun NumassBlock.filterChain(condition: (NumassEvent, NumassEvent) -> Boolean): N } fun NumassBlock.filter(condition: (NumassEvent) -> Boolean): NumassBlock { - return SimpleBlock(this.startTime, this.length, this.meta) { owner -> + return SimpleBlock(this.startTime, this.length) { owner -> this.events.asSequence().filter(condition).asIterable() } } fun NumassBlock.transform(transform: (NumassEvent) -> OrphanNumassEvent): NumassBlock { - return SimpleBlock(this.startTime, this.length, this.meta) { owner -> + return SimpleBlock(this.startTime, this.length) { owner -> this.events.asSequence() .map { transform(it).adopt(owner) } .asIterable() diff --git a/numass-core/src/main/kotlin/inr/numass/data/api/MetaBlock.kt b/numass-core/src/main/kotlin/inr/numass/data/api/MetaBlock.kt index fba2bd5a..36142bc5 100644 --- a/numass-core/src/main/kotlin/inr/numass/data/api/MetaBlock.kt +++ b/numass-core/src/main/kotlin/inr/numass/data/api/MetaBlock.kt @@ -1,6 +1,5 @@ package inr.numass.data.api -import hep.dataforge.meta.Meta import java.time.Duration import java.time.Instant import java.util.* @@ -10,7 +9,7 @@ import java.util.stream.Stream * A block constructed from a set of other blocks. Internal blocks are not necessary subsequent. Blocks are automatically sorted. * Created by darksnake on 16.07.2017. */ -class MetaBlock(blocks: Collection, override val meta: Meta = Meta.empty()) : NumassBlock { +class MetaBlock(blocks: Collection) : NumassBlock { private val blocks = TreeSet(Comparator.comparing{ it.startTime }) diff --git a/numass-core/src/main/kotlin/inr/numass/data/api/NumassBlock.kt b/numass-core/src/main/kotlin/inr/numass/data/api/NumassBlock.kt index 876bdda4..0cb5ea79 100644 --- a/numass-core/src/main/kotlin/inr/numass/data/api/NumassBlock.kt +++ b/numass-core/src/main/kotlin/inr/numass/data/api/NumassBlock.kt @@ -1,7 +1,5 @@ package inr.numass.data.api -import hep.dataforge.meta.Meta -import hep.dataforge.meta.Metoid import inr.numass.data.channel import kotlinx.coroutines.experimental.runBlocking import java.io.Serializable @@ -21,7 +19,7 @@ import java.util.stream.Stream */ class NumassEvent(val amp: Short, val timeOffset: Long, val owner: NumassBlock) : Serializable { - val channel: Int? + val channel: Int get() = owner.channel val time: Instant @@ -36,7 +34,7 @@ class NumassEvent(val amp: Short, val timeOffset: Long, val owner: NumassBlock) * * Created by darksnake on 06-Jul-17. */ -interface NumassBlock : Metoid { +interface NumassBlock { /** * The absolute start time of the block @@ -80,7 +78,6 @@ val OrphanNumassEvent.amp: Short class SimpleBlock( override val startTime: Instant, override val length: Duration, - override val meta: Meta = Meta.empty(), producer: suspend (NumassBlock) -> Iterable) : NumassBlock, Serializable { private val eventList = runBlocking { producer(this@SimpleBlock).toList()} 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 ca9260c1..b8e9e862 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 @@ -2,6 +2,7 @@ package inr.numass.data.api import hep.dataforge.io.envelopes.Envelope import hep.dataforge.meta.Metoid +import inr.numass.data.channel import inr.numass.data.storage.ClassicNumassPoint import inr.numass.data.storage.ProtoNumassPoint import java.time.Duration @@ -45,7 +46,7 @@ interface NumassPoint : Metoid, NumassBlock { * @return */ override val startTime: Instant - get() = meta.optValue(START_TIME_KEY).map { it.getTime() }.orElseGet { firstBlock.startTime } + get() = meta.optValue(START_TIME_KEY).map { it.time }.orElseGet { firstBlock.startTime } /** * Get the length key of meta or calculate length as a sum of block lengths. The latter could be a bit slow @@ -53,10 +54,7 @@ interface NumassPoint : Metoid, NumassBlock { * @return */ override val length: Duration - get() = Duration.ofNanos( - meta.optValue(LENGTH_KEY).map { it.getLong() } - .orElseGet { blocks.mapToLong { it -> it.length.toNanos() }.sum() } - ) + get() = Duration.ofNanos(blocks.filter{it.channel == 0}.mapToLong { it -> it.length.toNanos() }.sum()) /** * Get all events it all blocks as a single sequence 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 64176af4..974bdc6a 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 @@ -49,8 +49,7 @@ class ClassicNumassPoint(private val envelope: Envelope) : NumassPoint { //TODO split blocks using meta private inner class ClassicBlock( override val startTime: Instant, - override val length: Duration, - override val meta: Meta = Meta.empty()) : NumassBlock, Iterable { + override val length: Duration) : NumassBlock, Iterable { override val events: Stream get() = StreamSupport.stream(this.spliterator(), false) 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 ce14f825..f8ab6baa 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 @@ -3,9 +3,7 @@ package inr.numass.data.storage import hep.dataforge.context.Context import hep.dataforge.context.Global import hep.dataforge.io.envelopes.Envelope -import hep.dataforge.kodex.buildMeta import hep.dataforge.kodex.toList -import hep.dataforge.meta.Laminate import hep.dataforge.meta.Meta import inr.numass.data.NumassProto import inr.numass.data.api.NumassBlock @@ -26,7 +24,9 @@ import java.util.stream.Stream * Protobuf based numass point * Created by darksnake on 09.07.2017. */ -class ProtoNumassPoint(val proto: NumassProto.Point, override val meta: Meta) : NumassPoint { +class ProtoNumassPoint(override val meta: Meta, protoBuilder: () -> NumassProto.Point) : NumassPoint { + + val proto: NumassProto.Point by lazy(protoBuilder) override val blocks: Stream get() = proto.channelsList.stream() @@ -47,16 +47,25 @@ class ProtoNumassPoint(val proto: NumassProto.Point, override val meta: Meta) : super.startTime } + override val length: Duration + get() = if (meta.hasValue("acquisition_time")) { + Duration.ofMillis((meta.getDouble("acquisition_time") * 1000).toLong()) + } else { + super.length + } + + companion object { fun readFile(path: Path): ProtoNumassPoint { return fromEnvelope(NumassFileEnvelope.open(path, true)) } fun fromEnvelope(envelope: Envelope): ProtoNumassPoint { - val proto = envelope.dataStream.use { - NumassProto.Point.parseFrom(it) + return ProtoNumassPoint(envelope.meta){ + envelope.dataStream.use { + NumassProto.Point.parseFrom(it) + } } - return ProtoNumassPoint(proto, envelope.meta) } fun readFile(path: String, context: Context = Global): ProtoNumassPoint { @@ -71,20 +80,15 @@ class ProtoNumassPoint(val proto: NumassProto.Point, override val meta: Meta) : } } -class ProtoBlock(val channel: Int, private val block: NumassProto.Point.Channel.Block, parent: NumassBlock? = null) : NumassBlock { - override val meta: Meta by lazy { - val blockMeta = buildMeta { - "channel" to channel - } - return@lazy parent?.let { Laminate(blockMeta, parent.meta) } ?: blockMeta - } +class ProtoBlock(val channel: Int, private val block: NumassProto.Point.Channel.Block, val parent: NumassPoint? = null) : NumassBlock { override val startTime: Instant get() = ProtoNumassPoint.ofEpochNanos(block.time) override val length: Duration = when { block.length > 0 -> Duration.ofNanos(block.length) - meta.hasValue("acquisition_time") -> Duration.ofMillis((meta.getDouble("acquisition_time") * 1000).toLong()) + parent?.meta?.hasValue("acquisition_time") ?: false -> + Duration.ofMillis((parent!!.meta.getDouble("acquisition_time") * 1000).toLong()) else -> { LoggerFactory.getLogger(javaClass).error("No length information on block. Trying to infer from first and last events") val times = events.map { it.timeOffset }.toList() diff --git a/numass-viewer/src/main/kotlin/inr/numass/viewer/StorageView.kt b/numass-viewer/src/main/kotlin/inr/numass/viewer/StorageView.kt index 65ae050a..55807750 100644 --- a/numass-viewer/src/main/kotlin/inr/numass/viewer/StorageView.kt +++ b/numass-viewer/src/main/kotlin/inr/numass/viewer/StorageView.kt @@ -87,6 +87,17 @@ class StorageView(private val context: Context = Global) : View(title = "Numass } } + val children: List? by lazy { + when (content) { + is Storage -> (content.shelves().sorted() + content.loaders().sorted()).map { buildContainer(it, this) } + is NumassSet -> content.points.map { buildContainer(it, this) }.toList().sortedBy { it.id } + else -> null + } + } + + val hasChildren: Boolean + get() = (content is Storage) || (content is NumassPoint) + } override val root = borderpane { @@ -153,6 +164,15 @@ class StorageView(private val context: Context = Global) : View(title = "Numass } runLater { statusBar.progress = 0.0 } } + + /* + lazyPopulate( leafCheck = { it.value.hasChildren }) { + runLater { statusBar.progress = -1.0 } + it.value.children.also { + runLater { statusBar.progress = 0.0 } + } + } + */ } } cellFormat { value ->