These procedures provide a simple method for a user data acquisition/analysis program to access realtime data held in Shared Memory by the MIDAS Tape Server (or equivalent server).
The method used does not require or allow the user program to interact with the flow of data to storage.
The first 24 bytes of the returned data contain a block header (see below) which is the same as the block header used when data is written to disc.
Usage
To initialise and establish connection
int dataSpyOpen(int ID); /* ID = 0 => n */
To close connection
int dataSpyClose(int ID);
To retrieve a data block
int dataSpyRead (int ID, char *data, int length);
This procedure returns the length (in bytes) of the data returned or 0 if no data is available.
ID is the identifier of the shared data area to be used
data is the buffer to be used for the retrieved data
length is the length of this buffer in bytes
Implementation
typedef struct s_data_header { char header_id[8]; // contains the string EBYEDATA long header_sequence; // within the file short header_stream; // data acquisition stream number (in the range 1=>4) short header_tape; // =1 short header_MyEndian; // written as a native 1 by the tape server short header_DataEndian; // written as a native 1 in the hardware structure of the data following long header_dataLen; // total length of useful data following the header in bytes } DATA_HEADER;Following is a simple example of use of the library.
#include <stdio.h> #include <stdlib.h> #include <string.h> extern int dataSpyOpen (int id); extern int dataSpyClose (int id); extern int dataSpyRead (int id, char *data, int length); main (int argc, char **argv) { int buffer32 [16*1024]; int i,j,k; int x; int ID = 0; i = dataSpyOpen (ID); printf ("open = %d\n", i); x = dataSpyRead (ID, (char*)buffer32, 64*1024); if (x > 0) { printf ("read %d\n", x); k=0; for (i = 0; i < 64; i++) { for (j = 0; j < 8; j++) { printf(" 0x%08lx", buffer32[k] & 0x00000000ffffffff); k++; } printf ("\n"); } printf ("\n"); } else {printf ("no data\n");} i = dataSpyClose (ID); printf ("\nclose\n"); }