class VoltWatcher

A class for watching volts

Public Methods

void SetWriter(VoltBase* VWrite)
Assign a VoltBase object
void Reset()
Clear buffers and start over

Public

Constructors / Destructors
VoltWatcher(Dacc& In, int ID, const char* configfile, u_short bufSize=10)
Automatic constructor
VoltWatcher(char* channel, float offset, float scale, int ID, u_short bufSize=10)
Explicit constructor
~VoltWatcher()
Destructor
Processing functions
Fill the Dacc for one second
void AppendBuffers()
Update the active buffer
Wait for up to one minute
int Analyze()
Adjust the passive buffer and perform all calculations
void Watch(const u_short duration=0, const u_short delay=61)
Monitor one channel
Calculation functions
float RMS()
Root mean square
fComplex GetCoef(const float freq) const
Find a complex Fourier coefficient
float ApproxMaxF(const float freq, const bool YNPrint=NOPRINT) const
Find a dominant frequency
float Harmonics(const float freq)
Harmonic properties
Accessor functions
bool GetErrorStatus() const
Get the error status
int GetID() const
Get the ID
char* GetChannelName() const
Get the channel name

Protected Fields

const int _ID
Channel ID (and slot in a VoltBase)
char* _chanName
Name of the monitored channel
VoltBase* _VWrite
Pointer to the VoltBase (where data is sent)
const u_short _bufSize
Number of seconds in a filled buffer
u_long n
Number of data points in a filled buffer
float dt
Sampling interval
Hanning window
Cleans up the frequency spectrum
float _offset
DC offset
float _scale
How much to scale down amplitude
TSeries* TS
Pointer to the channel's TSeries in the Dacc
TSeries tVolt_even
Even buffer
TSeries tVolt_odd
Odd buffer
fComplex* S
Pointer to a complex array copied from passive buffer
bool _bufStat
Denotes the active buffer (EVEN or ODD)
u_short _bufCount
Number of seconds currently filled in the active buffer
bool _errStat
Denotes whether an error occured during configuration

Protected Methods

void GetConfiguration(Dacc& In, const char* configfile)
Get the VoltWatcher's configuration from file
void VoltWatcher::TestChannel(Dacc& In, const int decim8)
Test whether the channel name is OK.
void ErrMsg(const char* message)
Flags an error (sets <b>_errStat</b> to <b>true</b>) and displays an error message

Documentation

A VoltWatcher object is designed to read real-time data from an LHO online power-monitoring channel and periodically produce calculations. It obtains data via its static Dacc (Data Access) member and processes the data using a two-buffer system. A VoltWatcher contains two TSeries buffers - an "even" buffer and an "odd" one. A buffer is either "passive" or "active". "Active" means it is in the process of being filled with data, and "passive" means it is not. While the active buffer is being filled, calculations can be performed on the passive buffer. Once the active buffer is full, it becomes passive, and the other buffer is cleared and becomes active. <p> A VoltWatcher sends its calculations to a VoltBase object (if one has been assigned) and does not output its results any other way. A VoltWriter (or another object derived from VoltBase) should always accompany a VoltWatcher so that the results can be printed to the screen, saved to a file, etc. <p> CAUTION: Although the internal timing of the VoltWatcher object is automatic, its member functions must be carefully implemented externally in order for it to work properly. A simple example program for monitoring one channel is vwatch.cc; a more complicated program for monitoring several channels at once is multivw.cc. <p> NOTE: VoltWatchers get their configurations from config.vw - if the sampling rate specified is less than 2048 Hz or not a power of 2, it will be rejected.

Source code: VoltWriter.hh, VoltWriter.cc and VWMath.cc

Constructors / Destructors

VoltWatcher(Dacc& In, int ID, const char* configfile, u_short bufSize=10)
Construct a VoltWatcher based on an entry in the config.vw file
Parameters:
ID - The channel ID in config.vw
bufSize - Number of seconds in a filled buffer (default=10)

VoltWatcher(char* channel, float offset, float scale, int ID, u_short bufSize=10)
Construct a VoltWatcher explicitly
Parameters:
channel - The channel name (e.g. "H0:PEM-LVEA_V1")
offset - The DC offset in ADC units
scale - The ratio of ADC units to volts
ID - The channel ID in config.vw
bufSize - Number of seconds in a filled buffer

~VoltWatcher()
Destructor

Processing functions

Fills the Dacc for one second (for all channels added!)
Returns:
The GPS time (in seconds) at which the method was called

void AppendBuffers()
Appends the time series data in the Dacc to the active buffer. If the buffer was full, it is cleared first. If the buffer becomes filled, it becomes passive, and the other buffer becomes active.

Any frames waiting in the Dacc's buffer are skipped. <b>Fill ()</b> is then called until the current GPS time has a value of <b>delay</b> in the seconds field. For example, if <b>Delay (30)</b> is called at 12:16:45, the current time will be 12:16:30 when it is finished. If <b>delay</b> is 60 or greater, <b>Fill ()</b> will not be called.
Parameters:
delay - GPS seconds field to wait for

int Analyze()
The passive buffer is "fixed" - i.e. the DC offset is removed, the amplitude is scaled down from ADC units to volts, and a Hanning window is applied. All calculations are then performed on this data. The results and the start time of the data are sent to a VoltBase object if the VoltWatcher has been assigned to one.

void Watch(const u_short duration=0, const u_short delay=61)
The channel is monitored for the specified duration by continuously filling the buffers and making calculations. If the duration is set to zero, the method will run indefinitely. <b>Delay ()</b> is used before beginning.
Returns:
The VoltWatcher's ID
Parameters:
duration - Number of buffers to fill before completion
delay - GPS seconds field to wait for before beginning

Calculation functions

float RMS()
Calculate the root mean square of a TSeries object
Returns:
The root mean square of the time series
Parameters:
tVolt - A time series object

fComplex GetCoef(const float freq) const
The data in the passive buffer is used to calculate the complex Fourier coefficient for the given frequency.
Returns:
The Fourier coefficient as a complex float object
Parameters:
freq - Frequency

float ApproxMaxF(const float freq, const bool YNPrint=NOPRINT) const
The frequency with the highest amplitude in a small neighborhood is found for the passive buffer. The center of that neighborhood (i.e. an initial guess) is required.
Returns:
The dominant frequency in the neighborhood of the specified frequency
Parameters:
freq - Best guess of what the frequency should be
YNPrint - If PRINT is specified, the amplitude of the frequency found will be written to the screen

float Harmonics(const float freq)
The amplitudes and phases of all harmonics of the specified fundamental frequency (up to the Nyquist frequency) are calculated. The amplitudes are expressed as a percentage of the fundamental frequency's. The phases are relative to the fundamental frequency and are expressed in degrees. The total harmonic distortion is also calculated and returned. All results are sent to a VoltBase object if one has been assigned.
Returns:
The total harmonic distortion
Parameters:
freq - The fundamental frequency
YNPrint - If PRINT is specified, all amplitudes and phases will be written to the screen

Accessor functions

bool GetErrorStatus() const
Get the error status
Returns:
<b>true</b> if an error has occurred

int GetID() const
A VoltWatcher's ID number is also the slot number in its VoltBase
Returns:
The ID

char* GetChannelName() const
Get the name of the channel being monitored
Returns:
Channel name

void SetWriter(VoltBase* VWrite)
The VoltWriter will now send its calculations to the VoltBase specified by the pointer. One should make sure that two channels with the same ID number do not use the same VoltBase. VoltWriter's <b>addSlot ()</b> function is safer to use.
Parameters:
VWrite - A VoltBase pointer

void Reset()
Clear the data out of both buffers, set the buffer status to EVEN, and set the count to zero. These are the conditions immediately after construction.

void GetConfiguration(Dacc& In, const char* configfile)
Called during construction. Uses the ID number to get configuration information from config.vw. Information includes channel name, DC offset, scaling factor, and sampling rate. Errors are tested for and flagged if found. <b>TestChannel ()</b> is also called - a decimation factor is passed to it if the sampling rate is over 2048 Hz.
Parameters:
configfile - configuration file

void VoltWatcher::TestChannel(Dacc& In, const int decim8)
Tests whether the channel name is OK. An error is flagged if the channel is already requested on the Dacc or if the channel is not found. If the Dacc is having trouble reading frames, <b>exit ()</b> is called. The channel name is added to the Dacc (with a decimation factor) only if it checks out.
Parameters:
decim8 - Factor by which to pre-decimate data from the channel

void ErrMsg(const char* message)
Flags an error (sets <b>_errStat</b> to <b>true</b>) and displays an error message
Parameters:
message - Error message to display

const int _ID
Channel ID (and slot in a VoltBase)

char* _chanName
Name of the monitored channel

VoltBase* _VWrite
Pointer to the VoltBase (where data is sent)

const u_short _bufSize
Number of seconds in a filled buffer

u_long n
Number of data points in a filled buffer

float dt
Sampling interval

Hanning window
Cleans up the frequency spectrum

float _offset
DC offset

float _scale
How much to scale down amplitude

TSeries* TS
Pointer to the channel's TSeries in the Dacc

TSeries tVolt_even
Even buffer

TSeries tVolt_odd
Odd buffer

fComplex* S
Pointer to a complex array copied from passive buffer

bool _bufStat
Denotes the active buffer (EVEN or ODD)

u_short _bufCount
Number of seconds currently filled in the active buffer

bool _errStat
Denotes whether an error occured during configuration


This class has no child classes.
Author:
Charlie Shapiro
Version:
1.0; Last modified July 26, 2000
See Also:
VoltBase
VoltWriter
TSeries
Dacc

alphabetic index hierarchy of classes


generated by doc++