This page describes how to read a trigger matched event from the module. Sample code will be given for both the traditional and production readout skeletons.
The module buffers data in a larg memory buffer. Logic on board, in addition, maintains a FIFO (First In First Out) buffer that contains information that describes each event. The event descriptions allow you to determine, among other things, the size of each event prior to reading it.
The correct sequence to follow inreading out the module is to:
- Wait for the FIFO to have an entry for the event. (CCAENV1x90::isEventFIFOReady).
- Read the FIFO to get the event description. Note that the FIFO can only be read once per event. Its contents are destroyed after being read (CCAENV1x90::ReadEventFIFO).
- Decode the event size from the FIFO. This event size will be the size of TDC data in longwords. Ensure that you have a buffer large enough to hold this data. (CCAENV1x90::FIFOWordCount)
- Invoke the CCAENV1x90::ReadData member to read the event data into your buffer.
- Transfer data from this buffer to the spectrodaq buffer.
In the examples that follow we will not show how to encapsulate data into tagged packets.
See the approprate section below for more information:
The readout of the TDC belongs in the readevt() function of skeleton.cpp. The sample code below waits for data to be present in the FIFO for a fixed number of iterations. If data are in the FIFO, then there will be data in the buffer memory by definition. These data are read out to a temporary buffer and then transferred to the Spectrodaq buffer using the CopyIn function in the spectrodaq client library:
#define TDC_WAITLOOP 5 // (1)
static unsigned long TDCData[32768];
WORD
#ifdef __unix__
readevt (DAQWordBufferPtr& bufpt)
...
for (int i = 0; i < TDC_WAITLOOP; i++) {
if(pModule->isEventFIFOReady()) {
break;
}
}
if(pModule->isEventFIFOReady()) {
unsigned long fifo = pModule->ReadEventFIFO();
unsigned nWords = pModule->FIFOWordCount(fifo);
unsigned nRead = pModule->ReadData(TDCData, nWords);
bufpt.CopyIn(TDCData, 0, nRead*2);
bufpt += nRead*2;
}
...
- TDC_WAITLOOP defines the number of passes through the wait loop we will take before abandoning the wait for the TDC to have data. The value shown represents between 5 and 10 microseconds.
- TDCData is a temporary buffer into which the data will be read. This data buffer is declared to be 32Klongwords big, the size of the internal buffer memory in the TDC.
- This loop waits for the FIFO to indicate an event has been received. The loop is exited as soon as the FIFO has an event description.
- Since the loop can also exit when the count is exhausted, this if ensures that data are actually available from the module.
- The FIFO is read to give an event descriptor.
- The event descriptor is decoded to return the number of longwords of data buffered in the TDC board.
- The data are read into the TDCData buffer and the number of words actually read are returned. The CCAENV1x90::ReadData function understands that the module is in TriggerMatching mode. It will read a complete event from the data buffer and return the number of words it read. If the event was longer than the nWords parameter, then words will be cut out of the end of the event to allow the global trailer to be read into the user's buffer. You can determine that this has happened by noticing a discrepancy between the number of words read out and the number of words the global trailer says should have been read out.
- The CopyIn member is used to copy the data into the spectrodaq data buffer. CopyIn will put the words into the buffer in native machine order: Each 32 bit TDC data longword results in two buffer words. The first word represents the low order 16 bits of the longword, the second word, the high order 16 bits.
- The bufpt buffer pointer is incremented to point to the next free location in the spectrodaq buffer.
Next Clearing data from the module. Back Initializing the TDC Top Introduction
The read operation for the production readout system should be coded in the Read member of the event segment class. The operations this member should perform are analogous to those described in the previous section.
For example:
#define TDC_WAITLOOP 5 // (1)
static unsigned long TDCData[32768];
DAQWordBufferPtr&
v1x90segment::Read(DAQWordBufferPtr& rBuffer)
{
for(int i =0; i < TDC_WAITLOOP; i++ ) {
if(m_TDC.isEventFIFOReady()) {
break;
}
}
if(m_TDC.isEventFIFOReady()) {
unsigned long fifo = m_TDC.ReadEventFIFO();
unsigned nWords = m_TDC.FIFOWordCount(fifo);
unsigned nRead = m_TDC.ReadData(TDCData, nWords);
rBuffer.CopyIn(TDCData, 0, nRead*2);
rBuffer += nRead*2;
}
return rBuffer;
}
- TDC_WAITLOOP defines the number of passes through the wait loop we will take before abandoning the wait for the TDC to have data. The value shown represents between 5 and 10 microseconds.
- TDCData is a temporary buffer into which the data will be read. This data buffer is declared to be 32Klongwords big, the size of the internal buffer memory in the TDC.
- This loop waits for the FIFO to indicate an event has been received. The loop is exited as soon as the FIFO has an event description.
- Since the loop can also exit when the count is exhausted, this if ensures that data are actually available from the `module.
- The FIFO is read to give an event descriptor.
- The event descriptor is decoded to return the number of longwords of data buffered in the TDC board.
- The data are read into the TDCData buffer and the number of words actually read are returned. The CCAENV1x90::ReadData function understands that the module is in TriggerMatching mode. It will read a complete event from the data buffer and return the number of words it read. If the event was longer than the nWords parameter, then words will be cut out of the end of the event to allow the global trailer to be read into the user's buffer. You can determine that this has happened by noticing a discrepancy between the number of words read out and the number of words the global trailer says should have been read out.
- The CopyIn member is used to copy the data into the spectrodaq data buffer. CopyIn will put the words into the buffer in native machine order: Each 32 bit TDC data longword results in two buffer words. The first word represents the low order 16 bits of the longword, the second word, the high order 16 bits.
- The bufpt buffer pointer is incremented to point to the next free location in the spectrodaq buffer.
Next Clearing data from the module. Back Initializing the TDC Top Introduction
Generated on Wed Sep 17 08:38:10 2008 for NSCL Device support. by
1.5.1