Control update

This commit is contained in:
Alexander Nozik 2018-03-14 21:42:29 +03:00
parent 65d24017d8
commit cf3268244e
3 changed files with 43 additions and 34 deletions

View File

@ -3,9 +3,11 @@ package inr.numass.data
import hep.dataforge.io.envelopes.Envelope
import hep.dataforge.meta.Meta
import hep.dataforge.meta.MetaBuilder
import inr.numass.data.api.NumassBlock
import inr.numass.data.api.NumassPoint
import inr.numass.data.api.NumassSet
import inr.numass.data.api.SimpleNumassPoint
import inr.numass.data.storage.ProtoBlock
import java.io.InputStream
import java.util.stream.Collectors
import java.util.stream.Stream
@ -43,9 +45,16 @@ object NumassDataUtils {
/**
* Get valid data stream utilizing compression if it is present
*/
val Envelope.dataStream : InputStream
get() = if(this.meta.getString("compression", "none") == "zlib"){
val Envelope.dataStream: InputStream
get() = if (this.meta.getString("compression", "none") == "zlib") {
ZipInputStream(this.data.stream)
} else {
this.data.stream
}
val NumassBlock.channel: Int
get() = if (this is ProtoBlock) {
this.channel
} else {
0
}

View File

@ -43,36 +43,6 @@ class ProtoNumassPoint(private val envelope: Envelope) : NumassPoint {
return envelope.meta
}
class ProtoBlock(val channel: Int, private val block: NumassProto.Point.Channel.Block, private val meta: Meta) : NumassBlock {
override fun getStartTime(): Instant {
return ofEpochNanos(block.time)
}
override fun getLength(): Duration {
return Duration.ofNanos((meta.getDouble("params.b_size") / meta.getDouble("params.sample_freq") * 1e9).toLong())
}
override fun getEvents(): Stream<NumassEvent> {
val blockTime = startTime
if (block.hasEvents()) {
val events = block.events
return IntStream.range(0, events.timesCount).mapToObj { i -> NumassEvent(events.getAmplitudes(i).toShort(), blockTime, events.getTimes(i)) }
} else {
return Stream.empty()
}
}
override fun getFrames(): Stream<NumassFrame> {
val tickSize = Duration.ofNanos((1e9 / meta.getInt("params.sample_freq")).toLong())
return block.framesList.stream().map { frame ->
val time = startTime.plusNanos(frame.time)
val data = frame.data.asReadOnlyByteBuffer()
NumassFrame(time, tickSize, data.asShortBuffer())
}
}
}
companion object {
fun readFile(path: Path): ProtoNumassPoint {
return ProtoNumassPoint(NumassFileEnvelope.open(path, true))
@ -85,3 +55,33 @@ class ProtoNumassPoint(private val envelope: Envelope) : NumassPoint {
}
}
}
class ProtoBlock(val channel: Int, private val block: NumassProto.Point.Channel.Block, private val meta: Meta) : NumassBlock {
override fun getStartTime(): Instant {
return ProtoNumassPoint.ofEpochNanos(block.time)
}
override fun getLength(): Duration {
return Duration.ofNanos((meta.getDouble("params.b_size") / meta.getDouble("params.sample_freq") * 1e9).toLong())
}
override fun getEvents(): Stream<NumassEvent> {
val blockTime = startTime
if (block.hasEvents()) {
val events = block.events
return IntStream.range(0, events.timesCount).mapToObj { i -> NumassEvent(events.getAmplitudes(i).toShort(), blockTime, events.getTimes(i)) }
} else {
return Stream.empty()
}
}
override fun getFrames(): Stream<NumassFrame> {
val tickSize = Duration.ofNanos((1e9 / meta.getInt("params.sample_freq")).toLong())
return block.framesList.stream().map { frame ->
val time = startTime.plusNanos(frame.time)
val data = frame.data.asReadOnlyByteBuffer()
NumassFrame(time, tickSize, data.asShortBuffer())
}
}
}

View File

@ -55,7 +55,7 @@ class AmplitudeView(
private val container = PlotContainer(frame).apply {
val binnintSelector: ChoiceBox<Int> = ChoiceBox(FXCollections.observableArrayList(1, 2, 5, 10, 20, 50)).apply {
val binningSelector: ChoiceBox<Int> = ChoiceBox(FXCollections.observableArrayList(1, 2, 5, 10, 20, 50)).apply {
minWidth = 0.0
selectionModel.selectLast()
binningProperty.bind(this.selectionModel.selectedItemProperty())
@ -64,7 +64,7 @@ class AmplitudeView(
minWidth = 0.0
this.selectedProperty().bindBidirectional(normalizeProperty)
}
addToSideBar(0, binnintSelector, normalizeSwitch)
addToSideBar(0, binningSelector, normalizeSwitch)
}
private val data: ObservableMap<String, NumassPoint> = FXCollections.observableHashMap()