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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -13,244 +13,248 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package inr.numass.data;
|
||||
|
||||
import hep.dataforge.data.DataPoint;
|
||||
import hep.dataforge.data.MapDataPoint;
|
||||
import java.time.LocalDateTime;
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Darksnake
|
||||
*/
|
||||
public class NMPoint {
|
||||
|
||||
static final String[] dataNames = {"chanel", "count"};
|
||||
private LocalDateTime absouteTime;
|
||||
|
||||
// private MonitorCorrector corrector = null;
|
||||
// private double deadTime;
|
||||
private long eventsCount;
|
||||
|
||||
private int overflow;
|
||||
|
||||
private double pointLength;
|
||||
// private final MeasurementPoint point;
|
||||
private final int[] spectrum;
|
||||
private double uread;
|
||||
private double uset;
|
||||
|
||||
public NMPoint(RawNMPoint point) {
|
||||
if (point == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
this.pointLength = point.getLength();
|
||||
this.uset = point.getUset();
|
||||
this.uread = point.getUread();
|
||||
this.absouteTime = point.getAbsouteTime();
|
||||
this.eventsCount = point.getEventsCount();
|
||||
// this.point = point;
|
||||
spectrum = calculateSpectrum(point);
|
||||
}
|
||||
|
||||
// public PointSpectrum(RawPoint point, double deadTime) {
|
||||
// this(point);
|
||||
// this.deadTime = deadTime;
|
||||
// }
|
||||
private int[] calculateSpectrum(RawNMPoint point) {
|
||||
assert point.getEventsCount() > 0;
|
||||
|
||||
int[] result = new int[RawNMPoint.MAX_CHANEL];
|
||||
Arrays.fill(result, 0);
|
||||
point.getEvents().stream().forEach((event) -> {
|
||||
if (event.getChanel() >= RawNMPoint.MAX_CHANEL) {
|
||||
overflow++;
|
||||
} else {
|
||||
result[event.getChanel()]++;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
public DataPoint fastSlice(int... borders) {
|
||||
assert borders.length > 0;//FIXME replace by condition check
|
||||
sort(borders);
|
||||
assert borders[borders.length] < RawNMPoint.MAX_CHANEL;//FIXME replace by condition check
|
||||
|
||||
Integer[] slices = new Integer[borders.length + 2];
|
||||
String[] names = new String[borders.length + 2];
|
||||
|
||||
slices[0] = getCountInWindow(0, borders[0]);
|
||||
names[0] = Integer.toString(borders[0]);
|
||||
for (int i = 1; i < borders.length; i++) {
|
||||
slices[i] = getCountInWindow(borders[i - 1], borders[i]);
|
||||
names[i] = Integer.toString(borders[i]);
|
||||
}
|
||||
slices[borders.length + 1] = getCountInWindow(borders[borders.length], RawNMPoint.MAX_CHANEL);
|
||||
names[borders.length + 1] = Integer.toString(RawNMPoint.MAX_CHANEL);
|
||||
|
||||
slices[borders.length + 2] = RawNMPoint.MAX_CHANEL;
|
||||
names[borders.length + 2] = "TOTAL";
|
||||
|
||||
//FIXME fix it!
|
||||
return new MapDataPoint(names, slices);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the absouteTime
|
||||
*/
|
||||
public LocalDateTime getAbsouteTime() {
|
||||
return absouteTime;
|
||||
}
|
||||
|
||||
public int getCountInChanel(int chanel) {
|
||||
return spectrum[chanel];
|
||||
}
|
||||
|
||||
public int getCountInWindow(int from, int to) {
|
||||
int res = 0;
|
||||
for (int i = from; i <= to; i++) {
|
||||
res += spectrum[i];
|
||||
}
|
||||
if (res == Integer.MAX_VALUE) {
|
||||
throw new RuntimeException("integer overflow in spectrum calculation");
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public double getCountRate(int from, int to, double deadTime) {
|
||||
double wind = getCountInWindow(from, to) / getLength();
|
||||
double res;
|
||||
if (deadTime > 0) {
|
||||
double total = getEventsCount();
|
||||
double time = getLength();
|
||||
res = wind / (1 - total * deadTime / time);
|
||||
} else {
|
||||
res = wind;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public double getCountRateErr(int from, int to, double deadTime) {
|
||||
return Math.sqrt(getCountRate(from, to, deadTime) / getLength());
|
||||
}
|
||||
|
||||
public List<DataPoint> getData() {
|
||||
List<DataPoint> data = new ArrayList<>();
|
||||
for (int i = 0; i < RawNMPoint.MAX_CHANEL; i++) {
|
||||
data.add(new MapDataPoint(dataNames, i, spectrum[i]));
|
||||
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Events count - overflow
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long getEventsCount() {
|
||||
return eventsCount - getOverflow();
|
||||
}
|
||||
|
||||
public List<DataPoint> getData(int binning, boolean normalize) {
|
||||
List<DataPoint> data = new ArrayList<>();
|
||||
|
||||
double norm;
|
||||
if (normalize) {
|
||||
norm = getLength();
|
||||
} else {
|
||||
norm = 1d;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
|
||||
while (i < RawNMPoint.MAX_CHANEL - binning) {
|
||||
int start = i;
|
||||
double sum = spectrum[start] / norm;
|
||||
while (i < start + binning) {
|
||||
sum += spectrum[i] / norm;
|
||||
i++;
|
||||
}
|
||||
data.add(new MapDataPoint(dataNames, start + binning / 2d, sum));
|
||||
i++;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public Map<Double, Double> getMapWithBinning(int binning, boolean normalize) {
|
||||
Map<Double, Double> res = new LinkedHashMap<>();
|
||||
|
||||
double norm;
|
||||
if (normalize) {
|
||||
norm = getLength();
|
||||
} else {
|
||||
norm = 1d;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
|
||||
while (i < RawNMPoint.MAX_CHANEL - binning) {
|
||||
int start = i;
|
||||
double sum = spectrum[start] / norm;
|
||||
while (i < start + binning) {
|
||||
sum += spectrum[i] / norm;
|
||||
i++;
|
||||
}
|
||||
res.put(start + binning / 2d, sum);
|
||||
i++;
|
||||
}
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
public Map<Double, Double> getMapWithBinning(NMPoint reference, int binning) {
|
||||
Map<Double, Double> sp = this.getMapWithBinning(binning, true);
|
||||
Map<Double, Double> referenceSpectrum = reference.getMapWithBinning(binning, true);
|
||||
|
||||
Map<Double, Double> res = new LinkedHashMap<>();
|
||||
|
||||
sp.entrySet().stream().map((entry) -> entry.getKey()).forEach((bin) -> {
|
||||
res.put(bin, Math.max(sp.get(bin) - referenceSpectrum.get(bin), 0));
|
||||
});
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the overflow
|
||||
*/
|
||||
public int getOverflow() {
|
||||
return overflow;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the pointLength
|
||||
*/
|
||||
public double getLength() {
|
||||
return pointLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the uread
|
||||
*/
|
||||
public double getUread() {
|
||||
return uread;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the uset
|
||||
*/
|
||||
public double getUset() {
|
||||
return uset;
|
||||
}
|
||||
|
||||
}
|
||||
package inr.numass.data;
|
||||
|
||||
import hep.dataforge.data.DataPoint;
|
||||
import hep.dataforge.data.MapDataPoint;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import static java.util.Arrays.sort;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Darksnake
|
||||
*/
|
||||
public class NMPoint {
|
||||
|
||||
static final String[] dataNames = {"chanel", "count"};
|
||||
private Instant startTime;
|
||||
|
||||
// private MonitorCorrector corrector = null;
|
||||
// private double deadTime;
|
||||
private long eventsCount;
|
||||
|
||||
private int overflow;
|
||||
|
||||
private double pointLength;
|
||||
// private final MeasurementPoint point;
|
||||
private final int[] spectrum;
|
||||
private double uread;
|
||||
private double uset;
|
||||
|
||||
public NMPoint(RawNMPoint point) {
|
||||
if (point == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
this.pointLength = point.getLength();
|
||||
this.uset = point.getUset();
|
||||
this.uread = point.getUread();
|
||||
this.startTime = point.getStartTime();
|
||||
this.eventsCount = point.getEventsCount();
|
||||
// this.point = point;
|
||||
spectrum = calculateSpectrum(point);
|
||||
}
|
||||
|
||||
// public PointSpectrum(RawPoint point, double deadTime) {
|
||||
// this(point);
|
||||
// this.deadTime = deadTime;
|
||||
// }
|
||||
private int[] calculateSpectrum(RawNMPoint point) {
|
||||
assert point.getEventsCount() > 0;
|
||||
|
||||
int[] result = new int[RawNMPoint.MAX_CHANEL];
|
||||
Arrays.fill(result, 0);
|
||||
point.getEvents().stream().forEach((event) -> {
|
||||
if (event.getChanel() >= RawNMPoint.MAX_CHANEL) {
|
||||
overflow++;
|
||||
} else {
|
||||
result[event.getChanel()]++;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
public DataPoint fastSlice(int... borders) {
|
||||
assert borders.length > 0;//FIXME replace by condition check
|
||||
sort(borders);
|
||||
assert borders[borders.length] < RawNMPoint.MAX_CHANEL;//FIXME replace by condition check
|
||||
|
||||
Integer[] slices = new Integer[borders.length + 2];
|
||||
String[] names = new String[borders.length + 2];
|
||||
|
||||
slices[0] = getCountInWindow(0, borders[0]);
|
||||
names[0] = Integer.toString(borders[0]);
|
||||
for (int i = 1; i < borders.length; i++) {
|
||||
slices[i] = getCountInWindow(borders[i - 1], borders[i]);
|
||||
names[i] = Integer.toString(borders[i]);
|
||||
}
|
||||
slices[borders.length + 1] = getCountInWindow(borders[borders.length], RawNMPoint.MAX_CHANEL);
|
||||
names[borders.length + 1] = Integer.toString(RawNMPoint.MAX_CHANEL);
|
||||
|
||||
slices[borders.length + 2] = RawNMPoint.MAX_CHANEL;
|
||||
names[borders.length + 2] = "TOTAL";
|
||||
|
||||
//FIXME fix it!
|
||||
return new MapDataPoint(names, slices);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the absouteTime
|
||||
*/
|
||||
public Instant getStartTime() {
|
||||
if (startTime == null) {
|
||||
return Instant.EPOCH;
|
||||
} else {
|
||||
return startTime;
|
||||
}
|
||||
}
|
||||
|
||||
public int getCountInChanel(int chanel) {
|
||||
return spectrum[chanel];
|
||||
}
|
||||
|
||||
public int getCountInWindow(int from, int to) {
|
||||
int res = 0;
|
||||
for (int i = from; i <= to; i++) {
|
||||
res += spectrum[i];
|
||||
}
|
||||
if (res == Integer.MAX_VALUE) {
|
||||
throw new RuntimeException("integer overflow in spectrum calculation");
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public double getCountRate(int from, int to, double deadTime) {
|
||||
double wind = getCountInWindow(from, to) / getLength();
|
||||
double res;
|
||||
if (deadTime > 0) {
|
||||
double total = getEventsCount();
|
||||
double time = getLength();
|
||||
res = wind / (1 - total * deadTime / time);
|
||||
} else {
|
||||
res = wind;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public double getCountRateErr(int from, int to, double deadTime) {
|
||||
return Math.sqrt(getCountRate(from, to, deadTime) / getLength());
|
||||
}
|
||||
|
||||
public List<DataPoint> getData() {
|
||||
List<DataPoint> data = new ArrayList<>();
|
||||
for (int i = 0; i < RawNMPoint.MAX_CHANEL; i++) {
|
||||
data.add(new MapDataPoint(dataNames, i, spectrum[i]));
|
||||
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Events count - overflow
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long getEventsCount() {
|
||||
return eventsCount - getOverflow();
|
||||
}
|
||||
|
||||
public List<DataPoint> getData(int binning, boolean normalize) {
|
||||
List<DataPoint> data = new ArrayList<>();
|
||||
|
||||
double norm;
|
||||
if (normalize) {
|
||||
norm = getLength();
|
||||
} else {
|
||||
norm = 1d;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
|
||||
while (i < RawNMPoint.MAX_CHANEL - binning) {
|
||||
int start = i;
|
||||
double sum = spectrum[start] / norm;
|
||||
while (i < start + binning) {
|
||||
sum += spectrum[i] / norm;
|
||||
i++;
|
||||
}
|
||||
data.add(new MapDataPoint(dataNames, start + binning / 2d, sum));
|
||||
i++;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public Map<Double, Double> getMapWithBinning(int binning, boolean normalize) {
|
||||
Map<Double, Double> res = new LinkedHashMap<>();
|
||||
|
||||
double norm;
|
||||
if (normalize) {
|
||||
norm = getLength();
|
||||
} else {
|
||||
norm = 1d;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
|
||||
while (i < RawNMPoint.MAX_CHANEL - binning) {
|
||||
int start = i;
|
||||
double sum = spectrum[start] / norm;
|
||||
while (i < start + binning) {
|
||||
sum += spectrum[i] / norm;
|
||||
i++;
|
||||
}
|
||||
res.put(start + binning / 2d, sum);
|
||||
i++;
|
||||
}
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
public Map<Double, Double> getMapWithBinning(NMPoint reference, int binning) {
|
||||
Map<Double, Double> sp = this.getMapWithBinning(binning, true);
|
||||
Map<Double, Double> referenceSpectrum = reference.getMapWithBinning(binning, true);
|
||||
|
||||
Map<Double, Double> res = new LinkedHashMap<>();
|
||||
|
||||
sp.entrySet().stream().map((entry) -> entry.getKey()).forEach((bin) -> {
|
||||
res.put(bin, Math.max(sp.get(bin) - referenceSpectrum.get(bin), 0));
|
||||
});
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the overflow
|
||||
*/
|
||||
public int getOverflow() {
|
||||
return overflow;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the pointLength
|
||||
*/
|
||||
public double getLength() {
|
||||
return pointLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the uread
|
||||
*/
|
||||
public double getUread() {
|
||||
return uread;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the uset
|
||||
*/
|
||||
public double getUset() {
|
||||
return uset;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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];
|
||||
|
@ -13,169 +13,170 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package inr.numass.data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Хранит информацию о спектре точки, но не об отдельных событиях.
|
||||
*
|
||||
* @author Darksnake
|
||||
*/
|
||||
public class RawNMPoint implements Cloneable {
|
||||
|
||||
public static int MAX_CHANEL = 4095;
|
||||
private LocalDateTime absouteTime;
|
||||
private final List<NMEvent> events;
|
||||
private double t;
|
||||
private double uread;
|
||||
|
||||
private double uset;
|
||||
|
||||
public RawNMPoint(double U, List<NMEvent> events, double t) {
|
||||
this.uset = U;
|
||||
this.uread = U;
|
||||
this.events = events;
|
||||
this.t = t;
|
||||
}
|
||||
|
||||
public RawNMPoint(double Uset, double Uread, List<NMEvent> events, double t) {
|
||||
this.uset = Uset;
|
||||
this.uread = Uread;
|
||||
this.events = events;
|
||||
this.t = t;
|
||||
}
|
||||
|
||||
public RawNMPoint(double uset, double uread, List<NMEvent> events, double t, LocalDateTime absouteTime) {
|
||||
this.uset = uset;
|
||||
this.uread = uread;
|
||||
this.t = t;
|
||||
this.absouteTime = absouteTime;
|
||||
this.events = events;
|
||||
}
|
||||
|
||||
RawNMPoint() {
|
||||
events = new ArrayList<>();
|
||||
uset = 0;
|
||||
uread = 0;
|
||||
t = Double.NaN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RawNMPoint clone() {
|
||||
ArrayList<NMEvent> newevents = new ArrayList<>();
|
||||
for (NMEvent event : this.getEvents()) {
|
||||
newevents.add(event.clone());
|
||||
}
|
||||
return new RawNMPoint(getUset(), getUread(), newevents, getLength());
|
||||
}
|
||||
|
||||
public LocalDateTime getAbsouteTime() {
|
||||
return absouteTime;
|
||||
}
|
||||
|
||||
public double getCR() {
|
||||
return getEventsCount() / getLength();
|
||||
}
|
||||
|
||||
public double getCRError() {
|
||||
return Math.sqrt(getEventsCount()) / getLength();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the events
|
||||
*/
|
||||
public List<NMEvent> getEvents() {
|
||||
return events;
|
||||
}
|
||||
|
||||
public long getEventsCount() {
|
||||
return events.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Measurement time
|
||||
* @return the tset
|
||||
*/
|
||||
public double getLength() {
|
||||
if (Double.isNaN(t)) {
|
||||
throw new Error();
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Uread
|
||||
*/
|
||||
public double getUread() {
|
||||
if (uread <= 0) {
|
||||
return getUset();
|
||||
} else {
|
||||
return uread;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Uset
|
||||
*/
|
||||
public double getUset() {
|
||||
if (uset < 0) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return uset;
|
||||
}
|
||||
|
||||
public RawNMPoint merge(RawNMPoint point) {
|
||||
RawNMPoint res = this.clone();
|
||||
for (NMEvent newEvent : point.getEvents()) {
|
||||
res.putEvent(new NMEvent(newEvent.getChanel(), newEvent.getTime() + this.getLength()));
|
||||
}
|
||||
res.t += point.getLength();
|
||||
res.uread = (this.uread + point.uread) / 2;
|
||||
return res;
|
||||
}
|
||||
|
||||
void putEvent(NMEvent event) {
|
||||
events.add(event);
|
||||
}
|
||||
|
||||
public RawNMPoint selectChanels(int from, int to) {
|
||||
assert to > from;
|
||||
|
||||
List<NMEvent> res = new ArrayList<>();
|
||||
for (NMEvent event : this.getEvents()) {
|
||||
if ((event.getChanel() >= from) && (event.getChanel() <= to)) {
|
||||
res.add(event);
|
||||
}
|
||||
}
|
||||
return new RawNMPoint(getUset(), getUread(), res, getLength());
|
||||
}
|
||||
|
||||
void setAbsouteTime(LocalDateTime absouteTime) {
|
||||
this.absouteTime = absouteTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tset the tset to set
|
||||
*/
|
||||
void setLength(double tset) {
|
||||
this.t = tset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Uread the Uread to set
|
||||
*/
|
||||
void setUread(double Uread) {
|
||||
assert Uread >= 0;
|
||||
this.uread = Uread;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Uset the Uset to set
|
||||
*/
|
||||
void setUset(double Uset) {
|
||||
this.uset = Uset;
|
||||
}
|
||||
}
|
||||
package inr.numass.data;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Хранит информацию о спектре точки, но не об отдельных событиях.
|
||||
*
|
||||
* @author Darksnake
|
||||
*/
|
||||
public class RawNMPoint implements Cloneable {
|
||||
|
||||
public static int MAX_CHANEL = 4095;
|
||||
private Instant startTime;
|
||||
private final List<NMEvent> events;
|
||||
private double length;
|
||||
private double uread;
|
||||
|
||||
private double uset;
|
||||
|
||||
public RawNMPoint(double U, List<NMEvent> events, double t) {
|
||||
this.uset = U;
|
||||
this.uread = U;
|
||||
this.events = events;
|
||||
this.length = t;
|
||||
}
|
||||
|
||||
public RawNMPoint(double Uset, double Uread, List<NMEvent> events, double t) {
|
||||
this.uset = Uset;
|
||||
this.uread = Uread;
|
||||
this.events = events;
|
||||
this.length = t;
|
||||
}
|
||||
|
||||
public RawNMPoint(double uset, double uread, List<NMEvent> events, double t, Instant absouteTime) {
|
||||
this.uset = uset;
|
||||
this.uread = uread;
|
||||
this.length = t;
|
||||
this.startTime = absouteTime;
|
||||
this.events = events;
|
||||
}
|
||||
|
||||
RawNMPoint() {
|
||||
events = new ArrayList<>();
|
||||
uset = 0;
|
||||
uread = 0;
|
||||
length = Double.NaN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RawNMPoint clone() {
|
||||
ArrayList<NMEvent> newevents = new ArrayList<>();
|
||||
for (NMEvent event : this.getEvents()) {
|
||||
newevents.add(event.clone());
|
||||
}
|
||||
return new RawNMPoint(getUset(), getUread(), newevents, getLength());
|
||||
}
|
||||
|
||||
public Instant getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public double getCR() {
|
||||
return getEventsCount() / getLength();
|
||||
}
|
||||
|
||||
public double getCRError() {
|
||||
return Math.sqrt(getEventsCount()) / getLength();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the events
|
||||
*/
|
||||
public List<NMEvent> getEvents() {
|
||||
return events;
|
||||
}
|
||||
|
||||
public long getEventsCount() {
|
||||
return events.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Measurement time
|
||||
* @return the tset
|
||||
*/
|
||||
public double getLength() {
|
||||
if (Double.isNaN(length)) {
|
||||
throw new Error();
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Uread
|
||||
*/
|
||||
public double getUread() {
|
||||
if (uread <= 0) {
|
||||
return getUset();
|
||||
} else {
|
||||
return uread;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Uset
|
||||
*/
|
||||
public double getUset() {
|
||||
if (uset < 0) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return uset;
|
||||
}
|
||||
|
||||
public RawNMPoint merge(RawNMPoint point) {
|
||||
RawNMPoint res = this.clone();
|
||||
for (NMEvent newEvent : point.getEvents()) {
|
||||
res.putEvent(new NMEvent(newEvent.getChanel(), newEvent.getTime() + this.getLength()));
|
||||
}
|
||||
res.length += point.getLength();
|
||||
res.uread = (this.uread + point.uread) / 2;
|
||||
return res;
|
||||
}
|
||||
|
||||
void putEvent(NMEvent event) {
|
||||
events.add(event);
|
||||
}
|
||||
|
||||
public RawNMPoint selectChanels(int from, int to) {
|
||||
assert to > from;
|
||||
|
||||
List<NMEvent> res = new ArrayList<>();
|
||||
for (NMEvent event : this.getEvents()) {
|
||||
if ((event.getChanel() >= from) && (event.getChanel() <= to)) {
|
||||
res.add(event);
|
||||
}
|
||||
}
|
||||
return new RawNMPoint(getUset(), getUread(), res, getLength());
|
||||
}
|
||||
|
||||
void setStartTime(Instant absouteTime) {
|
||||
this.startTime = absouteTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tset the tset to set
|
||||
*/
|
||||
void setLength(double tset) {
|
||||
this.length = tset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Uread the Uread to set
|
||||
*/
|
||||
void setUread(double Uread) {
|
||||
assert Uread >= 0;
|
||||
this.uread = Uread;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Uset the Uset to set
|
||||
*/
|
||||
void setUset(double Uset) {
|
||||
this.uset = Uset;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,100 +13,94 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package inr.numass.data;
|
||||
|
||||
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.values.Value;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Darksnake
|
||||
*/
|
||||
public class SpectrumDataAdapter extends XYDataAdapter {
|
||||
|
||||
private static final String ANNOTATION_TIMENAME = "timeName";
|
||||
|
||||
private String timeName = "time";
|
||||
|
||||
public SpectrumDataAdapter() {
|
||||
}
|
||||
|
||||
public SpectrumDataAdapter(Meta aliasAnnotation) {
|
||||
super(aliasAnnotation);
|
||||
this.timeName = aliasAnnotation.getString(ANNOTATION_TIMENAME, "X");
|
||||
}
|
||||
|
||||
public SpectrumDataAdapter(String xName, String yName, String yErrName, String timeTime) {
|
||||
super(xName, yName, yErrName);
|
||||
this.timeName = timeTime;
|
||||
}
|
||||
|
||||
public SpectrumDataAdapter(String xName, String yName, String timeTime) {
|
||||
super(xName, yName);
|
||||
this.timeName = timeTime;
|
||||
}
|
||||
|
||||
public double getTime(DataPoint point) {
|
||||
if (point.names().contains(timeName)) {
|
||||
return point.getDouble(timeName);
|
||||
} else {
|
||||
return 1d;
|
||||
}
|
||||
}
|
||||
|
||||
public DataPoint buildSpectrumDataPoint(double x, long count, double t) {
|
||||
return new MapDataPoint(new String[]{xName,yName,timeName}, 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean providesYError(DataPoint point) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Value getYerr(DataPoint point) throws NameNotFoundException {
|
||||
if (point.names().contains(yErrName)) {
|
||||
return Value.of(super.getYerr(point).doubleValue()/getTime(point));
|
||||
} else{
|
||||
double y = super.getY(point).doubleValue();
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value getY(DataPoint point) {
|
||||
return Value.of(super.getY(point).doubleValue() / getTime(point));
|
||||
}
|
||||
|
||||
}
|
||||
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.meta.MetaBuilder;
|
||||
import hep.dataforge.values.Value;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Darksnake
|
||||
*/
|
||||
public class SpectrumDataAdapter extends XYDataAdapter {
|
||||
|
||||
private static final String POINT_LENGTH_NAME = "time";
|
||||
|
||||
public SpectrumDataAdapter() {
|
||||
}
|
||||
|
||||
public SpectrumDataAdapter(Meta meta) {
|
||||
super(meta);
|
||||
}
|
||||
|
||||
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 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) {
|
||||
return this.getFrom(point, POINT_LENGTH_NAME, 1d).doubleValue();
|
||||
}
|
||||
|
||||
public DataPoint buildSpectrumDataPoint(double x, long count, double 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[]{getValueName(X_NAME), getValueName(Y_NAME),
|
||||
getValueName(Y_ERR_NAME), getValueName(POINT_LENGTH_NAME)},
|
||||
x, count, countErr, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean providesYError(DataPoint point) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value getYerr(DataPoint point) throws NameNotFoundException {
|
||||
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 {
|
||||
return Value.of(Math.sqrt(y) / getTime(point));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public long getCount(DataPoint point) {
|
||||
return super.getY(point).numberValue().longValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value getY(DataPoint point) {
|
||||
return Value.of(super.getY(point).doubleValue() / getTime(point));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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()));
|
||||
}
|
||||
|
@ -13,71 +13,71 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package inr.numass.debunch;
|
||||
|
||||
import inr.numass.data.NMEvent;
|
||||
import inr.numass.data.RawNMPoint;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Darksnake
|
||||
*/
|
||||
public class DebunchReportImpl implements DebunchReport {
|
||||
|
||||
private final List<Frame> bunches;
|
||||
private final RawNMPoint pointAfter;
|
||||
private final RawNMPoint pointBefore;
|
||||
|
||||
public DebunchReportImpl(RawNMPoint pointBefore, RawNMPoint pointAfter, List<Frame> bunches) {
|
||||
this.pointBefore = pointBefore;
|
||||
this.pointAfter = pointAfter;
|
||||
this.bunches = bunches;
|
||||
}
|
||||
|
||||
DebunchReportImpl(RawNMPoint pointBefore, DebunchData debunchData) {
|
||||
this.pointBefore = pointBefore;
|
||||
pointAfter = new RawNMPoint(pointBefore.getUset(),pointBefore.getUread(),
|
||||
debunchData.getDebunchedEvents(), debunchData.getDebunchedLength(),pointBefore.getAbsouteTime());
|
||||
this.bunches = debunchData.getBunches();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public double eventsFiltred() {
|
||||
return 1-(double)getPoint().getEventsCount()/getInitialPoint().getEventsCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NMEvent> getBunchEvents() {
|
||||
List<NMEvent> res = new ArrayList<>();
|
||||
for (Frame interval : getBunches()) {
|
||||
res.addAll(interval.getEvents());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Frame> getBunches() {
|
||||
return bunches;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RawNMPoint getInitialPoint() {
|
||||
return pointBefore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RawNMPoint getPoint() {
|
||||
return pointAfter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double timeFiltred() {
|
||||
return 1-getPoint().getLength()/getInitialPoint().getLength();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
package inr.numass.debunch;
|
||||
|
||||
import inr.numass.data.NMEvent;
|
||||
import inr.numass.data.RawNMPoint;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Darksnake
|
||||
*/
|
||||
public class DebunchReportImpl implements DebunchReport {
|
||||
|
||||
private final List<Frame> bunches;
|
||||
private final RawNMPoint pointAfter;
|
||||
private final RawNMPoint pointBefore;
|
||||
|
||||
public DebunchReportImpl(RawNMPoint pointBefore, RawNMPoint pointAfter, List<Frame> bunches) {
|
||||
this.pointBefore = pointBefore;
|
||||
this.pointAfter = pointAfter;
|
||||
this.bunches = bunches;
|
||||
}
|
||||
|
||||
DebunchReportImpl(RawNMPoint pointBefore, DebunchData debunchData) {
|
||||
this.pointBefore = pointBefore;
|
||||
pointAfter = new RawNMPoint(pointBefore.getUset(),pointBefore.getUread(),
|
||||
debunchData.getDebunchedEvents(), debunchData.getDebunchedLength(),pointBefore.getStartTime());
|
||||
this.bunches = debunchData.getBunches();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public double eventsFiltred() {
|
||||
return 1-(double)getPoint().getEventsCount()/getInitialPoint().getEventsCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NMEvent> getBunchEvents() {
|
||||
List<NMEvent> res = new ArrayList<>();
|
||||
for (Frame interval : getBunches()) {
|
||||
res.addAll(interval.getEvents());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Frame> getBunches() {
|
||||
return bunches;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RawNMPoint getInitialPoint() {
|
||||
return pointBefore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RawNMPoint getPoint() {
|
||||
return pointAfter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double timeFiltred() {
|
||||
return 1-getPoint().getLength()/getInitialPoint().getLength();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,171 +13,174 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package inr.numass.generators;
|
||||
|
||||
import inr.numass.data.NMEvent;
|
||||
import inr.numass.data.RawNMPoint;
|
||||
import static java.lang.Math.max;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Darksnake
|
||||
*/
|
||||
public final class EventChainGenerator {
|
||||
|
||||
private final static double us = 1e-6;
|
||||
|
||||
private double blockStartTime = 0;
|
||||
|
||||
private final List<NMEvent> generatedChain = new ArrayList<>();
|
||||
private final EventGenerator generator;
|
||||
private final double length;
|
||||
private final List<NMEvent> pileupChain = new ArrayList<>();
|
||||
|
||||
private final List<NMEvent> registredChain = new ArrayList<>();
|
||||
|
||||
public EventChainGenerator(double cr, double length) {
|
||||
generator = new EventGenerator(cr);
|
||||
this.length = length;
|
||||
|
||||
run();
|
||||
}
|
||||
|
||||
public EventChainGenerator(double cr, double length, RawNMPoint source, int minChanel, int maxChanel) {
|
||||
generator = new EventGenerator(cr);
|
||||
this.generator.loadFromPoint(source, minChanel, maxChanel);
|
||||
this.length = length;
|
||||
|
||||
run();
|
||||
}
|
||||
|
||||
public EventChainGenerator(double cr, double length, Map<Double,Double> spectrum, int minChanel, int maxChanel) {
|
||||
generator = new EventGenerator(cr);
|
||||
this.generator.loadFromSpectrum(spectrum, minChanel, maxChanel);
|
||||
this.length = length;
|
||||
|
||||
run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Амлпитуда второго сигнала в зависимости от амплитуд наложенных сигналов и
|
||||
* задержки
|
||||
*
|
||||
* @param delay
|
||||
* @return
|
||||
*/
|
||||
private short getNewChanel(double delay, short prevChanel, short newChanel) {
|
||||
assert delay > 0;
|
||||
//эмпирическая формула для канала
|
||||
double x = delay / us;
|
||||
double coef = max(0, 0.99078 + 0.05098 * x - 0.45775 * x * x + 0.10962 * x * x * x);
|
||||
|
||||
return (short) (prevChanel + coef * newChanel);
|
||||
}
|
||||
|
||||
public RawNMPoint getPileUp() {
|
||||
return new RawNMPoint(2, pileupChain, length);
|
||||
}
|
||||
|
||||
public RawNMPoint getPointAsGenerated() {
|
||||
return new RawNMPoint(0, generatedChain, length);
|
||||
}
|
||||
|
||||
public RawNMPoint getPointAsRegistred() {
|
||||
return new RawNMPoint(1, registredChain, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Имеется второй сигнал
|
||||
*
|
||||
* @param delay
|
||||
* @return
|
||||
*/
|
||||
private boolean hasNew(double delay) {
|
||||
if (delay > 2.65 * us) {
|
||||
return false;
|
||||
} else if (delay < 2.35 * us) {
|
||||
return true;
|
||||
} else {
|
||||
return heads((2.65 * us - delay) / 0.3 / us);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean heads(double prob) {
|
||||
double r = generator.nextUniform();
|
||||
return r < prob;
|
||||
}
|
||||
|
||||
NMEvent nextEvent(NMEvent prev) {
|
||||
if (prev == null) {
|
||||
return generator.nextEvent(new NMEvent((short)0, 0));
|
||||
}
|
||||
|
||||
NMEvent event = generator.nextEvent(prev);
|
||||
generatedChain.add(event);
|
||||
double delay = event.getTime() - blockStartTime;
|
||||
if (notDT(delay)) {
|
||||
//Если система сбора данных успела переварить предыдущие события
|
||||
registredChain.add(event);
|
||||
blockStartTime = event.getTime();
|
||||
return event;
|
||||
} else {
|
||||
if ((!prevSurvived(delay)) && (!registredChain.isEmpty())) {
|
||||
//если первое событие не выжило, а ушло в наложения
|
||||
registredChain.remove(registredChain.size() - 1);
|
||||
}
|
||||
if (hasNew(delay)) {
|
||||
// Если есть событие с увеличенной амлитудой
|
||||
NMEvent pileup = new NMEvent(getNewChanel(delay, prev.getChanel(), event.getChanel()), event.getTime());
|
||||
registredChain.add(pileup);
|
||||
pileupChain.add(pileup);
|
||||
}
|
||||
//возвращаем предыдущее событие, чтобы отсчитывать мертвое время от него
|
||||
return prev;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Не попал в мертвое время и наложения
|
||||
*
|
||||
* @param delay
|
||||
* @return
|
||||
*/
|
||||
private boolean notDT(double delay) {
|
||||
if (delay > 7.0 * us) {
|
||||
return true;
|
||||
} else if (delay < 6.5 * us) {
|
||||
return false;
|
||||
} else {
|
||||
return heads((delay - 6.5 * us) / 0.5 / us);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Выжило предыдушее событие
|
||||
*
|
||||
* @param delay
|
||||
* @return
|
||||
*/
|
||||
private boolean prevSurvived(double delay) {
|
||||
if (delay > 2.65 * us) {
|
||||
return true;
|
||||
} else if (delay < 2.35 * us) {
|
||||
return false;
|
||||
} else {
|
||||
return heads((delay - 2.35 * us) / 0.3 / us);
|
||||
}
|
||||
}
|
||||
|
||||
private void run() {
|
||||
NMEvent next = null;
|
||||
|
||||
do {
|
||||
next = nextEvent(next);
|
||||
} while (next.getTime() < length);
|
||||
}
|
||||
|
||||
}
|
||||
package inr.numass.generators;
|
||||
|
||||
import inr.numass.data.NMEvent;
|
||||
import inr.numass.data.RawNMPoint;
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Darksnake
|
||||
*/
|
||||
public final class EventChainGenerator {
|
||||
|
||||
private final static double us = 1e-6;
|
||||
|
||||
private double blockStartTime = 0;
|
||||
|
||||
private final List<NMEvent> generatedChain = new ArrayList<>();
|
||||
private final EventGenerator generator;
|
||||
private final double length;
|
||||
private final List<NMEvent> pileupChain = new ArrayList<>();
|
||||
|
||||
private final List<NMEvent> registredChain = new ArrayList<>();
|
||||
|
||||
public EventChainGenerator(double cr, double length) {
|
||||
generator = new EventGenerator(cr);
|
||||
this.length = length;
|
||||
|
||||
run();
|
||||
}
|
||||
|
||||
public EventChainGenerator(double cr, double length, RawNMPoint source, int minChanel, int maxChanel) {
|
||||
generator = new EventGenerator(cr);
|
||||
this.generator.loadFromPoint(source, minChanel, maxChanel);
|
||||
this.length = length;
|
||||
|
||||
run();
|
||||
}
|
||||
|
||||
public EventChainGenerator(double cr, double length, Map<Double,Double> spectrum, int minChanel, int maxChanel) {
|
||||
generator = new EventGenerator(cr);
|
||||
this.generator.loadFromSpectrum(spectrum, minChanel, maxChanel);
|
||||
this.length = length;
|
||||
|
||||
run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Амлпитуда второго сигнала в зависимости от амплитуд наложенных сигналов и
|
||||
* задержки
|
||||
*
|
||||
* @param delay
|
||||
* @return
|
||||
*/
|
||||
private short getNewChanel(double delay, short prevChanel, short newChanel) {
|
||||
assert delay > 0;
|
||||
//эмпирическая формула для канала
|
||||
double x = delay / us;
|
||||
double coef = max(0, 0.99078 + 0.05098 * x - 0.45775 * x * x + 0.10962 * x * x * x);
|
||||
|
||||
return (short) (prevChanel + coef * newChanel);
|
||||
}
|
||||
|
||||
public RawNMPoint getPileUp() {
|
||||
return new RawNMPoint(2, pileupChain, length);
|
||||
}
|
||||
|
||||
public RawNMPoint getPointAsGenerated() {
|
||||
return new RawNMPoint(0, generatedChain, length);
|
||||
}
|
||||
|
||||
public RawNMPoint getPointAsRegistred() {
|
||||
return new RawNMPoint(1, registredChain, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Имеется второй сигнал
|
||||
*
|
||||
* @param delay
|
||||
* @return
|
||||
*/
|
||||
private boolean hasNew(double delay) {
|
||||
if (delay > 2.65 * us) {
|
||||
return false;
|
||||
} else if (delay < 2.35 * us) {
|
||||
return true;
|
||||
} else {
|
||||
return heads((2.65 * us - delay) / 0.3 / us);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean heads(double prob) {
|
||||
double r = generator.nextUniform();
|
||||
return r < prob;
|
||||
}
|
||||
|
||||
NMEvent nextEvent(NMEvent prev) {
|
||||
if (prev == null) {
|
||||
return generator.nextEvent(new NMEvent((short)0, 0));
|
||||
}
|
||||
|
||||
NMEvent event = generator.nextEvent(prev);
|
||||
generatedChain.add(event);
|
||||
double delay = event.getTime() - blockStartTime;
|
||||
if (notDT(delay)) {
|
||||
//Если система сбора данных успела переварить предыдущие события
|
||||
registredChain.add(event);
|
||||
blockStartTime = event.getTime();
|
||||
return event;
|
||||
} else {
|
||||
if ((!prevSurvived(delay)) && (!registredChain.isEmpty())) {
|
||||
//если первое событие не выжило, а ушло в наложения
|
||||
registredChain.remove(registredChain.size() - 1);
|
||||
}
|
||||
if (hasNew(delay)) {
|
||||
// Если есть событие с увеличенной амлитудой
|
||||
NMEvent pileup = new NMEvent(getNewChanel(delay, prev.getChanel(), event.getChanel()), event.getTime());
|
||||
registredChain.add(pileup);
|
||||
pileupChain.add(pileup);
|
||||
}
|
||||
//возвращаем предыдущее событие, чтобы отсчитывать мертвое время от него
|
||||
return prev;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Не попал в мертвое время и наложения
|
||||
*
|
||||
* @param delay
|
||||
* @return
|
||||
*/
|
||||
private boolean notDT(double delay) {
|
||||
if (delay > 7.0 * us) {
|
||||
return true;
|
||||
} else if (delay < 6.5 * us) {
|
||||
return false;
|
||||
} else {
|
||||
return heads((delay - 6.5 * us) / 0.5 / us);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Выжило предыдушее событие
|
||||
*
|
||||
* @param delay
|
||||
* @return
|
||||
*/
|
||||
private boolean prevSurvived(double delay) {
|
||||
if (delay > 2.65 * us) {
|
||||
return true;
|
||||
} else if (delay < 2.35 * us) {
|
||||
return false;
|
||||
} else {
|
||||
return heads((delay - 2.35 * us) / 0.3 / us);
|
||||
}
|
||||
}
|
||||
|
||||
private void run() {
|
||||
NMEvent next = null;
|
||||
|
||||
do {
|
||||
next = nextEvent(next);
|
||||
} while (next.getTime() < length);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,174 +13,174 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package inr.numass.utils;
|
||||
|
||||
import hep.dataforge.context.GlobalContext;
|
||||
import hep.dataforge.data.DataPoint;
|
||||
import hep.dataforge.data.ListDataSet;
|
||||
import hep.dataforge.data.MapDataPoint;
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Darksnake
|
||||
*/
|
||||
public class OldDataReader {
|
||||
|
||||
public static ListDataSet readConfig(String path) throws FileNotFoundException {
|
||||
String[] list = {"X","time","ushift"};
|
||||
ListDataSet res = new ListDataSet(list);
|
||||
File file = GlobalContext.instance().io().getFile(path);
|
||||
Scanner sc = new Scanner(file);
|
||||
sc.nextLine();
|
||||
|
||||
while(sc.hasNextLine()){
|
||||
String line = sc.nextLine();
|
||||
Scanner lineScan = new Scanner(line);
|
||||
int time = lineScan.nextInt();
|
||||
double u = lineScan.nextDouble();
|
||||
double ushift = 0;
|
||||
if(lineScan.hasNextDouble()){
|
||||
ushift = lineScan.nextDouble();
|
||||
}
|
||||
DataPoint point = new MapDataPoint(list, u,time,ushift);
|
||||
res.add(point);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static ListDataSet readData(String path, double Elow) {
|
||||
SpectrumDataAdapter factory = new SpectrumDataAdapter();
|
||||
ListDataSet res = factory.buildEmptyDataSet("");
|
||||
File file = GlobalContext.instance().io().getFile(path);
|
||||
double x;
|
||||
int count;
|
||||
int time;
|
||||
|
||||
setDefault(Locale.ENGLISH);
|
||||
|
||||
Scanner sc;
|
||||
try {
|
||||
sc = new Scanner(file);
|
||||
} catch (FileNotFoundException ex) {
|
||||
throw new RuntimeException(ex.getMessage());
|
||||
}
|
||||
double dummy;
|
||||
// sc.skip("\\D*");
|
||||
while (!sc.hasNextDouble()) {
|
||||
sc.nextLine();
|
||||
}
|
||||
while (sc.hasNextDouble() | sc.hasNextInt()) {
|
||||
/*Надо сделать, чтобы считывало весь файл*/
|
||||
x = sc.nextDouble();
|
||||
|
||||
dummy = sc.nextInt();
|
||||
|
||||
time = sc.nextInt();
|
||||
|
||||
dummy = sc.nextInt();
|
||||
dummy = sc.nextInt();
|
||||
dummy = sc.nextInt();
|
||||
dummy = sc.nextInt();
|
||||
dummy = sc.nextInt();
|
||||
dummy = sc.nextInt();
|
||||
|
||||
count = sc.nextInt();
|
||||
// count = (int) (count / (1 - 2.8E-6 / time * count));
|
||||
|
||||
dummy = sc.nextInt();
|
||||
dummy = sc.nextDouble();
|
||||
dummy = sc.nextDouble();
|
||||
dummy = sc.nextDouble();
|
||||
DataPoint point = factory.buildSpectrumDataPoint(x, count, time);
|
||||
if (x >= Elow) {
|
||||
res.add(point);
|
||||
}
|
||||
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static ListDataSet readDataAsGun(String path, double Elow) {
|
||||
SpectrumDataAdapter factory = new SpectrumDataAdapter();
|
||||
ListDataSet res = factory.buildEmptyDataSet("");
|
||||
File file = GlobalContext.instance().io().getFile(path);
|
||||
double x;
|
||||
long count;
|
||||
int time;
|
||||
|
||||
setDefault(Locale.ENGLISH);
|
||||
|
||||
Scanner sc;
|
||||
try {
|
||||
sc = new Scanner(file);
|
||||
} catch (FileNotFoundException ex) {
|
||||
throw new RuntimeException(ex.getMessage());
|
||||
}
|
||||
double dummy;
|
||||
sc.nextLine();
|
||||
while (sc.hasNext()) {
|
||||
x = sc.nextDouble();
|
||||
time = sc.nextInt();
|
||||
dummy = sc.nextInt();
|
||||
count = sc.nextLong();
|
||||
dummy = sc.nextDouble();
|
||||
dummy = sc.nextDouble();
|
||||
DataPoint point = factory.buildSpectrumDataPoint(x, count, time);
|
||||
if (x > Elow) {
|
||||
res.add(point);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static ListDataSet readSpectrumData(String path){
|
||||
SpectrumDataAdapter factory = new SpectrumDataAdapter();
|
||||
ListDataSet res = factory.buildEmptyDataSet("");
|
||||
File file = GlobalContext.instance().io().getFile(path);
|
||||
double x;
|
||||
double count;
|
||||
double time;
|
||||
|
||||
double cr;
|
||||
double crErr;
|
||||
|
||||
setDefault(Locale.ENGLISH);
|
||||
|
||||
Scanner sc;
|
||||
try {
|
||||
sc = new Scanner(file);
|
||||
} catch (FileNotFoundException ex) {
|
||||
throw new RuntimeException(ex.getMessage());
|
||||
}
|
||||
|
||||
while (sc.hasNext()) {
|
||||
String line = sc.nextLine();
|
||||
if (!line.startsWith("*")) {
|
||||
Scanner lsc = new Scanner(line);
|
||||
if (lsc.hasNextDouble() || lsc.hasNextInt()) {
|
||||
|
||||
x = lsc.nextDouble();
|
||||
lsc.next();
|
||||
time = lsc.nextDouble();
|
||||
lsc.next();
|
||||
lsc.next();
|
||||
count = lsc.nextDouble();
|
||||
cr = lsc.nextDouble();
|
||||
crErr = lsc.nextDouble();
|
||||
DataPoint point = factory.buildSpectrumDataPoint(x, (long)(cr*time), crErr*time, time);
|
||||
// SpectrumDataPoint point = new SpectrumDataPoint(x, (long) count, time);
|
||||
|
||||
res.add(point);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
package inr.numass.utils;
|
||||
|
||||
import hep.dataforge.context.GlobalContext;
|
||||
import hep.dataforge.data.DataPoint;
|
||||
import hep.dataforge.data.ListDataSet;
|
||||
import hep.dataforge.data.MapDataPoint;
|
||||
import inr.numass.data.SpectrumDataAdapter;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Locale;
|
||||
import java.util.Scanner;
|
||||
import static java.util.Locale.setDefault;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Darksnake
|
||||
*/
|
||||
public class OldDataReader {
|
||||
|
||||
public static ListDataSet readConfig(String path) throws FileNotFoundException {
|
||||
String[] list = {"X","time","ushift"};
|
||||
ListDataSet res = new ListDataSet(list);
|
||||
File file = GlobalContext.instance().io().getFile(path);
|
||||
Scanner sc = new Scanner(file);
|
||||
sc.nextLine();
|
||||
|
||||
while(sc.hasNextLine()){
|
||||
String line = sc.nextLine();
|
||||
Scanner lineScan = new Scanner(line);
|
||||
int time = lineScan.nextInt();
|
||||
double u = lineScan.nextDouble();
|
||||
double ushift = 0;
|
||||
if(lineScan.hasNextDouble()){
|
||||
ushift = lineScan.nextDouble();
|
||||
}
|
||||
DataPoint point = new MapDataPoint(list, u,time,ushift);
|
||||
res.add(point);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static ListDataSet readData(String path, double Elow) {
|
||||
SpectrumDataAdapter factory = new SpectrumDataAdapter();
|
||||
ListDataSet res = new ListDataSet(factory.getFormat());
|
||||
File file = GlobalContext.instance().io().getFile(path);
|
||||
double x;
|
||||
int count;
|
||||
int time;
|
||||
|
||||
setDefault(Locale.ENGLISH);
|
||||
|
||||
Scanner sc;
|
||||
try {
|
||||
sc = new Scanner(file);
|
||||
} catch (FileNotFoundException ex) {
|
||||
throw new RuntimeException(ex.getMessage());
|
||||
}
|
||||
double dummy;
|
||||
// sc.skip("\\D*");
|
||||
while (!sc.hasNextDouble()) {
|
||||
sc.nextLine();
|
||||
}
|
||||
while (sc.hasNextDouble() | sc.hasNextInt()) {
|
||||
/*Надо сделать, чтобы считывало весь файл*/
|
||||
x = sc.nextDouble();
|
||||
|
||||
dummy = sc.nextInt();
|
||||
|
||||
time = sc.nextInt();
|
||||
|
||||
dummy = sc.nextInt();
|
||||
dummy = sc.nextInt();
|
||||
dummy = sc.nextInt();
|
||||
dummy = sc.nextInt();
|
||||
dummy = sc.nextInt();
|
||||
dummy = sc.nextInt();
|
||||
|
||||
count = sc.nextInt();
|
||||
// count = (int) (count / (1 - 2.8E-6 / time * count));
|
||||
|
||||
dummy = sc.nextInt();
|
||||
dummy = sc.nextDouble();
|
||||
dummy = sc.nextDouble();
|
||||
dummy = sc.nextDouble();
|
||||
DataPoint point = factory.buildSpectrumDataPoint(x, count, time);
|
||||
if (x >= Elow) {
|
||||
res.add(point);
|
||||
}
|
||||
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static ListDataSet readDataAsGun(String path, double Elow) {
|
||||
SpectrumDataAdapter factory = new SpectrumDataAdapter();
|
||||
ListDataSet res = new ListDataSet(factory.getFormat());
|
||||
File file = GlobalContext.instance().io().getFile(path);
|
||||
double x;
|
||||
long count;
|
||||
int time;
|
||||
|
||||
setDefault(Locale.ENGLISH);
|
||||
|
||||
Scanner sc;
|
||||
try {
|
||||
sc = new Scanner(file);
|
||||
} catch (FileNotFoundException ex) {
|
||||
throw new RuntimeException(ex.getMessage());
|
||||
}
|
||||
double dummy;
|
||||
sc.nextLine();
|
||||
while (sc.hasNext()) {
|
||||
x = sc.nextDouble();
|
||||
time = sc.nextInt();
|
||||
dummy = sc.nextInt();
|
||||
count = sc.nextLong();
|
||||
dummy = sc.nextDouble();
|
||||
dummy = sc.nextDouble();
|
||||
DataPoint point = factory.buildSpectrumDataPoint(x, count, time);
|
||||
if (x > Elow) {
|
||||
res.add(point);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static ListDataSet readSpectrumData(String path){
|
||||
SpectrumDataAdapter factory = new SpectrumDataAdapter();
|
||||
ListDataSet res = new ListDataSet(factory.getFormat());
|
||||
File file = GlobalContext.instance().io().getFile(path);
|
||||
double x;
|
||||
double count;
|
||||
double time;
|
||||
|
||||
double cr;
|
||||
double crErr;
|
||||
|
||||
setDefault(Locale.ENGLISH);
|
||||
|
||||
Scanner sc;
|
||||
try {
|
||||
sc = new Scanner(file);
|
||||
} catch (FileNotFoundException ex) {
|
||||
throw new RuntimeException(ex.getMessage());
|
||||
}
|
||||
|
||||
while (sc.hasNext()) {
|
||||
String line = sc.nextLine();
|
||||
if (!line.startsWith("*")) {
|
||||
Scanner lsc = new Scanner(line);
|
||||
if (lsc.hasNextDouble() || lsc.hasNextInt()) {
|
||||
|
||||
x = lsc.nextDouble();
|
||||
lsc.next();
|
||||
time = lsc.nextDouble();
|
||||
lsc.next();
|
||||
lsc.next();
|
||||
count = lsc.nextDouble();
|
||||
cr = lsc.nextDouble();
|
||||
crErr = lsc.nextDouble();
|
||||
DataPoint point = factory.buildSpectrumDataPoint(x, (long)(cr*time), crErr*time, time);
|
||||
// SpectrumDataPoint point = new SpectrumDataPoint(x, (long) count, time);
|
||||
|
||||
res.add(point);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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(() -> {
|
||||
try {
|
||||
Task dirLoadTask = new DirectoryLoadTask(rootDir.toURI().toString());
|
||||
postTask(dirLoadTask);
|
||||
Viewer.runTask(dirLoadTask);
|
||||
}
|
||||
|
||||
NumassStorage root = NumassStorage.buildLocalNumassRoot(rootDir, true);
|
||||
setRootStorage(root);
|
||||
}
|
||||
|
||||
} catch (StorageException ex) {
|
||||
setProgress(0);
|
||||
setProgressText("Failed to load local storage");
|
||||
Logger.getLogger(MainViewerController.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}, "loader thread").start();
|
||||
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.buildNumassRoot(uri, true, false);
|
||||
setRootStorage(root);
|
||||
Platform.runLater(() -> storagePathLabel.setText("Storage: " + uri));
|
||||
} catch (StorageException ex) {
|
||||
updateProgress(0, 1);
|
||||
updateMessage("Failed to load storage " + uri);
|
||||
Logger.getLogger(MainViewerController.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
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());
|
||||
});
|
||||
|
||||
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());
|
||||
});
|
||||
|
||||
@Override
|
||||
public void setProgressText(String text) {
|
||||
Platform.runLater(() -> statusBar.setText(text));
|
||||
//statusBar.setText(text);
|
||||
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,28 +213,46 @@ 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> {
|
||||
|
||||
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);
|
||||
AnchorPane.setRightAnchor(component, 0.0);
|
||||
AnchorPane.setLeftAnchor(component, 0.0);
|
||||
AnchorPane.setBottomAnchor(component, 0.0);
|
||||
numassLoaderViewContainer.requestLayout();
|
||||
});
|
||||
postTask(treeBuilderTask);
|
||||
Viewer.runTask(treeBuilderTask);
|
||||
try {
|
||||
new NumassLoaderTreeBuilder(MainViewerController.this).fillTree(numassLoaderDataTree, rootStorage, (NumassData loader) -> {
|
||||
NumassLoaderViewComponent component = NumassLoaderViewComponent.build(loader);
|
||||
numassLoaderViewContainer.getChildren().clear();
|
||||
numassLoaderViewContainer.getChildren().add(component);
|
||||
AnchorPane.setTopAnchor(component, 0.0);
|
||||
AnchorPane.setRightAnchor(component, 0.0);
|
||||
AnchorPane.setLeftAnchor(component, 0.0);
|
||||
AnchorPane.setBottomAnchor(component, 0.0);
|
||||
numassLoaderViewContainer.requestLayout();
|
||||
});
|
||||
setProgress(0);
|
||||
setProgressText("Loaded");
|
||||
} catch (StorageException ex) {
|
||||
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,86 +119,105 @@ public class MspViewController implements Initializable {
|
||||
|
||||
public void fillMspData(Storage rootStorage) {
|
||||
if (rootStorage != null) {
|
||||
try {
|
||||
List<DataPoint> mspData = getMspData(rootStorage);
|
||||
Map<String, XYSeries> series = new HashMap<>();
|
||||
MspDataFillTask fillTask = new MspDataFillTask(rootStorage);
|
||||
if(callback!= null){
|
||||
callback.postTask(fillTask);
|
||||
}
|
||||
Viewer.runTask(fillTask);
|
||||
}
|
||||
}
|
||||
|
||||
for (DataPoint point : mspData) {
|
||||
for (String name : point.names()) {
|
||||
if (!name.equals("timestamp")) {
|
||||
if (!series.containsKey(name)) {
|
||||
series.put(name, new XYSeries(name));
|
||||
}
|
||||
long time = point.getValue("timestamp").timeValue().toEpochMilli();
|
||||
double value = point.getDouble(name);
|
||||
if (value > 0) {
|
||||
series.get(name).add(time, value);
|
||||
}
|
||||
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) {
|
||||
for (String name : point.names()) {
|
||||
if (!name.equals("timestamp")) {
|
||||
if (!series.containsKey(name)) {
|
||||
series.put(name, new XYSeries(name));
|
||||
}
|
||||
long time = point.getValue("timestamp").timeValue().toEpochMilli();
|
||||
double value = point.getDouble(name);
|
||||
if (value > 0) {
|
||||
series.get(name).add(time, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
XYSeriesCollection mspSeriesCollection = new XYSeriesCollection();
|
||||
List<String> names = new ArrayList<>(series.keySet());
|
||||
names.sort((String o1, String o2) -> {
|
||||
try {
|
||||
return Integer.valueOf(o1).compareTo(Integer.valueOf(o2));
|
||||
} catch (Exception ex) {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
for (String name : names) {
|
||||
mspSeriesCollection.addSeries(series.get(name));
|
||||
}
|
||||
updateMspPane(mspSeriesCollection);
|
||||
} catch (StorageException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<DataPoint> getMspData(Storage storage) throws StorageException {
|
||||
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);
|
||||
for (DataPoint dp : mspLoader.asDataSet()) {
|
||||
mspData.add(dp);
|
||||
last = dp;
|
||||
}
|
||||
if (last != null) {
|
||||
mspData.add(terminatorPoint(last));
|
||||
}
|
||||
XYSeriesCollection mspSeriesCollection = new XYSeriesCollection();
|
||||
List<String> names = new ArrayList<>(series.keySet());
|
||||
names.sort((String o1, String o2) -> {
|
||||
try {
|
||||
return Integer.valueOf(o1).compareTo(Integer.valueOf(o2));
|
||||
} catch (Exception ex) {
|
||||
LoggerFactory.getLogger(getClass()).error("Can't read msp loader data", ex);
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
for (String name : names) {
|
||||
mspSeriesCollection.addSeries(series.get(name));
|
||||
}
|
||||
updateMspPane(mspSeriesCollection);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
updateMessage("Loading mass spectrometer data from " + mspLoader.getName());
|
||||
updateProgress(-1, 1);
|
||||
for (DataPoint dp : mspLoader.asDataSet()) {
|
||||
mspData.add(dp);
|
||||
last = dp;
|
||||
}
|
||||
if (last != null) {
|
||||
mspData.add(terminatorPoint(last));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LoggerFactory.getLogger(getClass()).error("Can't read msp loader data", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// for (String shelfName : storage.shelves().keySet()) {
|
||||
// mspData.addAll(getMspData(storage.getShelf(shelfName)));
|
||||
// }
|
||||
|
||||
updateProgress("Loading msp data finished");
|
||||
updateProgress(0);
|
||||
return mspData;
|
||||
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,73 +284,66 @@ 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) {
|
||||
if (detectorData == null) {
|
||||
throw new IllegalArgumentException("Detector data not defined");
|
||||
}
|
||||
Platform.runLater(() -> {
|
||||
if (detectorData == null) {
|
||||
throw new IllegalArgumentException("Detector data not defined");
|
||||
}
|
||||
|
||||
detectorPointListView.getItems().clear();//removing all checkboxes
|
||||
detectorPlotPane.getChildren().clear();//removing plot
|
||||
detectorPointListView.getItems().clear();//removing all checkboxes
|
||||
detectorPlotPane.getChildren().clear();//removing plot
|
||||
|
||||
Meta frameMeta = new MetaBuilder("frame")
|
||||
.setValue("frameTitle", "Detector response plot")
|
||||
.setNode(new MetaBuilder("xAxis")
|
||||
.setValue("axisTitle", "ADC")
|
||||
.setValue("axisUnits", "channels")
|
||||
.build())
|
||||
.setNode(new MetaBuilder("yAxis")
|
||||
.setValue("axisTitle", "count rate")
|
||||
.setValue("axisUnits", "Hz")
|
||||
.build())
|
||||
.build();
|
||||
Meta frameMeta = new MetaBuilder("frame")
|
||||
.setValue("frameTitle", "Detector response plot")
|
||||
.setNode(new MetaBuilder("xAxis")
|
||||
.setValue("axisTitle", "ADC")
|
||||
.setValue("axisUnits", "channels")
|
||||
.build())
|
||||
.setNode(new MetaBuilder("yAxis")
|
||||
.setValue("axisTitle", "count rate")
|
||||
.setValue("axisUnits", "Hz")
|
||||
.build())
|
||||
.build();
|
||||
|
||||
detectorPlotFrame = new JFreeChartFrame("detectorSignal", frameMeta, detectorPlotPane);
|
||||
detectorPlotFrame = new JFreeChartFrame("detectorSignal", frameMeta, detectorPlotPane);
|
||||
|
||||
for (XYPlottable pl : detectorData) {
|
||||
detectorPlotFrame.add(pl);
|
||||
detectorPointListView.getItems().add(pl.getName());
|
||||
}
|
||||
for (XYPlottable pl : detectorData) {
|
||||
detectorPlotFrame.add(pl);
|
||||
detectorPointListView.getItems().add(pl.getName());
|
||||
}
|
||||
|
||||
for (String plotName : detectorPointListView.getItems()) {
|
||||
BooleanProperty checked = detectorPointListView.getItemBooleanProperty(plotName);
|
||||
checked.set(true);
|
||||
for (String plotName : detectorPointListView.getItems()) {
|
||||
BooleanProperty checked = detectorPointListView.getItemBooleanProperty(plotName);
|
||||
checked.set(true);
|
||||
|
||||
checked.addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
|
||||
detectorPlotFrame.get(plotName).getConfig().setValue("visible", newValue);
|
||||
});
|
||||
}
|
||||
checked.addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
|
||||
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");
|
||||
|
@ -13,54 +13,55 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package inr.numass.viewer;
|
||||
|
||||
import hep.dataforge.storage.commons.StoragePlugin;
|
||||
import inr.numass.storage.NumassDataLoader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author darksnake
|
||||
*/
|
||||
public class TestDirectoryViewer extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws IOException {
|
||||
new StoragePlugin().startGlobal();
|
||||
|
||||
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);
|
||||
// FXMLLoader fxml = new FXMLLoader(getClass().getResource("/fxml/DirectoryViewer.fxml"));
|
||||
//
|
||||
// Parent parent = fxml.load();
|
||||
//
|
||||
// NumassLoaderViewController controller = fxml.getController();
|
||||
//
|
||||
// controller.setModel(reader);
|
||||
|
||||
Scene scene = new Scene(comp, 800, 600);
|
||||
|
||||
primaryStage.setTitle("Detector Visualisation test");
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.setMinHeight(600);
|
||||
primaryStage.setMinWidth(800);
|
||||
// primaryStage.setResizable(false);
|
||||
|
||||
primaryStage.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
}
|
||||
package inr.numass.viewer;
|
||||
|
||||
import hep.dataforge.storage.commons.StoragePlugin;
|
||||
import inr.numass.storage.NumassDataLoader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author darksnake
|
||||
*/
|
||||
public class TestDirectoryViewer extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws IOException {
|
||||
new StoragePlugin().startGlobal();
|
||||
|
||||
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 = new NumassLoaderViewComponent();
|
||||
comp.loadData(reader);
|
||||
// FXMLLoader fxml = new FXMLLoader(getClass().getResource("/fxml/DirectoryViewer.fxml"));
|
||||
//
|
||||
// Parent parent = fxml.load();
|
||||
//
|
||||
// NumassLoaderViewController controller = fxml.getController();
|
||||
//
|
||||
// controller.setModel(reader);
|
||||
|
||||
Scene scene = new Scene(comp, 800, 600);
|
||||
|
||||
primaryStage.setTitle("Detector Visualisation test");
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.setMinHeight(600);
|
||||
primaryStage.setMinWidth(800);
|
||||
// primaryStage.setResizable(false);
|
||||
|
||||
primaryStage.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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,8 +52,12 @@ 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>
|
||||
<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" />
|
||||
<TextField fx:id="upChannelField" prefWidth="60.0" />
|
||||
<VBox>
|
||||
<children>
|
||||
<Label text="Lo channel" />
|
||||
<TextField fx:id="lowChannelField" prefWidth="60.0" />
|
||||
</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