Cleanup of work mechanism
This commit is contained in:
parent
0e55abfabc
commit
068b85c7eb
@ -7,17 +7,13 @@
|
||||
package inr.numass.scripts
|
||||
|
||||
import hep.dataforge.io.ColumnedDataWriter
|
||||
import hep.dataforge.tables.TableFormatBuilder
|
||||
import hep.dataforge.tables.ListTable
|
||||
import hep.dataforge.tables.MapPoint
|
||||
import hep.dataforge.tables.Table
|
||||
import hep.dataforge.tables.TableFormatBuilder
|
||||
import inr.numass.storage.NumassData
|
||||
import inr.numass.data.*
|
||||
import javafx.stage.FileChooser
|
||||
|
||||
|
||||
NumassData.metaClass.findPoint{double u ->
|
||||
delegate.getNMPoints().find{it.getUset() == u}.getMapWithBinning(20,true)
|
||||
delegate.getNMPoints().getWork{it.getUset() == u}.getMapWithBinning(20,true)
|
||||
}
|
||||
|
||||
Map<Double, Double> dif(NumassData data1, NumassData data2, double uset){
|
||||
|
@ -162,7 +162,7 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
|
||||
this.context = this.contextFactory.build(parentContext, config);
|
||||
|
||||
// attachig visual process manager
|
||||
processWindow.setManager(context.taskManager());
|
||||
processWindow.setManager(context.getWorkManager());
|
||||
|
||||
// setting io manager
|
||||
context.setIO(new WorkbenchIOManager(new NumassIO(), this));
|
||||
@ -337,7 +337,7 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
|
||||
runActions();
|
||||
}
|
||||
} else {
|
||||
this.context.taskManager().shutdown();
|
||||
this.context.getWorkManager().shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ public class Workbench extends Application {
|
||||
|
||||
scene.getWindow().setOnCloseRequest((WindowEvent event) -> {
|
||||
try {
|
||||
controller.getContext().taskManager().getRoot().cancel(true);
|
||||
controller.getContext().getWorkManager().getRoot().cancel(true);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import hep.dataforge.context.Context;
|
||||
import hep.dataforge.data.DataNode;
|
||||
import hep.dataforge.data.DataSet;
|
||||
import hep.dataforge.description.TypedActionDef;
|
||||
import hep.dataforge.goals.ProgressCallback;
|
||||
import hep.dataforge.io.ColumnedDataWriter;
|
||||
import hep.dataforge.meta.Meta;
|
||||
import hep.dataforge.stat.fit.FitState;
|
||||
@ -33,7 +32,7 @@ import java.util.Map;
|
||||
public class NumassFitScanSummaryTask extends AbstractTask<Table> {
|
||||
|
||||
@Override
|
||||
protected DataNode<Table> run(TaskModel model, ProgressCallback callback, DataNode<?> data) {
|
||||
protected DataNode<Table> run(TaskModel model, DataNode<?> data) {
|
||||
DataSet.Builder<Table> builder = DataSet.builder(Table.class);
|
||||
Action<FitState, Table> action = new FitSummaryAction();
|
||||
DataNode<FitState> input = data.getCheckedNode("fitscan", FitState.class);
|
||||
|
@ -8,7 +8,6 @@ package inr.numass.workspace;
|
||||
import hep.dataforge.actions.Action;
|
||||
import hep.dataforge.data.DataNode;
|
||||
import hep.dataforge.data.DataTree;
|
||||
import hep.dataforge.goals.ProgressCallback;
|
||||
import hep.dataforge.meta.Meta;
|
||||
import hep.dataforge.meta.MetaBuilder;
|
||||
import hep.dataforge.stat.fit.FitAction;
|
||||
@ -27,7 +26,7 @@ public class NumassFitScanTask extends AbstractTask<FitState> {
|
||||
|
||||
|
||||
@Override
|
||||
protected DataNode<FitState> run(TaskModel model, ProgressCallback callback, DataNode<?> data) {
|
||||
protected DataNode<FitState> run(TaskModel model, DataNode<?> data) {
|
||||
Meta config = model.meta();
|
||||
String scanParameter = config.getString("scan.parameter", "msterile2");
|
||||
|
||||
|
@ -10,7 +10,7 @@ import hep.dataforge.context.Context;
|
||||
import hep.dataforge.data.*;
|
||||
import hep.dataforge.description.DescriptorBuilder;
|
||||
import hep.dataforge.description.NodeDescriptor;
|
||||
import hep.dataforge.goals.ProgressCallback;
|
||||
import hep.dataforge.goals.Work;
|
||||
import hep.dataforge.meta.Meta;
|
||||
import hep.dataforge.meta.Template;
|
||||
import hep.dataforge.storage.api.Loader;
|
||||
@ -35,23 +35,23 @@ import java.net.URI;
|
||||
public class NumassPrepareTask extends AbstractTask<Table> {
|
||||
|
||||
@Override
|
||||
protected DataNode<Table> run(TaskModel model, ProgressCallback callback, DataNode<?> input) {
|
||||
protected DataNode<Table> run(TaskModel model, DataNode<?> input) {
|
||||
Meta config = model.meta();
|
||||
Context context = model.getContext();
|
||||
|
||||
//acquiring initial data. Data node could not be empty
|
||||
Meta dataMeta = config.getMeta("data");
|
||||
URI storageUri = input.getCheckedData("dataRoot", URI.class).get();
|
||||
DataSet.Builder<NumassData> dataBuilder = readData(callback, context, storageUri, dataMeta);
|
||||
DataSet.Builder<NumassData> dataBuilder = readData(getWork(model, input.getName()), context, storageUri, dataMeta);
|
||||
DataNode<NumassData> data = dataBuilder.build();
|
||||
|
||||
//preparing table data
|
||||
Meta prepareMeta = config.getMeta("prepare");
|
||||
DataNode<Table> tables = runAction(new PrepareDataAction(), callback, context, data, prepareMeta);
|
||||
DataNode<Table> tables = runAction(new PrepareDataAction(), context, data, prepareMeta);
|
||||
|
||||
if (config.hasMeta("monitor")) {
|
||||
Meta monitorMeta = config.getMeta("monitor");
|
||||
tables = runAction(new MonitorCorrectAction(), callback, context, tables, monitorMeta);
|
||||
tables = runAction(new MonitorCorrectAction(), context, tables, monitorMeta);
|
||||
}
|
||||
|
||||
//merging if needed
|
||||
@ -62,7 +62,7 @@ public class NumassPrepareTask extends AbstractTask<Table> {
|
||||
|
||||
config.getMetaList("merge").forEach(mergeNode -> {
|
||||
Meta mergeMeta = Template.compileTemplate(mergeNode, config);
|
||||
DataNode<Table> mergeData = runAction(new MergeDataAction(), callback, context, tablesForMerge.build(), mergeMeta);
|
||||
DataNode<Table> mergeData = runAction(new MergeDataAction(), context, tablesForMerge.build(), mergeMeta);
|
||||
mergeData.dataStream().forEach(d -> {
|
||||
resultBuilder.putData("merge." + d.getName(), d.anonymize());
|
||||
});
|
||||
@ -80,7 +80,7 @@ public class NumassPrepareTask extends AbstractTask<Table> {
|
||||
return model;
|
||||
}
|
||||
|
||||
private DataSet.Builder<NumassData> readData(ProgressCallback callback, Context context, URI numassRoot, Meta meta) {
|
||||
private DataSet.Builder<NumassData> readData(Work callback, Context context, URI numassRoot, Meta meta) {
|
||||
|
||||
NumassStorage storage = NumassStorage.buildNumassRoot(numassRoot, true, false);
|
||||
DataFilter filter = new DataFilter().configure(meta);
|
||||
@ -148,7 +148,7 @@ public class NumassPrepareTask extends AbstractTask<Table> {
|
||||
}
|
||||
}
|
||||
|
||||
private <T, R> DataNode<R> runAction(GenericAction<T, R> action, ProgressCallback callback, Context context, DataNode<T> data, Meta meta) {
|
||||
private <T, R> DataNode<R> runAction(GenericAction<T, R> action, Context context, DataNode<T> data, Meta meta) {
|
||||
return action.run(context, data, meta);
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,6 @@ import hep.dataforge.data.Data;
|
||||
import hep.dataforge.data.DataNode;
|
||||
import hep.dataforge.data.DataTree;
|
||||
import hep.dataforge.data.DataUtils;
|
||||
import hep.dataforge.goals.ProgressCallback;
|
||||
import hep.dataforge.io.ColumnedDataWriter;
|
||||
import hep.dataforge.meta.Meta;
|
||||
import hep.dataforge.meta.MetaBuilder;
|
||||
@ -33,6 +32,7 @@ import hep.dataforge.workspace.TaskModel;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
/**
|
||||
* Created by darksnake on 06-Sep-16.
|
||||
@ -44,7 +44,7 @@ public class NumassSubstractEmptySourceTask extends AbstractTask<Table> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DataNode<Table> run(TaskModel model, ProgressCallback callback, DataNode<?> data) {
|
||||
protected DataNode<Table> run(TaskModel model, DataNode<?> data) {
|
||||
DataTree.Builder<Table> builder = DataTree.builder(Table.class);
|
||||
DataNode<Table> rootNode = data.getCheckedNode("prepare", Table.class);
|
||||
Data<? extends Table> emptySource = data.getCheckedNode("empty", Table.class).getData();
|
||||
@ -77,9 +77,7 @@ public class NumassSubstractEmptySourceTask extends AbstractTask<Table> {
|
||||
|
||||
|
||||
private Data<? extends Table> subtractBackground(Data<? extends Table> mergeData, Data<? extends Table> emptyData) {
|
||||
return DataUtils.combine(Table.class, mergeData, emptyData, mergeData.meta(),
|
||||
(Table merge, Table empty) -> subtractBackground(merge, empty)
|
||||
);
|
||||
return DataUtils.combine(Table.class, mergeData, emptyData, mergeData.meta(), (BiFunction<Table, Table, Table>) this::subtractBackground);
|
||||
}
|
||||
|
||||
private Table subtractBackground(Table merge, Table empty) {
|
||||
|
@ -21,7 +21,7 @@ import hep.dataforge.exceptions.StorageException;
|
||||
import hep.dataforge.fx.fragments.FragmentWindow;
|
||||
import hep.dataforge.fx.fragments.LogFragment;
|
||||
import hep.dataforge.fx.work.WorkManagerFragment;
|
||||
import hep.dataforge.goals.ProgressCallback;
|
||||
import hep.dataforge.goals.Work;
|
||||
import inr.numass.NumassProperties;
|
||||
import inr.numass.storage.NumassData;
|
||||
import inr.numass.storage.NumassStorage;
|
||||
@ -131,17 +131,17 @@ public class MainViewerController implements Initializable {
|
||||
}
|
||||
|
||||
private void loadDirectory(String path) {
|
||||
getContext().taskManager().submit("viewer.loadDirectory", (ProgressCallback callback) -> {
|
||||
callback.updateTitle("Load storage (" + path + ")");
|
||||
callback.setProgress(-1);
|
||||
callback.updateMessage("Building numass storage tree...");
|
||||
getContext().getWorkManager().startWork("viewer.loadDirectory", (Work work) -> {
|
||||
work.setTitle("Load storage (" + path + ")");
|
||||
work.setProgress(-1);
|
||||
work.setStatus("Building numass storage tree...");
|
||||
try {
|
||||
NumassStorage root = NumassStorage.buildNumassRoot(path, true, false);
|
||||
setRootStorage(root);
|
||||
Platform.runLater(() -> storagePathLabel.setText("Storage: " + path));
|
||||
} catch (Exception ex) {
|
||||
callback.setProgress(0);
|
||||
callback.updateMessage("Failed to load storage " + path);
|
||||
work.setProgress(0);
|
||||
work.setStatus("Failed to load storage " + path);
|
||||
Logger.getLogger(MainViewerController.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
});
|
||||
@ -153,13 +153,13 @@ public class MainViewerController implements Initializable {
|
||||
|
||||
public void setRootStorage(NumassStorage root) {
|
||||
|
||||
getContext().taskManager().cleanup();
|
||||
getContext().taskManager().submit("viewer.storage.load", (ProgressCallback callback) -> {
|
||||
callback.updateTitle("Fill data to UI (" + root.getName() + ")");
|
||||
getContext().getWorkManager().cleanup();
|
||||
getContext().getWorkManager().startWork("viewer.storage.load", (Work callback) -> {
|
||||
callback.setTitle("Fill data to UI (" + root.getName() + ")");
|
||||
callback.setProgress(-1);
|
||||
Platform.runLater(() -> statusBar.setProgress(-1));
|
||||
|
||||
callback.updateMessage("Loading numass storage tree...");
|
||||
callback.setStatus("Loading numass storage tree...");
|
||||
|
||||
try {
|
||||
new NumassLoaderTreeBuilder().build(callback, numassLoaderDataTree, root, (NumassData loader) -> {
|
||||
@ -179,7 +179,7 @@ public class MainViewerController implements Initializable {
|
||||
|
||||
// callback.setProgress(1, 1);
|
||||
Platform.runLater(() -> statusBar.setProgress(0));
|
||||
callback.updateMessage("Numass storage tree loaded.");
|
||||
callback.setStatus("Numass storage tree loaded.");
|
||||
callback.setProgressToMax();
|
||||
});
|
||||
|
||||
|
@ -26,7 +26,8 @@ import hep.dataforge.context.Encapsulated;
|
||||
import hep.dataforge.names.AlphanumComparator;
|
||||
import hep.dataforge.names.Name;
|
||||
import hep.dataforge.plots.PlotUtils;
|
||||
import hep.dataforge.plots.data.*;
|
||||
import hep.dataforge.plots.data.PlotDataUtils;
|
||||
import hep.dataforge.plots.data.XYPlottable;
|
||||
import hep.dataforge.plots.fx.PlotContainer;
|
||||
import hep.dataforge.plots.jfreechart.JFreeChartFrame;
|
||||
import hep.dataforge.storage.api.PointLoader;
|
||||
@ -46,7 +47,6 @@ import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
/**
|
||||
* FXML Controller class
|
||||
@ -158,7 +158,7 @@ public class MspViewController implements Encapsulated {
|
||||
try {
|
||||
loader.open();
|
||||
List<DataPoint> points = new ArrayList<>();
|
||||
// callback.updateMessage("Loading mass spectrometer data from " + loader.getName());
|
||||
// callback.updateStatus("Loading mass spectrometer data from " + loader.getName());
|
||||
|
||||
DataPoint last = null;
|
||||
|
||||
@ -182,7 +182,7 @@ public class MspViewController implements Encapsulated {
|
||||
|
||||
// public void fillMspData(Storage rootStorage) {
|
||||
// if (rootStorage != null) {
|
||||
// context.taskManager().submit("viewer.msp.fill", (ProgressCallback callback) -> {
|
||||
// context.taskManager().submit("viewer.msp.fill", (TaskCallback callback) -> {
|
||||
// // callback.updateTitle("Fill msp data (" + rootStorage.getName() + ")");
|
||||
//
|
||||
// callback.updateTitle("Load msp data (" + rootStorage.getName() + ")");
|
||||
@ -198,7 +198,7 @@ public class MspViewController implements Encapsulated {
|
||||
// try {
|
||||
// PointLoader mspLoader = (PointLoader) loader;
|
||||
// mspLoader.open();
|
||||
// callback.updateMessage("Loading mass spectrometer data from " + mspLoader.getName());
|
||||
// callback.updateStatus("Loading mass spectrometer data from " + mspLoader.getName());
|
||||
// DataPoint last = null;
|
||||
// for (DataPoint dp : mspLoader) {
|
||||
// mspData.add(dp);
|
||||
@ -211,7 +211,7 @@ public class MspViewController implements Encapsulated {
|
||||
// LoggerFactory.getLogger(getClass()).error("Can't read msp loader data", ex);
|
||||
// }
|
||||
// });
|
||||
// callback.updateMessage("Loading msp data finished");
|
||||
// callback.updateStatus("Loading msp data finished");
|
||||
//// return mspData;
|
||||
//// List<DataPoint> mspData = (List<DataPoint>) loadProcess.getTask().get();
|
||||
//
|
||||
|
@ -16,7 +16,7 @@
|
||||
package inr.numass.viewer;
|
||||
|
||||
import hep.dataforge.exceptions.StorageException;
|
||||
import hep.dataforge.goals.ProgressCallback;
|
||||
import hep.dataforge.goals.Work;
|
||||
import inr.numass.storage.NumassData;
|
||||
import inr.numass.storage.NumassStorage;
|
||||
import javafx.application.Platform;
|
||||
@ -39,7 +39,7 @@ import java.util.function.Consumer;
|
||||
*/
|
||||
public class NumassLoaderTreeBuilder {
|
||||
|
||||
public void build(ProgressCallback callback,
|
||||
public void build(Work callback,
|
||||
TreeTableView<TreeItemValue> numassLoaderDataTree,
|
||||
NumassStorage rootStorage,
|
||||
Consumer<NumassData> numassViewBuilder) throws StorageException {
|
||||
@ -82,7 +82,7 @@ public class NumassLoaderTreeBuilder {
|
||||
}
|
||||
|
||||
private TreeItem<TreeItemValue> buildNode(NumassStorage storage,
|
||||
Consumer<NumassData> numassViewBuilder, ProgressCallback callback) throws StorageException {
|
||||
Consumer<NumassData> numassViewBuilder, Work callback) throws StorageException {
|
||||
TreeItem<TreeItemValue> node = new TreeItem<>(buildValue(storage));
|
||||
node.getChildren().setAll(buildChildren(storage, numassViewBuilder, callback));
|
||||
return node;
|
||||
@ -93,7 +93,7 @@ public class NumassLoaderTreeBuilder {
|
||||
}
|
||||
|
||||
private List<TreeItem<TreeItemValue>> buildChildren(NumassStorage storage,
|
||||
Consumer<NumassData> numassViewBuilder, ProgressCallback callback) throws StorageException {
|
||||
Consumer<NumassData> numassViewBuilder, Work callback) throws StorageException {
|
||||
List<TreeItem<TreeItemValue>> list = new ArrayList<>();
|
||||
|
||||
storage.shelves().values().stream().forEach(subStorage -> {
|
||||
@ -110,13 +110,13 @@ public class NumassLoaderTreeBuilder {
|
||||
}
|
||||
});
|
||||
|
||||
callback.updateMessage("Building storage " + storage.getName());
|
||||
callback.setStatus("Building storage " + storage.getName());
|
||||
callback.setProgress(0);
|
||||
callback.setMaxProgress(storage.loaders().size());
|
||||
storage.loaders().values().stream()
|
||||
.forEach(loader -> {
|
||||
if (loader instanceof NumassData) {
|
||||
callback.updateMessage("Building numass data loader " + loader.getName());
|
||||
callback.setStatus("Building numass data loader " + loader.getName());
|
||||
NumassData numassLoader = (NumassData) loader;
|
||||
TreeItem<TreeItemValue> numassLoaderTreeItem = new TreeItem<>(buildValue(numassLoader));
|
||||
list.add(numassLoaderTreeItem);
|
||||
@ -124,13 +124,13 @@ public class NumassLoaderTreeBuilder {
|
||||
callback.increaseProgress(1);
|
||||
});
|
||||
|
||||
callback.updateMessage("Loading legacy DAT files");
|
||||
callback.setStatus("Loading legacy DAT files");
|
||||
callback.setProgress(0);
|
||||
List<NumassData> legacyFiles = storage.legacyFiles();
|
||||
callback.setMaxProgress(legacyFiles.size());
|
||||
//adding legacy data files
|
||||
for (NumassData legacyDat : legacyFiles) {
|
||||
callback.updateMessage("Loading numass DAT file " + legacyDat.getName());
|
||||
callback.setStatus("Loading numass DAT file " + legacyDat.getName());
|
||||
TreeItem<TreeItemValue> numassLoaderTreeItem = new TreeItem<>(buildValue(legacyDat));
|
||||
callback.increaseProgress(1);
|
||||
list.add(numassLoaderTreeItem);
|
||||
|
@ -22,7 +22,7 @@ package inr.numass.viewer;
|
||||
*/
|
||||
|
||||
import hep.dataforge.context.Context;
|
||||
import hep.dataforge.goals.ProgressCallback;
|
||||
import hep.dataforge.goals.Work;
|
||||
import hep.dataforge.io.ColumnedDataWriter;
|
||||
import hep.dataforge.meta.Meta;
|
||||
import hep.dataforge.meta.MetaBuilder;
|
||||
@ -217,8 +217,8 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
|
||||
public void loadData(NumassData data) {
|
||||
this.data = data;
|
||||
if (data != null) {
|
||||
context.taskManager().<List<NMPoint>>submit("viewer.numass.load", (ProgressCallback callback) -> {
|
||||
callback.updateTitle("Load numass data (" + data.getName() + ")");
|
||||
context.getWorkManager().<List<NMPoint>>startWork("viewer.numass.load", (Work callback) -> {
|
||||
callback.setTitle("Load numass data (" + data.getName() + ")");
|
||||
points = data.getNMPoints();
|
||||
|
||||
Platform.runLater(() -> {
|
||||
@ -242,7 +242,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
|
||||
}
|
||||
|
||||
private void setupHVPane(Supplier<Table> hvData) {
|
||||
context.taskManager().submit("viewer.numass.hv", (ProgressCallback callback) -> {
|
||||
context.getWorkManager().startWork("viewer.numass.hv", (Work callback) -> {
|
||||
Table t = hvData.get();
|
||||
Platform.runLater(() -> {
|
||||
if (t != null) {
|
||||
@ -346,7 +346,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
|
||||
detectorPlot.removePlot();
|
||||
}
|
||||
|
||||
context.taskManager().submit("viewer.numass.load.detector", (ProgressCallback callback) -> {
|
||||
context.getWorkManager().startWork("viewer.numass.load.detector", (Work callback) -> {
|
||||
Meta plottableConfig = new MetaBuilder("plot")
|
||||
.setValue("connectionType", "step")
|
||||
.setValue("thickness", 2)
|
||||
|
Loading…
Reference in New Issue
Block a user