Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

Buffer arrival events

The main function of the Spectrodaq server is to provide buffers of data, as requested from producers of data. The CBufferEvent class provides the hook to respond to buffers received asyncrhonously. Each BufferEvent class can respond to buffers from a disjoint set of sources (links in Spectrodaq terminology).

In order to understand buffer data sources it is necessary to understand the folowing spectrodaq concepts:

With that understanding we can now look in more detail at the CBufferEvent class and how to use it. To respond to spectrodaq buffers you must:

In the example below, a buffer event is created which listens for, and receives all buffers from the local host. When a buffer is received, the first 64 words (16 bit integers) are dumped to stdout in hex notation with just enough header text to allow us to separate the buffers.

#include <spectrodaq.h>
#include <SpectroFramework.h>
#include <iostream.h>

typedef CBufferEvent<Word> WordBufferEvent;
typedef Pointer<DAQBuffer<Word>,Word> WordPointer;


static const int WordsToDump = 64;
static const int WordsPerLine= 16;
class MyBuffers : public WordBufferEvent
{
  ostream& m_rOutfile;
public:
  MyBuffers(const char* pName, ostream& routfile);
  virtual void OnBuffer(WordPointer& pBuffer);
};

MyBuffers::MyBuffers(const char* pname, ostream& routfile) :
  WordBufferEvent(pname),
  m_rOutfile(routfile)
{}

void
MyBuffers::OnBuffer(WordPointer& pBuffer)
{
  m_rOutfile << "---------------------- buffer -----------------";
  m_rOutfile << hex;
  for(int i =0; i < WordsToDump; i++) {
    if( (i% WordsPerLine) == 0) {
      cout << endl;
    }
    cout << *pBuffer << " ";
    ++pBuffer;
  }
  m_rOutfile << endl;

  m_rOutfile << dec;
}

class MyApp : public DAQROCNode
{
protected:
  int operator() (int argc, char** argv);

};
MyApp theApplication;

int
MyApp::operator()(int argc, char** argv)
{
  MyBuffers Receiver("BuferReceiver", cout);
  Receiver.setBufferTag(0);
  Receiver.setBufferMask(0);
  
  Receiver.AddLink("TCP://localhost:2602/", 0, 0);   // Relieable, all events
  Receiver.Enable();
  
  DAQThreadId id = Receiver.getThreadId();
  
  Join(id);
}


Generated on Thu Jan 6 16:58:45 2005 for Spectrodaq External Event Framework by  doxygen 1.3.9.1