Using tasks in numass viewer
This commit is contained in:
parent
c8ad2a51bc
commit
cbfbe27958
@ -89,7 +89,7 @@ public class PrepareDataAction extends OneToOneAction<NMFile, DataSet> {
|
||||
double cr = point.getCountRate(a, b, deadTime);
|
||||
double crErr = point.getCountRateErr(a, b, deadTime);
|
||||
|
||||
Instant timestamp = point.getAbsouteTime().toInstant(ZoneOffset.UTC);
|
||||
Instant timestamp = point.getStartTime();
|
||||
|
||||
dataList.add(new MapDataPoint(parnames, new Object[]{Uset, Uread, time, total, wind, corr, cr, crErr, timestamp}));
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import static java.lang.String.format;
|
||||
import static java.lang.String.format;
|
||||
import static java.lang.String.format;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -17,13 +17,13 @@ package inr.numass.data;
|
||||
|
||||
import hep.dataforge.data.DataPoint;
|
||||
import hep.dataforge.data.MapDataPoint;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import static java.util.Arrays.sort;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import static java.util.Arrays.sort;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -32,7 +32,7 @@ import java.util.Map;
|
||||
public class NMPoint {
|
||||
|
||||
static final String[] dataNames = {"chanel", "count"};
|
||||
private LocalDateTime absouteTime;
|
||||
private Instant startTime;
|
||||
|
||||
// private MonitorCorrector corrector = null;
|
||||
// private double deadTime;
|
||||
@ -54,7 +54,7 @@ public class NMPoint {
|
||||
this.pointLength = point.getLength();
|
||||
this.uset = point.getUset();
|
||||
this.uread = point.getUread();
|
||||
this.absouteTime = point.getAbsouteTime();
|
||||
this.startTime = point.getStartTime();
|
||||
this.eventsCount = point.getEventsCount();
|
||||
// this.point = point;
|
||||
spectrum = calculateSpectrum(point);
|
||||
@ -106,8 +106,12 @@ public class NMPoint {
|
||||
/**
|
||||
* @return the absouteTime
|
||||
*/
|
||||
public LocalDateTime getAbsouteTime() {
|
||||
return absouteTime;
|
||||
public Instant getStartTime() {
|
||||
if (startTime == null) {
|
||||
return Instant.EPOCH;
|
||||
} else {
|
||||
return startTime;
|
||||
}
|
||||
}
|
||||
|
||||
public int getCountInChanel(int chanel) {
|
||||
|
@ -24,6 +24,7 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Scanner;
|
||||
|
||||
@ -227,7 +228,7 @@ public class NumassDataReader {
|
||||
absoluteTime = absoluteTime.plusDays(1);
|
||||
}
|
||||
|
||||
point.setAbsouteTime(absoluteTime);
|
||||
point.setStartTime(absoluteTime.toInstant(ZoneOffset.UTC));
|
||||
|
||||
rx = readBlock(4);
|
||||
int Uread = rx[2] + 256 * rx[3];
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package inr.numass.data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -27,9 +27,9 @@ import java.util.List;
|
||||
public class RawNMPoint implements Cloneable {
|
||||
|
||||
public static int MAX_CHANEL = 4095;
|
||||
private LocalDateTime absouteTime;
|
||||
private Instant startTime;
|
||||
private final List<NMEvent> events;
|
||||
private double t;
|
||||
private double length;
|
||||
private double uread;
|
||||
|
||||
private double uset;
|
||||
@ -38,21 +38,21 @@ public class RawNMPoint implements Cloneable {
|
||||
this.uset = U;
|
||||
this.uread = U;
|
||||
this.events = events;
|
||||
this.t = t;
|
||||
this.length = t;
|
||||
}
|
||||
|
||||
public RawNMPoint(double Uset, double Uread, List<NMEvent> events, double t) {
|
||||
this.uset = Uset;
|
||||
this.uread = Uread;
|
||||
this.events = events;
|
||||
this.t = t;
|
||||
this.length = t;
|
||||
}
|
||||
|
||||
public RawNMPoint(double uset, double uread, List<NMEvent> events, double t, LocalDateTime absouteTime) {
|
||||
public RawNMPoint(double uset, double uread, List<NMEvent> events, double t, Instant absouteTime) {
|
||||
this.uset = uset;
|
||||
this.uread = uread;
|
||||
this.t = t;
|
||||
this.absouteTime = absouteTime;
|
||||
this.length = t;
|
||||
this.startTime = absouteTime;
|
||||
this.events = events;
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ public class RawNMPoint implements Cloneable {
|
||||
events = new ArrayList<>();
|
||||
uset = 0;
|
||||
uread = 0;
|
||||
t = Double.NaN;
|
||||
length = Double.NaN;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -72,8 +72,8 @@ public class RawNMPoint implements Cloneable {
|
||||
return new RawNMPoint(getUset(), getUread(), newevents, getLength());
|
||||
}
|
||||
|
||||
public LocalDateTime getAbsouteTime() {
|
||||
return absouteTime;
|
||||
public Instant getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public double getCR() {
|
||||
@ -100,10 +100,10 @@ public class RawNMPoint implements Cloneable {
|
||||
* @return the tset
|
||||
*/
|
||||
public double getLength() {
|
||||
if (Double.isNaN(t)) {
|
||||
if (Double.isNaN(length)) {
|
||||
throw new Error();
|
||||
}
|
||||
return t;
|
||||
return length;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -132,7 +132,7 @@ public class RawNMPoint implements Cloneable {
|
||||
for (NMEvent newEvent : point.getEvents()) {
|
||||
res.putEvent(new NMEvent(newEvent.getChanel(), newEvent.getTime() + this.getLength()));
|
||||
}
|
||||
res.t += point.getLength();
|
||||
res.length += point.getLength();
|
||||
res.uread = (this.uread + point.uread) / 2;
|
||||
return res;
|
||||
}
|
||||
@ -153,15 +153,15 @@ public class RawNMPoint implements Cloneable {
|
||||
return new RawNMPoint(getUset(), getUread(), res, getLength());
|
||||
}
|
||||
|
||||
void setAbsouteTime(LocalDateTime absouteTime) {
|
||||
this.absouteTime = absouteTime;
|
||||
void setStartTime(Instant absouteTime) {
|
||||
this.startTime = absouteTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tset the tset to set
|
||||
*/
|
||||
void setLength(double tset) {
|
||||
this.t = tset;
|
||||
this.length = tset;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -178,4 +178,5 @@ public class RawNMPoint implements Cloneable {
|
||||
void setUset(double Uset) {
|
||||
this.uset = Uset;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,13 +15,14 @@
|
||||
*/
|
||||
package inr.numass.data;
|
||||
|
||||
import hep.dataforge.data.DataAdapter;
|
||||
import hep.dataforge.meta.Meta;
|
||||
import hep.dataforge.data.DataPoint;
|
||||
import hep.dataforge.data.MapDataPoint;
|
||||
import hep.dataforge.data.XYDataAdapter;
|
||||
import hep.dataforge.exceptions.DataFormatException;
|
||||
import hep.dataforge.exceptions.NameNotFoundException;
|
||||
import hep.dataforge.names.Names;
|
||||
import hep.dataforge.meta.MetaBuilder;
|
||||
import hep.dataforge.values.Value;
|
||||
|
||||
/**
|
||||
@ -30,54 +31,48 @@ import hep.dataforge.values.Value;
|
||||
*/
|
||||
public class SpectrumDataAdapter extends XYDataAdapter {
|
||||
|
||||
private static final String ANNOTATION_TIMENAME = "timeName";
|
||||
|
||||
private String timeName = "time";
|
||||
private static final String POINT_LENGTH_NAME = "time";
|
||||
|
||||
public SpectrumDataAdapter() {
|
||||
}
|
||||
|
||||
public SpectrumDataAdapter(Meta aliasAnnotation) {
|
||||
super(aliasAnnotation);
|
||||
this.timeName = aliasAnnotation.getString(ANNOTATION_TIMENAME, "X");
|
||||
public SpectrumDataAdapter(Meta meta) {
|
||||
super(meta);
|
||||
}
|
||||
|
||||
public SpectrumDataAdapter(String xName, String yName, String yErrName, String timeTime) {
|
||||
super(xName, yName, yErrName);
|
||||
this.timeName = timeTime;
|
||||
public SpectrumDataAdapter(String xName, String yName, String yErrName, String measurementTime) {
|
||||
super(new MetaBuilder(DataAdapter.DATA_ADAPTER_ANNOTATION_NAME)
|
||||
.setValue(X_NAME, xName)
|
||||
.setValue(Y_NAME, yName)
|
||||
.setValue(Y_ERR_NAME, yErrName)
|
||||
.setValue(POINT_LENGTH_NAME, measurementTime)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public SpectrumDataAdapter(String xName, String yName, String timeTime) {
|
||||
super(xName, yName);
|
||||
this.timeName = timeTime;
|
||||
public SpectrumDataAdapter(String xName, String yName, String measurementTime) {
|
||||
super(new MetaBuilder(DataAdapter.DATA_ADAPTER_ANNOTATION_NAME)
|
||||
.setValue(X_NAME, xName)
|
||||
.setValue(Y_NAME, yName)
|
||||
.setValue(POINT_LENGTH_NAME, measurementTime)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public double getTime(DataPoint point) {
|
||||
if (point.names().contains(timeName)) {
|
||||
return point.getDouble(timeName);
|
||||
} else {
|
||||
return 1d;
|
||||
}
|
||||
return this.getFrom(point, POINT_LENGTH_NAME, 1d).doubleValue();
|
||||
}
|
||||
|
||||
public DataPoint buildSpectrumDataPoint(double x, long count, double t) {
|
||||
return new MapDataPoint(new String[]{xName,yName,timeName}, x,count,t);
|
||||
return new MapDataPoint(new String[]{getValueName(X_NAME), getValueName(Y_NAME),
|
||||
getValueName(POINT_LENGTH_NAME)},
|
||||
x, count, t);
|
||||
}
|
||||
|
||||
public DataPoint buildSpectrumDataPoint(double x, long count, double countErr, double t) {
|
||||
return new MapDataPoint(new String[]{xName,yName,yErrName,timeName}, x,count,countErr,t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Meta buildAnnotation() {
|
||||
Meta res = super.buildAnnotation();
|
||||
res.getBuilder().putValue(ANNOTATION_TIMENAME, timeName);
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Names getNames() {
|
||||
return Names.of(xName,yName);
|
||||
return new MapDataPoint(new String[]{getValueName(X_NAME), getValueName(Y_NAME),
|
||||
getValueName(Y_ERR_NAME), getValueName(POINT_LENGTH_NAME)},
|
||||
x, count, countErr, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -85,23 +80,22 @@ public class SpectrumDataAdapter extends XYDataAdapter {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Value getYerr(DataPoint point) throws NameNotFoundException {
|
||||
if (point.names().contains(yErrName)) {
|
||||
if (providesYError(point)) {
|
||||
return Value.of(super.getYerr(point).doubleValue() / getTime(point));
|
||||
} else {
|
||||
double y = super.getY(point).doubleValue();
|
||||
if(y<=0) throw new DataFormatException();
|
||||
else {
|
||||
if (y <= 0) {
|
||||
throw new DataFormatException();
|
||||
} else {
|
||||
return Value.of(Math.sqrt(y) / getTime(point));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public long getCount(DataPoint point) {
|
||||
return point.getValue(yName).numberValue().longValue();
|
||||
return super.getY(point).numberValue().longValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,6 +27,7 @@ import java.util.Iterator;
|
||||
import org.apache.commons.math3.random.JDKRandomGenerator;
|
||||
import org.apache.commons.math3.random.RandomDataGenerator;
|
||||
import org.apache.commons.math3.random.RandomGenerator;
|
||||
import static java.lang.Double.isNaN;
|
||||
|
||||
/**
|
||||
* Генератор наборов данных для спектров. На входе требуется набор данных,
|
||||
@ -64,7 +65,7 @@ public class SpectrumGenerator implements Generator {
|
||||
|
||||
@Override
|
||||
public ListDataSet generateData(Iterable<DataPoint> config) {
|
||||
ListDataSet res = adapter.buildEmptyDataSet("");
|
||||
ListDataSet res = new ListDataSet(adapter.getFormat());
|
||||
for (Iterator<DataPoint> it = config.iterator(); it.hasNext();) {
|
||||
res.add(this.generateDataPoint(it.next()));
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public class DebunchReportImpl implements DebunchReport {
|
||||
DebunchReportImpl(RawNMPoint pointBefore, DebunchData debunchData) {
|
||||
this.pointBefore = pointBefore;
|
||||
pointAfter = new RawNMPoint(pointBefore.getUset(),pointBefore.getUread(),
|
||||
debunchData.getDebunchedEvents(), debunchData.getDebunchedLength(),pointBefore.getAbsouteTime());
|
||||
debunchData.getDebunchedEvents(), debunchData.getDebunchedLength(),pointBefore.getStartTime());
|
||||
this.bunches = debunchData.getBunches();
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,9 @@ import static java.lang.Math.max;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import static java.lang.Math.max;
|
||||
import static java.lang.Math.max;
|
||||
import static java.lang.Math.max;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -23,8 +23,8 @@ import inr.numass.data.SpectrumDataAdapter;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Locale;
|
||||
import static java.util.Locale.setDefault;
|
||||
import java.util.Scanner;
|
||||
import static java.util.Locale.setDefault;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -56,7 +56,7 @@ public class OldDataReader {
|
||||
|
||||
public static ListDataSet readData(String path, double Elow) {
|
||||
SpectrumDataAdapter factory = new SpectrumDataAdapter();
|
||||
ListDataSet res = factory.buildEmptyDataSet("");
|
||||
ListDataSet res = new ListDataSet(factory.getFormat());
|
||||
File file = GlobalContext.instance().io().getFile(path);
|
||||
double x;
|
||||
int count;
|
||||
@ -108,7 +108,7 @@ public class OldDataReader {
|
||||
|
||||
public static ListDataSet readDataAsGun(String path, double Elow) {
|
||||
SpectrumDataAdapter factory = new SpectrumDataAdapter();
|
||||
ListDataSet res = factory.buildEmptyDataSet("");
|
||||
ListDataSet res = new ListDataSet(factory.getFormat());
|
||||
File file = GlobalContext.instance().io().getFile(path);
|
||||
double x;
|
||||
long count;
|
||||
@ -141,7 +141,7 @@ public class OldDataReader {
|
||||
|
||||
public static ListDataSet readSpectrumData(String path){
|
||||
SpectrumDataAdapter factory = new SpectrumDataAdapter();
|
||||
ListDataSet res = factory.buildEmptyDataSet("");
|
||||
ListDataSet res = new ListDataSet(factory.getFormat());
|
||||
File file = GlobalContext.instance().io().getFile(path);
|
||||
double x;
|
||||
double count;
|
||||
|
@ -23,6 +23,8 @@ import static java.lang.Math.sqrt;
|
||||
import org.apache.commons.math3.analysis.UnivariateFunction;
|
||||
import static java.lang.Math.abs;
|
||||
import static java.lang.Math.abs;
|
||||
import static java.lang.Math.abs;
|
||||
import static java.lang.Math.abs;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -19,7 +19,7 @@ import hep.dataforge.description.ActionDescriptor;
|
||||
import hep.dataforge.description.DescriptorUtils;
|
||||
import hep.dataforge.exceptions.NameNotFoundException;
|
||||
import hep.dataforge.fx.LogOutputPane;
|
||||
import hep.dataforge.fx.MetaEditorComponent;
|
||||
import hep.dataforge.fx.MetaEditor;
|
||||
import hep.dataforge.fx.MetaTreeItem;
|
||||
import hep.dataforge.io.IOManager;
|
||||
import hep.dataforge.io.MetaFileReader;
|
||||
@ -67,8 +67,8 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
|
||||
Context parentContext;
|
||||
MetaFactory<Context> contextFactory;
|
||||
|
||||
List<MetaEditorComponent> actionEditors = new ArrayList<>();
|
||||
MetaEditorComponent dataEditor;
|
||||
List<MetaEditor> actionEditors = new ArrayList<>();
|
||||
MetaEditor dataEditor;
|
||||
Context context;
|
||||
|
||||
Configuration dataConfig;
|
||||
@ -187,7 +187,7 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
|
||||
}
|
||||
});
|
||||
|
||||
MetaEditorComponent contextEditor = MetaEditorComponent.build(contextValues, null);
|
||||
MetaEditor contextEditor = MetaEditor.build(contextValues, null);
|
||||
|
||||
contextEditor.geTable().setShowRoot(false);
|
||||
contextPane.setContent(contextEditor);
|
||||
@ -203,7 +203,7 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
|
||||
} else {
|
||||
dataConfig = new Configuration("data");
|
||||
}
|
||||
dataEditor = MetaEditorComponent.build(dataConfig,
|
||||
dataEditor = MetaEditor.build(dataConfig,
|
||||
DescriptorUtils.buildDescriptor(
|
||||
DescriptorUtils.findAnnotatedElement("method::hep.dataforge.data.DataManager.read")
|
||||
));
|
||||
@ -219,7 +219,7 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
|
||||
actionsConfig.setNode("action", actions);
|
||||
|
||||
for (Configuration action : actions) {
|
||||
MetaEditorComponent actionEditor = new MetaEditorComponent();
|
||||
MetaEditor actionEditor = new MetaEditor();
|
||||
|
||||
MetaTreeItem rootItem = new MetaTreeItem(action, getDescriptorForAction(action.getString("type")));
|
||||
//Freezing actions names
|
||||
|
@ -34,10 +34,14 @@ import java.net.URL;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -172,13 +176,26 @@ public class NumassDataLoader extends AbstractLoader implements BinaryLoader<Env
|
||||
}
|
||||
|
||||
// LocalDateTime startTime = envelope.meta().get
|
||||
RawNMPoint raw = new RawNMPoint(envelope.meta().getDouble("external_meta.HV1_value", 0),
|
||||
double u = envelope.meta().getDouble("external_meta.HV1_value", 0);
|
||||
RawNMPoint raw = new RawNMPoint(u, u,
|
||||
events,
|
||||
envelope.meta().getValue("external_meta.acquisition_time").doubleValue());
|
||||
envelope.meta().getValue("external_meta.acquisition_time").doubleValue(),
|
||||
readTime(envelope.meta()));
|
||||
|
||||
return transformation.apply(raw);
|
||||
}
|
||||
|
||||
private static Instant readTime(Meta meta) {
|
||||
if (meta.hasValue("date") && meta.hasValue("start_time")) {
|
||||
LocalDate date = LocalDate.parse(meta.getString("date"), DateTimeFormatter.ofPattern("uuuu.MM.dd"));
|
||||
LocalTime time = LocalTime.parse(meta.getString("start_time"));
|
||||
LocalDateTime dateTime = LocalDateTime.of(date, time);
|
||||
return dateTime.toInstant(ZoneOffset.UTC);
|
||||
} else {
|
||||
return Instant.EPOCH;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read numass point without transformation
|
||||
*
|
||||
@ -244,7 +261,7 @@ public class NumassDataLoader extends AbstractLoader implements BinaryLoader<Env
|
||||
this.getPoints().stream().forEachOrdered((point) -> {
|
||||
res.add(readPoint(point));
|
||||
});
|
||||
// res.sort((NMPoint o1, NMPoint o2) -> o1.getAbsouteTime().compareTo(o2.getAbsouteTime()));
|
||||
// res.sort((NMPoint o1, NMPoint o2) -> o1.getStartTime().compareTo(o2.getStartTime()));
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -287,13 +304,17 @@ public class NumassDataLoader extends AbstractLoader implements BinaryLoader<Env
|
||||
|
||||
@Override
|
||||
public Instant startTime() {
|
||||
//TODO read meta
|
||||
return null;
|
||||
// List<NMPoint> points = getNMPoints();
|
||||
// if(!points.isEmpty()){
|
||||
// return points.get(0).getStartTime();
|
||||
// } else {
|
||||
// return null;
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
//TODO read from annotation
|
||||
return "";
|
||||
return meta().getString("description", "").replace("\\n", "\n");
|
||||
}
|
||||
}
|
||||
|
@ -85,12 +85,12 @@ public class NumassStorage extends FileStorage {
|
||||
}
|
||||
}
|
||||
|
||||
public static NumassStorage buildRemoteNumassRoot(String uri) throws StorageException {
|
||||
public static NumassStorage buildNumassRoot(String uri, boolean readOnly, boolean monitor) throws StorageException {
|
||||
try {
|
||||
Meta meta = new MetaBuilder("storage")
|
||||
.setValue("type", "file.numass")
|
||||
.setValue("readOnly", true)
|
||||
.setValue("monitor", false);
|
||||
.setValue("readOnly", readOnly)
|
||||
.setValue("monitor", monitor);
|
||||
return new NumassStorage(VFSUtils.getRemoteFile(uri), meta);
|
||||
} catch (FileSystemException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
|
@ -5,7 +5,7 @@ if (!hasProperty('mainClass')) {
|
||||
}
|
||||
mainClassName = mainClass
|
||||
|
||||
version = "0.2.2"
|
||||
version = "0.2.3"
|
||||
|
||||
description = "The viewer for numass data"
|
||||
|
||||
|
@ -5,11 +5,12 @@
|
||||
*/
|
||||
package inr.numass.viewer;
|
||||
|
||||
import javafx.concurrent.Task;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexander Nozik <altavir@gmail.com>
|
||||
*/
|
||||
public interface ProgressUpdateCallback {
|
||||
void setProgressText(String text);
|
||||
void setProgress(double progress);
|
||||
public interface FXTaskManager {
|
||||
void postTask(Task task);
|
||||
}
|
@ -24,10 +24,13 @@ import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.Optional;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.concurrent.Task;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
@ -48,6 +51,7 @@ import javafx.scene.control.TreeTableView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.stage.DirectoryChooser;
|
||||
import javafx.util.Duration;
|
||||
import javafx.util.Pair;
|
||||
import org.controlsfx.control.StatusBar;
|
||||
|
||||
@ -56,7 +60,7 @@ import org.controlsfx.control.StatusBar;
|
||||
*
|
||||
* @author Alexander Nozik
|
||||
*/
|
||||
public class MainViewerController implements Initializable, ProgressUpdateCallback {
|
||||
public class MainViewerController implements Initializable, FXTaskManager {
|
||||
|
||||
public static MainViewerController build(NumassStorage root) {
|
||||
MainViewerController res = new MainViewerController();
|
||||
@ -111,14 +115,14 @@ public class MainViewerController implements Initializable, ProgressUpdateCallba
|
||||
// TabPaneDetacher.create().makeTabsDetachable(tabPane);
|
||||
ConsoleDude.hookStdStreams(consoleArea);
|
||||
|
||||
SplitPaneDividerSlider slider = new SplitPaneDividerSlider(consoleSplit, 0, SplitPaneDividerSlider.Direction.DOWN);
|
||||
SplitPaneDividerSlider slider = new SplitPaneDividerSlider(consoleSplit, 0,
|
||||
SplitPaneDividerSlider.Direction.DOWN, Duration.seconds(1));
|
||||
|
||||
consoleButton.selectedProperty().addListener((ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) -> {
|
||||
slider.setAimContentVisible(t1);
|
||||
});
|
||||
slider.setAimContentVisible(false);
|
||||
slider.aimContentVisibleProperty().bindBidirectional(consoleButton.selectedProperty());
|
||||
|
||||
consoleButton.setSelected(false);
|
||||
loadRemoteButton.setDisable(true);
|
||||
mspController.setCallback(this);
|
||||
}
|
||||
|
||||
@FXML
|
||||
@ -131,39 +135,72 @@ public class MainViewerController implements Initializable, ProgressUpdateCallba
|
||||
final File rootDir = chooser.showDialog(((Node) event.getTarget()).getScene().getWindow());
|
||||
|
||||
if (rootDir != null) {
|
||||
storagePathLabel.setText("Storage: " + rootDir.getAbsolutePath());
|
||||
setProgress(-1);
|
||||
setProgressText("Building numass storage tree...");
|
||||
new Thread(() -> {
|
||||
Task dirLoadTask = new DirectoryLoadTask(rootDir.toURI().toString());
|
||||
postTask(dirLoadTask);
|
||||
Viewer.runTask(dirLoadTask);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class DirectoryLoadTask extends Task<Void> {
|
||||
|
||||
private final String uri;
|
||||
|
||||
public DirectoryLoadTask(String uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void call() throws Exception {
|
||||
updateTitle("Load storage ("+uri+")");
|
||||
updateProgress(-1, 1);
|
||||
updateMessage("Building numass storage tree...");
|
||||
try {
|
||||
|
||||
NumassStorage root = NumassStorage.buildLocalNumassRoot(rootDir, true);
|
||||
NumassStorage root = NumassStorage.buildNumassRoot(uri, true, false);
|
||||
setRootStorage(root);
|
||||
|
||||
Platform.runLater(() -> storagePathLabel.setText("Storage: " + uri));
|
||||
} catch (StorageException ex) {
|
||||
setProgress(0);
|
||||
setProgressText("Failed to load local storage");
|
||||
updateProgress(0, 1);
|
||||
updateMessage("Failed to load storage " + uri);
|
||||
Logger.getLogger(MainViewerController.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}, "loader thread").start();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProgress(double progress) {
|
||||
Platform.runLater(() -> statusBar.setProgress(progress));
|
||||
//statusBar.setProgress(progress);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public void postTask(Task task) {
|
||||
task.setOnRunning((e) -> {
|
||||
statusBar.setText(task.getTitle() + ": " + task.getMessage());
|
||||
statusBar.setProgress(task.getProgress());
|
||||
});
|
||||
|
||||
@Override
|
||||
public void setProgressText(String text) {
|
||||
Platform.runLater(() -> statusBar.setText(text));
|
||||
//statusBar.setText(text);
|
||||
task.messageProperty().addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> {
|
||||
statusBar.setText(task.getTitle() + ": " +newValue);
|
||||
});
|
||||
|
||||
task.progressProperty().addListener((ObservableValue<? extends Number> observable, Number oldValue, Number newValue) -> {
|
||||
statusBar.setProgress(newValue.doubleValue());
|
||||
});
|
||||
|
||||
task.setOnSucceeded((e) -> {
|
||||
statusBar.setText(task.getTitle() + ": Complete");
|
||||
statusBar.setProgress(0);
|
||||
});
|
||||
|
||||
task.setOnFailed((e) -> {
|
||||
statusBar.setText(task.getTitle() + ": Failed");
|
||||
statusBar.setProgress(0);
|
||||
});
|
||||
}
|
||||
|
||||
public void setRootStorage(NumassStorage root) {
|
||||
fillNumassStorageData(root);
|
||||
Task fillTask = new StorageDataFillTask(root);
|
||||
postTask(fillTask);
|
||||
Viewer.runTask(fillTask);
|
||||
|
||||
if (mspController != null) {
|
||||
mspController.setCallback(this);
|
||||
mspController.fillMspData(root);
|
||||
@ -176,14 +213,24 @@ public class MainViewerController implements Initializable, ProgressUpdateCallba
|
||||
|
||||
}
|
||||
|
||||
private void fillNumassStorageData(NumassStorage rootStorage) {
|
||||
if (rootStorage != null) {
|
||||
setProgress(-1);
|
||||
setProgressText("Loading numass storage tree...");
|
||||
private class StorageDataFillTask extends Task<Void> {
|
||||
|
||||
try {
|
||||
new NumassLoaderTreeBuilder(MainViewerController.this).fillTree(numassLoaderDataTree, rootStorage, (NumassData loader) -> {
|
||||
NumassLoaderViewComponent component = NumassLoaderViewComponent.build(loader);
|
||||
private final NumassStorage root;
|
||||
|
||||
public StorageDataFillTask(NumassStorage root) {
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void call() throws Exception {
|
||||
updateTitle("Fill data to UI ("+root.getName()+")");
|
||||
this.updateProgress(-1, 1);
|
||||
this.updateMessage("Loading numass storage tree...");
|
||||
|
||||
Task treeBuilderTask = new NumassLoaderTreeBuilder(numassLoaderDataTree, root, (NumassData loader) -> {
|
||||
NumassLoaderViewComponent component = new NumassLoaderViewComponent();
|
||||
component.loadData(loader);
|
||||
component.setCallback(MainViewerController.this);
|
||||
numassLoaderViewContainer.getChildren().clear();
|
||||
numassLoaderViewContainer.getChildren().add(component);
|
||||
AnchorPane.setTopAnchor(component, 0.0);
|
||||
@ -192,12 +239,20 @@ public class MainViewerController implements Initializable, ProgressUpdateCallba
|
||||
AnchorPane.setBottomAnchor(component, 0.0);
|
||||
numassLoaderViewContainer.requestLayout();
|
||||
});
|
||||
setProgress(0);
|
||||
setProgressText("Loaded");
|
||||
} catch (StorageException ex) {
|
||||
postTask(treeBuilderTask);
|
||||
Viewer.runTask(treeBuilderTask);
|
||||
try {
|
||||
treeBuilderTask.get();
|
||||
this.updateProgress(0, 1);
|
||||
this.updateMessage("Numass storage tree loaded.");
|
||||
this.succeeded();
|
||||
} catch (InterruptedException | ExecutionException ex) {
|
||||
this.failed();
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
@ -230,7 +285,7 @@ public class MainViewerController implements Initializable, ProgressUpdateCallba
|
||||
dialog.getDialogPane().setContent(grid);
|
||||
|
||||
// Request focus on the username field by default.
|
||||
Platform.runLater(() -> storageText.requestFocus());
|
||||
storageText.requestFocus();
|
||||
|
||||
// Convert the result to a username-password-pair when the login button is clicked.
|
||||
dialog.setResultConverter(dialogButton -> {
|
||||
@ -243,21 +298,9 @@ public class MainViewerController implements Initializable, ProgressUpdateCallba
|
||||
Optional<Pair<String, String>> result = dialog.showAndWait();
|
||||
|
||||
if (result.isPresent()) {
|
||||
storagePathLabel.setText("Storage: remote/" + result.get().getValue());
|
||||
|
||||
setProgress(-1);
|
||||
setProgressText("Building numass storage tree...");
|
||||
new Thread(() -> {
|
||||
try {
|
||||
NumassStorage root = NumassStorage.buildRemoteNumassRoot(result.get().getKey() + "/data/" + result.get().getValue());
|
||||
setRootStorage(root);
|
||||
} catch (StorageException ex) {
|
||||
setProgress(0);
|
||||
setProgressText("Failed to load remote storage");
|
||||
Logger.getLogger(MainViewerController.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}, "loader thread").start();
|
||||
|
||||
Task dirLoadTask = new DirectoryLoadTask(result.get().getKey() + "/data/" + result.get().getValue());
|
||||
postTask(dirLoadTask);
|
||||
Viewer.runTask(dirLoadTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ package inr.numass.viewer;
|
||||
*/
|
||||
import hep.dataforge.data.DataPoint;
|
||||
import hep.dataforge.data.MapDataPoint;
|
||||
import hep.dataforge.exceptions.StorageException;
|
||||
import hep.dataforge.storage.api.PointLoader;
|
||||
import hep.dataforge.storage.api.Storage;
|
||||
import hep.dataforge.values.Value;
|
||||
@ -35,6 +34,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
import javafx.application.Platform;
|
||||
import javafx.concurrent.Task;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
@ -58,7 +58,7 @@ import org.slf4j.LoggerFactory;
|
||||
*/
|
||||
public class MspViewController implements Initializable {
|
||||
|
||||
private ProgressUpdateCallback callback;
|
||||
private FXTaskManager callback;
|
||||
|
||||
@FXML
|
||||
private AnchorPane mspPlotPane;
|
||||
@ -119,8 +119,31 @@ public class MspViewController implements Initializable {
|
||||
|
||||
public void fillMspData(Storage rootStorage) {
|
||||
if (rootStorage != null) {
|
||||
try {
|
||||
List<DataPoint> mspData = getMspData(rootStorage);
|
||||
MspDataFillTask fillTask = new MspDataFillTask(rootStorage);
|
||||
if(callback!= null){
|
||||
callback.postTask(fillTask);
|
||||
}
|
||||
Viewer.runTask(fillTask);
|
||||
}
|
||||
}
|
||||
|
||||
private class MspDataFillTask extends Task<Void> {
|
||||
|
||||
private final Storage storage;
|
||||
|
||||
public MspDataFillTask(Storage storage) {
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void call() throws Exception {
|
||||
updateTitle("Fill msp data ("+storage.getName()+")");
|
||||
MspDataLoadTask loadTask = new MspDataLoadTask(storage);
|
||||
if(callback!= null){
|
||||
callback.postTask(loadTask);
|
||||
}
|
||||
Viewer.runTask(loadTask);
|
||||
List<DataPoint> mspData = loadTask.get();
|
||||
Map<String, XYSeries> series = new HashMap<>();
|
||||
|
||||
for (DataPoint point : mspData) {
|
||||
@ -150,21 +173,30 @@ public class MspViewController implements Initializable {
|
||||
mspSeriesCollection.addSeries(series.get(name));
|
||||
}
|
||||
updateMspPane(mspSeriesCollection);
|
||||
} catch (StorageException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<DataPoint> getMspData(Storage storage) throws StorageException {
|
||||
}
|
||||
|
||||
private class MspDataLoadTask extends Task<List<DataPoint>> {
|
||||
|
||||
private final Storage storage;
|
||||
|
||||
public MspDataLoadTask(Storage storage) {
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DataPoint> call() throws Exception {
|
||||
updateTitle("Load msp data ("+storage.getName()+")");
|
||||
List<DataPoint> mspData = new ArrayList<>();
|
||||
DataPoint last = null;
|
||||
for (String loaderName : storage.loaders().keySet()) {
|
||||
if (loaderName.startsWith("msp")) {
|
||||
try (PointLoader mspLoader = (PointLoader) storage.getLoader(loaderName)) {
|
||||
mspLoader.open();
|
||||
updateProgress("Loading mass spectrometer data from " + mspLoader.getName());
|
||||
updateProgress(-1);
|
||||
updateMessage("Loading mass spectrometer data from " + mspLoader.getName());
|
||||
updateProgress(-1, 1);
|
||||
for (DataPoint dp : mspLoader.asDataSet()) {
|
||||
mspData.add(dp);
|
||||
last = dp;
|
||||
@ -177,28 +209,15 @@ public class MspViewController implements Initializable {
|
||||
}
|
||||
}
|
||||
}
|
||||
// for (String shelfName : storage.shelves().keySet()) {
|
||||
// mspData.addAll(getMspData(storage.getShelf(shelfName)));
|
||||
// }
|
||||
|
||||
updateProgress("Loading msp data finished");
|
||||
updateProgress(0);
|
||||
updateMessage("Loading msp data finished");
|
||||
updateProgress(0, 1);
|
||||
return mspData;
|
||||
}
|
||||
|
||||
private void updateProgress(String progress) {
|
||||
if (callback != null) {
|
||||
callback.setProgressText(progress);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateProgress(double progress) {
|
||||
if (callback != null) {
|
||||
callback.setProgress(progress);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCallback(ProgressUpdateCallback callback) {
|
||||
public void setCallback(FXTaskManager callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.concurrent.Task;
|
||||
import javafx.scene.control.TreeItem;
|
||||
import javafx.scene.control.TreeTableColumn;
|
||||
import javafx.scene.control.TreeTableView;
|
||||
@ -35,19 +36,23 @@ import javafx.scene.input.MouseEvent;
|
||||
*
|
||||
* @author darksnake
|
||||
*/
|
||||
public class NumassLoaderTreeBuilder implements ProgressUpdateCallback {
|
||||
public class NumassLoaderTreeBuilder extends Task<Void> {
|
||||
|
||||
ProgressUpdateCallback callback;
|
||||
private final TreeTableView<TreeItemValue> numassLoaderDataTree;
|
||||
private final NumassStorage rootStorage;
|
||||
private final Consumer<NumassData> numassViewBuilder;
|
||||
|
||||
public NumassLoaderTreeBuilder(ProgressUpdateCallback callback) {
|
||||
this.callback = callback;
|
||||
public NumassLoaderTreeBuilder(TreeTableView<TreeItemValue> numassLoaderDataTree, NumassStorage rootStorage, Consumer<NumassData> numassViewBuilder) {
|
||||
this.numassLoaderDataTree = numassLoaderDataTree;
|
||||
this.rootStorage = rootStorage;
|
||||
this.numassViewBuilder = numassViewBuilder;
|
||||
}
|
||||
|
||||
public NumassLoaderTreeBuilder() {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void fillTree(TreeTableView<TreeItemValue> numassLoaderDataTree, NumassStorage rootStorage, Consumer<NumassData> numassViewBuilder) throws StorageException {
|
||||
@Override
|
||||
protected Void call() throws Exception {
|
||||
updateTitle("Load numass data ("+rootStorage.getName()+")");
|
||||
TreeItem<TreeItemValue> root = buildNode(rootStorage, numassViewBuilder);
|
||||
root.setExpanded(true);
|
||||
|
||||
@ -81,6 +86,7 @@ public class NumassLoaderTreeBuilder implements ProgressUpdateCallback {
|
||||
numassLoaderTimeColumn.setVisible(false);
|
||||
nummassLoaderDescriptionColumn.setVisible(false);
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
private TreeItem<TreeItemValue> buildNode(NumassStorage storage, Consumer<NumassData> numassViewBuilder) throws StorageException {
|
||||
@ -99,12 +105,12 @@ public class NumassLoaderTreeBuilder implements ProgressUpdateCallback {
|
||||
}
|
||||
}
|
||||
|
||||
setProgressText("Building storage " + storage.getName());
|
||||
updateMessage("Building storage " + storage.getName());
|
||||
|
||||
double counter = 0;
|
||||
for (Loader loader : storage.loaders().values()) {
|
||||
setProgressText("Building numass data loader " + loader.getName());
|
||||
setProgress(counter / storage.loaders().size());
|
||||
updateMessage("Building numass data loader " + loader.getName());
|
||||
updateProgress(counter, storage.loaders().size());
|
||||
|
||||
if (loader instanceof NumassData) {
|
||||
NumassData numassLoader = (NumassData) loader;
|
||||
@ -126,8 +132,8 @@ public class NumassLoaderTreeBuilder implements ProgressUpdateCallback {
|
||||
//adding legacy data files
|
||||
counter = 0;
|
||||
for (NumassData legacyDat : storage.legacyFiles()) {
|
||||
setProgressText("Loading numass DAT file " + legacyDat.getName());
|
||||
setProgress(counter / storage.loaders().size());
|
||||
updateMessage("Loading numass DAT file " + legacyDat.getName());
|
||||
updateProgress(counter, storage.loaders().size());
|
||||
TreeItem<TreeItemValue> numassLoaderTreeItem = new TreeItem<>(buildValue(legacyDat));
|
||||
list.add(numassLoaderTreeItem);
|
||||
counter++;
|
||||
@ -197,7 +203,7 @@ public class NumassLoaderTreeBuilder implements ProgressUpdateCallback {
|
||||
@Override
|
||||
public String getTime() {
|
||||
Instant startTime = loader.startTime();
|
||||
if (startTime == null) {
|
||||
if (startTime == null || startTime.equals(Instant.EPOCH)) {
|
||||
return "";
|
||||
} else {
|
||||
return loader.startTime().toString();
|
||||
@ -211,20 +217,6 @@ public class NumassLoaderTreeBuilder implements ProgressUpdateCallback {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProgress(double progress) {
|
||||
if (callback != null) {
|
||||
callback.setProgress(progress);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProgressText(String text) {
|
||||
if (callback != null) {
|
||||
callback.setProgressText(text);
|
||||
}
|
||||
}
|
||||
|
||||
public interface TreeItemValue {
|
||||
|
||||
public String getName();
|
||||
|
@ -22,6 +22,7 @@ package inr.numass.viewer;
|
||||
*/
|
||||
import hep.dataforge.data.DataPoint;
|
||||
import hep.dataforge.data.DataSet;
|
||||
import hep.dataforge.data.ListDataSet;
|
||||
import hep.dataforge.data.MapDataPoint;
|
||||
import hep.dataforge.io.ColumnedDataWriter;
|
||||
import hep.dataforge.meta.Meta;
|
||||
@ -41,11 +42,16 @@ import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.concurrent.Task;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
@ -63,6 +69,8 @@ import javafx.stage.FileChooser;
|
||||
import javafx.util.converter.NumberStringConverter;
|
||||
import org.controlsfx.control.CheckListView;
|
||||
import org.controlsfx.control.RangeSlider;
|
||||
import org.controlsfx.validation.ValidationSupport;
|
||||
import org.controlsfx.validation.Validator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -73,21 +81,7 @@ import org.slf4j.LoggerFactory;
|
||||
*/
|
||||
public class NumassLoaderViewComponent extends AnchorPane implements Initializable {
|
||||
|
||||
public static NumassLoaderViewComponent build(NumassData numassLoader) {
|
||||
NumassLoaderViewComponent component = new NumassLoaderViewComponent();
|
||||
FXMLLoader loader = new FXMLLoader(component.getClass().getResource("/fxml/NumassLoaderView.fxml"));
|
||||
|
||||
loader.setRoot(component);
|
||||
loader.setController(component);
|
||||
|
||||
try {
|
||||
loader.load();
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
component.setData(numassLoader);
|
||||
return component;
|
||||
}
|
||||
private FXTaskManager callback;
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(NumassLoaderViewComponent.class);
|
||||
private NumassData data;
|
||||
@ -120,15 +114,29 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
|
||||
private CheckBox detectorNormalizeSwitch;
|
||||
@FXML
|
||||
private Button detectorDataExportButton;
|
||||
|
||||
@FXML
|
||||
private TextField lowChannelField;
|
||||
|
||||
@FXML
|
||||
private TextField upChannelField;
|
||||
|
||||
@FXML
|
||||
private RangeSlider channelSlider;
|
||||
@FXML
|
||||
private Button spectrumExportButton;
|
||||
@FXML
|
||||
private TextField dTimeField;
|
||||
|
||||
public NumassLoaderViewComponent() {
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/NumassLoaderView.fxml"));
|
||||
|
||||
loader.setRoot(this);
|
||||
loader.setController(this);
|
||||
|
||||
try {
|
||||
loader.load();
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the controller class.
|
||||
@ -138,9 +146,8 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
|
||||
*/
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle rb) {
|
||||
// TODO
|
||||
detectorBinningSelector.setItems(FXCollections.observableArrayList(1, 2, 5, 10, 20));
|
||||
detectorBinningSelector.getSelectionModel().selectLast();
|
||||
detectorBinningSelector.setItems(FXCollections.observableArrayList(1, 2, 5, 10, 20, 50));
|
||||
detectorBinningSelector.getSelectionModel().select(4);
|
||||
detectorNormalizeSwitch.setSelected(true);
|
||||
|
||||
detectorPointListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
|
||||
@ -148,36 +155,83 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
|
||||
lowChannelField.textProperty().bindBidirectional(channelSlider.lowValueProperty(), new NumberStringConverter());
|
||||
upChannelField.textProperty().bindBidirectional(channelSlider.highValueProperty(), new NumberStringConverter());
|
||||
|
||||
channelSlider.setLowValue(300);
|
||||
channelSlider.setHighValue(1900);
|
||||
channelSlider.setHighValue(1900d);
|
||||
channelSlider.setLowValue(300d);
|
||||
|
||||
ChangeListener<? super Number> rangeChangeListener = (ObservableValue<? extends Number> observable, Number oldValue, Number newValue) -> {
|
||||
updateSpectrumPane();
|
||||
updateSpectrumPane(points);
|
||||
};
|
||||
|
||||
dTimeField.textProperty().addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> {
|
||||
updateSpectrumPane(points);
|
||||
});
|
||||
|
||||
channelSlider.lowValueProperty().addListener(rangeChangeListener);
|
||||
channelSlider.highValueProperty().addListener(rangeChangeListener);
|
||||
|
||||
ValidationSupport validationSupport = new ValidationSupport();
|
||||
Predicate<String> isNumber = (String t) -> {
|
||||
try {
|
||||
Double.parseDouble(t);
|
||||
return true;
|
||||
} catch (NumberFormatException | NullPointerException ex) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
validationSupport.registerValidator(dTimeField, Validator.createPredicateValidator(isNumber, "Must be number"));
|
||||
}
|
||||
|
||||
public NumassData getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(NumassData data) {
|
||||
public void setCallback(FXTaskManager callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
public void loadData(NumassData data) {
|
||||
this.data = data;
|
||||
if (data != null) {
|
||||
points = data.getNMPoints();
|
||||
//setup detector data
|
||||
setupDetectorPane(points);
|
||||
//setup spectrum plot
|
||||
updateSpectrumPane();
|
||||
|
||||
setupInfo(data);
|
||||
|
||||
detectorTab.getTabPane().getSelectionModel().select(detectorTab);
|
||||
LoadPointsTask task = new LoadPointsTask(data);
|
||||
if (callback != null) {
|
||||
callback.postTask(task);
|
||||
}
|
||||
Viewer.runTask(task);
|
||||
try {
|
||||
this.points = task.get();
|
||||
} catch (InterruptedException |ExecutionException ex) {
|
||||
logger.error("Can't load spectrum data points", ex);
|
||||
}
|
||||
} else {
|
||||
logger.error("The data model is null");
|
||||
}
|
||||
detectorTab.getTabPane().getSelectionModel().select(detectorTab);
|
||||
}
|
||||
|
||||
private class LoadPointsTask extends Task<List<NMPoint>> {
|
||||
|
||||
private final NumassData loader;
|
||||
|
||||
public LoadPointsTask(NumassData loader) {
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<NMPoint> call() throws Exception {
|
||||
updateTitle("Load numass data (" + loader.getName() + ")");
|
||||
List<NMPoint> points = loader.getNMPoints();
|
||||
Platform.runLater(() -> {
|
||||
//setup detector data
|
||||
setupDetectorPane(points);
|
||||
//setup spectrum plot
|
||||
updateSpectrumPane(points);
|
||||
|
||||
setupInfo(data);
|
||||
});
|
||||
return points;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -192,11 +246,11 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
|
||||
detectorBinningSelector.getSelectionModel().selectedItemProperty()
|
||||
.addListener((ObservableValue<? extends Integer> observable, Integer oldValue, Integer newValue) -> {
|
||||
boolean norm = detectorNormalizeSwitch.isSelected();
|
||||
updateDetectorPane(fillDetectorData(points, newValue, norm));
|
||||
updateDetectorPane(fillDetectorData(NumassLoaderViewComponent.this.points, newValue, norm));
|
||||
});
|
||||
detectorNormalizeSwitch.selectedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
|
||||
int bin = detectorBinningSelector.getValue();
|
||||
updateDetectorPane(fillDetectorData(points, bin, newValue));
|
||||
updateDetectorPane(fillDetectorData(NumassLoaderViewComponent.this.points, bin, newValue));
|
||||
});
|
||||
detectorDataExportButton.setDisable(false);
|
||||
}
|
||||
@ -204,10 +258,10 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
|
||||
private void setupInfo(NumassData loader) {
|
||||
Meta info = loader.getInfo();
|
||||
infoTextBox.setText(new JSONMetaWriter().writeString(info, null).
|
||||
replace("\\r", "\r").replace("\\n", "\n"));
|
||||
replace("\\r", "\r\t").replace("\\n", "\n\t"));
|
||||
}
|
||||
|
||||
private void updateSpectrumPane() {
|
||||
private void updateSpectrumPane(List<NMPoint> points) {
|
||||
if (spectrumPlotFrame == null) {
|
||||
Meta plotMeta = new MetaBuilder("plot")
|
||||
.setValue("xAxis.axisTitle", "U")
|
||||
@ -230,39 +284,31 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
|
||||
spectrumData.clear();
|
||||
} else {
|
||||
spectrumData.fillData(points.stream()
|
||||
.<DataPoint>map((NMPoint point) -> getSpectrumPoint(point, lowChannel, highChannel))
|
||||
.<DataPoint>map((NMPoint point) -> getSpectrumPoint(point, lowChannel, highChannel, getDTime()))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
||||
private DataPoint getSpectrumPoint(NMPoint point, int lowChannel, int highChannel) {
|
||||
double u = point.getUread();
|
||||
double count = point.getCountInWindow(lowChannel, highChannel);
|
||||
double time = point.getLength();
|
||||
double err = Math.sqrt(count);
|
||||
return new MapDataPoint(new String[]{"x", "y", "yErr"}, u, count / time, err / time);
|
||||
private double getDTime() {
|
||||
try {
|
||||
return Double.parseDouble(dTimeField.getText()) * 1e-6;
|
||||
} catch (NumberFormatException ex) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private DataPoint getSpectrumPoint(NMPoint point, int lowChannel, int upChannel, double dTime) {
|
||||
double u = point.getUread();
|
||||
return new MapDataPoint(new String[]{"x", "y", "yErr"}, u,
|
||||
point.getCountRate(lowChannel, upChannel, dTime),
|
||||
point.getCountRateErr(lowChannel, upChannel, dTime));
|
||||
}
|
||||
|
||||
// private void setupSpectrumPane(List<NMPoint> points, int lowChannel, int upChannel) {
|
||||
// updateSpectrumData(fillSpectrumData(points, (point) -> point.getCountInWindow(lowChannel, upChannel)));
|
||||
// }
|
||||
//
|
||||
// private void updateSpectrumData(XYIntervalSeriesCollection data) {
|
||||
// spectrumPlotPane.getChildren().clear();
|
||||
// NumberAxis xAxis = new NumberAxis("HV");
|
||||
// NumberAxis yAxis = new NumberAxis("count rate");
|
||||
//
|
||||
// xAxis.setAutoRangeIncludesZero(false);
|
||||
// yAxis.setAutoRangeIncludesZero(false);
|
||||
//
|
||||
// XYPlot plot = new XYPlot(data, xAxis, yAxis, new XYErrorRenderer());
|
||||
// JFreeChart spectrumPlot = new JFreeChart("spectrum", plot);
|
||||
// displayPlot(spectrumPlotPane, spectrumPlot);
|
||||
// }
|
||||
/**
|
||||
* update detector pane with new data
|
||||
*/
|
||||
private void updateDetectorPane(List<XYPlottable> detectorData) {
|
||||
Platform.runLater(() -> {
|
||||
if (detectorData == null) {
|
||||
throw new IllegalArgumentException("Detector data not defined");
|
||||
}
|
||||
@ -297,6 +343,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
|
||||
detectorPlotFrame.get(plotName).getConfig().setValue("visible", newValue);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private List<XYPlottable> fillDetectorData(List<NMPoint> points, int binning, boolean normalize) {
|
||||
@ -317,27 +364,6 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
|
||||
return plottables;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Fill spectrum with custom window calculator
|
||||
// *
|
||||
// * @param points
|
||||
// * @param lowerBoundCalculator
|
||||
// * @param upperBoundCalculator
|
||||
// * @return
|
||||
// */
|
||||
// private XYIntervalSeriesCollection fillSpectrumData(List<NMPoint> points, Function<NMPoint, Number> calculator) {
|
||||
// XYIntervalSeriesCollection collection = new XYIntervalSeriesCollection();
|
||||
// XYIntervalSeries ser = new XYIntervalSeries("spectrum");
|
||||
// for (NMPoint point : points) {
|
||||
// double u = point.getUread();
|
||||
// double count = calculator.apply(point).doubleValue();
|
||||
// double time = point.getLength();
|
||||
// double err = Math.sqrt(count);
|
||||
// ser.add(u, u, u, count / time, (count - err) / time, (count + err) / time);
|
||||
// }
|
||||
// collection.addSeries(ser);
|
||||
// return collection;
|
||||
// }
|
||||
@FXML
|
||||
private void checkAllAction(ActionEvent event) {
|
||||
detectorPointListView.getCheckModel().checkAll();
|
||||
@ -362,6 +388,49 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void onSpectrumExportClick(ActionEvent event) {
|
||||
if (points != null && !points.isEmpty()) {
|
||||
FileChooser fileChooser = new FileChooser();
|
||||
fileChooser.setTitle("Choose text export destination");
|
||||
fileChooser.setInitialFileName(data.getName() + "_spectrum.out");
|
||||
File destination = fileChooser.showSaveDialog(spectrumPlotPane.getScene().getWindow());
|
||||
if (destination != null) {
|
||||
String[] names = new String[]{"Uset", "Uread", "Length", "Total", "Window", "CR", "CRerr", "Timestamp"};
|
||||
int loChannel = (int) channelSlider.getLowValue();
|
||||
int upChannel = (int) channelSlider.getHighValue();
|
||||
double dTime = getDTime();
|
||||
ListDataSet spectrumDataSet = new ListDataSet(names);
|
||||
|
||||
for (NMPoint point : points) {
|
||||
spectrumDataSet.add(new MapDataPoint(names, new Object[]{
|
||||
point.getUset(),
|
||||
point.getUread(),
|
||||
point.getLength(),
|
||||
point.getEventsCount(),
|
||||
point.getCountInWindow(loChannel, upChannel),
|
||||
point.getCountRate(loChannel, upChannel, dTime),
|
||||
point.getCountRateErr(loChannel, upChannel, dTime),
|
||||
point.getStartTime()
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
try {
|
||||
String comment = String.format("Numass data viewer spectrum data export for %s%n"
|
||||
+ "Window: (%d, %d)%n"
|
||||
+ "Dead time per event: %g%n",
|
||||
data.getName(), loChannel, upChannel, dTime);
|
||||
|
||||
ColumnedDataWriter
|
||||
.writeDataSet(destination, spectrumDataSet, comment, false);
|
||||
} catch (IOException ex) {
|
||||
LoggerFactory.getLogger(getClass()).error("Destination file not found", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onExportButtonClick(ActionEvent event) {
|
||||
FileChooser fileChooser = new FileChooser();
|
||||
fileChooser.setTitle("Choose text export destination");
|
||||
|
@ -36,7 +36,8 @@ public class TestDirectoryViewer extends Application {
|
||||
NumassDataLoader reader = NumassDataLoader.fromLocalDir(null, new File("C:\\Users\\darksnake\\Dropbox\\PlayGround\\data-test\\20150703143643_1\\"));
|
||||
// NumassLoader reader = NumassLoader.fromZip(null, new File("C:\\Users\\darksnake\\Dropbox\\PlayGround\\data-test\\20150703143643_1.zip"));
|
||||
|
||||
NumassLoaderViewComponent comp = NumassLoaderViewComponent.build(reader);
|
||||
NumassLoaderViewComponent comp = new NumassLoaderViewComponent();
|
||||
comp.loadData(reader);
|
||||
// FXMLLoader fxml = new FXMLLoader(getClass().getResource("/fxml/DirectoryViewer.fxml"));
|
||||
//
|
||||
// Parent parent = fxml.load();
|
||||
|
@ -19,6 +19,7 @@ import hep.dataforge.exceptions.StorageException;
|
||||
import hep.dataforge.storage.commons.StoragePlugin;
|
||||
import java.io.IOException;
|
||||
import javafx.application.Application;
|
||||
import javafx.concurrent.Task;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
@ -34,7 +35,6 @@ public class Viewer extends Application {
|
||||
public void start(Stage primaryStage) throws StorageException, IOException {
|
||||
new StoragePlugin().startGlobal();
|
||||
|
||||
|
||||
FXMLLoader fxml = new FXMLLoader(getClass().getResource("/fxml/MainView.fxml"));
|
||||
|
||||
Parent parent = fxml.load();
|
||||
@ -52,7 +52,11 @@ public class Viewer extends Application {
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
||||
public static void runTask(Task task) {
|
||||
Thread th = new Thread(task);
|
||||
th.setDaemon(true);
|
||||
th.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
|
@ -16,6 +16,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<?import org.controlsfx.control.textfield.*?>
|
||||
<?import org.controlsfx.control.*?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import java.lang.*?>
|
||||
@ -24,9 +25,9 @@ limitations under the License.
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<fx:root id="AnchorPane" prefHeight="400.0" prefWidth="600.0" type="AnchorPane" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<fx:root id="AnchorPane" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" type="AnchorPane" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<children>
|
||||
<TabPane layoutX="200.0" layoutY="100.0" prefHeight="200.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<TabPane layoutX="200.0" layoutY="100.0" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<tabs>
|
||||
<Tab text="Info">
|
||||
<content>
|
||||
@ -41,15 +42,10 @@ limitations under the License.
|
||||
<content>
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
|
||||
<children>
|
||||
<BorderPane layoutX="200.0" layoutY="86.0" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<center>
|
||||
<AnchorPane fx:id="detectorPlotPane" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER" />
|
||||
</center>
|
||||
<right>
|
||||
<VBox fx:id="detectorOptionsPane" minWidth="-Infinity" prefWidth="200.0" spacing="2.0" style="-fx-border-color: blue;" BorderPane.alignment="CENTER">
|
||||
<BorderPane.margin>
|
||||
<Insets />
|
||||
</BorderPane.margin>
|
||||
<SplitPane dividerPositions="0.5" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<items>
|
||||
<AnchorPane fx:id="detectorPlotPane" minHeight="300.0" minWidth="300.0" prefHeight="200.0" prefWidth="200.0" />
|
||||
<VBox fx:id="detectorOptionsPane" maxWidth="250.0" prefWidth="200.0" spacing="2.0" style="-fx-border-color: blue;">
|
||||
<children>
|
||||
<Label text="Channels per bin">
|
||||
<VBox.margin>
|
||||
@ -78,8 +74,8 @@ limitations under the License.
|
||||
<padding>
|
||||
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
|
||||
</padding></VBox>
|
||||
</right>
|
||||
</BorderPane>
|
||||
</items>
|
||||
</SplitPane>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
@ -91,7 +87,7 @@ limitations under the License.
|
||||
</Tab>
|
||||
<Tab fx:id="spectrumTab" text="Spectrum">
|
||||
<content>
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
|
||||
<AnchorPane minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0">
|
||||
<children>
|
||||
<BorderPane prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<center>
|
||||
@ -100,9 +96,32 @@ limitations under the License.
|
||||
<top>
|
||||
<ToolBar prefHeight="40.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||
<items>
|
||||
<VBox>
|
||||
<children>
|
||||
<Label text="Lo channel" />
|
||||
<TextField fx:id="lowChannelField" prefWidth="60.0" />
|
||||
<RangeSlider fx:id="channelSlider" accessibleRole="SLIDER" highValue="1900.0" lowValue="300.0" majorTickUnit="500.0" max="4000.0" minorTickCount="5" prefHeight="38.0" prefWidth="336.0" showTickLabels="true" showTickMarks="true" />
|
||||
</children>
|
||||
</VBox>
|
||||
<RangeSlider fx:id="channelSlider" accessibleRole="SLIDER" highValue="1900.0" lowValue="300.0" majorTickUnit="500.0" max="4000.0" minorTickCount="5" prefHeight="38.0" prefWidth="276.0" showTickLabels="true" showTickMarks="true">
|
||||
<padding>
|
||||
<Insets left="10.0" right="10.0" />
|
||||
</padding></RangeSlider>
|
||||
<VBox>
|
||||
<children>
|
||||
<Label text="Up channel" />
|
||||
<TextField fx:id="upChannelField" prefWidth="60.0" />
|
||||
</children>
|
||||
</VBox>
|
||||
<Separator orientation="VERTICAL" />
|
||||
<VBox>
|
||||
<children>
|
||||
<Label text="Dead time (us)" />
|
||||
<TextField fx:id="dTimeField" prefHeight="25.0" prefWidth="0.0" text="7.2" />
|
||||
</children>
|
||||
</VBox>
|
||||
<Separator orientation="VERTICAL" />
|
||||
<Pane minWidth="0.0" HBox.hgrow="ALWAYS" />
|
||||
<Button fx:id="spectrumExportButton" mnemonicParsing="false" onAction="#onSpectrumExportClick" text="Export" />
|
||||
</items>
|
||||
</ToolBar>
|
||||
</top>
|
||||
|
Loading…
Reference in New Issue
Block a user