Content-type: text/html Man page of Buffer analysis framework library

Buffer analysis framework library

Section: NSCL Data analysis packages (3)
Updated: 0.1
Index Return to Main Contents
 

NAME

CBufferCallback - A callback class for ad-hoc buffer analysis.  

SYNOPSIS



 /* include: */

#include <config.h>
#include <CBufferCallback.h>

/* to get: */

class CBufferCallback
{
 public:

  // The constructor and destructor are just place holders for now.

  CBufferCallback() {}
  virtual ~CBufferCallback() {}

  int operator==(const CBufferCallback& rhs) const { return 1; }
  int operator!=(const CBufferCallback& rhs) const { return 0; }

  // Class functions:

  virtual void operator()(unsigned int nType, const void* pBuffer) = 0;

};

  /* In your code somewhere: */

  void* gpTCLApplication;

  /* Compile sort of like this */

  c++ -o yourprogram yourprogram.c -I$SpecTclHome/include  -L$SpecTclHome/lib \
        -lAnalysis -ltclPlus -lException -lBufferAnalysis

 

DESCRIPTION

The CBufferCallback class is an abstract base class that you must create a derived class from in order to create callbacks for the C++ buffer analysis framework. See EXAMPLES for an example of how this is supposed to work. Be sure, as well, to see the man page for CBufferProcessor(3). If you are more comfortable programming to a C interface, check out the man page for BufferAnalysis(3).  

PUBLIC INTERFACE

virtual void operator()(unsigned int nType, const void* pBuffer)
You must override this member function in your derived class to supply the behavior you want when your callback is invoked. This member function is called whenever your callback is invoked. The first parameter nType will be the buffer type. The second parameter pBuffer will point to the actual buffer. The headers buffer.h and buftypes.h describe the shape of the buffer and its contents respectively.
 

EXAMPLE

Much of the error handling require for production software is omitted for this example for the sake of brevity.

The example registers a callback object on all buffer types from 0 through MAXBUFTYPE. It counts the number of buffers of each type and, and the end of the data file, prints out the histogram of buffer types with zeroes supressed.


#include <config.h>
#include <CBufferCallback.h>
#include <CBufferProcessor.h>
#include <buftypes.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

#include <Iostream.h>

#ifdef HAVE_STD_NAMESPACE
using namespace std;
#endif

class HistogramCallback : public CBufferCallback
{
private:
  int histogram[MAXBUFTYPE];
public:
  void clear() {
    memset(histogram, 0, sizeof(histogram));
  }
  void dump(ostream& output) {
    for(int i=0; i < MAXBUFTYPE; i++) {
      if(histogram[i] != 0) {
        output << histogram[i] << " instances of buffer type: " << i << endl;
      }
    }
  }
  virtual void operator()(unsigned int ntype, const void* pBuffer) {
    histogram[ntype]++;
  }
};

int main(int argc, char** argv)
{
  unsigned short buffer[4096];
  int fd = open(argv[1], O_RDONLY);
  int nread;
  CBufferProcessor processor;
  HistogramCallback callback;

  for(int i=0; i < MAXBUFTYPE; i++) {
    processor.addCallback(i, callback);
  }

  callback.clear();
  
  while((nread = read(fd, buffer, sizeof(buffer))) > 0) {
    processor(buffer);
  }
  
  cout << "File : " << argv[1] << " run " << processor.runNumber()
       << " " << processor.Title() << endl;
  cout << "Run started: " << processor.runStartTime();
  cout << " Run ended: " << processor.runEndTime() << endl;
  cout << "Buffer type distribution: ;

  callback.dump(cout);
}

void* gpTCLApplication;


 

SEE ALSO

BufferAnalysis(3), CBufferProcessor(3)
 

Index

NAME
SYNOPSIS
DESCRIPTION
PUBLIC INTERFACE
EXAMPLE
SEE ALSO

This document was created by man2html, using the manual pages.
Time: 18:37:14 GMT, February 18, 2005