Refactoring
This commit is contained in:
parent
03af27d357
commit
f174440cd3
@ -95,8 +95,8 @@ public class PKT8App extends Application {
|
||||
device = setupDevice(deviceName, config);
|
||||
|
||||
// setting up storage connections
|
||||
if (config.hasNode("storage")) {
|
||||
config.getNodes("storage").forEach(node -> {
|
||||
if (config.hasMeta("storage")) {
|
||||
config.getMetaList("storage").forEach(node -> {
|
||||
Storage storage = StorageFactory.buildStorage(device.getContext(), node);
|
||||
if(config.hasValue("numass.run")){
|
||||
try {
|
||||
@ -148,7 +148,7 @@ public class PKT8App extends Application {
|
||||
public PKT8Device setupDevice(String deviceName, Meta config) throws ControlException {
|
||||
Meta deviceMeta;
|
||||
|
||||
if (config.hasNode("device")) {
|
||||
if (config.hasMeta("device")) {
|
||||
deviceMeta = MetaUtils.findNodeByValue(config, "device", "name", deviceName);
|
||||
} else {
|
||||
deviceMeta = config;
|
||||
|
@ -69,8 +69,8 @@ public class PKT8Device extends PortSensor<PKT8Result> {
|
||||
public void init() throws ControlException {
|
||||
|
||||
//read channel configuration
|
||||
if (meta().hasNode("channel")) {
|
||||
for (Meta node : meta().getNodes("channel")) {
|
||||
if (meta().hasMeta("channel")) {
|
||||
for (Meta node : meta().getMetaList("channel")) {
|
||||
String designation = node.getString("designation", "default");
|
||||
this.channels.put(designation, new PKT8Channel(node));
|
||||
}
|
||||
|
@ -80,13 +80,13 @@ public class PKT8PlotController implements Initializable, MeasurementListener<PK
|
||||
}
|
||||
|
||||
public void configure(Meta config) {
|
||||
if (config.hasNode("plotConfig")) {
|
||||
if (config.hasMeta("plotConfig")) {
|
||||
Meta plotConfig = MetaUtils.findNodeByValue(config, "plotConfig", "device", getDeviceName());
|
||||
if (plotConfig == null) {
|
||||
plotConfig = config.getNode("plotConfig");
|
||||
plotConfig = config.getMeta("plotConfig");
|
||||
}
|
||||
|
||||
setupPlotFrame(plotConfig.getNode("plotFrame", Meta.empty()));
|
||||
setupPlotFrame(plotConfig.getMeta("plotFrame", Meta.empty()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ public class PKT8PlotController implements Initializable, MeasurementListener<PK
|
||||
.forEach(channel -> {
|
||||
|
||||
//plot config from device configuration
|
||||
Meta deviceLineMeta = channel.meta().getNode("plot", channel.meta());
|
||||
Meta deviceLineMeta = channel.meta().getMeta("plot", channel.meta());
|
||||
|
||||
//Do not use view config here, it is applyed separately
|
||||
TimePlottable plottable = new TimePlottable(channel.getName());
|
||||
|
@ -89,7 +89,7 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po
|
||||
protected Meta getMetaForMeasurement(String name) {
|
||||
switch (name) {
|
||||
case "peakJump":
|
||||
return meta().getNode("peakJump");
|
||||
return meta().getMeta("peakJump");
|
||||
default:
|
||||
return super.getMetaForMeasurement(name);
|
||||
}
|
||||
@ -427,7 +427,7 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po
|
||||
sendAndWait("MeasurementRemove", name);
|
||||
if (sendAndWait("AddPeakJump", name, filterMode, accuracy, 0, 0, 0).isOK()) {
|
||||
peakMap = new LinkedHashMap<>();
|
||||
for (Meta peak : meta.getNodes("peak")) {
|
||||
for (Meta peak : meta.getMetaList("peak")) {
|
||||
peakMap.put(peak.getInt("mass"), peak.getString("name", peak.getString("mass")));
|
||||
if (!sendAndWait("MeasurementAddMass", peak.getString("mass")).isOK()) {
|
||||
throw new ControlException("Can't add mass to measurement measurement for msp");
|
||||
|
@ -152,7 +152,7 @@ public class MspViewController implements Initializable, MspListener {
|
||||
|
||||
public Configuration getViewConfig() {
|
||||
if (viewConfig == null) {
|
||||
viewConfig = new Configuration(getDevice().meta().getNode("peakJump"));
|
||||
viewConfig = new Configuration(getDevice().meta().getMeta("peakJump"));
|
||||
viewConfig.addObserver(viewConfigObserver);
|
||||
LoggerFactory.getLogger(getClass()).warn("Could not find view configuration. Using default view configuration instead.");
|
||||
}
|
||||
@ -181,14 +181,14 @@ public class MspViewController implements Initializable, MspListener {
|
||||
|
||||
public void setDeviceConfig(Context context, Meta config) {
|
||||
Meta mspConfig = null;
|
||||
if (config.hasNode("device")) {
|
||||
for (Meta d : config.getNodes("device")) {
|
||||
if (config.hasMeta("device")) {
|
||||
for (Meta d : config.getMetaList("device")) {
|
||||
if (d.getString("type", "unknown").equals(MSP_DEVICE_TYPE)
|
||||
&& d.getString("name", "msp").equals(this.mspName)) {
|
||||
mspConfig = d;
|
||||
}
|
||||
}
|
||||
} else if (config.hasNode("peakJump")) {
|
||||
} else if (config.hasMeta("peakJump")) {
|
||||
mspConfig = config;
|
||||
}
|
||||
|
||||
@ -213,8 +213,8 @@ public class MspViewController implements Initializable, MspListener {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
if (config.hasNode("plots.msp")) {
|
||||
setViewConfig(config.getNode("plots.msp"));
|
||||
if (config.hasMeta("plots.msp")) {
|
||||
setViewConfig(config.getMeta("plots.msp"));
|
||||
}
|
||||
|
||||
updatePlot();
|
||||
@ -251,11 +251,11 @@ public class MspViewController implements Initializable, MspListener {
|
||||
initPlot();
|
||||
}
|
||||
Meta config = getViewConfig();
|
||||
if (config.hasNode("plotFrame")) {
|
||||
this.plot.configure(config.getNode("plotFrame"));
|
||||
if (config.hasMeta("plotFrame")) {
|
||||
this.plot.configure(config.getMeta("plotFrame"));
|
||||
}
|
||||
if (config.hasNode("peakJump.line")) {
|
||||
for (Meta an : config.getNodes("peakJump.line")) {
|
||||
if (config.hasMeta("peakJump.line")) {
|
||||
for (Meta an : config.getMetaList("peakJump.line")) {
|
||||
String mass = an.getString("mass");
|
||||
|
||||
if (!this.plottables.hasPlottable(mass)) {
|
||||
@ -363,7 +363,7 @@ public class MspViewController implements Initializable, MspListener {
|
||||
private void onStoreButtonClick(ActionEvent event) {
|
||||
if (storeButton.isSelected()) {
|
||||
|
||||
if (!device.meta().hasNode("storage")) {
|
||||
if (!device.meta().hasMeta("storage")) {
|
||||
device.getLogger().info("Storage not defined. Starting storage selection dialog");
|
||||
DirectoryChooser chooser = new DirectoryChooser();
|
||||
File storageDir = chooser.showDialog(this.plotPane.getScene().getWindow());
|
||||
@ -374,13 +374,13 @@ public class MspViewController implements Initializable, MspListener {
|
||||
device.getConfig().putNode(new MetaBuilder("storage")
|
||||
.putValue("path", storageDir.getAbsolutePath()));
|
||||
}
|
||||
Meta storageConfig = device.meta().getNode("storage");
|
||||
Meta storageConfig = device.meta().getMeta("storage");
|
||||
Storage localStorage = StorageManager.buildFrom(device.getContext())
|
||||
.buildStorage(storageConfig);
|
||||
|
||||
String runName = device.meta().getString("numass.run", "");
|
||||
Meta meta = device.meta();
|
||||
if (meta.hasNode("numass")) {
|
||||
if (meta.hasMeta("numass")) {
|
||||
try {
|
||||
device.getLogger().info("Obtaining run information from cetral server...");
|
||||
NumassClient client = new NumassClient(meta.getString("numass.ip", "192.168.111.1"),
|
||||
|
@ -15,13 +15,8 @@ import hep.dataforge.storage.commons.LoaderFactory;
|
||||
import hep.dataforge.tables.TableFormatBuilder;
|
||||
import hep.dataforge.values.ValueType;
|
||||
import inr.numass.client.NumassClient;
|
||||
import inr.numass.readvac.devices.CM32Device;
|
||||
import inr.numass.readvac.devices.MKSBaratronDevice;
|
||||
import inr.numass.readvac.devices.MKSVacDevice;
|
||||
import inr.numass.readvac.devices.VITVacDevice;
|
||||
import inr.numass.readvac.devices.VacCollectorDevice;
|
||||
import inr.numass.readvac.devices.*;
|
||||
import inr.numass.readvac.fx.VacCollectorController;
|
||||
import java.io.File;
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
@ -29,6 +24,8 @@ import javafx.stage.Stage;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexander Nozik
|
||||
@ -53,19 +50,19 @@ public class ReadVac extends Application {
|
||||
}
|
||||
|
||||
Sensor<Double> p1 = new MKSVacDevice(config.getString("p1.port", "com::/dev/ttyUSB0"));
|
||||
p1.configure(config.getNode("p1", Meta.empty()));
|
||||
p1.configure(config.getMeta("p1", Meta.empty()));
|
||||
p1.setName(config.getString("p1.name", "P1"));
|
||||
Sensor<Double> p2 = new CM32Device(config.getString("p2.port", "tcp::192.168.111.32:4002"));
|
||||
p2.configure(config.getNode("p2", Meta.empty()));
|
||||
p2.configure(config.getMeta("p2", Meta.empty()));
|
||||
p2.setName(config.getString("p2.name", "P2"));
|
||||
Sensor<Double> p3 = new CM32Device(config.getString("p3.port", "tcp::192.168.111.32:4003"));
|
||||
p3.configure(config.getNode("p3", Meta.empty()));
|
||||
p3.configure(config.getMeta("p3", Meta.empty()));
|
||||
p3.setName(config.getString("p3.name", "P3"));
|
||||
Sensor<Double> px = new VITVacDevice(config.getString("px.port", "com::/dev/ttyUSB1"));
|
||||
px.configure(config.getNode("px", Meta.empty()));
|
||||
px.configure(config.getMeta("px", Meta.empty()));
|
||||
px.setName(config.getString("px.name", "Px"));
|
||||
Sensor<Double> baratron = new MKSBaratronDevice(config.getString("baratron.port", "tcp::192.168.111.33:4004"));
|
||||
baratron.configure(config.getNode("baratron", Meta.empty()));
|
||||
baratron.configure(config.getMeta("baratron", Meta.empty()));
|
||||
baratron.setName(config.getString("baratron.name", "Baratron"));
|
||||
|
||||
VacCollectorDevice collector = new VacCollectorDevice();
|
||||
@ -82,7 +79,7 @@ public class ReadVac extends Application {
|
||||
controller.setLoaderFactory((VacCollectorDevice device, Storage localStorage) -> {
|
||||
try {
|
||||
String runName = device.meta().getString("numass.run", "");
|
||||
if (config.hasNode("numass")) {
|
||||
if (config.hasMeta("numass")) {
|
||||
try {
|
||||
logger.info("Obtaining run information from cetral server...");
|
||||
NumassClient client = new NumassClient(config.getString("numass.ip", "192.168.111.1"),
|
||||
|
@ -232,7 +232,7 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
|
||||
private void onStoreToggle(ActionEvent event) {
|
||||
if (storeButton.isSelected()) {
|
||||
//creating storage on UI thread
|
||||
if (!device.meta().hasNode("storage")) {
|
||||
if (!device.meta().hasMeta("storage")) {
|
||||
getLogger().info("Storage not defined. Starting storage selection dialog");
|
||||
DirectoryChooser chooser = new DirectoryChooser();
|
||||
File storageDir = chooser.showDialog(plotHolder.getScene().getWindow());
|
||||
@ -243,7 +243,7 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
|
||||
device.getConfig().putNode(new MetaBuilder("storage")
|
||||
.putValue("path", storageDir.getAbsolutePath()));
|
||||
}
|
||||
Meta storageConfig = device.meta().getNode("storage");
|
||||
Meta storageConfig = device.meta().getMeta("storage");
|
||||
Storage localStorage = StorageManager.buildFrom(device.getContext())
|
||||
.buildStorage(storageConfig);
|
||||
//Start storage creation on non-UI thread
|
||||
|
@ -54,8 +54,8 @@ public class PlotFitResultAction extends OneToOneAction<FitState, FitState> {
|
||||
XYModel model = (XYModel) input.getModel();
|
||||
|
||||
XYAdapter adapter;
|
||||
if (metaData.hasNode("adapter")) {
|
||||
adapter = new XYAdapter(metaData.getNode("adapter"));
|
||||
if (metaData.hasMeta("adapter")) {
|
||||
adapter = new XYAdapter(metaData.getMeta("adapter"));
|
||||
} else if (input.getModel() instanceof XYModel) {
|
||||
adapter = model.getAdapter();
|
||||
} else {
|
||||
@ -66,7 +66,7 @@ public class PlotFitResultAction extends OneToOneAction<FitState, FitState> {
|
||||
|
||||
XYPlotFrame frame = (XYPlotFrame) PlotsPlugin
|
||||
.buildFrom(getContext()).buildPlotFrame(getName(), name,
|
||||
metaData.getNode("plot", Meta.empty()));
|
||||
metaData.getMeta("plot", Meta.empty()));
|
||||
|
||||
PlottableXYFunction fit = new PlottableXYFunction("fit");
|
||||
fit.setDensity(100, false);
|
||||
|
@ -259,8 +259,8 @@ public class NumassPlugin extends BasicPlugin {
|
||||
|
||||
return TransmissionInterpolator
|
||||
.fromFile(context, transmissionFile, transXName, transYName, nSmooth, w, stitchBorder);
|
||||
} else if (an.hasNode("transBuildAction")) {
|
||||
Meta transBuild = an.getNode("transBuildAction");
|
||||
} else if (an.hasMeta("transBuildAction")) {
|
||||
Meta transBuild = an.getMeta("transBuildAction");
|
||||
try {
|
||||
return TransmissionInterpolator.fromAction((Context) context,
|
||||
transBuild, transXName, transYName, nSmooth, w, stitchBorder);
|
||||
@ -273,8 +273,8 @@ public class NumassPlugin extends BasicPlugin {
|
||||
}
|
||||
|
||||
private XYAdapter getAdapter(Meta an) {
|
||||
if (an.hasNode(PointAdapter.DATA_ADAPTER_KEY)) {
|
||||
return new XYAdapter(an.getNode(PointAdapter.DATA_ADAPTER_KEY));
|
||||
if (an.hasMeta(PointAdapter.DATA_ADAPTER_KEY)) {
|
||||
return new XYAdapter(an.getMeta(PointAdapter.DATA_ADAPTER_KEY));
|
||||
} else {
|
||||
return new XYAdapter("Uread", "CR", "CRerr");
|
||||
}
|
||||
|
@ -36,16 +36,16 @@ public class AdjustErrorsAction extends OneToOneAction<Table, Table> {
|
||||
}
|
||||
|
||||
private DataPoint evalPoint(Meta meta, DataPoint dp) {
|
||||
if (meta.hasNode("point")) {
|
||||
for (Meta pointMeta : meta.getNodes("point")) {
|
||||
if (meta.hasMeta("point")) {
|
||||
for (Meta pointMeta : meta.getMetaList("point")) {
|
||||
if (pointMeta.getDouble("Uset") == dp.getDouble("Uset")) {
|
||||
return adjust(dp, pointMeta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (meta.hasNode("range")) {
|
||||
for (Meta rangeMeta : meta.getNodes("range")) {
|
||||
if (meta.hasMeta("range")) {
|
||||
for (Meta rangeMeta : meta.getMetaList("range")) {
|
||||
double from = rangeMeta.getDouble("from", 0);
|
||||
double to = rangeMeta.getDouble("to", Double.POSITIVE_INFINITY);
|
||||
double u = rangeMeta.getDouble("Uset");
|
||||
@ -55,8 +55,8 @@ public class AdjustErrorsAction extends OneToOneAction<Table, Table> {
|
||||
}
|
||||
}
|
||||
|
||||
if (meta.hasNode("all")) {
|
||||
return adjust(dp, meta.getNode("all"));
|
||||
if (meta.hasMeta("all")) {
|
||||
return adjust(dp, meta.getMeta("all"));
|
||||
}
|
||||
|
||||
return dp;
|
||||
|
@ -147,8 +147,8 @@ public class PrepareDataAction extends OneToOneAction<NumassData, Table> {
|
||||
if (meta.hasValue("correction")) {
|
||||
// log.report("Using correction from formula: {}", meta.getString("correction"));
|
||||
return evaluateExpression(point, meta.getString("correction"));
|
||||
} else if (meta.hasNode("underflow")) {
|
||||
return new UnderflowCorrection().get(log, meta.getNode("underflow"), point);
|
||||
} else if (meta.hasMeta("underflow")) {
|
||||
return new UnderflowCorrection().get(log, meta.getMeta("underflow"), point);
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public class ReadNumassDataAction extends OneToOneAction<Binary, NMFile> {
|
||||
|
||||
if (meta.getNodeNames(false).contains("debunch")) {
|
||||
DebunchAction debunch = new DebunchAction();
|
||||
Laminate laminate = new Laminate(meta.getNode("debunch"))
|
||||
Laminate laminate = new Laminate(meta.getMeta("debunch"))
|
||||
.setValueContext(getContext())
|
||||
.setDescriptor(debunch.getDescriptor());
|
||||
raw = debunch.execute(name, laminate, raw);
|
||||
|
@ -80,10 +80,10 @@ public class ShowEnergySpectrumAction extends OneToOneAction<NumassData, Table>
|
||||
|
||||
ColumnedDataWriter.writeDataSet(out, table, inputMeta.toString());
|
||||
|
||||
if (inputMeta.hasNode("plot") || inputMeta.getBoolean("plot", false)) {
|
||||
if (inputMeta.hasMeta("plot") || inputMeta.getBoolean("plot", false)) {
|
||||
XYPlotFrame frame = (XYPlotFrame) PlotsPlugin
|
||||
.buildFrom(getContext()).buildPlotFrame(getName(), name,
|
||||
inputMeta.getNode("plot", Meta.empty()));
|
||||
inputMeta.getMeta("plot", Meta.empty()));
|
||||
fillDetectorData(valueMap).forEach(frame::add);
|
||||
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ public class SlicingAction extends OneToOneAction<NMFile, NMFile> {
|
||||
Map<String, Pair<Integer, Integer>> slicingConfig;
|
||||
|
||||
LinkedHashMap<String, Pair<Integer, Integer>> res = new LinkedHashMap<>();
|
||||
List<? extends Meta> list = meta.getNode("sliceconfig").getNodes("slicepoint");
|
||||
List<? extends Meta> list = meta.getMeta("sliceconfig").getMetaList("slicepoint");
|
||||
|
||||
for (Meta slice : list) {
|
||||
String title = slice.getString("title", slice.getName());
|
||||
|
@ -73,7 +73,7 @@ public class SterileNeutrinoSpectrum extends AbstractParametricFunction {
|
||||
}
|
||||
|
||||
transmission = new NumassTransmission(context, configuration.getNodeOrEmpty("transmission"));
|
||||
resolution = new NumassResolution(configuration.getNode("resolution", Meta.empty()));
|
||||
resolution = new NumassResolution(configuration.getMeta("resolution", Meta.empty()));
|
||||
this.fast = configuration.getBoolean("fast", true);
|
||||
transRes = new TransRes();
|
||||
}
|
||||
|
@ -236,8 +236,8 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
|
||||
buildContext(config);
|
||||
|
||||
//loading data configuration
|
||||
if (config.hasNode("data")) {
|
||||
dataConfig = new Configuration(config.getNode("data"));
|
||||
if (config.hasMeta("data")) {
|
||||
dataConfig = new Configuration(config.getMeta("data"));
|
||||
//replacing file name value with appropriate nodes
|
||||
if (dataConfig.hasValue("file")) {
|
||||
Value fileValue = dataConfig.getValue("file");
|
||||
@ -258,7 +258,7 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
|
||||
//loading actions configuration
|
||||
actionsConfig = new Configuration("actionlist");
|
||||
|
||||
List<Configuration> actions = config.getNodes("action").stream()
|
||||
List<Configuration> actions = config.getMetaList("action").stream()
|
||||
.<Configuration>map(m -> new Configuration(m)).collect(Collectors.toList());
|
||||
|
||||
actionsConfig.attachNodeItem("action", actions);
|
||||
|
@ -33,7 +33,7 @@ public class NumassFitScanTask extends AbstractTask<FitState> {
|
||||
DataTree.Builder<FitState> resultBuilder = DataTree.builder(FitState.class);
|
||||
DataNode<Table> sourceNode = data.getCheckedNode("prepare", Table.class);
|
||||
|
||||
if (config.hasNode("merge")) {
|
||||
if (config.hasMeta("merge")) {
|
||||
//use merged data and ignore raw data
|
||||
sourceNode = sourceNode.getCheckedNode("merge", Table.class);
|
||||
}
|
||||
@ -47,10 +47,10 @@ public class NumassFitScanTask extends AbstractTask<FitState> {
|
||||
MetaBuilder overrideMeta = new MetaBuilder(fitConfig);
|
||||
overrideMeta.setValue("@resultName", String.format("%s[%s=%s]", d.getName(), scanParameter, val.stringValue()));
|
||||
|
||||
if (overrideMeta.hasNode("params." + scanParameter)) {
|
||||
if (overrideMeta.hasMeta("params." + scanParameter)) {
|
||||
overrideMeta.setValue("params." + scanParameter + ".value", val);
|
||||
} else {
|
||||
overrideMeta.getNodes("params.param").stream()
|
||||
overrideMeta.getMetaList("params.param").stream()
|
||||
.filter(par -> par.getString("name") == scanParameter).forEach(par -> par.setValue("value", val));
|
||||
}
|
||||
// Data<Table> newData = new Data<Table>(data.getGoal(),data.type(),overrideMeta);
|
||||
@ -67,7 +67,7 @@ public class NumassFitScanTask extends AbstractTask<FitState> {
|
||||
protected TaskModel transformModel(TaskModel model) {
|
||||
//Transmit meta as-is
|
||||
MetaBuilder metaBuilder = new MetaBuilder(model.meta()).removeNode("fit");
|
||||
if (model.meta().hasNode("filter")) {
|
||||
if (model.meta().hasMeta("filter")) {
|
||||
model.dependsOn("numass.filter", metaBuilder.build(), "prepare");
|
||||
} else {
|
||||
model.dependsOn("numass.prepare", metaBuilder.build(), "prepare");
|
||||
|
@ -47,7 +47,7 @@ public class NumassFitSummaryTask extends SingleActionTask<FitState, Table> {
|
||||
|
||||
@Override
|
||||
protected Meta transformMeta(TaskModel model) {
|
||||
return model.meta().getNode("summary");
|
||||
return model.meta().getMeta("summary");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -43,7 +43,7 @@ public class NumassFitTask extends SingleActionTask<Table, FitState> {
|
||||
|
||||
@Override
|
||||
public void validate(TaskModel model) {
|
||||
if (!model.meta().hasNode("fit")) {
|
||||
if (!model.meta().hasMeta("fit")) {
|
||||
throw new RuntimeException("Fit element not found in model");
|
||||
}
|
||||
}
|
||||
@ -55,14 +55,14 @@ public class NumassFitTask extends SingleActionTask<Table, FitState> {
|
||||
|
||||
@Override
|
||||
protected Meta transformMeta(TaskModel model) {
|
||||
return model.meta().getNode("fit");
|
||||
return model.meta().getMeta("fit");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TaskModel transformModel(TaskModel model) {
|
||||
//Transmit meta as-is
|
||||
MetaBuilder metaBuilder = new MetaBuilder(model.meta()).removeNode("fit");
|
||||
if (model.meta().hasNode("filter")) {
|
||||
if (model.meta().hasMeta("filter")) {
|
||||
model.dependsOn("numass.filter", metaBuilder.build(), "prepare");
|
||||
} else {
|
||||
model.dependsOn("numass.prepare", metaBuilder.build(), "prepare");
|
||||
|
@ -57,38 +57,38 @@ public class NumassPrepareTask extends AbstractTask<Table> {
|
||||
Context context = model.getContext();
|
||||
|
||||
//acquiring initial data. Data node could not be empty
|
||||
Meta dataMeta = config.getNode("data");
|
||||
Meta dataMeta = config.getMeta("data");
|
||||
URI storageUri = input.getCheckedData("dataRoot", URI.class).get();
|
||||
DataSet.Builder<NumassData> dataBuilder = readData(callback, context, storageUri, dataMeta);
|
||||
if (config.hasNode("empty")) {
|
||||
dataBuilder.putNode("empty", readData(callback, context, storageUri, config.getNode("empty")).build());
|
||||
if (config.hasMeta("empty")) {
|
||||
dataBuilder.putNode("empty", readData(callback, context, storageUri, config.getMeta("empty")).build());
|
||||
}
|
||||
|
||||
DataNode<NumassData> data = dataBuilder.build();
|
||||
|
||||
//preparing table data
|
||||
Meta prepareMeta = config.getNode("prepare");
|
||||
Meta prepareMeta = config.getMeta("prepare");
|
||||
DataNode<Table> tables = runAction(new PrepareDataAction(), callback, context, data, prepareMeta);
|
||||
|
||||
if (config.hasNode("monitor")) {
|
||||
Meta monitorMeta = config.getNode("monitor");
|
||||
if (config.hasMeta("monitor")) {
|
||||
Meta monitorMeta = config.getMeta("monitor");
|
||||
tables = runAction(new MonitorCorrectAction(), callback, context, tables, monitorMeta);
|
||||
}
|
||||
|
||||
//merging if needed
|
||||
if (config.hasNode("merge")) {
|
||||
if (config.hasMeta("merge")) {
|
||||
DataTree.Builder<Table> resultBuilder = DataTree.builder(Table.class);
|
||||
DataTree.Builder<Table> tablesForMerge = new DataTree.Builder<>(tables);
|
||||
|
||||
//extracting empty data
|
||||
if (config.hasNode("empty")) {
|
||||
if (config.hasMeta("empty")) {
|
||||
DataNode<Table> emptySourceNode = tables.getCheckedNode("empty", Table.class);
|
||||
Meta emptyMergeMeta = new MetaBuilder("emptySource").setValue("mergeName", "emptySource");
|
||||
resultBuilder.putData("merge.empty", runAction(new MergeDataAction(), callback, context, emptySourceNode, emptyMergeMeta).getData());
|
||||
tablesForMerge.removeNode("empty");
|
||||
}
|
||||
|
||||
config.getNodes("merge").forEach(mergeNode -> {
|
||||
config.getMetaList("merge").forEach(mergeNode -> {
|
||||
Meta mergeMeta = Template.compileTemplate(mergeNode, config);
|
||||
DataNode<Table> mergeData = runAction(new MergeDataAction(), callback, context, tablesForMerge.build(), mergeMeta);
|
||||
mergeData.dataStream().forEach(d -> {
|
||||
@ -158,7 +158,7 @@ public class NumassPrepareTask extends AbstractTask<Table> {
|
||||
|
||||
@Override
|
||||
public void validate(TaskModel model) {
|
||||
if (!model.meta().hasNode("data")) {
|
||||
if (!model.meta().hasMeta("data")) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ public class NumassTableFilterTask extends SingleActionTask<Table, Table> {
|
||||
@Override
|
||||
protected TaskModel transformModel(TaskModel model) {
|
||||
MetaBuilder metaBuilder = new MetaBuilder(model.meta()).removeNode("filter");
|
||||
if (model.meta().hasNode("empty")) {
|
||||
if (model.meta().hasMeta("empty")) {
|
||||
model.dependsOn("numass.substractEmpty", metaBuilder.build(), "prepare");
|
||||
} else {
|
||||
model.dependsOn("numass.prepare", metaBuilder.build(), "prepare");
|
||||
|
@ -0,0 +1,24 @@
|
||||
package inr.numass.client;
|
||||
|
||||
import hep.dataforge.meta.Meta;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by darksnake on 09-Oct-16.
|
||||
*/
|
||||
public class ClientUtils {
|
||||
public String getRunName(Meta config) {
|
||||
if (config.hasValue("numass.run")) {
|
||||
return config.getString("numass.run");
|
||||
} else if (config.hasMeta("numass.server")) {
|
||||
try {
|
||||
return new NumassClient(config.getMeta("numass.server")).getCurrentRun().getString("path");
|
||||
} catch (IOException e) {
|
||||
return "default";
|
||||
}
|
||||
} else {
|
||||
return "default";
|
||||
}
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@ import hep.dataforge.meta.Meta;
|
||||
import hep.dataforge.meta.MetaBuilder;
|
||||
import hep.dataforge.storage.commons.MessageFactory;
|
||||
import hep.dataforge.storage.commons.StorageUtils;
|
||||
import hep.dataforge.tables.DataPoint;
|
||||
import hep.dataforge.values.Value;
|
||||
import inr.numass.storage.NumassStorage;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -32,25 +33,32 @@ import java.nio.channels.FileChannel;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.time.Instant;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author darksnake
|
||||
*/
|
||||
public class NumassClient extends MessageFactory implements AutoCloseable, Responder {
|
||||
public class NumassClient implements AutoCloseable, Responder {
|
||||
|
||||
Socket socket;
|
||||
MessageFactory mf = new MessageFactory();
|
||||
|
||||
public NumassClient(String address, int port) throws IOException {
|
||||
socket = new Socket(address, port);
|
||||
socket.setSoTimeout(300);
|
||||
}
|
||||
|
||||
|
||||
public NumassClient(Meta meta) throws IOException {
|
||||
this(meta.getString("ip", "192.168.111.1"), meta.getInt("port", 8335));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
if (!socket.isClosed()) {
|
||||
write(terminator(), socket.getOutputStream());
|
||||
write(mf.terminator(), socket.getOutputStream());
|
||||
}
|
||||
socket.close();
|
||||
}
|
||||
@ -62,7 +70,7 @@ public class NumassClient extends MessageFactory implements AutoCloseable, Respo
|
||||
return read(socket.getInputStream());
|
||||
} catch (IOException ex) {
|
||||
LoggerFactory.getLogger(getClass()).error("Error in envelope exchange", ex);
|
||||
return errorResponseBase(message, ex).build();
|
||||
return mf.errorResponseBase(message, ex).build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,7 +84,7 @@ public class NumassClient extends MessageFactory implements AutoCloseable, Respo
|
||||
}
|
||||
|
||||
private EnvelopeBuilder requestActionBase(String type, String action) {
|
||||
return requestBase(type).putMetaValue("action", action);
|
||||
return mf.requestBase(type).putMetaValue("action", action);
|
||||
}
|
||||
|
||||
public Meta getCurrentRun() {
|
||||
@ -118,7 +126,7 @@ public class NumassClient extends MessageFactory implements AutoCloseable, Respo
|
||||
return StorageUtils.getErrorMeta(new FileNotFoundException(fileName));
|
||||
}
|
||||
|
||||
Envelope bin = requestBase("numass.data")
|
||||
Envelope bin = mf.requestBase("numass.data")
|
||||
.putMetaValue("action", "push")
|
||||
.putMetaValue("path", path)
|
||||
.putMetaValue("name", zipName)
|
||||
@ -148,7 +156,7 @@ public class NumassClient extends MessageFactory implements AutoCloseable, Respo
|
||||
Meta response = respond(env.build()).meta();
|
||||
if (response.getBoolean("success", true)) {
|
||||
Map<String, Value> res = new HashMap<>();
|
||||
response.getNodes("state").stream().forEach((stateMeta) -> {
|
||||
response.getMetaList("state").stream().forEach((stateMeta) -> {
|
||||
res.put(stateMeta.getString("name"), stateMeta.getValue("value"));
|
||||
});
|
||||
return res;
|
||||
@ -208,5 +216,40 @@ public class NumassClient extends MessageFactory implements AutoCloseable, Respo
|
||||
return respond(env.build()).meta();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create remote storage with given meta
|
||||
*
|
||||
* @param path full path relative to root storage
|
||||
* @param meta
|
||||
* @return
|
||||
*/
|
||||
public Envelope createStorage(String path, Meta meta) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create remote loader
|
||||
*
|
||||
* @param shelf full path to the shelf
|
||||
* @param name the name of the loader
|
||||
* @param meta loader meta
|
||||
* @return
|
||||
*/
|
||||
public Envelope createLoader(String shelf, String name, Meta meta) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send points to existing point loader
|
||||
*
|
||||
* @param shelf
|
||||
* @param loaderName
|
||||
* @param points
|
||||
* @return
|
||||
*/
|
||||
public Envelope sendDataPoints(String shelf, String loaderName, Collection<DataPoint> points) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -135,8 +135,8 @@ public class NumassRun implements Annotated, Responder {
|
||||
|
||||
private synchronized Envelope pushNote(Envelope message) {
|
||||
try {
|
||||
if (message.meta().hasNode("note")) {
|
||||
for (Meta node : message.meta().getNodes("note")) {
|
||||
if (message.meta().hasMeta("note")) {
|
||||
for (Meta node : message.meta().getMetaList("note")) {
|
||||
addNote(NumassNote.buildFrom(node));
|
||||
}
|
||||
} else {
|
||||
|
@ -96,7 +96,7 @@ public class NumassServer extends AbstractNetworkListener {
|
||||
|
||||
private void startRun(Meta annotation) throws StorageException {
|
||||
String path = annotation.getString("path", DEFAULT_RUN_PATH);
|
||||
//Meta meta = annotation.getNode("meta", null);
|
||||
//Meta meta = annotation.getMeta("meta", null);
|
||||
run = new NumassRun(path, NumassStorage.buildNumassStorage(root, path, false, true), getResponseFactory());
|
||||
getRootState().setValue("numass.current.run", path);
|
||||
}
|
||||
|
@ -20,13 +20,14 @@ import hep.dataforge.meta.Annotated;
|
||||
import hep.dataforge.meta.Meta;
|
||||
import hep.dataforge.storage.commons.StorageManager;
|
||||
import hep.dataforge.storage.filestorage.FileStorage;
|
||||
import java.io.File;
|
||||
import org.apache.commons.daemon.Daemon;
|
||||
import org.apache.commons.daemon.DaemonContext;
|
||||
import org.apache.commons.daemon.DaemonInitException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* A daemon wrapper for numass server
|
||||
*
|
||||
@ -79,8 +80,8 @@ public class NumassServerDaemon implements Daemon, Annotated {
|
||||
|
||||
String repoPath = meta().getString(NUMASS_REPO_PATH_PROPERTY, "/home/numass-storage/");
|
||||
Meta repoConfig = null;
|
||||
if (meta().hasNode(NUMASS_REPO_ELEMENT)) {
|
||||
repoConfig = meta().getNode(NUMASS_REPO_ELEMENT);
|
||||
if (meta().hasMeta(NUMASS_REPO_ELEMENT)) {
|
||||
repoConfig = meta().getMeta(NUMASS_REPO_ELEMENT);
|
||||
}
|
||||
logger.info("Initializing file storage in {}", repoPath);
|
||||
root = FileStorage.in(new File(repoPath), repoConfig);
|
||||
@ -92,8 +93,8 @@ public class NumassServerDaemon implements Daemon, Annotated {
|
||||
if (root != null) {
|
||||
root.open();
|
||||
Meta listenerConfig = null;
|
||||
if (meta().hasNode(LISTENER_ELEMENT)) {
|
||||
listenerConfig = meta().getNode(LISTENER_ELEMENT);
|
||||
if (meta().hasMeta(LISTENER_ELEMENT)) {
|
||||
listenerConfig = meta().getMeta(LISTENER_ELEMENT);
|
||||
}
|
||||
|
||||
listener = new NumassServer(root, listenerConfig);
|
||||
|
Loading…
Reference in New Issue
Block a user