Refactoring

This commit is contained in:
Alexander Nozik 2016-10-09 20:13:25 +03:00
parent 03af27d357
commit f174440cd3
26 changed files with 159 additions and 94 deletions

View File

@ -95,8 +95,8 @@ public class PKT8App extends Application {
device = setupDevice(deviceName, config); device = setupDevice(deviceName, config);
// setting up storage connections // setting up storage connections
if (config.hasNode("storage")) { if (config.hasMeta("storage")) {
config.getNodes("storage").forEach(node -> { config.getMetaList("storage").forEach(node -> {
Storage storage = StorageFactory.buildStorage(device.getContext(), node); Storage storage = StorageFactory.buildStorage(device.getContext(), node);
if(config.hasValue("numass.run")){ if(config.hasValue("numass.run")){
try { try {
@ -148,7 +148,7 @@ public class PKT8App extends Application {
public PKT8Device setupDevice(String deviceName, Meta config) throws ControlException { public PKT8Device setupDevice(String deviceName, Meta config) throws ControlException {
Meta deviceMeta; Meta deviceMeta;
if (config.hasNode("device")) { if (config.hasMeta("device")) {
deviceMeta = MetaUtils.findNodeByValue(config, "device", "name", deviceName); deviceMeta = MetaUtils.findNodeByValue(config, "device", "name", deviceName);
} else { } else {
deviceMeta = config; deviceMeta = config;

View File

@ -69,8 +69,8 @@ public class PKT8Device extends PortSensor<PKT8Result> {
public void init() throws ControlException { public void init() throws ControlException {
//read channel configuration //read channel configuration
if (meta().hasNode("channel")) { if (meta().hasMeta("channel")) {
for (Meta node : meta().getNodes("channel")) { for (Meta node : meta().getMetaList("channel")) {
String designation = node.getString("designation", "default"); String designation = node.getString("designation", "default");
this.channels.put(designation, new PKT8Channel(node)); this.channels.put(designation, new PKT8Channel(node));
} }

View File

@ -80,13 +80,13 @@ public class PKT8PlotController implements Initializable, MeasurementListener<PK
} }
public void configure(Meta config) { public void configure(Meta config) {
if (config.hasNode("plotConfig")) { if (config.hasMeta("plotConfig")) {
Meta plotConfig = MetaUtils.findNodeByValue(config, "plotConfig", "device", getDeviceName()); Meta plotConfig = MetaUtils.findNodeByValue(config, "plotConfig", "device", getDeviceName());
if (plotConfig == null) { 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 -> { .forEach(channel -> {
//plot config from device configuration //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 //Do not use view config here, it is applyed separately
TimePlottable plottable = new TimePlottable(channel.getName()); TimePlottable plottable = new TimePlottable(channel.getName());

View File

@ -89,7 +89,7 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po
protected Meta getMetaForMeasurement(String name) { protected Meta getMetaForMeasurement(String name) {
switch (name) { switch (name) {
case "peakJump": case "peakJump":
return meta().getNode("peakJump"); return meta().getMeta("peakJump");
default: default:
return super.getMetaForMeasurement(name); return super.getMetaForMeasurement(name);
} }
@ -427,7 +427,7 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po
sendAndWait("MeasurementRemove", name); sendAndWait("MeasurementRemove", name);
if (sendAndWait("AddPeakJump", name, filterMode, accuracy, 0, 0, 0).isOK()) { if (sendAndWait("AddPeakJump", name, filterMode, accuracy, 0, 0, 0).isOK()) {
peakMap = new LinkedHashMap<>(); 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"))); peakMap.put(peak.getInt("mass"), peak.getString("name", peak.getString("mass")));
if (!sendAndWait("MeasurementAddMass", peak.getString("mass")).isOK()) { if (!sendAndWait("MeasurementAddMass", peak.getString("mass")).isOK()) {
throw new ControlException("Can't add mass to measurement measurement for msp"); throw new ControlException("Can't add mass to measurement measurement for msp");

View File

@ -152,7 +152,7 @@ public class MspViewController implements Initializable, MspListener {
public Configuration getViewConfig() { public Configuration getViewConfig() {
if (viewConfig == null) { if (viewConfig == null) {
viewConfig = new Configuration(getDevice().meta().getNode("peakJump")); viewConfig = new Configuration(getDevice().meta().getMeta("peakJump"));
viewConfig.addObserver(viewConfigObserver); viewConfig.addObserver(viewConfigObserver);
LoggerFactory.getLogger(getClass()).warn("Could not find view configuration. Using default view configuration instead."); 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) { public void setDeviceConfig(Context context, Meta config) {
Meta mspConfig = null; Meta mspConfig = null;
if (config.hasNode("device")) { if (config.hasMeta("device")) {
for (Meta d : config.getNodes("device")) { for (Meta d : config.getMetaList("device")) {
if (d.getString("type", "unknown").equals(MSP_DEVICE_TYPE) if (d.getString("type", "unknown").equals(MSP_DEVICE_TYPE)
&& d.getString("name", "msp").equals(this.mspName)) { && d.getString("name", "msp").equals(this.mspName)) {
mspConfig = d; mspConfig = d;
} }
} }
} else if (config.hasNode("peakJump")) { } else if (config.hasMeta("peakJump")) {
mspConfig = config; mspConfig = config;
} }
@ -213,8 +213,8 @@ public class MspViewController implements Initializable, MspListener {
throw new RuntimeException(); throw new RuntimeException();
} }
if (config.hasNode("plots.msp")) { if (config.hasMeta("plots.msp")) {
setViewConfig(config.getNode("plots.msp")); setViewConfig(config.getMeta("plots.msp"));
} }
updatePlot(); updatePlot();
@ -251,11 +251,11 @@ public class MspViewController implements Initializable, MspListener {
initPlot(); initPlot();
} }
Meta config = getViewConfig(); Meta config = getViewConfig();
if (config.hasNode("plotFrame")) { if (config.hasMeta("plotFrame")) {
this.plot.configure(config.getNode("plotFrame")); this.plot.configure(config.getMeta("plotFrame"));
} }
if (config.hasNode("peakJump.line")) { if (config.hasMeta("peakJump.line")) {
for (Meta an : config.getNodes("peakJump.line")) { for (Meta an : config.getMetaList("peakJump.line")) {
String mass = an.getString("mass"); String mass = an.getString("mass");
if (!this.plottables.hasPlottable(mass)) { if (!this.plottables.hasPlottable(mass)) {
@ -363,7 +363,7 @@ public class MspViewController implements Initializable, MspListener {
private void onStoreButtonClick(ActionEvent event) { private void onStoreButtonClick(ActionEvent event) {
if (storeButton.isSelected()) { if (storeButton.isSelected()) {
if (!device.meta().hasNode("storage")) { if (!device.meta().hasMeta("storage")) {
device.getLogger().info("Storage not defined. Starting storage selection dialog"); device.getLogger().info("Storage not defined. Starting storage selection dialog");
DirectoryChooser chooser = new DirectoryChooser(); DirectoryChooser chooser = new DirectoryChooser();
File storageDir = chooser.showDialog(this.plotPane.getScene().getWindow()); File storageDir = chooser.showDialog(this.plotPane.getScene().getWindow());
@ -374,13 +374,13 @@ public class MspViewController implements Initializable, MspListener {
device.getConfig().putNode(new MetaBuilder("storage") device.getConfig().putNode(new MetaBuilder("storage")
.putValue("path", storageDir.getAbsolutePath())); .putValue("path", storageDir.getAbsolutePath()));
} }
Meta storageConfig = device.meta().getNode("storage"); Meta storageConfig = device.meta().getMeta("storage");
Storage localStorage = StorageManager.buildFrom(device.getContext()) Storage localStorage = StorageManager.buildFrom(device.getContext())
.buildStorage(storageConfig); .buildStorage(storageConfig);
String runName = device.meta().getString("numass.run", ""); String runName = device.meta().getString("numass.run", "");
Meta meta = device.meta(); Meta meta = device.meta();
if (meta.hasNode("numass")) { if (meta.hasMeta("numass")) {
try { try {
device.getLogger().info("Obtaining run information from cetral server..."); device.getLogger().info("Obtaining run information from cetral server...");
NumassClient client = new NumassClient(meta.getString("numass.ip", "192.168.111.1"), NumassClient client = new NumassClient(meta.getString("numass.ip", "192.168.111.1"),

View File

@ -15,13 +15,8 @@ import hep.dataforge.storage.commons.LoaderFactory;
import hep.dataforge.tables.TableFormatBuilder; import hep.dataforge.tables.TableFormatBuilder;
import hep.dataforge.values.ValueType; import hep.dataforge.values.ValueType;
import inr.numass.client.NumassClient; import inr.numass.client.NumassClient;
import inr.numass.readvac.devices.CM32Device; import inr.numass.readvac.devices.*;
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.fx.VacCollectorController; import inr.numass.readvac.fx.VacCollectorController;
import java.io.File;
import javafx.application.Application; import javafx.application.Application;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Scene; import javafx.scene.Scene;
@ -29,6 +24,8 @@ import javafx.stage.Stage;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File;
/** /**
* *
* @author Alexander Nozik * @author Alexander Nozik
@ -53,19 +50,19 @@ public class ReadVac extends Application {
} }
Sensor<Double> p1 = new MKSVacDevice(config.getString("p1.port", "com::/dev/ttyUSB0")); 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")); p1.setName(config.getString("p1.name", "P1"));
Sensor<Double> p2 = new CM32Device(config.getString("p2.port", "tcp::192.168.111.32:4002")); 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")); p2.setName(config.getString("p2.name", "P2"));
Sensor<Double> p3 = new CM32Device(config.getString("p3.port", "tcp::192.168.111.32:4003")); 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")); p3.setName(config.getString("p3.name", "P3"));
Sensor<Double> px = new VITVacDevice(config.getString("px.port", "com::/dev/ttyUSB1")); 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")); px.setName(config.getString("px.name", "Px"));
Sensor<Double> baratron = new MKSBaratronDevice(config.getString("baratron.port", "tcp::192.168.111.33:4004")); 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")); baratron.setName(config.getString("baratron.name", "Baratron"));
VacCollectorDevice collector = new VacCollectorDevice(); VacCollectorDevice collector = new VacCollectorDevice();
@ -82,7 +79,7 @@ public class ReadVac extends Application {
controller.setLoaderFactory((VacCollectorDevice device, Storage localStorage) -> { controller.setLoaderFactory((VacCollectorDevice device, Storage localStorage) -> {
try { try {
String runName = device.meta().getString("numass.run", ""); String runName = device.meta().getString("numass.run", "");
if (config.hasNode("numass")) { if (config.hasMeta("numass")) {
try { try {
logger.info("Obtaining run information from cetral server..."); logger.info("Obtaining run information from cetral server...");
NumassClient client = new NumassClient(config.getString("numass.ip", "192.168.111.1"), NumassClient client = new NumassClient(config.getString("numass.ip", "192.168.111.1"),

View File

@ -232,7 +232,7 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
private void onStoreToggle(ActionEvent event) { private void onStoreToggle(ActionEvent event) {
if (storeButton.isSelected()) { if (storeButton.isSelected()) {
//creating storage on UI thread //creating storage on UI thread
if (!device.meta().hasNode("storage")) { if (!device.meta().hasMeta("storage")) {
getLogger().info("Storage not defined. Starting storage selection dialog"); getLogger().info("Storage not defined. Starting storage selection dialog");
DirectoryChooser chooser = new DirectoryChooser(); DirectoryChooser chooser = new DirectoryChooser();
File storageDir = chooser.showDialog(plotHolder.getScene().getWindow()); File storageDir = chooser.showDialog(plotHolder.getScene().getWindow());
@ -243,7 +243,7 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
device.getConfig().putNode(new MetaBuilder("storage") device.getConfig().putNode(new MetaBuilder("storage")
.putValue("path", storageDir.getAbsolutePath())); .putValue("path", storageDir.getAbsolutePath()));
} }
Meta storageConfig = device.meta().getNode("storage"); Meta storageConfig = device.meta().getMeta("storage");
Storage localStorage = StorageManager.buildFrom(device.getContext()) Storage localStorage = StorageManager.buildFrom(device.getContext())
.buildStorage(storageConfig); .buildStorage(storageConfig);
//Start storage creation on non-UI thread //Start storage creation on non-UI thread

View File

@ -54,8 +54,8 @@ public class PlotFitResultAction extends OneToOneAction<FitState, FitState> {
XYModel model = (XYModel) input.getModel(); XYModel model = (XYModel) input.getModel();
XYAdapter adapter; XYAdapter adapter;
if (metaData.hasNode("adapter")) { if (metaData.hasMeta("adapter")) {
adapter = new XYAdapter(metaData.getNode("adapter")); adapter = new XYAdapter(metaData.getMeta("adapter"));
} else if (input.getModel() instanceof XYModel) { } else if (input.getModel() instanceof XYModel) {
adapter = model.getAdapter(); adapter = model.getAdapter();
} else { } else {
@ -66,7 +66,7 @@ public class PlotFitResultAction extends OneToOneAction<FitState, FitState> {
XYPlotFrame frame = (XYPlotFrame) PlotsPlugin XYPlotFrame frame = (XYPlotFrame) PlotsPlugin
.buildFrom(getContext()).buildPlotFrame(getName(), name, .buildFrom(getContext()).buildPlotFrame(getName(), name,
metaData.getNode("plot", Meta.empty())); metaData.getMeta("plot", Meta.empty()));
PlottableXYFunction fit = new PlottableXYFunction("fit"); PlottableXYFunction fit = new PlottableXYFunction("fit");
fit.setDensity(100, false); fit.setDensity(100, false);

View File

@ -259,8 +259,8 @@ public class NumassPlugin extends BasicPlugin {
return TransmissionInterpolator return TransmissionInterpolator
.fromFile(context, transmissionFile, transXName, transYName, nSmooth, w, stitchBorder); .fromFile(context, transmissionFile, transXName, transYName, nSmooth, w, stitchBorder);
} else if (an.hasNode("transBuildAction")) { } else if (an.hasMeta("transBuildAction")) {
Meta transBuild = an.getNode("transBuildAction"); Meta transBuild = an.getMeta("transBuildAction");
try { try {
return TransmissionInterpolator.fromAction((Context) context, return TransmissionInterpolator.fromAction((Context) context,
transBuild, transXName, transYName, nSmooth, w, stitchBorder); transBuild, transXName, transYName, nSmooth, w, stitchBorder);
@ -273,8 +273,8 @@ public class NumassPlugin extends BasicPlugin {
} }
private XYAdapter getAdapter(Meta an) { private XYAdapter getAdapter(Meta an) {
if (an.hasNode(PointAdapter.DATA_ADAPTER_KEY)) { if (an.hasMeta(PointAdapter.DATA_ADAPTER_KEY)) {
return new XYAdapter(an.getNode(PointAdapter.DATA_ADAPTER_KEY)); return new XYAdapter(an.getMeta(PointAdapter.DATA_ADAPTER_KEY));
} else { } else {
return new XYAdapter("Uread", "CR", "CRerr"); return new XYAdapter("Uread", "CR", "CRerr");
} }

View File

@ -36,16 +36,16 @@ public class AdjustErrorsAction extends OneToOneAction<Table, Table> {
} }
private DataPoint evalPoint(Meta meta, DataPoint dp) { private DataPoint evalPoint(Meta meta, DataPoint dp) {
if (meta.hasNode("point")) { if (meta.hasMeta("point")) {
for (Meta pointMeta : meta.getNodes("point")) { for (Meta pointMeta : meta.getMetaList("point")) {
if (pointMeta.getDouble("Uset") == dp.getDouble("Uset")) { if (pointMeta.getDouble("Uset") == dp.getDouble("Uset")) {
return adjust(dp, pointMeta); return adjust(dp, pointMeta);
} }
} }
} }
if (meta.hasNode("range")) { if (meta.hasMeta("range")) {
for (Meta rangeMeta : meta.getNodes("range")) { for (Meta rangeMeta : meta.getMetaList("range")) {
double from = rangeMeta.getDouble("from", 0); double from = rangeMeta.getDouble("from", 0);
double to = rangeMeta.getDouble("to", Double.POSITIVE_INFINITY); double to = rangeMeta.getDouble("to", Double.POSITIVE_INFINITY);
double u = rangeMeta.getDouble("Uset"); double u = rangeMeta.getDouble("Uset");
@ -55,8 +55,8 @@ public class AdjustErrorsAction extends OneToOneAction<Table, Table> {
} }
} }
if (meta.hasNode("all")) { if (meta.hasMeta("all")) {
return adjust(dp, meta.getNode("all")); return adjust(dp, meta.getMeta("all"));
} }
return dp; return dp;

View File

@ -147,8 +147,8 @@ public class PrepareDataAction extends OneToOneAction<NumassData, Table> {
if (meta.hasValue("correction")) { if (meta.hasValue("correction")) {
// log.report("Using correction from formula: {}", meta.getString("correction")); // log.report("Using correction from formula: {}", meta.getString("correction"));
return evaluateExpression(point, meta.getString("correction")); return evaluateExpression(point, meta.getString("correction"));
} else if (meta.hasNode("underflow")) { } else if (meta.hasMeta("underflow")) {
return new UnderflowCorrection().get(log, meta.getNode("underflow"), point); return new UnderflowCorrection().get(log, meta.getMeta("underflow"), point);
} else { } else {
return 1; return 1;
} }

View File

@ -50,7 +50,7 @@ public class ReadNumassDataAction extends OneToOneAction<Binary, NMFile> {
if (meta.getNodeNames(false).contains("debunch")) { if (meta.getNodeNames(false).contains("debunch")) {
DebunchAction debunch = new DebunchAction(); DebunchAction debunch = new DebunchAction();
Laminate laminate = new Laminate(meta.getNode("debunch")) Laminate laminate = new Laminate(meta.getMeta("debunch"))
.setValueContext(getContext()) .setValueContext(getContext())
.setDescriptor(debunch.getDescriptor()); .setDescriptor(debunch.getDescriptor());
raw = debunch.execute(name, laminate, raw); raw = debunch.execute(name, laminate, raw);

View File

@ -80,10 +80,10 @@ public class ShowEnergySpectrumAction extends OneToOneAction<NumassData, Table>
ColumnedDataWriter.writeDataSet(out, table, inputMeta.toString()); 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 XYPlotFrame frame = (XYPlotFrame) PlotsPlugin
.buildFrom(getContext()).buildPlotFrame(getName(), name, .buildFrom(getContext()).buildPlotFrame(getName(), name,
inputMeta.getNode("plot", Meta.empty())); inputMeta.getMeta("plot", Meta.empty()));
fillDetectorData(valueMap).forEach(frame::add); fillDetectorData(valueMap).forEach(frame::add);
} }

View File

@ -49,7 +49,7 @@ public class SlicingAction extends OneToOneAction<NMFile, NMFile> {
Map<String, Pair<Integer, Integer>> slicingConfig; Map<String, Pair<Integer, Integer>> slicingConfig;
LinkedHashMap<String, Pair<Integer, Integer>> res = new LinkedHashMap<>(); 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) { for (Meta slice : list) {
String title = slice.getString("title", slice.getName()); String title = slice.getString("title", slice.getName());

View File

@ -73,7 +73,7 @@ public class SterileNeutrinoSpectrum extends AbstractParametricFunction {
} }
transmission = new NumassTransmission(context, configuration.getNodeOrEmpty("transmission")); 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); this.fast = configuration.getBoolean("fast", true);
transRes = new TransRes(); transRes = new TransRes();
} }

View File

@ -236,8 +236,8 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
buildContext(config); buildContext(config);
//loading data configuration //loading data configuration
if (config.hasNode("data")) { if (config.hasMeta("data")) {
dataConfig = new Configuration(config.getNode("data")); dataConfig = new Configuration(config.getMeta("data"));
//replacing file name value with appropriate nodes //replacing file name value with appropriate nodes
if (dataConfig.hasValue("file")) { if (dataConfig.hasValue("file")) {
Value fileValue = dataConfig.getValue("file"); Value fileValue = dataConfig.getValue("file");
@ -258,7 +258,7 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
//loading actions configuration //loading actions configuration
actionsConfig = new Configuration("actionlist"); 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()); .<Configuration>map(m -> new Configuration(m)).collect(Collectors.toList());
actionsConfig.attachNodeItem("action", actions); actionsConfig.attachNodeItem("action", actions);

View File

@ -33,7 +33,7 @@ public class NumassFitScanTask extends AbstractTask<FitState> {
DataTree.Builder<FitState> resultBuilder = DataTree.builder(FitState.class); DataTree.Builder<FitState> resultBuilder = DataTree.builder(FitState.class);
DataNode<Table> sourceNode = data.getCheckedNode("prepare", Table.class); DataNode<Table> sourceNode = data.getCheckedNode("prepare", Table.class);
if (config.hasNode("merge")) { if (config.hasMeta("merge")) {
//use merged data and ignore raw data //use merged data and ignore raw data
sourceNode = sourceNode.getCheckedNode("merge", Table.class); sourceNode = sourceNode.getCheckedNode("merge", Table.class);
} }
@ -47,10 +47,10 @@ public class NumassFitScanTask extends AbstractTask<FitState> {
MetaBuilder overrideMeta = new MetaBuilder(fitConfig); MetaBuilder overrideMeta = new MetaBuilder(fitConfig);
overrideMeta.setValue("@resultName", String.format("%s[%s=%s]", d.getName(), scanParameter, val.stringValue())); 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); overrideMeta.setValue("params." + scanParameter + ".value", val);
} else { } else {
overrideMeta.getNodes("params.param").stream() overrideMeta.getMetaList("params.param").stream()
.filter(par -> par.getString("name") == scanParameter).forEach(par -> par.setValue("value", val)); .filter(par -> par.getString("name") == scanParameter).forEach(par -> par.setValue("value", val));
} }
// Data<Table> newData = new Data<Table>(data.getGoal(),data.type(),overrideMeta); // 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) { protected TaskModel transformModel(TaskModel model) {
//Transmit meta as-is //Transmit meta as-is
MetaBuilder metaBuilder = new MetaBuilder(model.meta()).removeNode("fit"); 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"); model.dependsOn("numass.filter", metaBuilder.build(), "prepare");
} else { } else {
model.dependsOn("numass.prepare", metaBuilder.build(), "prepare"); model.dependsOn("numass.prepare", metaBuilder.build(), "prepare");

View File

@ -47,7 +47,7 @@ public class NumassFitSummaryTask extends SingleActionTask<FitState, Table> {
@Override @Override
protected Meta transformMeta(TaskModel model) { protected Meta transformMeta(TaskModel model) {
return model.meta().getNode("summary"); return model.meta().getMeta("summary");
} }
@Override @Override

View File

@ -43,7 +43,7 @@ public class NumassFitTask extends SingleActionTask<Table, FitState> {
@Override @Override
public void validate(TaskModel model) { public void validate(TaskModel model) {
if (!model.meta().hasNode("fit")) { if (!model.meta().hasMeta("fit")) {
throw new RuntimeException("Fit element not found in model"); throw new RuntimeException("Fit element not found in model");
} }
} }
@ -55,14 +55,14 @@ public class NumassFitTask extends SingleActionTask<Table, FitState> {
@Override @Override
protected Meta transformMeta(TaskModel model) { protected Meta transformMeta(TaskModel model) {
return model.meta().getNode("fit"); return model.meta().getMeta("fit");
} }
@Override @Override
protected TaskModel transformModel(TaskModel model) { protected TaskModel transformModel(TaskModel model) {
//Transmit meta as-is //Transmit meta as-is
MetaBuilder metaBuilder = new MetaBuilder(model.meta()).removeNode("fit"); 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"); model.dependsOn("numass.filter", metaBuilder.build(), "prepare");
} else { } else {
model.dependsOn("numass.prepare", metaBuilder.build(), "prepare"); model.dependsOn("numass.prepare", metaBuilder.build(), "prepare");

View File

@ -57,38 +57,38 @@ public class NumassPrepareTask extends AbstractTask<Table> {
Context context = model.getContext(); Context context = model.getContext();
//acquiring initial data. Data node could not be empty //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(); URI storageUri = input.getCheckedData("dataRoot", URI.class).get();
DataSet.Builder<NumassData> dataBuilder = readData(callback, context, storageUri, dataMeta); DataSet.Builder<NumassData> dataBuilder = readData(callback, context, storageUri, dataMeta);
if (config.hasNode("empty")) { if (config.hasMeta("empty")) {
dataBuilder.putNode("empty", readData(callback, context, storageUri, config.getNode("empty")).build()); dataBuilder.putNode("empty", readData(callback, context, storageUri, config.getMeta("empty")).build());
} }
DataNode<NumassData> data = dataBuilder.build(); DataNode<NumassData> data = dataBuilder.build();
//preparing table data //preparing table data
Meta prepareMeta = config.getNode("prepare"); Meta prepareMeta = config.getMeta("prepare");
DataNode<Table> tables = runAction(new PrepareDataAction(), callback, context, data, prepareMeta); DataNode<Table> tables = runAction(new PrepareDataAction(), callback, context, data, prepareMeta);
if (config.hasNode("monitor")) { if (config.hasMeta("monitor")) {
Meta monitorMeta = config.getNode("monitor"); Meta monitorMeta = config.getMeta("monitor");
tables = runAction(new MonitorCorrectAction(), callback, context, tables, monitorMeta); tables = runAction(new MonitorCorrectAction(), callback, context, tables, monitorMeta);
} }
//merging if needed //merging if needed
if (config.hasNode("merge")) { if (config.hasMeta("merge")) {
DataTree.Builder<Table> resultBuilder = DataTree.builder(Table.class); DataTree.Builder<Table> resultBuilder = DataTree.builder(Table.class);
DataTree.Builder<Table> tablesForMerge = new DataTree.Builder<>(tables); DataTree.Builder<Table> tablesForMerge = new DataTree.Builder<>(tables);
//extracting empty data //extracting empty data
if (config.hasNode("empty")) { if (config.hasMeta("empty")) {
DataNode<Table> emptySourceNode = tables.getCheckedNode("empty", Table.class); DataNode<Table> emptySourceNode = tables.getCheckedNode("empty", Table.class);
Meta emptyMergeMeta = new MetaBuilder("emptySource").setValue("mergeName", "emptySource"); Meta emptyMergeMeta = new MetaBuilder("emptySource").setValue("mergeName", "emptySource");
resultBuilder.putData("merge.empty", runAction(new MergeDataAction(), callback, context, emptySourceNode, emptyMergeMeta).getData()); resultBuilder.putData("merge.empty", runAction(new MergeDataAction(), callback, context, emptySourceNode, emptyMergeMeta).getData());
tablesForMerge.removeNode("empty"); tablesForMerge.removeNode("empty");
} }
config.getNodes("merge").forEach(mergeNode -> { config.getMetaList("merge").forEach(mergeNode -> {
Meta mergeMeta = Template.compileTemplate(mergeNode, config); Meta mergeMeta = Template.compileTemplate(mergeNode, config);
DataNode<Table> mergeData = runAction(new MergeDataAction(), callback, context, tablesForMerge.build(), mergeMeta); DataNode<Table> mergeData = runAction(new MergeDataAction(), callback, context, tablesForMerge.build(), mergeMeta);
mergeData.dataStream().forEach(d -> { mergeData.dataStream().forEach(d -> {
@ -158,7 +158,7 @@ public class NumassPrepareTask extends AbstractTask<Table> {
@Override @Override
public void validate(TaskModel model) { public void validate(TaskModel model) {
if (!model.meta().hasNode("data")) { if (!model.meta().hasMeta("data")) {
} }
} }

View File

@ -28,7 +28,7 @@ public class NumassTableFilterTask extends SingleActionTask<Table, Table> {
@Override @Override
protected TaskModel transformModel(TaskModel model) { protected TaskModel transformModel(TaskModel model) {
MetaBuilder metaBuilder = new MetaBuilder(model.meta()).removeNode("filter"); 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"); model.dependsOn("numass.substractEmpty", metaBuilder.build(), "prepare");
} else { } else {
model.dependsOn("numass.prepare", metaBuilder.build(), "prepare"); model.dependsOn("numass.prepare", metaBuilder.build(), "prepare");

View File

@ -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";
}
}
}

View File

@ -20,6 +20,7 @@ import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder; import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.storage.commons.MessageFactory; import hep.dataforge.storage.commons.MessageFactory;
import hep.dataforge.storage.commons.StorageUtils; import hep.dataforge.storage.commons.StorageUtils;
import hep.dataforge.tables.DataPoint;
import hep.dataforge.values.Value; import hep.dataforge.values.Value;
import inr.numass.storage.NumassStorage; import inr.numass.storage.NumassStorage;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -32,25 +33,32 @@ import java.nio.channels.FileChannel;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import java.time.Instant; import java.time.Instant;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* @author darksnake * @author darksnake
*/ */
public class NumassClient extends MessageFactory implements AutoCloseable, Responder { public class NumassClient implements AutoCloseable, Responder {
Socket socket; Socket socket;
MessageFactory mf = new MessageFactory();
public NumassClient(String address, int port) throws IOException { public NumassClient(String address, int port) throws IOException {
socket = new Socket(address, port); socket = new Socket(address, port);
socket.setSoTimeout(300); socket.setSoTimeout(300);
} }
public NumassClient(Meta meta) throws IOException {
this(meta.getString("ip", "192.168.111.1"), meta.getInt("port", 8335));
}
@Override @Override
public void close() throws IOException { public void close() throws IOException {
if (!socket.isClosed()) { if (!socket.isClosed()) {
write(terminator(), socket.getOutputStream()); write(mf.terminator(), socket.getOutputStream());
} }
socket.close(); socket.close();
} }
@ -62,7 +70,7 @@ public class NumassClient extends MessageFactory implements AutoCloseable, Respo
return read(socket.getInputStream()); return read(socket.getInputStream());
} catch (IOException ex) { } catch (IOException ex) {
LoggerFactory.getLogger(getClass()).error("Error in envelope exchange", 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) { private EnvelopeBuilder requestActionBase(String type, String action) {
return requestBase(type).putMetaValue("action", action); return mf.requestBase(type).putMetaValue("action", action);
} }
public Meta getCurrentRun() { public Meta getCurrentRun() {
@ -118,7 +126,7 @@ public class NumassClient extends MessageFactory implements AutoCloseable, Respo
return StorageUtils.getErrorMeta(new FileNotFoundException(fileName)); return StorageUtils.getErrorMeta(new FileNotFoundException(fileName));
} }
Envelope bin = requestBase("numass.data") Envelope bin = mf.requestBase("numass.data")
.putMetaValue("action", "push") .putMetaValue("action", "push")
.putMetaValue("path", path) .putMetaValue("path", path)
.putMetaValue("name", zipName) .putMetaValue("name", zipName)
@ -148,7 +156,7 @@ public class NumassClient extends MessageFactory implements AutoCloseable, Respo
Meta response = respond(env.build()).meta(); Meta response = respond(env.build()).meta();
if (response.getBoolean("success", true)) { if (response.getBoolean("success", true)) {
Map<String, Value> res = new HashMap<>(); 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")); res.put(stateMeta.getString("name"), stateMeta.getValue("value"));
}); });
return res; return res;
@ -208,5 +216,40 @@ public class NumassClient extends MessageFactory implements AutoCloseable, Respo
return respond(env.build()).meta(); 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();
}
} }

View File

@ -135,8 +135,8 @@ public class NumassRun implements Annotated, Responder {
private synchronized Envelope pushNote(Envelope message) { private synchronized Envelope pushNote(Envelope message) {
try { try {
if (message.meta().hasNode("note")) { if (message.meta().hasMeta("note")) {
for (Meta node : message.meta().getNodes("note")) { for (Meta node : message.meta().getMetaList("note")) {
addNote(NumassNote.buildFrom(node)); addNote(NumassNote.buildFrom(node));
} }
} else { } else {

View File

@ -96,7 +96,7 @@ public class NumassServer extends AbstractNetworkListener {
private void startRun(Meta annotation) throws StorageException { private void startRun(Meta annotation) throws StorageException {
String path = annotation.getString("path", DEFAULT_RUN_PATH); 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()); run = new NumassRun(path, NumassStorage.buildNumassStorage(root, path, false, true), getResponseFactory());
getRootState().setValue("numass.current.run", path); getRootState().setValue("numass.current.run", path);
} }

View File

@ -20,13 +20,14 @@ import hep.dataforge.meta.Annotated;
import hep.dataforge.meta.Meta; import hep.dataforge.meta.Meta;
import hep.dataforge.storage.commons.StorageManager; import hep.dataforge.storage.commons.StorageManager;
import hep.dataforge.storage.filestorage.FileStorage; import hep.dataforge.storage.filestorage.FileStorage;
import java.io.File;
import org.apache.commons.daemon.Daemon; import org.apache.commons.daemon.Daemon;
import org.apache.commons.daemon.DaemonContext; import org.apache.commons.daemon.DaemonContext;
import org.apache.commons.daemon.DaemonInitException; import org.apache.commons.daemon.DaemonInitException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File;
/** /**
* A daemon wrapper for numass server * 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/"); String repoPath = meta().getString(NUMASS_REPO_PATH_PROPERTY, "/home/numass-storage/");
Meta repoConfig = null; Meta repoConfig = null;
if (meta().hasNode(NUMASS_REPO_ELEMENT)) { if (meta().hasMeta(NUMASS_REPO_ELEMENT)) {
repoConfig = meta().getNode(NUMASS_REPO_ELEMENT); repoConfig = meta().getMeta(NUMASS_REPO_ELEMENT);
} }
logger.info("Initializing file storage in {}", repoPath); logger.info("Initializing file storage in {}", repoPath);
root = FileStorage.in(new File(repoPath), repoConfig); root = FileStorage.in(new File(repoPath), repoConfig);
@ -92,8 +93,8 @@ public class NumassServerDaemon implements Daemon, Annotated {
if (root != null) { if (root != null) {
root.open(); root.open();
Meta listenerConfig = null; Meta listenerConfig = null;
if (meta().hasNode(LISTENER_ELEMENT)) { if (meta().hasMeta(LISTENER_ELEMENT)) {
listenerConfig = meta().getNode(LISTENER_ELEMENT); listenerConfig = meta().getMeta(LISTENER_ELEMENT);
} }
listener = new NumassServer(root, listenerConfig); listener = new NumassServer(root, listenerConfig);