rrdService.util
Class MathExpressionVirtualDataSource

java.lang.Object
  |
  +--rrdService.util.MathExpressionVirtualDataSource
All Implemented Interfaces:
java.io.Serializable

public class MathExpressionVirtualDataSource
extends java.lang.Object
implements java.io.Serializable

The class MathExpressionVirtualDataSource Create a new virtual data source by evaluating a mathematical expression, specified in Reverse Polish Notation (RPN). If you have ever used a traditional HP calculator you already know RPN. The idea behind RPN notation is, that you have a stack and push your data onto this stack. When ever you execute an operation, it takes as many data values from the stack as needed. The pushing of data is implicit, so when ever you specify a number or a variable, it gets pushed automatically.

If this is all a big load of incomprehensible words for you, maybe an example helps (a more complete explanation is given in [1]): The expression vname+3/2 becomes vname,3,2,/,+ in RPN. First the three values get pushed onto the stack (which now contains (the current value of) vname, a 3 and a 2). Then the / operator pops two values from the stack (3 and 2), divides the first argument by the second (3/2) and pushes the result (1.5) back onto the stack. Then the + operator pops two values (vname and 1.5) from the stack; both values are added up and the result gets pushes back onto the stack. In the end there is only one value left on the stack: The result of the expression.

The rpn-expression in the CDEF function takes both, constant values as well as vname variables. The following operators can be used on these values:

+, -, *, /, %
pops two values from the stack applies the selected operator and pushes the result back onto the stack. The % operator stands for the modulo operation.

SIN, COS, LOG, EXP, FLOOR, CEIL
pops one value from the stack, applies the selected function and pushes the result back onto the stack.

LT, LE, GT, GE, EQ
pops two values from the stack, compares them according to the selected condition and pushes either 1 back onto the stack if the condition is true and 0 if the condition was not true.

IF
pops three values from the stack. If the last value is not 0, the second value will be pushed back onto the stack, otherwise the first value is pushed back.

If the stack contains the values A, B, C, D, E are presently on the stack, the IF operator will pop the values E D and C of the stack. It will look at C and if it is not 0 it will push D back onto the stack, otherwise E will be sent back to the stack.

MIN, MAX
selects the lesser or larger of the two top stack values respectively

LIMIT
replaces the value with *UNKNOWN* if it is outside the limits specified by the two values above it on the stack.
  CDEF:a=alpha,0,100,LIMIT

DUP, EXC, POP
These manipulate the stack directly. DUP will duplicate the top of the stack, pushing the result back onto the stack. EXC will exchange the top two elements of the stack, and POP will pop off the top element of the stack. Having insufficient elements on the stack for these operations is an error.

UN
Pops one value off the stack, if it is *UNKNOWN*, 1 will be pushed back otherwise 0.

UNKN
Push an *UNKNOWN* value onto the stack.

PREV
Push *UNKNOWN* if its at the first value of a data set or otherwise the value of this CDEF at the previous time step. This allows you to perform calculations across the data.

INF, NEGINF
Push a positive or negative infinite (oo) value onto the stack. When drawing an infinite number it appears right at the top or bottom edge of the graph, depending whether you have a positive or negative infinite number.

NOW
Push the current (real world) time onto the stack.

TIME
Push the time the current sample was taken onto the stack. This is the number of non-skip seconds since 0:00:00 January 1, 1970.

LTIME
This is like TIME + current timezone offset in seconds. The current offset takes daylight saving time into account, given your OS supports this. If you were looking at a sample, in Zurich, in summer, the offset would be 2*3600 seconds, as Zurich at that time of year is 2 hours ahead of UTC.

Note that the timezone offset is always calculated for the time the current sample was taken at. It has nuthing todo with the time you are doing the calculation.

Please note that you may only use vname variables that you previously defined by either DEF or CDEF. Furthermore, as of this writing (version 0.99.25), you must use at least one vname per expression, that is ``CDEF:fourtytwo=2,40,+'' will yield an error message but not a vname fourtytwo that's always equal to 42.

Version:
1.0 date : 15/07/2001
Author:
Damien Pellier
See Also:
MathExpressionVirtualDataSource, RoundRobinGraphic, Serialized Form

Field Summary
private  java.lang.String rpnExpression
          rpnExpression of this virtual data source
private  java.lang.String virtualName
          virtualName virtual name for a data source
 
Constructor Summary
MathExpressionVirtualDataSource(java.lang.String virtualName, java.lang.String rpnExpression)
          Constructor of MathExpressionVirtualDataSource
 
Method Summary
 java.lang.String getRpnExpression()
          Returns the rpnExpression of this virtual data source
 java.lang.String getVirtualName()
          Returns the the virtual name for a data source
 void setRpnExpression(java.lang.String rpnExpression)
          Replaces the rpnExpression of this virtual data source
 void setVirtualName(java.lang.String virtualName)
          Replaces the the virtual name for a data source
 java.lang.String toString()
          Returns a string representation of this virtual data source built from a rpn expression
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

rpnExpression

private java.lang.String rpnExpression
rpnExpression of this virtual data source

virtualName

private java.lang.String virtualName
virtualName virtual name for a data source
Constructor Detail

MathExpressionVirtualDataSource

public MathExpressionVirtualDataSource(java.lang.String virtualName,
                                       java.lang.String rpnExpression)
Constructor of MathExpressionVirtualDataSource
Parameters:
virtualName - the virtual name for a data source
rpnExpression - the rpnExpression of this virtual data source
Method Detail

getRpnExpression

public java.lang.String getRpnExpression()
Returns the rpnExpression of this virtual data source

getVirtualName

public java.lang.String getVirtualName()
Returns the the virtual name for a data source

setRpnExpression

public void setRpnExpression(java.lang.String rpnExpression)
Replaces the rpnExpression of this virtual data source
Parameters:
rpnExpression - the rpnExpression of this virtual data source to set

setVirtualName

public void setVirtualName(java.lang.String virtualName)
Replaces the the virtual name for a data source
Parameters:
virtualName - the virtual name for a data source to set

toString

public java.lang.String toString()
Returns a string representation of this virtual data source built from a rpn expression
Overrides:
toString in class java.lang.Object

Copyright 1885-2001 FIRMENICH SA, Geneva

Submit a bug or feature
Copyright 1885-2001 FIRMENICH SA, Geneva,
All Rights Reserved.