CScalerBank

Name

CScalerBank -- Container for individual Scaler objects.

Synopsis


#include <CScalerBank>
         

          class  CScalerBank : public CScaler {
            
  virtual void initialize();
              virtual void clear();
              virtual void disable();
              virtual std::vector<uint32_t> read();
              void AddScalerModule(CScaler* pScaler);
              void DeleteScaler(CScaler* pScaler);
              ScalerIterator begin();
              ScalerIterator end();
              virtual const bool isComposite();
              void visit(CVisitor& visitor);
              size_t leafCount();
              size_t fullCount();
              virtual const bool isComposite();
               virtual  uint64_t timestamp();
               virtual  int sourceId();
             };
         

Description

CScalerBank is an ordered container of CScaler objects. As such, it allows scalers to be organized into a hierarchy (since CScalerBank objects are also CScaler objects they can contain other CScalerBanks).

The CExperiment has a single top level CScalerBank. It is the application's responsibility to put the top level of the scaler readout hierarchy in that CScalerBank. This is normally done in CSkeleton::SetupScalers.

Public member functions

virtual void initialize();

CScaler interface, invokes initialize on all elements of the collection. This performs a deep initialization of the scaler hardware.

virtual void clear();

CScaler Interface. Invokes clear on all members of the collection. This performs a deep clear of the scaler hardware.

virtual void disable();

CScaler interface. invokes disable on all members of the collection. This performs a deep disable of the scaler hardware in the hierarchy below this CScalerBank.

virtual std::vector<uint32_t> read();

CScaler interface. Reads the scalers in the collection in inertion order. The return value is a std::vector of the data read.

void AddScalerModule(CScaler* pScaler);

Adds the CScaler pScaler to the end of the collection maintained by this module.

void DeleteScaler(CScaler* pScaler);

If pScaler is an element of the collection it is removed from the collection. IF pScaler is not in the collection, this function does nothing.

ScalerIterator begin();

Returns a CScalerBank::ScalerIterator which is an iterator to the beginning of the collection. Iterators are pointer like objects. Dereferencing a CScalerBank::ScalerIterator retrieves the CScaler* at the iterator's position in the collection. Incrementing a CScalerBank::ScalerIterator 'points' to the next item in the collection.

See also end below.

ScalerIterator end();

Returns a CScalerBank::ScalerIterator that points off the end of the collection. Since iterators can be compared for equality, this provides a methdo to determine when an iterator has reached the end of iteration.

For example


CScalerBank theBank;
...
CScalerBank::ScalerIterator p = theBank.begin();
while(p != theBank.end()) {
    CScaler* pAScaler = *p;
    ...
    p++;
}
                        

virtual const bool isComposite();

Returns true indicating this scaler is a composite scaler and therefore implements insertion, deletion, visitation and iteration.

void visit(CVisitor& visitor);

Visits (in a shallow way), all members of the container. See the EXAMPLES for a way to do a deep visitation. visitor is a reference to an object from a class derived from CScalerBank::CVisitor. See "Types and public data" below for information about the CScalerBank::CVisitor class.

size_t leafCount();

Performs a deep visitation to count the total number of items in the hierarchy rooted at this object that are not composites. (for which isComposite returns false).

size_t fullCount();

Performs a deep visitation of the container to count the total number of elements regardless of the value returned by isComposite.

virtual uint64_t timestamp();

Returns the 'consensus' timestamp from the scaler bank. Each scaler in the bank is asked for its timestamp. If any return a value other than NULL_TIMESTAMP, the last visited module's timestamp is used as the body header timestamp of the module. If none do, NULL_TIMESTAMP is returned.

Normally there will be one scaler module that understands the timestamp (that module might well not return any scalers). That module's read method should read and save the timestamp for timestamp to return. You are assured that all scaler modules will have their read method invoked before the timestamp methods are invoked.

virtual int sourceId();

Returns the consensus Source id for the most recently read scaler event data. This is done by traversing the scaler modules invoking their sourceId methods. If any of them return other than -1, the value returned by the last such will be returned. If all return -1, that is returned instead. A value of -1 informs the framework to use the source id that was passed on the command line (e.g. via --sourceid).

Types and public data

CScalerBank::Iterator is an iterator over the container of CScaler objects maintained by this class. It supports the following operations:

dereference (unary *)

Returns the CScaler* at this position in the container.

pre/post increment

Advances to the next item in the container. This is a shallow advance.

Comparison (operator==) with other iterators

Determines if two iterators refer to the same location of the container. Along with the end method can use to determine when iterators have gone past the end of the container.

pre/post decrement

Points the iterator at the previous element of the container.

CScalerBank::CVisitor is an abstract base class for objects to be passed to the visit method. This base class has a single, pure virtual method: virtual void operator()(CScaler* pScaler);

This method is called during visitation for each element of the container. pScaler points to the element being visited.

EXAMPLES

The example in this section shows how to do deep visitation. The key is that when the visitor sees visits a composit element, it recursively invokes visit on that element. The example produces statistics on the number leaf and composite elements.

Example 1. Deep visitation in CScalerBank containers


class Statistics : public CScalerBank::CVisitor
{
private:
    unsigned    m_leaves;
    unsigned    m_composites;
public:
    Statitics() :
        m_leaves(0),
        m_composites(0) {}
    unsigned leaves() {return m_leaves;}
    unsigned composites() {return m_composites;}
    
    virtual void operator(CScaler* pScaler) {
        if (pScaler>isComposite()) {
            m_composites++;
            CScalerBank* pBank = reinterpret_cast<ScalerBank*>(pScaler);
            pBank>visit(*this);
        } else {
            m_leaves++;
        }
    }
};
                

SEE ALSO

CScaler