evio  6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
evio::BaseStructure Class Reference

This is the base class for all evio structures: Banks, Segments, and TagSegments. More...

#include <BaseStructure.h>

Public Types

typedef size_t size_type
 
typedef std::ptrdiff_t difference_type
 
typedef std::input_iterator_tag iterator_category
 
typedef std::shared_ptr
< BaseStructure
value_type
 
typedef std::shared_ptr
< BaseStructure
reference
 
typedef std::shared_ptr
< BaseStructure
pointer
 
typedef nodeIterator
< std::shared_ptr
< BaseStructure > > 
iterator
 
typedef nodeBreadthIterator
< std::shared_ptr
< BaseStructure > > 
breadth_iterator
 

Public Member Functions

iterator begin ()
 Get the beginning depth-first iterator. More...
 
iterator end ()
 Get the end depth-first iterator. More...
 
breadth_iterator bbegin ()
 Get the beginning breadth-first iterator. More...
 
breadth_iterator bend ()
 Get the end breadth-first iterator. More...
 
std::shared_ptr< BaseStructuregetThis ()
 
std::shared_ptr< const
BaseStructure
getThisConst () const
 
void insert (const std::shared_ptr< BaseStructure > newChild, size_t childIndex)
 Removes newChild from its present parent (if it has a parent), sets the child's parent to this node, and then adds the child to this node's child array at index childIndex. More...
 
void remove (size_t childIndex)
 Removes the child at the specified index from this node's children and sets that node's parent to null. More...
 
std::shared_ptr< BaseStructuregetParent () const
 Returns this node's parent or null if this node has no parent. More...
 
std::vector< std::shared_ptr
< BaseStructure > > 
getChildren () const
 Get the children of this structure. More...
 
std::shared_ptr< BaseStructuregetChildAt (size_t index) const
 Returns the child at the specified index in this node's child vector. More...
 
size_t getChildCount () const
 Returns the number of children of this node. More...
 
ssize_t getIndex (const std::shared_ptr< BaseStructure > aChild)
 Returns the index of the specified child in this node's child vector. More...
 
std::vector< std::shared_ptr
< BaseStructure > >::iterator 
childrenBegin ()
 Creates and returns a forward-order begin iterator of this node's children. More...
 
std::vector< std::shared_ptr
< BaseStructure > >::iterator 
childrenEnd ()
 Creates and returns a forward-order end iterator of this node's children. More...
 
void setAllowsChildren (bool allows)
 Determines whether or not this node is allowed to have children. More...
 
bool getAllowsChildren () const
 Returns true if this node is allowed to have children. More...
 
void removeFromParent ()
 Removes the subtree rooted at this node from the tree, giving this node a null parent. More...
 
void remove (const std::shared_ptr< BaseStructure > aChild)
 Removes aChild from this node's child vector, giving it a null parent. More...
 
void removeAllChildren ()
 Removes all of this node's children, setting their parents to null. More...
 
void add (std::shared_ptr< BaseStructure > newChild)
 Removes newChild from its parent and makes it a child of this node by adding it to the end of this node's child array. More...
 
bool isNodeAncestor (const std::shared_ptr< BaseStructure > anotherNode) const
 Returns true if anotherNode is an ancestor of this node – if it is this node, this node's parent, or an ancestor of this node's parent. More...
 
bool isNodeDescendant (std::shared_ptr< BaseStructure > anotherNode)
 Returns true if anotherNode is a descendant of this node – if it is this node, one of this node's children, or a descendant of one of this node's children. More...
 
std::shared_ptr< BaseStructuregetSharedAncestor (std::shared_ptr< BaseStructure > aNode)
 Returns the nearest common ancestor to this node and aNode. More...
 
bool isNodeRelated (std::shared_ptr< BaseStructure > aNode)
 Returns true if and only if aNode is in the same tree as this node. More...
 
uint32_t getDepth ()
 Returns the depth of the tree rooted at this node – the longest distance from this node to a leaf. More...
 
uint32_t getLevel () const
 Returns the number of levels above this node – the distance from the root to this node. More...
 
std::vector< std::shared_ptr
< BaseStructure > > 
getPath ()
 Returns the path from the root, to get to this node. More...
 
std::shared_ptr< BaseStructuregetRoot ()
 Returns the root of the tree that contains this node. More...
 
bool isRoot () const
 Returns true if this node is the root of the tree. More...
 
std::shared_ptr< BaseStructuregetNextNode ()
 Returns the node that follows this node in a preorder traversal of this node's tree (return left nodes all the way down before coming back and doing siblings from bottom up). More...
 
std::shared_ptr< BaseStructuregetPreviousNode ()
 Returns the node that precedes this node in a preorder traversal of this node's tree (return left nodes all the way down before coming back and doing siblings from bottom up). More...
 
bool isNodeChild (const std::shared_ptr< BaseStructure > aNode) const
 Returns true if aNode is a child of this node. More...
 
std::shared_ptr< BaseStructuregetFirstChild () const
 Returns this node's first child. More...
 
std::shared_ptr< BaseStructuregetLastChild () const
 Returns this node's last child. More...
 
std::shared_ptr< BaseStructuregetChildAfter (const std::shared_ptr< BaseStructure > aChild)
 Returns the child in this node's child vector that immediately follows aChild, which must be a child of this node. More...
 
std::shared_ptr< BaseStructuregetChildBefore (const std::shared_ptr< BaseStructure > aChild)
 Returns the child in this node's child vector that immediately precedes aChild, which must be a child of this node. More...
 
bool isNodeSibling (const std::shared_ptr< BaseStructure > anotherNode) const
 Returns true if anotherNode is a sibling of (has the same parent as) this node. More...
 
size_t getSiblingCount () const
 Returns the number of siblings of this node. More...
 
std::shared_ptr< BaseStructuregetNextSibling ()
 Returns the next sibling of this node in the parent's children vector. More...
 
std::shared_ptr< BaseStructuregetPreviousSibling ()
 Returns the previous sibling of this node in the parent's children vector. More...
 
bool isLeaf () const
 Returns true if this node has no children. More...
 
std::shared_ptr< BaseStructuregetFirstLeaf ()
 Finds and returns the first leaf that is a descendant of this node – either this node or its first child's first leaf. More...
 
std::shared_ptr< BaseStructuregetLastLeaf ()
 Finds and returns the last leaf that is a descendant of this node – either this node or its last child's last leaf. More...
 
std::shared_ptr< BaseStructuregetNextLeaf ()
 Returns the leaf after this node or null if this node is the last leaf in the tree. More...
 
std::shared_ptr< BaseStructuregetPreviousLeaf ()
 Returns the leaf before this node or null if this node is the first leaf in the tree. More...
 
ssize_t getLeafCount ()
 Returns the total number of leaves that are descendants of this node. More...
 
void visitAllStructures (std::shared_ptr< IEvioListener > listener)
 Visit all the structures in this structure (including the structure itself – which is considered its own descendant). More...
 
void visitAllStructures (std::shared_ptr< IEvioListener > listener, std::shared_ptr< IEvioFilter > filter)
 Visit all the structures in this structure (including the structure itself – which is considered its own descendant) in a depth first manner. More...
 
void getMatchingStructures (std::shared_ptr< IEvioFilter > filter, std::vector< std::shared_ptr< BaseStructure >> &vec)
 Visit all the descendant structures, and collect those that pass a filter. More...
 
void transform (std::shared_ptr< BaseStructure > const &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 "transform"). More...
 
virtual StructureType getStructureType () const
 
ByteOrder getByteOrder ()
 What is the byte order of this data? More...
 
void setByteOrder (ByteOrder const &order)
 Set the byte order of this data. More...
 
bool needSwap () const
 Is a byte swap required (i.e. More...
 
virtual std::string toString () const
 Obtain a string representation of the structure. More...
 
std::string treeToString (std::string const &indent) const
 Recursive method to obtain a string representation of the entire tree structure rooted at this structure. More...
 
std::shared_ptr
< BaseStructureHeader
getHeader () const
 Return the header for this structure. More...
 
size_t write (ByteBuffer &dest)
 Write myself out into a byte buffer with fastest algorithm I could find. More...
 
size_t write (uint8_t *dest, ByteOrder const &order)
 Write myself out to a pointer. More...
 
size_t writeQuick (uint8_t *dest)
 Write myself out as evio format data in the data's current byte order given by getByteOrder() at the given pointer. More...
 
size_t writeQuick (ByteBuffer &dest)
 Write myself into a ByteBuffer as evio format data in the data's current byte order given by getByteOrder(). More...
 
uint32_t getNumberDataItems ()
 Get the number of stored data items like number of banks, ints, floats, etc. More...
 
uint32_t setAllHeaderLengths ()
 Compute and set length of all header fields for this structure and all its descendants. More...
 
bool isContainer () const
 Checks whether this structure is a container, i.e. More...
 
uint32_t getTotalBytes () const
 Get the length of this structure in bytes, including the header. More...
 
std::vector< uint8_t > & getRawBytes ()
 Get the raw data of the structure. More...
 
std::vector< int16_t > & getShortData ()
 Gets the raw data as an int16_t vector if the content type as indicated by the header is appropriate. More...
 
std::vector< uint16_t > & getUShortData ()
 Gets the raw data as an uint16_t vector if the content type as indicated by the header is appropriate. More...
 
std::vector< int32_t > & getIntData ()
 Gets the raw data as an int32_t vector if the content type as indicated by the header is appropriate. More...
 
std::vector< uint32_t > & getUIntData ()
 Gets the raw data as an uint32_t vector if the content type as indicated by the header is appropriate. More...
 
std::vector< int64_t > & getLongData ()
 Gets the raw data as an int64_t vector if the content type as indicated by the header is appropriate. More...
 
std::vector< uint64_t > & getULongData ()
 Gets the raw data as an uint64_t vector if the content type as indicated by the header is appropriate. More...
 
std::vector< float > & getFloatData ()
 Gets the raw data as a float vector if the content type as indicated by the header is appropriate. More...
 
std::vector< double > & getDoubleData ()
 Gets the raw data as a double vector if the content type as indicated by the header is appropriate. More...
 
std::vector< signed char > & getCharData ()
 Gets the raw data as an signed char vector, if the contents type as indicated by the header is appropriate. More...
 
std::vector< unsigned char > & getUCharData ()
 Gets the raw data as an unsigned char vector, if the contents type as indicated by the header is appropriate. More...
 
std::vector< std::shared_ptr
< CompositeData > > & 
getCompositeData ()
 Gets the composite data as an vector of CompositeData objects, if the content type as indicated by the header is appropriate. More...
 
std::vector< std::string > & getStringData ()
 Gets the raw data (ascii) as an vector of string objects, if the contents type as indicated by the header is appropriate. More...
 
uint32_t unpackRawBytesToStrings ()
 Extract string data from rawBytes array. More...
 
void updateIntData ()
 If data in this structure was changed by modifying the vector returned from getIntData(), then this method needs to be called in order to make this object internally consistent. More...
 
void updateUIntData ()
 If data in this structure was changed by modifying the vector returned from getUIntData(), then this method needs to be called in order to make this object internally consistent. More...
 
void updateShortData ()
 If data in this structure was changed by modifying the vector returned from getShortData(), then this method needs to be called in order to make this object internally consistent. More...
 
void updateUShortData ()
 If data in this structure was changed by modifying the vector returned from getUShortData(), then this method needs to be called in order to make this object internally consistent. More...
 
void updateLongData ()
 If data in this structure was changed by modifying the vector returned from getLongData(), then this method needs to be called in order to make this object internally consistent. More...
 
void updateULongData ()
 If data in this structure was changed by modifying the vector returned from getULongData(), then this method needs to be called in order to make this object internally consistent. More...
 
void updateCharData ()
 If data in this structure was changed by modifying the vector returned from getCharData(), then this method needs to be called in order to make this object internally consistent. More...
 
void updateUCharData ()
 If data in this structure was changed by modifying the vector returned from getUCharData(), then this method needs to be called in order to make this object internally consistent. More...
 
void updateFloatData ()
 If data in this structure was changed by modifying the vector returned from getFloatData(), then this method needs to be called in order to make this object internally consistent. More...
 
void updateDoubleData ()
 If data in this structure was changed by modifying the vector returned from getDoubleData(), then this method needs to be called in order to make this object internally consistent. More...
 
void updateStringData ()
 If data in this structure was changed by modifying the vector returned from getStringData(), then this method needs to be called in order to make this object internally consistent. More...
 
void updateCompositeData ()
 If data in this structure was changed by modifying the vector returned from getCompositeData(), then this method needs to be called in order to make this object internally consistent. More...
 

Static Public Member Functions

static uint32_t stringToRawSize (const std::string &str)
 This method returns the number of bytes in a raw evio format of the given string vector, not including header. More...
 
static uint32_t stringsToRawSize (std::vector< std::string > const &strings)
 This method returns the number of bytes in a raw evio format of the given string vector, not including header. More...
 
static void stringsToRawBytes (std::vector< std::string > &strings, std::vector< uint8_t > &bytes)
 This method transforms a vector of strings into raw evio format data, not including header. More...
 
static void unpackRawBytesToStrings (std::vector< uint8_t > &bytes, size_t offset, std::vector< std::string > &strData)
 This method extracts a vector of strings from bytes of raw evio string data. More...
 
static void unpackRawBytesToStrings (std::vector< uint8_t > &bytes, size_t offset, size_t maxLength, std::vector< std::string > &strData)
 This method extracts a vector of strings from bytes of raw evio string data. More...
 
static void unpackRawBytesToStrings (uint8_t *bytes, size_t length, std::vector< std::string > &strData)
 This method extracts a vector of strings from bytes of raw evio string data. More...
 
static void unpackRawBytesToStrings (ByteBuffer &buffer, size_t pos, size_t length, std::vector< std::string > &strData)
 This method extracts a vector of strings from buffer containing raw evio string data. More...
 

Protected Member Functions

void setParent (const std::shared_ptr< BaseStructure > &newParent)
 Sets this node's parent to newParent but does not change the parent's child array. More...
 
std::vector< std::shared_ptr
< BaseStructure > > 
getPathToRoot (const std::shared_ptr< BaseStructure > &aNode, int depth) const
 Builds the parents of node up to and including the root node, where the original node is the last element in the returned vector. More...
 
bool getLengthsUpToDate () const
 Get whether the lengths of all header fields for this structure and all it descendants are up to date or not. More...
 
void setLengthsUpToDate (bool lengthsUpToDate)
 Set whether the lengths of all header fields for this structure and all it descendants are up to date or not. More...
 
uint32_t dataLength ()
 Compute the dataLength in 32-bit words. More...
 
void stringsToRawBytes ()
 This method transforms the internal vector of strings into internal rawBytes vector of evio format data not including header. More...
 
 BaseStructure ()
 Constructor. More...
 
 BaseStructure (std::shared_ptr< BaseStructureHeader > head)
 Constructor using a provided header. More...
 
 BaseStructure (const BaseStructure &srcBuf)
 Copy constructor. More...
 
 BaseStructure (BaseStructure &&srcBuf) noexcept
 Move constructor. More...
 
BaseStructureoperator= (BaseStructure &&other) noexcept
 Move assignment operator. More...
 
BaseStructureoperator= (const BaseStructure &other)
 Assignment operator. More...
 
void setRawBytes (uint8_t *bytes, uint32_t len)
 Set the data for the structure. More...
 
void setRawBytes (std::vector< uint8_t > &bytes)
 Set the data for the structure. More...
 

Protected Attributes

std::shared_ptr< BaseStructureparent = nullptr
 This node's parent, or null if this node has no parent. More...
 
std::vector< std::shared_ptr
< BaseStructure > > 
children
 Array of children, may be null if this node has no children. More...
 
bool allowsChildren = true
 True if the node is able to have children. More...
 
std::shared_ptr
< BaseStructureHeader
header
 Holds the header of the bank as a shared pointer. More...
 
std::vector< uint8_t > rawBytes
 The raw data of the structure. More...
 
std::vector< int16_t > shortData
 Used if raw data should be interpreted as shorts. More...
 
std::vector< uint16_t > ushortData
 Used if raw data should be interpreted as unsigned shorts. More...
 
std::vector< int32_t > intData
 Used if raw data should be interpreted as ints. More...
 
std::vector< uint32_t > uintData
 Used if raw data should be interpreted as unsigned ints. More...
 
std::vector< int64_t > longData
 Used if raw data should be interpreted as longs. More...
 
std::vector< uint64_t > ulongData
 Used if raw data should be interpreted as unsigned longs. More...
 
std::vector< double > doubleData
 Used if raw data should be interpreted as doubles. More...
 
std::vector< float > floatData
 Used if raw data should be interpreted as floats. More...
 
std::vector< std::shared_ptr
< CompositeData > > 
compositeData
 Used if raw data should be interpreted as composite type. More...
 
std::vector< signed char > charData
 Used if raw data should be interpreted as signed chars. More...
 
std::vector< unsigned char > ucharData
 Used if raw data should be interpreted as unsigned chars. More...
 
std::vector< std::string > stringList
 Used if raw data should be interpreted as a string. More...
 
int stringEnd = 0
 Keep track of end of the last string added to stringData (including null but not padding). More...
 
bool badStringFormat = false
 True if char data has non-ascii or non-printable characters, or has too little data to be in proper format. More...
 
size_t numberDataItems = 0
 The number of stored data items like number of banks, ints, floats, etc. More...
 
ByteOrder byteOrder {ByteOrder::ENDIAN_LOCAL}
 Endianness of the raw data if appropriate. More...
 
bool lengthsUpToDate = false
 Keep track of whether header length data is up-to-date or not. More...
 

Friends

class EventParser
 
class EvioReader
 
class EvioReaderV4
 
class EventBuilder
 
class StructureTransformer
 
class nodeIterator< std::shared_ptr< BaseStructure > >
 
class nodeBreadthIterator< std::shared_ptr< BaseStructure > >
 

Detailed Description

This is the base class for all evio structures: Banks, Segments, and TagSegments.

It is also a tree node which allows the evio structures to be represented as a tree and iterated over.

The tree code is taken from Java's DefaultMutableTreeNode class which has been ported to C++ and included here. In this code, all nodes, such as children and parent, are shared pointers. That explains inheriting from enable_shared_from_this since "this" object must also be used as a shared pointer.

Author
heddle - author of original Java BaseStructure class.
timmer - add byte order tracking, make setAllHeaderLengths more efficient in Java. Ported to C++.
Date
4/2/2020

Member Typedef Documentation

typedef std::ptrdiff_t evio::BaseStructure::difference_type
typedef std::input_iterator_tag evio::BaseStructure::iterator_category
typedef std::shared_ptr<BaseStructure> evio::BaseStructure::pointer

Constructor & Destructor Documentation

evio::BaseStructure::BaseStructure ( )
protected

Constructor.

See Also
BaseStructureHeader

References header.

evio::BaseStructure::BaseStructure ( std::shared_ptr< BaseStructureHeader head)
explicitprotected

Constructor using a provided header.

Parameters
headthe header to use.
See Also
BaseStructureHeader
evio::BaseStructure::BaseStructure ( const BaseStructure base)
protected

Copy constructor.

Parameters
baseBaseStructure to copy.

References allowsChildren, children, header, lengthsUpToDate, and parent.

evio::BaseStructure::BaseStructure ( BaseStructure &&  base)
protectednoexcept

Member Function Documentation

void evio::BaseStructure::add ( std::shared_ptr< BaseStructure newChild)

Removes newChild from its parent and makes it a child of this node by adding it to the end of this node's child array.

Originally part of java's DefaultMutableTreeNode.

See Also
insert
Parameters
newChildnode to add as a child of this node.
Exceptions
EvioExceptionif newChild is null, or this node does not allow children.

References getChildCount(), getThis(), and insert().

breadth_iterator evio::BaseStructure::bbegin ( )
inline

Get the beginning breadth-first iterator.

Returns
beginning breadth-first iterator.

References getThis().

Referenced by getDepth(), and getLeafCount().

iterator evio::BaseStructure::begin ( )
inline

Get the beginning depth-first iterator.

Returns
beginning depth-first iterator.

References getThis().

breadth_iterator evio::BaseStructure::bend ( )
inline

Get the end breadth-first iterator.

Returns
end breadth-first iterator.

References getThis().

Referenced by getDepth(), and getLeafCount().

std::vector< std::shared_ptr< BaseStructure > >::iterator evio::BaseStructure::childrenBegin ( )

Creates and returns a forward-order begin iterator of this node's children.

Modifying this node's child array invalidates any child iterators created before the modification. Originally part of java's DefaultMutableTreeNode.

Returns
a begin iterator of this node's children.

References children.

std::vector< std::shared_ptr< BaseStructure > >::iterator evio::BaseStructure::childrenEnd ( )

Creates and returns a forward-order end iterator of this node's children.

Modifying this node's child array invalidates any child iterators created before the modification. Originally part of java's DefaultMutableTreeNode.

Returns
an end iterator of this node's children.

References children.

uint32_t evio::BaseStructure::dataLength ( )
protected

Compute the dataLength in 32-bit words.

This is the amount of data needed by a leaf of primitives. For non-leafs (structures of structures) this returns 0. For data types smaller than an int, e.g. a short, it computes assuming padding to an integer number of ints. For example, if we are writing a byte array of length 3 or 4, the it would return 1. If the byte array is 5,6,7 or 8 it would return 2;

Returns
the amount of 32-bit words (ints) needed by a leaf of primitives, else 0.

References evio::DataType::CHAR8, evio::DataType::CHARSTAR8, evio::DataType::COMPOSITE, evio::DataType::getBytes(), getNumberDataItems(), header, isLeaf(), rawBytes, evio::DataType::UCHAR8, and evio::DataType::UNKNOWN32.

Referenced by setAllHeaderLengths().

iterator evio::BaseStructure::end ( )
inline

Get the end depth-first iterator.

Returns
end depth-first iterator.

References getThis().

Referenced by getIndex(), and remove().

bool evio::BaseStructure::getAllowsChildren ( ) const

Returns true if this node is allowed to have children.

Originally part of java's DefaultMutableTreeNode.

Returns
true if this node allows children, else false.

References allowsChildren.

ByteOrder evio::BaseStructure::getByteOrder ( )

What is the byte order of this data?

Returns
ByteOrder#ENDIAN_BIG or ByteOrder#ENDIAN_LITTLE.

References byteOrder.

Referenced by writeQuick().

std::vector< signed char > & evio::BaseStructure::getCharData ( )

Gets the raw data as an signed char vector, if the contents type as indicated by the header is appropriate.

If the returned vector's data is modified, then updateCharData MUST be called!

Returns
the data as an signed char vector, or null if this makes no sense for the given contents type.

References evio::DataType::CHAR8, charData, header, and rawBytes.

std::shared_ptr< BaseStructure > evio::BaseStructure::getChildAfter ( const std::shared_ptr< BaseStructure aChild)

Returns the child in this node's child vector that immediately follows aChild, which must be a child of this node.

If aChild is the last child, returns null. This method performs a linear search of this node's children for aChild and is O(n) where n is the number of children; to traverse the entire vector of children, use an iterator instead. Originally part of java's DefaultMutableTreeNode.

See Also
children
Parameters
aChildchild of this node which immediately precedes the returned child structure.
Exceptions
EvioExceptionif aChild is null or is not a child of this node.
Returns
the child of this node that immediately follows aChild.

References getChildAt(), getChildCount(), and getIndex().

std::shared_ptr< BaseStructure > evio::BaseStructure::getChildAt ( size_t  index) const

Returns the child at the specified index in this node's child vector.

Originally part of java's DefaultMutableTreeNode.

Parameters
indexan index into this node's child array.
Exceptions
std::out_of_rangeif index is out of bounds.
Returns
the BaseStructure in this node's child array at the specified index.

References children.

Referenced by getChildAfter(), getChildBefore(), getFirstChild(), getLastChild(), getNextNode(), and remove().

std::shared_ptr< BaseStructure > evio::BaseStructure::getChildBefore ( const std::shared_ptr< BaseStructure aChild)

Returns the child in this node's child vector that immediately precedes aChild, which must be a child of this node.

If aChild is the first child, returns null. This method performs a linear search of this node's children for aChild and is O(n) where n is the number of children. Originally part of java's DefaultMutableTreeNode.

Parameters
aChildchild of this node which comes immediately after the returned child structure.
Exceptions
EvioExceptionif aChild is null or is not a child of this node.
Returns
the child of this node that immediately precedes aChild.

References getChildAt(), and getIndex().

size_t evio::BaseStructure::getChildCount ( ) const

Returns the number of children of this node.

Originally part of java's DefaultMutableTreeNode.

Returns
the number of children of this node.

References children.

Referenced by add(), getChildAfter(), getFirstChild(), getLastChild(), getNextNode(), isLeaf(), isNodeChild(), removeAllChildren(), and treeToString().

std::vector< std::shared_ptr< BaseStructure > > evio::BaseStructure::getChildren ( ) const

Get the children of this structure.

Returns
the children of this structure.

References children.

std::vector< std::shared_ptr< CompositeData > > & evio::BaseStructure::getCompositeData ( )

Gets the composite data as an vector of CompositeData objects, if the content type as indicated by the header is appropriate.

Returns
the data as a vector of CompositeData objects, or null if this makes no sense for the given content type.
Exceptions
EvioExceptionif the data is internally inconsistent.

References byteOrder, evio::DataType::COMPOSITE, compositeData, header, evio::CompositeData::parse(), and rawBytes.

uint32_t evio::BaseStructure::getDepth ( )

Returns the depth of the tree rooted at this node – the longest distance from this node to a leaf.

If this node has no children, returns 0. This operation is much more expensive than getLevel() because it must effectively traverse the entire tree rooted at this node. Originally part of java's DefaultMutableTreeNode.

See Also
getLevel
Exceptions
EvioExceptionif internal logic error.
Returns
the depth of the tree whose root is this node.

References bbegin(), bend(), and getLevel().

std::vector< double > & evio::BaseStructure::getDoubleData ( )

Gets the raw data as a double vector if the content type as indicated by the header is appropriate.

If the returned vector's data is modified, then updateDoubleData MUST be called!

Returns
a reference to the data as a double vector.
Exceptions
EvioExceptionif contained data type is not double.

References evio::DataType::DOUBLE64, doubleData, header, needSwap(), rawBytes, and SWAP_64.

std::shared_ptr< BaseStructure > evio::BaseStructure::getFirstChild ( ) const

Returns this node's first child.

If this node has no children, throws EvioException. Originally part of java's DefaultMutableTreeNode.

Returns
the first child of this node
Exceptions
EvioExceptionif this node has no children.

References getChildAt(), and getChildCount().

std::shared_ptr< BaseStructure > evio::BaseStructure::getFirstLeaf ( )

Finds and returns the first leaf that is a descendant of this node – either this node or its first child's first leaf.

Returns this node if it is a leaf. Originally part of java's DefaultMutableTreeNode.

See Also
isLeaf
isNodeDescendant
Returns
the first leaf in the subtree rooted at this node.

References getThis().

std::vector< float > & evio::BaseStructure::getFloatData ( )

Gets the raw data as a float vector if the content type as indicated by the header is appropriate.

If the returned vector's data is modified, then updateFloatData MUST be called!

Returns
a reference to the data as a float vector.
Exceptions
EvioExceptionif contained data type is not float.

References evio::DataType::FLOAT32, floatData, header, needSwap(), rawBytes, and SWAP_32.

std::shared_ptr< BaseStructureHeader > evio::BaseStructure::getHeader ( ) const

Return the header for this structure.

Returns
the header for this structure.

References header.

ssize_t evio::BaseStructure::getIndex ( const std::shared_ptr< BaseStructure aChild)

Returns the index of the specified child in this node's child vector.

If the specified node is not a child of this node, returns -1. This method performs a linear search and is O(n) where n is the number of children. Originally part of java's DefaultMutableTreeNode.

Parameters
aChildthe BaseStructure to search for among this node's children.
Exceptions
EvioExceptionif aChild is null.
Returns
an int giving the index of the node in this node's child array, or -1 if the specified node is a not a child of this node.

References children, end(), and isNodeChild().

Referenced by getChildAfter(), getChildBefore(), and remove().

std::vector< int32_t > & evio::BaseStructure::getIntData ( )

Gets the raw data as an int32_t vector if the content type as indicated by the header is appropriate.

If the returned vector's data is modified, then updateIntData MUST be called!

Returns
a reference to the data as an int32_t vector.
Exceptions
EvioExceptionif contained data type is not int32_t.

References header, evio::DataType::INT32, intData, needSwap(), rawBytes, and SWAP_32.

std::shared_ptr< BaseStructure > evio::BaseStructure::getLastChild ( ) const

Returns this node's last child.

If this node has no children, throws EvioException. Originally part of java's DefaultMutableTreeNode.

Returns
the last child of this node.
Exceptions
EvioExceptionif this node has no children.

References getChildAt(), and getChildCount().

std::shared_ptr< BaseStructure > evio::BaseStructure::getLastLeaf ( )

Finds and returns the last leaf that is a descendant of this node – either this node or its last child's last leaf.

Returns this node if it is a leaf. Originally part of java's DefaultMutableTreeNode.

See Also
isLeaf
isNodeDescendant
Returns
the last leaf in the subtree rooted at this node.

References getThis().

ssize_t evio::BaseStructure::getLeafCount ( )

Returns the total number of leaves that are descendants of this node.

If this node is a leaf, returns 1. This method is O(n) where n is the number of descendants of this node. Originally part of java's DefaultMutableTreeNode.

See Also
isNodeAncestor
Exceptions
EvioExceptionif tree has zero leaves.
Returns
the number of leaves beneath this node.

References bbegin(), and bend().

bool evio::BaseStructure::getLengthsUpToDate ( ) const
protected

Get whether the lengths of all header fields for this structure and all it descendants are up to date or not.

Returns
whether the lengths of all header fields for this structure and all it descendants are up to date or not.

References lengthsUpToDate.

uint32_t evio::BaseStructure::getLevel ( ) const

Returns the number of levels above this node – the distance from the root to this node.

If this node is the root, returns 0. Originally part of java's DefaultMutableTreeNode.

See Also
getDepth
Returns
the number of levels above this node.

References getThisConst().

Referenced by getDepth(), and getSharedAncestor().

std::vector< int64_t > & evio::BaseStructure::getLongData ( )

Gets the raw data as an int64_t vector if the content type as indicated by the header is appropriate.

If the returned vector's data is modified, then updateLongData MUST be called!

Returns
a reference to the data as an int64_t vector.
Exceptions
EvioExceptionif contained data type is not int64_t.

References header, evio::DataType::LONG64, longData, needSwap(), rawBytes, and SWAP_64.

void evio::BaseStructure::getMatchingStructures ( std::shared_ptr< IEvioFilter filter,
std::vector< std::shared_ptr< BaseStructure >> &  vec 
)

Visit all the descendant structures, and collect those that pass a filter.

Parameters
filterthe filter that must be passed. If null, this will return all the structures.
vecvector provided to contain all structures that are accepted by the filter.

References visitAllStructures().

std::shared_ptr< BaseStructure > evio::BaseStructure::getNextLeaf ( )

Returns the leaf after this node or null if this node is the last leaf in the tree.

This operation is very inefficient. In order to determine the next node, this method first performs a linear search in the parent's child-list in order to find the current node.

This implementation makes the operation suitable for short traversals from a known position. But to traverse all of the leaves in the tree, you should use A depth-first iterator of the nodes in the tree and use isLeaf on each node to determine which are leaves. Originally part of java's DefaultMutableTreeNode.

See Also
nodeIterator
isLeaf
Returns
returns the next leaf past this node.

References getNextSibling(), and getParent().

std::shared_ptr< BaseStructure > evio::BaseStructure::getNextNode ( )

Returns the node that follows this node in a preorder traversal of this node's tree (return left nodes all the way down before coming back and doing siblings from bottom up).

Returns null if this node is the last node of the traversal. This is an inefficient way to traverse the entire tree; use an iterator instead. Originally part of java's DefaultMutableTreeNode.

Returns
the node that follows this node in a preorder traversal, or null if this node is last.

References getChildAt(), getChildCount(), getNextSibling(), and getParent().

std::shared_ptr< BaseStructure > evio::BaseStructure::getNextSibling ( )

Returns the next sibling of this node in the parent's children vector.

Returns null if this node has no parent or is the parent's last child. This method performs a linear search that is O(n) where n is the number of children; to traverse the entire array, use the parent's child iterator instead. Originally part of java's DefaultMutableTreeNode.

See Also
children.
Exceptions
EvioExceptionif child of parent is not a sibling.
Returns
the sibling of this node that immediately follows this node.

References getParent(), getThis(), and isNodeSibling().

Referenced by getNextLeaf(), and getNextNode().

uint32_t evio::BaseStructure::getNumberDataItems ( )

Get the number of stored data items like number of banks, ints, floats, etc.

(not the size in ints or bytes). Some items may be padded such as shorts and bytes. This will tell the meaningful number of such data items. In the case of containers, returns number of 32-bit words not in header.

Returns
number of stored data items (not size or length), or number of words if container.

References evio::DataType::CHARSTAR8, evio::DataType::COMPOSITE, compositeData, evio::DataType::getBytes(), getStringData(), header, isContainer(), numberDataItems, and rawBytes.

Referenced by dataLength().

std::shared_ptr< BaseStructure > evio::BaseStructure::getParent ( ) const

Returns this node's parent or null if this node has no parent.

Originally part of java's DefaultMutableTreeNode.

Returns
this node's parent BaseStructure, or null if this node has no parent.

References parent.

Referenced by getNextLeaf(), getNextNode(), getNextSibling(), getPreviousLeaf(), getPreviousNode(), getPreviousSibling(), getSiblingCount(), isNodeSibling(), isRoot(), and removeFromParent().

std::vector< std::shared_ptr< BaseStructure > > evio::BaseStructure::getPath ( )

Returns the path from the root, to get to this node.

The last element in the path is this node. Originally part of java's DefaultMutableTreeNode.

Returns
an vector of BaseStructure shared pointer giving the path, where the first element in the path is the root and the last element is this node.

References getPathToRoot(), and getThis().

std::vector< std::shared_ptr< BaseStructure > > evio::BaseStructure::getPathToRoot ( const std::shared_ptr< BaseStructure > &  aNode,
int  depth 
) const
protected

Builds the parents of node up to and including the root node, where the original node is the last element in the returned vector.

The length of the returned array gives the node's depth in the tree. Originally part of java's DefaultMutableTreeNode.

Parameters
aNodethe BaseStructure to get the path for.
depthan int giving the number of steps already taken towards the root (on recursive calls), used to size the returned vector.
Returns
a vector of BaseStructure shared pointer giving the path from the root to the specified node.

Referenced by getPath().

std::shared_ptr< BaseStructure > evio::BaseStructure::getPreviousLeaf ( )

Returns the leaf before this node or null if this node is the first leaf in the tree.

This operation is very inefficient. In order to determine the previous node, this method first performs a linear search in the parent's child-list in order to find the current node.

This implementation makes the operation suitable for short traversals from a known position. But to traverse all of the leaves in the tree, you should use A depth-first iterator of the nodes in the tree and use isLeaf on each node to determine which are leaves. Originally part of java's DefaultMutableTreeNode.

See Also
nodeIterator
isLeaf
Returns
returns the leaf before this node.

References getParent(), and getPreviousSibling().

std::shared_ptr< BaseStructure > evio::BaseStructure::getPreviousNode ( )

Returns the node that precedes this node in a preorder traversal of this node's tree (return left nodes all the way down before coming back and doing siblings from bottom up).

Returns null if this node is the first node of the traversal – the root of the tree. This is an inefficient way to traverse the entire tree; use an iterator instead. Originally part of java's DefaultMutableTreeNode.

Returns
the node that precedes this node in a preorder traversal, or null if this node is the first.

References getParent(), and getPreviousSibling().

std::shared_ptr< BaseStructure > evio::BaseStructure::getPreviousSibling ( )

Returns the previous sibling of this node in the parent's children vector.

Returns null if this node has no parent or is the parent's first child. This method performs a linear search that is O(n) where n is the number of children. Originally part of java's DefaultMutableTreeNode.

Exceptions
EvioExceptionif child of parent is not a sibling.
Returns
the sibling of this node that immediately precedes this node.

References getParent(), getThis(), and isNodeSibling().

Referenced by getPreviousLeaf(), and getPreviousNode().

std::vector< uint8_t > & evio::BaseStructure::getRawBytes ( )

Get the raw data of the structure.

Returns
the raw data of the structure.

References rawBytes.

std::shared_ptr< BaseStructure > evio::BaseStructure::getRoot ( )

Returns the root of the tree that contains this node.

The root is the ancestor with a null parent. Originally part of java's DefaultMutableTreeNode.

See Also
isNodeAncestor
Returns
the root of the tree that contains this node.

References getThis().

Referenced by isNodeRelated().

std::shared_ptr< BaseStructure > evio::BaseStructure::getSharedAncestor ( std::shared_ptr< BaseStructure aNode)

Returns the nearest common ancestor to this node and aNode.

Returns null if no such ancestor exists – if this node and aNode are in different trees or if aNode is null. A node is considered an ancestor of itself. Originally part of java's DefaultMutableTreeNode.

See Also
isNodeAncestor
isNodeDescendant
Parameters
aNodenode to find common ancestor with.
Exceptions
EvioExceptionif internal logic error.
Returns
nearest ancestor common to this node and aNode, or null if none.

References getLevel(), and getThis().

std::vector< int16_t > & evio::BaseStructure::getShortData ( )

Gets the raw data as an int16_t vector if the content type as indicated by the header is appropriate.

If the returned vector's data is modified, then updateShortData MUST be called!

Returns
a reference to the data as an int16_t vector.
Exceptions
EvioExceptionif contained data type is not int16_t.

References header, needSwap(), rawBytes, evio::DataType::SHORT16, shortData, and SWAP_16.

size_t evio::BaseStructure::getSiblingCount ( ) const

Returns the number of siblings of this node.

A node is its own sibling (if it has no parent or no siblings, this method returns 1). Originally part of java's DefaultMutableTreeNode.

Returns
the number of siblings of this node.

References getParent().

std::vector< std::string > & evio::BaseStructure::getStringData ( )

Gets the raw data (ascii) as an vector of string objects, if the contents type as indicated by the header is appropriate.

For any other behavior, the user should retrieve the data as a bytes and manipulate it in the exact manner desired. If there are non ascii or non-printing ascii chars or the bytes or not in evio format, a single string containing everything is returned.

Originally, in evio versions 1, 2 and 3, only one string was stored. Subsequent changes allowed a vector of strings to be stored and retrieved. The changes are backwards compatible.

The following is true about the string raw data format:

  • Each string IS immediately followed by an ending null (0).
  • All string data are further padded/ended with at least one 0x4 valued ASCII char (up to 4 possible).
  • The presence of 1 to 4 ending 4's distinguishes the recent string array version from the original, single string version.
  • The original version string may be padded with anything after its ending null.
Returns
the data as a vector of string objects if DataType is CHARSTAR8, or null if this makes no sense for the given type.

References evio::DataType::CHARSTAR8, header, rawBytes, stringList, and unpackRawBytesToStrings().

Referenced by getNumberDataItems().

virtual StructureType evio::BaseStructure::getStructureType ( ) const
inlinevirtual
std::shared_ptr<const BaseStructure> evio::BaseStructure::getThisConst ( ) const
inline
uint32_t evio::BaseStructure::getTotalBytes ( ) const

Get the length of this structure in bytes, including the header.

Returns
the length of this structure in bytes, including the header.

References header.

Referenced by write().

std::vector< unsigned char > & evio::BaseStructure::getUCharData ( )

Gets the raw data as an unsigned char vector, if the contents type as indicated by the header is appropriate.

If the returned vector's data is modified, then updateCharData MUST be called!

Returns
the data as an unsigned char vector, or null if this makes no sense for the given contents type.

References header, rawBytes, evio::DataType::UCHAR8, and ucharData.

std::vector< uint32_t > & evio::BaseStructure::getUIntData ( )

Gets the raw data as an uint32_t vector if the content type as indicated by the header is appropriate.

If the returned vector's data is modified, then updateUIntData MUST be called!

Returns
a reference to the data as an uint32_t vector.
Exceptions
EvioExceptionif contained data type is not uint32_t.

References header, needSwap(), rawBytes, SWAP_32, evio::DataType::UINT32, and uintData.

std::vector< uint64_t > & evio::BaseStructure::getULongData ( )

Gets the raw data as an uint64_t vector if the content type as indicated by the header is appropriate.

If the returned vector's data is modified, then updateULongData MUST be called!

Returns
a reference to the data as an uint64_t vector.
Exceptions
EvioExceptionif contained data type is not uint64_t.

References header, needSwap(), rawBytes, SWAP_64, evio::DataType::ULONG64, and ulongData.

std::vector< uint16_t > & evio::BaseStructure::getUShortData ( )

Gets the raw data as an uint16_t vector if the content type as indicated by the header is appropriate.

If the returned vector's data is modified, then updateUShortData MUST be called!

Returns
a reference to the data as an uint16_t vector.
Exceptions
EvioExceptionif contained data type is not uint16_t.

References header, needSwap(), rawBytes, SWAP_16, evio::DataType::USHORT16, and ushortData.

void evio::BaseStructure::insert ( const std::shared_ptr< BaseStructure newChild,
size_t  childIndex 
)

Removes newChild from its present parent (if it has a parent), sets the child's parent to this node, and then adds the child to this node's child array at index childIndex.

newChild must not be null and must not be an ancestor of this node. Originally part of java's DefaultMutableBaseStructure.

Parameters
newChildthe BaseStructure to insert under this node.
childIndexthe index in this node's child array. where this node is to be inserted.
Exceptions
std::out_of_rangeif childIndex is out of bounds.
EvioExceptionif newChild is null, is an ancestor of this node, or this node does not allow children.
See Also
isNodeDescendant

References allowsChildren, children, getThis(), isNodeAncestor(), and setLengthsUpToDate().

Referenced by add().

bool evio::BaseStructure::isContainer ( ) const

Checks whether this structure is a container, i.e.

a structure of structures.

Returns
true if this structure is a container. This is the same check as getAllowsChildren.

References header.

Referenced by getNumberDataItems().

bool evio::BaseStructure::isLeaf ( ) const

Returns true if this node has no children.

To distinguish between nodes that have no children and nodes that cannot have children (e.g. to distinguish files from empty directories), use this method in conjunction with getAllowsChildren. Originally part of java's DefaultMutableBaseStructure.

See Also
getAllowsChildren
Returns
true if this node has no children.

References getChildCount().

Referenced by dataLength(), setAllHeaderLengths(), treeToString(), and write().

bool evio::BaseStructure::isNodeAncestor ( const std::shared_ptr< BaseStructure anotherNode) const

Returns true if anotherNode is an ancestor of this node – if it is this node, this node's parent, or an ancestor of this node's parent.

(Note that a node is considered an ancestor of itself.) If anotherNode is null, this method returns false. This operation is at worst O(h) where h is the distance from the root to this node. Originally part of java's DefaultMutableTreeNode.

See Also
isNodeDescendant
getSharedAncestor
Parameters
anotherNodenode to test as an ancestor of this node
Returns
true if this node is a descendant of anotherNode

References getThisConst().

Referenced by insert().

bool evio::BaseStructure::isNodeChild ( const std::shared_ptr< BaseStructure aNode) const

Returns true if aNode is a child of this node.

If aNode is null, this method returns false. Originally part of java's DefaultMutableTreeNode.

Parameters
aNodestructure to test if it's a child of this one.
Returns
true if aNode is a child of this node; false if aNode is null.

References getChildCount(), and getThisConst().

Referenced by getIndex(), and remove().

bool evio::BaseStructure::isNodeDescendant ( std::shared_ptr< BaseStructure anotherNode)

Returns true if anotherNode is a descendant of this node – if it is this node, one of this node's children, or a descendant of one of this node's children.

Note that a node is considered a descendant of itself. If anotherNode is null, returns false. This operation is at worst O(h) where h is the distance from the root to anotherNode. Originally part of java's DefaultMutableTreeNode.

See Also
isNodeAncestor
getSharedAncestor
Parameters
anotherNodenode to test as descendant of this node
Returns
true if this node is an ancestor of anotherNode

References getThis().

bool evio::BaseStructure::isNodeRelated ( std::shared_ptr< BaseStructure aNode)

Returns true if and only if aNode is in the same tree as this node.

Returns false if aNode is null. Originally part of java's DefaultMutableTreeNode.

See Also
getSharedAncestor
getRoot
Parameters
aNodestructure to test if it's in the same tree as this one.
Returns
true if aNode is in the same tree as this node; false if aNode is null

References getRoot().

bool evio::BaseStructure::isNodeSibling ( const std::shared_ptr< BaseStructure anotherNode) const

Returns true if anotherNode is a sibling of (has the same parent as) this node.

A node is its own sibling. If anotherNode is null, returns false. Originally part of java's DefaultMutableTreeNode.

Parameters
anotherNodenode to test as sibling of this node.
Exceptions
EvioExceptionif sibling has different parent.
Returns
true if anotherNode is a sibling of this node.

References getParent(), and getThisConst().

Referenced by getNextSibling(), and getPreviousSibling().

bool evio::BaseStructure::isRoot ( ) const

Returns true if this node is the root of the tree.

The root is the only node in the tree with a null parent; every tree has exactly one root. Originally part of java's DefaultMutableTreeNode.

Returns
true if this node is the root of its tree.

References getParent().

bool evio::BaseStructure::needSwap ( ) const

Is a byte swap required (i.e.

is the data endian opposite of local endian)?

Returns
true if byte swapping is required.

References byteOrder, and evio::ByteOrder::ENDIAN_LOCAL.

Referenced by getDoubleData(), getFloatData(), getIntData(), getLongData(), getShortData(), getUIntData(), getULongData(), and getUShortData().

BaseStructure & evio::BaseStructure::operator= ( BaseStructure &&  other)
protectednoexcept

Move assignment operator.

Parameters
otherright side object.
Returns
left side object.

References allowsChildren, badStringFormat, byteOrder, charData, children, compositeData, doubleData, floatData, header, intData, lengthsUpToDate, longData, numberDataItems, parent, rawBytes, shortData, stringEnd, stringList, ucharData, uintData, ulongData, and ushortData.

BaseStructure & evio::BaseStructure::operator= ( const BaseStructure other)
protected

Assignment operator.

Parameters
otherright side object.
Returns
left side object.

References allowsChildren, children, header, lengthsUpToDate, and parent.

void evio::BaseStructure::remove ( size_t  childIndex)

Removes the child at the specified index from this node's children and sets that node's parent to null.

The child node to remove must be a BaseStructure. Originally part of java's DefaultMutableTreeNode.

Parameters
childIndexthe index of the child to remove
Exceptions
std::out_of_rangeif childIndex is out of bounds

References children, end(), getChildAt(), and setLengthsUpToDate().

void evio::BaseStructure::remove ( const std::shared_ptr< BaseStructure aChild)

Removes aChild from this node's child vector, giving it a null parent.

Originally part of java's DefaultMutableTreeNode.

Parameters
aChilda child of this node to remove
Exceptions
EvioExceptionif aChild is not a child of this node

References getIndex(), and isNodeChild().

void evio::BaseStructure::removeAllChildren ( )

Removes all of this node's children, setting their parents to null.

If this node has no children, this method does nothing. Originally part of java's DefaultMutableTreeNode.

References getChildCount().

Referenced by setAllowsChildren().

void evio::BaseStructure::removeFromParent ( )

Removes the subtree rooted at this node from the tree, giving this node a null parent.

Does nothing if this node is the root of its tree. Originally part of java's DefaultMutableTreeNode.

References getParent(), and getThis().

uint32_t evio::BaseStructure::setAllHeaderLengths ( )

Compute and set length of all header fields for this structure and all its descendants.

For writing events, this will be crucial for setting the values in the headers.

Returns
the length that would go in the header field (for a leaf).
Exceptions
EvioExceptionif the length is too large.

References children, dataLength(), header, isLeaf(), lengthsUpToDate, and setLengthsUpToDate().

Referenced by updateCharData(), updateCompositeData(), updateDoubleData(), updateFloatData(), updateIntData(), updateLongData(), updateShortData(), updateStringData(), updateUCharData(), updateUIntData(), updateULongData(), and updateUShortData().

void evio::BaseStructure::setAllowsChildren ( bool  allows)

Determines whether or not this node is allowed to have children.

If allows is false, all of this node's children are removed. Originally part of java's DefaultMutableTreeNode.

Note: By default, a node allows children.

Parameters
allowstrue if this node is allowed to have children.

References allowsChildren, and removeAllChildren().

void evio::BaseStructure::setByteOrder ( ByteOrder const &  order)

Set the byte order of this data.

This method cannot be used to swap data. It is only used to describe the endianness of the rawdata contained.

Parameters
orderByteOrder#ENDIAN_BIG or ByteOrder#ENDIAN_LITTLE.

References byteOrder.

void evio::BaseStructure::setLengthsUpToDate ( bool  lenUpToDate)
protected

Set whether the lengths of all header fields for this structure and all it descendants are up to date or not.

Parameters
lenUpToDateare the lengths of all header fields for this structure and all it descendants up to date or not.

References lengthsUpToDate, and parent.

Referenced by insert(), remove(), setAllHeaderLengths(), updateCharData(), updateCompositeData(), updateDoubleData(), updateFloatData(), updateIntData(), updateLongData(), updateShortData(), updateStringData(), updateUCharData(), updateUIntData(), updateULongData(), and updateUShortData().

void evio::BaseStructure::setParent ( const std::shared_ptr< BaseStructure > &  newParent)
protected

Sets this node's parent to newParent but does not change the parent's child array.

This method is called from insert and remove to reassign a child's parent, it should not be messaged from anywhere else. Originally part of java's DefaultMutableBaseStructure.

Parameters
newParentthis node's new parent.

References parent.

void evio::BaseStructure::setRawBytes ( uint8_t *  bytes,
uint32_t  len 
)
protected

Set the data for the structure.

Parameters
bytespointer to the data to be copied.
lennumber of bytes to be copied.

References rawBytes.

void evio::BaseStructure::setRawBytes ( std::vector< uint8_t > &  bytes)
protected

Set the data for the structure.

Parameters
bytesvector of data to be copied.

References rawBytes.

void evio::BaseStructure::stringsToRawBytes ( )
protected

This method transforms the internal vector of strings into internal rawBytes vector of evio format data not including header.

References header, numberDataItems, rawBytes, stringList, and evio::Util::stringsToRawSize().

Referenced by updateStringData().

void evio::BaseStructure::stringsToRawBytes ( std::vector< std::string > &  strings,
std::vector< uint8_t > &  bytes 
)
static

This method transforms a vector of strings into raw evio format data, not including header.

Parameters
stringsvector of strings to transform.
bytesvector of bytes to contain evio formatted strings.

References stringsToRawSize().

uint32_t evio::BaseStructure::stringsToRawSize ( std::vector< std::string > const &  strings)
static

This method returns the number of bytes in a raw evio format of the given string vector, not including header.

Parameters
stringsvector of strings to size.
Returns
the number of bytes in a raw evio format of the given strings.
0 if vector empty.

Referenced by stringsToRawBytes().

uint32_t evio::BaseStructure::stringToRawSize ( const std::string &  str)
static

This method returns the number of bytes in a raw evio format of the given string vector, not including header.

Parameters
strvector of strings to size.
Returns
the number of bytes in a raw evio format of the given strings.
0 if vector empty.
std::string evio::BaseStructure::toString ( ) const
virtual

Obtain a string representation of the structure.

Returns
a string representation of the structure.

Reimplemented in evio::EvioEvent.

References children, getStructureType(), header, rawBytes, evio::StructureType::STRUCT_BANK, evio::StructureType::toString(), and evio::DataType::toString().

Referenced by treeToString().

void evio::BaseStructure::transform ( std::shared_ptr< BaseStructure > const &  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 "transform").

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.

Parameters
structureBaseStructure from which to copy data.

References children, evio::DataType::getDataType(), evio::DataType::isStructure(), and lengthsUpToDate.

std::string evio::BaseStructure::treeToString ( std::string const &  indent) const

Recursive method to obtain a string representation of the entire tree structure rooted at this structure.

Parameters
indentstring containing indentation for this structure. Generally called with "".
Returns
a string representation of the entire tree structure rooted at this structure.

References children, getChildCount(), isLeaf(), and toString().

uint32_t evio::BaseStructure::unpackRawBytesToStrings ( )

Extract string data from rawBytes array.

Returns
number of strings extracted from bytes.

References badStringFormat, rawBytes, stringEnd, and stringList.

Referenced by getStringData(), and unpackRawBytesToStrings().

void evio::BaseStructure::unpackRawBytesToStrings ( std::vector< uint8_t > &  bytes,
size_t  offset,
std::vector< std::string > &  strData 
)
static

This method extracts a vector of strings from bytes of raw evio string data.

Parameters
bytesraw evio string data.
offsetoffset into raw data array.
strDatavector in which to place extracted strings.

References unpackRawBytesToStrings().

void evio::BaseStructure::unpackRawBytesToStrings ( std::vector< uint8_t > &  bytes,
size_t  offset,
size_t  maxLength,
std::vector< std::string > &  strData 
)
static

This method extracts a vector of strings from bytes of raw evio string data.

Don't go beyond the specified max character limit and stop at the first non-character value.

Parameters
bytesraw evio string data.
offsetoffset into raw data vector.
maxLengthmax length in bytes of valid data in bytes vector.
strDatavector in which to place extracted strings.
void evio::BaseStructure::unpackRawBytesToStrings ( uint8_t *  bytes,
size_t  length,
std::vector< std::string > &  strData 
)
static

This method extracts a vector of strings from bytes of raw evio string data.

Don't go beyond the specified max character limit and stop at the first non-character value.

Parameters
bytesraw evio string data.
lengthlength in bytes of valid data at bytes pointer.
strDatavector in which to place extracted strings.
void evio::BaseStructure::unpackRawBytesToStrings ( ByteBuffer buffer,
size_t  pos,
size_t  length,
std::vector< std::string > &  strData 
)
static

This method extracts a vector of strings from buffer containing raw evio string data.

Parameters
bufferbuffer containing evio string data.
posposition of string data in buffer.
lengthlength of string data in buffer in bytes.
strDatavector in which to place extracted strings.

References evio::ByteBuffer::array(), and evio::ByteBuffer::arrayOffset().

void evio::BaseStructure::updateCharData ( )

If data in this structure was changed by modifying the vector returned from getCharData(), then this method needs to be called in order to make this object internally consistent.

Exceptions
EvioExceptionif this object corresponds to a different data type.

References evio::DataType::CHAR8, charData, header, numberDataItems, rawBytes, setAllHeaderLengths(), setLengthsUpToDate(), and evio::DataType::toString().

void evio::BaseStructure::updateCompositeData ( )

If data in this structure was changed by modifying the vector returned from getCompositeData(), then this method needs to be called in order to make this object internally consistent.

Exceptions
EvioExceptionif this object corresponds to a different data type.

References byteOrder, evio::DataType::COMPOSITE, compositeData, evio::CompositeData::generateRawBytes(), header, numberDataItems, rawBytes, setAllHeaderLengths(), setLengthsUpToDate(), and evio::DataType::toString().

void evio::BaseStructure::updateDoubleData ( )

If data in this structure was changed by modifying the vector returned from getDoubleData(), then this method needs to be called in order to make this object internally consistent.

Exceptions
EvioExceptionif this object corresponds to a different data type.

References byteOrder, evio::ByteOrder::byteSwap64(), evio::DataType::DOUBLE64, doubleData, header, evio::ByteOrder::needToSwap(), numberDataItems, rawBytes, setAllHeaderLengths(), setLengthsUpToDate(), and evio::DataType::toString().

void evio::BaseStructure::updateFloatData ( )

If data in this structure was changed by modifying the vector returned from getFloatData(), then this method needs to be called in order to make this object internally consistent.

Exceptions
EvioExceptionif this object corresponds to a different data type.

References byteOrder, evio::ByteOrder::byteSwap32(), evio::DataType::FLOAT32, floatData, header, evio::ByteOrder::needToSwap(), numberDataItems, rawBytes, setAllHeaderLengths(), setLengthsUpToDate(), and evio::DataType::toString().

void evio::BaseStructure::updateIntData ( )

If data in this structure was changed by modifying the vector returned from getIntData(), then this method needs to be called in order to make this object internally consistent.

Exceptions
EvioExceptionif this object corresponds to a different data type.

References byteOrder, evio::ByteOrder::byteSwap32(), header, evio::DataType::INT32, intData, evio::ByteOrder::needToSwap(), numberDataItems, rawBytes, setAllHeaderLengths(), setLengthsUpToDate(), and evio::DataType::toString().

void evio::BaseStructure::updateLongData ( )

If data in this structure was changed by modifying the vector returned from getLongData(), then this method needs to be called in order to make this object internally consistent.

Exceptions
EvioExceptionif this object corresponds to a different data type.

References byteOrder, evio::ByteOrder::byteSwap64(), header, evio::DataType::LONG64, longData, evio::ByteOrder::needToSwap(), numberDataItems, rawBytes, setAllHeaderLengths(), setLengthsUpToDate(), and evio::DataType::toString().

void evio::BaseStructure::updateShortData ( )

If data in this structure was changed by modifying the vector returned from getShortData(), then this method needs to be called in order to make this object internally consistent.

Exceptions
EvioExceptionif this object corresponds to a different data type.

References byteOrder, evio::ByteOrder::byteSwap16(), header, evio::ByteOrder::needToSwap(), numberDataItems, rawBytes, setAllHeaderLengths(), setLengthsUpToDate(), evio::DataType::SHORT16, shortData, and evio::DataType::toString().

void evio::BaseStructure::updateStringData ( )

If data in this structure was changed by modifying the vector returned from getStringData(), then this method needs to be called in order to make this object internally consistent.

Exceptions
EvioExceptionif this object corresponds to a different data type.

References evio::DataType::CHARSTAR8, header, setAllHeaderLengths(), setLengthsUpToDate(), stringsToRawBytes(), and evio::DataType::toString().

void evio::BaseStructure::updateUCharData ( )

If data in this structure was changed by modifying the vector returned from getUCharData(), then this method needs to be called in order to make this object internally consistent.

Exceptions
EvioExceptionif this object corresponds to a different data type.

References header, numberDataItems, rawBytes, setAllHeaderLengths(), setLengthsUpToDate(), evio::DataType::toString(), evio::DataType::UCHAR8, and ucharData.

void evio::BaseStructure::updateUIntData ( )

If data in this structure was changed by modifying the vector returned from getUIntData(), then this method needs to be called in order to make this object internally consistent.

Exceptions
EvioExceptionif this object corresponds to a different data type.

References byteOrder, evio::ByteOrder::byteSwap32(), header, evio::ByteOrder::needToSwap(), numberDataItems, rawBytes, setAllHeaderLengths(), setLengthsUpToDate(), evio::DataType::toString(), evio::DataType::UINT32, and uintData.

void evio::BaseStructure::updateULongData ( )

If data in this structure was changed by modifying the vector returned from getULongData(), then this method needs to be called in order to make this object internally consistent.

Exceptions
EvioExceptionif this object corresponds to a different data type.

References byteOrder, evio::ByteOrder::byteSwap64(), header, evio::ByteOrder::needToSwap(), numberDataItems, rawBytes, setAllHeaderLengths(), setLengthsUpToDate(), evio::DataType::toString(), evio::DataType::ULONG64, and ulongData.

void evio::BaseStructure::updateUShortData ( )

If data in this structure was changed by modifying the vector returned from getUShortData(), then this method needs to be called in order to make this object internally consistent.

Exceptions
EvioExceptionif this object corresponds to a different data type.

References byteOrder, evio::ByteOrder::byteSwap16(), header, evio::ByteOrder::needToSwap(), numberDataItems, rawBytes, setAllHeaderLengths(), setLengthsUpToDate(), evio::DataType::toString(), evio::DataType::USHORT16, and ushortData.

void evio::BaseStructure::visitAllStructures ( std::shared_ptr< IEvioListener listener)

Visit all the structures in this structure (including the structure itself – which is considered its own descendant).

This is similar to listening to the event as it is being parsed, but is done to a complete (already) parsed event.

Parameters
listenera listener to notify as each structure is visited.

References getThis().

Referenced by getMatchingStructures().

void evio::BaseStructure::visitAllStructures ( std::shared_ptr< IEvioListener listener,
std::shared_ptr< IEvioFilter filter 
)

Visit all the structures in this structure (including the structure itself – which is considered its own descendant) in a depth first manner.

Parameters
listenera listener to notify as each structure is visited.
filteran 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.

References getThis().

size_t evio::BaseStructure::write ( ByteBuffer byteBuffer)

Write myself out into a byte buffer with fastest algorithm I could find.

Parameters
byteBufferthe byteBuffer to write to.
Returns
the number of bytes written.
Exceptions
overflow_errorif too little space in byteBuffer.

References evio::ByteBuffer::array(), evio::ByteBuffer::arrayOffset(), getTotalBytes(), evio::ByteBuffer::order(), evio::ByteBuffer::position(), and evio::ByteBuffer::remaining().

size_t evio::BaseStructure::writeQuick ( uint8_t *  dest)

Write myself out as evio format data in the data's current byte order given by getByteOrder() at the given pointer.

This method is much more efficient than using write(uint8_t *, ByteOrder const &).

However, be warned that this method is only useful when this structure has just been read from a file or buffer. Once the user adds data (and does not call the appropriate update method) or children to this structure, this method does NOT produce correct results.

Parameters
destpointer at which to write evio format data of this bank in currently set byte order.
Returns
the number of bytes written.

References byteOrder, header, and rawBytes.

size_t evio::BaseStructure::writeQuick ( ByteBuffer dest)

Write myself into a ByteBuffer as evio format data in the data's current byte order given by getByteOrder().

This method is much more efficient than using write(ByteBuffer &).

However, be warned that this method is only useful when this structure has just been read from a file or buffer. Once the user adds data (and does not call the appropriate update method) or children to this structure, this method does NOT produce correct results.

Parameters
destdestination ByteBuffer to contain evio format data of this bank in currently set byte order.
Returns
the number of bytes written.

References getByteOrder(), header, evio::ByteBuffer::order(), evio::ByteBuffer::put(), and rawBytes.

Friends And Related Function Documentation

friend class EventBuilder
friend
friend class EventParser
friend
friend class EvioReader
friend
friend class EvioReaderV4
friend
friend class nodeBreadthIterator< std::shared_ptr< BaseStructure > >
friend
friend class nodeIterator< std::shared_ptr< BaseStructure > >
friend
friend class StructureTransformer
friend

Member Data Documentation

bool evio::BaseStructure::allowsChildren = true
protected

True if the node is able to have children.

Referenced by BaseStructure(), getAllowsChildren(), insert(), operator=(), and setAllowsChildren().

bool evio::BaseStructure::badStringFormat = false
protected

True if char data has non-ascii or non-printable characters, or has too little data to be in proper format.

Referenced by BaseStructure(), operator=(), and unpackRawBytesToStrings().

std::vector<signed char> evio::BaseStructure::charData
protected

Used if raw data should be interpreted as signed chars.

The reason rawBytes is not used directly is because it may be padded and it may not, depending on whether this object was created by EvioReader or by EventBuilder, etc., etc. We don't want to return rawBytes when a user calls getCharData() if there are padding bytes in it.

Referenced by BaseStructure(), getCharData(), operator=(), updateCharData(), and write().

std::vector<std::shared_ptr<BaseStructure> > evio::BaseStructure::children
protected
std::vector<std::shared_ptr<CompositeData> > evio::BaseStructure::compositeData
protected

Used if raw data should be interpreted as composite type.

Referenced by BaseStructure(), getCompositeData(), getNumberDataItems(), operator=(), and updateCompositeData().

std::vector<double> evio::BaseStructure::doubleData
protected

Used if raw data should be interpreted as doubles.

Referenced by BaseStructure(), getDoubleData(), operator=(), updateDoubleData(), and write().

std::vector<float> evio::BaseStructure::floatData
protected

Used if raw data should be interpreted as floats.

Referenced by BaseStructure(), getFloatData(), operator=(), updateFloatData(), and write().

std::vector<int32_t> evio::BaseStructure::intData
protected

Used if raw data should be interpreted as ints.

Referenced by BaseStructure(), getIntData(), operator=(), updateIntData(), and write().

bool evio::BaseStructure::lengthsUpToDate = false
protected

Keep track of whether header length data is up-to-date or not.

Referenced by BaseStructure(), getLengthsUpToDate(), operator=(), setAllHeaderLengths(), setLengthsUpToDate(), and transform().

std::vector<int64_t> evio::BaseStructure::longData
protected

Used if raw data should be interpreted as longs.

Referenced by BaseStructure(), getLongData(), operator=(), updateLongData(), and write().

size_t evio::BaseStructure::numberDataItems = 0
protected

The number of stored data items like number of banks, ints, floats, etc.

(not the size in ints or bytes). Some items may be padded such as shorts and bytes. This will tell the meaningful number of such data items. In other words, no padding is included. In the case of containers, returns number of bytes not in header.

Referenced by BaseStructure(), getNumberDataItems(), operator=(), stringsToRawBytes(), updateCharData(), updateCompositeData(), updateDoubleData(), updateFloatData(), updateIntData(), updateLongData(), updateShortData(), updateUCharData(), updateUIntData(), updateULongData(), and updateUShortData().

std::shared_ptr<BaseStructure> evio::BaseStructure::parent = nullptr
protected

This node's parent, or null if this node has no parent.

Referenced by BaseStructure(), getParent(), operator=(), setLengthsUpToDate(), and setParent().

std::vector<int16_t> evio::BaseStructure::shortData
protected

Used if raw data should be interpreted as shorts.

Referenced by BaseStructure(), getShortData(), operator=(), updateShortData(), and write().

int evio::BaseStructure::stringEnd = 0
protected

Keep track of end of the last string added to stringData (including null but not padding).

Referenced by BaseStructure(), operator=(), and unpackRawBytesToStrings().

std::vector<std::string > evio::BaseStructure::stringList
protected

Used if raw data should be interpreted as a string.

Referenced by BaseStructure(), getStringData(), operator=(), stringsToRawBytes(), and unpackRawBytesToStrings().

std::vector<unsigned char> evio::BaseStructure::ucharData
protected

Used if raw data should be interpreted as unsigned chars.

Referenced by BaseStructure(), getUCharData(), operator=(), and updateUCharData().

std::vector<uint32_t> evio::BaseStructure::uintData
protected

Used if raw data should be interpreted as unsigned ints.

Referenced by BaseStructure(), getUIntData(), operator=(), and updateUIntData().

std::vector<uint64_t> evio::BaseStructure::ulongData
protected

Used if raw data should be interpreted as unsigned longs.

Referenced by BaseStructure(), getULongData(), operator=(), and updateULongData().

std::vector<uint16_t> evio::BaseStructure::ushortData
protected

Used if raw data should be interpreted as unsigned shorts.

Referenced by BaseStructure(), getUShortData(), operator=(), and updateUShortData().


The documentation for this class was generated from the following files: