Summary tasks for numass
This commit is contained in:
parent
3d235662a9
commit
e62716a80f
@ -33,6 +33,8 @@ class NumassWorkspaceSpec extends WorkspaceSpec {
|
|||||||
super.task(NumassFitScanTask)
|
super.task(NumassFitScanTask)
|
||||||
super.task(NumassSubstractEmptySourceTask)
|
super.task(NumassSubstractEmptySourceTask)
|
||||||
super.task(NumassFitScanSummaryTask)
|
super.task(NumassFitScanSummaryTask)
|
||||||
|
super.task(NumassFitTask)
|
||||||
|
super.task(NumassFitSummaryTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ import hep.dataforge.actions.GroupBuilder;
|
|||||||
import hep.dataforge.actions.ManyToOneAction;
|
import hep.dataforge.actions.ManyToOneAction;
|
||||||
import hep.dataforge.data.DataNode;
|
import hep.dataforge.data.DataNode;
|
||||||
import hep.dataforge.description.TypedActionDef;
|
import hep.dataforge.description.TypedActionDef;
|
||||||
|
import hep.dataforge.description.ValueDef;
|
||||||
import hep.dataforge.io.ColumnedDataWriter;
|
import hep.dataforge.io.ColumnedDataWriter;
|
||||||
import hep.dataforge.meta.Meta;
|
import hep.dataforge.meta.Meta;
|
||||||
import hep.dataforge.stat.fit.FitState;
|
import hep.dataforge.stat.fit.FitState;
|
||||||
@ -31,10 +32,10 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Darksnake
|
* @author Darksnake
|
||||||
*/
|
*/
|
||||||
@TypedActionDef(name = "summary", inputType = FitState.class, outputType = Table.class, info = "Generate summary for fit results of different datasets.")
|
@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<FitState, Table> {
|
public class SummaryAction extends ManyToOneAction<FitState, Table> {
|
||||||
|
|
||||||
public static final String SUMMARY_NAME = "sumName";
|
public static final String SUMMARY_NAME = "sumName";
|
||||||
@ -54,7 +55,12 @@ public class SummaryAction extends ManyToOneAction<FitState, Table> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Table execute(String nodeName, Map<String, FitState> input, Meta meta) {
|
protected Table execute(String nodeName, Map<String, FitState> 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];
|
String[] names = new String[2 * parNames.length + 2];
|
||||||
names[0] = "file";
|
names[0] = "file";
|
||||||
for (int i = 0; i < parNames.length; i++) {
|
for (int i = 0; i < parNames.length; i++) {
|
||||||
|
@ -53,7 +53,7 @@ public class NumassFitScanSummaryTask extends AbstractTask<Table> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "numass.fitsum";
|
return "numass.scansum";
|
||||||
}
|
}
|
||||||
|
|
||||||
@TypedActionDef(name = "sterileSummary", inputType = FitState.class, outputType = Table.class)
|
@TypedActionDef(name = "sterileSummary", inputType = FitState.class, outputType = Table.class)
|
||||||
|
@ -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<FitState, Table> {
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "numass.summary";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Action<FitState, Table> getAction(TaskModel model) {
|
||||||
|
return new SummaryAction().withContext(model.getContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected DataNode<FitState> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -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<Table, FitState> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "numass.fit";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected DataNode<Table> 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;
|
||||||
|
}
|
||||||
|
}
|
@ -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<String> arglist = cli.getArgList();
|
|
||||||
|
|
||||||
Workspace workspace = JavaGrindLauncher.buildWorkspace(new File(cfgPath), "inr.numass.NumassWorkspaceSpec");
|
|
||||||
|
|
||||||
if (arglist.size() == 0) {
|
|
||||||
new HelpFormatter().printHelp("launcher [opts] <task name> <meta name / meta>", 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user