From 27312b721f2a42799b7789ee574e7e29d59c8c13 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 10 Aug 2017 11:37:08 +0300 Subject: [PATCH] Numass prepare fixed --- .../inr/numass/actions/MergeDataAction.java | 38 +++++++++---------- .../inr/numass/tasks/NumassPrepareTask.java | 4 ++ 2 files changed, 23 insertions(+), 19 deletions(-) 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 e6f2ac6f..af0ae444 100644 --- a/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java +++ b/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java @@ -25,6 +25,8 @@ import hep.dataforge.meta.Laminate; import hep.dataforge.meta.Meta; import hep.dataforge.tables.*; import hep.dataforge.values.Values; +import inr.numass.data.api.NumassAnalyzer; +import inr.numass.data.api.NumassPoint; import inr.numass.utils.NumassUtils; import java.util.*; @@ -37,7 +39,7 @@ import java.util.*; public class MergeDataAction extends ManyToOneAction { public static final String MERGE_NAME = "mergeName"; - public static String[] parnames = {"Uset", "Uread", "Length", "Total", "Window", "CR", "CRerr"}; + 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") @@ -54,8 +56,8 @@ public class MergeDataAction extends ManyToOneAction { @Override protected Table execute(Context context, String nodeName, Map data, Laminate meta) { - Table res = mergeDataSets(nodeName, data.values()); - return new ListTable(res.getFormat(), TableTransform.sort(res, "Uset", true)); + Table res = mergeDataSets(data.values()); + return new ListTable(res.getFormat(), TableTransform.sort(res, NumassPoint.HV_KEY, true)); } @Override @@ -101,37 +103,37 @@ public class MergeDataAction extends ManyToOneAction { //усредняем измеренное напряжение double Uread = (dp1.getValue(parnames[1]).doubleValue() + dp2.getValue(parnames[1]).doubleValue()) / 2; - double t1 = dp1.getValue("Length").doubleValue(); - double t2 = dp2.getValue("Length").doubleValue(); + double t1 = dp1.getValue(NumassPoint.LENGTH_KEY).doubleValue(); + double t2 = dp2.getValue(NumassPoint.LENGTH_KEY).doubleValue(); double time = t1 + t2; long total = dp1.getValue(parnames[3]).intValue() + dp2.getValue(parnames[3]).intValue(); long wind = dp1.getValue(parnames[4]).intValue() + dp2.getValue(parnames[4]).intValue(); // double corr = dp1.getValue(parnames[5]).doubleValue() + dp2.getValue(parnames[5]).doubleValue(); - double cr1 = dp1.getValue("CR").doubleValue(); - double cr2 = dp2.getValue("CR").doubleValue(); + double cr1 = dp1.getValue(NumassAnalyzer.COUNT_RATE_KEY).doubleValue(); + double cr2 = dp2.getValue(NumassAnalyzer.COUNT_RATE_KEY).doubleValue(); double cr = (cr1 * t1 + cr2 * t2) / (t1 + t2); - double err1 = dp1.getDouble("CRerr"); - double err2 = dp2.getDouble("CRerr"); + double err1 = dp1.getDouble(NumassAnalyzer.COUNT_RATE_ERROR_KEY); + double err2 = dp2.getDouble(NumassAnalyzer.COUNT_RATE_ERROR_KEY); // абсолютные ошибки складываются квадратично double crErr = Math.sqrt(err1 * err1 * t1 * t1 + err2 * err2 * t2 * t2) / time; - ValueMap.Builder map = ValueMap.of(parnames, Uset, Uread, time, total, wind, cr, crErr).builder(); + ValueMap.Builder map = ValueMap.of(parnames, Uset, time, total, cr, crErr).builder(); - if (dp1.getNames().contains("relCR") && dp2.getNames().contains("relCR")) { - double relCR = (dp1.getDouble("relCR") + dp2.getDouble("relCR")) / 2; - map.putValue("relCR", relCR); - map.putValue("relCRerr", crErr * relCR / cr); - } +// if (dp1.getNames().contains("relCR") && dp2.getNames().contains("relCR")) { +// double relCR = (dp1.getDouble("relCR") + dp2.getDouble("relCR")) / 2; +// map.putValue("relCR", relCR); +// map.putValue("relCRerr", crErr * relCR / cr); +// } return map.build(); } - private Table mergeDataSets(String name, Collection ds) { + private Table mergeDataSets(Collection
ds) { //Сливаем все точки в один набор данных Map> points = new LinkedHashMap<>(); for (Table d : ds) { @@ -155,9 +157,7 @@ public class MergeDataAction extends ManyToOneAction { curPoint = mergeDataPoints(curPoint, newPoint); } return curPoint; - }).forEach((curPoint) -> { - res.add(curPoint); - }); + }).forEach(res::add); return new ListTable(MetaTableFormat.forNames(parnames), res); 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 7fef9eef..7562c561 100644 --- a/numass-main/src/main/java/inr/numass/tasks/NumassPrepareTask.java +++ b/numass-main/src/main/java/inr/numass/tasks/NumassPrepareTask.java @@ -6,6 +6,7 @@ package inr.numass.tasks; import hep.dataforge.actions.GenericAction; +import hep.dataforge.cache.CachePlugin; import hep.dataforge.context.Context; import hep.dataforge.data.DataFilter; import hep.dataforge.data.DataNode; @@ -55,6 +56,9 @@ public class NumassPrepareTask extends AbstractTask
{ tables = runAction(new TransformDataAction(), context, tables, prepareMeta); + //intermediate caching + tables = model.getContext().getFeature(CachePlugin.class).cacheNode("prepare", prepareMeta, tables); + if (config.hasMeta("monitor")) { Meta monitorMeta = config.getMeta("monitor"); tables = runAction(new MonitorCorrectAction(), context, tables, monitorMeta);