Refactor visualization
Replace usage of Stream:toList because of glitches in scripting
This commit is contained in:
parent
b911790238
commit
ef670f8418
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,5 +5,6 @@ out/
|
||||
.gradle
|
||||
build/
|
||||
/notebooks/.ipynb_checkpoints
|
||||
/kotlin-js-store/
|
||||
|
||||
!gradle-wrapper.jar
|
@ -1,24 +1,25 @@
|
||||
plugins {
|
||||
id("ru.mipt.npm.gradle.project")
|
||||
id("space.kscience.gradle.project")
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
maven("https://repo.kotlin.link")
|
||||
maven("https://maven.pkg.jetbrains.space/spc/p/sci/dev")
|
||||
}
|
||||
|
||||
group = "ru.inr.mass"
|
||||
version = "0.1.3"
|
||||
}
|
||||
|
||||
val dataforgeVersion by extra("0.5.2")
|
||||
val tablesVersion: String by extra("0.1.5")
|
||||
val kmathVersion by extra("0.3.0")
|
||||
val plotlyVersion: String by extra("0.5.0")
|
||||
val dataforgeVersion by extra("0.6.0-dev-15")
|
||||
val tablesVersion: String by extra("0.2.0-dev-3")
|
||||
val kmathVersion by extra("0.3.1-dev-6")
|
||||
val visionForgeVersion: String by rootProject.extra("0.3.0-dev-4")
|
||||
|
||||
|
||||
ksciencePublish{
|
||||
github("numass")
|
||||
space("https://maven.pkg.jetbrains.space/mipt-npm/p/numass/maven")
|
||||
}
|
||||
|
||||
|
@ -12,4 +12,4 @@ org.gradle.configureondemand=true
|
||||
org.gradle.parallel=true
|
||||
org.gradle.jvmargs=-XX:MaxMetaspaceSize=1G
|
||||
|
||||
toolsVersion=0.11.2-kotlin-1.6.10
|
||||
toolsVersion=0.13.3-kotlin-1.7.20
|
||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -9,7 +9,7 @@
|
||||
"source": [
|
||||
"@file:Repository(\"https://repo.kotlin.link\")\n",
|
||||
"@file:Repository(\"*mavenLocal\")\n",
|
||||
"@file:DependsOn(\"ru.inr.mass:numass-workspace:0.1.1\")"
|
||||
"@file:DependsOn(\"ru.inr.mass:numass-workspace:0.1.3\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -1,6 +1,5 @@
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
id("ru.mipt.npm.gradle.common")
|
||||
id("space.kscience.gradle.mpp")
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
@ -22,8 +21,8 @@ kotlin.sourceSets {
|
||||
}
|
||||
}
|
||||
|
||||
kscience{
|
||||
useAtomic()
|
||||
}
|
||||
//kscience{
|
||||
// useAtomic()
|
||||
//}
|
||||
|
||||
|
||||
|
@ -23,10 +23,6 @@ import ru.inr.mass.data.api.NumassPoint.Companion.HV_KEY
|
||||
import space.kscience.dataforge.meta.*
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.asName
|
||||
import space.kscience.dataforge.values.ListValue
|
||||
import space.kscience.dataforge.values.Value
|
||||
import space.kscience.dataforge.values.ValueType
|
||||
import space.kscience.dataforge.values.int
|
||||
import space.kscience.tables.ColumnHeader
|
||||
import space.kscience.tables.MetaRow
|
||||
import space.kscience.tables.RowTable
|
||||
|
@ -31,7 +31,9 @@ import kotlin.math.*
|
||||
* An analyzer which uses time information from events
|
||||
* Created by darksnake on 11.07.2017.
|
||||
*/
|
||||
public open class TimeAnalyzer(override val extractor: NumassEventExtractor) : NumassAnalyzer() {
|
||||
public open class TimeAnalyzer(
|
||||
override val extractor: NumassEventExtractor = NumassEventExtractor.EVENTS_ONLY,
|
||||
) : NumassAnalyzer() {
|
||||
|
||||
override suspend fun analyzeInternal(
|
||||
block: NumassBlock,
|
||||
@ -76,7 +78,7 @@ public open class TimeAnalyzer(override val extractor: NumassEventExtractor) : N
|
||||
filter { pair -> pair.second >= t0 }.collect { pair ->
|
||||
totalN++
|
||||
//TODO add progress listener here
|
||||
totalT+= pair.second
|
||||
totalT += pair.second
|
||||
}
|
||||
|
||||
if (totalN == 0L) {
|
||||
@ -114,10 +116,12 @@ public open class TimeAnalyzer(override val extractor: NumassEventExtractor) : N
|
||||
sumOf { it.countRate } / size,
|
||||
sumOf { it.countRateError.pow(2.0) } / size / size
|
||||
)
|
||||
|
||||
AveragingMethod.WEIGHTED -> Pair(
|
||||
sumOf { it.countRate * it.length } / totalTime,
|
||||
sumOf { (it.countRateError * it.length / totalTime).pow(2.0) }
|
||||
)
|
||||
|
||||
AveragingMethod.GEOMETRIC -> {
|
||||
val mean = exp(sumOf { ln(it.countRate) } / size)
|
||||
val variance = (mean / size).pow(2.0) * sumOf {
|
||||
|
@ -1,6 +1,5 @@
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
id("ru.mipt.npm.gradle.common")
|
||||
id("space.kscience.gradle.mpp")
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
@ -12,7 +11,7 @@ kotlin.sourceSets {
|
||||
dependencies {
|
||||
api("space.kscience:dataforge-context:$dataforgeVersion")
|
||||
api("space.kscience:dataforge-data:$dataforgeVersion")
|
||||
api("org.jetbrains.kotlinx:kotlinx-datetime:${ru.mipt.npm.gradle.KScienceVersions.dateTimeVersion}")
|
||||
api("org.jetbrains.kotlinx:kotlinx-datetime:${space.kscience.gradle.KScienceVersions.dateTimeVersion}")
|
||||
}
|
||||
}
|
||||
jvmMain{
|
||||
|
@ -1,7 +1,6 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("ru.mipt.npm.gradle.common")
|
||||
id("com.squareup.wire") version "4.2.0"
|
||||
id("space.kscience.gradle.jvm")
|
||||
id("com.squareup.wire") version "4.4.1"
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
@ -12,6 +11,13 @@ dependencies {
|
||||
api("space.kscience:dataforge-io:$dataforgeVersion")
|
||||
}
|
||||
|
||||
wire{
|
||||
kotlin{}
|
||||
wire {
|
||||
kotlin {
|
||||
out = "src/gen/kotlin"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sourceSets.main {
|
||||
kotlin.srcDir("src/gen/kotlin")
|
||||
}
|
||||
|
659
numass-data-proto/src/gen/kotlin/ru/inr/mass/data/proto/Point.kt
Normal file
659
numass-data-proto/src/gen/kotlin/ru/inr/mass/data/proto/Point.kt
Normal file
@ -0,0 +1,659 @@
|
||||
// Code generated by Wire protocol buffer compiler, do not edit.
|
||||
// Source: ru.inr.mass.data.proto.Point in numass-proto.proto
|
||||
package ru.inr.mass.`data`.proto
|
||||
|
||||
import com.squareup.wire.*
|
||||
import com.squareup.wire.Syntax.PROTO_3
|
||||
import com.squareup.wire.internal.immutableCopyOf
|
||||
import com.squareup.wire.internal.redactElements
|
||||
import okio.ByteString
|
||||
|
||||
public class Point(
|
||||
channels: List<Channel> = emptyList(),
|
||||
unknownFields: ByteString = ByteString.EMPTY,
|
||||
) : Message<Point, Nothing>(ADAPTER, unknownFields) {
|
||||
/**
|
||||
* Array of measuring channels
|
||||
*/
|
||||
@field:WireField(
|
||||
tag = 1,
|
||||
adapter = "ru.inr.mass.data.proto.Point${'$'}Channel#ADAPTER",
|
||||
label = WireField.Label.REPEATED,
|
||||
)
|
||||
public val channels: List<Channel> = immutableCopyOf("channels", channels)
|
||||
|
||||
@Deprecated(
|
||||
message = "Shouldn't be used in Kotlin",
|
||||
level = DeprecationLevel.HIDDEN,
|
||||
)
|
||||
public override fun newBuilder(): Nothing = throw
|
||||
AssertionError("Builders are deprecated and only available in a javaInterop build; see https://square.github.io/wire/wire_compiler/#kotlin")
|
||||
|
||||
public override fun equals(other: Any?): Boolean {
|
||||
if (other === this) return true
|
||||
if (other !is Point) return false
|
||||
if (unknownFields != other.unknownFields) return false
|
||||
if (channels != other.channels) return false
|
||||
return true
|
||||
}
|
||||
|
||||
public override fun hashCode(): Int {
|
||||
var result = super.hashCode
|
||||
if (result == 0) {
|
||||
result = unknownFields.hashCode()
|
||||
result = result * 37 + channels.hashCode()
|
||||
super.hashCode = result
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
public override fun toString(): String {
|
||||
val result = mutableListOf<String>()
|
||||
if (channels.isNotEmpty()) result += """channels=$channels"""
|
||||
return result.joinToString(prefix = "Point{", separator = ", ", postfix = "}")
|
||||
}
|
||||
|
||||
public fun copy(channels: List<Channel> = this.channels, unknownFields: ByteString =
|
||||
this.unknownFields): Point = Point(channels, unknownFields)
|
||||
|
||||
public companion object {
|
||||
@JvmField
|
||||
public val ADAPTER: ProtoAdapter<Point> = object : ProtoAdapter<Point>(
|
||||
FieldEncoding.LENGTH_DELIMITED,
|
||||
Point::class,
|
||||
"type.googleapis.com/ru.inr.mass.data.proto.Point",
|
||||
PROTO_3,
|
||||
null,
|
||||
"numass-proto.proto"
|
||||
) {
|
||||
public override fun encodedSize(`value`: Point): Int {
|
||||
var size = value.unknownFields.size
|
||||
size += Channel.ADAPTER.asRepeated().encodedSizeWithTag(1, value.channels)
|
||||
return size
|
||||
}
|
||||
|
||||
public override fun encode(writer: ProtoWriter, `value`: Point): Unit {
|
||||
Channel.ADAPTER.asRepeated().encodeWithTag(writer, 1, value.channels)
|
||||
writer.writeBytes(value.unknownFields)
|
||||
}
|
||||
|
||||
public override fun encode(writer: ReverseProtoWriter, `value`: Point): Unit {
|
||||
writer.writeBytes(value.unknownFields)
|
||||
Channel.ADAPTER.asRepeated().encodeWithTag(writer, 1, value.channels)
|
||||
}
|
||||
|
||||
public override fun decode(reader: ProtoReader): Point {
|
||||
val channels = mutableListOf<Channel>()
|
||||
val unknownFields = reader.forEachTag { tag ->
|
||||
when (tag) {
|
||||
1 -> channels.add(Channel.ADAPTER.decode(reader))
|
||||
else -> reader.readUnknownField(tag)
|
||||
}
|
||||
}
|
||||
return Point(
|
||||
channels = channels,
|
||||
unknownFields = unknownFields
|
||||
)
|
||||
}
|
||||
|
||||
public override fun redact(`value`: Point): Point = value.copy(
|
||||
channels = value.channels.redactElements(Channel.ADAPTER),
|
||||
unknownFields = ByteString.EMPTY
|
||||
)
|
||||
}
|
||||
|
||||
private const val serialVersionUID: Long = 0L
|
||||
}
|
||||
|
||||
/**
|
||||
* A single channel for multichannel detector readout
|
||||
*/
|
||||
public class Channel(
|
||||
/**
|
||||
* The number of measuring channel
|
||||
*/
|
||||
@field:WireField(
|
||||
tag = 1,
|
||||
adapter = "com.squareup.wire.ProtoAdapter#UINT64",
|
||||
label = WireField.Label.OMIT_IDENTITY,
|
||||
)
|
||||
public val id: Long = 0L,
|
||||
blocks: List<Block> = emptyList(),
|
||||
unknownFields: ByteString = ByteString.EMPTY,
|
||||
) : Message<Channel, Nothing>(ADAPTER, unknownFields) {
|
||||
/**
|
||||
* Blocks
|
||||
*/
|
||||
@field:WireField(
|
||||
tag = 2,
|
||||
adapter = "ru.inr.mass.data.proto.Point${'$'}Channel${'$'}Block#ADAPTER",
|
||||
label = WireField.Label.REPEATED,
|
||||
)
|
||||
public val blocks: List<Block> = immutableCopyOf("blocks", blocks)
|
||||
|
||||
@Deprecated(
|
||||
message = "Shouldn't be used in Kotlin",
|
||||
level = DeprecationLevel.HIDDEN,
|
||||
)
|
||||
public override fun newBuilder(): Nothing = throw
|
||||
AssertionError("Builders are deprecated and only available in a javaInterop build; see https://square.github.io/wire/wire_compiler/#kotlin")
|
||||
|
||||
public override fun equals(other: Any?): Boolean {
|
||||
if (other === this) return true
|
||||
if (other !is Channel) return false
|
||||
if (unknownFields != other.unknownFields) return false
|
||||
if (id != other.id) return false
|
||||
if (blocks != other.blocks) return false
|
||||
return true
|
||||
}
|
||||
|
||||
public override fun hashCode(): Int {
|
||||
var result = super.hashCode
|
||||
if (result == 0) {
|
||||
result = unknownFields.hashCode()
|
||||
result = result * 37 + id.hashCode()
|
||||
result = result * 37 + blocks.hashCode()
|
||||
super.hashCode = result
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
public override fun toString(): String {
|
||||
val result = mutableListOf<String>()
|
||||
result += """id=$id"""
|
||||
if (blocks.isNotEmpty()) result += """blocks=$blocks"""
|
||||
return result.joinToString(prefix = "Channel{", separator = ", ", postfix = "}")
|
||||
}
|
||||
|
||||
public fun copy(
|
||||
id: Long = this.id,
|
||||
blocks: List<Block> = this.blocks,
|
||||
unknownFields: ByteString = this.unknownFields,
|
||||
): Channel = Channel(id, blocks, unknownFields)
|
||||
|
||||
public companion object {
|
||||
@JvmField
|
||||
public val ADAPTER: ProtoAdapter<Channel> = object : ProtoAdapter<Channel>(
|
||||
FieldEncoding.LENGTH_DELIMITED,
|
||||
Channel::class,
|
||||
"type.googleapis.com/ru.inr.mass.data.proto.Point.Channel",
|
||||
PROTO_3,
|
||||
null,
|
||||
"numass-proto.proto"
|
||||
) {
|
||||
public override fun encodedSize(`value`: Channel): Int {
|
||||
var size = value.unknownFields.size
|
||||
if (value.id != 0L) size += ProtoAdapter.UINT64.encodedSizeWithTag(1, value.id)
|
||||
size += Block.ADAPTER.asRepeated().encodedSizeWithTag(2, value.blocks)
|
||||
return size
|
||||
}
|
||||
|
||||
public override fun encode(writer: ProtoWriter, `value`: Channel): Unit {
|
||||
if (value.id != 0L) ProtoAdapter.UINT64.encodeWithTag(writer, 1, value.id)
|
||||
Block.ADAPTER.asRepeated().encodeWithTag(writer, 2, value.blocks)
|
||||
writer.writeBytes(value.unknownFields)
|
||||
}
|
||||
|
||||
public override fun encode(writer: ReverseProtoWriter, `value`: Channel): Unit {
|
||||
writer.writeBytes(value.unknownFields)
|
||||
Block.ADAPTER.asRepeated().encodeWithTag(writer, 2, value.blocks)
|
||||
if (value.id != 0L) ProtoAdapter.UINT64.encodeWithTag(writer, 1, value.id)
|
||||
}
|
||||
|
||||
public override fun decode(reader: ProtoReader): Channel {
|
||||
var id: Long = 0L
|
||||
val blocks = mutableListOf<Block>()
|
||||
val unknownFields = reader.forEachTag { tag ->
|
||||
when (tag) {
|
||||
1 -> id = ProtoAdapter.UINT64.decode(reader)
|
||||
2 -> blocks.add(Block.ADAPTER.decode(reader))
|
||||
else -> reader.readUnknownField(tag)
|
||||
}
|
||||
}
|
||||
return Channel(
|
||||
id = id,
|
||||
blocks = blocks,
|
||||
unknownFields = unknownFields
|
||||
)
|
||||
}
|
||||
|
||||
public override fun redact(`value`: Channel): Channel = value.copy(
|
||||
blocks = value.blocks.redactElements(Block.ADAPTER),
|
||||
unknownFields = ByteString.EMPTY
|
||||
)
|
||||
}
|
||||
|
||||
private const val serialVersionUID: Long = 0L
|
||||
}
|
||||
|
||||
/**
|
||||
* A continuous measurement block
|
||||
*/
|
||||
public class Block(
|
||||
/**
|
||||
* Block start in epoch nanos
|
||||
*/
|
||||
@field:WireField(
|
||||
tag = 1,
|
||||
adapter = "com.squareup.wire.ProtoAdapter#UINT64",
|
||||
label = WireField.Label.OMIT_IDENTITY,
|
||||
)
|
||||
public val time: Long = 0L,
|
||||
frames: List<Frame> = emptyList(),
|
||||
/**
|
||||
* Events array
|
||||
*/
|
||||
@field:WireField(
|
||||
tag = 3,
|
||||
adapter = "ru.inr.mass.data.proto.Point${'$'}Channel${'$'}Block${'$'}Events#ADAPTER",
|
||||
label = WireField.Label.OMIT_IDENTITY,
|
||||
)
|
||||
public val events: Events? = null,
|
||||
/**
|
||||
* block size in nanos. If missing, take from meta.
|
||||
*/
|
||||
@field:WireField(
|
||||
tag = 4,
|
||||
adapter = "com.squareup.wire.ProtoAdapter#UINT64",
|
||||
label = WireField.Label.OMIT_IDENTITY,
|
||||
)
|
||||
public val length: Long = 0L,
|
||||
/**
|
||||
* tick size in nanos. Obsolete, to be removed
|
||||
*/
|
||||
@field:WireField(
|
||||
tag = 5,
|
||||
adapter = "com.squareup.wire.ProtoAdapter#UINT64",
|
||||
label = WireField.Label.OMIT_IDENTITY,
|
||||
jsonName = "binSize",
|
||||
)
|
||||
public val bin_size: Long = 0L,
|
||||
unknownFields: ByteString = ByteString.EMPTY,
|
||||
) : Message<Block, Nothing>(ADAPTER, unknownFields) {
|
||||
/**
|
||||
* Frames array
|
||||
*/
|
||||
@field:WireField(
|
||||
tag = 2,
|
||||
adapter = "ru.inr.mass.data.proto.Point${'$'}Channel${'$'}Block${'$'}Frame#ADAPTER",
|
||||
label = WireField.Label.REPEATED,
|
||||
)
|
||||
public val frames: List<Frame> = immutableCopyOf("frames", frames)
|
||||
|
||||
@Deprecated(
|
||||
message = "Shouldn't be used in Kotlin",
|
||||
level = DeprecationLevel.HIDDEN,
|
||||
)
|
||||
public override fun newBuilder(): Nothing = throw
|
||||
AssertionError("Builders are deprecated and only available in a javaInterop build; see https://square.github.io/wire/wire_compiler/#kotlin")
|
||||
|
||||
public override fun equals(other: Any?): Boolean {
|
||||
if (other === this) return true
|
||||
if (other !is Block) return false
|
||||
if (unknownFields != other.unknownFields) return false
|
||||
if (time != other.time) return false
|
||||
if (frames != other.frames) return false
|
||||
if (events != other.events) return false
|
||||
if (length != other.length) return false
|
||||
if (bin_size != other.bin_size) return false
|
||||
return true
|
||||
}
|
||||
|
||||
public override fun hashCode(): Int {
|
||||
var result = super.hashCode
|
||||
if (result == 0) {
|
||||
result = unknownFields.hashCode()
|
||||
result = result * 37 + time.hashCode()
|
||||
result = result * 37 + frames.hashCode()
|
||||
result = result * 37 + (events?.hashCode() ?: 0)
|
||||
result = result * 37 + length.hashCode()
|
||||
result = result * 37 + bin_size.hashCode()
|
||||
super.hashCode = result
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
public override fun toString(): String {
|
||||
val result = mutableListOf<String>()
|
||||
result += """time=$time"""
|
||||
if (frames.isNotEmpty()) result += """frames=$frames"""
|
||||
if (events != null) result += """events=$events"""
|
||||
result += """length=$length"""
|
||||
result += """bin_size=$bin_size"""
|
||||
return result.joinToString(prefix = "Block{", separator = ", ", postfix = "}")
|
||||
}
|
||||
|
||||
public fun copy(
|
||||
time: Long = this.time,
|
||||
frames: List<Frame> = this.frames,
|
||||
events: Events? = this.events,
|
||||
length: Long = this.length,
|
||||
bin_size: Long = this.bin_size,
|
||||
unknownFields: ByteString = this.unknownFields,
|
||||
): Block = Block(time, frames, events, length, bin_size, unknownFields)
|
||||
|
||||
public companion object {
|
||||
@JvmField
|
||||
public val ADAPTER: ProtoAdapter<Block> = object : ProtoAdapter<Block>(
|
||||
FieldEncoding.LENGTH_DELIMITED,
|
||||
Block::class,
|
||||
"type.googleapis.com/ru.inr.mass.data.proto.Point.Channel.Block",
|
||||
PROTO_3,
|
||||
null,
|
||||
"numass-proto.proto"
|
||||
) {
|
||||
public override fun encodedSize(`value`: Block): Int {
|
||||
var size = value.unknownFields.size
|
||||
if (value.time != 0L) size += ProtoAdapter.UINT64.encodedSizeWithTag(1, value.time)
|
||||
size += Frame.ADAPTER.asRepeated().encodedSizeWithTag(2, value.frames)
|
||||
if (value.events != null) size += Events.ADAPTER.encodedSizeWithTag(3, value.events)
|
||||
if (value.length != 0L) size += ProtoAdapter.UINT64.encodedSizeWithTag(4, value.length)
|
||||
if (value.bin_size != 0L) size += ProtoAdapter.UINT64.encodedSizeWithTag(5,
|
||||
value.bin_size)
|
||||
return size
|
||||
}
|
||||
|
||||
public override fun encode(writer: ProtoWriter, `value`: Block): Unit {
|
||||
if (value.time != 0L) ProtoAdapter.UINT64.encodeWithTag(writer, 1, value.time)
|
||||
Frame.ADAPTER.asRepeated().encodeWithTag(writer, 2, value.frames)
|
||||
if (value.events != null) Events.ADAPTER.encodeWithTag(writer, 3, value.events)
|
||||
if (value.length != 0L) ProtoAdapter.UINT64.encodeWithTag(writer, 4, value.length)
|
||||
if (value.bin_size != 0L) ProtoAdapter.UINT64.encodeWithTag(writer, 5, value.bin_size)
|
||||
writer.writeBytes(value.unknownFields)
|
||||
}
|
||||
|
||||
public override fun encode(writer: ReverseProtoWriter, `value`: Block): Unit {
|
||||
writer.writeBytes(value.unknownFields)
|
||||
if (value.bin_size != 0L) ProtoAdapter.UINT64.encodeWithTag(writer, 5, value.bin_size)
|
||||
if (value.length != 0L) ProtoAdapter.UINT64.encodeWithTag(writer, 4, value.length)
|
||||
if (value.events != null) Events.ADAPTER.encodeWithTag(writer, 3, value.events)
|
||||
Frame.ADAPTER.asRepeated().encodeWithTag(writer, 2, value.frames)
|
||||
if (value.time != 0L) ProtoAdapter.UINT64.encodeWithTag(writer, 1, value.time)
|
||||
}
|
||||
|
||||
public override fun decode(reader: ProtoReader): Block {
|
||||
var time: Long = 0L
|
||||
val frames = mutableListOf<Frame>()
|
||||
var events: Events? = null
|
||||
var length: Long = 0L
|
||||
var bin_size: Long = 0L
|
||||
val unknownFields = reader.forEachTag { tag ->
|
||||
when (tag) {
|
||||
1 -> time = ProtoAdapter.UINT64.decode(reader)
|
||||
2 -> frames.add(Frame.ADAPTER.decode(reader))
|
||||
3 -> events = Events.ADAPTER.decode(reader)
|
||||
4 -> length = ProtoAdapter.UINT64.decode(reader)
|
||||
5 -> bin_size = ProtoAdapter.UINT64.decode(reader)
|
||||
else -> reader.readUnknownField(tag)
|
||||
}
|
||||
}
|
||||
return Block(
|
||||
time = time,
|
||||
frames = frames,
|
||||
events = events,
|
||||
length = length,
|
||||
bin_size = bin_size,
|
||||
unknownFields = unknownFields
|
||||
)
|
||||
}
|
||||
|
||||
public override fun redact(`value`: Block): Block = value.copy(
|
||||
frames = value.frames.redactElements(Frame.ADAPTER),
|
||||
events = value.events?.let(Events.ADAPTER::redact),
|
||||
unknownFields = ByteString.EMPTY
|
||||
)
|
||||
}
|
||||
|
||||
private const val serialVersionUID: Long = 0L
|
||||
}
|
||||
|
||||
/**
|
||||
* Raw data frame
|
||||
*/
|
||||
public class Frame(
|
||||
/**
|
||||
* Time in nanos from the beginning of the block
|
||||
*/
|
||||
@field:WireField(
|
||||
tag = 1,
|
||||
adapter = "com.squareup.wire.ProtoAdapter#UINT64",
|
||||
label = WireField.Label.OMIT_IDENTITY,
|
||||
)
|
||||
public val time: Long = 0L,
|
||||
/**
|
||||
* Frame data as an array of int16 measured in arbitrary channels
|
||||
*/
|
||||
@field:WireField(
|
||||
tag = 2,
|
||||
adapter = "com.squareup.wire.ProtoAdapter#BYTES",
|
||||
label = WireField.Label.OMIT_IDENTITY,
|
||||
declaredName = "data",
|
||||
)
|
||||
public val data_: ByteString = ByteString.EMPTY,
|
||||
unknownFields: ByteString = ByteString.EMPTY,
|
||||
) : Message<Frame, Nothing>(ADAPTER, unknownFields) {
|
||||
@Deprecated(
|
||||
message = "Shouldn't be used in Kotlin",
|
||||
level = DeprecationLevel.HIDDEN,
|
||||
)
|
||||
public override fun newBuilder(): Nothing = throw
|
||||
AssertionError("Builders are deprecated and only available in a javaInterop build; see https://square.github.io/wire/wire_compiler/#kotlin")
|
||||
|
||||
public override fun equals(other: Any?): Boolean {
|
||||
if (other === this) return true
|
||||
if (other !is Frame) return false
|
||||
if (unknownFields != other.unknownFields) return false
|
||||
if (time != other.time) return false
|
||||
if (data_ != other.data_) return false
|
||||
return true
|
||||
}
|
||||
|
||||
public override fun hashCode(): Int {
|
||||
var result = super.hashCode
|
||||
if (result == 0) {
|
||||
result = unknownFields.hashCode()
|
||||
result = result * 37 + time.hashCode()
|
||||
result = result * 37 + data_.hashCode()
|
||||
super.hashCode = result
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
public override fun toString(): String {
|
||||
val result = mutableListOf<String>()
|
||||
result += """time=$time"""
|
||||
result += """data_=$data_"""
|
||||
return result.joinToString(prefix = "Frame{", separator = ", ", postfix = "}")
|
||||
}
|
||||
|
||||
public fun copy(
|
||||
time: Long = this.time,
|
||||
data_: ByteString = this.data_,
|
||||
unknownFields: ByteString = this.unknownFields,
|
||||
): Frame = Frame(time, data_, unknownFields)
|
||||
|
||||
public companion object {
|
||||
@JvmField
|
||||
public val ADAPTER: ProtoAdapter<Frame> = object : ProtoAdapter<Frame>(
|
||||
FieldEncoding.LENGTH_DELIMITED,
|
||||
Frame::class,
|
||||
"type.googleapis.com/ru.inr.mass.data.proto.Point.Channel.Block.Frame",
|
||||
PROTO_3,
|
||||
null,
|
||||
"numass-proto.proto"
|
||||
) {
|
||||
public override fun encodedSize(`value`: Frame): Int {
|
||||
var size = value.unknownFields.size
|
||||
if (value.time != 0L) size += ProtoAdapter.UINT64.encodedSizeWithTag(1, value.time)
|
||||
if (value.data_ != ByteString.EMPTY) size += ProtoAdapter.BYTES.encodedSizeWithTag(2,
|
||||
value.data_)
|
||||
return size
|
||||
}
|
||||
|
||||
public override fun encode(writer: ProtoWriter, `value`: Frame): Unit {
|
||||
if (value.time != 0L) ProtoAdapter.UINT64.encodeWithTag(writer, 1, value.time)
|
||||
if (value.data_ != ByteString.EMPTY) ProtoAdapter.BYTES.encodeWithTag(writer, 2,
|
||||
value.data_)
|
||||
writer.writeBytes(value.unknownFields)
|
||||
}
|
||||
|
||||
public override fun encode(writer: ReverseProtoWriter, `value`: Frame): Unit {
|
||||
writer.writeBytes(value.unknownFields)
|
||||
if (value.data_ != ByteString.EMPTY) ProtoAdapter.BYTES.encodeWithTag(writer, 2,
|
||||
value.data_)
|
||||
if (value.time != 0L) ProtoAdapter.UINT64.encodeWithTag(writer, 1, value.time)
|
||||
}
|
||||
|
||||
public override fun decode(reader: ProtoReader): Frame {
|
||||
var time: Long = 0L
|
||||
var data_: ByteString = ByteString.EMPTY
|
||||
val unknownFields = reader.forEachTag { tag ->
|
||||
when (tag) {
|
||||
1 -> time = ProtoAdapter.UINT64.decode(reader)
|
||||
2 -> data_ = ProtoAdapter.BYTES.decode(reader)
|
||||
else -> reader.readUnknownField(tag)
|
||||
}
|
||||
}
|
||||
return Frame(
|
||||
time = time,
|
||||
data_ = data_,
|
||||
unknownFields = unknownFields
|
||||
)
|
||||
}
|
||||
|
||||
public override fun redact(`value`: Frame): Frame = value.copy(
|
||||
unknownFields = ByteString.EMPTY
|
||||
)
|
||||
}
|
||||
|
||||
private const val serialVersionUID: Long = 0L
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event block obtained directly from device of from frame analysis
|
||||
* In order to save space, times and amplitudes are in separate arrays.
|
||||
* Amplitude and time with the same index correspond to the same event
|
||||
*/
|
||||
public class Events(
|
||||
times: List<Long> = emptyList(),
|
||||
amplitudes: List<Long> = emptyList(),
|
||||
unknownFields: ByteString = ByteString.EMPTY,
|
||||
) : Message<Events, Nothing>(ADAPTER, unknownFields) {
|
||||
/**
|
||||
* Array of time in nanos from the beginning of the block
|
||||
*/
|
||||
@field:WireField(
|
||||
tag = 1,
|
||||
adapter = "com.squareup.wire.ProtoAdapter#UINT64",
|
||||
label = WireField.Label.PACKED,
|
||||
)
|
||||
public val times: List<Long> = immutableCopyOf("times", times)
|
||||
|
||||
/**
|
||||
* Array of amplitudes of events in channels
|
||||
*/
|
||||
@field:WireField(
|
||||
tag = 2,
|
||||
adapter = "com.squareup.wire.ProtoAdapter#UINT64",
|
||||
label = WireField.Label.PACKED,
|
||||
)
|
||||
public val amplitudes: List<Long> = immutableCopyOf("amplitudes", amplitudes)
|
||||
|
||||
@Deprecated(
|
||||
message = "Shouldn't be used in Kotlin",
|
||||
level = DeprecationLevel.HIDDEN,
|
||||
)
|
||||
public override fun newBuilder(): Nothing = throw
|
||||
AssertionError("Builders are deprecated and only available in a javaInterop build; see https://square.github.io/wire/wire_compiler/#kotlin")
|
||||
|
||||
public override fun equals(other: Any?): Boolean {
|
||||
if (other === this) return true
|
||||
if (other !is Events) return false
|
||||
if (unknownFields != other.unknownFields) return false
|
||||
if (times != other.times) return false
|
||||
if (amplitudes != other.amplitudes) return false
|
||||
return true
|
||||
}
|
||||
|
||||
public override fun hashCode(): Int {
|
||||
var result = super.hashCode
|
||||
if (result == 0) {
|
||||
result = unknownFields.hashCode()
|
||||
result = result * 37 + times.hashCode()
|
||||
result = result * 37 + amplitudes.hashCode()
|
||||
super.hashCode = result
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
public override fun toString(): String {
|
||||
val result = mutableListOf<String>()
|
||||
if (times.isNotEmpty()) result += """times=$times"""
|
||||
if (amplitudes.isNotEmpty()) result += """amplitudes=$amplitudes"""
|
||||
return result.joinToString(prefix = "Events{", separator = ", ", postfix = "}")
|
||||
}
|
||||
|
||||
public fun copy(
|
||||
times: List<Long> = this.times,
|
||||
amplitudes: List<Long> = this.amplitudes,
|
||||
unknownFields: ByteString = this.unknownFields,
|
||||
): Events = Events(times, amplitudes, unknownFields)
|
||||
|
||||
public companion object {
|
||||
@JvmField
|
||||
public val ADAPTER: ProtoAdapter<Events> = object : ProtoAdapter<Events>(
|
||||
FieldEncoding.LENGTH_DELIMITED,
|
||||
Events::class,
|
||||
"type.googleapis.com/ru.inr.mass.data.proto.Point.Channel.Block.Events",
|
||||
PROTO_3,
|
||||
null,
|
||||
"numass-proto.proto"
|
||||
) {
|
||||
public override fun encodedSize(`value`: Events): Int {
|
||||
var size = value.unknownFields.size
|
||||
size += ProtoAdapter.UINT64.asPacked().encodedSizeWithTag(1, value.times)
|
||||
size += ProtoAdapter.UINT64.asPacked().encodedSizeWithTag(2, value.amplitudes)
|
||||
return size
|
||||
}
|
||||
|
||||
public override fun encode(writer: ProtoWriter, `value`: Events): Unit {
|
||||
ProtoAdapter.UINT64.asPacked().encodeWithTag(writer, 1, value.times)
|
||||
ProtoAdapter.UINT64.asPacked().encodeWithTag(writer, 2, value.amplitudes)
|
||||
writer.writeBytes(value.unknownFields)
|
||||
}
|
||||
|
||||
public override fun encode(writer: ReverseProtoWriter, `value`: Events): Unit {
|
||||
writer.writeBytes(value.unknownFields)
|
||||
ProtoAdapter.UINT64.asPacked().encodeWithTag(writer, 2, value.amplitudes)
|
||||
ProtoAdapter.UINT64.asPacked().encodeWithTag(writer, 1, value.times)
|
||||
}
|
||||
|
||||
public override fun decode(reader: ProtoReader): Events {
|
||||
val times = mutableListOf<Long>()
|
||||
val amplitudes = mutableListOf<Long>()
|
||||
val unknownFields = reader.forEachTag { tag ->
|
||||
when (tag) {
|
||||
1 -> times.add(ProtoAdapter.UINT64.decode(reader))
|
||||
2 -> amplitudes.add(ProtoAdapter.UINT64.decode(reader))
|
||||
else -> reader.readUnknownField(tag)
|
||||
}
|
||||
}
|
||||
return Events(
|
||||
times = times,
|
||||
amplitudes = amplitudes,
|
||||
unknownFields = unknownFields
|
||||
)
|
||||
}
|
||||
|
||||
public override fun redact(`value`: Events): Events = value.copy(
|
||||
unknownFields = ByteString.EMPTY
|
||||
)
|
||||
}
|
||||
|
||||
private const val serialVersionUID: Long = 0L
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,10 +4,7 @@ import ru.inr.mass.data.api.NumassPoint
|
||||
import ru.inr.mass.data.api.NumassSet
|
||||
import ru.inr.mass.data.api.NumassSet.Companion.NUMASS_HV_TARGET
|
||||
import ru.inr.mass.data.api.readEnvelope
|
||||
import space.kscience.dataforge.context.Context
|
||||
import space.kscience.dataforge.context.error
|
||||
import space.kscience.dataforge.context.logger
|
||||
import space.kscience.dataforge.context.warn
|
||||
import space.kscience.dataforge.context.*
|
||||
import space.kscience.dataforge.io.io
|
||||
import space.kscience.dataforge.io.readEnvelopeFile
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
@ -16,14 +13,16 @@ import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.asName
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.util.stream.Collectors
|
||||
import kotlin.io.path.*
|
||||
import kotlin.streams.toList
|
||||
|
||||
@OptIn(ExperimentalPathApi::class)
|
||||
public class NumassDirectorySet internal constructor(
|
||||
public val context: Context,
|
||||
public val numassProto: NumassProtoPlugin,
|
||||
public val path: Path,
|
||||
) : NumassSet {
|
||||
) : NumassSet, ContextAware {
|
||||
|
||||
override val context: Context
|
||||
get() = numassProto.context
|
||||
|
||||
@OptIn(DFExperimental::class)
|
||||
override val meta: Meta
|
||||
@ -43,12 +42,12 @@ public class NumassDirectorySet internal constructor(
|
||||
it.fileName.name.startsWith("p")
|
||||
}.map { pointPath ->
|
||||
try {
|
||||
context.readNumassPointFile(pointPath)
|
||||
numassProto.readNumassPointFile(pointPath)
|
||||
} catch (e: Exception) {
|
||||
context.logger.error(e) { "Error reading Numass point file $pointPath" }
|
||||
null
|
||||
}
|
||||
}.toList().filterNotNull()
|
||||
}.collect(Collectors.toList()).filterNotNull()
|
||||
|
||||
|
||||
@OptIn(DFExperimental::class)
|
||||
@ -73,20 +72,3 @@ public class NumassDirectorySet internal constructor(
|
||||
|
||||
public companion object
|
||||
}
|
||||
|
||||
@OptIn(DFExperimental::class)
|
||||
public fun Context.readNumassPointFile(path: Path): NumassPoint? {
|
||||
val envelope = io.readEnvelopeFile(path)
|
||||
return ProtoNumassPoint.fromEnvelope(envelope)
|
||||
}
|
||||
|
||||
public fun Context.readNumassPointFile(path: String): NumassPoint? = readNumassPointFile(Path.of(path))
|
||||
|
||||
@OptIn(ExperimentalPathApi::class)
|
||||
public fun Context.readNumassDirectory(path: Path): NumassDirectorySet {
|
||||
if (!path.exists()) error("Path $path does not exist")
|
||||
if (!path.isDirectory()) error("The path $path is not a directory")
|
||||
return NumassDirectorySet(this, path)
|
||||
}
|
||||
|
||||
public fun Context.readNumassDirectory(path: String): NumassDirectorySet = readNumassDirectory(Path.of(path))
|
@ -1,28 +1,77 @@
|
||||
package ru.inr.mass.data.proto
|
||||
|
||||
import kotlinx.coroutines.launch
|
||||
import ru.inr.mass.data.api.NumassPoint
|
||||
import space.kscience.dataforge.context.AbstractPlugin
|
||||
import space.kscience.dataforge.context.Context
|
||||
import space.kscience.dataforge.context.PluginFactory
|
||||
import space.kscience.dataforge.context.PluginTag
|
||||
import space.kscience.dataforge.data.DataSource
|
||||
import space.kscience.dataforge.data.DataTree
|
||||
import space.kscience.dataforge.data.static
|
||||
import space.kscience.dataforge.io.EnvelopeFormatFactory
|
||||
import space.kscience.dataforge.io.IOPlugin
|
||||
import space.kscience.dataforge.io.readEnvelopeFile
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.misc.DFExperimental
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.NameToken
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.exists
|
||||
import kotlin.io.path.isDirectory
|
||||
import kotlin.io.path.relativeTo
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
public class NumassProtoPlugin : AbstractPlugin() {
|
||||
public val io: IOPlugin by require(IOPlugin)
|
||||
override val tag: PluginTag get() = Companion.tag
|
||||
|
||||
override fun content(target: String): Map<Name, Any> = if(target == EnvelopeFormatFactory.ENVELOPE_FORMAT_TYPE){
|
||||
override fun content(target: String): Map<Name, Any> = if (target == EnvelopeFormatFactory.ENVELOPE_FORMAT_TYPE) {
|
||||
mapOf(TaggedNumassEnvelopeFormat.name to TaggedNumassEnvelopeFormat)
|
||||
} else{
|
||||
} else {
|
||||
super.content(target)
|
||||
}
|
||||
|
||||
public companion object : PluginFactory<NumassProtoPlugin> {
|
||||
override fun invoke(meta: Meta, context: Context): NumassProtoPlugin = NumassProtoPlugin()
|
||||
override fun build(context: Context, meta: Meta): NumassProtoPlugin = NumassProtoPlugin()
|
||||
override val tag: PluginTag = PluginTag("numass-proto", group = "ru.inr.mass")
|
||||
override val type: KClass<out NumassProtoPlugin> = NumassProtoPlugin::class
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@OptIn(DFExperimental::class)
|
||||
public fun NumassProtoPlugin.readNumassPointFile(path: Path): NumassPoint? {
|
||||
val envelope = io.readEnvelopeFile(path)
|
||||
return ProtoNumassPoint.fromEnvelope(envelope)
|
||||
}
|
||||
|
||||
public fun NumassProtoPlugin.readNumassPointFile(path: String): NumassPoint? = readNumassPointFile(Path.of(path))
|
||||
|
||||
public fun NumassProtoPlugin.readNumassDirectory(path: Path): NumassDirectorySet {
|
||||
if (!path.exists()) error("Path $path does not exist")
|
||||
if (!path.isDirectory()) error("The path $path is not a directory")
|
||||
return NumassDirectorySet(this, path)
|
||||
}
|
||||
|
||||
public fun NumassProtoPlugin.readNumassDirectory(path: String): NumassDirectorySet = readNumassDirectory(Path.of(path))
|
||||
public suspend fun NumassProtoPlugin.readRepository(path: Path): DataTree<NumassDirectorySet> = DataSource {
|
||||
Files.walk(path).filter {
|
||||
it.isDirectory() && it.resolve("meta").exists()
|
||||
}.forEach { childPath ->
|
||||
val name = Name(childPath.relativeTo(path).map { segment ->
|
||||
NameToken(segment.fileName.toString())
|
||||
})
|
||||
val value = readNumassDirectory(childPath)
|
||||
launch {
|
||||
static(name, value, value.meta)
|
||||
}
|
||||
}
|
||||
//TODO add file watcher
|
||||
}
|
||||
|
||||
public suspend fun NumassProtoPlugin.readRepository(path: String): DataTree<NumassDirectorySet> = readRepository(Path.of(path))
|
||||
|
||||
public fun NumassProtoPlugin.readPoint(path: String): NumassPoint = readNumassPointFile(path)
|
||||
?: error("Can't read numass point at $path")
|
||||
|
@ -31,9 +31,6 @@ import ru.inr.mass.data.api.NumassFrame
|
||||
import ru.inr.mass.data.api.NumassPoint
|
||||
import space.kscience.dataforge.io.Envelope
|
||||
import space.kscience.dataforge.meta.*
|
||||
import space.kscience.dataforge.values.ValueType
|
||||
import space.kscience.dataforge.values.long
|
||||
import space.kscience.dataforge.values.string
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.InputStream
|
||||
@ -87,9 +84,10 @@ internal class ProtoNumassPoint(
|
||||
override val startTime: Instant
|
||||
get() {
|
||||
val startTimeValue = meta["start_time"]?.value
|
||||
return when{
|
||||
return when {
|
||||
startTimeValue == null -> Instant.DISTANT_PAST
|
||||
startTimeValue.type == ValueType.STRING -> LocalDateTime.parse(startTimeValue.string).toInstant(TimeZone.UTC)
|
||||
startTimeValue.type == ValueType.STRING -> LocalDateTime.parse(startTimeValue.string)
|
||||
.toInstant(TimeZone.UTC)
|
||||
//TODO fix time zones!!!
|
||||
startTimeValue.type == ValueType.NUMBER -> Instant.fromEpochMilliseconds(startTimeValue.long)
|
||||
else -> error("Can't decode start time")
|
||||
@ -116,7 +114,7 @@ internal class ProtoNumassPoint(
|
||||
|
||||
override fun toString(): String = "ProtoNumassPoint(index = ${index}, hv = $voltage)"
|
||||
|
||||
public companion object {
|
||||
companion object {
|
||||
|
||||
/**
|
||||
* Get valid data stream utilizing compression if it is present
|
||||
@ -142,6 +140,7 @@ internal class ProtoNumassPoint(
|
||||
inflater.end()
|
||||
ByteArrayInputStream(unzippeddata).use(block)
|
||||
}
|
||||
|
||||
else -> {
|
||||
data?.read {
|
||||
block(asInputStream())
|
||||
@ -149,7 +148,7 @@ internal class ProtoNumassPoint(
|
||||
}
|
||||
}
|
||||
|
||||
public fun fromEnvelope(envelope: Envelope): ProtoNumassPoint? {
|
||||
fun fromEnvelope(envelope: Envelope): ProtoNumassPoint? {
|
||||
if (envelope.data == null) return null
|
||||
return ProtoNumassPoint(envelope.meta) {
|
||||
envelope.useData {
|
||||
@ -180,6 +179,7 @@ public class ProtoNumassBlock(
|
||||
block.length > 0 -> block.length.nanoseconds
|
||||
parent?.meta?.get("acquisition_time") != null ->
|
||||
(parent.meta["acquisition_time"].double ?: (0.0 * 1000)).milliseconds
|
||||
|
||||
else -> {
|
||||
LoggerFactory.getLogger(javaClass)
|
||||
.error("No length information on block. Trying to infer from first and last events")
|
||||
@ -221,7 +221,8 @@ public class ProtoNumassBlock(
|
||||
} else {
|
||||
ShortArray(shortBuffer.limit()) { shortBuffer.get(it) }
|
||||
}
|
||||
FrameType.TQDC2021 -> ShortArray(shortBuffer.limit()){
|
||||
|
||||
FrameType.TQDC2021 -> ShortArray(shortBuffer.limit()) {
|
||||
(shortBuffer.get(it).toUShort().toInt() - Short.MAX_VALUE).toShort()
|
||||
}
|
||||
}
|
||||
|
@ -18,18 +18,19 @@ package ru.inr.mass.data.proto
|
||||
|
||||
import io.ktor.utils.io.core.*
|
||||
import space.kscience.dataforge.context.Context
|
||||
import space.kscience.dataforge.context.invoke
|
||||
import space.kscience.dataforge.io.*
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.meta.get
|
||||
import space.kscience.dataforge.meta.string
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.plus
|
||||
import space.kscience.dataforge.names.parseAsName
|
||||
import java.util.*
|
||||
|
||||
|
||||
public class TaggedNumassEnvelopeFormat(private val io: IOPlugin) : EnvelopeFormat {
|
||||
|
||||
private fun Tag.toBinary() = Binary(24) {
|
||||
private fun Tag.toBinary() = Binary {
|
||||
writeRawString(START_SEQUENCE)
|
||||
writeRawString("DFNU")
|
||||
writeShort(metaFormatKey)
|
||||
@ -70,7 +71,7 @@ public class TaggedNumassEnvelopeFormat(private val io: IOPlugin) : EnvelopeForm
|
||||
val metaFormat = io.resolveMetaFormat(tag.metaFormatKey)
|
||||
?: error("Meta format with key ${tag.metaFormatKey} not found")
|
||||
|
||||
val meta: Meta = metaFormat.readObject(input.readBinary(tag.metaSize.toInt()))
|
||||
val meta: Meta = metaFormat.readObjectFrom(input.readBinary(tag.metaSize.toInt()))
|
||||
|
||||
val data = input.readBinary(tag.dataSize.toInt())
|
||||
|
||||
@ -87,10 +88,10 @@ public class TaggedNumassEnvelopeFormat(private val io: IOPlugin) : EnvelopeForm
|
||||
?: error("Meta format with key ${tag.metaFormatKey} not found")
|
||||
}
|
||||
|
||||
val meta: Meta = metaFormat.readObject(input.readBinary(tag.metaSize.toInt()))
|
||||
val meta: Meta = metaFormat.readObjectFrom(input.readBinary(tag.metaSize.toInt()))
|
||||
|
||||
|
||||
return PartialEnvelope(meta, 30u + tag.metaSize, tag.dataSize)
|
||||
return PartialEnvelope(meta, 30 + tag.metaSize.toInt(), tag.dataSize)
|
||||
}
|
||||
|
||||
private data class Tag(
|
||||
@ -99,17 +100,17 @@ public class TaggedNumassEnvelopeFormat(private val io: IOPlugin) : EnvelopeForm
|
||||
val dataSize: ULong,
|
||||
)
|
||||
|
||||
override fun toMeta(): Meta = Meta {
|
||||
IOFormat.NAME_KEY put name.toString()
|
||||
}
|
||||
// override fun toMeta(): Meta = Meta {
|
||||
// NAME_KEY put name.toString()
|
||||
// }
|
||||
|
||||
public companion object : EnvelopeFormatFactory {
|
||||
private const val START_SEQUENCE = "#!"
|
||||
private const val END_SEQUENCE = "!#\r\n"
|
||||
|
||||
override val name: Name = super.name + "numass"
|
||||
override val name: Name = "envelope.numass".parseAsName()
|
||||
|
||||
override fun invoke(meta: Meta, context: Context): EnvelopeFormat {
|
||||
override fun build(context: Context, meta: Meta): EnvelopeFormat {
|
||||
val io = context.io
|
||||
|
||||
val metaFormatName = meta["name"].string?.let { Name.parse(it) } ?: JsonMetaFormat.name
|
||||
|
@ -6,9 +6,10 @@ import ru.inr.mass.data.api.NumassSet
|
||||
import ru.inr.mass.data.api.ParentBlock
|
||||
import ru.inr.mass.data.api.channels
|
||||
import space.kscience.dataforge.context.Context
|
||||
import space.kscience.dataforge.context.fetch
|
||||
import space.kscience.dataforge.meta.ListValue
|
||||
import space.kscience.dataforge.meta.get
|
||||
import space.kscience.dataforge.meta.string
|
||||
import space.kscience.dataforge.values.ListValue
|
||||
import java.nio.file.Path
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@ -16,11 +17,12 @@ class TestNumassDirectory {
|
||||
val context = Context("numass-test") {
|
||||
plugin(NumassProtoPlugin)
|
||||
}
|
||||
val numassProto = context.fetch(NumassProtoPlugin)
|
||||
|
||||
@Test
|
||||
fun testDanteRead() {
|
||||
val dataPath = Path.of("src/test/resources", "testData/dante")
|
||||
val testSet = context.readNumassDirectory(dataPath)
|
||||
val testSet = numassProto.readNumassDirectory(dataPath)
|
||||
assertEquals("2018-04-13T22:01:46", testSet.meta["end_time"].string)
|
||||
assertEquals(ListValue.EMPTY, testSet.meta["comments"]?.value)
|
||||
assertEquals(31, testSet.points.size)
|
||||
@ -32,12 +34,12 @@ class TestNumassDirectory {
|
||||
@Test
|
||||
fun testTQDCRead() = runBlocking {
|
||||
val pointPath = Path.of("src/test/resources", "testData/tqdc")
|
||||
val set: NumassSet = context.readNumassDirectory(pointPath)
|
||||
val set: NumassSet = numassProto.readNumassDirectory(pointPath)
|
||||
val point = set.first { it.voltage == 18200.0 }
|
||||
point.channels.forEach { (channel, block) ->
|
||||
println("$channel: $block")
|
||||
if(block is ParentBlock){
|
||||
block.blocks.toList().forEach{
|
||||
if (block is ParentBlock) {
|
||||
block.blocks.toList().forEach {
|
||||
println("\t${it.channel}:${it.eventsCount}")
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,14 @@
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
id("ru.mipt.npm.gradle.common")
|
||||
id("space.kscience.gradle.mpp")
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
val visionForgeVersion = "0.2.0-dev-24"
|
||||
val visionForgeVersion: String by rootProject.extra
|
||||
|
||||
val production: Boolean by rootProject.extra(false)
|
||||
|
||||
kotlin {
|
||||
js{
|
||||
js(IR) {
|
||||
browser {
|
||||
webpackTask {
|
||||
this.outputFileName = "js/numass-web.js"
|
||||
@ -16,17 +17,6 @@ kotlin {
|
||||
binaries.executable()
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
val jsBrowserDistribution by tasks.getting
|
||||
|
||||
tasks.getByName<ProcessResources>("jvmProcessResources") {
|
||||
dependsOn(jsBrowserDistribution)
|
||||
afterEvaluate {
|
||||
from(jsBrowserDistribution)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
@ -44,8 +34,26 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
kscience{
|
||||
afterEvaluate {
|
||||
val distributionTask = if (production) {
|
||||
tasks.getByName("jsBrowserDistribution")
|
||||
} else {
|
||||
tasks.getByName("jsBrowserDevelopmentExecutableDistribution")
|
||||
}
|
||||
|
||||
tasks.getByName<ProcessResources>("jvmProcessResources") {
|
||||
dependsOn(distributionTask)
|
||||
from(distributionTask)
|
||||
include("**/*.js")
|
||||
if (production) {
|
||||
include("**/*.map")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kscience {
|
||||
useSerialization {
|
||||
json()
|
||||
}
|
||||
withContextReceivers()
|
||||
}
|
||||
|
@ -8,28 +8,22 @@ import space.kscience.dataforge.context.PluginFactory
|
||||
import space.kscience.dataforge.context.PluginTag
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.visionforge.Vision
|
||||
import space.kscience.visionforge.VisionBase
|
||||
import space.kscience.visionforge.VisionGroupBase
|
||||
import space.kscience.visionforge.VisionPlugin
|
||||
import space.kscience.visionforge.plotly.PlotlyPlugin
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
public class NumassCommonPlugin(meta: Meta) : VisionPlugin(meta) {
|
||||
public class NumassCommonPlugin(meta: Meta = Meta.EMPTY) : VisionPlugin(meta) {
|
||||
override val tag: PluginTag get() = Companion.tag
|
||||
|
||||
public val plotlyPlugin: PlotlyPlugin by require(PlotlyPlugin)
|
||||
|
||||
override val visionSerializersModule: SerializersModule get() = numassSerializersModule
|
||||
|
||||
public companion object : PluginFactory<NumassCommonPlugin> {
|
||||
override val tag: PluginTag = PluginTag("numass.common", "ru.inr.mass")
|
||||
override val type: KClass<NumassCommonPlugin> = NumassCommonPlugin::class
|
||||
override fun invoke(meta: Meta, context: Context): NumassCommonPlugin = NumassCommonPlugin()
|
||||
|
||||
private val numassSerializersModule = SerializersModule {
|
||||
override fun build(context: Context, meta: Meta): NumassCommonPlugin = NumassCommonPlugin()
|
||||
|
||||
internal val numassSerializersModule = SerializersModule {
|
||||
polymorphic(Vision::class) {
|
||||
subclass(VisionBase.serializer())
|
||||
subclass(VisionGroupBase.serializer())
|
||||
subclass(VisionOfNumassHv.serializer())
|
||||
subclass(VisionOfNumassPoint.serializer())
|
||||
subclass(VisionOfNumassHv.serializer())
|
||||
|
@ -1,24 +1,23 @@
|
||||
package ru.inr.mass.data.server
|
||||
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.serialization.Serializable
|
||||
import ru.inr.mass.data.api.NumassBlock
|
||||
import ru.inr.mass.data.api.NumassPoint
|
||||
import ru.inr.mass.data.api.NumassSet
|
||||
import ru.inr.mass.data.api.NumassSet.Companion.NUMASS_HV_TARGET
|
||||
import ru.inr.mass.data.api.channels
|
||||
import ru.inr.mass.data.proto.HVData
|
||||
import ru.inr.mass.data.proto.HVEntry
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.names.NameToken
|
||||
import space.kscience.dataforge.provider.top
|
||||
import space.kscience.visionforge.VisionBase
|
||||
import space.kscience.visionforge.VisionGroupBase
|
||||
import space.kscience.visionforge.AbstractVision
|
||||
|
||||
|
||||
public typealias SimpleAmplitudeSpectrum = Map<UShort, UInt>
|
||||
public typealias SimpleAmplitudeSpectrum = Map<Short, UInt>
|
||||
|
||||
private suspend fun NumassBlock.simpleAmplitudeSpectrum(): SimpleAmplitudeSpectrum {
|
||||
val res = mutableMapOf<UShort, UInt>()
|
||||
internal suspend fun NumassBlock.simpleAmplitudeSpectrum(): SimpleAmplitudeSpectrum {
|
||||
val res = mutableMapOf<Short, UInt>()
|
||||
events.collect {
|
||||
res[it.amplitude] = (res[it.amplitude] ?: 0U) + 1U
|
||||
}
|
||||
@ - |