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> override val events: Stream<NumassEvent>
get() = if (block.hasEvents()) { get() = if (block.hasEvents()) {
val events = block.events 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) } IntStream.range(0, events.timesCount).mapToObj { i -> NumassEvent(events.getAmplitudes(i).toShort(), events.getTimes(i), this) }
} else { } else {
Stream.empty() Stream.empty()

View File

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

View File

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

View File

@ -2,16 +2,18 @@ package inr.numass.viewer
import hep.dataforge.fx.meta.MetaViewer import hep.dataforge.fx.meta.MetaViewer
import inr.numass.data.analyzers.NumassAnalyzer 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.*
import tornadofx.controlsfx.borders import tornadofx.controlsfx.borders
import tornadofx.controlsfx.toGlyph
class PointInfoView(val point: CachedPoint) : MetaViewer(point.meta) { class PointInfoView(val point: CachedPoint) : MetaViewer(point.meta) {
private val count: Int by lazy {
runBlocking { val countProperty = SimpleIntegerProperty(0)
point.spectrum.await().sumBy { it.getValue(NumassAnalyzer.COUNT_KEY).int } var count by countProperty
}
}
override val root = super.root.apply { override val root = super.root.apply {
top { top {
@ -19,16 +21,30 @@ class PointInfoView(val point: CachedPoint) : MetaViewer(point.meta) {
borders { borders {
lineBorder().build() 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 { row {
hbox { hbox {
label("Total number of events: ") label("Total number of events: ")
label("$count") label {
textProperty().bind(countProperty.asString())
}
} }
} }
row { row {
hbox { hbox {
label("Total count rate: ") 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) })
}
} }
} }
} }