Difference between revisions of "RRM 3-14 Compression"

From EPICSWIKI
(→‎special: Fix: ALG and N are SPC_RESET, not SPC_NOMOD.)
(HOPR, LOPR fields FLOAT -> DOUBLE)
 
(4 intermediate revisions by 2 users not shown)
Line 25: Line 25:
=== Read Parameters and Algorithm Parameters ===
=== Read Parameters and Algorithm Parameters ===


These fields determine what channel to read and how to compress the data. The user specifies the algorithm to be used in the ALG field. There are five possible algorithms which can be specified as follows:
These fields determine what channel to read and how to compress the data. The user specifies the algorithm to be used in the ALG field. There are six possible algorithms which can be specified as follows:


* <CODE>Circular Buffer</CODE>
* <CODE>Circular Buffer</CODE>
Line 32: Line 32:
* <CODE>N to 1 High Value</CODE>
* <CODE>N to 1 High Value</CODE>
* <CODE>N to 1 Average</CODE>
* <CODE>N to 1 Average</CODE>
* <CODE>N to 1 Median</CODE>


These algorithms are explained in one of the sections below.
These algorithms are explained in one of the sections below.
Line 41: Line 42:
<TH>Field<TH>Summary<TH>Type<TH>DCT<TH>Initial<TH>Access<TH>Modify<TH>Rec Proc Monitor<TH>PP<TR>
<TH>Field<TH>Summary<TH>Type<TH>DCT<TH>Initial<TH>Access<TH>Modify<TH>Rec Proc Monitor<TH>PP<TR>
<TD>RES<TD>Reset<TD>SHORT<TD>No<TD>0<TD>Yes<TD>Yes<TD>No<TD>No<TR>
<TD>RES<TD>Reset<TD>SHORT<TD>No<TD>0<TD>Yes<TD>Yes<TD>No<TD>No<TR>
<TD>ALG<TD>Algorithm<TD>[[RRM 3-14 Menu Choices|RECCHOICE]]<TD>Yes<TD>0<TD>Yes<TD>No<TD>No<TD>No<TR>
<TD>ALG<TD>Algorithm<TD>[[RRM 3-14 Menu Choices|RECCHOICE]]<TD>Yes<TD>0<TD>Yes<TD>Yes<TD>No<TD>No<TR>
<TD>NSAM<TD>Number in Sample<TD>ULONG<TD>Yes<TD>1<TD>Yes<TD>No<TD>No<TD>No<TR>
<TD>NSAM<TD>Number in Sample<TD>ULONG<TD>Yes<TD>1<TD>Yes<TD>No<TD>No<TD>No<TR>
<TD>N<TD>Number<TD>ULONG<TD>Yes<TD>1<TD>Yes<TD>No<TD>No<TD>No<TR>
<TD>N<TD>Number<TD>ULONG<TD>Yes<TD>1<TD>Yes<TD>Yes<TD>No<TD>No<TR>
<TD>ILIL<TD>Initial Low Interest Value<TD>FLOAT<TD>Yes<TD>0<TD>Yes<TD>Yes<TD>No<TD>No<TR>
<TD>ILIL<TD>Initial Low Interest Value<TD>DOUBLE<TD>Yes<TD>0<TD>Yes<TD>Yes<TD>No<TD>No<TR>
<TD>IHIL<TD>Initial High Interest Value<TD>FLOAT<TD>Yes<TD>0<TD>Yes<TD>Yes<TD>No<TD>No
<TD>IHIL<TD>Initial High Interest Value<TD>DOUBLE<TD>Yes<TD>0<TD>Yes<TD>Yes<TD>No<TD>No
</TABLE>
</TABLE>


Line 60: Line 61:
The <CODE>Circular Buffer</CODE> algorithm keeps a circular buffer of length NSAM. Each time the record is processed, it gets the data referenced by INP and puts it into the circular buffer referenced by VAL. Note that when INP refers to a scalar, VAL is just a time ordered circular buffer of values obtained from INP.
The <CODE>Circular Buffer</CODE> algorithm keeps a circular buffer of length NSAM. Each time the record is processed, it gets the data referenced by INP and puts it into the circular buffer referenced by VAL. Note that when INP refers to a scalar, VAL is just a time ordered circular buffer of values obtained from INP.


<CODE>Average</CODE> takes an average of all the elements of the array obtained from INP; that is, the entire array referenced by INP is retrieved, and the average of the elements is placed in the next element of the circular buffer. The retrieved array is truncated to be of length NSAM. N successive arrays are averaged and placed in the circular buffer. Thus, VAL[0] holds the average of the first sampling of INP, VAL[1] holds the average of the next sampling of INP, and so on. The following shows the equation:
<CODE>Average</CODE> takes an average of every element of the array obtained from INP over time; that is, the entire array referenced by INP is retrieved, and for each element the new average is calculated and placed in the corresponding element of the value buffer. The retrieved array is truncated to be of length NSAM. N successive arrays are averaged and placed in the buffer. Thus, VAL[0] holds the average of the first element of INP over N samples, VAL[1] holds the average of the next element of INP over N samples, and so on. The following shows the equation:


[[Image:RRM 3-14 Compression-1.gif]]
[[Image:RRM 3-14 Compression-1.gif]]


If <CODE>N to 1 Low Value</CODE>, <CODE>N to 1 High Value</CODE>, or <CODE>N to 1 Average</CODE> are chosen, then VAL is a circular buffer of NSAM samples. The actual algorithm depends on whether INP references a scalar or an array. If INP refers to a scalar, then N successive time ordered samples of INP are taken. After the Nth sample is obtained a new value, determined by the algorithm (LOW, HIGH, or AVE), is written to the circular buffer referenced by VAL. If LOW, the lowest value is written; if HIGH, the highest value of all the samples is written; and if AVE, the average of all the samples are written.
If any of the <CODE>N to 1</CODE>algorithms are chosen, then VAL is a circular buffer of NSAM samples.
 
The actual algorithm depends on whether INP references a scalar or an array. If INP refers to a scalar, then N successive time ordered samples of INP are taken. After the Nth sample is obtained a new value, determined by the algorithm (Lowest, Highest, or Average), is written to the circular buffer referenced by VAL. If <CODE>Low Value</CODE> the lowest value of all the samples is written; if <CODE>High Value</CODE> the highest value is written; and if <CODE>Average</CODE>, the average of all the samples are written.  The <CODE>Median</CODE> setting behaves like <CODE>Average</CODE> with scalar input data.


If INP refers to an array, then the following applies:
If INP refers to an array, then the following applies:


; <CODE>N to 1 Low Value</CODE>
; <CODE>N to 1 Low Value</CODE>
: Compress N to 1 samples, keeping the lowest value
: Compress N to 1 samples, keeping the lowest value.
; <CODE>N to 1 High Value</CODE>
; <CODE>N to 1 High Value</CODE>
: Compress N to 1 samples, keeping the highest value
: Compress N to 1 samples, keeping the highest value.
; <CODE>N to 1 Average</CODE>
; <CODE>N to 1 Average</CODE>
: Compress N to 1 samples, taking the average
: Compress N to 1 samples, taking the average value.
; <CODE>N to 1 Median</CODE>
: Compress N to 1 samples, taking the median value.


The compression record keeps (NSAM) data samples.
The compression record keeps NSAM data samples.


The N field determines the number of fields to compress into 1.
The field N determines the number of elements to compress into each result.


Thus, if NSAM was 3, and N was also equal to 3, then the algorithms would work as in the following diagram:
Thus, if NSAM was 3, and N was also equal to 3, then the algorithms would work as in the following diagram:
Line 83: Line 88:
[[Image:RRM 3-14 Compression-2.gif]]
[[Image:RRM 3-14 Compression-2.gif]]


OFF number of samples are ignored at the beginning of the array being compressed. IHIL and ILIL are used as initial value filters when compressing arrays; that is, the compression does not begin until a value is found that is either greater than IHIL or less than ILIL
IHIL and ILIL can be set to provide an initial value filter on the input array. If ILIL &lt; IHIL input elements will be skipped until a value is found that is in the range ILIL to IHIL.


RES resets the algorithm before the maximum number of samples are reached.
RES resets the algorithm before the maximum number of samples are reached.


=== Operator Display Parameters ===
=== Operator Display Parameters ===
Line 104: Line 108:
<TH>Field<TH>Summary<TH>Type<TH>DCT<TH>Initial<TH>Access<TH>Modify<TH>Rec Proc Monitor<TH>PP<TR>
<TH>Field<TH>Summary<TH>Type<TH>DCT<TH>Initial<TH>Access<TH>Modify<TH>Rec Proc Monitor<TH>PP<TR>
<TD>EGU<TD>Engineering Units<TD>STRING [16]<TD>Yes<TD>null<TD>Yes<TD>Yes<TD>No<TD>No<TR>
<TD>EGU<TD>Engineering Units<TD>STRING [16]<TD>Yes<TD>null<TD>Yes<TD>Yes<TD>No<TD>No<TR>
<TD>HOPR<TD>High Operating Range<TD>FLOAT<TD>Yes<TD>0<TD>Yes<TD>Yes<TD>No<TD>No<TR>
<TD>HOPR<TD>High Operating Range<TD>DOUBLE<TD>Yes<TD>0<TD>Yes<TD>Yes<TD>No<TD>No<TR>
<TD>LOPR<TD>Low Operating Range<TD>FLOAT<TD>Yes<TD>0<TD>Yes<TD>Yes<TD>No<TD>No<TR>
<TD>LOPR<TD>Low Operating Range<TD>DOUBLE<TD>Yes<TD>0<TD>Yes<TD>Yes<TD>No<TD>No<TR>
<TD>PREC<TD>Display Precision<TD>SHORT<TD>Yes<TD>0<TD>Yes<TD>Yes<TD>No<TD>No<TR>
<TD>PREC<TD>Display Precision<TD>SHORT<TD>Yes<TD>0<TD>Yes<TD>Yes<TD>No<TD>No<TR>
<TD>NAME<TD>Record Name<TD>STRING [29]<TD>Yes<TD>0<TD>Yes<TD>No<TD>No<TD>&nbsp;<TR>
<TD>NAME<TD>Record Name<TD>STRING [29]<TD>Yes<TD>0<TD>Yes<TD>No<TD>No<TD>&nbsp;<TR>
<TD>DESC<TD>Description<TD>STRING [29]<TD>Yes<TD>Null<TD>Yes<TD>Yes<TD>No<TD>No
<TD>DESC<TD>Description<TD>STRING [29]<TD>Yes<TD>Null<TD>Yes<TD>Yes<TD>No<TD>No
</TABLE>
</TABLE>


=== Alarm Parameters ===
=== Alarm Parameters ===

Latest revision as of 12:29, 3 December 2012

EPICS Record Reference Manual


compress - Compression

The data compression record is used to collect and compress data from arrays. When the INP field references a data array field, it immediately compresses the entire array into an element of an array using one of several algorithms, overwriting the previous element. If the INP field obtains its value from a scalar-value field, the compression record will collect a new sample each time the record is processed and add it to the compressed data array as a circular buffer.

The INP link can also specify a constant; however, if this is the case, the compression algorithms are ignored, and the record support routines merely return after checking the FLNK field.

Parameter Fields

The data compression fields fall into the following categories:

  • scan parameters
  • read parameters
  • operator display parameters
  • run-time parameters

Scanning Parameters

The compression record has the standard fields for specifying under what circumstances the record will be processed. These fields are listed in Scan Fields. In addition, Scanning Specification explains how these fields are used. Since the compression record supports no direct interfaces to hardware, its SCAN field cannot specify I/O Intr.


Read Parameters and Algorithm Parameters

These fields determine what channel to read and how to compress the data. The user specifies the algorithm to be used in the ALG field. There are six possible algorithms which can be specified as follows:

  • Circular Buffer
  • Average
  • N to 1 Low Value
  • N to 1 High Value
  • N to 1 Average
  • N to 1 Median

These algorithms are explained in one of the sections below.

The RES field can be accessed at run time to cause the algorithm to reset itself.


FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
RESResetSHORTNo0YesYesNoNo
ALGAlgorithmRECCHOICEYes0YesYesNoNo
NSAMNumber in SampleULONGYes1YesNoNoNo
NNumberULONGYes1YesYesNoNo
ILILInitial Low Interest ValueDOUBLEYes0YesYesNoNo
IHILInitial High Interest ValueDOUBLEYes0YesYesNoNo


Input Specification

The input specification should be a database or channel access link. Though INP can be a constant, the data compression algorithms are supported only when INP is a database link. See Address Specification for information on specifying links.


Algorithms and Related Fields

As stated above, the ALG field specifies which algorithm to be performed on the data. The rest of the fields--NSAM, N, ILIL, IHIL, and OFF--are used in the compressions, though N is not used in the Circular Buffer algorithm and ILIL, IHIL, and OFF are used neither in the Circular Buffer algorithm nor in the Average algorithm.

The Circular Buffer algorithm keeps a circular buffer of length NSAM. Each time the record is processed, it gets the data referenced by INP and puts it into the circular buffer referenced by VAL. Note that when INP refers to a scalar, VAL is just a time ordered circular buffer of values obtained from INP.

Average takes an average of every element of the array obtained from INP over time; that is, the entire array referenced by INP is retrieved, and for each element the new average is calculated and placed in the corresponding element of the value buffer. The retrieved array is truncated to be of length NSAM. N successive arrays are averaged and placed in the buffer. Thus, VAL[0] holds the average of the first element of INP over N samples, VAL[1] holds the average of the next element of INP over N samples, and so on. The following shows the equation:

RRM 3-14 Compression-1.gif

If any of the N to 1algorithms are chosen, then VAL is a circular buffer of NSAM samples.

The actual algorithm depends on whether INP references a scalar or an array. If INP refers to a scalar, then N successive time ordered samples of INP are taken. After the Nth sample is obtained a new value, determined by the algorithm (Lowest, Highest, or Average), is written to the circular buffer referenced by VAL. If Low Value the lowest value of all the samples is written; if High Value the highest value is written; and if Average, the average of all the samples are written. The Median setting behaves like Average with scalar input data.

If INP refers to an array, then the following applies:

N to 1 Low Value
Compress N to 1 samples, keeping the lowest value.
N to 1 High Value
Compress N to 1 samples, keeping the highest value.
N to 1 Average
Compress N to 1 samples, taking the average value.
N to 1 Median
Compress N to 1 samples, taking the median value.

The compression record keeps NSAM data samples.

The field N determines the number of elements to compress into each result.

Thus, if NSAM was 3, and N was also equal to 3, then the algorithms would work as in the following diagram:

RRM 3-14 Compression-2.gif

IHIL and ILIL can be set to provide an initial value filter on the input array. If ILIL < IHIL input elements will be skipped until a value is found that is in the range ILIL to IHIL.

RES resets the algorithm before the maximum number of samples are reached.

Operator Display Parameters

These parameters are used to present meaningful data to the operator. They display the value and other parameters of the record either textually or graphically.

The HOPR and LOPR fields only specify the range for VAL, HIHI, HIGH, LOLO and LOW fields.

PREC controls the floating-point precision whenever get_precision is called, and the field being referenced is the VAL field (i.e., one of the values contained in the circular buffer).

The EGU field should be given a string that describes the value of VAL, but is used whenever the get_units record support routine is called.

See Fields Common to All Record Types for more on the record name (NAME) and description (DESC) fields.


FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
EGUEngineering UnitsSTRING [16]YesnullYesYesNoNo
HOPRHigh Operating RangeDOUBLEYes0YesYesNoNo
LOPRLow Operating RangeDOUBLEYes0YesYesNoNo
PRECDisplay PrecisionSHORTYes0YesYesNoNo
NAMERecord NameSTRING [29]Yes0YesNoNo 
DESCDescriptionSTRING [29]YesNullYesYesNoNo

Alarm Parameters

The compression record has the alarm parameters common to all record types. Alarm Fields lists other fields related to a alarms that are common to all record types.


Run-time Parameters

These parameters are used by the run-time code for processing the data compression algorithm. They are not configurable by the user, though some are accessible at run-time. They can represent the current state of the waveform or of the record whose field is referenced by the INP field.

NUSE holds the number of elements currently stored in VAL.

BPTR is a pointer that refers to the buffer referenced by VAL.

The SPTR field pointer to an array that is used for array averages.

WPTR is used by the dbGetlinks routines.


FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
NUSENumber UsedULONGNo0YesNoNoNo
BPTRBuffer PointerNOACCESSNo0NoNoNo 
SPTRSumming Buffer PointerNOACCESSNo0NoNoNo 
WPTRWork Buffer PointerNOACCESSNo0NoNoNo 
CVBCompress Value BufferDOUBLENo0YesNoNoNo
INXCurrent Index of Circular BufferULONGNo0YesNoNoNo


Record Support

Record Support Routines

init_record

Space for all necessary arrays is allocated. The addresses are stored in the appropriate fields in the record.

process

See next section.

special

This routine is called when RSET, ALG, or N are set. It performs a reset.

get_value

Fills in the values of struct valueDes so that they refer to VAL.

cvt_dbaddr

This is called by dbNameToAddr. It makes the dbAddr structure refer to the actual buffer holding the result.

get_array_info

Obtains values from the circular buffer referenced by VAL.

put_array_info

Writes values into the circular buffer referenced by VAL.

get_units

Retrieves EGU.

get_precision

Retrieves PREC.

get_graphic_double

Sets the upper display and lower display limits for a field. If the field is VAL, the limits are set to HOPR and LOPR, else if the field has upper and lower limits defined they will be used, else the upper and lower maximum values for the field type will be used.

get_control_double

Sets the upper control and the lower control limits for a field. If the field is VAL, the limits are set to HOPR and LOPR, else if the field has upper and lower limits defined they will be used, else the upper and lower maximum values for the field type will be used.

Record Processing

Routine process implements the following algorithm:

  1. If INP is not a database link, check monitors and the forward link and return.
  2. Get the current data referenced by INP.
  3. Perform the appropriate algorithm:
    • Average: Read N successive instances of INP and perform an element by element average. Until N instances have been obtained it just return without checking monitors or the forward link. When N instances have been obtained complete the algorithm, store the result in the VAL array, check monitors and the forward link, and return.
    • Circular Buffer: Write the values obtained from INP into the VAL array as a circular buffer, check monitors and the forward link, and return.
    • N to 1 xxx and INP refers to a scalar: Obtain N successive values from INP and apply the NTO1xxx algorithm to these values. Until N values are obtained monitors and forward links are not checked. When N successive values have been obtained, complete the algorithm, check monitors and the forward link, and return.
    • N to 1 xxx and INP refers to an array: The ILIL and IHIL are honored if ILIL < IHIL. The input array is divided into subarrays of length N. The specified N to 1 xxx compression algorithm is applied to each sub-array and the result stored in the array referenced by VAL. The monitors and forward link are checked.
  4. If success, set UDF to FALSE.
  5. Check to see if monitors should be invoked:
    • Alarm monitors are invoked if the alarm status or severity has changed.
    • NSEV and NSTA are reset to 0.
  6. Scan forward link if necessary, set PACT FALSE, and return.




EPICS Record Reference Manual - 19 MAY 1998