public abstract class BaseStructure extends java.lang.Object implements java.lang.Cloneable, IEvioStructure, javax.swing.tree.MutableTreeNode, IEvioWriter
MutableTreeNode
because a tree representation of
events is created when a new event is parsed.Note that using an EventBuilder for the same event in more than one thread can cause problems. For example the boolean lengthsUpToDate in this class would need to be volatile.
Constructor and Description |
---|
BaseStructure(BaseStructureHeader header)
Constructor using a provided header
|
Modifier and Type | Method and Description |
---|---|
void |
appendByteData(byte[] data)
Appends byte data to the structure.
|
void |
appendByteData(java.nio.ByteBuffer byteData)
Appends byte data to the structure.
|
void |
appendCompositeData(CompositeData[] data)
Appends CompositeData objects to the structure.
|
void |
appendDoubleData(java.nio.ByteBuffer byteData)
Appends double data to the structure.
|
void |
appendDoubleData(double[] data)
Appends double data to the structure.
|
void |
appendFloatData(java.nio.ByteBuffer byteData)
Appends float data to the structure.
|
void |
appendFloatData(float[] data)
Appends float data to the structure.
|
void |
appendIntData(java.nio.ByteBuffer byteData)
Appends int data to the structure.
|
void |
appendIntData(int[] data)
Appends int data to the structure.
|
void |
appendLongData(java.nio.ByteBuffer byteData)
Appends long data to the structure.
|
void |
appendLongData(long[] data)
Appends long data to the structure.
|
void |
appendShortData(java.nio.ByteBuffer byteData)
Appends short data to the structure.
|
void |
appendShortData(short[] data)
Appends short data to the structure.
|
void |
appendStringData(java.lang.String s)
Appends string to the structure (as ascii).
|
void |
appendStringData(java.lang.String[] s)
Appends an array of strings to the structure (as ascii).
|
java.util.Enumeration<? extends javax.swing.tree.TreeNode> |
children()
Get an enumeration of all the children of this structure.
|
java.lang.Object |
clone()
Clone this object.
|
boolean |
getAllowsChildren()
Checks whether children are allowed.
|
byte[] |
getByteData()
This is a method from the IEvioStructure Interface.
|
java.nio.ByteOrder |
getByteOrder()
What is the byte order of this data?
|
javax.swing.tree.TreeNode |
getChildAt(int index)
Obtain the child at the given index.
|
int |
getChildCount()
Get the count of the number of children.
|
java.util.Vector<BaseStructure> |
getChildren()
Deprecated.
child structures are no longer keep in a Vector
|
java.util.List<BaseStructure> |
getChildrenList()
Get the children of this structure.
|
CompositeData[] |
getCompositeData()
This is a method from the IEvioStructure Interface.
|
java.lang.String |
getDescription()
Get the description from the name provider (dictionary), if there is one.
|
double[] |
getDoubleData()
This is a method from the IEvioStructure Interface.
|
float[] |
getFloatData()
This is a method from the IEvioStructure Interface.
|
BaseStructureHeader |
getHeader()
This is a method from the IEvioStructure Interface.
|
int |
getIndex(javax.swing.tree.TreeNode node)
Get the index of a node.
|
int[] |
getIntData()
This is a method from the IEvioStructure Interface.
|
long[] |
getLongData()
This is a method from the IEvioStructure Interface.
|
java.util.List<BaseStructure> |
getMatchingStructures(IEvioFilter filter)
Visit all the descendant structures, and collect those that pass a filter.
|
int |
getNumberDataItems()
Get the number of stored data items like number of banks, ints, floats, etc.
|
BaseStructure |
getParent()
Get the parent of this structure.
|
byte[] |
getRawBytes()
Get the raw data of the structure.
|
short[] |
getShortData()
This is a method from the IEvioStructure Interface.
|
java.lang.String[] |
getStringData()
This is a method from the IEvioStructure Interface.
|
abstract StructureType |
getStructureType()
A convenience method use instead of "instanceof" to see what type
of structure we have.
|
int |
getTotalBytes()
Get the length of this structure in bytes, including the header.
|
abstract java.lang.String |
getXMLElementName()
Get the element name for the structure for writing to XML.
|
void |
insert(javax.swing.tree.MutableTreeNode child)
Convenience method to add a child at the end of the child list.
|
void |
insert(javax.swing.tree.MutableTreeNode child,
int index)
Add a child at the given index.
|
boolean |
isContainer()
Checks whether this structure is a container, i.e.
|
boolean |
isLeaf()
Checks whether this is a leaf.
|
boolean |
isSwap()
Is a byte swap required? This is java and therefore big endian.
|
void |
remove(int index)
Removes the child at index from the receiver.
|
void |
remove(javax.swing.tree.MutableTreeNode child)
Removes the child.
|
void |
removeFromParent()
Remove this node from its parent.
|
int |
setAllHeaderLengths()
Compute and set length of all header fields for this structure and all its descendants.
|
void |
setByteData(byte[] data)
Set the data in this structure to the given array of bytes.
|
void |
setByteData(java.nio.ByteBuffer byteData)
Set the data in this structure to the bytes contained in the given ByteBuffer.
|
void |
setByteOrder(java.nio.ByteOrder byteOrder)
Set the byte order of this data.
|
void |
setCompositeData(CompositeData[] data)
Set the data in this structure to the given array of CompositeData objects.
|
void |
setDoubleData(java.nio.ByteBuffer byteData)
Set the data in this structure to the doubles contained in the given ByteBuffer.
|
void |
setDoubleData(double[] data)
Set the data in this structure to the given array of doubles.
|
void |
setFloatData(java.nio.ByteBuffer byteData)
Set the data in this structure to the floats contained in the given ByteBuffer.
|
void |
setFloatData(float[] data)
Set the data in this structure to the given array of floats.
|
void |
setIntData(java.nio.ByteBuffer byteData)
Set the data in this structure to the ints contained in the given ByteBuffer.
|
void |
setIntData(int[] data)
Set the data in this structure to the given array of ints.
|
void |
setLongData(java.nio.ByteBuffer byteData)
Set the data in this structure to the longs contained in the given ByteBuffer.
|
void |
setLongData(long[] data)
Set the data in this structure to the given array of longs.
|
void |
setParent(javax.swing.tree.MutableTreeNode parent)
Set the parent for this node.
|
void |
setRawBytes(byte[] rawBytes)
Set the data for the structure.
|
void |
setShortData(java.nio.ByteBuffer byteData)
Set the data in this structure to the shorts contained in the given ByteBuffer.
|
void |
setShortData(short[] data)
Set the data in this structure to the given array of shorts.
|
void |
setStringData(java.lang.String[] data)
Set the data in this structure to the given array of Strings.
|
void |
setUserObject(java.lang.Object arg0)
This method is not relevant for this implementation.
|
static byte[] |
stringsToRawBytes(java.lang.String[] strings)
This method transforms an array of Strings into raw evio format data,
not including header.
|
static int |
stringsToRawSize(java.lang.String[] strings)
This method returns the number of bytes in a raw
evio format of the given string array, not including header.
|
java.lang.String |
toString()
Obtain a string representation of the structure.
|
java.lang.String |
toXML()
Write this structure out as an XML format string.
|
java.lang.String |
toXML(boolean hex)
Write this structure out as an XML format string.
|
abstract void |
toXML(javax.xml.stream.XMLStreamWriter xmlWriter)
This is a method that must be filled in by subclasses.
|
abstract void |
toXML(javax.xml.stream.XMLStreamWriter xmlWriter,
boolean hex)
This is a method that must be filled in by subclasses.
|
void |
transform(BaseStructure structure)
This method does a partial copy and is designed to help convert
between banks, segments,and tagsegments in the
StructureTransformer
class (hence the name "transfrom"). |
static java.lang.String[] |
unpackRawBytesToStrings(byte[] rawBytes,
int offset)
This method extracts an array of strings from byte array of raw evio string data.
|
static java.lang.String[] |
unpackRawBytesToStrings(byte[] rawBytes,
int offset,
int maxLength)
This method extracts an array of strings from byte array of raw evio string data.
|
static java.lang.String[] |
unpackRawBytesToStrings(java.nio.ByteBuffer buffer,
int pos,
int length)
This method extracts an array of strings from buffer containing raw evio string data.
|
void |
vistAllStructures(IEvioListener listener)
Visit all the structures in this structure (including the structure itself --
which is considered its own descendant).
|
void |
vistAllStructures(IEvioListener listener,
IEvioFilter filter)
Visit all the structures in this structure (including the structure itself --
which is considered its own descendant) in a depth first manner.
|
int |
write(java.nio.ByteBuffer byteBuffer)
Write myself out a byte buffer with fastest algorithms I could find.
|
public BaseStructure(BaseStructureHeader header)
header
- the header to use.BaseStructureHeader
public void transform(BaseStructure structure)
StructureTransformer
class (hence the name "transfrom").
It copies all the data from another BaseStructure object.
Children are not copied in the deep clone way,
but their references are added to this structure.
It does not copy header data or the parent either.structure
- BaseStructure from which to copy data.public java.lang.Object clone()
clone
in class java.lang.Object
public abstract StructureType getStructureType()
getStructureType
in interface IEvioStructure
StructureType
of this structure.StructureType
public abstract void toXML(javax.xml.stream.XMLStreamWriter xmlWriter)
xmlWriter
- the writer used to write the events.
It is tied to an open file.public abstract void toXML(javax.xml.stream.XMLStreamWriter xmlWriter, boolean hex)
xmlWriter
- the writer used to write the events.
It is tied to an open file.hex
- if true, ints get displayed in hexadecimalpublic abstract java.lang.String getXMLElementName()
public java.lang.String toXML()
public java.lang.String toXML(boolean hex)
hex
- if true, ints get displayed in hexadecimalpublic java.nio.ByteOrder getByteOrder()
ByteOrder.BIG_ENDIAN
or ByteOrder.LITTLE_ENDIAN
public void setByteOrder(java.nio.ByteOrder byteOrder)
byteOrder
- ByteOrder.BIG_ENDIAN
or ByteOrder.LITTLE_ENDIAN
public boolean isSwap()
true
if byte swapping is required (data is little endian).public java.lang.String getDescription()
getDescription
in interface IEvioStructure
public java.lang.String toString()
toString
in class java.lang.Object
public BaseStructureHeader getHeader()
getHeader
in interface IEvioStructure
public int getNumberDataItems()
public int getTotalBytes()
public byte[] getRawBytes()
public void setRawBytes(byte[] rawBytes)
rawBytes
- the structure raw data.public int[] getIntData()
NOTE: since Java does not have unsigned primitives, both INT32 and UINT32 data types will be returned as int arrays. The application will have to deal with reinterpreting signed ints that are negative as unsigned ints.
getIntData
in interface IEvioStructure
null
if this makes no sense for the given content type.public long[] getLongData()
NOTE: since Java does not have unsigned primitives, both LONG64 and ULONG64 data types will be returned as long arrays. The application will have to deal with reinterpreting signed longs that are negative as unsigned longs.
getLongData
in interface IEvioStructure
null
if this makes no sense for the given content type.public float[] getFloatData()
getFloatData
in interface IEvioStructure
null
if this makes no sense for the given contents type.public double[] getDoubleData()
getDoubleData
in interface IEvioStructure
null
if this makes no sense for the given content type.public short[] getShortData()
NOTE: since Java does not have unsigned primitives, both SHORT16 and USHORT16 data types will be returned as short arrays. The application will have to deal with reinterpreting signed shorts that are negative as unsigned shorts.
getShortData
in interface IEvioStructure
null
if this makes no sense for the given contents type.public CompositeData[] getCompositeData() throws EvioException
getCompositeData
in interface IEvioStructure
null
if this makes no sense for the given content type.EvioException
- if the data is internally inconsistentpublic byte[] getByteData()
NOTE: since Java does not have unsigned primitives, CHAR8 and UCHAR8 data types will be returned as byte arrays. The application will have to deal with reinterpreting bytes as characters, if necessary.
getByteData
in interface IEvioStructure
null
if this makes no sense for the given contents type.public java.lang.String[] getStringData()
Originally, in evio versions 1, 2 and 3, only one string was stored. Recent changes allow an array of strings to be stored and retrieved. The changes are backwards compatible. The following is true about the string raw data format:
getStringData
in interface IEvioStructure
null
if this makes no sense for the given type.public static int stringsToRawSize(java.lang.String[] strings)
strings
- array of String objects to sizepublic static byte[] stringsToRawBytes(java.lang.String[] strings)
strings
- array of String objects to transformpublic static java.lang.String[] unpackRawBytesToStrings(byte[] rawBytes, int offset)
rawBytes
- raw evio string dataoffset
- offset into raw data arraypublic static java.lang.String[] unpackRawBytesToStrings(byte[] rawBytes, int offset, int maxLength)
rawBytes
- raw evio string dataoffset
- offset into raw data arraymaxLength
- max length in bytes of valid data in rawBytes arraypublic static java.lang.String[] unpackRawBytesToStrings(java.nio.ByteBuffer buffer, int pos, int length)
buffer
- buffer containing evio string datapos
- position of string data in bufferlength
- length of string data in buffer in bytespublic BaseStructure getParent()
null
parent (the only orphan). All other structures have non-null parent giving the container in which they
were embedded. Part of the MutableTreeNode
interface.getParent
in interface javax.swing.tree.TreeNode
public java.util.Enumeration<? extends javax.swing.tree.TreeNode> children()
MutableTreeNode
interface.children
in interface javax.swing.tree.TreeNode
public void insert(javax.swing.tree.MutableTreeNode child, int index)
insert
in interface javax.swing.tree.MutableTreeNode
child
- the child to add.index
- the target index. Part of the MutableTreeNode
interface.public void insert(javax.swing.tree.MutableTreeNode child)
child
- the child to add. It will be added to the end of child list.public void remove(int index)
MutableTreeNode
interface.remove
in interface javax.swing.tree.MutableTreeNode
index
- the target index for removal.public void remove(javax.swing.tree.MutableTreeNode child)
MutableTreeNode
interface.remove
in interface javax.swing.tree.MutableTreeNode
child
- the child node being removed.public void removeFromParent()
MutableTreeNode
interface.removeFromParent
in interface javax.swing.tree.MutableTreeNode
public void setParent(javax.swing.tree.MutableTreeNode parent)
MutableTreeNode
interface.setParent
in interface javax.swing.tree.MutableTreeNode
public void vistAllStructures(IEvioListener listener)
listener
- an listener to notify as each structure is visited.public void vistAllStructures(IEvioListener listener, IEvioFilter filter)
listener
- an listener to notify as each structure is visited.filter
- an optional filter that must "accept" structures before
they are passed to the listener. If null
, all
structures are passed. In this way, specific types of
structures can be captured.public java.util.List<BaseStructure> getMatchingStructures(IEvioFilter filter)
filter
- the filter that must be passed. If null
,
this will return all the structures.public void setUserObject(java.lang.Object arg0)
MutableTreeNode
interface.setUserObject
in interface javax.swing.tree.MutableTreeNode
public boolean getAllowsChildren()
MutableTreeNode
interface.getAllowsChildren
in interface javax.swing.tree.TreeNode
true
if this node does not hold primitive data,
i.e., if it is a structure of structures (a container).public javax.swing.tree.TreeNode getChildAt(int index)
MutableTreeNode
interface.getChildAt
in interface javax.swing.tree.TreeNode
index
- the target index.public int getChildCount()
MutableTreeNode
interface.getChildCount
in interface javax.swing.tree.TreeNode
public int getIndex(javax.swing.tree.TreeNode node)
MutableTreeNode
interface.getIndex
in interface javax.swing.tree.TreeNode
public boolean isLeaf()
MutableTreeNode
interface.isLeaf
in interface javax.swing.tree.TreeNode
true
if this is a structure with a primitive data type, i.e., it is not a container
structure that contains other structures.public boolean isContainer()
true
if this structure is a container. This is the same check as
getAllowsChildren()
.@Deprecated public java.util.Vector<BaseStructure> getChildren()
getChildrenList()
instead.public java.util.List<BaseStructure> getChildrenList()
public int setAllHeaderLengths() throws EvioException
EvioException
- if the length is too large (> Integer.MAX_VALUE
),public int write(java.nio.ByteBuffer byteBuffer)
write
in interface IEvioWriter
byteBuffer
- the byteBuffer to write to.public void appendIntData(int[] data) throws EvioException
data
- the int data to append, or set if there is no existing data.EvioException
- if adding data to a structure of a different data type;
if data has too many elements to store in raw byte array (JVM limit)public void appendIntData(java.nio.ByteBuffer byteData) throws EvioException
byteData
- the data in ByteBuffer form to append, or set if there is no existing data.EvioException
- if adding data to a structure of a different data type;
if data has too many elements to store in raw byte array (JVM limit)public void appendShortData(short[] data) throws EvioException
data
- the short data to append, or set if there is no existing data.EvioException
- if adding data to a structure of a different data type;
if data has too many elements to store in raw byte array (JVM limit)public void appendShortData(java.nio.ByteBuffer byteData) throws EvioException
byteData
- the data in ByteBuffer form to append, or set if there is no existing data.EvioException
- if adding data to a structure of a different data type;
if data has too many elements to store in raw byte array (JVM limit)public void appendLongData(long[] data) throws EvioException
data
- the long data to append, or set if there is no existing data.EvioException
- if adding data to a structure of a different data type;
if data has too many elements to store in raw byte array (JVM limit)public void appendLongData(java.nio.ByteBuffer byteData) throws EvioException
byteData
- the data in ByteBuffer form to append, or set if there is no existing data.EvioException
- if adding data to a structure of a different data type;
if data has too many elements to store in raw byte array (JVM limit)public void appendByteData(byte[] data) throws EvioException
data
- the byte data to append, or set if there is no existing data.EvioException
- if adding data to a structure of a different data type;
if data has too many elements to store in raw byte array (JVM limit)public void appendByteData(java.nio.ByteBuffer byteData) throws EvioException
byteData
- the data in ByteBuffer form to append, or set if there is no existing data.EvioException
- if adding data to a structure of a different data type;
if data has too many elements to store in raw byte array (JVM limit)public void appendFloatData(float[] data) throws EvioException
data
- the float data to append, or set if there is no existing data.EvioException
- if adding data to a structure of a different data type;
if data has too many elements to store in raw byte array (JVM limit)public void appendFloatData(java.nio.ByteBuffer byteData) throws EvioException
byteData
- the data in ByteBuffer form to append, or set if there is no existing data.EvioException
- if adding data to a structure of a different data type;
if data has too many elements to store in raw byte array (JVM limit)public void appendStringData(java.lang.String s) throws EvioException
Integer.MAX_VALUE
in size.s
- the string to append (as ascii), or set if there is no existing data.EvioException
- if adding data to a structure of a different data typepublic void appendStringData(java.lang.String[] s) throws EvioException
Integer.MAX_VALUE
in size.s
- the strings to append (as ascii), or set if there is no existing data.EvioException
- if adding data to a structure of a different data type or to
badly formatted (not proper evio) data.public void appendDoubleData(double[] data) throws EvioException
data
- the double data to append, or set if there is no existing data.EvioException
- if adding data to a structure of a different data type;
if data has too many elements to store in raw byte array (JVM limit)public void appendDoubleData(java.nio.ByteBuffer byteData) throws EvioException
byteData
- the data in ByteBuffer form to append, or set if there is no existing data.EvioException
- if adding data to a structure of a different data type;
if data has too many elements to store in raw byte array (JVM limit)public void appendCompositeData(CompositeData[] data) throws EvioException
data
- the CompositeData objects to append, or set if there is no existing data.EvioException
- if adding data to a structure of a different data type;
if data takes up too much memory to store in raw byte array (JVM limit)public void setIntData(int[] data) throws EvioException
DataType.UINT32
or DataType.INT32
,
it will be reset in the header to DataType.INT32
.data
- the int data to set to.EvioException
- if data has too many elements to store in raw byte array (JVM limit)public void setIntData(java.nio.ByteBuffer byteData) throws EvioException
DataType.UINT32
or DataType.INT32
,
it will be reset in the header to DataType.INT32
.byteData
- the int data in ByteBuffer form.EvioException
- if data has too many elements to store in raw byte array (JVM limit)public void setShortData(short[] data) throws EvioException
DataType.USHORT16
or DataType.SHORT16
,
it will be reset in the header to DataType.SHORT16
.data
- the short data to set to.EvioException
- if data has too many elements to store in raw byte array (JVM limit)public void setShortData(java.nio.ByteBuffer byteData) throws EvioException
DataType.USHORT16
or DataType.SHORT16
,
it will be reset in the header to DataType.SHORT16
.byteData
- the short data in ByteBuffer form.EvioException
- if data has too many elements to store in raw byte array (JVM limit)public void setLongData(long[] data) throws EvioException
DataType.ULONG64
or DataType.LONG64
,
it will be reset in the header to DataType.LONG64
.data
- the long data to set to.EvioException
- if data has too many elements to store in raw byte array (JVM limit)public void setLongData(java.nio.ByteBuffer byteData) throws EvioException
DataType.ULONG64
or DataType.LONG64
,
it will be reset in the header to DataType.LONG64
.byteData
- the long data in ByteBuffer form.EvioException
- if data has too many elements to store in raw byte array (JVM limit)public void setByteData(byte[] data) throws EvioException
DataType.UCHAR8
or DataType.CHAR8
,
it will be reset in the header to DataType.CHAR8
.data
- the byte data to set to.EvioException
- if data has too many elements to store in raw byte array (JVM limit)public void setByteData(java.nio.ByteBuffer byteData) throws EvioException
DataType.UCHAR8
or DataType.CHAR8
,
it will be reset in the header to DataType.CHAR8
.byteData
- the byte data in ByteBuffer form.EvioException
- if data has too many elements to store in raw byte array (JVM limit)public void setFloatData(float[] data) throws EvioException
DataType.FLOAT32
, it will be reset in the
header to that type.data
- the float data to set to.EvioException
- if data has too many elements to store in raw byte array (JVM limit)public void setFloatData(java.nio.ByteBuffer byteData) throws EvioException
DataType.FLOAT32
, it will be reset in the
header to that type.byteData
- the float data in ByteBuffer form.EvioException
- if data has too many elements to store in raw byte array (JVM limit)public void setDoubleData(double[] data) throws EvioException
DataType.DOUBLE64
, it will be reset in the
header to that type.data
- the double data to set to.EvioException
- if data has too many elements to store in raw byte array (JVM limit)public void setDoubleData(java.nio.ByteBuffer byteData) throws EvioException
DataType.DOUBLE64
, it will be reset in the
header to that type.byteData
- the double data in ByteBuffer form.EvioException
- if data has too many elements to store in raw byte array (JVM limit)public void setStringData(java.lang.String[] data)
DataType.CHARSTAR8
,it will be reset in the
header to that type.data
- the String data to set to.public void setCompositeData(CompositeData[] data) throws EvioException
DataType.COMPOSITE
, it will be reset in the
header to that type.data
- the array of CompositeData objects to set to.EvioException
- if data uses too much memory to store in raw byte array (JVM limit)