de.unihalle.informatik.Alida.operator
Class ALDProcessingDAG

java.lang.Object
  extended by de.unihalle.informatik.Alida.operator.ALDProcessingDAG

public class ALDProcessingDAG
extends java.lang.Object

This class handles the construction of a processing DAG from opNode instances and writing this processing history as extended graphml to file.


Nested Class Summary
static class ALDProcessingDAG.HistoryType
          Type of the processing history to be generated.
 
Field Summary
private  java.util.Vector<ALDDataPort> allDataports
           
private  java.util.Vector<ALDEdge> allEdges
           
private  java.util.Vector<ALDOpNode> allOpNodes
           
private static boolean debug
          debug flag for debugging output.
private  int graphIndex
          This index is the index used to build the prefix for all Ids for elements for the next history to add to the current graphml.
private  ALDProcessingDAG.HistoryType historyType
          Type of the history to be generated.
static char idSeparator
          Character separating graphId prefix from rest
private  boolean ignoreHiding
          Ignore hidden flag of opnodes when creating a processing history.
private  java.util.Vector<ALDOpNodePort> opNodePortsTraced
           
private  java.util.Vector<ALDOpNode> opNodesClone
           
private  java.util.Vector<ALDOpNode> opNodesInGraph
           
private  java.util.Vector<ALDDataPort> writtenDataports
           
 
Constructor Summary
ALDProcessingDAG()
           
 
Method Summary
private  void addAttrToEdge(org.graphdrawing.graphml.xmlns.EdgeType edge, java.lang.String key, java.lang.String value)
          Add an attribute to a graphml edge
private  void addAttrToGraph(org.graphdrawing.graphml.xmlns.GraphType graph, java.lang.String key, java.lang.String value)
          Add an attribute to a graphml graph
private  void addAttrToGraphml(org.graphdrawing.graphml.xmlns.GraphmlType graphml, java.lang.String key, java.lang.String value)
          Add an attribute to a graphml element
private  void addAttrToNode(org.graphdrawing.graphml.xmlns.NodeType node, java.lang.String key, java.lang.String value)
          Add an attribute to a graphml node
private  void addAttrToPort(org.graphdrawing.graphml.xmlns.PortType port, java.lang.String key, java.lang.String value)
          Add an attribute to a graphml port
private  org.graphdrawing.graphml.xmlns.NodeType addDataPortToGraphml(org.graphdrawing.graphml.xmlns.GraphType graph, ALDDataPort dataport)
          Add a data port to the graphML graph
private  void addEdge(org.graphdrawing.graphml.xmlns.GraphType graph, ALDPort sourcePort, ALDPort targetPort, int idx)
          Add an graphml edge to graph with index idx
private  void addGraphmlHistory(org.graphdrawing.graphml.xmlns.GraphType graph, ALDDataPort dataport)
          Add the complete history of an object represented by a data port, which was read from a graphml file, to a graph object.
private  void addKey(org.graphdrawing.graphml.xmlns.GraphmlType graphml, java.lang.String id, org.graphdrawing.graphml.xmlns.KeyForType.Enum domain, java.lang.String name, org.graphdrawing.graphml.xmlns.KeyTypeType.Enum keyType)
          add a key definition to graphml
private  org.graphdrawing.graphml.xmlns.NodeType addOpNodePortToGraphml(org.graphdrawing.graphml.xmlns.GraphType graph, ALDOpNodePort port)
          Add a opNode port object to the graphML graph
private  org.graphdrawing.graphml.xmlns.NodeType addOpNodeToGraph(org.graphdrawing.graphml.xmlns.GraphType graph, ALDOpNode opNode)
          Add an opNode to the graph of the enclosing opNode.
private  void addParameterHash(org.graphdrawing.graphml.xmlns.NodeType node, ALDOpNode opNode)
          Add the parameter hash to to a graphml node.
private  void addXmlHistory(org.graphdrawing.graphml.xmlns.NodeType node, org.apache.xmlbeans.XmlObject xmlHistory)
          Add the complete history of a ALDData from a generic XML file to a graphml node.
 org.graphdrawing.graphml.xmlns.GraphmlDocument createGraphmlDocument(java.lang.Object sourceObjOfHistory)
          Create the processing history for sourceObjOfHistory and convert to graphml object.
 org.graphdrawing.graphml.xmlns.GraphmlDocument createGraphmlDocument(java.lang.Object sourceObjOfHistory, ALDProcessingDAG.HistoryType historyType)
          Create the processing history for sourceObjOfHistory and convert to graphml object.
 org.graphdrawing.graphml.xmlns.GraphmlDocument createGraphmlDocument(java.lang.Object sourceObjOfHistory, ALDProcessingDAG.HistoryType historyType, boolean ignoreHiding)
          Create the processing history for sourceObjOfHistory and convert to graphml object.
private  void fatal(java.lang.String msg)
          Output fatal error to stderr and throw an exception
private  void findSibblingsAndParent(ALDOpNode opNode, java.util.Vector<ALDInputPort> inputPorts, int depth)
          Find all sibblings and the parent of opNode.
private  java.lang.String getDataPortId(ALDDataPort dataport)
          Return an ID used in graphml for a data port
static boolean getDebug()
          Return the debug state
(package private) static java.lang.String getGraphId(java.lang.String id)
          Get the graphIP at the beginning of an id up (exculing) idSeparator
(package private) static java.lang.String getGraphName(int idx)
          Return an ID used in graphml for graph
private  java.lang.String getOpNodeId(ALDOpNode opNode)
          Return an ID used in graphml an opNode
private  java.lang.String getPortId(ALDPort p)
          Return an ID used in graphml for a port
private  void handleInputPorts(ALDOpNode parentOpNode, java.util.Vector<ALDInputPort> inputPorts, java.util.Vector<ALDInputPort> parentsInputports, java.util.LinkedList<ALDOutputPort> outputPortToTraceback)
          Trace back each port of inputPorts which are input ports of a child of parentOpNode.
private  void handlePort(ALDOpNode opNode, ALDPort port)
          Handle a port to register the incoming edge and to potentially register dataport to opNode.
private  void inconsistent(java.lang.String msg)
          Output error to stderr
private  boolean isCompleteOpnode(ALDOpNode opNode)
          Is a complete history to be created for this opNode?
private  boolean isHiddenOpnode(ALDOpNode opNode)
          Should we hide this opnode.
private  boolean isToplevelOpnode(ALDOpNode opNode)
          Is this an opNode of the toplevel operator.
private  void outputOpNode(ALDOpNode opNode, org.graphdrawing.graphml.xmlns.GraphType graph)
          Output opNode and it ports, and recursively its children to the graph.
private  void register(ALDOpNode opNode, ALDDataPort dataport)
          Register the dataport as directly included in opNode.
private  void register(ALDOpNode parentOpNode, ALDOpNode opNode)
          Register an opNode as child to its parents if not already found directly or indirectly before.
(package private) static java.lang.String removeGraphId(java.lang.String id)
          Remove the graphIP including idSeparator at the beginning of an id
static void setDebug(boolean value)
          Set the debug state
private  void tracebackDAG(java.lang.Object sourceObjOfHistory)
          Trace back the implicit DAG created during processing for sourceObjOfHistory.
private  java.util.Vector<ALDInputPort> visitOpNode(ALDOpNode opNode, ALDOutputPort portOfInterest, int depth)
          Visit the opNode either completely or according to data dependency as define by the opNode and the globale state of the processing DAG.
private  java.util.Vector<ALDInputPort> visitOpNodeComplete(ALDOpNode opNode, int depth)
          Completely visits this opNode.
private  java.util.Vector<ALDInputPort> visitOpNodeDatadependency(ALDOpNode opNode, ALDOutputPort portOfInterest, int depth)
          Visit the opNode detecting all inner children and data ports on which the output port of interest portOfInterest depends on.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

allDataports

private java.util.Vector<ALDDataPort> allDataports

allEdges

private java.util.Vector<ALDEdge> allEdges

allOpNodes

private java.util.Vector<ALDOpNode> allOpNodes

debug

private static boolean debug
debug flag for debugging output. We make this static to be able to control from outside as instances of this class are created inside methods we use.


graphIndex

private int graphIndex
This index is the index used to build the prefix for all Ids for elements for the next history to add to the current graphml. The currently build graph has index 0.


historyType

private ALDProcessingDAG.HistoryType historyType
Type of the history to be generated.


idSeparator

public static final char idSeparator
Character separating graphId prefix from rest

See Also:
Constant Field Values

ignoreHiding

private boolean ignoreHiding
Ignore hidden flag of opnodes when creating a processing history. i.e. all opnodes are visible.


opNodePortsTraced

private java.util.Vector<ALDOpNodePort> opNodePortsTraced

opNodesClone

private java.util.Vector<ALDOpNode> opNodesClone

opNodesInGraph

private java.util.Vector<ALDOpNode> opNodesInGraph

writtenDataports

private java.util.Vector<ALDDataPort> writtenDataports
Constructor Detail

ALDProcessingDAG

public ALDProcessingDAG()
Method Detail

addAttrToEdge

private void addAttrToEdge(org.graphdrawing.graphml.xmlns.EdgeType edge,
                           java.lang.String key,
                           java.lang.String value)
Add an attribute to a graphml edge


addAttrToGraph

private void addAttrToGraph(org.graphdrawing.graphml.xmlns.GraphType graph,
                            java.lang.String key,
                            java.lang.String value)
Add an attribute to a graphml graph


addAttrToGraphml

private void addAttrToGraphml(org.graphdrawing.graphml.xmlns.GraphmlType graphml,
                              java.lang.String key,
                              java.lang.String value)
Add an attribute to a graphml element


addAttrToNode

private void addAttrToNode(org.graphdrawing.graphml.xmlns.NodeType node,
                           java.lang.String key,
                           java.lang.String value)
Add an attribute to a graphml node


addAttrToPort

private void addAttrToPort(org.graphdrawing.graphml.xmlns.PortType port,
                           java.lang.String key,
                           java.lang.String value)
Add an attribute to a graphml port


addDataPortToGraphml

private org.graphdrawing.graphml.xmlns.NodeType addDataPortToGraphml(org.graphdrawing.graphml.xmlns.GraphType graph,
                                                                     ALDDataPort dataport)
                                                              throws ALDProcessingDAGException
Add a data port to the graphML graph

Throws:
ALDProcessingDAGException

addEdge

private void addEdge(org.graphdrawing.graphml.xmlns.GraphType graph,
                     ALDPort sourcePort,
                     ALDPort targetPort,
                     int idx)
              throws ALDProcessingDAGException
Add an graphml edge to graph with index idx

Throws:
ALDProcessingDAGException

addGraphmlHistory

private void addGraphmlHistory(org.graphdrawing.graphml.xmlns.GraphType graph,
                               ALDDataPort dataport)
                        throws ALDProcessingDAGException
Add the complete history of an object represented by a data port, which was read from a graphml file, to a graph object. Add all nodes and edges (besides the toplevel graph) from the history to the graph object at the toplevel of the graph and connect the output port to the node representing the data port. Rename IDs in the history which is connected.

Parameters:
graph - Graph to add the history read from file
dataport -
Throws:
ALDProcessingDAGException

addKey

private void addKey(org.graphdrawing.graphml.xmlns.GraphmlType graphml,
                    java.lang.String id,
                    org.graphdrawing.graphml.xmlns.KeyForType.Enum domain,
                    java.lang.String name,
                    org.graphdrawing.graphml.xmlns.KeyTypeType.Enum keyType)
add a key definition to graphml


addOpNodePortToGraphml

private org.graphdrawing.graphml.xmlns.NodeType addOpNodePortToGraphml(org.graphdrawing.graphml.xmlns.GraphType graph,
                                                                       ALDOpNodePort port)
                                                                throws ALDProcessingDAGException
Add a opNode port object to the graphML graph

Throws:
ALDProcessingDAGException

addOpNodeToGraph

private org.graphdrawing.graphml.xmlns.NodeType addOpNodeToGraph(org.graphdrawing.graphml.xmlns.GraphType graph,
                                                                 ALDOpNode opNode)
Add an opNode to the graph of the enclosing opNode. Add a node to the graph, set its attributes and properties. Add also also the parameters of the opNode with its values.


addParameterHash

private void addParameterHash(org.graphdrawing.graphml.xmlns.NodeType node,
                              ALDOpNode opNode)
Add the parameter hash to to a graphml node.


addXmlHistory

private void addXmlHistory(org.graphdrawing.graphml.xmlns.NodeType node,
                           org.apache.xmlbeans.XmlObject xmlHistory)
Add the complete history of a ALDData from a generic XML file to a graphml node. The complete xml tree is put in place without any processing.


createGraphmlDocument

public org.graphdrawing.graphml.xmlns.GraphmlDocument createGraphmlDocument(java.lang.Object sourceObjOfHistory)
                                                                     throws ALDProcessingDAGException
Create the processing history for sourceObjOfHistory and convert to graphml object. The complete history according is created. This method is equivalent to createGraphmlDocument( sourceObjOfHistory, HistoryType.COMPLETE, false).

Parameters:
sourceObjOfHistory - for which the processing history to be created.
Returns:
Processing history as graphml object or null if no history is available.
Throws:
ALDProcessingDAGException

createGraphmlDocument

public org.graphdrawing.graphml.xmlns.GraphmlDocument createGraphmlDocument(java.lang.Object sourceObjOfHistory,
                                                                            ALDProcessingDAG.HistoryType historyType)
                                                                     throws ALDProcessingDAGException
Create the processing history for sourceObjOfHistory and convert to graphml object. This method is equivalent to createGraphmlDocument( sourceObjOfHistory, historyType, false).

Parameters:
sourceObjOfHistory - for which the processing history to be written.
historyType - type/moude of history to be created.
Returns:
Processing history as graphml object or null if no history is available.
Throws:
ALDProcessingDAGException

createGraphmlDocument

public org.graphdrawing.graphml.xmlns.GraphmlDocument createGraphmlDocument(java.lang.Object sourceObjOfHistory,
                                                                            ALDProcessingDAG.HistoryType historyType,
                                                                            boolean ignoreHiding)
                                                                     throws ALDProcessingDAGException
Create the processing history for sourceObjOfHistory and convert to graphml object.

Parameters:
sourceObjOfHistory - for which the processing history to be written.
historyType - type/mode of history to be created.
ignoreHiding - if true hiding of opnodes is ignores, i.e. all opnodes added to the history.
Returns:
Processing history as graphml object or null if no history is available.
Throws:
ALDProcessingDAGException

fatal

private void fatal(java.lang.String msg)
            throws ALDProcessingDAGException
Output fatal error to stderr and throw an exception

Throws:
ALDProcessingDAGException

findSibblingsAndParent

private void findSibblingsAndParent(ALDOpNode opNode,
                                    java.util.Vector<ALDInputPort> inputPorts,
                                    int depth)
                             throws ALDProcessingDAGException
Find all sibblings and the parent of opNode. If history is of type data dependency, then find everything on which the inputPorts given as arguments (which are input ports of opNode) depend on. If complete then visit all childs of the opNodes parent completey.

findSibblingsAndParent invokes itself recursively using the input ports of the parent on which the history of the parent depends on. These are all input ports if we visit the parent completely, otherwise the data dependencies of the inputPorts. The recursion terminates at the toplevel operator.

Throws:
ALDProcessingDAGException

getDataPortId

private java.lang.String getDataPortId(ALDDataPort dataport)
Return an ID used in graphml for a data port


getDebug

public static boolean getDebug()
Return the debug state

Returns:
Current debug state

getGraphId

static java.lang.String getGraphId(java.lang.String id)
Get the graphIP at the beginning of an id up (exculing) idSeparator


getGraphName

static java.lang.String getGraphName(int idx)
Return an ID used in graphml for graph


getOpNodeId

private java.lang.String getOpNodeId(ALDOpNode opNode)
Return an ID used in graphml an opNode


getPortId

private java.lang.String getPortId(ALDPort p)
                            throws ALDProcessingDAGException
Return an ID used in graphml for a port

Throws:
ALDProcessingDAGException

handleInputPorts

private void handleInputPorts(ALDOpNode parentOpNode,
                              java.util.Vector<ALDInputPort> inputPorts,
                              java.util.Vector<ALDInputPort> parentsInputports,
                              java.util.LinkedList<ALDOutputPort> outputPortToTraceback)
                       throws ALDProcessingDAGException
Trace back each port of inputPorts which are input ports of a child of parentOpNode. If the origin of such an input port is of type input port, then it is a port of parentOpNode and added to parentsInputports. (As this are the input ports detected according to data dependency.) If it is of type output port, then is is a port of a sibbling and needs to be traced back if the sibbling is not hidden, thus added to outputPortToTraceback. If it is a data port is is just registered.

Throws:
ALDProcessingDAGException

handlePort

private void handlePort(ALDOpNode opNode,
                        ALDPort port)
                 throws ALDProcessingDAGException
Handle a port to register the incoming edge and to potentially register dataport to opNode. Port is either an OutputPort of opNode or an InputPort of a child of opNode. If it is of type DataPort, than a dataport of opNoe is found an registered. A edge to an output port of a child opnode is added only, if this child i snot hidden.

Throws:
ALDProcessingDAGException

inconsistent

private void inconsistent(java.lang.String msg)
Output error to stderr


isCompleteOpnode

private boolean isCompleteOpnode(ALDOpNode opNode)
Is a complete history to be created for this opNode?

Returns:
true if global history type/mode is COMPLETE, or global history type/mode is OPNODETYPE and the opNode is complete. Otherwise false. The only exceptions are opnodes of the ALDToplevelOperator as we have to allow to find the way to operators in other threads.

isHiddenOpnode

private boolean isHiddenOpnode(ALDOpNode opNode)
Should we hide this opnode.

Returns:
true if opNode is hidden and global ignore of hiding is false.

isToplevelOpnode

private boolean isToplevelOpnode(ALDOpNode opNode)
Is this an opNode of the toplevel operator.


outputOpNode

private void outputOpNode(ALDOpNode opNode,
                          org.graphdrawing.graphml.xmlns.GraphType graph)
                   throws ALDProcessingDAGException
Output opNode and it ports, and recursively its children to the graph. An opNode is represented by an node and contains a (graphml) graph as is containts nested ports and further opNodes.

Throws:
ALDProcessingDAGException

register

private void register(ALDOpNode opNode,
                      ALDDataPort dataport)
Register the dataport as directly included in opNode.


register

private void register(ALDOpNode parentOpNode,
                      ALDOpNode opNode)
Register an opNode as child to its parents if not already found directly or indirectly before. This is a child found through connections between ports and not during execution of operators.


removeGraphId

static java.lang.String removeGraphId(java.lang.String id)
Remove the graphIP including idSeparator at the beginning of an id


setDebug

public static void setDebug(boolean value)
Set the debug state

Parameters:
value - New debug state

tracebackDAG

private void tracebackDAG(java.lang.Object sourceObjOfHistory)
                   throws ALDProcessingDAGException
Trace back the implicit DAG created during processing for sourceObjOfHistory. As a side effect the vector allOpNodes, allEdges, allDataports are filled containing all opnodes, dataports and edges as elements of the processing history of sourceObjOfHistory.

Parameters:
sourceObjOfHistory - Object for which the processing history is to be created
Throws:
ALDProcessingDAGException

visitOpNode

private java.util.Vector<ALDInputPort> visitOpNode(ALDOpNode opNode,
                                                   ALDOutputPort portOfInterest,
                                                   int depth)
                                            throws ALDProcessingDAGException
Visit the opNode either completely or according to data dependency as define by the opNode and the globale state of the processing DAG. If history is according to data dependency then trace back the history of portOfInterest which is an output port of opNode.

Returns:
Input ports of opNode on which its history depends on. These are all input ports for a complete history, otherwise the input ports, on which portOfInterest depends on.
Throws:
ALDProcessingDAGException

visitOpNodeComplete

private java.util.Vector<ALDInputPort> visitOpNodeComplete(ALDOpNode opNode,
                                                           int depth)
                                                    throws ALDProcessingDAGException
Completely visits this opNode. Add the opNode to the processing DAG as well as the directly included dataports. All edges within this opNode are also added if not connected to a hidden opnode. Recursively visit all non hidden children of this opNode. We assume that this method is never called for a hidden opNode.

Returns:
All input ports a the history for a complete node depends on all inputs.
Throws:
ALDProcessingDAGException

visitOpNodeDatadependency

private java.util.Vector<ALDInputPort> visitOpNodeDatadependency(ALDOpNode opNode,
                                                                 ALDOutputPort portOfInterest,
                                                                 int depth)
                                                          throws ALDProcessingDAGException
Visit the opNode detecting all inner children and data ports on which the output port of interest portOfInterest depends on. Add the opNode to the processing DAG as well as the detected children and dataports. Recursively visit the detected children of this opNode. The method assumes, that opNode is not hidden.

Returns:
Input ports of this opNode on which the output port of interest portOfInterest depends on.
Throws:
ALDProcessingDAGException