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 e721f9c1..d90cab08 100644
--- a/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java
+++ b/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java
@@ -42,8 +42,7 @@ public class MergeDataAction extends ManyToOneAction
{
public static String[] parnames = {NumassPoint.HV_KEY, NumassPoint.LENGTH_KEY, NumassAnalyzer.COUNT_KEY, NumassAnalyzer.COUNT_RATE_KEY, NumassAnalyzer.COUNT_RATE_ERROR_KEY};
@Override
- @SuppressWarnings("unchecked")
- protected List> buildGroups(Context context, DataNode input, Meta actionMeta) {
+ protected List> buildGroups(Context context, DataNode input, Meta actionMeta) {
Meta meta = inputMeta(context, input.meta(), actionMeta);
List> groups;
if (meta.hasValue("grouping.byValue")) {
diff --git a/numass-main/src/main/java/inr/numass/tasks/NumassFitScanSummaryTask.java b/numass-main/src/main/java/inr/numass/tasks/NumassFitScanSummaryTask.java
deleted file mode 100644
index ce98b8dd..00000000
--- a/numass-main/src/main/java/inr/numass/tasks/NumassFitScanSummaryTask.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * 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.actions.ManyToOneAction;
-import hep.dataforge.context.Context;
-import hep.dataforge.data.DataNode;
-import hep.dataforge.data.DataSet;
-import hep.dataforge.description.TypedActionDef;
-import hep.dataforge.meta.Laminate;
-import hep.dataforge.meta.Meta;
-import hep.dataforge.stat.fit.FitResult;
-import hep.dataforge.stat.fit.ParamSet;
-import hep.dataforge.stat.fit.UpperLimitGenerator;
-import hep.dataforge.tables.ListTable;
-import hep.dataforge.tables.Table;
-import hep.dataforge.tables.TableTransform;
-import hep.dataforge.workspace.tasks.AbstractTask;
-import hep.dataforge.workspace.tasks.TaskModel;
-import inr.numass.NumassUtils;
-
-import java.util.Map;
-
-/**
- * @author Alexander Nozik
- */
-public class NumassFitScanSummaryTask extends AbstractTask {
-
- @Override
- protected DataNode run(TaskModel model, DataNode> data) {
- DataSet.Builder builder = DataSet.builder(Table.class);
- Action action = new FitSummaryAction();
- DataNode input = data.getCheckedNode("fitscan", FitResult.class);
- input.nodeStream().filter(it -> it.dataSize(false) > 0).forEach(node ->
- builder.putData(node.getName(), action.run(model.getContext(), node, model.meta()).getData())
- );
- return builder.build();
- }
-
- @Override
- protected void buildModel(TaskModel.Builder model, Meta meta) {
- model.dependsOn("fitscan", meta, "fitscan");
- }
-
-
- @Override
- public String getName() {
- return "scansum";
- }
-
- @TypedActionDef(name = "sterileSummary", inputType = FitResult.class, outputType = Table.class)
- private class FitSummaryAction extends ManyToOneAction {
-
- @Override
- protected Table execute(Context context, String nodeName, Map input, Laminate meta) {
- ListTable.Builder builder = new ListTable.Builder("m", "U2", "U2err", "U2limit", "E0", "trap");
- input.forEach((key, fitRes) -> {
- ParamSet pars = fitRes.getParameters();
-
- double u2Val = pars.getDouble("U2") / pars.getError("U2");
-
- double limit;
- if (Math.abs(u2Val) < 3) {
- limit = UpperLimitGenerator.getConfidenceLimit(u2Val) * pars.getError("U2");
- } else {
- limit = Double.NaN;
- }
-
- builder.row(
- Math.sqrt(pars.getValue("msterile2").doubleValue()),
- pars.getValue("U2"),
- pars.getError("U2"),
- limit,
- pars.getValue("E0"),
- pars.getValue("trap"));
- });
- Table res = TableTransform.sort(builder.build(), "m", true);
- output(context, nodeName, stream -> NumassUtils.INSTANCE.write(stream,meta,res));
- return res;
- }
-
- }
-
-}
diff --git a/numass-main/src/main/java/inr/numass/tasks/NumassFitScanTask.java b/numass-main/src/main/java/inr/numass/tasks/NumassFitScanTask.java
deleted file mode 100644
index b181753e..00000000
--- a/numass-main/src/main/java/inr/numass/tasks/NumassFitScanTask.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.data.DataNode;
-import hep.dataforge.data.DataTree;
-import hep.dataforge.meta.Meta;
-import hep.dataforge.meta.MetaBuilder;
-import hep.dataforge.stat.fit.FitAction;
-import hep.dataforge.stat.fit.FitResult;
-import hep.dataforge.tables.Table;
-import hep.dataforge.values.Value;
-import hep.dataforge.workspace.tasks.AbstractTask;
-import hep.dataforge.workspace.tasks.TaskModel;
-
-import java.util.Objects;
-import java.util.stream.Collectors;
-
-/**
- * @author Alexander Nozik
- */
-public class NumassFitScanTask extends AbstractTask {
-
-
- @Override
- protected DataNode run(TaskModel model, DataNode> data) {
- Meta config = model.meta();
- String scanParameter = config.getString("parameter", "msterile2");
-
- Value scanValues;
- if (config.hasValue("masses")) {
- scanValues = Value.of(config.getValue("masses")
- .listValue().stream()
- .map(it -> Math.pow(it.doubleValue() * 1000, 2.0))
- .collect(Collectors.toList())
- );
- } else {
- scanValues = config.getValue("values", Value.of("[2.5e5, 1e6, 2.25e6, 4e6, 6.25e6, 9e6]"));
- }
- Action action = new FitAction();
- DataTree.Builder resultBuilder = DataTree.builder(FitResult.class);
- DataNode sourceNode = data.getCheckedNode("prepare", Table.class);
-
- if (config.hasMeta("merge")) {
- //use merged data and ignore raw data
- sourceNode = sourceNode.getCheckedNode("merge", Table.class);
- }
-
- //do fit
-
- Meta fitConfig = config.getMeta("fit");
- sourceNode.dataStream().forEach(table -> {
- for (int i = 0; i < scanValues.listValue().size(); i++) {
- Value val = scanValues.listValue().get(i);
- MetaBuilder overrideMeta = new MetaBuilder(fitConfig);
-
- String resultName = String.format("%s[%s=%s]", table.getName(), scanParameter, val.stringValue());
-// overrideMeta.setValue("@resultName", String.format("%s[%s=%s]", table.getName(), scanParameter, val.stringValue()));
-
- if (overrideMeta.hasMeta("params." + scanParameter)) {
- overrideMeta.setValue("params." + scanParameter + ".value", val);
- } else {
- overrideMeta.getMetaList("params.param").stream()
- .filter(par -> Objects.equals(par.getString("name"), scanParameter)).forEach(par -> par.setValue("value", val));
- }
-// Data newData = new Data(data.getGoal(),data.type(),overrideMeta);
- DataNode node = action.run(model.getContext(), DataNode.of(resultName, table, Meta.empty()), overrideMeta);
- resultBuilder.putData(table.getName() + ".fit_" + i, node.getData());
- }
- });
-
-
- return resultBuilder.build();
- }
-
- @Override
- protected void buildModel(TaskModel.Builder model, Meta meta) {
- model.configure(meta.getMetaOrEmpty("scan"));
- model.configure(it->it.putNode(meta.getMetaOrEmpty("fit")));
- if (meta.hasMeta("filter")) {
- model.dependsOn("filter", meta, "prepare");
- } else if (meta.hasMeta("empty")) {
- model.dependsOn("subtractEmpty", meta, "prepare");
- } else {
- model.dependsOn("prepare", meta, "prepare");
- }
- }
-
- @Override
- public String getName() {
- return "fitscan";
- }
-
-}
diff --git a/numass-main/src/main/java/inr/numass/tasks/NumassFitSummaryTask.java b/numass-main/src/main/java/inr/numass/tasks/NumassFitSummaryTask.java
deleted file mode 100644
index 50633e25..00000000
--- a/numass-main/src/main/java/inr/numass/tasks/NumassFitSummaryTask.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2015 Alexander Nozik.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package inr.numass.tasks;
-
-import hep.dataforge.actions.Action;
-import hep.dataforge.data.DataNode;
-import hep.dataforge.meta.Meta;
-import hep.dataforge.stat.fit.FitState;
-import hep.dataforge.tables.Table;
-import hep.dataforge.workspace.tasks.SingleActionTask;
-import hep.dataforge.workspace.tasks.TaskModel;
-import inr.numass.actions.SummaryAction;
-
-/**
- * Created by darksnake on 16-Sep-16.
- */
-public class NumassFitSummaryTask extends SingleActionTask {
- @Override
- public String getName() {
- return "summary";
- }
-
- @Override
- protected Action getAction(TaskModel model) {
- return new SummaryAction();
- }
-
- @Override
- protected DataNode gatherNode(DataNode> data) {
- return data.getCheckedNode("fit", FitState.class);
- }
-
- @Override
- protected Meta transformMeta(TaskModel model) {
- return model.meta().getMeta("summary");
- }
-
- @Override
- protected void buildModel(TaskModel.Builder model, Meta meta) {
- model.dependsOn("fit", meta, "fit");
- }
-}
diff --git a/numass-main/src/main/java/inr/numass/tasks/NumassFitTask.java b/numass-main/src/main/java/inr/numass/tasks/NumassFitTask.java
deleted file mode 100644
index aba59ea8..00000000
--- a/numass-main/src/main/java/inr/numass/tasks/NumassFitTask.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright 2015 Alexander Nozik.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package inr.numass.tasks;
-
-import hep.dataforge.actions.Action;
-import hep.dataforge.actions.ActionUtils;
-import hep.dataforge.data.DataNode;
-import hep.dataforge.meta.Meta;
-import hep.dataforge.plotfit.PlotFitResultAction;
-import hep.dataforge.stat.fit.FitAction;
-import hep.dataforge.stat.fit.FitResult;
-import hep.dataforge.tables.Table;
-import hep.dataforge.workspace.tasks.SingleActionTask;
-import hep.dataforge.workspace.tasks.TaskModel;
-
-/**
- * Created by darksnake on 16-Sep-16.
- */
-public class NumassFitTask extends SingleActionTask {
-
- @Override
- public String getName() {
- return "fit";
- }
-
- @Override
- protected DataNode gatherNode(DataNode> data) {
- return data.getCheckedNode("prepare", Table.class);
- }
-
- @Override
- public void validate(TaskModel model) {
- if (model.meta().isEmpty()) {
- throw new RuntimeException("Fit element not found in model");
- }
- }
-
- @Override
- protected Action getAction(TaskModel model) {
- Action action = new FitAction();
- if (model.meta().getBoolean("frame", false)) {
- return ActionUtils.compose(action, new PlotFitResultAction());
- } else {
- return action;
- }
- }
-
- @Override
- protected Meta transformMeta(TaskModel model) {
- return model.meta();
- }
-
-
- @Override
- protected void buildModel(TaskModel.Builder model, Meta meta) {
- if (meta.hasMeta("filter")) {
- model.dependsOn("filter", meta, "prepare");
- } else if (meta.hasMeta("empty")) {
- model.dependsOn("subtractEmpty", meta, "prepare");
- } else {
- model.dependsOn("prepare", meta, "prepare");
- }
- }
-}
diff --git a/numass-main/src/main/java/inr/numass/tasks/NumassPrepareTask.java b/numass-main/src/main/java/inr/numass/tasks/NumassPrepareTask.java
index 9fd1db2d..92c80238 100644
--- a/numass-main/src/main/java/inr/numass/tasks/NumassPrepareTask.java
+++ b/numass-main/src/main/java/inr/numass/tasks/NumassPrepareTask.java
@@ -31,6 +31,7 @@ import inr.numass.data.api.NumassSet;
@NodeDef(name = "prepare")
@NodeDef(name = "monitor")
@NodeDef(name = "merge")
+@Deprecated
public class NumassPrepareTask extends AbstractTask {
@Override
diff --git a/numass-main/src/main/java/inr/numass/tasks/NumassTableFilterTask.java b/numass-main/src/main/java/inr/numass/tasks/NumassTableFilterTask.java
deleted file mode 100644
index feda3f93..00000000
--- a/numass-main/src/main/java/inr/numass/tasks/NumassTableFilterTask.java
+++ /dev/null
@@ -1,98 +0,0 @@
-package inr.numass.tasks;
-
-import hep.dataforge.actions.Action;
-import hep.dataforge.actions.OneToOneAction;
-import hep.dataforge.context.Context;
-import hep.dataforge.data.DataNode;
-import hep.dataforge.description.TypedActionDef;
-import hep.dataforge.meta.Laminate;
-import hep.dataforge.meta.Meta;
-import hep.dataforge.tables.Table;
-import hep.dataforge.tables.TableTransform;
-import hep.dataforge.values.Value;
-import hep.dataforge.values.Values;
-import hep.dataforge.workspace.tasks.SingleActionTask;
-import hep.dataforge.workspace.tasks.TaskModel;
-import inr.numass.utils.ExpressionUtils;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.function.Predicate;
-
-/**
- * Created by darksnake on 13-Aug-16.
- */
-public class NumassTableFilterTask extends SingleActionTask {
-
- @Override
- public String getName() {
- return "filter";
- }
-
- @Override
- protected DataNode gatherNode(DataNode> data) {
- return data.getCheckedNode("prepare", Table.class);
- }
-
-
- @Override
- protected void buildModel(TaskModel.Builder model, Meta meta) {
- if (meta.hasMeta("empty")) {
- model.dependsOn("subtractEmpty", meta, "prepare");
- } else {
- model.dependsOn("prepare", meta, "prepare");
- }
- }
-
- @Override
- protected Action getAction(TaskModel model) {
- return new FilterTableAction();
- }
-
- @TypedActionDef(name = "filterTable", inputType = Table.class, outputType = Table.class)
- private class FilterTableAction extends OneToOneAction {
- @Override
- protected Table execute(Context context, String name, Table input, Laminate inputMeta) {
- if (inputMeta.hasValue("from") || inputMeta.hasValue("to")) {
- double uLo = inputMeta.getDouble("from", 0);
- double uHi = inputMeta.getDouble("to", Double.POSITIVE_INFINITY);
- getLogger(context,inputMeta).debug("Filtering finished");
- return TableTransform.filter(input, "Uset", uLo, uHi);
- } else if (inputMeta.hasValue("condition")) {
- Predicate predicate = (dp) -> ExpressionUtils.condition(inputMeta.getString("condition"), unbox(dp));
- return TableTransform.filter(input, predicate);
- } else {
- throw new RuntimeException("No filtering condition specified");
- }
- }
- }
-
- private Map unbox(Values dp) {
- Map res = new HashMap<>();
- for (String field : dp.getNames()) {
- Value val = dp.getValue(field);
- Object obj;
- switch (val.getType()) {
- case BOOLEAN:
- obj = val.booleanValue();
- break;
- case NUMBER:
- obj = val.doubleValue();
- break;
- case STRING:
- obj = val.stringValue();
- break;
- case TIME:
- obj = val.timeValue();
- break;
- case NULL:
- obj = null;
- break;
- default:
- throw new Error("unreachable statement");
- }
- res.put(field, obj);
- }
- return res;
- }
-}
diff --git a/numass-main/src/main/kotlin/inr/numass/NumassPlugin.kt b/numass-main/src/main/kotlin/inr/numass/NumassPlugin.kt
index b75a1b15..0f13d19e 100644
--- a/numass-main/src/main/kotlin/inr/numass/NumassPlugin.kt
+++ b/numass-main/src/main/kotlin/inr/numass/NumassPlugin.kt
@@ -22,8 +22,6 @@ import hep.dataforge.context.PluginDef
import hep.dataforge.kodex.fx.plots.PlotContainer
import hep.dataforge.maths.MathPlugin
import hep.dataforge.meta.Meta
-import hep.dataforge.plotfit.PlotFitResultAction
-import hep.dataforge.plots.PlotDataAction
import hep.dataforge.plots.jfreechart.JFreeChartFrame
import hep.dataforge.stat.fit.FitManager
import hep.dataforge.stat.models.ModelManager
@@ -31,7 +29,6 @@ import hep.dataforge.stat.models.WeightedXYModel
import hep.dataforge.stat.models.XYModel
import hep.dataforge.tables.ValuesAdapter
import hep.dataforge.tables.XYAdapter
-import inr.numass.actions.*
import inr.numass.data.api.NumassAnalyzer
import inr.numass.data.api.NumassPoint
import inr.numass.models.*
@@ -64,15 +61,6 @@ class NumassPlugin : BasicPlugin() {
val actions = context.pluginManager().getOrLoad(ActionManager::class.java)
actions.attach(context)
- actions.putAction(MergeDataAction::class.java)
- actions.putAction(MonitorCorrectAction::class.java)
- actions.putAction(SummaryAction::class.java)
- actions.putAction(PlotDataAction::class.java)
- actions.putAction(PlotFitResultAction::class.java)
- actions.putAction(AdjustErrorsAction::class.java)
- actions.putAction(SubstractSpectrumAction::class.java)
-
- //actions.putTask(NumassPrepareTask::class.java)
actions.putTask(NumassTableFilterTask::class.java)
actions.putTask(NumassFitScanTask::class.java)
actions.putTask(NumassFitScanSummaryTask::class.java)
@@ -84,11 +72,7 @@ class NumassPlugin : BasicPlugin() {
actions.put(mergeEmptyTask)
actions.put(monitorTableTask)
actions.put(subtractEmptyTask)
- }
-
- override fun detach() {
- //TODO clean up
- super.detach()
+ actions.put(transformTask)
}
private fun loadMath(math: MathPlugin) {
diff --git a/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanSummaryTask.kt b/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanSummaryTask.kt
new file mode 100644
index 00000000..a38187e2
--- /dev/null
+++ b/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanSummaryTask.kt
@@ -0,0 +1,78 @@
+/*
+ * 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.context.Context
+import hep.dataforge.data.DataNode
+import hep.dataforge.data.DataSet
+import hep.dataforge.description.TypedActionDef
+import hep.dataforge.meta.Laminate
+import hep.dataforge.meta.Meta
+import hep.dataforge.stat.fit.FitResult
+import hep.dataforge.stat.fit.UpperLimitGenerator
+import hep.dataforge.tables.ListTable
+import hep.dataforge.tables.Table
+import hep.dataforge.tables.TableTransform
+import hep.dataforge.workspace.tasks.AbstractTask
+import hep.dataforge.workspace.tasks.TaskModel
+import inr.numass.NumassUtils
+
+/**
+ * @author Alexander Nozik
+ */
+class NumassFitScanSummaryTask : AbstractTask() {
+
+ override fun run(model: TaskModel, data: DataNode<*>): DataNode {
+ val builder = DataSet.builder(Table::class.java)
+ val action = FitSummaryAction()
+ val input = data.getCheckedNode("fitscan", FitResult::class.java)
+ input.nodeStream().filter { it -> it.dataSize(false) > 0 }.forEach { node -> builder.putData(node.name, action.run(model.context, node, model.meta()).data) }
+ return builder.build()
+ }
+
+ override fun buildModel(model: TaskModel.Builder, meta: Meta) {
+ model.dependsOn("fitscan", meta, "fitscan")
+ }
+
+
+ override fun getName(): String {
+ return "scansum"
+ }
+
+ @TypedActionDef(name = "sterileSummary", inputType = FitResult::class, outputType = Table::class)
+ private inner class FitSummaryAction : ManyToOneAction() {
+
+ override fun execute(context: Context, nodeName: String, input: Map, meta: Laminate): Table {
+ val builder = ListTable.Builder("m", "U2", "U2err", "U2limit", "E0", "trap")
+ input.forEach { key, fitRes ->
+ val pars = fitRes.parameters
+
+ val u2Val = pars.getDouble("U2")!! / pars.getError("U2")
+
+ val limit: Double
+ if (Math.abs(u2Val) < 3) {
+ limit = UpperLimitGenerator.getConfidenceLimit(u2Val) * pars.getError("U2")
+ } else {
+ limit = java.lang.Double.NaN
+ }
+
+ builder.row(
+ Math.sqrt(pars.getValue("msterile2").doubleValue()),
+ pars.getValue("U2"),
+ pars.getError("U2"),
+ limit,
+ pars.getValue("E0"),
+ pars.getValue("trap"))
+ }
+ val res = TableTransform.sort(builder.build(), "m", true)
+ output(context, nodeName) { stream -> NumassUtils.write(stream, meta, res) }
+ return res
+ }
+
+ }
+
+}
diff --git a/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanTask.kt b/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanTask.kt
new file mode 100644
index 00000000..e2f7a521
--- /dev/null
+++ b/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitScanTask.kt
@@ -0,0 +1,86 @@
+/*
+ * 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.data.DataNode
+import hep.dataforge.data.DataTree
+import hep.dataforge.meta.Meta
+import hep.dataforge.meta.MetaBuilder
+import hep.dataforge.stat.fit.FitAction
+import hep.dataforge.stat.fit.FitResult
+import hep.dataforge.tables.Table
+import hep.dataforge.values.ListValue
+import hep.dataforge.values.Value
+import hep.dataforge.workspace.tasks.AbstractTask
+import hep.dataforge.workspace.tasks.TaskModel
+import java.util.stream.Collectors
+
+/**
+ * @author Alexander Nozik
+ */
+class NumassFitScanTask : AbstractTask() {
+
+
+ override fun run(model: TaskModel, data: DataNode<*>): DataNode {
+ val config = model.meta()
+ val scanParameter = config.getString("parameter", "msterile2")
+
+ val scanValues: Value = if (config.hasValue("masses")) {
+ ListValue(config.getValue("masses")
+ .listValue().stream()
+ .map { it -> Math.pow(it.doubleValue() * 1000, 2.0) }
+ .collect(Collectors.toList())
+ )
+ } else {
+ config.getValue("values", Value.of("[2.5e5, 1e6, 2.25e6, 4e6, 6.25e6, 9e6]"))
+ }
+
+ val action = FitAction()
+ val resultBuilder = DataTree.builder(FitResult::class.java)
+ val sourceNode = data.checked(Table::class.java)
+
+ //do fit
+
+ val fitConfig = config.getMeta("fit")
+ sourceNode.dataStream().forEach { table ->
+ for (i in 0 until scanValues.listValue().size) {
+ val `val` = scanValues.listValue()[i]
+ val overrideMeta = MetaBuilder(fitConfig)
+
+ val resultName = String.format("%s[%s=%s]", table.name, scanParameter, `val`.stringValue())
+ // overrideMeta.setValue("@resultName", String.format("%s[%s=%s]", table.getName(), scanParameter, val.stringValue()));
+
+ if (overrideMeta.hasMeta("params." + scanParameter)) {
+ overrideMeta.setValue("params.$scanParameter.value", `val`)
+ } else {
+ overrideMeta.getMetaList("params.param").stream()
+ .filter { par -> par.getString("name") == scanParameter }.forEach { par -> par.setValue("value", `val`) }
+ }
+ // Data newData = new Data(data.getGoal(),data.type(),overrideMeta);
+ val node = action.run(model.context, DataNode.of(resultName, table, Meta.empty()), overrideMeta)
+ resultBuilder.putData(table.name + ".fit_" + i, node.data)
+ }
+ }
+
+
+ return resultBuilder.build()
+ }
+
+ override fun buildModel(model: TaskModel.Builder, meta: Meta) {
+ model.configure(meta.getMetaOrEmpty("scan"))
+ model.configure { it -> it.putNode(meta.getMetaOrEmpty("fit")) }
+ when {
+ meta.hasMeta("filter") -> model.dependsOn("filter", meta, "prepare")
+ meta.hasMeta("empty") -> model.dependsOn("subtractEmpty", meta, "prepare")
+ else -> model.dependsOn("prepare", meta, "prepare")
+ }
+ }
+
+ override fun getName(): String {
+ return "fitscan"
+ }
+
+}
diff --git a/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitSummaryTask.kt b/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitSummaryTask.kt
new file mode 100644
index 00000000..a1471914
--- /dev/null
+++ b/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitSummaryTask.kt
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2015 Alexander Nozik.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package inr.numass.tasks
+
+import hep.dataforge.actions.Action
+import hep.dataforge.data.DataNode
+import hep.dataforge.meta.Meta
+import hep.dataforge.stat.fit.FitState
+import hep.dataforge.tables.Table
+import hep.dataforge.workspace.tasks.SingleActionTask
+import hep.dataforge.workspace.tasks.TaskModel
+import inr.numass.actions.SummaryAction
+
+/**
+ * Created by darksnake on 16-Sep-16.
+ */
+class NumassFitSummaryTask : SingleActionTask() {
+ override fun getName(): String {
+ return "summary"
+ }
+
+ override fun getAction(model: TaskModel): Action {
+ return SummaryAction()
+ }
+
+ override fun gatherNode(data: DataNode<*>): DataNode {
+ return data.getCheckedNode("fit", FitState::class.java)
+ }
+
+ override fun transformMeta(model: TaskModel): Meta {
+ return model.meta().getMeta("summary")
+ }
+
+ override fun buildModel(model: TaskModel.Builder, meta: Meta) {
+ model.dependsOn("fit", meta, "fit")
+ }
+}
diff --git a/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitTask.kt b/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitTask.kt
new file mode 100644
index 00000000..9941bba5
--- /dev/null
+++ b/numass-main/src/main/kotlin/inr/numass/tasks/NumassFitTask.kt
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2015 Alexander Nozik.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package inr.numass.tasks
+
+import hep.dataforge.actions.Action
+import hep.dataforge.actions.ActionUtils
+import hep.dataforge.data.DataNode
+import hep.dataforge.meta.Meta
+import hep.dataforge.plotfit.PlotFitResultAction
+import hep.dataforge.stat.fit.FitAction
+import hep.dataforge.stat.fit.FitResult
+import hep.dataforge.tables.Table
+import hep.dataforge.workspace.tasks.SingleActionTask
+import hep.dataforge.workspace.tasks.TaskModel
+
+/**
+ * Created by darksnake on 16-Sep-16.
+ */
+class NumassFitTask : SingleActionTask() {
+
+ override fun getName(): String {
+ return "fit"
+ }
+
+ override fun gatherNode(data: DataNode<*>): DataNode {
+ return data.checked(Table::class.java)
+ }
+
+ override fun validate(model: TaskModel) {
+ if (model.meta().isEmpty) {
+ throw RuntimeException("Fit element not found in model")
+ }
+ }
+
+ override fun getAction(model: TaskModel): Action {
+ val action = FitAction()
+ return if (model.meta().getBoolean("frame", false)) {
+ ActionUtils.compose(action, PlotFitResultAction())
+ } else {
+ action
+ }
+ }
+
+ override fun buildModel(model: TaskModel.Builder, meta: Meta) {
+ model.dependsOn("transform", meta);
+ }
+}
diff --git a/numass-main/src/main/kotlin/inr/numass/tasks/NumassTableFilterTask.kt b/numass-main/src/main/kotlin/inr/numass/tasks/NumassTableFilterTask.kt
new file mode 100644
index 00000000..4d416de0
--- /dev/null
+++ b/numass-main/src/main/kotlin/inr/numass/tasks/NumassTableFilterTask.kt
@@ -0,0 +1,77 @@
+package inr.numass.tasks
+
+import hep.dataforge.actions.Action
+import hep.dataforge.actions.OneToOneAction
+import hep.dataforge.context.Context
+import hep.dataforge.data.DataNode
+import hep.dataforge.description.TypedActionDef
+import hep.dataforge.meta.Laminate
+import hep.dataforge.meta.Meta
+import hep.dataforge.tables.Table
+import hep.dataforge.tables.TableTransform
+import hep.dataforge.values.ValueType
+import hep.dataforge.values.Values
+import hep.dataforge.workspace.tasks.SingleActionTask
+import hep.dataforge.workspace.tasks.TaskModel
+import inr.numass.data.api.NumassPoint
+import inr.numass.utils.ExpressionUtils
+import java.util.*
+
+/**
+ * Created by darksnake on 13-Aug-16.
+ */
+class NumassTableFilterTask : SingleActionTask() {
+
+ override fun getName(): String {
+ return "filter"
+ }
+
+ override fun gatherNode(data: DataNode<*>): DataNode {
+ return data.checked(Table::class.java)
+ }
+
+
+ override fun buildModel(model: TaskModel.Builder, meta: Meta) {
+ if (meta.hasMeta("empty")) {
+ model.dependsOn("did", meta)
+ } else {
+ model.dependsOn("transform", meta)
+ }
+ }
+
+ override fun getAction(model: TaskModel): Action {
+ return FilterTableAction()
+ }
+
+ @TypedActionDef(name = "filterTable", inputType = Table::class, outputType = Table::class)
+ private inner class FilterTableAction : OneToOneAction() {
+ override fun execute(context: Context, name: String, input: Table, inputMeta: Laminate): Table {
+ if (inputMeta.hasValue("from") || inputMeta.hasValue("to")) {
+ val uLo = inputMeta.getDouble("from", 0.0)!!
+ val uHi = inputMeta.getDouble("to", java.lang.Double.POSITIVE_INFINITY)!!
+ getLogger(context, inputMeta).debug("Filtering finished")
+ return TableTransform.filter(input, NumassPoint.HV_KEY, uLo, uHi)
+ } else if (inputMeta.hasValue("condition")) {
+ return TableTransform.filter(input) { ExpressionUtils.condition(inputMeta.getString("condition"), unbox(it)) }
+ } else {
+ throw RuntimeException("No filtering condition specified")
+ }
+ }
+ }
+
+ private fun unbox(dp: Values): Map {
+ val res = HashMap()
+ for (field in dp.names) {
+ val value = dp.getValue(field)
+ val obj: Any? = when (value.type) {
+ ValueType.BOOLEAN -> value.booleanValue()
+ ValueType.NUMBER -> value.doubleValue()
+ ValueType.STRING -> value.stringValue()
+ ValueType.TIME -> value.timeValue()
+ ValueType.NULL -> null
+ }
+ res.put(field, obj)
+ }
+ return res
+ }
+}
diff --git a/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt b/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt
index 5dcc229c..d085da08 100644
--- a/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt
+++ b/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt
@@ -5,11 +5,12 @@ import hep.dataforge.data.DataSet
import hep.dataforge.data.DataTree
import hep.dataforge.data.DataUtils
import hep.dataforge.description.ValueDef
-import hep.dataforge.io.ColumnedDataWriter
import hep.dataforge.kodex.configure
import hep.dataforge.kodex.fx.plots.PlotManager
import hep.dataforge.kodex.fx.plots.plus
import hep.dataforge.kodex.task
+import hep.dataforge.meta.Meta
+import hep.dataforge.meta.MetaUtils
import hep.dataforge.plots.PlotFrame
import hep.dataforge.plots.data.DataPlot
import hep.dataforge.plots.jfreechart.JFreeChartFrame
@@ -20,6 +21,7 @@ import hep.dataforge.values.ValueType
import inr.numass.NumassUtils
import inr.numass.actions.MergeDataAction
import inr.numass.actions.MergeDataAction.MERGE_NAME
+import inr.numass.actions.TransformDataAction
import inr.numass.addSetMarkers
import inr.numass.data.analyzers.SmartAnalyzer
import inr.numass.data.api.NumassSet
@@ -89,7 +91,7 @@ val monitorTableTask = task("monitor") {
val analyzeTask = task("analyze") {
model { meta ->
dependsOn("select", meta);
- configure(meta.getMetaOrEmpty("analyzer"))
+ configure(MetaUtils.optEither(meta, "analyzer", "prepare").orElse(Meta.empty()))
}
pipe {
result { set ->
@@ -120,7 +122,7 @@ val mergeEmptyTask = task("empty") {
.removeNode("data")
.removeNode("empty")
.setNode("data", meta.getMeta("empty"))
- .setValue(MERGE_NAME, meta.getString(MERGE_NAME, "") + "_empty");
+ .setValue("merge." + MERGE_NAME, meta.getString("merge." + MERGE_NAME, "") + "_empty");
dependsOn("merge", newMeta)
}
transform { data ->
@@ -138,7 +140,7 @@ val subtractEmptyTask = task("dif") {
dependsOn("merge", meta, "data")
dependsOn("empty", meta, "empty")
}
- transform { data ->
+ transform { data ->
val builder = DataTree.builder(Table::class.java)
val rootNode = data.getCheckedNode("data", Table::class.java)
val empty = data.getCheckedNode("empty", Table::class.java).data
@@ -149,9 +151,9 @@ val subtractEmptyTask = task("dif") {
res.goal.onComplete { r, _ ->
if (r != null) {
- val out = context.io().out("numass.merge", input.name + "_subtract")
- ColumnedDataWriter.writeTable(out, r,
- input.meta().builder.setNode("empty", empty.meta()).toString())
+ context.io().out("numass.merge", input.name + "_subtract").use {
+ NumassUtils.write(it, empty.meta(), r)
+ }
}
}
@@ -159,4 +161,20 @@ val subtractEmptyTask = task("dif") {
})
builder.build()
}
-}
\ No newline at end of file
+}
+
+val transformTask = task("transform") {
+ model { meta ->
+ if (meta.hasMeta("merge")) {
+ if (meta.hasMeta("empty")) {
+ dependsOn("dif", meta)
+ } else {
+ dependsOn("merge", meta);
+ }
+ } else {
+ dependsOn("analyze", meta);
+ }
+ configure(MetaUtils.optEither(meta, "transform", "prepare").orElse(Meta.empty()))
+ }
+ action(TransformDataAction());
+}