KTask!
This commit is contained in:
parent
97f27cdad1
commit
bb9a3c6fa8
@ -22,7 +22,7 @@ public abstract class AbstractAnalyzer implements NumassAnalyzer {
|
||||
public static String TIME_KEY = "timestamp";
|
||||
|
||||
public static String[] NAME_LIST = {LENGTH_KEY, COUNT_KEY, COUNT_RATE_KEY, COUNT_RATE_ERROR_KEY, WINDOW_KEY, TIME_KEY};
|
||||
public static String[] NAME_LIST_WITH_HV = {HV_KEY, LENGTH_KEY, COUNT_KEY, COUNT_RATE_KEY, COUNT_RATE_ERROR_KEY, WINDOW_KEY, TIME_KEY};
|
||||
// public static String[] NAME_LIST_WITH_HV = {HV_KEY, LENGTH_KEY, COUNT_KEY, COUNT_RATE_KEY, COUNT_RATE_ERROR_KEY, WINDOW_KEY, TIME_KEY};
|
||||
@Nullable
|
||||
private final SignalProcessor processor;
|
||||
|
||||
|
@ -60,7 +60,7 @@ public class NumassPlugin extends BasicPlugin {
|
||||
public static JFreeChartFrame displayJFreeChart(String title, double width, double height, Meta meta) {
|
||||
JFreeChartFrame frame = new JFreeChartFrame(meta);
|
||||
frame.configureValue("title", title);
|
||||
PlotContainer.Companion.display(frame,title,width,height);
|
||||
PlotContainer.Companion.display(frame, title, width, height);
|
||||
return frame;
|
||||
}
|
||||
|
||||
@ -96,6 +96,8 @@ public class NumassPlugin extends BasicPlugin {
|
||||
actions.putTask(NumassFitScanSummaryTask.class);
|
||||
actions.putTask(NumassFitTask.class);
|
||||
actions.putTask(NumassFitSummaryTask.class);
|
||||
actions.put(NumassTasksKt.getSelectDataTask());
|
||||
actions.put(NumassTasksKt.getMonitorTableTask());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,7 +27,7 @@ public class AnalyzeDataAction extends OneToOneAction<NumassSet, Table> {
|
||||
//TODO add processor here
|
||||
NumassAnalyzer analyzer = new SmartAnalyzer();
|
||||
Table res = analyzer.analyzeSet(input, inputMeta);
|
||||
output(context, name, stream -> NumassUtils.writeSomething(stream, inputMeta, res));
|
||||
output(context, name, stream -> NumassUtils.write(stream, inputMeta, res));
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ public class MergeDataAction extends ManyToOneAction<Table, Table> {
|
||||
|
||||
@Override
|
||||
protected void afterGroup(Context context, String groupName, Meta outputMeta, Table output) {
|
||||
output(context, groupName, stream -> NumassUtils.writeSomething(stream, outputMeta, output));
|
||||
output(context, groupName, stream -> NumassUtils.write(stream, outputMeta, output));
|
||||
}
|
||||
|
||||
private Values mergeDataPoints(Values dp1, Values dp2) {
|
||||
|
@ -136,7 +136,7 @@ public class MonitorCorrectAction extends OneToOneAction<Table, Table> {
|
||||
// }
|
||||
Table res = new ListTable(dataList);
|
||||
|
||||
output(context, name, stream -> NumassUtils.writeSomething(stream, meta, res));
|
||||
output(context, name, stream -> NumassUtils.write(stream, meta, res));
|
||||
|
||||
return res;
|
||||
}
|
||||
@ -201,7 +201,7 @@ public class MonitorCorrectAction extends OneToOneAction<Table, Table> {
|
||||
String monitorFileName = meta.getString("monitorFile", "monitor");
|
||||
ListTable data = new ListTable(monitorPoints);
|
||||
|
||||
output(context, monitorFileName, stream -> NumassUtils.writeSomething(stream, meta, data));
|
||||
output(context, monitorFileName, stream -> NumassUtils.write(stream, meta, data));
|
||||
// ColumnedDataWriter.writeTable(stream, TableTransform.sort(data, "Timestamp", true), "Monitor points", monitorNames);
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public class SubstractSpectrumAction extends OneToOneAction<Table, Table> {
|
||||
});
|
||||
|
||||
Table res = builder.build();
|
||||
output(context,name, stream -> NumassUtils.writeSomething(stream,inputMeta,res));
|
||||
output(context,name, stream -> NumassUtils.write(stream,inputMeta,res));
|
||||
return res;
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException("Could not read reference file", ex);
|
||||
|
@ -115,7 +115,7 @@ public class SummaryAction extends ManyToOneAction<FitState, Table> {
|
||||
|
||||
@Override
|
||||
protected void afterGroup(Context context, String groupName, Meta outputMeta, Table output) {
|
||||
output(context, groupName, stream -> NumassUtils.writeSomething(stream, outputMeta, output));
|
||||
output(context, groupName, stream -> NumassUtils.write(stream, outputMeta, output));
|
||||
super.afterGroup(context, groupName, outputMeta, output);
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ public class TransformDataAction extends OneToOneAction<Table, Table> {
|
||||
Table res = table.addColumn(ListColumn.build(table.getColumn(COUNT_RATE_KEY).getFormat(), cr.stream()))
|
||||
.addColumn(ListColumn.build(table.getColumn(COUNT_RATE_ERROR_KEY).getFormat(), crErr.stream()));
|
||||
|
||||
output(context, name, stream -> NumassUtils.writeSomething(stream, meta, res));
|
||||
output(context, name, stream -> NumassUtils.write(stream, meta, res));
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ public class NumassFitScanSummaryTask extends AbstractTask<Table> {
|
||||
pars.getValue("trap"));
|
||||
});
|
||||
Table res = TableTransform.sort(builder.build(), "m", true);
|
||||
output(context, nodeName, stream -> NumassUtils.writeSomething(stream,meta,res));
|
||||
output(context, nodeName, stream -> NumassUtils.write(stream,meta,res));
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -8,8 +8,6 @@ package inr.numass.tasks;
|
||||
import hep.dataforge.actions.GenericAction;
|
||||
import hep.dataforge.cache.CachePlugin;
|
||||
import hep.dataforge.context.Context;
|
||||
import hep.dataforge.data.CustomDataFilter;
|
||||
import hep.dataforge.data.DataFilter;
|
||||
import hep.dataforge.data.DataNode;
|
||||
import hep.dataforge.data.DataTree;
|
||||
import hep.dataforge.description.NodeDef;
|
||||
@ -33,7 +31,6 @@ import inr.numass.data.api.NumassSet;
|
||||
@NodeDef(name = "prepare")
|
||||
@NodeDef(name = "monitor")
|
||||
@NodeDef(name = "merge")
|
||||
@NodeDef(name = "data")
|
||||
public class NumassPrepareTask extends AbstractTask<Table> {
|
||||
|
||||
@Override
|
||||
@ -42,15 +39,7 @@ public class NumassPrepareTask extends AbstractTask<Table> {
|
||||
Context context = model.getContext();
|
||||
|
||||
//acquiring initial data. Data node could not be empty
|
||||
|
||||
DataFilter filter = new CustomDataFilter(config.getMeta("data"));
|
||||
|
||||
DataNode<NumassSet> data = filter.filter(input.checked(NumassSet.class));
|
||||
|
||||
// Meta dataMeta = config.getMeta("data");
|
||||
// URI storageUri = input.getCheckedData("dataRoot", URI.class).get();
|
||||
// DataSet.Builder<NumassData> dataBuilder = readData(getWork(model, input.getName()), context, storageUri, dataMeta);
|
||||
// DataNode<NumassData> data = dataBuilder.builder();
|
||||
DataNode<NumassSet> data = input.getCheckedNode("data", NumassSet.class);
|
||||
|
||||
//preparing table data
|
||||
Meta prepareMeta = config.getMeta("prepare");
|
||||
@ -89,110 +78,22 @@ public class NumassPrepareTask extends AbstractTask<Table> {
|
||||
protected void buildModel(TaskModel.Builder model, Meta meta) {
|
||||
model.configure(
|
||||
new MetaBuilder()
|
||||
.putNode(meta.getMetaOrEmpty("data"))
|
||||
.putNode(meta.getMetaOrEmpty("prepare"))
|
||||
.putNode(meta.getMetaOrEmpty("monitor"))
|
||||
.putNode(meta.getMetaOrEmpty("merge"))
|
||||
|
||||
);
|
||||
|
||||
if (meta.hasValue("data.from")) {
|
||||
model.data(meta.getString("data.from.*"));
|
||||
} else {
|
||||
model.data("*");
|
||||
}
|
||||
model.dependsOn("data", meta.getMetaOrEmpty("data"), "data");
|
||||
}
|
||||
|
||||
// private DataSet.Builder<NumassData> readData(Work callback, Context context, URI numassRoot, Meta meta) {
|
||||
//
|
||||
// NumassStorage storage = NumassStorage.buildNumassRoot(numassRoot, true, false);
|
||||
// CustomDataFilter filter = new CustomDataFilter().configure(meta);
|
||||
//
|
||||
// boolean forwardOnly = meta.getBoolean("forwardOnly", false);
|
||||
// boolean reverseOnly = meta.getBoolean("reverseOnly", false);
|
||||
//// SetDirectionUtility.load(context);
|
||||
//
|
||||
// DataSet.Builder<NumassData> builder = DataSet.builder(NumassData.class);
|
||||
// callback.setMaxProgress(StorageUtils.loaderStream(storage).count());
|
||||
// StorageUtils.loaderStream(storage).forEach(pair -> {
|
||||
// Loader loader = pair.getValue();
|
||||
// if (loader instanceof NumassDataLoader) {
|
||||
// NumassDataLoader nd = (NumassDataLoader) loader;
|
||||
// Data<NumassData> datum = buildData(context, nd, meta);
|
||||
// if (filter.acceptData(pair.getKey(), datum)) {
|
||||
// boolean accept = true;
|
||||
// if (forwardOnly || reverseOnly) {
|
||||
// boolean reversed = nd.isReversed();
|
||||
// accept = (reverseOnly && reversed) || (forwardOnly && !reversed);
|
||||
// }
|
||||
// if (accept) {
|
||||
// builder.putData(pair.getKey(), datum);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// callback.increaseProgress(1d);
|
||||
// });
|
||||
//
|
||||
// if (meta.getBoolean("loadLegacy", false)) {
|
||||
// storage.legacyFiles().forEach(nd -> {
|
||||
// Data<NumassData> datum = Data.buildStatic(nd);
|
||||
// if (filter.acceptData(nd.getName(), datum)) {
|
||||
// builder.putData("legacy." + nd.getName(), datum);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// //FIXME remove in later revisions
|
||||
//// SetDirectionUtility.save(context);
|
||||
//
|
||||
// return builder;
|
||||
// }
|
||||
|
||||
// private Data<NumassData> buildData(Context context, NumassDataLoader loader, Meta meta) {
|
||||
// if (meta.hasNode("debunch")) {
|
||||
// return Data.buildStatic(loader.applyRawTransformation(rp -> debunch(context, rp, meta.getMeta("debunch"))));
|
||||
// } else {
|
||||
// return Data.buildStatic(loader);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private NMPoint debunch(Context context, RawNMPoint point, Meta meta) {
|
||||
// int upper = meta.getInt("upperchanel", RawNMPoint.MAX_CHANEL);
|
||||
// int lower = meta.getInt("lowerchanel", 0);
|
||||
// double rejectionprob = meta.getDouble("rejectprob", 1e-10);
|
||||
// double framelength = meta.getDouble("framelength", 1);
|
||||
// double maxCR = meta.getDouble("maxcr", 500d);
|
||||
//
|
||||
// double cr = point.selectChanels(lower, upper).getCr();
|
||||
// if (cr < maxCR) {
|
||||
// DebunchReport report = new FrameAnalizer(rejectionprob, framelength, lower, upper).debunchPoint(point);
|
||||
// return new NMPoint(report.getPoint());
|
||||
// } else {
|
||||
// return new NMPoint(point);
|
||||
// }
|
||||
// }
|
||||
|
||||
private <T, R> DataNode<R> runAction(GenericAction<T, R> action, Context context, DataNode<T> data, Meta meta) {
|
||||
return action.run(context, data, meta);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void validate(TaskModel model) {
|
||||
// if (!model.meta().hasMeta("data")) {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "prepare";
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public NodeDescriptor getDescriptor() {
|
||||
// return new DescriptorBuilder(getName())
|
||||
// .addNode("prepare", PrepareDataAction.class)
|
||||
// .addNode("monitor", MonitorCorrectAction.class)
|
||||
// .addNode("merge", MergeDataAction.class)
|
||||
// .builder();
|
||||
// }
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ public class NumassUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeSomething(OutputStream stream, Meta meta, Markedup something) {
|
||||
public static void write(OutputStream stream, Meta meta, Markedup something) {
|
||||
writeEnvelope(stream, meta, out -> new SimpleMarkupRenderer(out).render(something.markup(meta)));
|
||||
}
|
||||
|
||||
|
38
numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt
Normal file
38
numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt
Normal file
@ -0,0 +1,38 @@
|
||||
package inr.numass.tasks
|
||||
|
||||
import hep.dataforge.data.CustomDataFilter
|
||||
import hep.dataforge.kodex.task
|
||||
import hep.dataforge.tables.ListTable
|
||||
import hep.dataforge.tables.Table
|
||||
import inr.numass.data.analyzers.SmartAnalyzer
|
||||
import inr.numass.data.api.NumassSet
|
||||
import inr.numass.utils.NumassUtils
|
||||
|
||||
val selectDataTask = task("data") {
|
||||
transform { data ->
|
||||
CustomDataFilter(meta).filter<NumassSet>(data.checked(NumassSet::class.java))
|
||||
}
|
||||
}
|
||||
|
||||
val monitorTableTask = task("monitor") {
|
||||
join<NumassSet, Table> {
|
||||
result { data ->
|
||||
val monitorVoltage = meta.getDouble("monitorVoltage", 16000.0);
|
||||
val analyzer = SmartAnalyzer()
|
||||
val analyzerMeta = meta.getMetaOrEmpty("analyzer")
|
||||
val builder = ListTable.Builder("timestamp", "count", "cr", "crErr")
|
||||
.rows(
|
||||
data.values.stream().parallel()
|
||||
.flatMap { it.points }
|
||||
.filter { it.voltage == monitorVoltage }
|
||||
.map { it -> analyzer.analyzePoint(it, analyzerMeta) }
|
||||
)
|
||||
|
||||
context.io().out("numass.monitor",name).use {
|
||||
NumassUtils.write(it, meta, builder.build())
|
||||
}
|
||||
|
||||
return@result builder.build();
|
||||
}
|
||||
}
|
||||
}
|
@ -13,15 +13,17 @@ import inr.numass.data.NumassDataUtils
|
||||
import inr.numass.data.analyzers.SimpleAnalyzer
|
||||
import inr.numass.data.api.NumassAnalyzer
|
||||
import inr.numass.data.api.NumassPoint
|
||||
import javafx.beans.Observable
|
||||
import javafx.beans.property.SimpleBooleanProperty
|
||||
import javafx.beans.property.SimpleObjectProperty
|
||||
import javafx.collections.FXCollections
|
||||
import javafx.collections.ObservableMap
|
||||
import javafx.concurrent.Task
|
||||
import javafx.scene.control.CheckBox
|
||||
import javafx.scene.control.ChoiceBox
|
||||
import javafx.scene.image.ImageView
|
||||
import tornadofx.*
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
class AmplitudeView(
|
||||
private val analyzer: NumassAnalyzer = SimpleAnalyzer(),
|
||||
@ -63,61 +65,109 @@ class AmplitudeView(
|
||||
}
|
||||
|
||||
private val data: MutableMap<String, NumassPoint> = HashMap();
|
||||
private val taskMap: ObservableMap<String, Task<DataPlot>> = FXCollections.observableHashMap();
|
||||
|
||||
init {
|
||||
binningProperty.onChange {
|
||||
putAll(data)
|
||||
}
|
||||
normalizeProperty.onChange {
|
||||
putAll(data)
|
||||
}
|
||||
taskMap.addListener { _: Observable ->
|
||||
runLater {
|
||||
val running = taskMap.values.count { it.isRunning }
|
||||
|
||||
if (running == 0) {
|
||||
container.progress = 1.0
|
||||
} else {
|
||||
container.progress = running.toDouble() / taskMap.size
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override val root = borderpane {
|
||||
center = container.root
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate or get spectrum from the cache
|
||||
*/
|
||||
private fun getSpectrum(point: NumassPoint): Table {
|
||||
return cache.computeIfAbsent(point) { analyzer.getSpectrum(point, Meta.empty()) }
|
||||
|
||||
}
|
||||
|
||||
private fun updateView() {
|
||||
fun cleanTasks() {
|
||||
runLater {
|
||||
taskMap.entries.filter { !it.value.isRunning }.forEach { taskMap.remove(it.key) }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Put or replace current plot with name `key`
|
||||
*/
|
||||
fun putOne(key: String, point: NumassPoint): Task<DataPlot> {
|
||||
val valueAxis = if (normalize) {
|
||||
NumassAnalyzer.COUNT_RATE_KEY
|
||||
} else {
|
||||
NumassAnalyzer.COUNT_KEY
|
||||
}
|
||||
|
||||
val progress = AtomicInteger(0);
|
||||
runLater { container.progress = 0.0 }
|
||||
data.put(key, point)
|
||||
|
||||
runAsync {
|
||||
val totalCount = data.size
|
||||
|
||||
data.map { entry ->
|
||||
val seriesName = String.format("%s: %.2f", entry.key, entry.value.voltage)
|
||||
DataPlot.plot(
|
||||
seriesName,
|
||||
XYAdapter(NumassAnalyzer.CHANNEL_KEY, valueAxis),
|
||||
NumassDataUtils.spectrumWithBinning(getSpectrum(entry.value), binning)
|
||||
).configure {
|
||||
"connectionType" to "step"
|
||||
"thickness" to 2
|
||||
"showLine" to true
|
||||
"showSymbol" to false
|
||||
"showErrors" to false
|
||||
"JFreeChart.cache" to true
|
||||
}.also {
|
||||
runLater { container.progress = progress.incrementAndGet().toDouble() / data.size }
|
||||
}
|
||||
val res = runAsync {
|
||||
val seriesName = String.format("%s: %.2f", key, point.voltage)
|
||||
DataPlot.plot(
|
||||
seriesName,
|
||||
XYAdapter(NumassAnalyzer.CHANNEL_KEY, valueAxis),
|
||||
NumassDataUtils.spectrumWithBinning(getSpectrum(point), binning)
|
||||
).configure {
|
||||
"connectionType" to "step"
|
||||
"thickness" to 2
|
||||
"showLine" to true
|
||||
"showSymbol" to false
|
||||
"showErrors" to false
|
||||
"JFreeChart.cache" to true
|
||||
}
|
||||
} ui { plots ->
|
||||
frame.setAll(plots)
|
||||
} ui { plot ->
|
||||
frame.add(plot)
|
||||
//detectorDataExportButton.isDisable = false
|
||||
}
|
||||
|
||||
taskMap.put(key, res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
fun update(map: Map<String, NumassPoint>) {
|
||||
synchronized(data) {
|
||||
//Remove obsolete keys
|
||||
data.keys.filter { !map.containsKey(it) }.forEach {
|
||||
data.remove(it)
|
||||
frame.remove(it);
|
||||
}
|
||||
this.data.putAll(map);
|
||||
updateView()
|
||||
fun putAll(data: Map<String, NumassPoint>): Map<String, Task<DataPlot>> {
|
||||
cleanTasks()
|
||||
return data.mapValues { entry ->
|
||||
putOne(entry.key, entry.value)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the plot and cancel loading task if it is in progress.
|
||||
*/
|
||||
fun remove(name: String) {
|
||||
frame.remove(name);
|
||||
taskMap[name]?.cancel();
|
||||
taskMap.remove(name);
|
||||
data.remove(name)
|
||||
}
|
||||
|
||||
/**
|
||||
* Set frame content to the given map. All keys not in the map are removed.
|
||||
*/
|
||||
fun setAll(map: Map<String, NumassPoint>) {
|
||||
taskMap.clear();
|
||||
//Remove obsolete keys
|
||||
data.keys.filter { !map.containsKey(it) }.forEach {
|
||||
remove(it)
|
||||
}
|
||||
this.putAll(map);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ import java.util.logging.Level
|
||||
/**
|
||||
* Created by darksnake on 14-Apr-17.
|
||||
*/
|
||||
@Deprecated("obsolete")
|
||||
class MainView : View("Numass data viewer") {
|
||||
override val root: AnchorPane by fxml("/fxml/MainView.fxml");
|
||||
|
||||
|
@ -51,6 +51,7 @@ import java.util.stream.Collectors
|
||||
*
|
||||
* Created by darksnake on 14-Apr-17.
|
||||
*/
|
||||
@Deprecated("obsolete")
|
||||
class NumassLoaderView : View() {
|
||||
override val root: AnchorPane by fxml("/fxml/NumassLoaderView.fxml")
|
||||
// lateinit var main: MainView
|
||||
@ -252,7 +253,7 @@ class NumassLoaderView : View() {
|
||||
} ui { hvData ->
|
||||
hvData.ifPresent {
|
||||
for (dp in it) {
|
||||
val block = dp.getString("block", "default")
|
||||
val block = dp.getString("block", "default").replace(".","_")
|
||||
if (!hvPlotData.has(block)) {
|
||||
hvPlotData.add(TimePlot(block))
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import inr.numass.data.api.NumassAnalyzer
|
||||
import inr.numass.data.api.NumassPoint
|
||||
import inr.numass.data.api.NumassSet
|
||||
import javafx.beans.property.SimpleIntegerProperty
|
||||
import javafx.geometry.Insets
|
||||
import javafx.geometry.Orientation
|
||||
import javafx.scene.image.ImageView
|
||||
import javafx.util.converter.IntegerStringConverter
|
||||
@ -98,11 +99,14 @@ class SpectrumView(
|
||||
vbox {
|
||||
label("Lo channel")
|
||||
textfield {
|
||||
prefWidth= 60.0
|
||||
textProperty().bindBidirectional(loChannelProperty.asObject(), IntegerStringConverter())
|
||||
}
|
||||
}
|
||||
|
||||
items += RangeSlider().apply {
|
||||
padding = Insets(0.0, 10.0, 0.0, 10.0)
|
||||
prefWidth = 300.0
|
||||
lowValue = 500.0
|
||||
highValue = 3100.0
|
||||
highValueProperty().bindBidirectional(upChannelProperty)
|
||||
@ -118,6 +122,7 @@ class SpectrumView(
|
||||
vbox {
|
||||
label("Up channel")
|
||||
textfield {
|
||||
prefWidth= 60.0
|
||||
textProperty().bindBidirectional(upChannelProperty.asObject(), IntegerStringConverter())
|
||||
}
|
||||
}
|
||||
|
130
numass-viewer/src/main/kotlin/inr/numass/viewer/StorageView.kt
Normal file
130
numass-viewer/src/main/kotlin/inr/numass/viewer/StorageView.kt
Normal file
@ -0,0 +1,130 @@
|
||||
package inr.numass.viewer
|
||||
|
||||
import hep.dataforge.context.Context
|
||||
import hep.dataforge.context.Global
|
||||
import hep.dataforge.exceptions.StorageException
|
||||
import hep.dataforge.kodex.fx.dfIcon
|
||||
import hep.dataforge.storage.filestorage.FileStorageFactory
|
||||
import inr.numass.NumassProperties
|
||||
import inr.numass.data.storage.NumassStorage
|
||||
import javafx.application.Platform
|
||||
import javafx.beans.property.SimpleObjectProperty
|
||||
import javafx.beans.property.SimpleStringProperty
|
||||
import javafx.collections.FXCollections
|
||||
import javafx.collections.ObservableList
|
||||
import javafx.geometry.Insets
|
||||
import javafx.scene.image.ImageView
|
||||
import javafx.scene.layout.Priority
|
||||
import javafx.scene.text.Font
|
||||
import javafx.stage.DirectoryChooser
|
||||
import org.controlsfx.control.StatusBar
|
||||
import tornadofx.*
|
||||
import java.io.File
|
||||
import java.net.URI
|
||||
|
||||
class StorageView : View(title = "Numass storage", icon = ImageView(dfIcon)) {
|
||||
|
||||
val selected: ObservableList<Any> = FXCollections.observableArrayList();
|
||||
|
||||
private val context: Context
|
||||
get() = Global.instance()
|
||||
|
||||
val storageProperty = SimpleObjectProperty<NumassStorage>()
|
||||
var storage by storageProperty
|
||||
|
||||
|
||||
val storageNameProperty = SimpleStringProperty("")
|
||||
var storageName by storageNameProperty
|
||||
|
||||
val statusBar = StatusBar();
|
||||
|
||||
override val root = borderpane {
|
||||
top {
|
||||
toolbar {
|
||||
prefHeight = 40.0
|
||||
button("load") {
|
||||
action {
|
||||
val chooser = DirectoryChooser()
|
||||
chooser.title = "Select numass storage root"
|
||||
val storageRoot = NumassProperties.getNumassProperty("numass.storage.root")
|
||||
try {
|
||||
if (storageRoot == null) {
|
||||
chooser.initialDirectory = File(".").absoluteFile
|
||||
} else {
|
||||
chooser.initialDirectory = File(storageRoot)
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
NumassProperties.setNumassProperty("numass.storage.root", null)
|
||||
}
|
||||
|
||||
val rootDir = chooser.showDialog(primaryStage.scene.window)
|
||||
|
||||
if (rootDir != null) {
|
||||
NumassProperties.setNumassProperty("numass.storage.root", rootDir.absolutePath)
|
||||
loadDirectory(rootDir.toURI())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
label(storageNameProperty) {
|
||||
padding = Insets(0.0, 0.0, 0.0, 10.0);
|
||||
font = Font.font("System Bold", 13.0);
|
||||
}
|
||||
pane {
|
||||
hgrow = Priority.ALWAYS
|
||||
}
|
||||
togglebutton("Console") {
|
||||
|
||||
}
|
||||
}
|
||||
center {
|
||||
splitpane {
|
||||
// treetableview {
|
||||
//
|
||||
// }
|
||||
tabpane {
|
||||
|
||||
}
|
||||
setDividerPosition(0, 0.3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bottom = statusBar;
|
||||
|
||||
}
|
||||
|
||||
private fun loadDirectory(path: URI) {
|
||||
runAsync {
|
||||
updateTitle("Load storage ($path)")
|
||||
updateProgress(-1.0, -1.0);
|
||||
updateMessage("Building numass storage tree...")
|
||||
val root = NumassStorage(context, FileStorageFactory.buildStorageMeta(path, true, true));
|
||||
setRootStorage(root)
|
||||
Platform.runLater { storageName = "Storage: " + path }
|
||||
updateProgress(1.0, 1.0)
|
||||
}
|
||||
}
|
||||
|
||||
fun setRootStorage(root: NumassStorage) {
|
||||
|
||||
runAsync {
|
||||
updateTitle("Fill data to UI (" + root.name + ")")
|
||||
updateProgress(-1.0, 1.0)
|
||||
Platform.runLater { statusBar.progress = -1.0 }
|
||||
|
||||
updateMessage("Loading numass storage tree...")
|
||||
|
||||
try {
|
||||
storageProperty.set(root)
|
||||
} catch (ex: StorageException) {
|
||||
context.logger.error("Could not load the storage", ex);
|
||||
}
|
||||
|
||||
// callback.setProgress(1, 1);
|
||||
Platform.runLater { statusBar.progress = 0.0 }
|
||||
updateMessage("Numass storage tree loaded.")
|
||||
updateProgress(1.0, 1.0)
|
||||
}
|
||||
}
|
||||
}
|
@ -59,9 +59,9 @@ class ViewerTest : View(title = "Numass viewer test", icon = ImageView(dfIcon))
|
||||
}
|
||||
|
||||
fun update(set: NumassSet) {
|
||||
amp.update(set.points.filter { it.voltage != 16000.0 }.collect(Collectors.toMap({ "point_${it.voltage}" }, { it })));
|
||||
//sp.update(mapOf("test" to set));
|
||||
//hv.update(set)
|
||||
amp.setAll(set.points.filter { it.voltage != 16000.0 }.collect(Collectors.toMap({ "point_${it.voltage}" }, { it })));
|
||||
sp.update(mapOf("test" to set));
|
||||
hv.update(set)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,38 +21,36 @@ limitations under the License.
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
<?import org.controlsfx.control.StatusBar?>
|
||||
<AnchorPane id="AnchorPane" prefHeight="768.0" prefWidth="1024.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<children>
|
||||
<BorderPane prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<top>
|
||||
<AnchorPane id="AnchorPane" prefHeight="768.0" prefWidth="1024.0" xmlns="http://javafx.com/javafx/8.0.111"
|
||||
xmlns:fx="http://javafx.com/fxml/1">
|
||||
<BorderPane prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
|
||||
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<top>
|
||||
<ToolBar nodeOrientation="LEFT_TO_RIGHT" prefHeight="40.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||
<items>
|
||||
<Button fx:id="loadDirectoryButton" mnemonicParsing="false" text="Load directory" />
|
||||
<Button fx:id="loadRemoteButton" mnemonicParsing="false" text="Remote storage" />
|
||||
<Label fx:id="storagePathLabel" text="Storage:" textFill="BLUE" textOverrun="CENTER_ELLIPSIS">
|
||||
<font>
|
||||
<Font name="System Bold" size="13.0" />
|
||||
</font>
|
||||
<padding>
|
||||
<Insets left="10.0" />
|
||||
</padding></Label>
|
||||
<Pane HBox.hgrow="ALWAYS" />
|
||||
<!--<ToggleButton fx:id="processManagerButton" mnemonicParsing="false" text="ProcessManager" />-->
|
||||
<ToggleButton fx:id="consoleButton" contentDisplay="CENTER" mnemonicParsing="false" text="Console" />
|
||||
</items>
|
||||
<Button fx:id="loadDirectoryButton" mnemonicParsing="false" text="Load directory"/>
|
||||
<Button fx:id="loadRemoteButton" mnemonicParsing="false" text="Remote storage"/>
|
||||
<Label fx:id="storagePathLabel" text="Storage:" textFill="BLUE" textOverrun="CENTER_ELLIPSIS">
|
||||
<font>
|
||||
<Font name="System Bold" size="13.0"/>
|
||||
</font>
|
||||
<padding>
|
||||
<Insets left="10.0"/>
|
||||
</padding>
|
||||
</Label>
|
||||
<Pane HBox.hgrow="ALWAYS"/>
|
||||
<!--<ToggleButton fx:id="processManagerButton" mnemonicParsing="false" text="ProcessManager" />-->
|
||||
<ToggleButton fx:id="consoleButton" contentDisplay="CENTER" mnemonicParsing="false" text="Console"/>
|
||||
</ToolBar>
|
||||
</top>
|
||||
<bottom>
|
||||
<StatusBar fx:id="statusBar" BorderPane.alignment="CENTER" />
|
||||
</bottom>
|
||||
<center>
|
||||
<SplitPane dividerPositions="0.2984344422700587" prefHeight="160.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||
<items>
|
||||
<BorderPane fx:id="treePane" prefHeight="200.0" prefWidth="200.0" />
|
||||
<BorderPane fx:id="loaderPane" prefHeight="200.0" prefWidth="200.0" />
|
||||
</items>
|
||||
</SplitPane>
|
||||
</center>
|
||||
</BorderPane>
|
||||
</children>
|
||||
</top>
|
||||
<bottom>
|
||||
<StatusBar fx:id="statusBar" BorderPane.alignment="CENTER"/>
|
||||
</bottom>
|
||||
<center>
|
||||
<SplitPane dividerPositions="0.2984344422700587" prefHeight="160.0" prefWidth="200.0"
|
||||
BorderPane.alignment="CENTER">
|
||||
<BorderPane fx:id="treePane" prefHeight="200.0" prefWidth="200.0"/>
|
||||
<BorderPane fx:id="loaderPane" prefHeight="200.0" prefWidth="200.0"/>
|
||||
</SplitPane>
|
||||
</center>
|
||||
</BorderPane>
|
||||
</AnchorPane>
|
||||
|
Loading…
Reference in New Issue
Block a user