Calculations
In this section we want to answer question around specific calculations in jBEAM.
Â
How to use map values in formula?
Only the Formula Editor with Text Resolver allows the direct selection of a map value in the window. For the other two (Formula Editor for numeric Objects, Formula Editor for numeric Channels), the map value must first be converted into a data object.
Proceed as follows:
Use Property → DataItem component (menu: Math → Conversions) and select the requested map value. If the map value provides a measurement unit, this gets also applied to the data object:
Create data object from map property Object 1#Mass test objectThe result from step 1 is a data object you can use in i.e. Formula Editor for numeric Objects:
Force formula from map value and channel
The result of max(abs(A)) in formula editor for numeric object (line by line)is max (A), not considering the negative part
The formula editor (line by line) calculates the complete formula line by line. There are no intermediate channels available but only individual values for each line. Therefore a max() operation can be done only with a direct input channel as argument (max(A)). Then it takes for each line the maximum of the input channel A. Also it does only know the last used input channel was A but not, that another operation was done in between (as max(abs(A))). Therefore any statistical function (max(), min(), …) is only allowed with an input channel as direct argument. In the past we had no statistical functions in this formula editor. But customers wanted formulas as "A - min(A)“ which works as long as these statistical values have only a direct input channel as argument.
The object formula editor works completely different. Each operation is done completely for the whole input object (channel, matrix, single value) and gets the appropriate resulting object. In your sample with A as a channel the intermediate result of abs(A) is a channel and the following max(abs(A)) is the maximum of the intermediate channel, which is a single value.Â
Meanwhile we can say the object formula editor is the favorite one. It is faster has more functions and works better due to its object approach. The formula editor (line by line) should be used only in special circumstances, e.g. with an input channel of a measurement component where the measurement value come into jBEAM value by value, which is line by line.
How can I define several result objects in Inline Java-Class?
Result objects can be defined using parent.setResultObjects(...). By default, a DoubleChannel is created. This can be overwritten in init. Example:
@Override
public void init(InlineUserClassParentIF parent) {
this.parent = parent;
try {
GroupOfChannels result = ProducerUtils.getResultDataObject(parent, "Gruppe", GroupOfChannels.class, true);
StringChannel result2 = ProducerUtils.getResultDataObject(parent, "StringChannel", StringChannel.class, true);
parent.setResultObjects(result, result2);
} catch (Cea2ItemNotAvailable | Cea2UnsupportedDataType e) {
throw new IllegalStateException(e);
}
}
@Override
public void validate() {
if (parent == null) {
return;
}
GroupOfChannels result = (GroupOfChannels) parent.getResultObject(0);
StringChannel result2 = (StringChannel) parent.getResultObject(1);
...