org.jlab.coda.et
Class Event

java.lang.Object
  extended byorg.jlab.coda.et.Event

public class Event
extends java.lang.Object

This class defines an ET event.


Field Summary
(package private)  int age
          Specifies whether the event was obtained as a new event (through newEvents), or as a "used" event (through getEvents).
(package private)  int byteOrder
          An integer used to keep track of the data's byte ordering.
(package private)  int[] control
          An array of integers normally used by stations to filter events out of their input lists.
(package private)  byte[] data
          The event data is stored here.
(package private)  int dataStatus
          Status of the data.
(package private)  int id
          Unique id number.
(package private)  boolean isJava
          Flag specifying whether the ET system process is Java based or not.
(package private)  int length
          Length of the valid data in bytes.
(package private)  int memSize
          Size of the data buffer in bytes.
(package private)  int modify
          Specifies whether the user wants to read the event only, will modify only the event header, or will modify the data.
(package private)  int owner
          The attachment id which owns or got the event.
(package private)  int priority
          Event priority which is either high Constants.high or low Constants.low.
(package private)  int sizeLimit
          Size limit of events' data buffers in bytes.
 
Constructor Summary
(package private) Event(int size)
          Creates an event object for users of Java-based ET systems or by the system itself.
(package private) Event(int size, int limit, boolean isJavaSystem)
          Creates an event object for ET system users.
 
Method Summary
static int bytesToInt(byte[] b, int off)
          Converts 4 bytes of a byte array into an integer.
static short bytesToShort(byte[] b, int off)
          Converts 2 bytes of a byte array into a short.
 void codaSwap()
          Swaps data that is in the CODA format only.
 byte[] copyData()
          Gets the event's data array.
 void copyDataIn(byte[] dat)
          Set the event's data by copying it in.
 void copyDataIn(byte[] dat, int srcOff, int destOff, int len)
          Set the event's data by copying it in.
 int getByteOrder()
          Gets the event's byte order - either Constants.endianBig or Constants.endianLittle.
 int[] getControl()
          Gets the event's control array.
 byte[] getData()
          Gets the event's data array.
 int getDataStatus()
          Gets the status of the data.
 int getId()
          Gets the event's id number.
 int getLength()
          Gets the length of the data in bytes.
 int getMemSize()
          Gets the size of the data buffer in bytes.
 int getModify()
          Gets the event's modify value.
 int getPriority()
          Gets the event's priority.
 int getSizeLimit()
          Gets the size limit of the data buffer in bytes when using a C-based ET system.
(package private)  void init()
          Initialize an event's fields.
static void intToBytes(int intVal, byte[] b, int off)
          Copies an integer value into 4 bytes of a byte array.
 boolean needToSwap()
          Tells caller if the event data needs to be swapped in order to be the correct byte order.
 void setByteOrder(int endian)
          Set the event's byte order.
 void setControl(int[] con)
          Sets the event's control array by copying it in.
 void setData(byte[] dat)
          Sets the event's data without copying.
 void setDataStatus(int status)
          Sets the event's data status.
 void setLength(int len)
          Sets the event's data length in bytes.
 void setPriority(int pri)
          Sets the event's priority.
static void shortToBytes(short shortVal, byte[] b, int off)
          Copies a short value into 2 bytes of a byte array.
static void swapArrayInt(byte[] b, int off)
          Swaps 4 bytes of a byte array in place.
static void swapArrayShort(byte[] b, int off)
          Swaps 2 bytes of a byte array in place.
static int swapInt(int n)
          Swaps the byte order of an integer.
static short swapShort(short n)
          Swaps the byte order of a short.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

id

int id
Unique id number.


age

int age
Specifies whether the event was obtained as a new event (through newEvents), or as a "used" event (through getEvents). If the event is new, its value is Constants.eventNew otherwise Constants.eventUsed.


priority

int priority
Event priority which is either high Constants.high or low Constants.low.


owner

int owner
The attachment id which owns or got the event. If it's owned by the system its value is Constants.system.


length

int length
Length of the valid data in bytes.


memSize

int memSize
Size of the data buffer in bytes.


sizeLimit

int sizeLimit
Size limit of events' data buffers in bytes. This is important to know when Java users connect to C-based ET systems. The C-based ET systems cannot allow users to increase an event's data size beyond what was originally allocated. In Java systems there is no size limit besides computer and JVM limits.


dataStatus

int dataStatus
Status of the data. It can be ok Constants.dataOk, corrupted Constants.dataCorrupt, or possibly corrupted Constants.dataPossiblyCorrupt.


byteOrder

int byteOrder
An integer used to keep track of the data's byte ordering.


modify

int modify
Specifies whether the user wants to read the event only, will modify only the event header, or will modify the data.


control

int[] control
An array of integers normally used by stations to filter events out of their input lists. It is used to control the flow of events through the ET system.


data

byte[] data
The event data is stored here.


isJava

boolean isJava
Flag specifying whether the ET system process is Java based or not.

Constructor Detail

Event

Event(int size)
Creates an event object for users of Java-based ET systems or by the system itself. Event objects are only created once in the ET system process - when the ET system is started up.

Parameters:
size - size of the data array in bytes

Event

Event(int size,
      int limit,
      boolean isJavaSystem)
Creates an event object for ET system users.

Parameters:
size - size of the data array in bytes.
limit - limit on the size of the data array in bytes. Only used for C-based ET systems.
isJavaSystem - is ET system Java based?
Method Detail

init

void init()
Initialize an event's fields. Called for an event each time it passes through GRAND_CENTRAL station.


getId

public int getId()
Gets the event's id number.

Returns:
event's id number

getPriority

public int getPriority()
Gets the event's priority.

Returns:
event's priority

getLength

public int getLength()
Gets the length of the data in bytes.

Returns:
length of the data in bytes

getMemSize

public int getMemSize()
Gets the size of the data buffer in bytes.

Returns:
size of the data buffer in bytes

getSizeLimit

public int getSizeLimit()
Gets the size limit of the data buffer in bytes when using a C-based ET system.

Returns:
size size limit of the data buffer in bytes

getDataStatus

public int getDataStatus()
Gets the status of the data.

Returns:
status of the data

getModify

public int getModify()
Gets the event's modify value.

Returns:
event's modify value

getControl

public int[] getControl()
Gets the event's control array.

Returns:
event's control array

getData

public byte[] getData()
Gets the event's data array.

Returns:
event's data array

copyData

public byte[] copyData()
Gets the event's data array.

Returns:
a clone of the event's data array

setData

public void setData(byte[] dat)
             throws EtException
Sets the event's data without copying. The length and memSize members of the event are automatically set to the data array's length.

Parameters:
dat - data array
Throws:
EtException

copyDataIn

public void copyDataIn(byte[] dat)
                throws EtException
Set the event's data by copying it in. The event's length member is set to the length of the argument array.

Parameters:
dat - data array
Throws:
EtException - if the data array is the wrong size

copyDataIn

public void copyDataIn(byte[] dat,
                       int srcOff,
                       int destOff,
                       int len)
                throws EtException
Set the event's data by copying it in. The event's length member is not changed.

Parameters:
dat - data array
srcOff - offset in "dat" byte array
destOff - offset in the event's byte array
len - bytes of data to copy
Throws:
EtException - if the data array is the wrong size

setPriority

public void setPriority(int pri)
                 throws EtException
Sets the event's priority.

Parameters:
pri - event priority
Throws:
EtException - if argument is a bad value

setLength

public void setLength(int len)
               throws EtException
Sets the event's data length in bytes.

Parameters:
len - data length
Throws:
EtException - if length is less than zero

setControl

public void setControl(int[] con)
                throws EtException
Sets the event's control array by copying it in.

Parameters:
con - control array
Throws:
EtException - if control array has the wrong number of elements

setDataStatus

public void setDataStatus(int status)
                   throws EtException
Sets the event's data status.

Parameters:
status - data status
Throws:
EtException - if argument is a bad value

getByteOrder

public int getByteOrder()
Gets the event's byte order - either Constants.endianBig or Constants.endianLittle.

Returns:
event's byte order

setByteOrder

public void setByteOrder(int endian)
                  throws EtException
Set the event's byte order. Values can be Constants.endianBig, Constants.endianLittle, Constants.endianLocal, Constants.endianNotLocal, or Constants.endianSwitch

Parameters:
endian - endian value
Throws:
EtException - if argument is a bad value

needToSwap

public boolean needToSwap()
                   throws EtException
Tells caller if the event data needs to be swapped in order to be the correct byte order.

Returns:
true if swapping is needed, otherwise false
Throws:
EtException - if the byte order has a bad value

codaSwap

public void codaSwap()
Swaps data that is in the CODA format only.


swapInt

public static final int swapInt(int n)
Swaps the byte order of an integer.

Parameters:
n - integer to be swapped
Returns:
swapped integer

swapShort

public static final short swapShort(short n)
Swaps the byte order of a short.

Parameters:
n - short to be swapped
Returns:
swapped short

bytesToInt

public static final int bytesToInt(byte[] b,
                                   int off)
Converts 4 bytes of a byte array into an integer.

Parameters:
b - byte array
off - offset into the byte array (0 = start at first element)
Returns:
integer value

intToBytes

public static final void intToBytes(int intVal,
                                    byte[] b,
                                    int off)
Copies an integer value into 4 bytes of a byte array.

Parameters:
intVal - integer value
b - byte array
off - offset into the byte array

swapArrayInt

public static final void swapArrayInt(byte[] b,
                                      int off)
Swaps 4 bytes of a byte array in place.

Parameters:
b - byte array
off - offset into the byte array

bytesToShort

public static final short bytesToShort(byte[] b,
                                       int off)
Converts 2 bytes of a byte array into a short.

Parameters:
b - byte array
off - offset into the byte array (0 = start at first element)
Returns:
short value

shortToBytes

public static final void shortToBytes(short shortVal,
                                      byte[] b,
                                      int off)
Copies a short value into 2 bytes of a byte array.

Parameters:
shortVal - short value
b - byte array
off - offset into the byte array

swapArrayShort

public static final void swapArrayShort(byte[] b,
                                        int off)
Swaps 2 bytes of a byte array in place.

Parameters:
b - byte array
off - offset into the byte array