Fixes in context builder and GUI

This commit is contained in:
Alexander Nozik 2018-05-09 17:05:45 +03:00
parent eef07d565e
commit 1072f56815
4 changed files with 39 additions and 20 deletions

View File

@ -102,6 +102,9 @@ class ProtoBlock(val channel: Int, private val block: NumassProto.Point.Channel.
override val events: Stream<NumassEvent>
get() = if (block.hasEvents()) {
val events = block.events
if(events.timesCount!= events.amplitudesCount){
LoggerFactory.getLogger(javaClass).error("The block is broken. Number of times is ${events.timesCount} and number of amplitudes is ${events.amplitudesCount}")
}
IntStream.range(0, events.timesCount).mapToObj { i -> NumassEvent(events.getAmplitudes(i).toShort(), events.getTimes(i), this) }
} else {
Stream.empty()

View File

@ -15,8 +15,8 @@ import inr.numass.data.storage.NumassStorageFactory
fun main(args: Array<String>) {
val context = buildContext("NUMASS", NumassPlugin::class.java, FXPlotManager::class.java) {
rootDir = "D:\\Work\\Numass\\sterile\\2017_11"
dataDir = "D:\\Work\\Numass\\data\\2017_11"
rootDir = "D:\\Work\\Numass\\sterile\\2018_04"
dataDir = "D:\\Work\\Numass\\data\\2018_04"
}
val storage = NumassStorageFactory.buildLocal(context, "Fill_2", true, false);

View File

@ -29,19 +29,19 @@ import kotlinx.coroutines.experimental.async
private val analyzer = SimpleAnalyzer()
class CachedPoint(point: NumassPoint) : NumassPoint by point {
private val lazyBlocks: () -> List<NumassBlock> = { point.blocks }
class CachedPoint(val point: NumassPoint) : NumassPoint by point {
override val blocks: List<NumassBlock>
get() = lazyBlocks()
override val blocks: List<NumassBlock> by lazy { point.blocks }
override val meta: Meta = point.meta
val channelSpectra: Deferred<Map<Int, Table>> = async(start = CoroutineStart.LAZY) {
val channelSpectra: Deferred<Map<Int, Table>>
get() = async(start = CoroutineStart.LAZY) {
return@async point.channels.mapValues { (_, value) -> analyzer.getAmplitudeSpectrum(value) }
}
val spectrum: Deferred<Table> = async(start = CoroutineStart.LAZY) {
val spectrum: Deferred<Table>
get() = async(start = CoroutineStart.LAZY) {
analyzer.getAmplitudeSpectrum(point)
}
}

View File

@ -2,16 +2,18 @@ package inr.numass.viewer
import hep.dataforge.fx.meta.MetaViewer
import inr.numass.data.analyzers.NumassAnalyzer
import kotlinx.coroutines.experimental.runBlocking
import javafx.beans.property.SimpleIntegerProperty
import kotlinx.coroutines.experimental.async
import org.controlsfx.glyphfont.FontAwesome
import tornadofx.*
import tornadofx.controlsfx.borders
import tornadofx.controlsfx.toGlyph
class PointInfoView(val point: CachedPoint) : MetaViewer(point.meta) {
private val count: Int by lazy {
runBlocking {
point.spectrum.await().sumBy { it.getValue(NumassAnalyzer.COUNT_KEY).int }
}
}
val countProperty = SimpleIntegerProperty(0)
var count by countProperty
override val root = super.root.apply {
top {
@ -19,16 +21,30 @@ class PointInfoView(val point: CachedPoint) : MetaViewer(point.meta) {
borders {
lineBorder().build()
}
row {
button(graphic = FontAwesome.Glyph.REFRESH.toGlyph()) {
action {
async {
val res = point.spectrum.await().sumBy { it.getValue(NumassAnalyzer.COUNT_KEY).int }
runLater { count = res }
}
}
}
}
row {
hbox {
label("Total number of events: ")
label("$count")
label {
textProperty().bind(countProperty.asString())
}
}
}
row {
hbox {
label("Total count rate: ")
label(String.format("%.2f", count.toDouble() / point.length.toMillis() * 1000))
label {
textProperty().bind(countProperty.stringBinding { String.format("%.2f", it!!.toDouble() / point.length.toMillis() * 1000) })
}
}
}
}