numass fixes

This commit is contained in:
Alexander Nozik 2017-04-26 19:09:55 +03:00
parent 2fb2a6ca4a
commit 852efe7131
3 changed files with 32 additions and 28 deletions

View File

@ -5,6 +5,7 @@
*/ */
package inr.numass.data; package inr.numass.data;
import hep.dataforge.data.Data;
import hep.dataforge.meta.Annotated; import hep.dataforge.meta.Annotated;
import hep.dataforge.meta.Meta; import hep.dataforge.meta.Meta;
import hep.dataforge.names.Named; import hep.dataforge.names.Named;
@ -13,7 +14,6 @@ import hep.dataforge.tables.Table;
import java.time.Instant; import java.time.Instant;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -42,8 +42,8 @@ public interface NumassData extends Named, Annotated, Iterable<NumassPoint> {
Instant startTime(); Instant startTime();
default Supplier<Table> getHVData() { default Data<Table> getHVData() {
return () -> null; return Data.buildStatic(null);
} }
/** /**

View File

@ -16,6 +16,7 @@
package inr.numass.storage; package inr.numass.storage;
import hep.dataforge.context.Global; import hep.dataforge.context.Global;
import hep.dataforge.data.Data;
import hep.dataforge.exceptions.StorageException; import hep.dataforge.exceptions.StorageException;
import hep.dataforge.io.ColumnedDataReader; import hep.dataforge.io.ColumnedDataReader;
import hep.dataforge.io.envelopes.Envelope; import hep.dataforge.io.envelopes.Envelope;
@ -257,19 +258,20 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
} }
@Override @Override
public Supplier<Table> getHVData() { public Data<Table> getHVData() {
Envelope hvEnvelope = getHVEnvelope(); Envelope hvEnvelope = getHVEnvelope();
if (hvEnvelope == null) { if (hvEnvelope == null) {
return () -> null; return Data.buildStatic(null);
} } else {
return () -> { return Data.generate(Table.class, hvEnvelope.meta(), () -> {
try { try {
return new ColumnedDataReader(hvEnvelope.getData().getStream(), "timestamp", "block", "value").toTable(); return new ColumnedDataReader(hvEnvelope.getData().getStream(), "timestamp", "block", "value").toTable();
} catch (IOException ex) { } catch (IOException ex) {
LoggerFactory.getLogger(getClass()).error("Failed to load HV data from file", ex); LoggerFactory.getLogger(getClass()).error("Failed to load HV data from file", ex);
return null; return null;
} }
}; });
}
} }
private Envelope getHVEnvelope() { private Envelope getHVEnvelope() {

View File

@ -2,6 +2,7 @@ package inr.numass.viewer
import hep.dataforge.context.Context import hep.dataforge.context.Context
import hep.dataforge.context.Global import hep.dataforge.context.Global
import hep.dataforge.data.Data
import hep.dataforge.fx.work.Work import hep.dataforge.fx.work.Work
import hep.dataforge.fx.work.WorkManager import hep.dataforge.fx.work.WorkManager
import hep.dataforge.io.ColumnedDataWriter import hep.dataforge.io.ColumnedDataWriter
@ -36,7 +37,6 @@ import org.controlsfx.validation.Validator
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import tornadofx.* import tornadofx.*
import java.io.IOException import java.io.IOException
import java.util.function.Supplier
import java.util.logging.Level import java.util.logging.Level
import java.util.stream.Collectors import java.util.stream.Collectors
@ -51,6 +51,7 @@ class NumassLoaderView : View() {
var data: NumassData? = null var data: NumassData? = null
val spectrumData = PlottableData("spectrum") val spectrumData = PlottableData("spectrum")
val hvPlotData = PlottableGroup<TimePlottable>()
private val detectorPlotPane: AnchorPane by fxid(); private val detectorPlotPane: AnchorPane by fxid();
private val tabPane: TabPane by fxid(); private val tabPane: TabPane by fxid();
@ -172,20 +173,21 @@ class NumassLoaderView : View() {
} }
} }
private fun setupHVPane(hvData: Supplier<Table>) { private fun setupHVPane(hvData: Data<Table>) {
getWorkManager().startWork("viewer.numass.hv") { callback: Work -> runAsync {
val t = hvData.get() hvData.get()
Platform.runLater { } ui {
val set = PlottableGroup<TimePlottable>() for (pl in hvPlotData){
for (dp in t) { pl.clear()
}
for (dp in it) {
val block = dp.getString("block", "default") val block = dp.getString("block", "default")
if (!set.has(block)) { if (!hvPlotData.has(block)) {
set.add(TimePlottable(block)) hvPlotData.add(TimePlottable(block))
} }
set.get(block).put(dp.getValue("timestamp").timeValue(), dp.getValue("value")) hvPlotData.get(block).put(dp.getValue("timestamp").timeValue(), dp.getValue("value"))
}
hvPlot.plot.addAll(set)
} }
hvPlot.plot.addAll(hvPlotData)
} }
} }
@ -294,7 +296,7 @@ class NumassLoaderView : View() {
callback.increaseProgress(1.0) callback.increaseProgress(1.0)
datum; datum;
} }
} ui{ } ui {
detectorPlotFrame.setAll(it) detectorPlotFrame.setAll(it)
} }