|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jlab.coda.jevio.BaseStructure
public abstract class BaseStructure
This is the base class for all evio structures: Banks, Segments, and TagSegments.
It implements 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 Summary | |
---|---|
BaseStructure(BaseStructureHeader header)
Constructor using a provided header |
Method Summary | |
---|---|
void |
appendByteData(byte[] data)
Appends byte data to the structure. |
void |
appendCompositeData(CompositeData[] data)
Appends CompositeData objects to the structure. |
void |
appendDoubleData(double[] data)
Appends double data to the structure. |
void |
appendFloatData(float[] data)
Appends float data to the structure. |
void |
appendIntData(int[] data)
Appends int data to the structure. |
void |
appendLongData(long[] data)
Appends long 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). |
java.util.Enumeration<?> |
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()
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 |
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(double[] data)
Set the data in this structure to the given array of doubles. |
void |
setFloatData(float[] data)
Set the data in this structure to the given array of floats. |
void |
setIntData(int[] data)
Set the data in this structure to the given array of ints. |
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(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. |
static int |
stringsToRawSize(java.lang.String[] strings)
This method returns the number of bytes in a raw evio format of the given string array. |
java.lang.String |
toString()
Obtain a string representation of the structure. |
java.lang.String |
toXML()
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. |
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 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. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public BaseStructure(BaseStructureHeader header)
header
- the header to use.BaseStructureHeader
Method Detail |
---|
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 java.lang.String getXMLElementName()
public java.lang.String toXML()
public 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 size
public static byte[] stringsToRawBytes(java.lang.String[] strings)
strings
- array of String objects to transform
public static java.lang.String[] unpackRawBytesToStrings(byte[] rawBytes, int offset)
rawBytes
- raw evio string dataoffset
- offset into raw data array
public 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<?> 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()
.public java.util.Vector<BaseStructure> getChildren()
public int setAllHeaderLengths()
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 typepublic void appendShortData(short[] data) throws EvioException
data
- the short data to append, or set if there is no existing data.
EvioException
public void appendLongData(long[] data) throws EvioException
data
- the long data to append, or set if there is no existing data.
EvioException
public void appendByteData(byte[] data) throws EvioException
data
- the byte data to append, or set if there is no existing data.
EvioException
public void appendFloatData(float[] data) throws EvioException
data
- the float data to append, or set if there is no existing data.
EvioException
public void appendStringData(java.lang.String s) throws EvioException
s
- the string to append (as ascii), or set if there is no existing data.
EvioException
public void appendDoubleData(double[] data) throws EvioException
data
- the double data to append, or set if there is no existing data.
EvioException
public void appendCompositeData(CompositeData[] data) throws EvioException
data
- the CompositeData objects to append, or set if there is no existing data.
EvioException
public void setIntData(int[] data)
DataType.UINT32
or DataType.INT32
,
it will be reset in the header to DataType.INT32
.
data
- the int data to set to.public void setShortData(short[] data)
DataType.USHORT16
or DataType.SHORT16
,
it will be reset in the header to DataType.SHORT16
.
data
- the short data to set to.public void setLongData(long[] data)
DataType.ULONG64
or DataType.LONG64
,
it will be reset in the header to DataType.LONG64
.
data
- the long data to set to.public void setByteData(byte[] data)
DataType.UCHAR8
or DataType.CHAR8
,
it will be reset in the header to DataType.CHAR8
.
data
- the byte data to set to.public void setFloatData(float[] data)
DataType.FLOAT32
, it will be reset in the
header to that type.
data
- the float data to set to.public void setDoubleData(double[] data)
DataType.DOUBLE64
, it will be reset in the
header to that type.
data
- the double data to set to.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)
DataType.COMPOSITE
, it will be reset in the
header to that type.
data
- the array of CompositeData objects to set to.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |