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

This class is used to read the bytes of just an evio structure (NOT a full evio formatted file or buffer). More...

#include <EvioCompactStructureHandler.h>

Public Member Functions

 EvioCompactStructureHandler (std::shared_ptr< EvioNode > &node)
 Constructor for reading an EvioNode object. More...
 
 EvioCompactStructureHandler (std::shared_ptr< ByteBuffer > &byteBuffer, const DataType &type)
 Constructor for reading a buffer that contains 1 structure only (no record headers). More...
 
void setBuffer (std::shared_ptr< ByteBuffer > &buf, const DataType &type)
 This method can be used to avoid creating additional EvioCompactStructureHandler objects by reusing this one with another buffer. More...
 
bool isClosed ()
 Has close() been called (without reopening by calling setBuffer)? More...
 
std::shared_ptr< ByteBuffer > & getByteBuffer ()
 Get the byte buffer being read. More...
 
std::shared_ptr< EvioNode > & getStructure ()
 Get the EvioNode object associated with the structure. More...
 
std::shared_ptr< EvioNode > & getScannedStructure ()
 Get the EvioNode object associated with the structure which has been scanned so all substructures are contained in the node.allNodes vector. More...
 
std::vector< std::shared_ptr< EvioNode > > & scanStructure ()
 This method scans the event in the buffer. More...
 
std::vector< std::shared_ptr< EvioNode > > searchStructure (uint16_t tag, uint8_t num)
 This method searches the event and returns a vector of objects each of which contain information about a single evio structure which matches the given tag and num. More...
 
std::vector< std::shared_ptr< EvioNode > > searchStructure (std::string const &dictName, std::shared_ptr< EvioXMLDictionary > dictionary)
 This method searches the event and returns a vector of objects each of which contain information about a single evio structure which matches the given dictionary entry name. More...
 
std::shared_ptr< ByteBuffer > & removeStructure (std::shared_ptr< EvioNode > removeNode)
 This method removes the data, represented by the given node, from the buffer. More...
 
std::shared_ptr< ByteBuffer > & addStructure (std::shared_ptr< ByteBuffer > addBuffer)
 This method adds a bank, segment, or tagsegment onto the end of a structure which contains banks, segments, or tagsegments respectively. More...
 
std::shared_ptr< ByteBuffergetData (std::shared_ptr< EvioNode > &node)
 Get the data associated with an evio structure in ByteBuffer form. More...
 
std::shared_ptr< ByteBuffergetData (std::shared_ptr< EvioNode > &node, bool copy)
 Get the data associated with an evio structure in ByteBuffer form. More...
 
std::shared_ptr< ByteBuffergetStructureBuffer (std::shared_ptr< EvioNode > &node)
 Get an evio structure (bank, seg, or tagseg) in ByteBuffer form. More...
 
std::shared_ptr< ByteBuffergetStructureBuffer (std::shared_ptr< EvioNode > &node, bool copy)
 Get an evio structure (bank, seg, or tagseg) in ByteBuffer form. More...
 
std::vector< std::shared_ptr< EvioNode > > & getNodes ()
 This method returns a vector of all evio structures in buffer as EvioNode objects. More...
 
std::vector< std::shared_ptr< EvioNode > > & getChildNodes ()
 This method returns a vector of all child evio structures in buffer as EvioNode objects. More...
 
ByteOrder getByteOrder ()
 Get the byte order of buffer being read. More...
 
void close ()
 This only sets the position to its initial value. More...
 

Detailed Description

This class is used to read the bytes of just an evio structure (NOT a full evio formatted file or buffer).

It is also capable of adding another structure to or removing it from that structure. The EvioCompactReader class is similar but reads files and buffers in the complete evio version format. It is theoretically thread-safe. It is designed to be fast and does NOT do a deserialization on the buffer examined.

Author
timmer

Constructor & Destructor Documentation

◆ EvioCompactStructureHandler() [1/2]

evio::EvioCompactStructureHandler::EvioCompactStructureHandler ( std::shared_ptr< EvioNode > &  node)
explicit

Constructor for reading an EvioNode object.

The data represented by the given EvioNode object will be copied to a new buffer (obtainable by calling getByteBuffer()) and the node and all of its descendants will switch to that new buffer.

Parameters
nodethe node to be analyzed.

◆ EvioCompactStructureHandler() [2/2]

evio::EvioCompactStructureHandler::EvioCompactStructureHandler ( std::shared_ptr< ByteBuffer > &  buf,
const DataType type 
)

Constructor for reading a buffer that contains 1 structure only (no record headers).

The data in the given ByteBuffer object will be copied to a new buffer (obtainable by calling getByteBuffer()).

Parameters
bufthe buffer to be read that contains 1 structure only (no block headers).
typethe type of outermost structure contained in buffer, may be DataType#BANK, DataType#SEGMENT, DataType#TAGSEGMENT or equivalent.
Exceptions
EvioExceptionif byteBuffer arg is null; if type arg is null or is not an evio structure; if byteBuffer not in proper format;

References setBuffer().

Member Function Documentation

◆ addStructure()

std::shared_ptr< ByteBuffer > & evio::EvioCompactStructureHandler::addStructure ( std::shared_ptr< ByteBuffer addBuffer)

This method adds a bank, segment, or tagsegment onto the end of a structure which contains banks, segments, or tagsegments respectively.

It is the responsibility of the caller to make sure that the buffer argument contains valid evio data (only data representing the bank or structure to be added - not in file format with bank header and the like) which is compatible with the type of data structure stored in the parent structure. This means it is not possible to add to structures which contain only a primitive data type.

To produce properly formatted evio data, use EvioBank#write(ByteBuffer), EvioSegment#write(ByteBuffer) or EvioTagSegment#write(ByteBuffer) depending on whether a bank, seg, or tagseg is being added.

The given buffer argument must be ready to read with its position and limit defining the limits of the data to copy. This method is locked due to the bulk, relative puts.

Parameters
addBufferbuffer containing evio data to add (not evio file format, i.e. no bank headers)
Returns
a new ByteBuffer object which is created and filled with all the data including what was just added.
Exceptions
EvioExceptionif addBuffer is null; if addBuffer arg is empty or has non-evio format; if addBuffer is opposite endian to current event buffer; if added data is not the proper length (i.e. multiple of 4 bytes); if there is an internal programming error; if object closed.

References evio::ByteOrder::ENDIAN_BIG, evio::DataType::isBank(), evio::DataType::isStructure(), and evio::EvioNode::scanStructure().

◆ close()

void evio::EvioCompactStructureHandler::close ( )

This only sets the position to its initial value.

◆ getByteBuffer()

std::shared_ptr< ByteBuffer > & evio::EvioCompactStructureHandler::getByteBuffer ( )

Get the byte buffer being read.

Returns
the byte buffer being read.

◆ getByteOrder()

ByteOrder evio::EvioCompactStructureHandler::getByteOrder ( )

Get the byte order of buffer being read.

Returns
the byte order of buffer being read.

◆ getChildNodes()

std::vector< std::shared_ptr< EvioNode > > & evio::EvioCompactStructureHandler::getChildNodes ( )

This method returns a vector of all child evio structures in buffer as EvioNode objects.

Exceptions
EvioExceptionif object closed
Returns
vector of all child evio structures in buffer as EvioNode objects.

References scanStructure().

◆ getData() [1/2]

std::shared_ptr< ByteBuffer > evio::EvioCompactStructureHandler::getData ( std::shared_ptr< EvioNode > &  node)

Get the data associated with an evio structure in ByteBuffer form.

The returned buffer is a view into this reader's buffer (no copy done). Changes in one will affect the other.

Parameters
nodeevio structure whose data is to be retrieved
Exceptions
EvioExceptionif object closed
Returns
ByteBuffer object containing data. Position and limit are set for reading.

◆ getData() [2/2]

std::shared_ptr< ByteBuffer > evio::EvioCompactStructureHandler::getData ( std::shared_ptr< EvioNode > &  node,
bool  copy 
)

Get the data associated with an evio structure in ByteBuffer form.

Depending on the copy argument, the returned buffer will either be a copy of or a view into the data of this reader's buffer.

This method is locked due to the bulk, relative gets & puts.

Parameters
nodeevio structure whose data is to be retrieved
copyif true, then return a copy as opposed to a view into this reader object's buffer.
Exceptions
EvioExceptionif object closed
Returns
ByteBuffer object containing data. Position and limit are set for reading.

◆ getNodes()

std::vector< std::shared_ptr< EvioNode > > & evio::EvioCompactStructureHandler::getNodes ( )

This method returns a vector of all evio structures in buffer as EvioNode objects.

Exceptions
EvioExceptionif object closed
Returns
vector of all evio structures in buffer as EvioNode objects.

References scanStructure().

◆ getScannedStructure()

std::shared_ptr< EvioNode > & evio::EvioCompactStructureHandler::getScannedStructure ( )

Get the EvioNode object associated with the structure which has been scanned so all substructures are contained in the node.allNodes vector.

Returns
EvioNode object associated with the structure, or null if there is none.

References evio::EvioNode::scanStructure().

◆ getStructure()

std::shared_ptr< EvioNode > & evio::EvioCompactStructureHandler::getStructure ( )

Get the EvioNode object associated with the structure.

Returns
EvioNode object associated with the structure.

◆ getStructureBuffer() [1/2]

std::shared_ptr< ByteBuffer > evio::EvioCompactStructureHandler::getStructureBuffer ( std::shared_ptr< EvioNode > &  node)

Get an evio structure (bank, seg, or tagseg) in ByteBuffer form.

The returned buffer is a view into the data of this reader's buffer.

This method is locked due to the bulk, relative gets & puts.

Parameters
nodenode object representing evio structure of interest
Returns
ByteBuffer object containing bank's/event's bytes. Position and limit are set for reading.
Exceptions
EvioExceptionif object closed

◆ getStructureBuffer() [2/2]

std::shared_ptr< ByteBuffer > evio::EvioCompactStructureHandler::getStructureBuffer ( std::shared_ptr< EvioNode > &  node,
bool  copy 
)

Get an evio structure (bank, seg, or tagseg) in ByteBuffer form.

Depending on the copy argument, the returned buffer will either be a copy of or a view into the data of this reader's buffer.

This method is locked due to the bulk, relative gets & puts.

Parameters
nodenode object representing evio structure of interest
copyif true, then return a copy as opposed to a view into this reader object's buffer.
Returns
ByteBuffer object containing structure's bytes. Position and limit are set for reading.
Exceptions
EvioExceptionif object closed

◆ isClosed()

bool evio::EvioCompactStructureHandler::isClosed ( )

Has close() been called (without reopening by calling setBuffer)?

Returns
true
if this object closed, else
false
.

◆ removeStructure()

std::shared_ptr< ByteBuffer > & evio::EvioCompactStructureHandler::removeStructure ( std::shared_ptr< EvioNode removeNode)

This method removes the data, represented by the given node, from the buffer.

It also marks the node and its descendants as obsolete. They must not be used anymore.

Parameters
removeNodeevio structure to remove from buffer
Returns
backing buffer updated to reflect the node removal
Exceptions
EvioExceptionif object closed; if node was not found in any event; if internal programming error

References evio::ByteBuffer::clear(), evio::ByteOrder::ENDIAN_BIG, evio::ByteBuffer::order(), and evio::ByteBuffer::put().

◆ scanStructure()

std::vector< std::shared_ptr< EvioNode > > & evio::EvioCompactStructureHandler::scanStructure ( )

This method scans the event in the buffer.

The results are stored for future reference so the event is only scanned once. It returns a vector of EvioNode objects representing evio structures (banks, segs, tagsegs).

Returns
vector of objects (evio structures containing data) obtained from the scan

References evio::EvioNode::scanStructure().

Referenced by getChildNodes(), getNodes(), and searchStructure().

◆ searchStructure() [1/2]

std::vector< std::shared_ptr< EvioNode > > evio::EvioCompactStructureHandler::searchStructure ( std::string const &  dictName,
std::shared_ptr< EvioXMLDictionary dictionary 
)

This method searches the event and returns a vector of objects each of which contain information about a single evio structure which matches the given dictionary entry name.

Parameters
dictNamename of dictionary entry to search for
dictionarydictionary to use
Returns
vector of EvioNode objects corresponding to matching evio structures (empty if none found)
Exceptions
EvioExceptionif either dictName or dictionary arg is empty/null; if dictName is an invalid dictionary entry; if object closed.

References searchStructure().

◆ searchStructure() [2/2]

std::vector< std::shared_ptr< EvioNode > > evio::EvioCompactStructureHandler::searchStructure ( uint16_t  tag,
uint8_t  num 
)

This method searches the event and returns a vector of objects each of which contain information about a single evio structure which matches the given tag and num.

Parameters
tagtag to match
numnum to match
Returns
vector of EvioNode objects corresponding to matching evio structures (empty if none found)
Exceptions
EvioExceptionif object closed.

References scanStructure().

Referenced by searchStructure().

◆ setBuffer()

void evio::EvioCompactStructureHandler::setBuffer ( std::shared_ptr< ByteBuffer > &  buf,
const DataType type 
)

This method can be used to avoid creating additional EvioCompactStructureHandler objects by reusing this one with another buffer.

Parameters
bufthe buffer to be read that contains 1 structure only (no block headers).
typethe type of outermost structure contained in buffer, may be DataType#BANK, DataType#SEGMENT, DataType#TAGSEGMENT or equivalent.
Exceptions
EvioExceptionif type is not an evio structure; if buf not in proper format;

References evio::DataType::isBank(), and evio::DataType::isStructure().

Referenced by EvioCompactStructureHandler().


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