for (Node node : graphContext.getGraph().getNodes()) { final NodeContext nodeContext = graphContext.getNodeContext(node); currentOperator = nodeContext.getOperator(); if (currentOperator instanceof ReadOp) { final Product product = currentOperator.getTargetProduct();
private void initNodeContext(final NodeContext nodeContext, Operator graphOp) throws GraphException { if (nodeContext.isInitialized()) { return; } for (NodeSource source : nodeContext.getNode().getSources()) { NodeContext sourceNodeContext = getNodeContext(source.getSourceNode()); Product sourceProduct = null; if (sourceNodeContext != null) { initNodeContext(sourceNodeContext, graphOp); sourceProduct = sourceNodeContext.getTargetProduct(); } else { if (graphOp != null) { sourceProduct = graphOp.getSourceProduct(source.getSourceNodeId()); } } if (sourceProduct == null) { throw new GraphException(getMissingSourceMessage(nodeContext.getNode(), source)); } nodeContext.addSourceProduct(source.getName(), sourceProduct); } Node node = nodeContext.getNode(); DomElement configuration = node.getConfiguration(); OperatorConfiguration opConfiguration = this.createOperatorConfiguration(configuration, new HashMap<String, Object>()); nodeContext.setOperatorConfiguration(opConfiguration); nodeContext.initTargetProduct(); getInitNodeContextDeque().addFirst(nodeContext); }
/** * Disposes this {@code GraphContext}. */ public void dispose() { Deque<NodeContext> initNodeContextDeque = getInitNodeContextDeque(); while (!initNodeContextDeque.isEmpty()) { NodeContext nodeContext = initNodeContextDeque.pop(); nodeContext.dispose(); } }
final int numXTiles = dimension.width; final int numYTiles = dimension.height; Dimension tileSize = nodeContextList.get(0).getTargetProduct().getPreferredTileSize(); for (int tileY = 0; tileY < numYTiles; tileY++) { for (int tileX = 0; tileX < numXTiles; tileX++) { fireTileStarted(graphContext, tileRectangle); for (NodeContext nodeContext : nodeContextList) { Product targetProduct = nodeContext.getTargetProduct(); if (nodeContext.canComputeTileStack()) { PlanarImage image = nodeContext.getTargetImage(band); if (image != null) { forceTileComputation(image, tileX, tileY, semaphore, tileScheduler, listeners, PlanarImage image = nodeContext.getTargetImage(band); if (image == null) { if (OperatorContext.isRegularBand(band) && band.isSourceImageSet()) { PlanarImage image = nodeContext.getTargetImage(band); if (image != null) { forceTileComputation(image, tileX, tileY, semaphore, tileScheduler, listeners,
public void testTargetProductIsSetByAnnotation() throws GraphException { Graph graph = new Graph("graph"); Node node = new Node("OutputNotSet", notInitTargetProductOpSPI.getOperatorAlias()); graph.addNode(node); GraphContext graphContext = new GraphContext(graph); NodeContext nodeContext = graphContext.getNodeContext(node); NotInitOutputOperator notInitOutputOperator = (NotInitOutputOperator) nodeContext.getOperator(); assertNotNull("Output of operator is null", notInitOutputOperator.output); assertSame(nodeContext.getTargetProduct(), notInitOutputOperator.output); }
public void testSourceProductWithAlias() throws GraphException { Graph graph = new Graph("graph"); Node goodNode = new Node("Good", goodOpSpi.getOperatorAlias()); Node consumerNode = new Node("AliasConsumer", aliasConsumerOpSpi.getOperatorAlias()); consumerNode.addSource(new NodeSource("alias", "Good")); graph.addNode(goodNode); graph.addNode(consumerNode); GraphContext graphContext = new GraphContext(graph); NodeContext consumerNodeContext = graphContext.getNodeContext(consumerNode); assertSame(((ConsumerWithAliasSourceOperator) consumerNodeContext.getOperator()).input1, consumerNodeContext.getSourceProduct("alias")); }
private void initOutput(Operator graphOp) throws GraphException { for (Node node : getGraph().getNodes()) { NodeContext nodeContext = getNodeContext(node); if (nodeContext.isOutput()) { initNodeContext(nodeContext, graphOp); addOutputNodeContext(nodeContext); } } }
/** * Returns an array containing the output products generated by this graph's output * nodes, i.e. nodes that are not input to other nodes. * * @return an array containing the output products of this graph */ public Product[] getOutputProducts() { Product[] products = new Product[outputNodeContextList.size()]; for (int i = 0; i < products.length; i++) { products[i] = outputNodeContextList.get(i).getTargetProduct(); } return products; }
/** * Creates a GraphContext for the given {@code graph} and a {@code logger}. * * @param graph the {@link org.esa.beam.framework.gpf.graph.Graph} to create the context for * @throws GraphException if the graph context could not be created */ public GraphContext(Graph graph, Operator graphOp) throws GraphException { if (graph.getNodeCount() == 0) { throw new GraphException("Empty graph."); } this.graph = graph; this.logger = BeamLogManager.getSystemLogger(); outputNodeContextList = new ArrayList<>(graph.getNodeCount() / 2); nodeContextMap = new HashMap<>(graph.getNodeCount() * 2); for (Node node : graph.getNodes()) { nodeContextMap.put(node, new NodeContext(this, node)); } initNodeContextDeque = new ArrayDeque<>(graph.getNodeCount()); initNodeDependencies(); initOutput(graphOp); }
public void testAnnotationsProcessed() throws Exception { Graph graph = new Graph("graph"); Node node1 = new Node("node1", "Op1"); Node node2 = new Node("node2", "Op2"); Node node3 = new Node("node3", "Op3"); node2.addSource(new NodeSource("input", "node1")); node3.addSource(new NodeSource("input1", "node1")); node3.addSource(new NodeSource("input2", "node2")); graph.addNode(node1); graph.addNode(node2); graph.addNode(node3); GraphContext graphContext = new GraphContext(graph); NodeContext nodeContext2 = graphContext.getNodeContext(node2); NodeContext nodeContext3 = graphContext.getNodeContext(node3); TestOps.Op2 op2 = ((TestOps.Op2) nodeContext2.getOperator()); TestOps.Op3 op3 = ((TestOps.Op3) nodeContext3.getOperator()); assertNotNull(op2.input); assertSame(nodeContext2.getSourceProduct("input"), op2.input); assertNotNull(op3.input1); assertNotNull(op3.input2); assertSame(nodeContext3.getSourceProduct("input1"), op3.input1); assertSame(nodeContext3.getSourceProduct("input2"), op3.input2); assertNotNull(op3.inputs); assertEquals(0, op3.inputs.length); assertEquals(false, op3.ignoreSign); // has NO default value assertEquals("NN", op3.interpolMethod); // has default value assertEquals(1.5, op3.factor); // has default value }
public void testSourceToNodeResolving() throws GraphException { Graph graph = new Graph("chain1"); Node node1 = new Node("node1", "org.esa.beam.framework.gpf.TestOps$Op1$Spi"); Node node2 = new Node("node2", "org.esa.beam.framework.gpf.TestOps$Op2$Spi"); node2.addSource(new NodeSource("input", "node1")); Node node3 = new Node("node3", "org.esa.beam.framework.gpf.TestOps$Op3$Spi"); node3.addSource(new NodeSource("input1", "node1")); node3.addSource(new NodeSource("input2", "node2")); graph.addNode(node1); graph.addNode(node2); graph.addNode(node3); GraphContext graphContext = new GraphContext(graph); assertEquals(node2.getSource(0).getSourceNode(), node1); assertEquals(node3.getSource(0).getSourceNode(), node1); assertEquals(node3.getSource(1).getSourceNode(), node2); assertFalse(graphContext.getNodeContext(node1).isOutput()); assertFalse(graphContext.getNodeContext(node2).isOutput()); assertTrue(graphContext.getNodeContext(node3).isOutput()); }
private Map<Dimension, List<NodeContext>> buildTileDimensionMap(NodeContext[] outputNodeContexts) { final int mapSize = outputNodeContexts.length; Map<Dimension, List<NodeContext>> tileSizeMap = new HashMap<Dimension, List<NodeContext>>(mapSize); for (NodeContext outputNodeContext : outputNodeContexts) { Product targetProduct = outputNodeContext.getTargetProduct(); Dimension tileSize = targetProduct.getPreferredTileSize(); final int numXTiles = MathUtils.ceilInt(targetProduct.getSceneRasterWidth() / (double) tileSize.width); final int numYTiles = MathUtils.ceilInt(targetProduct.getSceneRasterHeight() / (double) tileSize.height); Dimension tileDim = new Dimension(numXTiles, numYTiles); List<NodeContext> nodeContextList = tileSizeMap.get(tileDim); if (nodeContextList == null) { nodeContextList = new ArrayList<NodeContext>(mapSize); tileSizeMap.put(tileDim, nodeContextList); } nodeContextList.add(outputNodeContext); } return tileSizeMap; }
Node node = getGraph().getNode(referenceNodeId); NodeContext referredNodeContext = getNodeContext(node); Operator operator = referredNodeContext.getOperator(); OperatorConfiguration.PropertyReference propertyReference = new OperatorConfiguration.PropertyReference(parameterName, propertyName, operator); references.add(propertyReference);
@Override public void initialize() throws OperatorException { try { Graph graph = ((Spi) getSpi()).graph; OperatorContext operatorContext = getOperatorContext(); setOperatorParameters(graph, operatorContext); NodeContext targetNodeContext = getTargetNodeContext(graph); if (targetNodeContext == null) { throw new OperatorException("No target node found..."); } setTargetProduct(targetNodeContext.getOperator().getTargetProduct()); } catch (GraphException e) { throw new OperatorException(e); } }
public void testSpiCreation() throws GraphException { Graph graph = new Graph("chain1"); Node node1 = new Node("node1", "Op1"); graph.addNode(node1); GraphContext graphContext = new GraphContext(graph); NodeContext nodeContext = graphContext.getNodeContext(node1); assertEquals("Op1", graph.getNode("node1").getOperatorName()); assertEquals("org.esa.beam.framework.gpf.TestOps$Op1", nodeContext.getOperator().getClass().getName()); }
TestOps.Op4 op4 = (TestOps.Op4) bertNodeContext.getOperator(); final Object targetProperty = op4.getTargetProperty("pi"); assertNotNull(targetProperty); TestOps.Op2 op2 = (TestOps.Op2) bazNodeContext.getOperator(); assertEquals(3.142, op2.threshold, 0.0);
TestOps.Op4 op4 = (TestOps.Op4) bertNodeContext.getOperator(); final Object targetProperty = op4.getTargetProperty("pi"); assertNotNull(targetProperty); TestOps.Op2 op2 = (TestOps.Op2) bazNodeContext.getOperator(); assertEquals(3.142, op2.threshold, 0.0);
TestOps.Op2 op2 = (TestOps.Op2) nodeContext2.getOperator(); assertEquals(0.86, op2.threshold, 1.e-10); TestOps.Op3 op3 = (TestOps.Op3) nodeContext3.getOperator(); assertEquals(true, op3.ignoreSign); assertEquals("A+B", op3.expression);