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 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))
|
||||
|
@ -23,7 +23,7 @@ object NumassDataUtils {
|
||||
override val points: Stream<out NumassPoint> by lazy {
|
||||
val points = sets.stream().flatMap<NumassPoint> { it.points }
|
||||
.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 {
|
||||
|
@ -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) }
|
||||
|
||||
|
@ -15,7 +15,7 @@ import java.util.stream.Stream
|
||||
interface NumassPoint : Metoid, NumassBlock {
|
||||
|
||||
|
||||
val blocks: Stream<NumassBlock>
|
||||
val blocks: List<NumassBlock>
|
||||
|
||||
/**
|
||||
* 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<NumassEvent>
|
||||
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<NumassFrame>
|
||||
get() = blocks.flatMap { it.frames }
|
||||
get() = blocks.stream().flatMap { it.frames }
|
||||
|
||||
companion object {
|
||||
|
||||
|
@ -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<NumassBlock>
|
||||
class SimpleNumassPoint(override val blocks: List<NumassBlock>, meta: Meta) : MetaHolder(meta), NumassPoint {
|
||||
|
||||
/**
|
||||
* Input blocks must be sorted
|
||||
* @param voltage
|
||||
* @param blocks
|
||||
*/
|
||||
constructor(voltage: Double, blocks: Collection<NumassBlock>) : super(MetaBuilder("point").setValue(NumassPoint.HV_KEY, voltage)) {
|
||||
this.blockList = blocks.sortedBy { it.startTime }
|
||||
}
|
||||
constructor(blocks: Collection<NumassBlock>, voltage: Double) :
|
||||
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")
|
||||
|
||||
|
||||
return SimpleNumassPoint(pointMeta, listOf<NumassBlock>(block))
|
||||
return SimpleNumassPoint(listOf<NumassBlock>(block), pointMeta)
|
||||
}
|
||||
|
||||
@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 blocks: Stream<NumassBlock>
|
||||
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<NumassBlock> 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")) {
|
||||
|
@ -28,13 +28,14 @@ class ProtoNumassPoint(override val meta: Meta, protoBuilder: () -> NumassProto.
|
||||
|
||||
val proto: NumassProto.Point by lazy(protoBuilder)
|
||||
|
||||
override val blocks: Stream<NumassBlock>
|
||||
get() = proto.channelsList.stream()
|
||||
override val blocks: List<NumassBlock> by lazy {
|
||||
proto.channelsList.stream()
|
||||
.flatMap { channel ->
|
||||
channel.blocksList.stream()
|
||||
.map { block -> ProtoBlock(channel.id.toInt(), block, this) }
|
||||
.sorted(Comparator.comparing<ProtoBlock, Instant> { 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
|
||||
}
|
||||
|
@ -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()));
|
||||
}
|
||||
|
@ -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)
|
||||
|
||||
|
@ -26,7 +26,7 @@ fun main(args: Array<String>) {
|
||||
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
|
||||
|
@ -50,10 +50,10 @@ fun main(args: Array<String>) {
|
||||
putStatic(
|
||||
"point_${hv.toInt()}",
|
||||
SimpleNumassPoint(
|
||||
hv,
|
||||
all.points.filter {
|
||||
it.voltage == hv
|
||||
}.collect(Collectors.toList())
|
||||
}.collect(Collectors.toList()),
|
||||
hv
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user