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

View File

@ -43,10 +43,23 @@ class ProtoNumassPoint(private val envelope: Envelope) : NumassPoint {
return envelope.meta return envelope.meta
} }
class ProtoBlock(val channel: Int, private val block: NumassProto.Point.Channel.Block, private val meta: Meta) : NumassBlock { companion object {
fun readFile(path: Path): ProtoNumassPoint {
return ProtoNumassPoint(NumassFileEnvelope.open(path, true))
}
fun ofEpochNanos(nanos: Long): Instant {
val seconds = Math.floorDiv(nanos, 1e9.toInt().toLong())
val reminder = (nanos % 1e9).toInt()
return Instant.ofEpochSecond(seconds, reminder.toLong())
}
}
}
class ProtoBlock(val channel: Int, private val block: NumassProto.Point.Channel.Block, private val meta: Meta) : NumassBlock {
override fun getStartTime(): Instant { override fun getStartTime(): Instant {
return ofEpochNanos(block.time) return ProtoNumassPoint.ofEpochNanos(block.time)
} }
override fun getLength(): Duration { override fun getLength(): Duration {
@ -71,17 +84,4 @@ class ProtoNumassPoint(private val envelope: Envelope) : NumassPoint {
NumassFrame(time, tickSize, data.asShortBuffer()) NumassFrame(time, tickSize, data.asShortBuffer())
} }
} }
}
companion object {
fun readFile(path: Path): ProtoNumassPoint {
return ProtoNumassPoint(NumassFileEnvelope.open(path, true))
}
fun ofEpochNanos(nanos: Long): Instant {
val seconds = Math.floorDiv(nanos, 1e9.toInt().toLong())
val reminder = (nanos % 1e9).toInt()
return Instant.ofEpochSecond(seconds, reminder.toLong())
}
}
} }

View File

@ -55,7 +55,7 @@ class AmplitudeView(
private val container = PlotContainer(frame).apply { 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 minWidth = 0.0
selectionModel.selectLast() selectionModel.selectLast()
binningProperty.bind(this.selectionModel.selectedItemProperty()) binningProperty.bind(this.selectionModel.selectedItemProperty())
@ -64,7 +64,7 @@ class AmplitudeView(
minWidth = 0.0 minWidth = 0.0
this.selectedProperty().bindBidirectional(normalizeProperty) this.selectedProperty().bindBidirectional(normalizeProperty)
} }
addToSideBar(0, binnintSelector, normalizeSwitch) addToSideBar(0, binningSelector, normalizeSwitch)
} }
private val data: ObservableMap<String, NumassPoint> = FXCollections.observableHashMap() private val data: ObservableMap<String, NumassPoint> = FXCollections.observableHashMap()