Using viewer version 0.5 by default
This commit is contained in:
parent
ab5c97252e
commit
252002db5a
@ -15,7 +15,7 @@ if (!hasProperty('mainClass')) {
|
||||
|
||||
mainClassName = mainClass
|
||||
|
||||
version = "0.4.0"
|
||||
version = "0.5.0"
|
||||
|
||||
description = "The viewer for numass data"
|
||||
|
||||
|
@ -70,7 +70,7 @@ class AmplitudeView(
|
||||
private val data: ObservableMap<String, NumassPoint> = FXCollections.observableHashMap()
|
||||
private val plots: ObservableMap<String, Goal<DataPlot>> = FXCollections.observableHashMap()
|
||||
|
||||
val isEmpty = booleanBinding(data){data.isEmpty()}
|
||||
val isEmpty = booleanBinding(data) { data.isEmpty() }
|
||||
|
||||
private val progress = object : DoubleBinding() {
|
||||
init {
|
||||
@ -130,9 +130,8 @@ class AmplitudeView(
|
||||
} else {
|
||||
NumassAnalyzer.COUNT_KEY
|
||||
}
|
||||
val seriesName = String.format("%s: %.2f", key, point.voltage)
|
||||
DataPlot.plot(
|
||||
seriesName,
|
||||
key,
|
||||
XYAdapter(NumassAnalyzer.CHANNEL_KEY, valueAxis),
|
||||
NumassDataUtils.spectrumWithBinning(getSpectrum(point), binning)
|
||||
).configure {
|
||||
|
@ -3,15 +3,17 @@ package inr.numass.viewer
|
||||
import hep.dataforge.kodex.configure
|
||||
import hep.dataforge.kodex.fx.dfIcon
|
||||
import hep.dataforge.kodex.fx.plots.PlotContainer
|
||||
import hep.dataforge.kodex.fx.runGoal
|
||||
import hep.dataforge.kodex.fx.ui
|
||||
import hep.dataforge.plots.PlotFrame
|
||||
import hep.dataforge.plots.data.TimePlot
|
||||
import hep.dataforge.plots.jfreechart.JFreeChartFrame
|
||||
import inr.numass.data.api.NumassSet
|
||||
import javafx.collections.FXCollections
|
||||
import javafx.collections.ObservableList
|
||||
import javafx.collections.MapChangeListener
|
||||
import javafx.collections.ObservableMap
|
||||
import javafx.scene.image.ImageView
|
||||
import tornadofx.*
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
|
||||
/**
|
||||
@ -30,36 +32,31 @@ class HVView : View(title = "High voltage time plot", icon = ImageView(dfIcon))
|
||||
center = PlotContainer(frame).root
|
||||
}
|
||||
|
||||
private val data: ObservableList<NumassSet> = FXCollections.observableArrayList()
|
||||
private val data: ObservableMap<String, NumassSet> = FXCollections.observableHashMap()
|
||||
val isEmpty = booleanBinding(data) { data.isEmpty() }
|
||||
|
||||
init {
|
||||
data.onChange { change ->
|
||||
frame.plots.clear()
|
||||
container.sideBarExpanded = false
|
||||
|
||||
val progress = AtomicInteger(0);
|
||||
data.addListener { change: MapChangeListener.Change<out String, out NumassSet> ->
|
||||
if (change.wasRemoved()) {
|
||||
frame.remove(change.key)
|
||||
}
|
||||
if (change.wasAdded()) {
|
||||
runLater { container.progress = -1.0 }
|
||||
|
||||
change.list.forEach { data ->
|
||||
runAsync {
|
||||
val res = data.hvData
|
||||
runLater { container.progress = progress.incrementAndGet().toDouble() / change.list.size }
|
||||
res
|
||||
runGoal("hvData[${change.key}]") {
|
||||
change.valueAdded.hvData
|
||||
} ui { hvData ->
|
||||
hvData.ifPresent {
|
||||
for (dp in it) {
|
||||
val blockName = dp.getString("block", "default").replace(".", "_");
|
||||
//val blockName = dp.getString("block", "default").replace(".", "_");
|
||||
//val opt = frame.opt(blockName)
|
||||
val plot = frame.opt(blockName).orElseGet {
|
||||
TimePlot(blockName).configure {
|
||||
val plot = frame.opt(change.key).orElseGet {
|
||||
TimePlot(change.key).configure {
|
||||
"connectionType" to "step"
|
||||
"thickness" to 2
|
||||
"showLine" to true
|
||||
"showSymbol" to false
|
||||
"showErrors" to false
|
||||
}
|
||||
.apply { frame.add(this) }
|
||||
}.apply { frame.add(this) }
|
||||
} as TimePlot;
|
||||
plot.put(dp.getValue("timestamp").timeValue(), dp.getValue("value"))
|
||||
}
|
||||
@ -67,20 +64,17 @@ class HVView : View(title = "High voltage time plot", icon = ImageView(dfIcon))
|
||||
container.progress = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun update(vararg sets: NumassSet) {
|
||||
data.setAll(*sets)
|
||||
fun add(id: String, set: NumassSet) {
|
||||
data.put(id, set)
|
||||
}
|
||||
|
||||
fun add(set: NumassSet) {
|
||||
this.data.add(set)
|
||||
}
|
||||
|
||||
fun remove(set: NumassSet) {
|
||||
this.data.remove(set);
|
||||
fun remove(id: String) {
|
||||
data.remove(id);
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,6 +3,8 @@ package inr.numass.viewer
|
||||
import hep.dataforge.kodex.configure
|
||||
import hep.dataforge.kodex.fx.dfIcon
|
||||
import hep.dataforge.kodex.fx.plots.PlotContainer
|
||||
import hep.dataforge.kodex.fx.runGoal
|
||||
import hep.dataforge.kodex.fx.ui
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.plots.PlotFrame
|
||||
import hep.dataforge.plots.data.DataPlot
|
||||
@ -145,9 +147,11 @@ class SpectrumView(
|
||||
frame.remove(change.key);
|
||||
}
|
||||
|
||||
if (change.wasAdded()) {
|
||||
updateView()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSpectrum(point: NumassPoint): Table {
|
||||
return cache.computeIfAbsent(point) { analyzer.getSpectrum(point, Meta.empty()) }
|
||||
@ -166,7 +170,7 @@ class SpectrumView(
|
||||
}
|
||||
} as DataPlot
|
||||
|
||||
runAsync {
|
||||
runGoal("spectrumData[$name]") {
|
||||
set.points.map { point ->
|
||||
val count = NumassAnalyzer.countInWindow(getSpectrum(point), loChannel.toShort(), upChannel.toShort());
|
||||
val seconds = point.length.toMillis() / 1000.0;
|
||||
|
@ -2,9 +2,11 @@ package inr.numass.viewer
|
||||
|
||||
import hep.dataforge.context.Context
|
||||
import hep.dataforge.context.Global
|
||||
import hep.dataforge.exceptions.StorageException
|
||||
import hep.dataforge.fx.fragments.FragmentWindow
|
||||
import hep.dataforge.fx.fragments.LogFragment
|
||||
import hep.dataforge.kodex.fx.dfIcon
|
||||
import hep.dataforge.kodex.fx.runGoal
|
||||
import hep.dataforge.kodex.fx.ui
|
||||
import hep.dataforge.storage.api.Loader
|
||||
import hep.dataforge.storage.api.Storage
|
||||
import hep.dataforge.storage.filestorage.FileStorageFactory
|
||||
@ -13,7 +15,7 @@ import inr.numass.data.api.NumassPoint
|
||||
import inr.numass.data.api.NumassSet
|
||||
import inr.numass.data.storage.NumassDataLoader
|
||||
import inr.numass.data.storage.NumassStorage
|
||||
import javafx.application.Platform
|
||||
import javafx.beans.property.SimpleBooleanProperty
|
||||
import javafx.beans.property.SimpleObjectProperty
|
||||
import javafx.beans.property.SimpleStringProperty
|
||||
import javafx.geometry.Insets
|
||||
@ -45,13 +47,40 @@ class StorageView(private val context: Context = Global.instance()) : View(title
|
||||
private val hvView: HVView by inject();
|
||||
private val scView: SlowControlView by inject();
|
||||
|
||||
private data class NamedPoint(val id: String, val point: NumassPoint)
|
||||
private inner class Container(val id: String, val content: Any) {
|
||||
val checkedProperty = SimpleBooleanProperty(false)
|
||||
var checked by checkedProperty
|
||||
|
||||
init {
|
||||
checkedProperty.onChange { selected ->
|
||||
when (content) {
|
||||
is NumassPoint -> {
|
||||
if (selected) {
|
||||
ampView.add(id, content)
|
||||
} else {
|
||||
ampView.remove(id)
|
||||
}
|
||||
}
|
||||
is NumassSet -> {
|
||||
if (selected) {
|
||||
spectrumView.add(id, content)
|
||||
hvView.add(id, content)
|
||||
} else {
|
||||
spectrumView.remove(id)
|
||||
hvView.remove(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override val root = borderpane {
|
||||
top {
|
||||
toolbar {
|
||||
prefHeight = 40.0
|
||||
button("load") {
|
||||
button("Load") {
|
||||
action {
|
||||
val chooser = DirectoryChooser()
|
||||
chooser.title = "Select numass storage root"
|
||||
@ -82,56 +111,43 @@ class StorageView(private val context: Context = Global.instance()) : View(title
|
||||
hgrow = Priority.ALWAYS
|
||||
}
|
||||
togglebutton("Console") {
|
||||
|
||||
isSelected = false
|
||||
FragmentWindow.build(this) {
|
||||
LogFragment().apply {
|
||||
addRootLogHandler()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
center {
|
||||
splitpane {
|
||||
treeview<Any> {
|
||||
treeview<Container> {
|
||||
storageProperty.onChange {
|
||||
root = TreeItem(it)
|
||||
if (it != null) {
|
||||
root = TreeItem(Container("root", it))
|
||||
root.isExpanded = true
|
||||
populate { parent ->
|
||||
val value = parent.value
|
||||
val value = parent.value.content
|
||||
when (value) {
|
||||
is Storage -> value.shelves() + value.loaders()
|
||||
is NumassSet -> value.points.map { point -> NamedPoint("${getSetName(value)}/${point.voltage}", point) }.toList()
|
||||
is Storage -> (value.shelves() + value.loaders()).map { buildContainer(it, parent.value) }
|
||||
is NumassSet -> value.points.map { buildContainer(it, parent.value) }.toList()
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cellFormat { value ->
|
||||
when (value) {
|
||||
is Storage -> text = value.name
|
||||
when (value.content) {
|
||||
is Storage -> text = value.id
|
||||
is NumassSet -> {
|
||||
text = null
|
||||
graphic = checkbox {
|
||||
text = value.name
|
||||
val setName = getSetName(value)
|
||||
selectedProperty().onChange { selected ->
|
||||
if (selected) {
|
||||
spectrumView.add(setName, value)
|
||||
hvView.add(value)
|
||||
} else {
|
||||
spectrumView.remove(setName)
|
||||
hvView.remove(value)
|
||||
graphic = checkbox(value.id, value.checkedProperty)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
is NamedPoint -> {
|
||||
is NumassPoint -> {
|
||||
text = null
|
||||
graphic = checkbox {
|
||||
text = value.id
|
||||
selectedProperty().onChange { selected ->
|
||||
if (selected) {
|
||||
ampView.add(value.id, value.point)
|
||||
} else {
|
||||
ampView.remove(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
graphic = checkbox(value.id, value.checkedProperty)
|
||||
}
|
||||
else -> {
|
||||
text = (value as Loader).name
|
||||
@ -139,18 +155,22 @@ class StorageView(private val context: Context = Global.instance()) : View(title
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tabpane {
|
||||
tab("Amplitude spectra", ampView.root) {
|
||||
tab("Amplitude spectra") {
|
||||
content = ampView.root
|
||||
isClosable = false
|
||||
visibleWhen(ampView.isEmpty.not())
|
||||
//visibleWhen(ampView.isEmpty.not())
|
||||
}
|
||||
tab("HV", hvView.root) {
|
||||
tab("HV") {
|
||||
content = hvView.root
|
||||
isClosable = false
|
||||
visibleWhen(hvView.isEmpty.not())
|
||||
//visibleWhen(hvView.isEmpty.not())
|
||||
}
|
||||
tab("Numass spectra", spectrumView.root) {
|
||||
tab("Numass spectra") {
|
||||
content = spectrumView.root
|
||||
isClosable = false
|
||||
visibleWhen(spectrumView.isEmpty.not())
|
||||
//visibleWhen(spectrumView.isEmpty.not())
|
||||
}
|
||||
}
|
||||
setDividerPosition(0, 0.3);
|
||||
@ -162,46 +182,70 @@ class StorageView(private val context: Context = Global.instance()) : View(title
|
||||
|
||||
}
|
||||
|
||||
private fun getSetName(value: NumassSet): String {
|
||||
return if (value is NumassDataLoader) {
|
||||
value.path
|
||||
private fun buildContainer(content: Any, parent: Container): Container {
|
||||
return when (content) {
|
||||
is Storage -> {
|
||||
Container(content.fullPath, content)
|
||||
}
|
||||
is NumassSet -> {
|
||||
val id = if (content is NumassDataLoader) {
|
||||
content.path
|
||||
} else {
|
||||
value.name
|
||||
content.name
|
||||
}
|
||||
Container(id, content)
|
||||
}
|
||||
is NumassPoint -> {
|
||||
Container("${parent.id}/${content.voltage}".replace(".", "_"), content)
|
||||
}
|
||||
is Loader -> {
|
||||
Container(content.path, content);
|
||||
}
|
||||
else -> throw IllegalArgumentException("Unknown content type: ${content::class.java}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// private fun getSetName(value: NumassSet): String {
|
||||
// return if (value is NumassDataLoader) {
|
||||
// value.path
|
||||
// } else {
|
||||
// value.name
|
||||
// }
|
||||
// }
|
||||
|
||||
private fun loadDirectory(path: URI) {
|
||||
runGoal("loadDirectory[$path]") {
|
||||
title = "Load storage ($path)"
|
||||
progress = -1.0
|
||||
message = "Building numass storage tree..."
|
||||
val root = NumassStorage(context, FileStorageFactory.buildStorageMeta(path, true, true));
|
||||
setRootStorage(root)
|
||||
Platform.runLater { storageName = "Storage: " + path }
|
||||
NumassStorage(context, FileStorageFactory.buildStorageMeta(path, true, true)).also {
|
||||
progress = 1.0
|
||||
}
|
||||
}
|
||||
} ui {
|
||||
storage = it
|
||||
storageName = "Storage: " + path
|
||||
|
||||
fun setRootStorage(root: Storage) {
|
||||
runGoal("loadStorage[${root.name}]") {
|
||||
title = "Fill data to UI (" + root.name + ")"
|
||||
progress = -1.0
|
||||
runLater { statusBar.progress = -1.0 }
|
||||
|
||||
message = "Loading numass storage tree..."
|
||||
|
||||
runLater {
|
||||
try {
|
||||
storageProperty.set(root)
|
||||
} catch (ex: StorageException) {
|
||||
context.logger.error("Could not load the storage", ex);
|
||||
}
|
||||
}
|
||||
|
||||
// callback.setProgress(1, 1);
|
||||
runLater { statusBar.progress = 0.0 }
|
||||
message = "Numass storage tree loaded."
|
||||
progress = 1.0
|
||||
}
|
||||
}
|
||||
// fun setRootStorage(root: Storage) {
|
||||
// runGoal("loadStorage[${root.name}]") {
|
||||
// title = "Fill data to UI (" + root.name + ")"
|
||||
// progress = -1.0
|
||||
// runLater { statusBar.progress = -1.0 }
|
||||
//
|
||||
// message = "Loading numass storage tree..."
|
||||
//
|
||||
// runLater {
|
||||
// storage = root
|
||||
// }
|
||||
//
|
||||
// // callback.setProgress(1, 1);
|
||||
// runLater { statusBar.progress = 0.0 }
|
||||
// message = "Numass storage tree loaded."
|
||||
// progress = 1.0
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
@ -3,25 +3,23 @@ package inr.numass.viewer
|
||||
import ch.qos.logback.classic.Level
|
||||
import ch.qos.logback.classic.Logger
|
||||
import hep.dataforge.context.Global
|
||||
import hep.dataforge.kodex.fx.dfIcon
|
||||
import hep.dataforge.storage.commons.StorageManager
|
||||
import javafx.stage.Stage
|
||||
import org.slf4j.LoggerFactory
|
||||
import tornadofx.*
|
||||
|
||||
/**
|
||||
* Created by darksnake on 14-Apr-17.
|
||||
*/
|
||||
class Viewer : App(MainView::class) {
|
||||
|
||||
override fun start(stage: Stage) {
|
||||
stage.icons += dfIcon
|
||||
class Viewer : App(StorageView::class) {
|
||||
init{
|
||||
(LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME) as Logger).level = Level.INFO
|
||||
Global.setDefaultContext(Global.instance())
|
||||
StorageManager().startGlobal()
|
||||
super.start(stage)
|
||||
}
|
||||
|
||||
// override fun start(stage: Stage) {
|
||||
// stage.icons += dfIcon
|
||||
//// (LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME) as Logger).level = Level.INFO
|
||||
// super.start(stage)
|
||||
// }
|
||||
|
||||
override fun stop() {
|
||||
super.stop()
|
||||
Global.terminate();
|
||||
|
@ -26,9 +26,9 @@ class ViewerComponentsTest : View(title = "Numass viewer test", icon = ImageView
|
||||
|
||||
private val cache: MutableMap<NumassPoint, Table> = ConcurrentHashMap();
|
||||
|
||||
val amp = AmplitudeView(cache = cache)
|
||||
val sp = SpectrumView(cache = cache)
|
||||
val hv = HVView()
|
||||
val amp: AmplitudeView by inject(params = mapOf("cache" to cache))//= AmplitudeView(cache = cache)
|
||||
val sp: SpectrumView by inject(params = mapOf("cache" to cache))
|
||||
val hv: HVView by inject()
|
||||
|
||||
override val root = borderpane {
|
||||
top {
|
||||
@ -55,7 +55,7 @@ class ViewerComponentsTest : View(title = "Numass viewer test", icon = ImageView
|
||||
fun update(set: NumassSet) {
|
||||
amp.setAll(set.points.filter { it.voltage != 16000.0 }.collect(Collectors.toMap({ "point_${it.voltage}" }, { it })));
|
||||
sp.add("test", set);
|
||||
hv.update(set)
|
||||
hv.add(set.name, set)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user