org.jlab.coda.jevio
Class EventBuilder

java.lang.Object
  extended by org.jlab.coda.jevio.EventBuilder

public class EventBuilder
extends java.lang.Object

This class is used for creating and manipulating events. One constructor is convenient for creating new events while another is useful for manipulating existing events. You can create a new EventBuilder for each event being handled, However, in many cases one can use the same EventBuilder for all events by calling the setEvent method. The only reason a singleton pattern was not used was to allow for the possibility that events will be built or manipulated on multiple threads.

Author:
heddle

Constructor Summary
EventBuilder(EvioEvent event)
          This is the constructor to use when you want to manipulate an existing event.
EventBuilder(int tag, DataType dataType, int num)
          This is the constructor to use for an EventBuilder object that will operate on a new, empty event.
 
Method Summary
 void addChild(BaseStructure parent, BaseStructure child)
          Add a child to a parent structure.
 void appendByteData(BaseStructure structure, byte[] data)
          Appends byte data to the structure.
 void appendDoubleData(BaseStructure structure, double[] data)
          Appends double data to the structure.
 void appendFloatData(BaseStructure structure, float[] data)
          Appends float data to the structure.
 void appendIntData(BaseStructure structure, int[] data)
          Appends int data to the structure.
 void appendLongData(BaseStructure structure, long[] data)
          Appends long data to the structure.
 void appendShortData(BaseStructure structure, short[] data)
          Appends short data to the structure.
 void appendStringData(BaseStructure structure, java.lang.String data)
          Appends string data to the structure.
 void clearData(BaseStructure structure)
          This clears all the data fields in a structure, but not the parent or the children.
 EvioEvent getEvent()
          Get the underlying event.
static void main(java.lang.String[] args)
          Main program for testing.
 void remove(BaseStructure child)
          This removes a structure (and all its descendants) from the tree.
 void setAllHeaderLengths()
          This goes through the event recursively, and makes sure all the length fields in the headers are properly set.
 void setByteData(BaseStructure structure, byte[] data)
          Set byte data to the structure.
 void setEvent(EvioEvent event)
          Set the underlying event.
 void setFloatData(BaseStructure structure, float[] data)
          Set float data to the structure.
 void setIntData(BaseStructure structure, double[] data)
          Set double data to the structure.
 void setIntData(BaseStructure structure, int[] data)
          Set int data to the structure.
 void setLongData(BaseStructure structure, long[] data)
          Set long data to the structure.
 void setShortData(BaseStructure structure, short[] data)
          Set short data to the structure.
 void setStringData(BaseStructure structure, java.lang.String[] data)
          Set string data to the structure.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventBuilder

public EventBuilder(int tag,
                    DataType dataType,
                    int num)
This is the constructor to use for an EventBuilder object that will operate on a new, empty event.

Parameters:
tag - the tag for the event header (which is just a bank header).
dataType - the data type for the event object--which again is just the type for the outer most bank. Often an event is a bank of banks, so typically this will be DataType.BANK, or 0xe (14).
num - often an ordinal enumeration.

EventBuilder

public EventBuilder(EvioEvent event)
This is the constructor to use when you want to manipulate an existing event.

Parameters:
event - the event to manipulate.
Method Detail

setAllHeaderLengths

public void setAllHeaderLengths()
This goes through the event recursively, and makes sure all the length fields in the headers are properly set.


clearData

public void clearData(BaseStructure structure)
This clears all the data fields in a structure, but not the parent or the children. This keeps the existing tree structure intact. To remove a structure (and, consequently, all its descendants) from the tree, use remove

Parameters:
structure - the segment to clear.

addChild

public void addChild(BaseStructure parent,
                     BaseStructure child)
              throws EvioException
Add a child to a parent structure.

Parameters:
parent - the parent structure.
child - the child structure.
Throws:
EvioException - if parent or child is null, child has wrong byte order, is wrong structure type, or parent is not a container

remove

public void remove(BaseStructure child)
            throws EvioException
This removes a structure (and all its descendants) from the tree.

Parameters:
child - the child structure to remove.
Throws:
EvioException

setIntData

public void setIntData(BaseStructure structure,
                       int[] data)
                throws EvioException
Set int data to the structure. If the structure has data, it is overwritten even if the existing data is of a different type.

Parameters:
structure - the structure to receive the data.
data - the int data to write.
Throws:
EvioException - if structure arg is null

setShortData

public void setShortData(BaseStructure structure,
                         short[] data)
                  throws EvioException
Set short data to the structure. If the structure has data, it is overwritten even if the existing data is of a different type.

Parameters:
structure - the structure to receive the data.
data - the short data to write.
Throws:
EvioException - if structure arg is null

setLongData

public void setLongData(BaseStructure structure,
                        long[] data)
                 throws EvioException
Set long data to the structure. If the structure has data, it is overwritten even if the existing data is of a different type.

Parameters:
structure - the structure to receive the data.
data - the long data to write.
Throws:
EvioException - if structure arg is null

setByteData

public void setByteData(BaseStructure structure,
                        byte[] data)
                 throws EvioException
Set byte data to the structure. If the structure has data, it is overwritten even if the existing data is of a different type.

Parameters:
structure - the structure to receive the data.
data - the byte data to write.
Throws:
EvioException - if structure arg is null

appendIntData

public void appendIntData(BaseStructure structure,
                          int[] data)
                   throws EvioException
Appends int data to the structure. If the structure has no data, then this is the same as setting the data.

Parameters:
structure - the structure to receive the data, which is appended.
data - the int data to append, or set if there is no existing data.
Throws:
EvioException

setFloatData

public void setFloatData(BaseStructure structure,
                         float[] data)
                  throws EvioException
Set float data to the structure. If the structure has data, it is overwritten even if the existing data is of a different type.

Parameters:
structure - the structure to receive the data.
data - the float data to write.
Throws:
EvioException - if structure arg is null

setIntData

public void setIntData(BaseStructure structure,
                       double[] data)
                throws EvioException
Set double data to the structure. If the structure has data, it is overwritten even if the existing data is of a different type.

Parameters:
structure - the structure to receive the data.
data - the double data to write.
Throws:
EvioException - if structure arg is null

setStringData

public void setStringData(BaseStructure structure,
                          java.lang.String[] data)
                   throws EvioException
Set string data to the structure. If the structure has data, it is overwritten even if the existing data is of a different type.

Parameters:
structure - the structure to receive the data.
data - the string data to write.
Throws:
EvioException - if structure arg is null

appendShortData

public void appendShortData(BaseStructure structure,
                            short[] data)
                     throws EvioException
Appends short data to the structure. If the structure has no data, then this is the same as setting the data.

Parameters:
structure - the structure to receive the data, which is appended.
data - the short data to append, or set if there is no existing data.
Throws:
EvioException

appendLongData

public void appendLongData(BaseStructure structure,
                           long[] data)
                    throws EvioException
Appends long data to the structure. If the structure has no data, then this is the same as setting the data.

Parameters:
structure - the structure to receive the data, which is appended.
data - the long data to append, or set if there is no existing data.
Throws:
EvioException

appendByteData

public void appendByteData(BaseStructure structure,
                           byte[] data)
                    throws EvioException
Appends byte data to the structure. If the structure has no data, then this is the same as setting the data.

Parameters:
structure - the structure to receive the data, which is appended.
data - the byte data to append, or set if there is no existing data.
Throws:
EvioException

appendFloatData

public void appendFloatData(BaseStructure structure,
                            float[] data)
                     throws EvioException
Appends float data to the structure. If the structure has no data, then this is the same as setting the data.

Parameters:
structure - the structure to receive the data, which is appended.
data - the float data to append, or set if there is no existing data.
Throws:
EvioException

appendDoubleData

public void appendDoubleData(BaseStructure structure,
                             double[] data)
                      throws EvioException
Appends double data to the structure. If the structure has no data, then this is the same as setting the data.

Parameters:
structure - the structure to receive the data, which is appended.
data - the double data to append, or set if there is no existing data.
Throws:
EvioException

appendStringData

public void appendStringData(BaseStructure structure,
                             java.lang.String data)
                      throws EvioException
Appends string data to the structure. If the structure has no data, then this is the same as setting the data.

Parameters:
structure - the structure to receive the data, which is appended.
data - the string to append, or set if there is no existing data.
Throws:
EvioException

getEvent

public EvioEvent getEvent()
Get the underlying event.

Returns:
the underlying event.

setEvent

public void setEvent(EvioEvent event)
Set the underlying event. As far as this event builder is concerned, the previous underlying event is lost, and all subsequent calls will affect the newly supplied event. param the new underlying event.


main

public static void main(java.lang.String[] args)
Main program for testing.

Parameters:
args - ignored command line arguments.