Constructing a module.

The CAENV1x90 module support comes in the form of a C++ class. In C++, classes can be thought of as data types and operations on variables (called objects) of that data type. The life cycle of an object in C++ is usually:

This section describes how to construct an object of type CCAENV1x90. One of these must be constructed for each CAEN1x90 card you intend to use in your experiment. Two types of construction are possible; static and dynamic.

Dynamic construction, in general is more flexible since it allows the parameters of the constructor to be determined at run time (e.g. by reading an experiment configuration file).

The constructor of an object is always a function named after the class of the object. For the CAENV1x90, the constructor is called CCAENV1x90::CCAENV1x90

The constructor requires the following parameters:

The remainder of this page describes:

In all cases we assume the base address of the module is 0xee000000 of crate 0, to be initialized as virtual module 3.

Constructing a module in traditional Readout

In traditional readout, you should construct a module in the initevt function. Since initevt, clearevt and readevt are all likely to need access to the module, a pointer to modules you are going to create should be declared at file scope. The sample below shows how to do this without re-creating the module object each time.

At File scope, prior to the implementation of initevt, declare a CCAENV1x90 pointer initialized to 0:

#include <CCAENV1x90.h>                 // (1)
...

static CCAENV1x90* pModule(0);          // (2)

  1. The CCAENV1x90.h header file is located in the DAQ include directory. This include directive defines the class and other stuff you may need.
  2. This creates a pointer to a CCAENV1x90 and initializes the value of the pointer to 0. 0 valued pointers are considered invalid (point to nothing). Initializing the pointer to 0 will allow us to determine in initevt() whether or not the module has been created yet. Up until now, no CCAENV1x90 objects have been created.

Within initevt, we will create the module itself. Refer to Initializing the TDC for information about how to initialize the module once its object has been created.

void
initevt ()
{
   ...
   if(!pModule) {                           // (1)
      pModule= new CCAENV1x90(3,
                              0,
                              0xee000000); // (2)
   }
   ...

}

  1. If the module pointer still is zero valued the module has not yet been constructed.
  2. Construct the module. The parameters in order are nSlot, nCrate, nBase as described previously. The module object is dynamically created and a pointer to the module stored in the pModule variable.

Next Initializing the TDC Back Introduction

Constructing a module in production readout

The production readout software operates in a fundamentally different manner than the traditional readout. With production readout, you must generate Event Segments. Event segments are themselves classes, with member data and member functions that operate on these data. Each event segment is be responsible for managing some section of the readout of an experiment. The organization of a large experiment into readout segments is left to the user/programmer.

Logically, event segments should carry the objects that represent the modules they will read as part of their member data. Construction of the Event Segment can imply construction of these objects.

The following code example shows the class definition (header file) of an event segment that contains a single CCAENV1x90 TDC module object:

#ifndef __v1x90segment_h
#define __v1x90segment_h

#include  <CEventSegment.h>
#include <spectrodaq.h>
#include  <CCAENV1x90.h>


class v1x90segment : public CEventSegment      // (1)

{
 private:
  CCAENV1x90  m_TDC;                          // (2)
 public:
  v1x90segment(unsigned int slot, unsigned int crate,
               unsigned long base);           // (3)
  virtual   void Initialize ();
  virtual   DAQWordBufferPtr& Read (DAQWordBufferPtr& rBuffer)   ;
  virtual   void Clear ()   ;
  virtual   unsigned int MaxSize ()   { return 100;} // for compatibility.
  
};


#endif

  1. All event segments must be declared to inherit from CEventSegment, the base class for all event segments.
  2. A CCAENV1x90 object is declared as member data for the class v1x90segment. The name of the object will be m_TDC. By making this object private, only the member functions of v1x90segment can operate on this module. Additional member functions could be defined to support controlled external access to this object.
  3. The constructor of the segment is defined to include the parameters needed to construct the module (m_TDC).

The implementation of the constructor creates the TDC module. Recall that a class construtor is called each time an object of the class type has been created, either dynamically or statically. The constructor code is shown below:

v1x90segment::v1x90segment(unsigned int slot,
                           unsigned int crate,
                           unsigned long base) :  // (1)
  m_TDC(slot, crate, base)                        // (2)
{
}

  1. The : here indicates that the construtor will have an initializer list. An initializer list is a list of constructors either of the base class or of member data. Initializer lists are used to parameterize the constructors of the base class or member data as needed.

Once a v1x90segment is constructed, it will also contain a member object named m_TDC that is a CCAENV1x90 TDC object. The TDC can be controlled by the class member functions through this object.

Next Initializing the TDC Back Introduction


Generated on Wed Sep 17 08:38:10 2008 for NSCL Device support. by  doxygen 1.5.1