diff --git a/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8App.java b/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8App.java index d4039b12..19094ea3 100644 --- a/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8App.java +++ b/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8App.java @@ -38,13 +38,6 @@ public class PKT8App extends Application { PKT8MainViewController controller; - /** - * @param args the command line arguments - */ - public static void main(String[] args) { - launch(args); - } - @Override public void start(Stage primaryStage) throws IOException, ControlException, ParseException { Locale.setDefault(Locale.US);// чтобы отделение десятичных знаков было точкой @@ -72,10 +65,12 @@ public class PKT8App extends Application { primaryStage.show(); - if(getParameters().getNamed().containsKey("cfgFile")){ + if (getParameters().getNamed().containsKey("cfgFile")) { controller.setConfig(MetaFileReader.read(new File(getParameters().getNamed().get("cfgFile")))); - } else if (Boolean.parseBoolean(getParameters().getNamed().getOrDefault("debug","false"))){ + } else if (Boolean.parseBoolean(getParameters().getNamed().getOrDefault("debug", "false"))) { controller.loadTestConfig(); + } else { + controller.startConfigDialog(); } } @@ -89,4 +84,11 @@ public class PKT8App extends Application { // System.exit(0); } + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + launch(args); + } + } diff --git a/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8Device.java b/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8Device.java index 8a9bad52..f8dd6e94 100644 --- a/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8Device.java +++ b/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8Device.java @@ -16,6 +16,10 @@ package inr.numass.cryotemp; import hep.dataforge.control.collectors.RegularPointCollector; +import hep.dataforge.control.connections.LoaderConnection; +import hep.dataforge.control.connections.PointListenerConnection; +import hep.dataforge.control.connections.Roles; +import hep.dataforge.control.connections.StorageConnection; import hep.dataforge.control.devices.PortSensor; import hep.dataforge.control.measurements.AbstractMeasurement; import hep.dataforge.control.measurements.Measurement; @@ -26,9 +30,10 @@ import hep.dataforge.exceptions.PortException; import hep.dataforge.exceptions.StorageException; import hep.dataforge.meta.Meta; import hep.dataforge.storage.api.PointLoader; -import hep.dataforge.storage.api.Storage; import hep.dataforge.storage.commons.LoaderFactory; import hep.dataforge.storage.commons.StorageFactory; +import hep.dataforge.tables.DataPoint; +import hep.dataforge.tables.PointListener; import hep.dataforge.tables.TableFormatBuilder; import java.time.Duration; @@ -90,6 +95,8 @@ public class PKT8Device extends PortSensor { setSPS(meta().getInt("sps", 0)); setBUF(meta().getInt("abuf", 100)); + setupStorage(); + } @Override @@ -234,39 +241,51 @@ public class PKT8Device extends PortSensor { } private void setupStorage() { - if (meta().hasNode("storage")) { - try { - Storage storage = StorageFactory.buildStorage(getContext(), meta().getNode("storage", Meta.empty())); - String suffix = Integer.toString((int) Instant.now().toEpochMilli()); - // Building data format - TableFormatBuilder TableFormatBuilder = new TableFormatBuilder() - .addTime("timestamp"); - List names = new ArrayList<>(); + // Building data format + TableFormatBuilder tableFormatBuilder = new TableFormatBuilder() + .addTime("timestamp"); + List names = new ArrayList<>(); - for (PKT8Channel channel : channels.values()) { - TableFormatBuilder.addNumber(channel.getName()); - names.add(channel.getName()); - } - - PointLoader pointLoader = LoaderFactory.buildPointLoder(storage, "cryotemp_" + suffix, "", "timestamp", TableFormatBuilder.build()); - - Duration duration = Duration.parse(meta().getString("averagingDuration", "PT30S")); - - collector = new RegularPointCollector((dp) -> { - if (pointLoader != null) { - try { - getLogger().debug("Point measurement complete. Pushing..."); - pointLoader.push(dp); - } catch (StorageException ex) { - getLogger().error("Error while pushing point to loader", ex); - } - } - }, duration, names); - } catch (StorageException ex) { - getLogger().error("Can't setup storage", ex); - } + for (PKT8Channel channel : channels.values()) { + tableFormatBuilder.addNumber(channel.getName()); + names.add(channel.getName()); } + + // setting up storage connections + if (meta().hasNode("storage")) { + meta().getNodes("storage").forEach(node -> { + connect(new StorageConnection(StorageFactory.buildStorage(getContext(), node))); + }); + } + + // setting up loader for each of storages + forEachTypedConnection(Roles.STORAGE_ROLE, StorageConnection.class, connection -> { + String suffix = Integer.toString((int) Instant.now().toEpochMilli()); + + PointLoader pointLoader = null; + try { + pointLoader = LoaderFactory.buildPointLoder(connection.getStorage(), + "cryotemp_" + suffix, "", "timestamp", tableFormatBuilder.build()); + this.connect(new LoaderConnection(pointLoader), Roles.POINT_LISTENER_ROLE); + } catch (StorageException e) { + getLogger().error("Failed to build loader from storage {}", connection.getStorage().getName()); + } + + }); + + // setting up the collector + Duration duration = Duration.parse(meta().getString("averagingDuration", "PT30S")); + collector = new RegularPointCollector((DataPoint dp) -> { + forEachTypedConnection(Roles.POINT_LISTENER_ROLE, PointListener.class, listener -> { + getLogger().debug("Point measurement complete. Pushing..."); + listener.accept(dp); + }); + }, duration, names); + } + + public void connectPointListener(PointListenerConnection listener){ + this.connect(listener, Roles.POINT_LISTENER_ROLE); } @Override @@ -296,9 +315,6 @@ public class PKT8Device extends PortSensor { getLogger().error("Failed to clear PKT8 port"); // throw new MeasurementException(e); } - if (collector == null) { - setupStorage(); - } return super.startMeasurement(); } diff --git a/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8MainViewController.java b/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8MainViewController.java index 8f24f3e9..bf51544b 100644 --- a/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8MainViewController.java +++ b/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8MainViewController.java @@ -37,7 +37,6 @@ import javafx.beans.Observable; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; -import javafx.scene.control.Button; import javafx.scene.control.ToggleButton; import javafx.scene.layout.AnchorPane; import javafx.stage.FileChooser; @@ -64,8 +63,7 @@ public class PKT8MainViewController implements Initializable, DeviceListener, Me private PKT8Device device; private FXPlotFrame plotFrame; private TimePlottableGroup plottables; - @FXML - private Button loadConfigButton; + @FXML private ToggleButton startStopButton; @FXML @@ -87,7 +85,7 @@ public class PKT8MainViewController implements Initializable, DeviceListener, Me */ @Override public void initialize(URL url, ResourceBundle rb) { - setupPlotFrame(null); +// setupPlotFrame(Meta.empty()); this.consoleFragment = new ConsoleFragment(); consoleFragment.bindTo(consoleButton); rawDataButton.selectedProperty().addListener(new InvalidationListener() { @@ -103,8 +101,7 @@ public class PKT8MainViewController implements Initializable, DeviceListener, Me }); } - @FXML - private void onLoadConfigClick(ActionEvent event) throws IOException, ParseException, ControlException { + public void startConfigDialog() throws IOException, ParseException, ControlException { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Open configuration file"); fileChooser.setInitialFileName(DEFAULT_CONFIG_LOCATION); @@ -112,7 +109,7 @@ public class PKT8MainViewController implements Initializable, DeviceListener, Me fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("xml", "*.xml", "*.XML")); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("json", "*.json", "*.JSON")); // fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("all", "*.*")); - File cfgFile = fileChooser.showOpenDialog(loadConfigButton.getScene().getWindow()); + File cfgFile = fileChooser.showOpenDialog(startStopButton.getScene().getWindow()); if (cfgFile != null) { setConfig(MetaFileReader.read(cfgFile)); @@ -140,7 +137,7 @@ public class PKT8MainViewController implements Initializable, DeviceListener, Me plotConfig = config.getNode("plotConfig"); } - setupPlotFrame(plotConfig.getNode("plotFrame", null)); + setupPlotFrame(plotConfig.getNode("plotFrame", Meta.empty())); } if (config.hasNode("device")) { @@ -157,8 +154,8 @@ public class PKT8MainViewController implements Initializable, DeviceListener, Me */ private synchronized void setupPlotFrame(Meta plotFrameMeta) { plottables = new TimePlottableGroup(); - plottables.setMaxItems(plotFrameMeta.getInt("maxItems",3000)); - plottables.setMaxAge(Duration.parse(plotFrameMeta.getString("maxAge","PT2H"))); + plottables.setMaxItems(plotFrameMeta.getInt("maxItems", 3000)); + plottables.setMaxAge(Duration.parse(plotFrameMeta.getString("maxAge", "PT2H"))); plotArea.getChildren().clear(); plotFrame = new JFreeChartFrame(plotFrameMeta); PlotUtils.setXAxis(plotFrame, "timestamp", null, "time"); @@ -209,9 +206,6 @@ public class PKT8MainViewController implements Initializable, DeviceListener, Me startStopButton.setDisable(false); } -// public void applyViewConfig(Meta viewConfig) { -// plottables.applyConfig(viewConfig); -// } @Override public void notifyDeviceShutdown(Device device) { @@ -219,15 +213,9 @@ public class PKT8MainViewController implements Initializable, DeviceListener, Me } -// @Override -// public void sendMessage(Device device, int priority, Meta message) { -// String tag = message.getString("tag", ""); -// logArea.appendText(String.format("%s > (%s) [%s] %s%n", device.getName(), Instant.now().toString(), tag, message)); -// } - - @Override public synchronized void onMeasurementResult(Measurement measurement, PKT8Result result, Instant time) { + //PENDING replace by connection? if (rawDataButton.isSelected()) { plottables.put(result.channel, result.rawValue); } else { diff --git a/numass-control/cryotemp/src/main/resources/fxml/PKT8MainView.fxml b/numass-control/cryotemp/src/main/resources/fxml/PKT8MainView.fxml index 54ca0c24..5ab0f2ce 100644 --- a/numass-control/cryotemp/src/main/resources/fxml/PKT8MainView.fxml +++ b/numass-control/cryotemp/src/main/resources/fxml/PKT8MainView.fxml @@ -17,22 +17,23 @@ limitations under the License. --> - - - -
- -
- + + +
+ +
+ - + - -