OutputPortExtender - How to add a precondition

radone
radone New Altair Community Member
edited November 5 in Community Q&A
I have input port extender defined as folows:
private OutputPortExtender innerOut1 = new OutputPortExtender(
"Example Set", getSubprocess(0).getInnerSources());
The code is generated from operator and therefore it is not possible to use any passthrough rule.

How can I add a Metadata precodndition to the innerOut1 port?

This approach failed:
innerOut1.deliverMetaData(getMetadata());
private List<MetaData> getMetadata() {
List<MetaData> metadata = new Vector<MetaData>();
metadata.add(new MetaData(ExampleSet.class));
return metadata;
}
Thanks in advance for any help.

Answers

  • fischer
    fischer New Altair Community Member
    Hi,

    output ports don't have preconditions. For InputPortExtenders, you either pass it a desiredMetaData in the constuctor if your precondition is as simple as requiring an IOObject of a certain type, or you override makePrecondition.

    The rules for the output ports are handeled just as those of any other port.

    Best,
    Simon
  • StaryVena
    StaryVena New Altair Community Member
    Hi,
    I can't figure out, how to add generation rule for OutputPortExtender.
    Simon Fischer wrote:


    The rules for the output ports are handeled just as those of any other port.

    This is defined only for OutputPort.
    getTransformer().addGenerationRule(port, IOObject.class);
    How can I do same thing for OutputPortExtender?

    Thanks for your answers.
  • StaryVena
    StaryVena New Altair Community Member
    I made small work around by modifying OneToManyPassThroughRule class:

    public class ManyGenerationRule implements MDTransformationRule {

    private final Collection<OutputPort> outputPorts;
    MetaData metaData;

    public ManyGenerationRule(OutputPorts outputPorts, MetaData metaData) {
    this(outputPorts.getAllPorts(), metaData);
    }

    public ManyGenerationRule(Collection<OutputPort> outputPorts, MetaData metaData) {
    this.outputPorts = outputPorts;
    this.metaData = metaData;
    }

    @Override
    public void transformMD() {
    int i = 0;
    for (OutputPort outputPort : outputPorts) {
    if (metaData != null) {
    metaData = metaData.clone();
    metaData.addToHistory(outputPort);
    outputPort.deliverMD(metaData);
    } else {
    outputPort.deliverMD(null);
    }
    i++;
    }
    }
    }
    But I'm not sure if it is good solution of this problem. Is there better way to solve it?
  • IngoRM
    IngoRM New Altair Community Member
    Hi,

    Simon is out of office right now but I am sure he will come back to you later.

    Cheers,
    Ingo
  • fischer
    fischer New Altair Community Member
    Hi StaryVena,

    I think your solution is perfect. To be honest, I don't know why we don't have a ready-made class like the one you posted, but I also can't think of an operator that would use it - why would an operator produce several identical objects? May I ask what your application is, maybe I can make a better proposal then.

    Best,
    Simon
  • StaryVena
    StaryVena New Altair Community Member
    Simon Fischer wrote:

    ..., but I also can't think of an operator that would use it - why would an operator produce several identical objects? May I ask what your application is, maybe I can make a better proposal then.
    It is inner output port of OperatorChain. Segmented image comes to outer input port  and to inner operators is sent only one segment per one subprocess run. Segmented image and one segment have different IOObject class. It could be used Multiply operator and single output port, but almost always will be used several inner operators. Thats why I prefer output port extender instead of single port.

    Thank you for your answer.
    Ciao
    StaryVena
  • fischer
    fischer New Altair Community Member
    Hi,

    then I think your solution is fine.

    Best,
    Simon