CRingScalerItem

Name

CRingScalerItem -- Encapsulate ring buffer scaler items.

Synopsis


#include <CRingScaleritem.h>
         
 class CRingScalerItem {

  CRingScalerItem(size_t numScalers);
  CRingScalerItem(uint32_t startTime, uint32_t stopTime, time_t timestamp, std::vector<uint32_t> scalers);
  CRingScalerItem(const CRingItem& rhs)
          throws std::bad_cast;
  CRingScalerItem(const CRingScalerItem& rhs);

  virtual ~CRingScalerItem();

  CRingScalerItem& operator=(const CRingScalerItem& rhs);
  const int operator==(const CRingScalerItem& rhs);
  int operator!=(const CRingScalerItem& rhsconst );
  void setStartTime(uint32_t startTime);
  const uint32_t getStartTime();
  void setEndTime(uint32_t endTime);
  const uint32_t getEndTime();
  void setTimestamp(time_t stamp);
  const time_t getTimestamp();
  void setScaler(uint32_t channel, uint32_t value)
          throws CRangeError;
  const uint32_t getScaler(uint32_t channel)
          throws CRangeError;
  const std::vector<uint32_t> getScalers();
  const uint32_t getScalerCount();
}

Description

CRingScalerItem encapsulates scaler items that either have been gotten from a ring or are being formatted to be inserted into a ring.

Public member functions

CRingScalerItem(size_t numScalers);

Constructor for a ring scaler item that will hold numScalers incremental scaler values. The interval start and stop times are set to zero and the timestamp to the current time. Scaler values are not initialized (specifically don't assume they are zero).

CRingScalerItem(uint32_t startTime, uint32_t stopTime, time_t timestamp, std::vector<uint32_t> scalers);

Full constructor for a scaler ring item. startTime is the number of seconds of active run time at the start of the interval measured by these scalers, and stopTime the end. timestamp is the absolute time of the end of the measurement interval (or more accurately, the time at which the scaler item was formatted). sclaers are a vector of scaler values.

CRingScalerItem(const CRingItem& rhs) throws std::bad_cast;

Constructs a scaler item from an existing ring item rhs. If rsh's type is not INCREMENTAL_SCALERS, a std::bad_cast exception is thrown.

CRingScalerItem(const CRingScalerItem& rhs);

Constructs a functional duplicate of the scaler item rhs (copy construction).

CRingScalerItem& operator=(const CRingScalerItem& rhs);

Assigns to this object from rhs. The object will become a functional equivalent of rhs. If later compared to rhs equality will be true.

const int operator==(const CRingScalerItem& rhs);

Compares rhs with the object for functional equivalency.

int operator!=(const CRingScalerItem& rhsconst );

Compares the item for functional equivalency and returns the logical inverse of the result.

void setStartTime(uint32_t startTime);

Sets the interval start time offset to startTime. This is supposed to be the time into the run at which this set of scalers started counting. Inactive run time is not counted.

const uint32_t getStartTime();

Returns the counting interval start time.

void setEndTime(uint32_t endTime);

Sets the intervale end time to endTime. This is supposed to be the number of seconds in to the run at which the scalers for this item were read and cleared. Note that only active seconds are acounted.

const uint32_t getEndTime();

Returns the time offset into the run at which the scalers were read. For a properly formatted item, this value should be larger than that returned by getStartTime.

void setTimestamp(time_t stamp);

Sets the timestamp for the item. This should be the time at which the buffer was formatted. It is a time_t as described in documentation of the unix time function.

const time_t getTimestamp();

Returns the timestamp for an item. This is supopsed to be compatible for the argument to e.g. ctime in the byte order of the creating system.

void setScaler(uint32_t channel, uint32_t value) throws CRangeError;

Sets the value of scaler number channel to value. If channel is larger than the number of scalers the item was constructed with, CRangError is thrown.

const uint32_t getScaler(uint32_t channel) throws CRangeError;

Returns the value of the scaler channel channel. If the channel is too large a CRangeError is thrown.

const std::vector<uint32_t> getScalers();

Returns a vector that consists of the values of all of the incremental scalers in the item.

const uint32_t getScalerCount();

Returns the number of scalers in the item.

Types and public data

See the ScalerItem type in <DataFormat.h>.

Exceptions

std::bad_cast

This is thrown in the event an attempt is made to construct a CRingScalerItem object from a CRingItem whose type is not INCREMENTAL_SCALERS.

CRangeError

Thrown in the event an effort is made to access a scaler channel that does not exist.

EXAMPLES

In the following example, an item is gotten from a ring buffer. If it is a scaler item, it is used to construct a new scaler item. ring is assumed to be a CRingBuffer object or a reference to one.

Example 1. Constructing a scaler item from an item gotten from a ring


#include <DataFormat.h>
#include <CRingItem.h>
#include <CRingScalerItem>
...

CAllButPredicate  all;                                        (1)
CRingItem*        pItem = CRingItem::getFromRing(ring, all);  (2)

if (pItem->type() == INCREMENTAL_SCALERS) {                   (3)
   CRingScalerItem scalers(*pItem);                           (4)
   ...
}
else {
...
}
delete pItem;                                                (5)
 
            
(1)
This predicate accepts all ring buffer item types without sampling. The CAllButPredicate accepts all ring types without sampling except those explicitly defined.
(2)
Gets the next item from the ring, regardless of type.
(3)
Before constructing a CRingScalerItem object, it's important to ensure the object is atually a scaler item. Without this check it would be necessary to wrap this code in a try/catch block for std::bad_cast.
(4)
If the item is a scaler item, it is converted into a CScalerItem and processed.
(5)
Regardless, the original CRingItem object must be deleted.