Tables optimizzed and partially moved to kotlin
This commit is contained in:
parent
97f534646d
commit
09a651b556
@ -180,6 +180,9 @@ class DanteClient(val ip: String, chainLength: Int) : AutoCloseable {
|
|||||||
val board = header[1]
|
val board = header[1]
|
||||||
val packet = header[2]
|
val packet = header[2]
|
||||||
val length = (header[3].positive * 0x100 + header[4].positive * 0x010 + header[5].positive) * 4
|
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)
|
val payload = ByteArray(length)
|
||||||
DataInputStream(stream).readFully(payload)
|
DataInputStream(stream).readFully(payload)
|
||||||
handle(DanteMessage(command, board.positive, packet.positive, payload))
|
handle(DanteMessage(command, board.positive, packet.positive, payload))
|
||||||
|
@ -23,7 +23,7 @@ object NumassDataUtils {
|
|||||||
override val points: Stream<out NumassPoint> by lazy {
|
override val points: Stream<out NumassPoint> by lazy {
|
||||||
val points = sets.stream().flatMap<NumassPoint> { it.points }
|
val points = sets.stream().flatMap<NumassPoint> { it.points }
|
||||||
.collect(Collectors.groupingBy<NumassPoint, Double> { it.voltage })
|
.collect(Collectors.groupingBy<NumassPoint, Double> { 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 {
|
override val meta: Meta by lazy {
|
||||||
|
@ -83,7 +83,7 @@ class TimeAnalyzer @JvmOverloads constructor(private val processor: SignalProces
|
|||||||
|
|
||||||
override fun analyzePoint(point: NumassPoint, config: Meta): Values {
|
override fun analyzePoint(point: NumassPoint, config: Meta): Values {
|
||||||
//Average count rates, do not sum events
|
//Average count rates, do not sum events
|
||||||
val res = point.blocks
|
val res = point.blocks.stream()
|
||||||
.map { it -> analyze(it, config) }
|
.map { it -> analyze(it, config) }
|
||||||
.reduce(null) { v1, v2 -> this.combineBlockResults(v1, v2) }
|
.reduce(null) { v1, v2 -> this.combineBlockResults(v1, v2) }
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ import java.util.stream.Stream
|
|||||||
interface NumassPoint : Metoid, NumassBlock {
|
interface NumassPoint : Metoid, NumassBlock {
|
||||||
|
|
||||||
|
|
||||||
val blocks: Stream<NumassBlock>
|
val blocks: List<NumassBlock>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the voltage setting for the point
|
* Get the voltage setting for the point
|
||||||
@ -38,7 +38,7 @@ interface NumassPoint : Metoid, NumassBlock {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
val firstBlock: NumassBlock
|
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
|
* Get the starting time from meta or from first block
|
||||||
@ -54,7 +54,7 @@ interface NumassPoint : Metoid, NumassBlock {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
override val length: Duration
|
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
|
* Get all events it all blocks as a single sequence
|
||||||
@ -66,7 +66,7 @@ interface NumassPoint : Metoid, NumassBlock {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
override val events: Stream<NumassEvent>
|
override val events: Stream<NumassEvent>
|
||||||
get() = blocks.flatMap { it.events }
|
get() = blocks.stream().flatMap { it.events }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all frames in all blocks as a single sequence
|
* Get all frames in all blocks as a single sequence
|
||||||
@ -74,7 +74,7 @@ interface NumassPoint : Metoid, NumassBlock {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
override val frames: Stream<NumassFrame>
|
override val frames: Stream<NumassFrame>
|
||||||
get() = blocks.flatMap { it.frames }
|
get() = blocks.stream().flatMap { it.frames }
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
@ -4,28 +4,18 @@ import hep.dataforge.meta.Meta
|
|||||||
import hep.dataforge.meta.MetaBuilder
|
import hep.dataforge.meta.MetaBuilder
|
||||||
import hep.dataforge.meta.MetaHolder
|
import hep.dataforge.meta.MetaHolder
|
||||||
|
|
||||||
import java.util.stream.Stream
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple static implementation of NumassPoint
|
* A simple static implementation of NumassPoint
|
||||||
* Created by darksnake on 08.07.2017.
|
* Created by darksnake on 08.07.2017.
|
||||||
*/
|
*/
|
||||||
class SimpleNumassPoint : MetaHolder, NumassPoint {
|
class SimpleNumassPoint(override val blocks: List<NumassBlock>, meta: Meta) : MetaHolder(meta), NumassPoint {
|
||||||
private val blockList: List<NumassBlock>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Input blocks must be sorted
|
* Input blocks must be sorted
|
||||||
* @param voltage
|
* @param voltage
|
||||||
* @param blocks
|
* @param blocks
|
||||||
*/
|
*/
|
||||||
constructor(voltage: Double, blocks: Collection<NumassBlock>) : super(MetaBuilder("point").setValue(NumassPoint.HV_KEY, voltage)) {
|
constructor(blocks: Collection<NumassBlock>, voltage: Double) :
|
||||||
this.blockList = blocks.sortedBy { it.startTime }
|
this(blocks.sortedBy { it.startTime }, MetaBuilder("point").setValue(NumassPoint.HV_KEY, voltage))
|
||||||
}
|
|
||||||
|
|
||||||
constructor(meta: Meta, blocks: Collection<NumassBlock>) : super(meta) {
|
|
||||||
this.blockList = blocks.sortedBy { it.startTime }
|
|
||||||
}
|
|
||||||
|
|
||||||
override val blocks: Stream<NumassBlock>
|
|
||||||
get() = blockList.stream()
|
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,7 @@ constructor(override val name: String, private val path: Path, meta: Meta) : Num
|
|||||||
.setValue("source", "legacy")
|
.setValue("source", "legacy")
|
||||||
|
|
||||||
|
|
||||||
return SimpleNumassPoint(pointMeta, listOf<NumassBlock>(block))
|
return SimpleNumassPoint(listOf<NumassBlock>(block), pointMeta)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
|
@ -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 index: Int = meta.getInt("external_meta.point_index", super.index)
|
||||||
|
|
||||||
override val blocks: Stream<NumassBlock>
|
override val blocks: List<NumassBlock> by lazy {
|
||||||
get() {
|
val length: Long = if (envelope.meta.hasValue("external_meta.acquisition_time")) {
|
||||||
val length: Long = if (envelope.meta.hasValue("external_meta.acquisition_time")) {
|
envelope.meta.getValue("external_meta.acquisition_time").long
|
||||||
envelope.meta.getValue("external_meta.acquisition_time").getLong()
|
} else {
|
||||||
} else {
|
envelope.meta.getValue("acquisition_time").long
|
||||||
envelope.meta.getValue("acquisition_time").getLong()
|
|
||||||
}
|
|
||||||
return Stream.of(ClassicBlock(startTime, Duration.ofSeconds(length)))
|
|
||||||
}
|
}
|
||||||
|
listOf(ClassicBlock(startTime, Duration.ofSeconds(length)))
|
||||||
|
}
|
||||||
|
|
||||||
override val startTime: Instant
|
override val startTime: Instant
|
||||||
get() = if (meta.hasValue("start_time")) {
|
get() = if (meta.hasValue("start_time")) {
|
||||||
|
@ -28,13 +28,14 @@ class ProtoNumassPoint(override val meta: Meta, protoBuilder: () -> NumassProto.
|
|||||||
|
|
||||||
val proto: NumassProto.Point by lazy(protoBuilder)
|
val proto: NumassProto.Point by lazy(protoBuilder)
|
||||||
|
|
||||||
override val blocks: Stream<NumassBlock>
|
override val blocks: List<NumassBlock> by lazy {
|
||||||
get() = proto.channelsList.stream()
|
proto.channelsList.stream()
|
||||||
.flatMap { channel ->
|
.flatMap { channel ->
|
||||||
channel.blocksList.stream()
|
channel.blocksList.stream()
|
||||||
.map { block -> ProtoBlock(channel.id.toInt(), block, this) }
|
.map { block -> ProtoBlock(channel.id.toInt(), block, this) }
|
||||||
.sorted(Comparator.comparing<ProtoBlock, Instant> { it.startTime })
|
.sorted(Comparator.comparing<ProtoBlock, Instant> { it.startTime })
|
||||||
}
|
}.toList()
|
||||||
|
}
|
||||||
|
|
||||||
override val voltage: Double = meta.getDouble("external_meta.HV1_value", super.voltage)
|
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
|
override val startTime: Instant
|
||||||
get() = if (meta.hasValue("start_time")) {
|
get() = if (meta.hasValue("start_time")) {
|
||||||
meta.getValue("start_time").getTime()
|
meta.getValue("start_time").time
|
||||||
} else {
|
} else {
|
||||||
super.startTime
|
super.startTime
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ import inr.numass.actions.TimeAnalyzerAction
|
|||||||
import inr.numass.data.NumassDataUtils
|
import inr.numass.data.NumassDataUtils
|
||||||
import inr.numass.data.api.NumassPoint
|
import inr.numass.data.api.NumassPoint
|
||||||
import inr.numass.data.api.NumassSet
|
import inr.numass.data.api.NumassSet
|
||||||
import inr.numass.data.api.SimpleNumassPoint
|
|
||||||
import inr.numass.data.storage.NumassStorageFactory
|
import inr.numass.data.storage.NumassStorageFactory
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,7 +48,7 @@ new GrindShell(ctx).eval {
|
|||||||
def builder = DataSet.builder(NumassPoint)
|
def builder = DataSet.builder(NumassPoint)
|
||||||
|
|
||||||
hvs.each { hv ->
|
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
|
it.voltage == hv
|
||||||
}.collect()));
|
}.collect()));
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import hep.dataforge.meta.Meta
|
|||||||
import inr.numass.NumassPlugin
|
import inr.numass.NumassPlugin
|
||||||
import inr.numass.actions.TimeAnalyzerAction
|
import inr.numass.actions.TimeAnalyzerAction
|
||||||
import inr.numass.data.GeneratorKt
|
import inr.numass.data.GeneratorKt
|
||||||
import inr.numass.data.api.SimpleNumassPoint
|
|
||||||
import org.apache.commons.math3.random.JDKRandomGenerator
|
import org.apache.commons.math3.random.JDKRandomGenerator
|
||||||
|
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
@ -36,7 +35,7 @@ new GrindShell(ctx).eval {
|
|||||||
GeneratorKt.generateBlock(Instant.now().plusNanos(it * length), length, chain)
|
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)
|
def meta = Meta.empty()//Grind.buildMeta(plotHist: false)
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ fun main(args: Array<String>) {
|
|||||||
generateBlock(Instant.now().plusNanos(it * length), length, generator)
|
generateBlock(Instant.now().plusNanos(it * length), length, generator)
|
||||||
}
|
}
|
||||||
|
|
||||||
val point = SimpleNumassPoint(10000.0, blocks)
|
val point = SimpleNumassPoint(blocks, 10000.0)
|
||||||
|
|
||||||
val meta = buildMeta {
|
val meta = buildMeta {
|
||||||
"t0" to 1e7
|
"t0" to 1e7
|
||||||
|
@ -50,10 +50,10 @@ fun main(args: Array<String>) {
|
|||||||
putStatic(
|
putStatic(
|
||||||
"point_${hv.toInt()}",
|
"point_${hv.toInt()}",
|
||||||
SimpleNumassPoint(
|
SimpleNumassPoint(
|
||||||
hv,
|
|
||||||
all.points.filter {
|
all.points.filter {
|
||||||
it.voltage == hv
|
it.voltage == hv
|
||||||
}.collect(Collectors.toList())
|
}.collect(Collectors.toList()),
|
||||||
|
hv
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ object Threshold {
|
|||||||
.flatMap { set -> set.points.toList() }
|
.flatMap { set -> set.points.toList() }
|
||||||
.groupBy { it.voltage }
|
.groupBy { it.voltage }
|
||||||
.forEach { key, value ->
|
.forEach { key, value ->
|
||||||
val point = SimpleNumassPoint(key, value)
|
val point = SimpleNumassPoint(value, key)
|
||||||
val name = key.toInt().toString()
|
val name = key.toInt().toString()
|
||||||
dataBuilder.putStatic(name, point, buildMeta("meta", "voltage" to key));
|
dataBuilder.putStatic(name, point, buildMeta("meta", "voltage" to key));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user