From cca98f4fab4b44c50b2c846e81a4ed9c58dc23fb Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 21 Mar 2016 15:29:31 +0300 Subject: [PATCH] Finished refactoring --- .../java/inr/numass/cryotemp/PKT8Device.java | 2 +- .../inr/numass/readvac/fx/VacuumeterView.java | 2 +- .../plotfit/PlotFitResultAction.java | 6 +- .../src/main/java/inr/numass/Main.java | 32 ++--- .../src/main/java/inr/numass/NumassIO.java | 17 ++- .../numass/actions/AdjustErrorsAction.java | 4 +- .../inr/numass/actions/DebunchAction.java | 17 ++- .../inr/numass/actions/FindBorderAction.java | 5 +- .../inr/numass/actions/MergeDataAction.java | 109 ++++++++---------- .../numass/actions/MonitorCorrectAction.java | 12 +- .../inr/numass/actions/PrepareDataAction.java | 6 +- .../numass/actions/ReadNumassDataAction.java | 16 +-- .../actions/ShowLossSpectrumAction.java | 26 ++--- .../numass/actions/ShowSpectrumAction.java | 12 +- .../inr/numass/actions/SlicingAction.java | 6 +- .../inr/numass/actions/SummaryAction.java | 84 ++++++++------ .../main/java/inr/numass/data/ESpectrum.java | 11 +- .../src/main/java/inr/numass/data/NMFile.java | 2 +- .../main/java/inr/numass/data/NumassData.java | 2 +- .../inr/numass/data/NumassDataReader.java | 8 +- .../main/java/inr/numass/data/RawNMFile.java | 5 +- .../inr/numass/data/SpectrumInformation.java | 19 +-- .../models/TransmissionInterpolator.java | 5 +- .../java/inr/numass/utils/TritiumUtils.java | 15 +-- .../workbench/NumassWorkbenchController.java | 8 +- .../java/inr/numass/workbench/OutputTab.java | 2 +- .../java/inr/numass/workbench/StagePane.java | 2 +- .../java/inr/numass/prop/ar/JNAEpisode.java | 2 +- .../java/inr/numass/prop/ar/JNASpectrum.java | 2 +- 29 files changed, 213 insertions(+), 226 deletions(-) diff --git a/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8Device.java b/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8Device.java index b5a22a5a..394fb08e 100644 --- a/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8Device.java +++ b/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8Device.java @@ -15,7 +15,7 @@ */ package inr.numass.cryotemp; -import hep.dataforge.content.Named; +import hep.dataforge.names.Named; import hep.dataforge.context.Context; import hep.dataforge.control.collectors.RegularPointCollector; import hep.dataforge.control.measurements.DataDevice; diff --git a/numass-control/vac/src/main/java/inr/numass/readvac/fx/VacuumeterView.java b/numass-control/vac/src/main/java/inr/numass/readvac/fx/VacuumeterView.java index f73fd5ab..a3c85aab 100644 --- a/numass-control/vac/src/main/java/inr/numass/readvac/fx/VacuumeterView.java +++ b/numass-control/vac/src/main/java/inr/numass/readvac/fx/VacuumeterView.java @@ -5,7 +5,7 @@ */ package inr.numass.readvac.fx; -import hep.dataforge.content.Named; +import hep.dataforge.names.Named; import hep.dataforge.control.connections.DeviceViewController; import hep.dataforge.control.devices.Device; import hep.dataforge.control.measurements.Measurement; 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 2d69b32b..8ed2c7f9 100644 --- a/numass-main/src/main/java/hep/dataforge/plotfit/PlotFitResultAction.java +++ b/numass-main/src/main/java/hep/dataforge/plotfit/PlotFitResultAction.java @@ -47,7 +47,7 @@ public class PlotFitResultAction extends OneToOneAction { } @Override - protected FitState execute(Logable log, Meta metaData, FitState input) { + protected FitState execute(Logable log, String name, Meta metaData, FitState input) { PointSet data = input.getDataSet(); if (!(input.getModel() instanceof XYModel)) { @@ -68,12 +68,11 @@ public class PlotFitResultAction extends OneToOneAction { UnivariateFunction function = (double x) -> model.getSpectrum().value(x, input.getParameters()); XYPlotFrame frame = (XYPlotFrame) PlotsPlugin - .buildFrom(getContext()).buildPlotFrame(getName(), input.getName(), + .buildFrom(getContext()).buildPlotFrame(getName(), name, metaData.getNode("plot", null)); //JFreeChartFrame.drawFrame(reader.getString("plotTitle", "Fit result plot for "+input.getName()), null); // double[] x = new double[data.size()]; - // double[] y = new double[data.size()]; // double xMin = Double.POSITIVE_INFINITY; // @@ -94,7 +93,6 @@ public class PlotFitResultAction extends OneToOneAction { // xMax = x[i]; // } // } - frame.add(new PlottableFunction("fit", function, data, adapter));//FIXME replace by helper frame.add(PlottableData.plot("data", adapter, data)); diff --git a/numass-main/src/main/java/inr/numass/Main.java b/numass-main/src/main/java/inr/numass/Main.java index 363783a5..59f9344a 100644 --- a/numass-main/src/main/java/inr/numass/Main.java +++ b/numass-main/src/main/java/inr/numass/Main.java @@ -15,19 +15,20 @@ */ package inr.numass; -import hep.dataforge.actions.ActionResult; -import static hep.dataforge.actions.RunManager.executeXML; +import hep.dataforge.actions.RunManager; import hep.dataforge.context.Context; import static hep.dataforge.context.GlobalContext.out; -import hep.dataforge.data.DataManager; +import hep.dataforge.data.DataNode; +import hep.dataforge.data.FileDataFactory; import hep.dataforge.datafitter.MINUITPlugin; import hep.dataforge.io.IOManager; +import hep.dataforge.io.MetaFileReader; +import hep.dataforge.meta.Meta; import static inr.numass.NumassContext.printDescription; import inr.numass.workbench.Workbench; import java.io.File; import java.io.FileNotFoundException; import java.util.Locale; -import static java.util.Locale.setDefault; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.filechooser.FileFilter; @@ -40,6 +41,7 @@ import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static java.util.Locale.setDefault; /** * @@ -55,7 +57,7 @@ public class Main { } @SuppressWarnings("deprecation") - public static ActionResult run(NumassContext context, String[] args) throws Exception { + public static DataNode run(NumassContext context, String[] args) throws Exception { Logger logger = LoggerFactory.getLogger("numass-main"); Options options = prepareOptions(); @@ -67,15 +69,15 @@ public class Main { } catch (ParseException exp) { // oops, something went wrong logger.error("Command line error. Reason: " + exp.getMessage()); - return ActionResult.empty(); + return DataNode.empty(); } if (line.hasOption("lc")) { printDescription(context, true); - return ActionResult.empty(); + return DataNode.empty(); } else if (line.hasOption("l")) { printDescription(context, false); - return ActionResult.empty(); + return DataNode.empty(); } String cfgPath; @@ -90,20 +92,22 @@ public class Main { cfgPath = line.getOptionValue("c"); if (cfgPath == null) { logger.info("Configutation path not provided."); - return ActionResult.empty(); + return DataNode.empty(); } - File config = context.io().getFile(cfgPath); + File configFile = context.io().getFile(cfgPath); - if (!config.exists()) { + if (!configFile.exists()) { throw new FileNotFoundException("Configuration file not found"); } + + Meta config = MetaFileReader.read(configFile).build(); - context.putValue(IOManager.ROOT_DIRECTORY_CONTEXT_KEY, config.getParentFile().toString()); + context.putValue(IOManager.ROOT_DIRECTORY_CONTEXT_KEY, configFile.getParentFile().toString()); applyCLItoContext(line, context); - return executeXML(context, config); + return RunManager.executeAction(context, config); } else { Workbench.main(args); return null; @@ -125,7 +129,7 @@ public class Main { dataDir = new File(workDir, dataPath); } if (dataDir.exists() && dataDir.isDirectory()) { - context.putValue(DataManager.DATA_DIR, dataDir.getAbsolutePath()); + context.putValue(FileDataFactory.DATA_DIR_KEY, dataDir.getAbsolutePath()); } else { throw new FileNotFoundException("Data directory not found"); } diff --git a/numass-main/src/main/java/inr/numass/NumassIO.java b/numass-main/src/main/java/inr/numass/NumassIO.java index 865cf06e..b826b8ff 100644 --- a/numass-main/src/main/java/inr/numass/NumassIO.java +++ b/numass-main/src/main/java/inr/numass/NumassIO.java @@ -15,6 +15,7 @@ */ package inr.numass; +import hep.dataforge.data.FileData; import hep.dataforge.io.BasicIOManager; import hep.dataforge.meta.Meta; import hep.dataforge.names.Name; @@ -29,6 +30,7 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.output.TeeOutputStream; /** @@ -38,7 +40,7 @@ import org.apache.commons.io.output.TeeOutputStream; public class NumassIO extends BasicIOManager { public static final String NUMASS_OUTPUT_CONTEXT_KEY = "numass.outputDir"; - + @Override public OutputStream out(Name stage, Name name) { List tokens = new ArrayList<>(); @@ -96,7 +98,7 @@ public class NumassIO extends BasicIOManager { } } - public static RawNMFile readAsDat(BinaryData source, Meta config) { + public static RawNMFile readAsDat(FileData source, Meta config) { try { return new NumassDataReader(source, config).read(); } catch (IOException ex) { @@ -104,17 +106,14 @@ public class NumassIO extends BasicIOManager { } } - public static RawNMFile readAsPaw(BinaryData source) { - try { - return new NumassPawReader().readPaw(source.getInputStream(), source.getName()); - } catch (IOException ex) { - throw new RuntimeException(ex); - } + public static RawNMFile readAsPaw(FileData source) { + return new NumassPawReader().readPaw(source.get(), source.fileName()); } public static RawNMFile getNumassData(FileData source, Meta config) { RawNMFile dataFile; - switch (source.getExtension()) { + String extension = FilenameUtils.getExtension(source.fileName()); + switch (extension) { case "paw": dataFile = readAsPaw(source); break; 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 fac109d0..5517a435 100644 --- a/numass-main/src/main/java/inr/numass/actions/AdjustErrorsAction.java +++ b/numass-main/src/main/java/inr/numass/actions/AdjustErrorsAction.java @@ -30,13 +30,13 @@ public class AdjustErrorsAction extends OneToOneAction { } @Override - protected PointSet execute(Logable log, Meta meta, PointSet input) { + protected PointSet execute(Logable log, String name,Meta meta, PointSet input) { List points = new ArrayList<>(); for (DataPoint dp : input) { points.add(evalPoint(meta, dp)); } - return new ListPointSet(input.getName(), input.meta(), points, input.getDataFormat()); + return new ListPointSet(points, input.getDataFormat()); } private DataPoint evalPoint(Meta meta, DataPoint dp) { diff --git a/numass-main/src/main/java/inr/numass/actions/DebunchAction.java b/numass-main/src/main/java/inr/numass/actions/DebunchAction.java index 68d48cd5..34546ee4 100644 --- a/numass-main/src/main/java/inr/numass/actions/DebunchAction.java +++ b/numass-main/src/main/java/inr/numass/actions/DebunchAction.java @@ -33,20 +33,19 @@ import java.io.PrintWriter; * @author Darksnake */ @TypedActionDef(name = "debunch", inputType = RawNMFile.class, outputType = RawNMFile.class) -@ValueDef(name = "upperchanel", type = "NUMBER", def = "4095", info = "An upper chanel for debuncing") -@ValueDef(name = "lowerchanel", type = "NUMBER", def = "0", info = "A lower chanel for debuncing") -@ValueDef(name = "rejectprob", type = "NUMBER", def = "1e-5", info = "Rejection probability") -@ValueDef(name = "framelength", type = "NUMBER", def = "5", info = "Frame length in seconds") -@ValueDef(name = "maxcr", type = "NUMBER", def = "100", info = "Maximum count rate for debunching") -public class DebunchAction extends OneToOneAction { - +@ValueDef(name = "upperchanel", type = "NUMBER", def = "4095", info = "An upper chanel for debuncing") +@ValueDef(name = "lowerchanel", type = "NUMBER", def = "0", info = "A lower chanel for debuncing") +@ValueDef(name = "rejectprob", type = "NUMBER", def = "1e-5", info = "Rejection probability") +@ValueDef(name = "framelength", type = "NUMBER", def = "5", info = "Frame length in seconds") +@ValueDef(name = "maxcr", type = "NUMBER", def = "100", info = "Maximum count rate for debunching") +public class DebunchAction extends OneToOneAction { public DebunchAction(Context context, Meta an) { super(context, an); } @Override - protected RawNMFile execute(Logable log, Meta reader, RawNMFile source) throws ContentException { + protected RawNMFile execute(Logable log, String name, Meta reader, RawNMFile source) throws ContentException { log.log("File {} started", source.getName()); int upper = source.meta().getInt("upperchanel", this.meta().getInt("upperchanel", RawNMPoint.MAX_CHANEL)); @@ -72,7 +71,7 @@ public class DebunchAction extends OneToOneAction { }); log.log("File {} completed", source.getName()); - log.getLog().print(new PrintWriter(buildActionOutput(source))); + log.getLog().print(new PrintWriter(buildActionOutput(name))); // res.configure(source.meta()); return res; diff --git a/numass-main/src/main/java/inr/numass/actions/FindBorderAction.java b/numass-main/src/main/java/inr/numass/actions/FindBorderAction.java index 691e4e2a..891126ec 100644 --- a/numass-main/src/main/java/inr/numass/actions/FindBorderAction.java +++ b/numass-main/src/main/java/inr/numass/actions/FindBorderAction.java @@ -33,13 +33,12 @@ import java.io.OutputStream; @TypedActionDef(name = "findBorder", inputType = NMFile.class, outputType = NMFile.class) public class FindBorderAction extends OneToOneAction { - public FindBorderAction(Context context, Meta an) { super(context, an); } @Override - protected NMFile execute(Logable log, Meta reader, NMFile source) throws ContentException { + protected NMFile execute(Logable log, String name, Meta reader, NMFile source) throws ContentException { log.log("File {} started", source.getName()); int upperBorder = meta().getInt("upper", 4096); @@ -56,7 +55,7 @@ public class FindBorderAction extends OneToOneAction { BorderData bData = new BorderData(source, upperBorder, lowerBorder, referencePoint); - OutputStream stream = buildActionOutput(source); + OutputStream stream = buildActionOutput(name); ColumnedDataWriter.writeDataSet(stream, bData, String.format("%s : lower = %d upper = %d", source.getName(), lowerBorder, upperBorder)); 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 fae0f733..88a8041b 100644 --- a/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java +++ b/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java @@ -17,8 +17,8 @@ package inr.numass.actions; import hep.dataforge.actions.ManyToOneAction; import hep.dataforge.actions.GroupBuilder; -import hep.dataforge.content.NamedGroup; import hep.dataforge.context.Context; +import hep.dataforge.data.DataNode; import hep.dataforge.points.DataPoint; import hep.dataforge.points.ListPointSet; import hep.dataforge.points.MapPoint; @@ -27,12 +27,15 @@ import hep.dataforge.description.TypedActionDef; import hep.dataforge.io.ColumnedDataWriter; import hep.dataforge.io.log.Logable; import hep.dataforge.meta.Meta; +import hep.dataforge.meta.MetaBuilder; import java.io.OutputStream; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import hep.dataforge.points.PointSet; +import java.util.Collection; +import java.util.stream.Collectors; /** * @@ -40,7 +43,6 @@ import hep.dataforge.points.PointSet; */ @TypedActionDef(name = "merge", inputType = PointSet.class, outputType = PointSet.class, description = "Merge different numass data files into one.") @NodeDef(name = "grouping", info = "The defenition of grouping rule for this merge", target = "method::hep.dataforge.content.GroupBuilder.byAnnotation") -//@Parameter(name = "groupBy", def = "mergeTag", info = "Defines the name of the value by which grouping is made. The value is supposed to be a String, but in practice could be any type which could be converted to String.") public class MergeDataAction extends ManyToOneAction { public static final String MERGE_NAME = "mergeName"; @@ -51,80 +53,61 @@ public class MergeDataAction extends ManyToOneAction { } @Override - protected List> buildGroups(Meta reader, List input) { - List> groups; - if (reader.hasValue("grouping.byValue")) { - groups = super.buildGroups(reader, input); + @SuppressWarnings("unchecked") + protected List> buildGroups(DataNode input) { + Meta meta = inputMeta(input.meta()); + List> groups; + if (meta.hasValue("grouping.byValue")) { + groups = super.buildGroups(input); } else { - groups = GroupBuilder.byValue(MERGE_NAME, reader.getString(MERGE_NAME, "merge")).group(input); + groups = GroupBuilder.byValue(MERGE_NAME, meta.getString(MERGE_NAME, "merge")).group(input); } return groups; } @Override - protected PointSet execute(Logable log, Meta reader, NamedGroup input) { - return mergeOne(log, input.getName(), input.asList()); -// List res = new ArrayList<>(); -// for (NamedGroup buildGroups : groups) { -// res.add(mergeOne(log, buildGroups.getName(), buildGroups.asList())); -// } -// return new ContentList<>(input.getName(), PointSet.class, res); + protected PointSet execute(Logable log, DataNode input) { + return mergeOne(log, input); } - private PointSet mergeOne(Logable log, String fileName, List files) { - PointSet[] data = new PointSet[files.size()]; - String head = "Numass data merge\n"; + private PointSet mergeOne(Logable log, DataNode input) { + List data = input.stream().map(item -> item.getValue().get()).collect(Collectors.toList()); + PointSet res = mergeDataSets(input.getName(), data); + return res.sort("Uset", true); + } - String numassPath = ""; + @Override + protected void afterGroup(Logable log, String groupName, Meta outputMeta, PointSet output) { + OutputStream stream = buildActionOutput(groupName); + ColumnedDataWriter.writeDataSet(stream, output, outputMeta.toString()); + } - /* - * Проверяем являются ли пути одинаковыми у всех файлов - * TODO не изящное решение - */ - for (int i = 0; i < files.size(); i++) { - data[i] = files.get(i); - head += "\t" + data[i].getName() + "\n"; - if (numassPath != null) { - String newPath = data[i].meta().getString("numass.path", null); - if (numassPath.isEmpty()) { - numassPath = newPath; - } else { - if (!numassPath.equals(newPath)) { - numassPath = null; + @Override + protected MetaBuilder outputMeta(DataNode input) { + + String numassPath = input.stream().map(item -> item.getValue().meta().getString("numass.path", null)) + .reduce("", (String path, String newPath) -> { + if (path == null) { + return null; + } else if (path.isEmpty()) { + return newPath; + } else if (!path.equals(newPath)) { + return null; + } else { + return newPath; } - } - } - } - - PointSet res = mergeDataSets(fileName, data); + }); + MetaBuilder builder = super.outputMeta(input); /* - * Указываем путь только если он одинаковый для всех входных файлов + * Указываем путь только есл0и он одинаковый для всех входных файлов */ if (numassPath != null) { - res.setMeta(res.meta().getBuilder().putValue("numass.path", numassPath).build()); + builder.putValue("numass.path", numassPath); } - - res = res.sort("Uset", true); - - OutputStream stream = buildActionOutput(res); - - ColumnedDataWriter.writeDataSet(stream, res, head); - - return res; + return builder; } -// private Map> buildMergeGroups(String mergeBy, NamedGroup input) { -// Map> map = new HashMap<>(); -// for (PointSet ds : input) { -// String tag = ds.meta().getString(mergeBy, meta().getString(mergeBy, "merge")); -// if (!map.containsKey(tag)) { -// map.put(tag, new ArrayList<>()); -// } -// map.get(tag).add(ds); -// } -// return map; -// } private DataPoint mergeDataPoints(DataPoint dp1, DataPoint dp2) { if (dp1 == null) { return dp2; @@ -167,7 +150,7 @@ public class MergeDataAction extends ManyToOneAction { return map; } - private PointSet mergeDataSets(String name, PointSet... ds) { + private PointSet mergeDataSets(String name, Collection ds) { //Сливаем все точки в один набор данных Map> points = new LinkedHashMap<>(); for (PointSet d : ds) { @@ -185,15 +168,17 @@ public class MergeDataAction extends ManyToOneAction { List res = new ArrayList<>(); - for (Map.Entry> entry : points.entrySet()) { + points.entrySet().stream().map((entry) -> { DataPoint curPoint = null; for (DataPoint newPoint : entry.getValue()) { curPoint = mergeDataPoints(curPoint, newPoint); } + return curPoint; + }).forEach((curPoint) -> { res.add(curPoint); - } + }); - return new ListPointSet(name, null, res); + return new ListPointSet(res); } 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 00299b47..dee95feb 100644 --- a/numass-main/src/main/java/inr/numass/actions/MonitorCorrectAction.java +++ b/numass-main/src/main/java/inr/numass/actions/MonitorCorrectAction.java @@ -57,7 +57,7 @@ public class MonitorCorrectAction extends OneToOneAction { } @Override - protected PointSet execute(Logable log, Meta reader, PointSet sourceData) throws ContentException { + protected PointSet execute(Logable log, String name, Meta reader, PointSet sourceData) throws ContentException { double monitor = reader.getDouble("monitorPoint", Double.NaN); @@ -131,9 +131,9 @@ public class MonitorCorrectAction extends OneToOneAction { // } else { // format = DataFormat.of(parnames); // } - PointSet data = new ListPointSet(sourceData.getName(), sourceData.meta(), dataList); + PointSet data = new ListPointSet(dataList); - OutputStream stream = buildActionOutput(data); + OutputStream stream = buildActionOutput(name); ColumnedDataWriter.writeDataSet(stream, data, head); @@ -141,15 +141,15 @@ public class MonitorCorrectAction extends OneToOneAction { } @Override - protected void afterAction(ActionResult pack) throws ContentException { + protected void afterAction(String name, PointSet res) { printMonitorData(); - super.afterAction(pack); + super.afterAction(name, res); //To change body of generated methods, choose Tools | Templates. } private void printMonitorData() { String monitorFileName = meta().getString("monitorFile", "monitor"); OutputStream stream = buildActionOutput(monitorFileName); - ListPointSet data = new ListPointSet("monitor", null, monitorPoints); + ListPointSet data = new ListPointSet(monitorPoints); ColumnedDataWriter.writeDataSet(stream, data.sort("Timestamp", true), "Monitor points", monitorNames); } 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 b3a54774..f524ba2c 100644 --- a/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java +++ b/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java @@ -62,7 +62,7 @@ public class PrepareDataAction extends OneToOneAction { } @Override - protected ListPointSet execute(Logable log, Meta reader, NMFile dataFile) throws ContentException { + protected ListPointSet execute(Logable log, String name, Meta reader, NMFile dataFile) { // log.logString("File %s started", dataFile.getName()); int upper = dataFile.meta().getInt("upperWindow", this.meta().getInt("upperWindow", RawNMPoint.MAX_CHANEL - 1)); @@ -112,9 +112,9 @@ public class PrepareDataAction extends OneToOneAction { } head = head + "\n" + new XMLMetaWriter().writeString(meta(), null) + "\n"; - ListPointSet data = new ListPointSet(dataFile.getName(), dataFile.meta(), dataList, format); + ListPointSet data = new ListPointSet(dataList, format); - OutputStream stream = buildActionOutput(data); + OutputStream stream = buildActionOutput(name); ColumnedDataWriter.writeDataSet(stream, data, head); // log.logString("File %s completed", dataFile.getName()); diff --git a/numass-main/src/main/java/inr/numass/actions/ReadNumassDataAction.java b/numass-main/src/main/java/inr/numass/actions/ReadNumassDataAction.java index 71d862ba..73dfe36b 100644 --- a/numass-main/src/main/java/inr/numass/actions/ReadNumassDataAction.java +++ b/numass-main/src/main/java/inr/numass/actions/ReadNumassDataAction.java @@ -17,7 +17,7 @@ package inr.numass.actions; import hep.dataforge.actions.OneToOneAction; import hep.dataforge.context.Context; -import hep.dataforge.points.FileData; +import hep.dataforge.data.FileData; import hep.dataforge.description.NodeDef; import hep.dataforge.description.TypedActionDef; import hep.dataforge.description.ValueDef; @@ -29,7 +29,7 @@ import inr.numass.data.NMFile; import inr.numass.data.RawNMFile; /** - * + * * @author Darksnake */ @TypedActionDef(name = "readData", @@ -46,20 +46,20 @@ public class ReadNumassDataAction extends OneToOneAction { } @Override - protected NMFile execute(Logable log, Meta reader, FileData source) throws ContentException { + protected NMFile execute(Logable log, String name, Meta reader, FileData source) throws ContentException { // log.logString("File '%s' started", source.getName()); RawNMFile raw = getNumassData(source, meta()); if (meta().getBoolean("paw", false)) { - raw.generatePAW(buildActionOutput(source.getName() + ".paw")); + raw.generatePAW(buildActionOutput(name + ".paw")); } - - if(meta().hasNode("debunch")){ + + if (meta().hasNode("debunch")) { DebunchAction debunch = new DebunchAction(getContext(), meta().getNode("debunch")); - raw = debunch.execute(log, null, raw); + raw = debunch.execute(log, name, null, raw); } NMFile result = new NMFile(raw); - + return result; } 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 450e1c26..ec8de34c 100644 --- a/numass-main/src/main/java/inr/numass/actions/ShowLossSpectrumAction.java +++ b/numass-main/src/main/java/inr/numass/actions/ShowLossSpectrumAction.java @@ -70,7 +70,7 @@ public class ShowLossSpectrumAction extends OneToOneAction { } @Override - protected FitState execute(Logable log, Meta reader, FitState input) { + protected FitState execute(Logable log, String name, Meta reader, FitState input) { ParamSet pars = input.getParameters(); if (!pars.names().contains(names)) { LoggerFactory.getLogger(getClass()).error("Wrong input FitState. Must be loss spectrum fit."); @@ -80,9 +80,9 @@ public class ShowLossSpectrumAction extends OneToOneAction { UnivariateFunction scatterFunction; boolean calculateRatio = false; XYPlotFrame frame = (XYPlotFrame) PlotsPlugin.buildFrom(getContext()) - .buildPlotFrame(getName(), input.getName()+".loss", + .buildPlotFrame(getName(), name + ".loss", new MetaBuilder("plot") - .setValue("plotTitle", "Differential scattering crossection for " + input.getName()) + .setValue("plotTitle", "Differential scattering crossection for " + name) ); switch (input.getModel().getName()) { case "scatter-variable": @@ -107,12 +107,12 @@ public class ShowLossSpectrumAction extends OneToOneAction { threshold = reader.getDouble("ionThreshold", 17); ionRatio = calcultateIonRatio(pars, threshold); log.log("The ionization ratio (using threshold {}) is {}", threshold, ionRatio); - ionRatioError = calultateIonRatioError(input, threshold); + ionRatioError = calultateIonRatioError(name, input, threshold); log.log("the ionization ration standard deviation (using threshold {}) is {}", threshold, ionRatioError); } if (reader.getBoolean("printResult", false)) { - PrintWriter writer = new PrintWriter(new OutputStreamWriter(buildActionOutput(input), Charset.forName("UTF-8"))); + PrintWriter writer = new PrintWriter(new OutputStreamWriter(buildActionOutput(name), Charset.forName("UTF-8"))); // writer.println("*** FIT PARAMETERS ***"); input.print(writer); // for (Param param : pars.getSubSet(names).getParams()) { @@ -150,7 +150,7 @@ public class ShowLossSpectrumAction extends OneToOneAction { } writer.printf("%s%n", "chi2"); - writer.printf("%s\t", input.getName()); + writer.printf("%s\t", name); for (Param param : pars.getSubSet(names).getParams()) { writer.printf("%f\t%f\t", param.value(), param.getErr()); @@ -174,7 +174,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, input.getName(), parameters, covariance); + PointSet spreadData = generateSpread(writer, name, parameters, covariance); ColumnedDataWriter.writeDataSet(System.out, spreadData, "", spreadData.getDataFormat().asArray()); } } @@ -208,10 +208,10 @@ public class ShowLossSpectrumAction extends OneToOneAction { return exProb / ionProb; } - public double calultateIonRatioError(FitState state, double threshold) { + public double calultateIonRatioError(String dataNeme, FitState state, double threshold) { ParamSet parameters = state.getParameters().getSubSet(new String[]{"exPos", "ionPos", "exW", "ionW", "exIonRatio"}); NamedMatrix covariance = state.getCovariance(); - return calultateIonRatioError(state.getName(), parameters, covariance, threshold); + return calultateIonRatioError(dataNeme, parameters, covariance, threshold); } @SuppressWarnings("Unchecked") @@ -225,14 +225,14 @@ public class ShowLossSpectrumAction extends OneToOneAction { .filter(d -> !Double.isNaN(d)) .toArray(); - Histogram hist = new Histogram("ionRatio", 0.3, 0.5, 0.002); + Histogram hist = new Histogram(0.3, 0.5, 0.002); hist.fill(res); XYPlotFrame frame = (XYPlotFrame) PlotsPlugin.buildFrom(getContext()) - .buildPlotFrame(getName(), name+".ionRatio", + .buildPlotFrame(getName(), name + ".ionRatio", new MetaBuilder("plot").setValue("plotTitle", "Ion ratio Distribution for " + name) ); // XYPlotFrame frame = JFreeChartFrame.drawFrame("Ion ratio Distribution for " + name, null); - frame.add(PlottableData.plot(hist, new XYAdapter("binCenter", "count"))); + frame.add(PlottableData.plot("ionRatio", hist, new XYAdapter("binCenter", "count"))); return new DescriptiveStatistics(res).getStandardDeviation(); } @@ -272,7 +272,7 @@ public class ShowLossSpectrumAction extends OneToOneAction { } } String[] pointNames = {"e", "central", "lower", "upper", "dispersion"}; - ListPointSet res = new ListPointSet("spread", pointNames); + ListPointSet res = new ListPointSet(pointNames); for (int i = 0; i < gridPoints; i++) { res.add(new MapPoint(pointNames, grid[i], central[i], lower[i], upper[i], dispersion[i])); diff --git a/numass-main/src/main/java/inr/numass/actions/ShowSpectrumAction.java b/numass-main/src/main/java/inr/numass/actions/ShowSpectrumAction.java index bc366181..e8e8fcf3 100644 --- a/numass-main/src/main/java/inr/numass/actions/ShowSpectrumAction.java +++ b/numass-main/src/main/java/inr/numass/actions/ShowSpectrumAction.java @@ -50,7 +50,7 @@ public class ShowSpectrumAction extends OneToOneAction { } @Override - protected NMFile execute(Logable log, Meta reader, NMFile source) throws ContentException { + protected NMFile execute(Logable log, String name, Meta reader, NMFile source) throws ContentException { log.log("File {} started", source.getName()); List printPoints = new ArrayList<>(); @@ -73,9 +73,9 @@ public class ShowSpectrumAction extends OneToOneAction { } if (printPoints.size() > 0) { - ESpectrum data = new ESpectrum(source.getName(), printPoints, chanelsPerBin, normalize); + ESpectrum data = new ESpectrum(printPoints, chanelsPerBin, normalize); - OutputStream stream = buildActionOutput(data); + OutputStream stream = buildActionOutput(name); ColumnedDataWriter.writeDataSet(stream, data, source.getName()); @@ -156,13 +156,13 @@ public class ShowSpectrumAction extends OneToOneAction { } JFreeChartFrame frame = FXPlotUtils.displayJFreeChart(head, null); - + frame.getYAxisConfig().putValue("title", axisName); JFreeChart chart = frame.getChart(); - + chart.getXYPlot().setDataset(dataset); - + chart.getXYPlot().setRenderer(new XYLineAndShapeRenderer(true, false)); chart.getLegend().setPosition(RectangleEdge.RIGHT); diff --git a/numass-main/src/main/java/inr/numass/actions/SlicingAction.java b/numass-main/src/main/java/inr/numass/actions/SlicingAction.java index 7db29b2a..855c9232 100644 --- a/numass-main/src/main/java/inr/numass/actions/SlicingAction.java +++ b/numass-main/src/main/java/inr/numass/actions/SlicingAction.java @@ -49,7 +49,7 @@ public class SlicingAction extends OneToOneAction { } @Override - protected NMFile execute(Logable log, Meta reader, NMFile source) throws ContentException { + protected NMFile execute(Logable log, String name, Meta reader, NMFile source) throws ContentException { boolean normalize; Map> slicingConfig; @@ -73,9 +73,9 @@ public class SlicingAction extends OneToOneAction { SlicedData sData = new SlicedData(source, slicingConfig, normalize); - OutputStream stream = buildActionOutput(source); + OutputStream stream = buildActionOutput(name); - ColumnedDataWriter.writeDataSet(stream, sData, null); + ColumnedDataWriter.writeDataSet(stream, sData, null); log.log("File {} completed", source.getName()); 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 30541039..6c82a7fb 100644 --- a/numass-main/src/main/java/inr/numass/actions/SummaryAction.java +++ b/numass-main/src/main/java/inr/numass/actions/SummaryAction.java @@ -17,8 +17,9 @@ package inr.numass.actions; import hep.dataforge.actions.ManyToOneAction; import hep.dataforge.actions.GroupBuilder; -import hep.dataforge.content.NamedGroup; import hep.dataforge.context.Context; +import hep.dataforge.data.Data; +import hep.dataforge.data.DataNode; import hep.dataforge.points.Format; import hep.dataforge.points.DataPoint; import hep.dataforge.points.ListPointSet; @@ -33,6 +34,8 @@ import java.io.OutputStream; import java.util.Arrays; import java.util.List; import hep.dataforge.points.PointSet; +import java.util.function.Consumer; +import javafx.util.Pair; /** * @@ -40,26 +43,28 @@ import hep.dataforge.points.PointSet; */ @TypedActionDef(name = "summary", inputType = FitState.class, outputType = PointSet.class, description = "Generate summary for fit results of different datasets.") public class SummaryAction extends ManyToOneAction { - + public static final String SUMMARY_NAME = "sumName"; public SummaryAction(Context context, Meta annotation) { super(context, annotation); } - - @Override - protected List> buildGroups(Meta reader, List input) { - List> groups; - if (reader.hasNode("grouping")) { - groups = super.buildGroups(reader, input); - } else { - groups = GroupBuilder.byValue(SUMMARY_NAME, reader.getString(SUMMARY_NAME, "summary")).group(input); - } - return groups; - } @Override - protected PointSet execute(Logable log, Meta reader, NamedGroup input){ + @SuppressWarnings("unchecked") + protected List> buildGroups(DataNode input) { + Meta meta = inputMeta(input.meta()); + List> groups; + if (meta.hasValue("grouping.byValue")) { + groups = super.buildGroups(input); + } else { + groups = GroupBuilder.byValue(SUMMARY_NAME, meta.getString(SUMMARY_NAME, "summary")).group(input); + } + return groups; + } + + @Override + protected PointSet execute(Logable log, DataNode input) { String[] parNames = meta().getStringArray("parnames"); String[] names = new String[2 * parNames.length + 2]; names[0] = "file"; @@ -69,32 +74,33 @@ public class SummaryAction extends ManyToOneAction { } names[names.length - 1] = "chi2"; -// boolean calculateWAV = meta().getBoolean("wav", true); - String fileName = reader.getString(SUMMARY_NAME, "summary"); - - ListPointSet res = new ListPointSet(fileName, Format.forNames(8, names)); + ListPointSet res = new ListPointSet(Format.forNames(8, names)); double[] weights = new double[parNames.length]; Arrays.fill(weights, 0); double[] av = new double[parNames.length]; Arrays.fill(av, 0); - for (FitState state : input) { - Value[] values = new Value[names.length]; - values[0] = Value.of(state.getName()); - for (int i = 0; i < parNames.length; i++) { - Value val = Value.of(state.getParameters().getValue(parNames[i])); - values[2 * i + 1] = val; - Value err = Value.of(state.getParameters().getError(parNames[i])); - values[2 * i + 2] = err; - double weight = 1 / err.doubleValue() / err.doubleValue(); - av[i] += val.doubleValue() * weight; - weights[i] += weight; + input.stream().forEach(new Consumer>>() { + @Override + public void accept(Pair> item) { + FitState state = item.getValue().get(); + Value[] values = new Value[names.length]; + values[0] = Value.of(item.getKey()); + for (int i = 0; i < parNames.length; i++) { + Value val = Value.of(state.getParameters().getValue(parNames[i])); + values[2 * i + 1] = val; + Value err = Value.of(state.getParameters().getError(parNames[i])); + values[2 * i + 2] = err; + double weight = 1 / err.doubleValue() / err.doubleValue(); + av[i] += val.doubleValue() * weight; + weights[i] += weight; + } + values[values.length - 1] = Value.of(state.getChi2()); + DataPoint point = new MapPoint(names, values); + res.add(point); } - values[values.length - 1] = Value.of(state.getChi2()); - DataPoint point = new MapPoint(names, values); - res.add(point); - } + }); Value[] averageValues = new Value[names.length]; averageValues[0] = Value.of("average"); @@ -107,11 +113,15 @@ public class SummaryAction extends ManyToOneAction { res.add(new MapPoint(names, averageValues)); - OutputStream stream = buildActionOutput(res); - - ColumnedDataWriter.writeDataSet(stream, res, fileName); - return res; } + @Override + protected void afterGroup(Logable log, String groupName, Meta outputMeta, PointSet output) { + OutputStream stream = buildActionOutput(groupName); + ColumnedDataWriter.writeDataSet(stream, output, groupName); + + super.afterGroup(log, groupName, outputMeta, output); + } + } 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 9be9aa74..0aa2ee64 100644 --- a/numass-main/src/main/java/inr/numass/data/ESpectrum.java +++ b/numass-main/src/main/java/inr/numass/data/ESpectrum.java @@ -24,19 +24,12 @@ import hep.dataforge.values.ValueFormat; import hep.dataforge.values.ValueFormatFactory; import hep.dataforge.values.ValueType; import java.io.OutputStream; -import static java.lang.String.format; import java.util.ArrayList; import java.util.HashMap; 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; /** * @@ -61,8 +54,8 @@ public class ESpectrum extends ListPointSet { int binning = 1; - public ESpectrum(String name, List points, int binning, boolean normalize) { - super(name, prepareFormat(points)); + public ESpectrum(List points, int binning, boolean normalize) { + super(prepareFormat(points)); this.binning = binning; fill(points, normalize); } diff --git a/numass-main/src/main/java/inr/numass/data/NMFile.java b/numass-main/src/main/java/inr/numass/data/NMFile.java index 7fd64139..571aaaa5 100644 --- a/numass-main/src/main/java/inr/numass/data/NMFile.java +++ b/numass-main/src/main/java/inr/numass/data/NMFile.java @@ -15,7 +15,7 @@ */ package inr.numass.data; -import hep.dataforge.content.NamedMetaHolder; +import hep.dataforge.names.NamedMetaHolder; import hep.dataforge.description.ValueDef; import hep.dataforge.meta.Meta; import hep.dataforge.meta.MetaBuilder; diff --git a/numass-main/src/main/java/inr/numass/data/NumassData.java b/numass-main/src/main/java/inr/numass/data/NumassData.java index 3a8d9d7b..3bd85294 100644 --- a/numass-main/src/main/java/inr/numass/data/NumassData.java +++ b/numass-main/src/main/java/inr/numass/data/NumassData.java @@ -5,7 +5,7 @@ */ package inr.numass.data; -import hep.dataforge.content.Named; +import hep.dataforge.names.Named; import hep.dataforge.meta.Meta; import java.time.Instant; import java.util.List; diff --git a/numass-main/src/main/java/inr/numass/data/NumassDataReader.java b/numass-main/src/main/java/inr/numass/data/NumassDataReader.java index b0239655..cae352ac 100644 --- a/numass-main/src/main/java/inr/numass/data/NumassDataReader.java +++ b/numass-main/src/main/java/inr/numass/data/NumassDataReader.java @@ -15,7 +15,7 @@ */ package inr.numass.data; -import hep.dataforge.points.BinaryData; +import hep.dataforge.data.FileData; import hep.dataforge.meta.MergeRule; import hep.dataforge.meta.Meta; import java.io.BufferedInputStream; @@ -39,9 +39,9 @@ public class NumassDataReader { private Meta config; private double HVdev; - public NumassDataReader(BinaryData data, Meta config) throws IOException { - this(data.getInputStream(), data.meta() - .getString("filename", data.getName()), MergeRule.replace(config, data.meta())); + public NumassDataReader(FileData data, Meta config) throws IOException { + this(data.get(), data.meta() + .getString("filename", data.fileName()), MergeRule.replace(config, data.meta())); } public NumassDataReader(String file, String fname, Meta config) throws FileNotFoundException { diff --git a/numass-main/src/main/java/inr/numass/data/RawNMFile.java b/numass-main/src/main/java/inr/numass/data/RawNMFile.java index dd4545f8..b443adb4 100644 --- a/numass-main/src/main/java/inr/numass/data/RawNMFile.java +++ b/numass-main/src/main/java/inr/numass/data/RawNMFile.java @@ -15,8 +15,7 @@ */ package inr.numass.data; -import hep.dataforge.content.Content; -import hep.dataforge.content.NamedMetaHolder; +import hep.dataforge.names.NamedMetaHolder; import java.io.BufferedOutputStream; import java.io.OutputStream; import java.io.PrintWriter; @@ -27,7 +26,7 @@ import java.util.List; * Contains the whole data but requires a lot of memory * @author Darksnake */ -public class RawNMFile extends NamedMetaHolder implements Content { +public class RawNMFile extends NamedMetaHolder { // public static String TYPE = ":data:numassdatafile"; diff --git a/numass-main/src/main/java/inr/numass/data/SpectrumInformation.java b/numass-main/src/main/java/inr/numass/data/SpectrumInformation.java index d1667cf7..b1abbce0 100644 --- a/numass-main/src/main/java/inr/numass/data/SpectrumInformation.java +++ b/numass-main/src/main/java/inr/numass/data/SpectrumInformation.java @@ -21,6 +21,7 @@ import hep.dataforge.functions.ParametricFunction; import static hep.dataforge.maths.MatrixOperations.inverse; import hep.dataforge.maths.NamedDoubleSet; import hep.dataforge.maths.NamedMatrix; +import inr.numass.utils.TritiumUtils; import org.apache.commons.math3.analysis.UnivariateFunction; import org.apache.commons.math3.linear.Array2DRowRealMatrix; import org.apache.commons.math3.linear.RealMatrix; @@ -39,7 +40,7 @@ public class SpectrumInformation { public NamedMatrix getExpetedCovariance(NamedDoubleSet set, ListPointSet data, String... parNames) { String[] names = parNames; - if(names.length==0) { + if (names.length == 0) { names = source.namesAsArray(); } NamedMatrix info = this.getInformationMatrix(set, data, names); @@ -56,28 +57,28 @@ public class SpectrumInformation { * @return */ public NamedMatrix getInformationMatrix(NamedDoubleSet set, ListPointSet data, String... parNames) { - SpectrumDataAdapter reader = new SpectrumDataAdapter(data.meta().getNode("aliases")); - + SpectrumDataAdapter reader = TritiumUtils.adapter(); + String[] names = parNames; - if(names.length==0) { + if (names.length == 0) { names = source.namesAsArray(); } assert source.names().contains(set.namesAsArray()); assert source.names().contains(names); RealMatrix res = new Array2DRowRealMatrix(names.length, names.length); - + for (DataPoint dp : data) { /*PENDING Тут имеется глобальная неоптимальность связанная с тем, * что при каждом вызове вычисляются две производные * Нужно вычислять сразу всю матрицу для каждой точки, тогда количество * вызовов производных будет строго равно 1. - */ + */ res = res.add(getPointInfoMatrix(set, reader.getX(dp).doubleValue(), reader.getTime(dp), names).getMatrix()); } return new NamedMatrix(res, names); } - + // формула правильная! public double getPoinSignificance(NamedDoubleSet set, String name1, String name2, double x) { return source.derivValue(name1, x, set) * source.derivValue(name2, x, set) / source.value(x, set); @@ -97,7 +98,7 @@ public class SpectrumInformation { for (int i = 0; i < names.length; i++) { for (int j = i; j < names.length; j++) { - double value = getPoinSignificance(set, names[i], names[j], x)*t; + double value = getPoinSignificance(set, names[i], names[j], x) * t; res.setEntry(i, j, value); if (i != j) { res.setEntry(j, i, value); @@ -106,7 +107,7 @@ public class SpectrumInformation { } return new NamedMatrix(res, names); - + } /** 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 ddbeebb1..69f4ce27 100644 --- a/numass-main/src/main/java/inr/numass/models/TransmissionInterpolator.java +++ b/numass-main/src/main/java/inr/numass/models/TransmissionInterpolator.java @@ -18,6 +18,7 @@ package inr.numass.models; import hep.dataforge.actions.ActionResult; import hep.dataforge.actions.RunManager; import hep.dataforge.context.Context; +import hep.dataforge.data.DataNode; import hep.dataforge.points.DataPoint; import hep.dataforge.io.ColumnedDataReader; import hep.dataforge.meta.Meta; @@ -47,8 +48,8 @@ public class TransmissionInterpolator implements UnivariateFunction { @SuppressWarnings("unchecked") public static TransmissionInterpolator fromAction(Context context, Meta actionAnnotation, String xName, String yName, int nSmooth, double w, double border) throws InterruptedException { - ActionResult pack = RunManager.executeAction(context, actionAnnotation); - PointSet data = pack.iterator().next().get(); + DataNode node = RunManager.executeAction(context, actionAnnotation); + PointSet data = node.iterator().next().get(); return new TransmissionInterpolator(data, xName, yName, nSmooth, w, border); } 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 8e2f0682..2aab6ec6 100644 --- a/numass-main/src/main/java/inr/numass/utils/TritiumUtils.java +++ b/numass-main/src/main/java/inr/numass/utils/TritiumUtils.java @@ -18,17 +18,10 @@ package inr.numass.utils; import hep.dataforge.points.DataPoint; import hep.dataforge.points.ListPointSet; import inr.numass.data.SpectrumDataAdapter; -import static java.lang.Math.abs; 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; /** * @@ -68,7 +61,7 @@ public class TritiumUtils { * @return */ public static ListPointSet correctForDeadTime(ListPointSet data, double dtime) { - SpectrumDataAdapter reader = new SpectrumDataAdapter(data.meta().getNode("aliases")); + SpectrumDataAdapter reader = adapter(); ListPointSet res = new ListPointSet(data.getDataFormat()); for (DataPoint dp : data) { double corrFactor = 1 / (1 - dtime * reader.getCount(dp) /reader.getTime(dp)); @@ -86,7 +79,7 @@ public class TritiumUtils { * @return */ public static ListPointSet setHVScale(ListPointSet data, double beta) { - SpectrumDataAdapter reader = new SpectrumDataAdapter(data.meta().getNode("aliases")); + SpectrumDataAdapter reader = adapter(); ListPointSet res = new ListPointSet(data.getDataFormat()); for (DataPoint dp : data) { double corrFactor = 1 + beta; @@ -95,6 +88,10 @@ public class TritiumUtils { return res; } + public static SpectrumDataAdapter adapter(){ + return new SpectrumDataAdapter("Uset", "CR", "CRerr", "Time"); + } + /** * Integral beta spectrum background with given amplitude (total count rate * from) diff --git a/numass-main/src/main/java/inr/numass/workbench/NumassWorkbenchController.java b/numass-main/src/main/java/inr/numass/workbench/NumassWorkbenchController.java index 3598751d..74432c6c 100644 --- a/numass-main/src/main/java/inr/numass/workbench/NumassWorkbenchController.java +++ b/numass-main/src/main/java/inr/numass/workbench/NumassWorkbenchController.java @@ -14,7 +14,9 @@ import hep.dataforge.actions.ActionStateListener; import hep.dataforge.actions.RunManager; import hep.dataforge.context.Context; import hep.dataforge.context.GlobalContext; -import hep.dataforge.data.DataManager; +import hep.dataforge.data.DataFactory; +import hep.dataforge.data.DataNode; +import hep.dataforge.data.FileDataFactory; import hep.dataforge.description.ActionDescriptor; import hep.dataforge.description.DescriptorUtils; import hep.dataforge.exceptions.NameNotFoundException; @@ -296,9 +298,9 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder public void runActions() { clearAllStages(); new Thread(() -> { - ActionResult data = new DataManager(getContext()).readFromConfig(getDataConfiguration()); + DataNode data = new FileDataFactory().build(getContext(), getDataConfiguration()); Action action = RunManager.readAction(getContext(), getActionConfiguration()); - action.addListener(this); +// action.addListener(this); action.run(data); Platform.runLater(() -> statusBar.setText("Execution complete")); }, "actions").start(); diff --git a/numass-main/src/main/java/inr/numass/workbench/OutputTab.java b/numass-main/src/main/java/inr/numass/workbench/OutputTab.java index ae3a98d7..f5b8c1c7 100644 --- a/numass-main/src/main/java/inr/numass/workbench/OutputTab.java +++ b/numass-main/src/main/java/inr/numass/workbench/OutputTab.java @@ -5,7 +5,7 @@ */ package inr.numass.workbench; -import hep.dataforge.content.Named; +import hep.dataforge.names.Named; import javafx.scene.control.Tab; /** diff --git a/numass-main/src/main/java/inr/numass/workbench/StagePane.java b/numass-main/src/main/java/inr/numass/workbench/StagePane.java index 4066ac3b..8075834c 100644 --- a/numass-main/src/main/java/inr/numass/workbench/StagePane.java +++ b/numass-main/src/main/java/inr/numass/workbench/StagePane.java @@ -5,7 +5,7 @@ */ package inr.numass.workbench; -import hep.dataforge.content.Named; +import hep.dataforge.names.Named; import hep.dataforge.meta.Meta; import hep.dataforge.plots.PlotFrame; import java.util.HashMap; diff --git a/numass-prop/src/main/java/inr/numass/prop/ar/JNAEpisode.java b/numass-prop/src/main/java/inr/numass/prop/ar/JNAEpisode.java index a19d1a9b..d80659d4 100644 --- a/numass-prop/src/main/java/inr/numass/prop/ar/JNAEpisode.java +++ b/numass-prop/src/main/java/inr/numass/prop/ar/JNAEpisode.java @@ -15,7 +15,7 @@ */ package inr.numass.prop.ar; -import hep.dataforge.content.NamedMetaHolder; +import hep.dataforge.names.NamedMetaHolder; import hep.dataforge.meta.Meta; import java.util.Iterator; import java.util.List; diff --git a/numass-prop/src/main/java/inr/numass/prop/ar/JNASpectrum.java b/numass-prop/src/main/java/inr/numass/prop/ar/JNASpectrum.java index 0c005c1e..bca91472 100644 --- a/numass-prop/src/main/java/inr/numass/prop/ar/JNASpectrum.java +++ b/numass-prop/src/main/java/inr/numass/prop/ar/JNASpectrum.java @@ -15,7 +15,7 @@ */ package inr.numass.prop.ar; -import hep.dataforge.content.NamedMetaHolder; +import hep.dataforge.names.NamedMetaHolder; import hep.dataforge.points.DataPoint; import hep.dataforge.points.ListPointSet; import hep.dataforge.points.MapPoint;