diff --git a/numass-main/src/main/groovy/inr/numass/NumassWorkspaceSpec.groovy b/numass-main/src/main/groovy/inr/numass/NumassWorkspaceSpec.groovy index 183d76b5..5a21ff8a 100644 --- a/numass-main/src/main/groovy/inr/numass/NumassWorkspaceSpec.groovy +++ b/numass-main/src/main/groovy/inr/numass/NumassWorkspaceSpec.groovy @@ -33,6 +33,8 @@ class NumassWorkspaceSpec extends WorkspaceSpec { super.task(NumassFitScanTask) super.task(NumassSubstractEmptySourceTask) super.task(NumassFitScanSummaryTask) + super.task(NumassFitTask) + super.task(NumassFitSummaryTask) } 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 6180e4f6..e3ae86b3 100644 --- a/numass-main/src/main/java/inr/numass/actions/SummaryAction.java +++ b/numass-main/src/main/java/inr/numass/actions/SummaryAction.java @@ -19,6 +19,7 @@ import hep.dataforge.actions.GroupBuilder; import hep.dataforge.actions.ManyToOneAction; import hep.dataforge.data.DataNode; import hep.dataforge.description.TypedActionDef; +import hep.dataforge.description.ValueDef; import hep.dataforge.io.ColumnedDataWriter; import hep.dataforge.meta.Meta; import hep.dataforge.stat.fit.FitState; @@ -31,10 +32,10 @@ import java.util.List; import java.util.Map; /** - * * @author Darksnake */ @TypedActionDef(name = "summary", inputType = FitState.class, outputType = Table.class, info = "Generate summary for fit results of different datasets.") +@ValueDef(name = "parnames", multiple = true, required = true, info = "List of names of parameters for which summary should be done") public class SummaryAction extends ManyToOneAction { public static final String SUMMARY_NAME = "sumName"; @@ -54,7 +55,12 @@ public class SummaryAction extends ManyToOneAction { @Override protected Table execute(String nodeName, Map input, Meta meta) { - String[] parNames = meta.getStringArray("parnames"); + String[] parNames; + if (meta.hasValue("parnames")) { + parNames = meta.getStringArray("parnames"); + } else { + throw new RuntimeException("Infering parnames not suppoerted"); + } String[] names = new String[2 * parNames.length + 2]; names[0] = "file"; for (int i = 0; i < parNames.length; i++) { diff --git a/numass-main/src/main/java/inr/numass/workspace/NumassFitScanSummaryTask.java b/numass-main/src/main/java/inr/numass/workspace/NumassFitScanSummaryTask.java index e1a15218..54f7b29e 100644 --- a/numass-main/src/main/java/inr/numass/workspace/NumassFitScanSummaryTask.java +++ b/numass-main/src/main/java/inr/numass/workspace/NumassFitScanSummaryTask.java @@ -53,7 +53,7 @@ public class NumassFitScanSummaryTask extends AbstractTask { @Override public String getName() { - return "numass.fitsum"; + return "numass.scansum"; } @TypedActionDef(name = "sterileSummary", inputType = FitState.class, outputType = Table.class) diff --git a/numass-main/src/main/java/inr/numass/workspace/NumassFitSummaryTask.java b/numass-main/src/main/java/inr/numass/workspace/NumassFitSummaryTask.java new file mode 100644 index 00000000..60d5f77f --- /dev/null +++ b/numass-main/src/main/java/inr/numass/workspace/NumassFitSummaryTask.java @@ -0,0 +1,62 @@ +/* + * 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.workspace; + +import hep.dataforge.actions.Action; +import hep.dataforge.data.DataNode; +import hep.dataforge.meta.Meta; +import hep.dataforge.meta.MetaBuilder; +import hep.dataforge.stat.fit.FitState; +import hep.dataforge.tables.Table; +import hep.dataforge.workspace.SingleActionTask; +import hep.dataforge.workspace.TaskModel; +import inr.numass.actions.SummaryAction; + +/** + * Created by darksnake on 16-Sep-16. + */ +public class NumassFitSummaryTask extends SingleActionTask { + @Override + public String getName() { + return "numass.summary"; + } + + @Override + protected Action getAction(TaskModel model) { + return new SummaryAction().withContext(model.getContext()); + } + + @Override + protected DataNode gatherNode(DataNode data) { + return data.getCheckedNode("fit", FitState.class); + } + + @Override + protected Meta transformMeta(TaskModel model) { + return model.meta().getNode("summary"); + } + + @Override + protected TaskModel transformModel(TaskModel model) { + //Transmit meta as-is + MetaBuilder meta = model.meta().getBuilder().removeNode("summary"); + model.dependsOn("numass.fit", meta.build(), "fit"); + return model; + } + + +} diff --git a/numass-main/src/main/java/inr/numass/workspace/NumassFitTask.java b/numass-main/src/main/java/inr/numass/workspace/NumassFitTask.java new file mode 100644 index 00000000..e594e2ad --- /dev/null +++ b/numass-main/src/main/java/inr/numass/workspace/NumassFitTask.java @@ -0,0 +1,72 @@ +/* + * 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.workspace; + +import hep.dataforge.actions.Action; +import hep.dataforge.data.DataNode; +import hep.dataforge.meta.Meta; +import hep.dataforge.meta.MetaBuilder; +import hep.dataforge.stat.fit.FitAction; +import hep.dataforge.stat.fit.FitState; +import hep.dataforge.tables.Table; +import hep.dataforge.workspace.SingleActionTask; +import hep.dataforge.workspace.TaskModel; + +/** + * Created by darksnake on 16-Sep-16. + */ +public class NumassFitTask extends SingleActionTask { + + @Override + public String getName() { + return "numass.fit"; + } + + @Override + protected DataNode
gatherNode(DataNode data) { + return data.getCheckedNode("prepare", Table.class); + } + + @Override + public void validate(TaskModel model) { + if (!model.meta().hasNode("fit")) { + throw new RuntimeException("Fit element not found in model"); + } + } + + @Override + protected Action getAction(TaskModel model) { + return new FitAction().withContext(model.getContext()); + } + + @Override + protected Meta transformMeta(TaskModel model) { + return model.meta().getNode("fit"); + } + + @Override + protected TaskModel transformModel(TaskModel model) { + //Transmit meta as-is + MetaBuilder metaBuilder = new MetaBuilder(model.meta()).removeNode("fit"); + if (model.meta().hasNode("filter")) { + model.dependsOn("numass.filter", metaBuilder.build(), "prepare"); + } else { + model.dependsOn("numass.prepare", metaBuilder.build(), "prepare"); + } + return model; + } +} diff --git a/numass-main/src/main/java/inr/numass/workspace/NumassJavaGrindLauncher.java b/numass-main/src/main/java/inr/numass/workspace/NumassJavaGrindLauncher.java deleted file mode 100644 index b9b9571a..00000000 --- a/numass-main/src/main/java/inr/numass/workspace/NumassJavaGrindLauncher.java +++ /dev/null @@ -1,62 +0,0 @@ -package inr.numass.workspace; - -import hep.dataforge.context.GlobalContext; -import hep.dataforge.data.DataNode; -import hep.dataforge.grind.JavaGrindLauncher; -import hep.dataforge.meta.Meta; -import hep.dataforge.workspace.Workspace; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.HelpFormatter; -import org.apache.commons.cli.Options; - -import java.io.File; -import java.util.List; -import java.util.stream.Collectors; - -/** - * Created by darksnake on 12-Aug-16. - */ -@Deprecated -public class NumassJavaGrindLauncher { - - public static void main(String[] args) throws Exception { - Options options = new Options(); - options.addOption("c", "config", true, "Configuration file for workspace"); - options.addOption("o", "overlay", false, "If meta with the same name as parameter exist in the workspace, use it as lower layer"); - - CommandLine cli = new DefaultParser().parse(options, args); - - String cfgPath = cli.getOptionValue('c', "workspace.groovy"); - - List arglist = cli.getArgList(); - - Workspace workspace = JavaGrindLauncher.buildWorkspace(new File(cfgPath), "inr.numass.NumassWorkspaceSpec"); - - if (arglist.size() == 0) { - new HelpFormatter().printHelp("launcher [opts] ", options); - return; - } else if (arglist.size() == 1) { - String taskName = arglist.get(0); - workspace.runTask(taskName, taskName); - } else { - String taskName = arglist.get(0); - String theRest = arglist.stream().skip(1).collect(Collectors.joining()); - DataNode node; - if (theRest.contains("{") || theRest.contains("(")) { - Meta meta = JavaGrindLauncher.buildMeta(theRest); - boolean overlay = cli.hasOption("o"); - node = workspace.runTask(taskName, meta, overlay); - } else { - node = workspace.runTask(taskName, theRest); - } - - node.computeAll(); - GlobalContext.instance().close(); - } -// -// JavaGrindLauncher.buildWorkspace(new File(cfgPath), NumassWorkspaceSpec.class) -// .runTask("numass.fitsum", "sum").computeAll(); - } - -}