Incomplete. Trying to implement one-to-many actions.

This commit is contained in:
Alexander Nozik 2017-01-29 21:48:57 +03:00
parent 068b85c7eb
commit b97ac722ed
16 changed files with 101 additions and 17 deletions

View File

@ -3,7 +3,7 @@ package inr.numass
import hep.dataforge.context.Global
import hep.dataforge.grind.GrindWorkspaceBuilder
import hep.dataforge.grind.terminal.GrindTerminal
import inr.numass.workspace.*
import inr.numass.tasks.*
/**
* Created by darksnake on 29-Aug-16.

View File

@ -2,7 +2,7 @@ package inr.numass.scripts
import hep.dataforge.grind.GrindWorkspaceBuilder
import hep.dataforge.tables.Table
import inr.numass.workspace.*
import inr.numass.tasks.*
/**
* Created by darksnake on 26-Dec-16.

View File

@ -81,7 +81,7 @@ public class NumassPlugin extends BasicPlugin {
ActionManager actions = ActionManager.buildFrom(context);
actions.register(SlicingAction.class);
actions.register(PrepareDataAction.class);
actions.register(ReadNumassDataAction.class);
actions.register(ReadLegacyDataAction.class);
actions.register(MergeDataAction.class);
actions.register(FindBorderAction.class);
actions.register(MonitorCorrectAction.class);

View File

@ -0,0 +1,22 @@
package inr.numass.actions;
import hep.dataforge.actions.OneToOneAction;
import hep.dataforge.context.Context;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.meta.Laminate;
import inr.numass.storage.NumassStorage;
import java.net.URI;
/**
* TODO generalize and move to dataforge-stoage
* Create a Storage from given URI object
* Created by darksnake on 29-Jan-17.
*/
@TypedActionDef(name = "buildStorage", inputType = URI.class, outputType = NumassStorage.class)
public class BuildStorageAction extends OneToOneAction<URI, NumassStorage> {
@Override
protected NumassStorage execute(Context context, String name, URI input, Laminate inputMeta) {
return NumassStorage.buildNumassRoot(input, inputMeta.getBoolean("readOnly", true), inputMeta.getBoolean("monitor", false));
}
}

View File

@ -3,7 +3,7 @@ package inr.numass.actions;
import hep.dataforge.actions.ManyToOneAction;
import hep.dataforge.context.Context;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.meta.Meta;
import hep.dataforge.meta.Laminate;
import inr.numass.storage.NMPoint;
import inr.numass.storage.NumassData;
@ -19,7 +19,7 @@ import java.util.stream.IntStream;
public class JoinNumassDataAction extends ManyToOneAction<NumassData, NumassData> {
@Override
protected NumassData execute(Context context, String nodeName, Map<String, NumassData> input, Meta meta) {
protected NumassData execute(Context context, String nodeName, Map<String, NumassData> input, Laminate meta) {
throw new UnsupportedOperationException("not implemented");
}

View File

@ -22,6 +22,7 @@ import hep.dataforge.data.DataNode;
import hep.dataforge.description.NodeDef;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.io.ColumnedDataWriter;
import hep.dataforge.meta.Laminate;
import hep.dataforge.meta.Meta;
import hep.dataforge.tables.*;
@ -52,7 +53,7 @@ public class MergeDataAction extends ManyToOneAction<Table, Table> {
}
@Override
protected Table execute(Context context, String nodeName, Map<String, Table> data, Meta meta) {
protected Table execute(Context context, String nodeName, Map<String, Table> data, Laminate meta) {
Table res = mergeDataSets(nodeName, data.values());
return new ListTable(res.getFormat(), TableTransform.sort(res, "Uset", true));
}

View File

@ -39,7 +39,7 @@ import static inr.numass.NumassIO.getNumassData;
def = "2.468555393226049", type = "NUMBER")
@ValueDef(name = "noUset", info = "If 'true', then Uset = Uread")
@NodeDef(name = "debunch", target = "class::inr.numass.actions.DebunchAction", info = "If given, governs debunching")
public class ReadNumassDataAction extends OneToOneAction<Binary, NMFile> {
public class ReadLegacyDataAction extends OneToOneAction<Binary, NMFile> {
@Override
protected NMFile execute(Context context, String name, Binary source, Laminate meta) throws ContentException {

View File

@ -0,0 +1,60 @@
package inr.numass.actions;
import hep.dataforge.actions.OneToManyAction;
import hep.dataforge.context.Context;
import hep.dataforge.meta.Laminate;
import hep.dataforge.meta.Meta;
import hep.dataforge.storage.api.Loader;
import inr.numass.debunch.DebunchReport;
import inr.numass.debunch.FrameAnalizer;
import inr.numass.storage.*;
import java.util.Map;
/**
* Created by darksnake on 29-Jan-17.
*/
public class ReadStorageAction extends OneToManyAction<NumassStorage, NumassData> {
@Override
protected Map<String, Meta> prepareMeta(Context context, String inputName, Laminate meta) {
return null;
}
@Override
protected NumassData execute(Context context, String inputName, String outputName, NumassStorage input, Laminate meta) {
try(Loader loader = input.getLoader(outputName)) {
if (loader instanceof NumassDataLoader) {
NumassDataLoader nd = (NumassDataLoader) loader;
return buildData(context, nd, meta);
} else {
throw new RuntimeException("Numass loader expected");
}
} catch (Exception ex){
throw new RuntimeException(ex);
}
}
private NumassData buildData(Context context, NumassDataLoader loader, Meta meta) {
if (meta.hasNode("debunch")) {
return loader.applyRawTransformation(rp -> debunch(context, rp, meta.getMeta("debunch")));
} else {
return loader;
}
}
private NMPoint debunch(Context context, RawNMPoint point, Meta meta) {
int upper = meta.getInt("upperchanel", RawNMPoint.MAX_CHANEL);
int lower = meta.getInt("lowerchanel", 0);
double rejectionprob = meta.getDouble("rejectprob", 1e-10);
double framelength = meta.getDouble("framelength", 1);
double maxCR = meta.getDouble("maxcr", 500d);
double cr = point.selectChanels(lower, upper).getCR();
if (cr < maxCR) {
DebunchReport report = new FrameAnalizer(rejectionprob, framelength, lower, upper).debunchPoint(point);
return new NMPoint(report.getPoint());
} else {
return new NMPoint(point);
}
}
}

View File

@ -22,6 +22,7 @@ import hep.dataforge.data.DataNode;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.description.ValueDef;
import hep.dataforge.io.ColumnedDataWriter;
import hep.dataforge.meta.Laminate;
import hep.dataforge.meta.Meta;
import hep.dataforge.stat.fit.FitState;
import hep.dataforge.tables.*;
@ -55,7 +56,7 @@ public class SummaryAction extends ManyToOneAction<FitState, Table> {
}
@Override
protected Table execute(Context context,String nodeName, Map<String, FitState> input, Meta meta) {
protected Table execute(Context context, String nodeName, Map<String, FitState> input, Laminate meta) {
String[] parNames;
if (meta.hasValue("parnames")) {
parNames = meta.getStringArray("parnames");

View File

@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package inr.numass.workspace;
package inr.numass.tasks;
import hep.dataforge.actions.Action;
import hep.dataforge.actions.ManyToOneAction;
@ -12,7 +12,7 @@ import hep.dataforge.data.DataNode;
import hep.dataforge.data.DataSet;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.io.ColumnedDataWriter;
import hep.dataforge.meta.Meta;
import hep.dataforge.meta.Laminate;
import hep.dataforge.stat.fit.FitState;
import hep.dataforge.stat.fit.ParamSet;
import hep.dataforge.stat.fit.UpperLimitGenerator;
@ -57,7 +57,7 @@ public class NumassFitScanSummaryTask extends AbstractTask<Table> {
private class FitSummaryAction extends ManyToOneAction<FitState, Table> {
@Override
protected Table execute(Context context, String nodeName, Map<String, FitState> input, Meta meta) {
protected Table execute(Context context, String nodeName, Map<String, FitState> input, Laminate meta) {
ListTable.Builder builder = new ListTable.Builder("msterile2", "U2", "U2err", "U2limit", "E0", "trap");
input.forEach((key, fitRes) -> {
ParamSet pars = fitRes.getParameters();

View File

@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package inr.numass.workspace;
package inr.numass.tasks;
import hep.dataforge.actions.Action;
import hep.dataforge.data.DataNode;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package inr.numass.workspace;
package inr.numass.tasks;
import hep.dataforge.actions.Action;
import hep.dataforge.data.DataNode;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package inr.numass.workspace;
package inr.numass.tasks;
import hep.dataforge.actions.Action;
import hep.dataforge.actions.ActionUtils;

View File

@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package inr.numass.workspace;
package inr.numass.tasks;
import hep.dataforge.actions.GenericAction;
import hep.dataforge.context.Context;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package inr.numass.workspace;
package inr.numass.tasks;
import hep.dataforge.data.Data;
import hep.dataforge.data.DataNode;

View File

@ -1,4 +1,4 @@
package inr.numass.workspace;
package inr.numass.tasks;
import hep.dataforge.actions.Action;
import hep.dataforge.actions.OneToOneAction;