From 73908683b8bd03636e16c117333223ed30d3cd46 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 24 Apr 2016 22:17:52 +0300 Subject: [PATCH] [no commit message] --- .../inr/numass/control/msp/MspDevice.java | 4 +- .../plotfit/PlotFitResultAction.java | 3 +- .../numass/actions/AdjustErrorsAction.java | 3 +- .../inr/numass/actions/MergeDataAction.java | 7 +- .../numass/actions/MonitorCorrectAction.java | 1 + .../inr/numass/actions/PrepareDataAction.java | 10 +- .../actions/ShowLossSpectrumAction.java | 2 +- .../java/inr/numass/actions/SlicedData.java | 6 +- .../inr/numass/actions/SummaryAction.java | 4 +- .../main/java/inr/numass/data/ESpectrum.java | 15 ++- .../inr/numass/data/SpectrumGenerator.java | 7 ++ .../src/main/java/inr/numass/models/FSS.java | 3 +- .../models/TransmissionInterpolator.java | 3 +- .../java/inr/numass/utils/OldDataReader.java | 112 ++++++++++++++++++ .../java/inr/numass/utils/TritiumUtils.java | 13 +- numass-storage/numass-server/build.gradle | 11 ++ .../java/inr/numass/server/HandlerUtils.java | 4 +- .../inr/numass/server/NumassRootHandler.java | 84 +++++++------ .../java/inr/numass/server/NumassServer.java | 74 ++---------- .../numass/server/NumassStorageHandler.java | 21 +++- .../main/resources/templates/NumassRoot.ftl | 51 ++++++++ .../inr/numass/viewer/MspViewController.java | 2 +- numass.gradle | 1 + 23 files changed, 306 insertions(+), 135 deletions(-) create mode 100644 numass-storage/numass-server/src/main/resources/templates/NumassRoot.ftl diff --git a/numass-control/msp/src/main/java/inr/numass/control/msp/MspDevice.java b/numass-control/msp/src/main/java/inr/numass/control/msp/MspDevice.java index 11b85ec3..d3cf82a4 100644 --- a/numass-control/msp/src/main/java/inr/numass/control/msp/MspDevice.java +++ b/numass-control/msp/src/main/java/inr/numass/control/msp/MspDevice.java @@ -30,7 +30,7 @@ import hep.dataforge.exceptions.MeasurementException; import hep.dataforge.exceptions.PortException; import hep.dataforge.exceptions.StorageException; import hep.dataforge.meta.Meta; -import hep.dataforge.points.Format; +import hep.dataforge.points.PointFormat; import hep.dataforge.points.FormatBuilder; import hep.dataforge.storage.api.PointLoader; import hep.dataforge.storage.api.Storage; @@ -411,7 +411,7 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po builder.addNumber(peakName); }); - Format format = builder.build(); + PointFormat format = builder.build(); String suffix = Integer.toString((int) Instant.now().toEpochMilli()); PointLoader loader = LoaderFactory diff --git a/numass-main/src/main/java/hep/dataforge/plotfit/PlotFitResultAction.java b/numass-main/src/main/java/hep/dataforge/plotfit/PlotFitResultAction.java index 043ab74d..8cd06155 100644 --- a/numass-main/src/main/java/hep/dataforge/plotfit/PlotFitResultAction.java +++ b/numass-main/src/main/java/hep/dataforge/plotfit/PlotFitResultAction.java @@ -33,6 +33,7 @@ import hep.dataforge.plots.data.PlottableData; import hep.dataforge.plots.data.PlottableFunction; import org.apache.commons.math3.analysis.UnivariateFunction; import hep.dataforge.points.PointSet; +import hep.dataforge.points.PointSource; /** * @@ -46,7 +47,7 @@ public class PlotFitResultAction extends OneToOneAction { @Override protected FitState execute(Context context,Logable log, String name, Laminate metaData, FitState input) { - PointSet data = input.getDataSet(); + PointSource data = input.getDataSet(); if (!(input.getModel() instanceof XYModel)) { log.logError("The fit model should be instance of XYModel for this action. Action failed!"); return input; diff --git a/numass-main/src/main/java/inr/numass/actions/AdjustErrorsAction.java b/numass-main/src/main/java/inr/numass/actions/AdjustErrorsAction.java index 5cd4b408..2f1ba297 100644 --- a/numass-main/src/main/java/inr/numass/actions/AdjustErrorsAction.java +++ b/numass-main/src/main/java/inr/numass/actions/AdjustErrorsAction.java @@ -17,6 +17,7 @@ import hep.dataforge.meta.Meta; import java.util.ArrayList; import java.util.List; import hep.dataforge.points.PointSet; +import hep.dataforge.points.PointSource; /** * Adjust errors for all numass points in the dataset @@ -33,7 +34,7 @@ public class AdjustErrorsAction extends OneToOneAction { points.add(evalPoint(meta, dp)); } - return new ListPointSet(points, input.getDataFormat()); + return new ListPointSet(input.getFormat(), points); } private DataPoint evalPoint(Meta meta, DataPoint dp) { diff --git a/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java b/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java index a6760c98..4896b90c 100644 --- a/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java +++ b/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java @@ -29,6 +29,7 @@ import hep.dataforge.points.DataPoint; import hep.dataforge.points.ListPointSet; import hep.dataforge.points.MapPoint; import hep.dataforge.points.PointSet; +import hep.dataforge.points.PointSource; import java.io.OutputStream; import java.util.ArrayList; import java.util.Collection; @@ -63,7 +64,7 @@ public class MergeDataAction extends ManyToOneAction { @Override protected PointSet execute(Context context, Logable log, String nodeName, Map data, Meta meta) { PointSet res = mergeDataSets(nodeName, data.values()); - return res.sort("Uset", true); + return new ListPointSet(res.getFormat(),res.sort("Uset", true)); } @Override @@ -143,8 +144,8 @@ public class MergeDataAction extends ManyToOneAction { private PointSet mergeDataSets(String name, Collection ds) { //Сливаем все точки в один набор данных Map> points = new LinkedHashMap<>(); - for (PointSet d : ds) { - if (!d.getDataFormat().contains(parnames)) { + for (PointSource d : ds) { + if (!d.getFormat().contains(parnames)) { throw new IllegalArgumentException(); } for (DataPoint dp : d) { diff --git a/numass-main/src/main/java/inr/numass/actions/MonitorCorrectAction.java b/numass-main/src/main/java/inr/numass/actions/MonitorCorrectAction.java index 4058ff2c..56b71412 100644 --- a/numass-main/src/main/java/inr/numass/actions/MonitorCorrectAction.java +++ b/numass-main/src/main/java/inr/numass/actions/MonitorCorrectAction.java @@ -37,6 +37,7 @@ import java.util.Map.Entry; import java.util.TreeMap; import java.util.concurrent.CopyOnWriteArrayList; import hep.dataforge.points.PointSet; +import hep.dataforge.points.PointSource; /** * diff --git a/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java b/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java index 1f532c23..2dbf416c 100644 --- a/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java +++ b/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java @@ -17,7 +17,7 @@ package inr.numass.actions; import hep.dataforge.actions.OneToOneAction; import hep.dataforge.context.Context; -import hep.dataforge.points.Format; +import hep.dataforge.points.PointFormat; import hep.dataforge.points.DataPoint; import hep.dataforge.points.ListPointSet; import hep.dataforge.points.MapPoint; @@ -90,13 +90,13 @@ public class PrepareDataAction extends OneToOneAction { dataList.add(new MapPoint(parnames, new Object[]{Uset, Uread, time, total, wind, corr, cr, crErr, timestamp})); } - Format format; + PointFormat format; if (!dataList.isEmpty()) { //Генерируем автоматический формат по первой строчке - format = Format.forPoint(dataList.get(0)); + format = PointFormat.forPoint(dataList.get(0)); } else { - format = Format.forNames(8, parnames); + format = PointFormat.forNames(8, parnames); } // AnnotationBuilder builder = dataFile.meta().getBuilder(); @@ -109,7 +109,7 @@ public class PrepareDataAction extends OneToOneAction { } head = head + "\n" + new XMLMetaWriter().writeString(meta, null) + "\n"; - ListPointSet data = new ListPointSet(dataList, format); + ListPointSet data = new ListPointSet(format, dataList); OutputStream stream = buildActionOutput(context, name); diff --git a/numass-main/src/main/java/inr/numass/actions/ShowLossSpectrumAction.java b/numass-main/src/main/java/inr/numass/actions/ShowLossSpectrumAction.java index ab1d4d30..04fc82c9 100644 --- a/numass-main/src/main/java/inr/numass/actions/ShowLossSpectrumAction.java +++ b/numass-main/src/main/java/inr/numass/actions/ShowLossSpectrumAction.java @@ -172,7 +172,7 @@ public class ShowLossSpectrumAction extends OneToOneAction { ParamSet parameters = input.getParameters().getSubSet(new String[]{"exPos", "ionPos", "exW", "ionW", "exIonRatio"}); NamedMatrix covariance = input.getCovariance(); PointSet spreadData = generateSpread(writer, name, parameters, covariance); - ColumnedDataWriter.writeDataSet(System.out, spreadData, "", spreadData.getDataFormat().asArray()); + ColumnedDataWriter.writeDataSet(System.out, spreadData, "", spreadData.getFormat().asArray()); } } diff --git a/numass-main/src/main/java/inr/numass/actions/SlicedData.java b/numass-main/src/main/java/inr/numass/actions/SlicedData.java index 01d01f2b..b5750c12 100644 --- a/numass-main/src/main/java/inr/numass/actions/SlicedData.java +++ b/numass-main/src/main/java/inr/numass/actions/SlicedData.java @@ -15,7 +15,7 @@ */ package inr.numass.actions; -import hep.dataforge.points.Format; +import hep.dataforge.points.PointFormat; import hep.dataforge.points.ListPointSet; import hep.dataforge.points.MapPoint; import hep.dataforge.values.Value; @@ -36,11 +36,11 @@ public class SlicedData extends ListPointSet { private static final String UNAME = "U"; - private static Format prepateFormat(Map> intervals){ + private static PointFormat prepateFormat(Map> intervals){ ArrayList names = new ArrayList<>(intervals.keySet()); names.add(0, TNAME); names.add(0, UNAME); - return Format.forNames(8, names); + return PointFormat.forNames(8, names); } diff --git a/numass-main/src/main/java/inr/numass/actions/SummaryAction.java b/numass-main/src/main/java/inr/numass/actions/SummaryAction.java index bfca810b..d5c6cf5e 100644 --- a/numass-main/src/main/java/inr/numass/actions/SummaryAction.java +++ b/numass-main/src/main/java/inr/numass/actions/SummaryAction.java @@ -19,7 +19,7 @@ import hep.dataforge.actions.ManyToOneAction; import hep.dataforge.actions.GroupBuilder; import hep.dataforge.context.Context; import hep.dataforge.data.DataNode; -import hep.dataforge.points.Format; +import hep.dataforge.points.PointFormat; import hep.dataforge.points.DataPoint; import hep.dataforge.points.ListPointSet; import hep.dataforge.points.MapPoint; @@ -68,7 +68,7 @@ public class SummaryAction extends ManyToOneAction { } names[names.length - 1] = "chi2"; - ListPointSet res = new ListPointSet(Format.forNames(8, names)); + ListPointSet res = new ListPointSet(PointFormat.forNames(8, names)); double[] weights = new double[parNames.length]; Arrays.fill(weights, 0); diff --git a/numass-main/src/main/java/inr/numass/data/ESpectrum.java b/numass-main/src/main/java/inr/numass/data/ESpectrum.java index 0aa2ee64..27841366 100644 --- a/numass-main/src/main/java/inr/numass/data/ESpectrum.java +++ b/numass-main/src/main/java/inr/numass/data/ESpectrum.java @@ -15,7 +15,7 @@ */ package inr.numass.data; -import hep.dataforge.points.Format; +import hep.dataforge.points.PointFormat; import hep.dataforge.points.ListPointSet; import hep.dataforge.points.MapPoint; import hep.dataforge.io.ColumnedDataWriter; @@ -30,6 +30,13 @@ 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; +import static java.lang.String.format; +import static java.lang.String.format; +import static java.lang.String.format; +import static java.lang.String.format; +import static java.lang.String.format; /** * @@ -39,7 +46,7 @@ public class ESpectrum extends ListPointSet { private final static String binCenter = "chanel"; - private static Format prepareFormat(List points) { + private static PointFormat prepareFormat(List points) { // ArrayList names = new ArrayList<>(); // names.add(binCenter); Map format = new LinkedHashMap<>(); @@ -49,7 +56,7 @@ public class ESpectrum extends ListPointSet { format.put(format("%.3f", point.getUread()), ValueFormatFactory.fixedWidth(10)); } - return new Format(format); + return new PointFormat(format); } int binning = 1; @@ -82,7 +89,7 @@ public class ESpectrum extends ListPointSet { public void printToFile(OutputStream stream) { ColumnedDataWriter.writeDataSet(stream, this, null); -// new ColumnedDataWriter(stream, this.getDataFormat().asArray()).writeDataSet(this, null); +// new ColumnedDataWriter(stream, this.getFormat().asArray()).writeDataSet(this, null); } } diff --git a/numass-main/src/main/java/inr/numass/data/SpectrumGenerator.java b/numass-main/src/main/java/inr/numass/data/SpectrumGenerator.java index 061a4649..c88a105e 100644 --- a/numass-main/src/main/java/inr/numass/data/SpectrumGenerator.java +++ b/numass-main/src/main/java/inr/numass/data/SpectrumGenerator.java @@ -27,6 +27,13 @@ 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; +import static java.lang.Double.isNaN; +import static java.lang.Double.isNaN; +import static java.lang.Double.isNaN; +import static java.lang.Double.isNaN; +import static java.lang.Double.isNaN; +import static java.lang.Double.isNaN; /** * Генератор наборов данных для спектров. На входе требуется набор данных, diff --git a/numass-main/src/main/java/inr/numass/models/FSS.java b/numass-main/src/main/java/inr/numass/models/FSS.java index 8c97e5b7..8e7bfefc 100644 --- a/numass-main/src/main/java/inr/numass/models/FSS.java +++ b/numass-main/src/main/java/inr/numass/models/FSS.java @@ -22,6 +22,7 @@ import java.io.FileNotFoundException; import java.util.ArrayList; import org.apache.commons.math3.util.Pair; import hep.dataforge.points.PointSet; +import hep.dataforge.points.PointSource; /** * @@ -34,7 +35,7 @@ public class FSS{ public FSS(File FSSFile) { try { - PointSet data = IOUtils.readColumnedData(FSSFile,"E","P"); + PointSource data = IOUtils.readColumnedData(FSSFile,"E","P"); this.points = new ArrayList<>(); norm = 0; for (DataPoint dp : data) { diff --git a/numass-main/src/main/java/inr/numass/models/TransmissionInterpolator.java b/numass-main/src/main/java/inr/numass/models/TransmissionInterpolator.java index 6dfe84d7..29e578c1 100644 --- a/numass-main/src/main/java/inr/numass/models/TransmissionInterpolator.java +++ b/numass-main/src/main/java/inr/numass/models/TransmissionInterpolator.java @@ -22,6 +22,7 @@ import hep.dataforge.io.ColumnedDataReader; import hep.dataforge.meta.Meta; import hep.dataforge.points.DataPoint; import hep.dataforge.points.PointSet; +import hep.dataforge.points.PointSource; import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; @@ -49,7 +50,7 @@ public class TransmissionInterpolator implements UnivariateFunction { public static TransmissionInterpolator fromAction(Context context, Meta actionAnnotation, String xName, String yName, int nSmooth, double w, double border) throws InterruptedException { DataNode node = ActionUtils.runConfig(context, actionAnnotation); - PointSet data = node.getData().get(); + PointSource data = node.getData().get(); return new TransmissionInterpolator(data, xName, yName, nSmooth, w, border); } diff --git a/numass-main/src/main/java/inr/numass/utils/OldDataReader.java b/numass-main/src/main/java/inr/numass/utils/OldDataReader.java index 52214b6a..bfd8cb7f 100644 --- a/numass-main/src/main/java/inr/numass/utils/OldDataReader.java +++ b/numass-main/src/main/java/inr/numass/utils/OldDataReader.java @@ -40,6 +40,118 @@ import static java.util.Locale.setDefault; import static java.util.Locale.setDefault; import static java.util.Locale.setDefault; import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; /** * diff --git a/numass-main/src/main/java/inr/numass/utils/TritiumUtils.java b/numass-main/src/main/java/inr/numass/utils/TritiumUtils.java index 2aab6ec6..c424f5da 100644 --- a/numass-main/src/main/java/inr/numass/utils/TritiumUtils.java +++ b/numass-main/src/main/java/inr/numass/utils/TritiumUtils.java @@ -22,6 +22,13 @@ import static java.lang.Math.exp; 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; +import static java.lang.Math.abs; +import static java.lang.Math.abs; +import static java.lang.Math.abs; +import static java.lang.Math.abs; /** * @@ -41,7 +48,7 @@ public class TritiumUtils { // public static ListPointSet applyDrift(ListPointSet data, double driftPerSecond) { // double t = 0; // -// ListPointSet res = new ListPointSet(data.getDataFormat()); +// ListPointSet res = new ListPointSet(data.getFormat()); // for (DataPoint d : data) { // SpectrumDataPoint dp = (SpectrumDataPoint) d; // double corrFactor = 1 + driftPerSecond * t; @@ -62,7 +69,7 @@ public class TritiumUtils { */ public static ListPointSet correctForDeadTime(ListPointSet data, double dtime) { SpectrumDataAdapter reader = adapter(); - ListPointSet res = new ListPointSet(data.getDataFormat()); + ListPointSet res = new ListPointSet(data.getFormat()); for (DataPoint dp : data) { double corrFactor = 1 / (1 - dtime * reader.getCount(dp) /reader.getTime(dp)); res.add(reader.buildSpectrumDataPoint(reader.getX(dp).doubleValue(), (long) (reader.getCount(dp)*corrFactor),reader.getTime(dp))); @@ -80,7 +87,7 @@ public class TritiumUtils { */ public static ListPointSet setHVScale(ListPointSet data, double beta) { SpectrumDataAdapter reader = adapter(); - ListPointSet res = new ListPointSet(data.getDataFormat()); + ListPointSet res = new ListPointSet(data.getFormat()); for (DataPoint dp : data) { double corrFactor = 1 + beta; res.add(reader.buildSpectrumDataPoint(reader.getX(dp).doubleValue()*corrFactor, reader.getCount(dp), reader.getTime(dp))); diff --git a/numass-storage/numass-server/build.gradle b/numass-storage/numass-server/build.gradle index a6e5f75c..acb50728 100644 --- a/numass-storage/numass-server/build.gradle +++ b/numass-storage/numass-server/build.gradle @@ -11,6 +11,17 @@ task runServer(type: JavaExec) { standardInput = System.in } +//sourceSets.main.resources{ +// srcDir project(':dataforge-storage:storage-servlet').file('ratpack') +//} + +//task copyAssets(type: Copy) { +// from project(':dataforge-storage:storage-servlet').file('src/main/resouces/ratpack') +// into 'src/main/resouces/ratpack' +//} + +//processResources.dependsOn("copyAssets") + dependencies { compile project(':numass-storage') compile project(':dataforge-storage:storage-servlet') diff --git a/numass-storage/numass-server/src/main/java/inr/numass/server/HandlerUtils.java b/numass-storage/numass-server/src/main/java/inr/numass/server/HandlerUtils.java index eb2518ce..1487d979 100644 --- a/numass-storage/numass-server/src/main/java/inr/numass/server/HandlerUtils.java +++ b/numass-storage/numass-server/src/main/java/inr/numass/server/HandlerUtils.java @@ -14,7 +14,8 @@ import hep.dataforge.values.Value; */ public class HandlerUtils { - public static void renderStates(StringBuilder b, StateLoader states) { + public static String renderStates(StateLoader states) { + StringBuilder b = new StringBuilder(); b.append("
\n"); for (String state : states.getStateNames()) { Value val = states.getValue(state); @@ -37,6 +38,7 @@ public class HandlerUtils { state, color, val.stringValue())); } b.append("
\n"); + return b.toString(); } public static void renderHTMLHeader(StringBuilder b) { diff --git a/numass-storage/numass-server/src/main/java/inr/numass/server/NumassRootHandler.java b/numass-storage/numass-server/src/main/java/inr/numass/server/NumassRootHandler.java index 47dda0f4..516393d6 100644 --- a/numass-storage/numass-server/src/main/java/inr/numass/server/NumassRootHandler.java +++ b/numass-storage/numass-server/src/main/java/inr/numass/server/NumassRootHandler.java @@ -5,13 +5,18 @@ */ package inr.numass.server; +import freemarker.template.Template; import hep.dataforge.exceptions.StorageException; import hep.dataforge.storage.api.Loader; import hep.dataforge.storage.api.StateLoader; import hep.dataforge.storage.api.Storage; import hep.dataforge.storage.commons.JSONMetaWriter; -import static inr.numass.server.HandlerUtils.*; -import inr.numass.storage.NumassStorage; +import hep.dataforge.storage.servlet.Utils; +import static inr.numass.server.HandlerUtils.renderStates; +import java.io.StringWriter; +import java.util.HashMap; +import java.util.Map; +import org.slf4j.LoggerFactory; import ratpack.handling.Context; import ratpack.handling.Handler; @@ -19,6 +24,7 @@ import ratpack.handling.Handler; * * @author Alexander Nozik */ +@SuppressWarnings("unchecked") public class NumassRootHandler implements Handler { private final JSONMetaWriter writer = new JSONMetaWriter(); @@ -30,43 +36,51 @@ public class NumassRootHandler implements Handler { } @Override - public void handle(Context c) throws Exception { - c.getResponse().contentType("text/html"); - StringBuilder b = new StringBuilder(); - renderHTMLHeader(b); - b.append("

Server configuration

\n"); - if (!server.meta().isEmpty()) { - b.append("

Server metadata:

\n"); - b.append(writer.writeString(server.meta())); - b.append("\n"); - } - if (server.getRootState() != null) { - b.append("

Current root state:

\n"); - renderStates(b, server.getRootState()); - } - if (server.getRun() != null) { - b.append("

Current run configuration

\n"); - if (!server.getRun().meta().isEmpty()) { - b.append("

Run metadata:

\n"); - b.append(writer.writeString(server.getRun().meta())); - b.append("\n"); - } - StateLoader runStates = server.getRun().getStates(); - if (!runStates.isEmpty()) { - b.append("

Current run state:

\n"); - renderStates(b, runStates); + public void handle(Context ctx) throws Exception { + try { + ctx.getResponse().contentType("text/html"); + Template template = Utils.freemarkerConfig().getTemplate("NumassRoot.ftl"); + + Map data = new HashMap(6); + if (!server.meta().isEmpty()) { + data.put("serverMeta", writer.writeString(server.meta())); } - b.append("

Current run storage content:

\n"); - NumassStorage storage = server.getRun().getStorage(); - try { - renderStorage(c, b, storage); - } catch (StorageException ex) { - b.append("\nError reading sotrage structure!!!\n"); + if (server.getRootState() != null) { + data.put("serverRootState", renderStates(server.getRootState())); } + + if (server.getRun() != null) { + data.put("runPresent", true); + if (!server.getRun().meta().isEmpty()) { + data.put("runMeta", writer.writeString(server.getRun().meta())); + } + + StateLoader runState = server.getRun().getStates(); + if (!runState.isEmpty()) { + data.put("runState", renderStates(runState)); + } + + try { + StringBuilder b = new StringBuilder(); + renderStorage(ctx, b, server.getRun().getStorage()); + data.put("storageContent", b.toString()); + } catch (StorageException ex) { + data.put("storageContent", ex.toString()); + } + } else { + data.put("runPresent", false); + } + + StringWriter stringWriter = new StringWriter(); + template.process(data, stringWriter); + + ctx.render(stringWriter.toString()); + + } catch (Exception ex) { + LoggerFactory.getLogger(getClass()).error("Error rendering storage tree"); + ctx.render(ex.toString()); } - renderHTMLFooter(b); - c.render(b); } private void renderStorage(Context ctx, StringBuilder b, Storage storage) throws StorageException { diff --git a/numass-storage/numass-server/src/main/java/inr/numass/server/NumassServer.java b/numass-storage/numass-server/src/main/java/inr/numass/server/NumassServer.java index 4e4c63d8..34c3a72c 100644 --- a/numass-storage/numass-server/src/main/java/inr/numass/server/NumassServer.java +++ b/numass-storage/numass-server/src/main/java/inr/numass/server/NumassServer.java @@ -24,13 +24,16 @@ import hep.dataforge.storage.commons.AbstractNetworkListener; import hep.dataforge.storage.commons.LoaderFactory; import hep.dataforge.storage.commons.StorageManager; import hep.dataforge.storage.filestorage.FileStorage; -import hep.dataforge.storage.servlet.StorageRatpackHandler; import inr.numass.storage.NumassStorage; import java.io.File; import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import ratpack.file.FileHandlerSpec; import ratpack.handling.Chain; +import ratpack.server.BaseDir; import ratpack.server.RatpackServer; import ratpack.server.RatpackServerSpec; import ratpack.server.ServerConfigBuilder; @@ -81,8 +84,12 @@ public class NumassServer extends AbstractNetworkListener { super.open(); int port = meta().getInt("ratpack.port", 8336); ratpack = RatpackServer.start((RatpackServerSpec server) -> server - .serverConfig((ServerConfigBuilder config) -> config.port(port)) + .serverConfig((ServerConfigBuilder config) -> config +// .baseDir(Paths.get(getClass().getClassLoader().getResource("ratpack").toURI())) +// .baseDir(BaseDir.find()) + .port(port)) .handlers((Chain chain) -> chain +// .files() .get(new NumassRootHandler(this)) .get("storage", new NumassStorageHandler(root)) ) @@ -232,67 +239,4 @@ public class NumassServer extends AbstractNetworkListener { public NumassRun getRun() { return run; } - -// private class NumassRootHandler implements Handler { -// -// @Override -// public void handle(Context c) throws Exception { -// c.getResponse().contentType("text/html"); -// StringBuilder b = new StringBuilder(); -// renderHTMLHeader(b); -// b.append("

Server configuration

\n"); -// if (!meta().isEmpty()) { -// b.append("

Server metadata:

\n"); -// b.append(writer.writeString(meta())); -// b.append("\n"); -// } -// if (getRootState() != null) { -// b.append("

Current root state:

\n"); -// renderStates(b, getRootState()); -// } -// if (getRun() != null) { -// b.append("

Current run configuration

\n"); -// if (!run.meta().isEmpty()) { -// b.append("

Run metadata:

\n"); -// b.append(writer.writeString(getRun().meta())); -// b.append("\n"); -// } -// StateLoader runStates = getRun().getStates(); -// if (!runStates.isEmpty()) { -// b.append("

Current run state:

\n"); -// renderStates(b, runStates); -// } -// -// b.append("

Current run storage content:

\n"); -// NumassStorage storage = getRun().getStorage(); -// try { -// renderStorage(c, b, storage); -// } catch (StorageException ex) { -// b.append("\nError reading sotrage structure!!!\n"); -// } -// } -// renderHTMLFooter(b); -// c.render(b); -// } -// -// private void renderStorage(Context ctx, StringBuilder b, Storage storage) throws StorageException { -// b.append("
\n"); -// for (Storage shelf : storage.shelves().values()) { -// b.append(String.format("

+ %s

%n", shelf.getName())); -// renderStorage(ctx, b, shelf); -// } -// b.append("
\n"); -// for (Loader loader : storage.loaders().values()) { -// defaultRenderLoader(ctx, b, loader); -// } -// b.append("
\n"); -// b.append("
\n"); -// } -// -// private void defaultRenderLoader(Context ctx, StringBuilder b, Loader loader) { -// String href = "/storage?path="+loader.getFullPath(); -// b.append(String.format("

%s (%s)

", href, loader.getName(), loader.getType())); -// } -// -// } } diff --git a/numass-storage/numass-server/src/main/java/inr/numass/server/NumassStorageHandler.java b/numass-storage/numass-server/src/main/java/inr/numass/server/NumassStorageHandler.java index ffd48691..3911e67b 100644 --- a/numass-storage/numass-server/src/main/java/inr/numass/server/NumassStorageHandler.java +++ b/numass-storage/numass-server/src/main/java/inr/numass/server/NumassStorageHandler.java @@ -12,9 +12,13 @@ import hep.dataforge.storage.api.Storage; import hep.dataforge.storage.servlet.StorageRatpackHandler; import hep.dataforge.storage.servlet.Utils; import java.io.StringWriter; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; import java.util.Comparator; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; @@ -28,6 +32,11 @@ import ratpack.handling.Context; */ public class NumassStorageHandler extends StorageRatpackHandler { + private static DateTimeFormatter formatter + = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT) + .withLocale(Locale.US) + .withZone(ZoneId.systemDefault()); + public NumassStorageHandler(Storage root) { super(root); } @@ -40,7 +49,7 @@ public class NumassStorageHandler extends StorageRatpackHandler { ctx.getResponse().contentType("text/html"); Template template = Utils.freemarkerConfig().getTemplate("NoteLoader.ftl"); - List notes = getNotes(loader).limit(100).map(note->render(note)).collect(Collectors.toList()); + List notes = getNotes(loader).limit(100).map(note -> render(note)).collect(Collectors.toList()); Map data = new HashMap(2); data.put("notes", notes); @@ -57,11 +66,11 @@ public class NumassStorageHandler extends StorageRatpackHandler { super.renderObjects(ctx, loader); } } - - private String render(NumassNote note){ - return String.format("%s: %s %s", note.ref(), note.time(), note.content()); + + private String render(NumassNote note) { + return String.format("%s %s", note.ref(), formatter.format(note.time()), note.content()); } - + /** * Stream of notes in the last to first order * @@ -84,6 +93,6 @@ public class NumassStorageHandler extends StorageRatpackHandler { return -o1.time().compareTo(o2.time()); } }); - } + } } diff --git a/numass-storage/numass-server/src/main/resources/templates/NumassRoot.ftl b/numass-storage/numass-server/src/main/resources/templates/NumassRoot.ftl new file mode 100644 index 00000000..6f0082f5 --- /dev/null +++ b/numass-storage/numass-server/src/main/resources/templates/NumassRoot.ftl @@ -0,0 +1,51 @@ + + + + + + + + + + + Numass storage + + + +

Server configuration

+ <#if serverMeta??> +

Server metadata:

+ ${serverMeta} + +
+ <#if serverRootState??> +

Current root state:

+ ${serverRootState} + +
+ <#if runPresent> +

Current run configuration

+ <#if runMeta??> +

Run metadata:

+ ${runMeta} + + <#if runState?? > +

Current run state:

+ ${runState} + + +

Current run storage content:

+ ${storageContent} + + + + + + + + + \ No newline at end of file diff --git a/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java b/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java index 72e98ba0..4d781287 100644 --- a/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java +++ b/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java @@ -101,7 +101,7 @@ public class MspViewController { try (final PointLoader mspLoader = (PointLoader) rootStorage.getLoader(loaderName)) { mspLoader.open(); callback.updateMessage("Loading mass spectrometer data from " + mspLoader.getName()); - for (DataPoint dp : mspLoader.asDataSet()) { + for (DataPoint dp : mspLoader) { mspData.add(dp); last = dp; } diff --git a/numass.gradle b/numass.gradle index 4408a58c..9619044a 100644 --- a/numass.gradle +++ b/numass.gradle @@ -13,6 +13,7 @@ configurations { } repositories { + jcenter() mavenCentral() maven { url "http://www.inr.ru/~nozik/maven2/" } // mavenLocal()