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 9c3b6561..4f240187 100644 --- a/numass-main/src/main/java/hep/dataforge/plotfit/PlotFitResultAction.java +++ b/numass-main/src/main/java/hep/dataforge/plotfit/PlotFitResultAction.java @@ -45,7 +45,7 @@ import java.util.stream.StreamSupport; public class PlotFitResultAction extends OneToOneAction { @Override - protected FitState execute(Context context, Reportable log, String name, Laminate metaData, FitState input) { + protected FitState execute(Reportable log, String name, Laminate metaData, FitState input) { PointSource data = input.getDataSet(); if (!(input.getModel() instanceof XYModel)) { @@ -66,7 +66,7 @@ public class PlotFitResultAction extends OneToOneAction { Function function = (x) -> model.getSpectrum().value(x, input.getParameters()); XYPlotFrame frame = (XYPlotFrame) PlotsPlugin - .buildFrom(context).buildPlotFrame(getName(), name, + .buildFrom(getContext()).buildPlotFrame(getName(), name, metaData.getNode("plot", Meta.empty())); PlottableXYFunction fit = new PlottableXYFunction("fit"); diff --git a/numass-main/src/main/java/inr/numass/NumassContext.java b/numass-main/src/main/java/inr/numass/NumassContext.java index b4a0470a..4007e5b3 100644 --- a/numass-main/src/main/java/inr/numass/NumassContext.java +++ b/numass-main/src/main/java/inr/numass/NumassContext.java @@ -26,7 +26,6 @@ import hep.dataforge.exceptions.DescriptorException; import hep.dataforge.maths.integration.GaussRuleIntegrator; import hep.dataforge.maths.integration.UnivariateIntegrator; import hep.dataforge.meta.Meta; -import inr.numass.storage.SetDirectionUtility; import java.io.PrintWriter; /** @@ -37,6 +36,7 @@ public class NumassContext extends Context { public static UnivariateIntegrator defaultIntegrator = new GaussRuleIntegrator(300); public static UnivariateIntegrator highDensityIntegrator = new GaussRuleIntegrator(500); + public NumassContext(Context parent, Meta config) { super(parent, "numass", config); diff --git a/numass-main/src/main/java/inr/numass/NumassPlugin.java b/numass-main/src/main/java/inr/numass/NumassPlugin.java index 438240fe..1c8de1ed 100644 --- a/numass-main/src/main/java/inr/numass/NumassPlugin.java +++ b/numass-main/src/main/java/inr/numass/NumassPlugin.java @@ -89,7 +89,7 @@ public class NumassPlugin extends BasicPlugin { } @Override - public void detach(Context context) { + public void detach() { } 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 c71540db..fff75463 100644 --- a/numass-main/src/main/java/inr/numass/actions/AdjustErrorsAction.java +++ b/numass-main/src/main/java/inr/numass/actions/AdjustErrorsAction.java @@ -6,7 +6,6 @@ package inr.numass.actions; import hep.dataforge.actions.OneToOneAction; -import hep.dataforge.context.Context; import hep.dataforge.description.TypedActionDef; import hep.dataforge.io.reports.Reportable; import hep.dataforge.meta.Laminate; @@ -27,7 +26,7 @@ import java.util.List; public class AdjustErrorsAction extends OneToOneAction { @Override - protected Table execute(Context context, Reportable log, String name, Laminate meta, Table input) { + protected Table execute(Reportable log, String name, Laminate meta, Table input) { List points = new ArrayList<>(); for (DataPoint dp : input) { points.add(evalPoint(meta, 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 d111d13b..ddf35baf 100644 --- a/numass-main/src/main/java/inr/numass/actions/DebunchAction.java +++ b/numass-main/src/main/java/inr/numass/actions/DebunchAction.java @@ -16,7 +16,6 @@ package inr.numass.actions; import hep.dataforge.actions.OneToOneAction; -import hep.dataforge.context.Context; import hep.dataforge.description.TypedActionDef; import hep.dataforge.description.ValueDef; import hep.dataforge.exceptions.ContentException; @@ -41,7 +40,7 @@ import java.io.PrintWriter; public class DebunchAction extends OneToOneAction { @Override - protected RawNMFile execute(Context context, Reportable log, String name, Laminate meta, RawNMFile source) throws ContentException { + protected RawNMFile execute(Reportable log, String name, Laminate meta, RawNMFile source) throws ContentException { log.report("File {} started", source.getName()); int upper = meta.getInt("upperchanel", RawNMPoint.MAX_CHANEL); @@ -67,7 +66,7 @@ public class DebunchAction extends OneToOneAction { }); log.report("File {} completed", source.getName()); - log.getReport().print(new PrintWriter(buildActionOutput(context, name))); + log.getReport().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 a9daea70..4b7643da 100644 --- a/numass-main/src/main/java/inr/numass/actions/FindBorderAction.java +++ b/numass-main/src/main/java/inr/numass/actions/FindBorderAction.java @@ -47,7 +47,7 @@ public class FindBorderAction extends OneToOneAction { private UnivariateFunction normCorrection = e -> 1 + 13.265 * Math.exp(-e / 2343.4); @Override - protected Table execute(Context context, Reportable log, String name, Laminate meta, NumassData source) throws ContentException { + protected Table execute(Reportable log, String name, Laminate meta, NumassData source) throws ContentException { log.report("File {} started", source.getName()); int upperBorder = meta.getInt("upper", 4094); @@ -67,7 +67,7 @@ public class FindBorderAction extends OneToOneAction { fill(dataBuilder, source, lowerBorder, upperBorder, referencePoint); Table bData = dataBuilder.build(); - OutputStream stream = buildActionOutput(context, name); + OutputStream stream = buildActionOutput(name); ColumnedDataWriter.writeDataSet(stream, bData, String.format("%s : lower = %d upper = %d", name, 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 7dc29d01..38a0b03a 100644 --- a/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java +++ b/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java @@ -50,11 +50,11 @@ public class MergeDataAction extends ManyToOneAction { @Override @SuppressWarnings("unchecked") - protected List> buildGroups(Context context, DataNode input, Meta actionMeta) { - Meta meta = inputMeta(context, input.meta(), actionMeta); + protected List> buildGroups(DataNode input, Meta actionMeta) { + Meta meta = inputMeta(input.meta(), actionMeta); List> groups; if (meta.hasValue("grouping.byValue")) { - groups = super.buildGroups(context, input, actionMeta); + groups = super.buildGroups(input, actionMeta); } else { groups = GroupBuilder.byValue(MERGE_NAME, meta.getString(MERGE_NAME, "merge")).group(input); } @@ -62,14 +62,14 @@ public class MergeDataAction extends ManyToOneAction { } @Override - protected Table execute(Context context, Reportable log, String nodeName, Map data, Meta meta) { + protected Table execute(Reportable log, String nodeName, Map data, Meta meta) { Table res = mergeDataSets(nodeName, data.values()); return new ListTable(res.getFormat(),res.sort("Uset", true)); } @Override - protected void afterGroup(Context context, Reportable log, String groupName, Meta outputMeta, Table output) { - OutputStream stream = buildActionOutput(context, groupName); + protected void afterGroup(Reportable log, String groupName, Meta outputMeta, Table output) { + OutputStream stream = buildActionOutput(groupName); ColumnedDataWriter.writeDataSet(stream, output, outputMeta.toString()); } 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 25f4e8b2..acf72378 100644 --- a/numass-main/src/main/java/inr/numass/actions/MonitorCorrectAction.java +++ b/numass-main/src/main/java/inr/numass/actions/MonitorCorrectAction.java @@ -53,7 +53,7 @@ public class MonitorCorrectAction extends OneToOneAction { //FIXME remove from state @Override - protected Table execute(Context context, Reportable log, String name, Laminate meta, Table sourceData) throws ContentException { + protected Table execute(Reportable log, String name, Laminate meta, Table sourceData) throws ContentException { double monitor = meta.getDouble("monitorPoint", Double.NaN); @@ -144,7 +144,7 @@ public class MonitorCorrectAction extends OneToOneAction { // } Table data = new ListTable(dataList); - OutputStream stream = buildActionOutput(context, name); + OutputStream stream = buildActionOutput(name); ColumnedDataWriter.writeDataSet(stream, data, head); @@ -152,15 +152,15 @@ public class MonitorCorrectAction extends OneToOneAction { } @Override - protected void afterAction(Context context, String name, Table res, Laminate meta) { - printMonitorData(context, meta); - super.afterAction(context, name, res, meta); + protected void afterAction(String name, Table res, Laminate meta) { + printMonitorData(meta); + super.afterAction(name, res, meta); } - private void printMonitorData(Context context, Meta meta) { + private void printMonitorData(Meta meta) { if (!monitorPoints.isEmpty()) { String monitorFileName = meta.getString("monitorFile", "monitor"); - OutputStream stream = buildActionOutput(context, monitorFileName); + OutputStream stream = buildActionOutput(monitorFileName); ListTable data = new ListTable(monitorPoints); ColumnedDataWriter.writeDataSet(stream, data.sort("Timestamp", true), "Monitor points", monitorNames); } diff --git a/numass-main/src/main/java/inr/numass/actions/PileupSimulationAction.java b/numass-main/src/main/java/inr/numass/actions/PileupSimulationAction.java index c939a53a..d5d25c54 100644 --- a/numass-main/src/main/java/inr/numass/actions/PileupSimulationAction.java +++ b/numass-main/src/main/java/inr/numass/actions/PileupSimulationAction.java @@ -31,7 +31,7 @@ import java.util.Map; public class PileupSimulationAction extends OneToOneAction> { @Override - protected Map execute(Context context, Reportable log, String name, Laminate inputMeta, NumassData input) { + protected Map execute(Reportable log, String name, Laminate inputMeta, NumassData input) { int lowerChannel = inputMeta.getInt("lowerChannel", 1); int upperChannel = inputMeta.getInt("upperChannel", RawNMPoint.MAX_CHANEL - 1); 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 c665d8bd..3c914984 100644 --- a/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java +++ b/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java @@ -16,7 +16,6 @@ package inr.numass.actions; import hep.dataforge.actions.OneToOneAction; -import hep.dataforge.context.Context; import hep.dataforge.description.TypedActionDef; import hep.dataforge.description.ValueDef; import hep.dataforge.exceptions.ContentException; @@ -71,7 +70,7 @@ public class PrepareDataAction extends OneToOneAction { } @Override - protected ListTable execute(Context context, Reportable log, String name, Laminate meta, NumassData dataFile) { + protected ListTable execute(Reportable log, String name, Laminate meta, NumassData dataFile) { // log.report("File %s started", dataFile.getName()); int upper = meta.getInt("upperWindow", RawNMPoint.MAX_CHANEL - 1); @@ -131,7 +130,7 @@ public class PrepareDataAction extends OneToOneAction { ListTable data = new ListTable(format, dataList); - OutputStream stream = buildActionOutput(context, name); + 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 28e2f529..685a5c6e 100644 --- a/numass-main/src/main/java/inr/numass/actions/ReadNumassDataAction.java +++ b/numass-main/src/main/java/inr/numass/actions/ReadNumassDataAction.java @@ -42,19 +42,19 @@ import inr.numass.storage.RawNMFile; public class ReadNumassDataAction extends OneToOneAction { @Override - protected NMFile execute(Context context, Reportable log, String name, Laminate meta, Binary source) throws ContentException { + protected NMFile execute(Reportable log, String name, Laminate meta, Binary source) throws ContentException { // log.logString("File '%s' started", source.getName()); RawNMFile raw = getNumassData(source, meta); if (meta.getBoolean("paw", false)) { - raw.generatePAW(buildActionOutput(context, name + ".paw")); + raw.generatePAW(buildActionOutput(name + ".paw")); } if (meta.getNodeNames(false).contains("debunch")) { DebunchAction debunch = new DebunchAction(); Laminate laminate = new Laminate(meta.getNode("debunch")) - .setValueContext(context) + .setValueContext(getContext()) .setDescriptor(debunch.getDescriptor()); - raw = debunch.execute(context, log, name, laminate, raw); + raw = debunch.execute(log, name, laminate, raw); } NMFile result = new NMFile(raw); diff --git a/numass-main/src/main/java/inr/numass/actions/ReadNumassStorageAction.java b/numass-main/src/main/java/inr/numass/actions/ReadNumassStorageAction.java index 4421e8c0..c4055fe4 100644 --- a/numass-main/src/main/java/inr/numass/actions/ReadNumassStorageAction.java +++ b/numass-main/src/main/java/inr/numass/actions/ReadNumassStorageAction.java @@ -6,7 +6,6 @@ package inr.numass.actions; import hep.dataforge.actions.GenericAction; -import hep.dataforge.context.Context; import hep.dataforge.context.DFProcess; import hep.dataforge.context.ProcessManager.Callback; import hep.dataforge.data.Data; @@ -35,7 +34,7 @@ import inr.numass.storage.SetDirectionUtility; public class ReadNumassStorageAction extends GenericAction { @Override - public DataNode run(Context context, DataNode data, Meta actionMeta) { + public DataNode run(DataNode data, Meta actionMeta) { try { NumassStorage storage = NumassStorage.buildNumassRoot(actionMeta.getString("uri"), true, false); DataFilter filter = new DataFilter().configure(actionMeta); @@ -43,45 +42,46 @@ public class ReadNumassStorageAction extends GenericAction { boolean forwardOnly = actionMeta.getBoolean("forwardOnly", false); boolean reverseOnly = actionMeta.getBoolean("reverseOnly", false); - DFProcess> process = context.processManager().>post(getName(), (Callback callback) -> { - //FIXME remove in later revisions - SetDirectionUtility.load(context); + DFProcess> process = getContext().processManager() + .>post(getName(), (Callback callback) -> { + //FIXME remove in later revisions + SetDirectionUtility.load(getContext()); - DataSet.Builder builder = DataSet.builder(NumassData.class); - callback.setMaxProgress(StorageUtils.loaderStream(storage).count()); - StorageUtils.loaderStream(storage).forEach(pair -> { - Loader loader = pair.getValue(); - if (loader instanceof NumassData) { - NumassDataLoader nd = (NumassDataLoader) loader; - Data datum = new StaticData<>(nd); - if (filter.acceptData(pair.getKey(), datum)) { - boolean accept = true; - if (forwardOnly || reverseOnly) { - boolean reversed = nd.isReversed(); - accept = (reverseOnly && reversed) || (forwardOnly && !reversed); + DataSet.Builder builder = DataSet.builder(NumassData.class); + callback.setMaxProgress(StorageUtils.loaderStream(storage).count()); + StorageUtils.loaderStream(storage).forEach(pair -> { + Loader loader = pair.getValue(); + if (loader instanceof NumassData) { + NumassDataLoader nd = (NumassDataLoader) loader; + Data datum = new StaticData<>(nd); + if (filter.acceptData(pair.getKey(), datum)) { + boolean accept = true; + if (forwardOnly || reverseOnly) { + boolean reversed = nd.isReversed(); + accept = (reverseOnly && reversed) || (forwardOnly && !reversed); + } + if (accept) { + builder.putData(pair.getKey(), datum); + } + } } - if (accept) { - builder.putData(pair.getKey(), datum); - } - } - } - callback.increaseProgress(1d); - }); + callback.increaseProgress(1d); + }); - if (actionMeta.getBoolean("loadLegacy", false)) { - logger().info("Loading legacy files"); - storage.legacyFiles().forEach(nd -> { - Data datum = new StaticData<>(nd); - if (filter.acceptData(nd.getName(), datum)) { - builder.putData("legacy." + nd.getName(), datum); + if (actionMeta.getBoolean("loadLegacy", false)) { + logger().info("Loading legacy files"); + storage.legacyFiles().forEach(nd -> { + Data datum = new StaticData<>(nd); + if (filter.acceptData(nd.getName(), datum)) { + builder.putData("legacy." + nd.getName(), datum); + } + }); } + //FIXME remove in later revisions + SetDirectionUtility.save(getContext()); + + return builder.build(); }); - } - //FIXME remove in later revisions - SetDirectionUtility.save(context); - - return builder.build(); - }); return process.getTask().get(); } catch (Exception ex) { diff --git a/numass-main/src/main/java/inr/numass/actions/ShowEnergySpectrumAction.java b/numass-main/src/main/java/inr/numass/actions/ShowEnergySpectrumAction.java index 2a639d6b..c7b2abe0 100644 --- a/numass-main/src/main/java/inr/numass/actions/ShowEnergySpectrumAction.java +++ b/numass-main/src/main/java/inr/numass/actions/ShowEnergySpectrumAction.java @@ -42,7 +42,7 @@ import java.util.stream.Collectors; public class ShowEnergySpectrumAction extends OneToOneAction { @Override - protected Table execute(Context context, Reportable log, String name, Laminate inputMeta, NumassData input) { + protected Table execute(Reportable log, String name, Laminate inputMeta, NumassData input) { int binning = inputMeta.getInt("binning", 20); boolean normalize = inputMeta.getBoolean("normalize", true); List points = input.getNMPoints(); @@ -85,14 +85,14 @@ public class ShowEnergySpectrumAction extends OneToOneAction builder.row(mb.build()); }); - OutputStream out = buildActionOutput(context, name); + OutputStream out = buildActionOutput(name); Table table = builder.build(); ColumnedDataWriter.writeDataSet(out, table, inputMeta.toString()); if (inputMeta.hasNode("plot") || inputMeta.getBoolean("plot", false)) { XYPlotFrame frame = (XYPlotFrame) PlotsPlugin - .buildFrom(context).buildPlotFrame(getName(), name, + .buildFrom(getContext()).buildPlotFrame(getName(), name, inputMeta.getNode("plot", Meta.empty())); fillDetectorData(valueMap).forEach(frame::add); 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 9ca735be..19a08218 100644 --- a/numass-main/src/main/java/inr/numass/actions/ShowLossSpectrumAction.java +++ b/numass-main/src/main/java/inr/numass/actions/ShowLossSpectrumAction.java @@ -16,7 +16,6 @@ package inr.numass.actions; import hep.dataforge.actions.OneToOneAction; -import hep.dataforge.context.Context; import hep.dataforge.datafitter.FitState; import hep.dataforge.datafitter.FitTaskResult; import hep.dataforge.datafitter.Param; @@ -66,7 +65,7 @@ public class ShowLossSpectrumAction extends OneToOneAction { private static final String[] names = {"X", "exPos", "ionPos", "exW", "ionW", "exIonRatio"}; @Override - protected FitState execute(Context context, Reportable log, String name, Laminate meta, FitState input) { + protected FitState execute(Reportable log, String name, Laminate meta, FitState input) { ParamSet pars = input.getParameters(); if (!pars.names().contains(names)) { LoggerFactory.getLogger(getClass()).error("Wrong input FitState. Must be loss spectrum fit."); @@ -75,7 +74,7 @@ public class ShowLossSpectrumAction extends OneToOneAction { UnivariateFunction scatterFunction; boolean calculateRatio = false; - XYPlotFrame frame = (XYPlotFrame) PlotsPlugin.buildFrom(context) + XYPlotFrame frame = (XYPlotFrame) PlotsPlugin.buildFrom(getContext()) .buildPlotFrame(getName(), name + ".loss", new MetaBuilder("plot") .setValue("plotTitle", "Differential scattering crossection for " + name) @@ -103,12 +102,12 @@ public class ShowLossSpectrumAction extends OneToOneAction { threshold = meta.getDouble("ionThreshold", 17); ionRatio = calcultateIonRatio(pars, threshold); log.report("The ionization ratio (using threshold {}) is {}", threshold, ionRatio); - ionRatioError = calultateIonRatioError(context, name, input, threshold); + ionRatioError = calultateIonRatioError(name, input, threshold); log.report("the ionization ration standard deviation (using threshold {}) is {}", threshold, ionRatioError); } if (meta.getBoolean("printResult", false)) { - PrintWriter writer = new PrintWriter(new OutputStreamWriter(buildActionOutput(context, name), 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()) { @@ -204,14 +203,14 @@ public class ShowLossSpectrumAction extends OneToOneAction { return exProb / ionProb; } - public double calultateIonRatioError(Context context, String dataNeme, 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(context, dataNeme, parameters, covariance, threshold); + return calultateIonRatioError(dataNeme, parameters, covariance, threshold); } @SuppressWarnings("Unchecked") - public double calultateIonRatioError(Context context, String name, NamedValueSet parameters, NamedMatrix covariance, double threshold) { + public double calultateIonRatioError(String name, NamedValueSet parameters, NamedMatrix covariance, double threshold) { int number = 10000; double[] res = new GaussianParameterGenerator(parameters, covariance) @@ -223,7 +222,7 @@ public class ShowLossSpectrumAction extends OneToOneAction { Histogram hist = new Histogram(0.3, 0.5, 0.002); hist.fill(res); - XYPlotFrame frame = (XYPlotFrame) PlotsPlugin.buildFrom(context) + XYPlotFrame frame = (XYPlotFrame) PlotsPlugin.buildFrom(getContext()) .buildPlotFrame(getName(), name + ".ionRatio", new MetaBuilder("plot").setValue("plotTitle", "Ion ratio Distribution for " + name) ); 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 7048f0af..ffd18b30 100644 --- a/numass-main/src/main/java/inr/numass/actions/SlicingAction.java +++ b/numass-main/src/main/java/inr/numass/actions/SlicingAction.java @@ -46,7 +46,7 @@ public class SlicingAction extends OneToOneAction { } @Override - protected NMFile execute(Context context, Reportable log, String name, Laminate meta, NMFile source) throws ContentException { + protected NMFile execute(Reportable log, String name, Laminate meta, NMFile source) throws ContentException { boolean normalize; Map> slicingConfig; @@ -70,7 +70,7 @@ public class SlicingAction extends OneToOneAction { SlicedData sData = new SlicedData(source, slicingConfig, normalize); - OutputStream stream = buildActionOutput(context, name); + OutputStream stream = buildActionOutput(name); ColumnedDataWriter.writeDataSet(stream, sData, null); 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 ac3a69a7..0bd6c841 100644 --- a/numass-main/src/main/java/inr/numass/actions/SummaryAction.java +++ b/numass-main/src/main/java/inr/numass/actions/SummaryAction.java @@ -46,11 +46,11 @@ public class SummaryAction extends ManyToOneAction { @Override @SuppressWarnings("unchecked") - protected List> buildGroups(Context context, DataNode input, Meta actionMeta) { - Meta meta = inputMeta(context, input.meta(), actionMeta); + protected List> buildGroups(DataNode input, Meta actionMeta) { + Meta meta = inputMeta(input.meta(), actionMeta); List> groups; if (meta.hasValue("grouping.byValue")) { - groups = super.buildGroups(context, input, actionMeta); + groups = super.buildGroups(input, actionMeta); } else { groups = GroupBuilder.byValue(SUMMARY_NAME, meta.getString(SUMMARY_NAME, "summary")).group(input); } @@ -58,7 +58,7 @@ public class SummaryAction extends ManyToOneAction { } @Override - protected Table execute(Context context, Reportable log, String nodeName, Map input, Meta meta) { + protected Table execute(Reportable log, String nodeName, Map input, Meta meta) { String[] parNames = meta.getStringArray("parnames"); String[] names = new String[2 * parNames.length + 2]; names[0] = "file"; @@ -108,11 +108,11 @@ public class SummaryAction extends ManyToOneAction { } @Override - protected void afterGroup(Context context, Reportable log, String groupName, Meta outputMeta, Table output) { - OutputStream stream = buildActionOutput(context, groupName); + protected void afterGroup(Reportable log, String groupName, Meta outputMeta, Table output) { + OutputStream stream = buildActionOutput(groupName); ColumnedDataWriter.writeDataSet(stream, output, groupName); - super.afterGroup(context, log, groupName, outputMeta, output); + super.afterGroup(log, groupName, outputMeta, output); } } diff --git a/numass-main/src/main/java/inr/numass/tasks/PrepareTask.java b/numass-main/src/main/java/inr/numass/tasks/PrepareTask.java new file mode 100644 index 00000000..b93442c0 --- /dev/null +++ b/numass-main/src/main/java/inr/numass/tasks/PrepareTask.java @@ -0,0 +1,89 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package inr.numass.tasks; + +import hep.dataforge.actions.Action; +import hep.dataforge.context.Context; +import hep.dataforge.context.ProcessManager; +import hep.dataforge.data.DataNode; +import hep.dataforge.data.DataTree; +import hep.dataforge.meta.Meta; +import hep.dataforge.meta.Template; +import hep.dataforge.tables.Table; +import hep.dataforge.workspace.GenericTask; +import hep.dataforge.workspace.TaskModel; +import hep.dataforge.workspace.TaskState; +import inr.numass.actions.MergeDataAction; +import inr.numass.actions.PrepareDataAction; +import inr.numass.actions.ReadNumassStorageAction; +import inr.numass.storage.NumassData; + +/** + * + * @author Alexander Nozik + */ +public class PrepareTask extends GenericTask { + + /* + + + + + + + + + + + + + + */ + @Override + @SuppressWarnings("unchecked") + protected TaskState transform(ProcessManager.Callback callback, Context context, TaskState state, Meta config) { + //acquiring initial data. Data node could not be empty + Meta dataMeta = Template.compileTemplate(config.getNode("data"), config); + DataNode data = runAction(new ReadNumassStorageAction(), callback, context, DataNode.empty(), dataMeta); + state.setData("data", data); + //preparing table data + Meta prepareMeta = Template.compileTemplate(config.getNode("prepare"), config); + DataNode tables = runAction(new PrepareDataAction(), callback, context, data, prepareMeta); + state.setData("prepare", tables); + //merging if needed + if (config.hasNode("merge")) { + DataTree.Builder resultBuilder = DataTree.builder(Table.class); + tables.dataStream().forEach(pair -> resultBuilder.putData(pair.getKey(), pair.getValue())); + config.getNodes("merge").forEach(mergeNode -> { + Meta mergeMeta = Template.compileTemplate(mergeNode, config); + DataNode
mergeData = runAction(new MergeDataAction(), callback, context, tables, mergeMeta); + mergeData.dataStream().forEach(pair -> { + resultBuilder.putData("merge." + pair.getKey(), pair.getValue()); + }); + }); + } else { + state.finish(tables); + } + return state; + } + + private DataNode runAction(Action action, ProcessManager.Callback callback, Context context, DataNode data, Meta meta) { + return action.withContext(context).withParentProcess(callback.processName()).run(data, meta); + } + + @Override + public void validate(TaskModel model) { + if (!model.meta().hasNode("data")) { + + } + } + + @Override + public String getName() { + return "numass.prepare"; + } + +} diff --git a/numass-main/src/main/java/inr/numass/test/TestLazyData.java b/numass-main/src/main/java/inr/numass/test/TestLazyData.java new file mode 100644 index 00000000..59f1d8ba --- /dev/null +++ b/numass-main/src/main/java/inr/numass/test/TestLazyData.java @@ -0,0 +1,41 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package inr.numass.test; + +import hep.dataforge.actions.ActionController; +import java.util.concurrent.CompletableFuture; + +/** + * + * @author Alexander Nozik + */ +public class TestLazyData { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + ActionController lock = new ActionController(); + CompletableFuture future = lock.hold(() -> { + System.out.println(" I am initialized"); + return "abcd"; + }); + future = future.thenCompose((String res) -> CompletableFuture.supplyAsync(() -> { + System.out.println(" I am capitalized"); + return res.toUpperCase(); + })); + future = future.handleAsync((res, err) -> { + System.out.println(" I am handled"); + return "handled " + res; + }); + System.out.println("Releasing hold"); + lock.release(); + +// dat1.getInFuture().thenRunAsync(() -> System.out.println(" I am finished")); +// dat1.getInFuture().thenAcceptAsync((res) -> System.out.println(" I am finished")); + } + +} 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 fde344bc..93c765f7 100644 --- a/numass-main/src/main/java/inr/numass/workbench/NumassWorkbenchController.java +++ b/numass-main/src/main/java/inr/numass/workbench/NumassWorkbenchController.java @@ -158,6 +158,7 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder context.setIO(new WorkbenchIOManager(new NumassIO(), this)); buildContextPane(); context.getReport().addReportListener(new FXReportListener(logPane)); + // display plots iside workbench PlotsPlugin.buildFrom(context).setPlotHolderDelegate(this); diff --git a/numass-storage/src/main/java/inr/numass/storage/SetDirectionUtility.java b/numass-storage/src/main/java/inr/numass/storage/SetDirectionUtility.java index 2b8af3fd..9112b4ab 100644 --- a/numass-storage/src/main/java/inr/numass/storage/SetDirectionUtility.java +++ b/numass-storage/src/main/java/inr/numass/storage/SetDirectionUtility.java @@ -41,6 +41,7 @@ public class SetDirectionUtility { return new File(context.io().getTmpDirectory(), FILE_NAME); } + @SuppressWarnings("unchecked") public static synchronized void load(Context context) { context.getLogger().info("Loading set direction utility"); File file = cacheFile(context);