Chapter 2. Setting up the software
Í As previously mentioned, our event processor class must be derived from a CEventProcessor.
This class definition does that.
Ï The TreeParameter package provides both individual parameters (CTreeParameter), and arrays of
parameters, (CTreeParameterArray). In this application we will create a
CTreeParameterArray that will have one element for each channel of the CAEN V785. This data
member will be a reference to that array. A reference in C++ is a variable that operates like a pointer
with the notation of something that is not a pointer. For example, if I have a pointer p to a structure
containing an element b, I would access that element using the notation: p->b. If I have a reference r
to the same structure, I would access element b using the notation r.b.
Ð The m_nId member variable will be used to hold the id of the packet our event processor is
supposed to decode.
Ñ The m_nSlot member variable will be used to hold the geographical address of the CAEN V785
we are unpacking. This member is used as a sanity check. Sanity checks double check that the code
you write is operating the way you think it should. In this case, if the packet that matches our id does
not contain data that is from the ADC with the correct geographical address, we know that
something has gone seriously wrong. It is a good practice to employ sanity checks whenever you can
think of one.
Ò The constructor is called to initialize the members of an object of class MyEventProcessor. It’s
parameters are as follows:
ourId
Provides the packet id that this object will locate and unpack. By parameterizing this, our class
can unpack more than one packet id as long as the packet body is data from a single CAEN
V785 ADC
ourSlot
Provides the slot number of the ADC we expect to see in the packet of type ourId. This
enables us to perform the sanity check we described earlier.
baseParameterName
CTreeParameter objects have a parameter name, this parameter name becomes the SpecTcl
parameter name. In the case of CTreeParameterArray objects, the parameter name becomes
a base name and actual parameters have a period and an element number appended to this
basename. For example, a ten parameter array with the base name george might create
SpecTcl parameters george.00, george.01 ... george.09. The baseParameterName
will be used to set the CTreeParameterArray base name.
(10) A destructor is necessary when classes use dynamcially allocated data, in order to prevent memory
leaks when an object is destroyed.
(11) operator() allows objects of a class to be treated as functions that can be called. Objects of this
sort behave as functions that can retain state between calls. The function call operator of a
CEventProcessor is a virtual function which means that the appropriate function for pointer to an
object derived from CEventProcessor will be selected at run time from the actual class of the
object the pointer points to (in this case a MyEventProcessor. The function call operator for
19
Comentários a estes Manuais