Content-type: text/html
/* Include these: */
#include <config.h>
#include <BufferAnalysis.h>
#include <buffer.h>
#include <buftypes.h>
/* And you get these */
typedef void (NSCLBufferCallback)(unsigned int, const void*, void*);
void ProcessNSCLBuffer(const void* pBuffer); /*!< Process a single buffer */
int ScalersSeen(); /*!< scalers present this run? */
int ScalerCount(); /*!< # scalers this run */
unsigned long LastIncrement(unsigned int n); /*!< increment for a channel */
float Total(unsigned int n); /*!< Totals for a channel */
long LastIntervalStart(); /*!< scaler interval start time */
long LastIntevalEnd(); /*!< Scaler interval end time */
const char* Title(); /*!< Run title. */
unsigned int RunNumber(); /*!< Number of current run */
const char* RunStartTime(); /*!< When the run started. */
const char* RunEndTime(); /*!< When the run ended. */
void AddBufferCallback(NSCLBufferCallback* cb,
unsigned int type,
void* userdata); /*!< add a callback */
void RemoveBufferCallback(NSCLBufferCallback* cb,
unsigned int type,
void* userdata); /*!< get rid of a callback */
/* In your code: */
void* gpTCLApplication;
/* Compile sort of like this */
cc -o yourprogram yourprogram.c -I$SpecTclHome/include -L$SpecTclHome/lib \
-lAnalysis -ltclPlus -lException -lBufferAnalysis
BufferAnalysis provides a C language programming framework for ad-hoc analysis of NSCL data buffers. While this framework is used within SpecTcl for NSCL specific buffer processing, you may also use this framework to build ad-hoc analysis programs that don't depend on SpecTcl to operate.
The software decodes buffers by buffer type and dispatches to an ordered set of callbacks that can be established on each buffer type. The library establishes a standard set of callbacks to support the processing of run state transition and scaler buffers to maintain the information that is provided by the other functions in the library.
See EXAMPLES below for more information about how to use this software.
Note: much error checking that should be done is not done in the examples below in order to keep the brief.
The first example, processes buffers and prints out the scaler totals at the end of a run. Note that this requires on user callbacks.
#include <config.h>
#include <BufferAnalysis.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
int main(int argc, char** argv)
{
unsigned short buffer[4096];
int fd;
int nread;
int i;
fd = open(argv[1], O_RDONLY);
while((nread = read(fd, buffer, sizeof(buffer))) > 0) {
ProcessNSCLBuffer(buffer);
}
printf("File: %s, Run number %d, Title: %sStarted %s Ended %s,
argv[1], RunNumber(), Title(), RunStartTime(), RunEndTime());
printf("Elapsed run time: %d seconds, LastIntervalEnd());
for(i = 0; i < ScalerCount(); i++) {
printf("Scaler channel %d total: %f,
i, Total(i));
}
return 0;
}
The second example establishes a scaler buffer callback that prints out scaler increments and totals for each scaler buffer. It uses the fact that callbacks are ordered to avoid having to actually analyze the buffer as all the information it needs is produced by the standard callbacks. In order to identify the run, a begin run callback is also established.
#include <config.h>
#include <BufferAnalysis.h>
#include <buftypes.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
void BeginCallback(unsigned int ntype, const void* pBuffer, void* pData)
{
const char* pFilename = (const char*)pData;
printf("Starting analysis of %s, Run %d %sun started: %s,
pFilename, RunNumber(), Title(), RunStartTime());
}
void ScalerCallback(unsigned int ntype, const void* pBuffer, void* pData)
{
int i;
printf("---- Scalers from %d sec to %d sec elapsed time----",
LastIntervalStart(), LastIntervalEnd());
for(i =0; i < ScalerCount(); i++) {
printf("Chanel %d Increments %d Totals %d,
i, LastIncrement(i), Total(i));
}
}
int main(int argc, char** argv)
{
unsigned short buffer[4096];
int fd;
int nread;
int i;
fd = open(argv[1], O_RDONLY);
AddBufferCallback(BeginCallback, BEGRUNBF, argv[1]);
AddBufferCallback(ScalerCallback, SCALERBF, NULL);
while((nread = read(fd, buffer, sizeof(buffer))) > 0) {
ProcessNSCLBuffer(buffer);
}
printf("Run Ended %s, RunEndTime());
return 0;
}
void* gpTCLApplication;
The LastIncrement function can only operate over 1/2 full scale range since it uses negative values to return errors. This provides only 31 bits of scaler range, while some NSCL scaler modules support 32 bits of range.