From 8cc6d0365f04640f3e686d93f6e0ed00658c8e34 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 10 Aug 2016 14:19:50 +0300 Subject: [PATCH] [no commit message] --- .../inr/numass/actions/SummaryAction.java | 1 - .../tasks/NumassFitScanSummaryTask.java | 67 +++++++++++++++++++ .../inr/numass/tasks/NumassFitScanTask.java | 13 +++- .../workbench/NumassWorkbenchController.java | 2 +- 4 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 numass-main/src/main/java/inr/numass/tasks/NumassFitScanSummaryTask.java 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 77667bda..30aa46f2 100644 --- a/numass-main/src/main/java/inr/numass/actions/SummaryAction.java +++ b/numass-main/src/main/java/inr/numass/actions/SummaryAction.java @@ -17,7 +17,6 @@ package inr.numass.actions; import hep.dataforge.actions.GroupBuilder; import hep.dataforge.actions.ManyToOneAction; -import hep.dataforge.context.Context; import hep.dataforge.data.DataNode; import hep.dataforge.stat.fit.FitState; import hep.dataforge.description.TypedActionDef; diff --git a/numass-main/src/main/java/inr/numass/tasks/NumassFitScanSummaryTask.java b/numass-main/src/main/java/inr/numass/tasks/NumassFitScanSummaryTask.java new file mode 100644 index 00000000..308ec4f6 --- /dev/null +++ b/numass-main/src/main/java/inr/numass/tasks/NumassFitScanSummaryTask.java @@ -0,0 +1,67 @@ +/* + * 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.ManyToOneAction; +import hep.dataforge.computation.WorkManager; +import hep.dataforge.context.Context; +import hep.dataforge.data.Data; +import hep.dataforge.data.DataNode; +import hep.dataforge.description.TypedActionDef; +import hep.dataforge.io.reports.Reportable; +import hep.dataforge.meta.Meta; +import hep.dataforge.stat.fit.FitState; +import hep.dataforge.stat.fit.ParamSet; +import hep.dataforge.tables.ListTable; +import hep.dataforge.tables.Table; +import hep.dataforge.workspace.GenericTask; +import hep.dataforge.workspace.TaskModel; +import hep.dataforge.workspace.TaskState; +import java.util.Map; + +/** + * + * @author Alexander Nozik + */ +public class NumassFitScanSummaryTask extends GenericTask { + + @Override + protected TaskState transform(WorkManager.Callback callback, Context context, TaskState state, Meta config) { + return state.finish(new FitSummaryAction().withContext(context).run((DataNode) state.getData(), config)); + } + + @Override + protected TaskModel transformModel(TaskModel model) { + //Transmit meta as-is + model.dependsOn("numass.fitscan", model.meta()); + return model; + } + + @Override + public String getName() { + return "numass.fitsum"; + } + + @TypedActionDef(name = "fitSummary", inputType = FitState.class, outputType = Table.class) + private class FitSummaryAction extends ManyToOneAction { + + @Override + protected Table execute(Reportable log, String nodeName, Map input, Meta meta) { + ListTable.Builder builder = new ListTable.Builder("msterile2", "U2", "U2err", "E0", "trap"); + input.forEach((key, fitRes) -> { + ParamSet pars = fitRes.getParameters(); + builder.row(pars.getValue("msterile2"), + pars.getValue("U2"), + pars.getError("U2"), + pars.getValue("E0"), + pars.getValue("trap")); + }); + return builder.build(); + } + + } + +} diff --git a/numass-main/src/main/java/inr/numass/tasks/NumassFitScanTask.java b/numass-main/src/main/java/inr/numass/tasks/NumassFitScanTask.java index 9f50296d..ea613a42 100644 --- a/numass-main/src/main/java/inr/numass/tasks/NumassFitScanTask.java +++ b/numass-main/src/main/java/inr/numass/tasks/NumassFitScanTask.java @@ -34,7 +34,15 @@ public class NumassFitScanTask extends GenericTask { Value scanValues = config.getValue("scanValues", Value.of(new String[]{"0.5, 1, 1.5, 2, 2.5, 3"})); Action action = new FitAction().withContext(context).withParentProcess(callback.workName()); DataTree.Builder resultBuilder = DataTree.builder(FitState.class); - state.getData().forEachWithType(Table.class, (name, data) -> { + DataNode sourceNode = state.getData(); + + if (config.hasNode("merge")) { + //use merged data and ignore raw data + sourceNode = sourceNode.getNode("merge").get(); + } + + //do fit + sourceNode.forEachDataWithType(Table.class, (name, data) -> { DataNode res = scanValues.listValue().stream().parallel().map(val -> { MetaBuilder overrideMeta = new MetaBuilder("override"); overrideMeta.setValue("@resultName", String.format("%s[%s=%s]", name, scanParameter, val.stringValue())); @@ -47,9 +55,10 @@ public class NumassFitScanTask extends GenericTask { (DataSet.Builder builder, DataNode node) -> builder.putData(node.getName(), node.getData()), (DataSet.Builder builder1, DataSet.Builder builder2) -> builder1.putAll(builder2.getDataMap()) ).build(); - resultBuilder.putNode(name, res); + resultBuilder.putData(name, res.getData()); }); + state.finish(resultBuilder.build()); return state; } 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 ef57a5c2..03a750ab 100644 --- a/numass-main/src/main/java/inr/numass/workbench/NumassWorkbenchController.java +++ b/numass-main/src/main/java/inr/numass/workbench/NumassWorkbenchController.java @@ -365,7 +365,7 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder DataNode data = new FileDataFactory().build(getContext(), getDataConfiguration()); try { - ActionUtils.runAction(getContext(), data, getActionConfiguration()).compute(); + ActionUtils.runAction(getContext(), data, getActionConfiguration()).computeAll(); Platform.runLater(() -> statusBar.setText("Execution complete")); } catch (Exception ex) { if (ex instanceof java.util.concurrent.CancellationException) {