GLAST / LAT > DAQ and FSW > FSW > Doxygen Index> GRBP / dev > grbstream / mv2304
#include <GRBP/io/GRB_stream.h>
#include <GRB/GRB_pktdef.h>
#include <GRB/GRB_msgdef.h>
#include <PBI/PTR.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
Classes | |
struct | _streamCloseCbp |
Structure to bind the close callback routine with a parameter. More... | |
struct | _GRB_streamHeader |
Standard header for both input and output streams. More... | |
struct | _GRB_istreamBody |
Internal structure used to control the input access to an GRB file or data section. More... | |
struct | _GRB_ostreamBody |
Context for an output event/packet stream. More... | |
union | _GRB_streamBody |
Union of all the stream types. More... | |
union | _GRB_stream |
Standard GRB stream handle. More... | |
Typedefs | |
typedef enum _GRB_STREAM_DIR_K | GRB_STREAM_DIR_K |
Typedef for enum _GRB_STREAM_DIR_K. | |
typedef enum _GRB_STREAM_DIR_K | GRB_streamDir |
Typedef for enum _GRB_STREAM_DIR_K. | |
typedef enum _GRB_STREAM_BOUNDS_K | GRB_STREAM_BOUNDS_K |
Typedef for enum _GRB_STREAM_BOUNDS_K. | |
typedef int(* | streamClose )(void *file) |
Generic stream close function signature. | |
typedef struct _streamCloseCbp | streamCloseCbp |
Typedef for struct _streamCloseCbp. | |
typedef struct _GRB_streamHeader | GRB_streamHeader |
Typedef for struct _GRB_streamHeader. | |
typedef struct _GRB_istreamBody | GRB_istreamBody |
Typedef for struct _GRB_streamFileBody. | |
typedef struct _GRB_ostreamBody | GRB_ostreamBody |
Typedef for struct _GRB_ostreamBody. | |
typedef union _GRB_streamBody | GRB_streamBody |
Typedef for union _GRB_streamBody. | |
typedef struct _GRB_stream | GRB_stream |
Typedef for struct _GRB_stream. | |
Enumerations | |
enum | _GRB_STREAM_DIR_K { GRB_STREAM_DIR_K_READ = 0, GRB_STREAM_DIR_K_WRITE = 1 } |
Enumeration of the IO direction, i.e. read or write. More... | |
enum | _GRB_STREAM_BOUNDS_K { GRB_STREAM_BOUNDS_K_MAXPKT = 1 << 16, GRB_STREAM_BOUNDS_K_LOWER = GRB_STREAM_BOUNDS_K_MAXPKT, GRB_STREAM_BOUNDS_K_UPPER = 1 << 25, GRB_STREAM_BOUNDS_K_OVERFLOW = GRB_STREAM_BOUNDS_K_MAXPKT } |
Upper and lower bounds on the segment size. More... | |
Functions | |
static GRB_stream * | fileOpen (GRB_streamType type, const char *fileName, int segment_size) |
Opens a GRB file for reading. | |
static int | fileRead (GRB_stream *stream, unsigned int *ptr, size_t nbytes) |
Reads the specified number of bytes. | |
static GRB_stream * | map (unsigned int *grb_data) |
Prepares an in memory data structure to be read. | |
static void * | mem_alloc (unsigned int nbytes) |
Wraps the 'real' allocator. | |
static void | mem_free (void *ptr) |
Wraps the 'real' deallocator. | |
GRB_stream * | GRB_streamOpen (GRB_streamType type, const void *name, int segment) |
Opens a GRB file or data for reading. | |
int | GRB_streamRead (GRB_stream *stream) |
Reads the GRB file associated with the event stream handle istream. | |
const GRB_pktHdr * | GRB_streamLocate (GRB_stream *stream, int advance) |
Returns a pointer to the current packet and, optionally, advances the current packet to the next packet. | |
int | GRB_streamClose (GRB_stream *stream) |
Closes the file after it has been read. | |
GRB_stream * | GRB_streamCreate (GRB_streamType type, const char *name, int rsvd_mbz) |
Creates a file to receive the GRB data packets. | |
int | GRB_streamFree (GRB_stream *stream) |
Frees the memory associated with the contents of the file. |
CVS $Id: GRB_stream.c,v 1.2 2011/03/30 22:11:52 russell Exp $
Typedef for enum _GRB_STREAM_BOUNDS_K.
The lower bound must be constrained to be at least the size of the largest event.
The upper bound is really only a default used and can be easily overridden. The upper bound must be at least the size of a maximally sized event, but really is set by purely practical considerations. Since this is unit of a read, on very large files, there can be a considerable delay if this read is very large. This is annoying, particularly in the case where one working interactively and just processing the first few events. So this size is set to be something that is large enough to be accommodate most files, but small enough to keep the read latency to something tolerable on human timescales.
The overflow region is provided as an area where discontigious events may be reassembled into a contigious block of memory. As such, it must be at least the size of a maximally sized event.
enum _GRB_STREAM_BOUNDS_K |
Upper and lower bounds on the segment size.
enum _GRB_STREAM_DIR_K |
static GRB_stream * fileOpen | ( | GRB_streamType | type, | |
const char * | fileName, | |||
int | segmentSize | |||
) | [static] |
Opens a GRB file for reading.
type | The stream type, must be either
| |
fileName | The name of the GRB file to open | |
segmentSize | The largest portion of the file that will be buffered on a read.
|
References _GRB_stream::bdy, _GRB_istreamBody::buf, _GRB_streamHeader::close, _GRB_istreamBody::cur_pkt, _GRB_istreamBody::cur_size, _GRB_streamHeader::dir, _GRB_istreamBody::fate, _GRB_istreamBody::fd, _GRB_streamHeader::free, GRB_STREAM_BOUNDS_K_LOWER, GRB_STREAM_BOUNDS_K_OVERFLOW, GRB_STREAM_BOUNDS_K_UPPER, GRB_STREAM_DIR_K_READ, GRB_STREAM_TYPE_K_FILE, _GRB_stream::hdr, _GRB_streamBody::in, mem_alloc(), _GRB_istreamBody::name, _GRB_istreamBody::nprocess, _streamCloseCbp::prm, _streamCloseCbp::rtn, _GRB_istreamBody::seg_size, _GRB_istreamBody::tot_left, _GRB_istreamBody::tot_size, _GRB_streamHeader::type, and _GRB_istreamBody::which.
Referenced by GRB_streamOpen().
static int fileRead | ( | GRB_stream * | stream, | |
unsigned int * | ptr, | |||
size_t | nbytes | |||
) | [static] |
Reads the specified number of bytes.
References _GRB_stream::bdy, _GRB_istreamBody::fd, _GRB_streamBody::in, and _GRB_istreamBody::name.
Referenced by GRB_streamRead().
int GRB_streamClose | ( | GRB_stream * | stream | ) |
Closes the file after it has been read.
This function only closes the file after its contents have been read into memory. To free the memory associated with the contents of the file, the user must call GRB_streamFree().
References _GRB_streamHeader::close, _GRB_stream::hdr, _streamCloseCbp::prm, and _streamCloseCbp::rtn.
GRB_stream * GRB_streamCreate | ( | GRB_streamType | type, | |
const char * | name, | |||
int | rsvd_mbz | |||
) |
Creates a file to receive the GRB data packets.
type | The type of stream to open GRB_STREAM_TYPE_K_FILE or GRB_STREAM_TYPE_K_DATA | |
name | The name of the section or file to create | |
rsvd_mbz | Reserved, must be 0 |
References _GRB_stream::bdy, _GRB_streamHeader::close, _GRB_streamHeader::dir, _GRB_ostreamBody::file, _GRB_streamHeader::free, GRB_STREAM_DIR_K_WRITE, GRB_STREAM_TYPE_K_DATA, GRB_STREAM_TYPE_K_FILE, _GRB_stream::hdr, mem_alloc(), _GRB_ostreamBody::name, _GRB_streamBody::out, _streamCloseCbp::prm, _streamCloseCbp::rtn, and _GRB_streamHeader::type.
int GRB_streamFree | ( | GRB_stream * | stream | ) |
Frees the memory associated with the contents of the file.
stream | The event builder stream handle |
References _GRB_streamHeader::free, _GRB_stream::hdr, and mem_free().
const GRB_pktHdr * GRB_streamLocate | ( | GRB_stream * | stream, | |
int | advance | |||
) |
Returns a pointer to the current packet and, optionally, advances the current packet to the next packet.
stream | The stream handle | |
advance | If non-zero, advance to the internal next packet pointer to the next packet. This is the normal way one would serially read a file of packets |
References _GRB_stream::bdy, _GRB_istreamBody::cur_pkt, _GRB_streamBody::in, and _GRB_istreamBody::lst_pkt.
GRB_stream * GRB_streamOpen | ( | GRB_streamType | type, | |
const void * | name, | |||
int | segment | |||
) |
Opens a GRB file or data for reading.
type | The type of stream to open
| |
name | The name of the GRB file or the address of data section to open | |
segment | Interpretation is dependent on type. If type is
|
References fileOpen(), GRB_STREAM_TYPE_K_DATA, GRB_STREAM_TYPE_K_FILE, GRB_STREAM_TYPE_K_FILESEG, and map().
int GRB_streamRead | ( | GRB_stream * | stream | ) |
Reads the GRB file associated with the event stream handle istream.
stream | A previously opened event builder stream handle |
0,if | successful | |
-1,if | not |
References _GRB_stream::bdy, _GRB_istreamBody::buf, _GRB_istreamBody::cur_pkt, fileRead(), GRB_STREAM_TYPE_K_FILE, _GRB_stream::hdr, _GRB_streamBody::in, _GRB_istreamBody::lst_pkt, _GRB_istreamBody::seg_size, and _GRB_streamHeader::type.
static GRB_stream * map | ( | unsigned int * | data | ) | [static] |
Prepares an in memory data structure to be read.
data | Pointer to the in memory data structure. |
References _GRB_streamHeader::close, _GRB_streamHeader::dir, _GRB_streamHeader::free, GRB_STREAM_DIR_K_READ, GRB_STREAM_TYPE_K_DATA, _GRB_stream::hdr, mem_alloc(), _streamCloseCbp::prm, _streamCloseCbp::rtn, and _GRB_streamHeader::type.
Referenced by GRB_streamOpen().
static void * mem_alloc | ( | unsigned int | nbytes | ) | [static] |
Wraps the 'real' allocator.
nbytes | The number of bytes |
Referenced by fileOpen(), GRB_streamCreate(), and map().
static void mem_free | ( | void * | ptr | ) | [static] |
Wraps the 'real' deallocator.
ptr | Pointer to the memory to free |
Referenced by GRB_streamFree().