#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();}
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.
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.
CScalerBank::Iterator is an iterator over
the container of CScaler objects
maintained by this class. It supports the following operations:
Returns the CScaler* at this
position in the container.
Advances to the next item in the container. This is a shallow advance.
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.
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.
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++;
}
}
};