From 4433392920ce9a85178039d25b84e12a52b46cc1 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 19 Dec 2016 10:09:26 +0300 Subject: [PATCH] Advanced filters for numass --- .../workspace/NumassTableFilterTask.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/numass-main/src/main/java/inr/numass/workspace/NumassTableFilterTask.java b/numass-main/src/main/java/inr/numass/workspace/NumassTableFilterTask.java index ec39b9c8..75c62128 100644 --- a/numass-main/src/main/java/inr/numass/workspace/NumassTableFilterTask.java +++ b/numass-main/src/main/java/inr/numass/workspace/NumassTableFilterTask.java @@ -10,10 +10,13 @@ import hep.dataforge.meta.MetaBuilder; import hep.dataforge.tables.DataPoint; import hep.dataforge.tables.Table; import hep.dataforge.tables.TableTransform; +import hep.dataforge.values.Value; import hep.dataforge.workspace.SingleActionTask; import hep.dataforge.workspace.TaskModel; import inr.numass.utils.ExpressionUtils; +import java.util.HashMap; +import java.util.Map; import java.util.function.Predicate; /** @@ -57,11 +60,40 @@ public class NumassTableFilterTask extends SingleActionTask { getLogger(inputMeta).debug("Filtering finished"); return TableTransform.filter(input, "Uset", uLo, uHi); } else if (inputMeta.hasValue("filter.condition")) { - Predicate predicate = (dp) -> ExpressionUtils.condition(inputMeta.getString("filter.condition"), dp.asMap()); + Predicate predicate = (dp) -> ExpressionUtils.condition(inputMeta.getString("filter.condition"), unbox(dp)); return TableTransform.filter(input, predicate); } else { throw new RuntimeException("No filtering condition specified"); } } } + + private Map unbox(DataPoint dp) { + Map res = new HashMap<>(); + for (String field : dp.names()) { + Value val = dp.getValue(field); + Object obj; + switch (val.valueType()) { + 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; + } }