evioswap.c File Reference

#include <stdlib.h>
#include <stdio.h>
#include "evio.h"

Functions

int eviofmt (char *fmt, unsigned char *ifmt, int ifmtLen)
int eviofmtswap (uint32_t *iarr, int nwrd, unsigned char *ifmt, int nfmt, int tolocal)
 This function converts (swaps) an array of EVIO composite type data between IEEE (big endian) and DECS (little endian) in place.
void evioswap (uint32_t *buf, int tolocal, uint32_t *dest)
 Routine to swap the endianness of an evio event (bank).
int32_t swap_int32_t_value (int32_t val)
 This routine swaps the bytes of a 32 bit integer and returns the swapped value.
uint32_tswap_int32_t (uint32_t *data, unsigned int length, uint32_t *dest)
 This routine swaps a buffer of 32 bit integers.

Detailed Description

 ################################
 COMPOSITE DATA:
 ################################
   This is a new type of data (value = 0xf) which originated with Hall B.
   It is a composite type and allows for possible expansion in the future
   if there is a demand. Basically it allows the user to specify a custom
   format by means of a string - stored in a tagsegment. The data in that
   format follows in a bank. The routine to swap this data must be provided
   by the definer of the composite type - in this case Hall B. The swapping
   function is plugged into this evio library's swapping routine.
   Here's what it looks like.
 MSB(31)                          LSB(0)
 <---  32 bits ------------------------>
 _______________________________________
 |  tag    | type |    length          | --> tagsegment header
 |_________|______|____________________|
 |        Data Format String           |
 |                                     |
 |_____________________________________|
 |              length                 | \
 |_____________________________________|  \  bank header
 |       tag      |  type   |   num    |  /
 |________________|_________|__________| /
 |               Data                  |
 |                                     |
 |_____________________________________|
 

The beginning tagsegment is a normal evio tagsegment containing a string (type = 0x3). Currently its type and tag are not used - at least not for data formatting. The bank is a normal evio bank header with data following. The format string is used to read/write this data so that takes care of any padding that may exist. As with the tagsegment, the tag, type, & num are ignored.


Function Documentation

int eviofmt ( char *  fmt,
unsigned char *  ifmt,
int  ifmtLen 
)
  This routine transforms a composite, format-containing
  ASCII string to an unsigned char array. It is to be used
  in conjunction with eviofmtswap to swap the endianness of
  composite data.
   format code bits <- format in ascii form
     [7:4] [3:0]
       #     0           #'('
       0    15           #'(' same as above, but have to take # from the data (32-bit)
       0     0            ')'
       #     1           #'i'   unsigned int
       #     2           #'F'   floating point
       #     3           #'a'   8-bit char (C++)
       #     4           #'S'   short
       #     5           #'s'   unsigned short
       #     6           #'C'   char
       #     7           #'c'   unsigned char
       #     8           #'D'   double (64-bit float)
       #     9           #'L'   long long (64-bit int)
       #    10           #'l'   unsigned long long (64-bit int)
       #    11           #'I'   int
       #    12           #'A'   hollerit (4-byte char with int endining)
   NOTES:
    1. If format ends but end of data did not reach, format in last parenthesis
       will be repeated until all data processed; if there are no parenthesis
       in format, data processing will be started from the beginnig of the format
       (FORTRAN agreement)
    2. The number of repeats '#' must be the number between 2 and 15; if the number
       of repeats is symbol 'N' instead of the number, it will be taken from data
       assuming 'int' format
 
Parameters:
fmt null-terminated composite data format string
ifmt unsigned char array to hold transformed format
ifmtLen length of unsigned char array, ifmt, in # of chars
Returns:
the number of bytes in ifmt[] (positive)
-1 to -8 for improper format string
-9 if unsigned char array is too small

References debugprint, and MAX.

int eviofmtswap ( uint32_t iarr,
int  nwrd,
unsigned char *  ifmt,
int  nfmt,
int  tolocal 
)

This function converts (swaps) an array of EVIO composite type data between IEEE (big endian) and DECS (little endian) in place.

This data does NOT include the composite type's beginning tagsegment and the format string it contains. It also does NOT include the data's bank header words.

Converts the data of array (iarr[i], i=0...nwrd-1) using the format code (ifmt[j], j=0...nfmt-1) .

Algorithm description:

Data processed inside while (ib < nwrd) loop, where 'ib' is iarr[] index; loop breaks when 'ib' reaches the number of elements in iarr[]

Parameters:
iarr pointer to data to be swapped
nwrd number of data words (32-bit ints) to be swapped
ifmt unsigned char array holding translated format
nfmt length of unsigned char array, ifmt, in # of chars
tolocal if 0 data is of same endian as local host, else data is of opposite endian
Returns:
0 if success
-1 if nwrd or nfmt arg(s) < 0

References EVIO_SWAP16, EVIO_SWAP32, and EVIO_SWAP64.

void evioswap ( uint32_t buf,
int  tolocal,
uint32_t dest 
)

Routine to swap the endianness of an evio event (bank).

Parameters:
buf buffer of evio event data to be swapped
tolocal if 0 buf contains data of same endian as local host, else buf has data of opposite endian
dest buffer to place swapped data into. If this is NULL, then dest = buf.

Referenced by evRead(), evReadNoCopy(), and evReadRandom().

uint32_t * swap_int32_t ( uint32_t data,
unsigned int  length,
uint32_t dest 
)

This routine swaps a buffer of 32 bit integers.

Parameters:
data pointer to data to be swapped
length number of 32 bit ints to be swapped
dest pointer to where swapped data is to be copied to. If NULL, the data is swapped in place.
Returns:
pointer to beginning of swapped data

References EVIO_SWAP32.

int32_t swap_int32_t_value ( int32_t  val  ) 

This routine swaps the bytes of a 32 bit integer and returns the swapped value.

Rewritten to be a wrapper for EVIO_SWAP32(x) macro.

Parameters:
val int val to be swapped
Returns:
swapped value
Deprecated:
Use the EVIO_SWAP32(x) macro instead of this routine.

References EVIO_SWAP32.


Generated on 4 Feb 2014 for evio by  doxygen 1.6.1