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

Class to hold static methods used to swap evio data. More...

#include <EvioSwap.h>

Static Public Member Functions

static void swapArray32 (uint8_t *data, uint32_t dataLen)
 Swap byte array in place assuming bytes are 32 bit ints. More...
 
static void swapEvent (std::shared_ptr< ByteBuffer > &srcBuffer, std::shared_ptr< ByteBuffer > &destBuffer, std::vector< std::shared_ptr< EvioNode >> &nodeList, bool storeNodes=false, bool swapData=true, size_t srcPos=0, size_t destPos=0)
 This method swaps the byte order of an entire evio event or bank. More...
 
static void swapBankHeader (std::shared_ptr< EvioNode > &node, std::shared_ptr< ByteBuffer > &srcBuffer, std::shared_ptr< ByteBuffer > &destBuffer, size_t srcPos=0, size_t destPos=0)
 
static void swapSegmentHeader (std::shared_ptr< EvioNode > &node, std::shared_ptr< ByteBuffer > &srcBuffer, std::shared_ptr< ByteBuffer > &destBuffer, size_t srcPos=0, size_t destPos=0)
 
static void swapTagSegmentHeader (std::shared_ptr< EvioNode > &node, std::shared_ptr< ByteBuffer > &srcBuffer, std::shared_ptr< ByteBuffer > &destBuffer, size_t srcPos=0, size_t destPos=0)
 
static void swapData (DataType const &type, std::shared_ptr< ByteBuffer > &srcBuffer, std::shared_ptr< ByteBuffer > &destBuffer, uint32_t len, bool inPlace=false, size_t srcPos=0, size_t destPos=0)
 This method swaps the data of an evio leaf structure. More...
 
static void swapStructure (std::shared_ptr< EvioNode > &node, std::shared_ptr< ByteBuffer > &srcBuffer, std::shared_ptr< ByteBuffer > &destBuffer, std::vector< std::shared_ptr< EvioNode >> &nodeList, bool storeNodes=false, bool swapData=true, bool inPlace=false, size_t srcPos=0, size_t destPos=0)
 Swap an evio structure. More...
 
static void swapEvent (uint32_t *buf, int tolocal, uint32_t *dest)
 Method to swap the endianness of an evio event (bank). More...
 
static void swapEvent (ByteBuffer &buf, ByteBuffer &dest)
 Method to swap the endianness of an evio event (bank). More...
 
static void swapEvent (std::shared_ptr< ByteBuffer > &buf, std::shared_ptr< ByteBuffer > &dest)
 Method to swap the endianness of an evio event (bank). More...
 
static void swapBank (uint32_t *buf, bool toLocal, uint32_t *dest)
 Routine to swap the endianness of an evio bank. More...
 
static void swapSegment (uint32_t *buf, bool toLocal, uint32_t *dest)
 Routine to swap the endianness of an evio segment. More...
 
static void swapTagsegment (uint32_t *buf, bool toLocal, uint32_t *dest)
 Routine to swap the endianness of an evio tagsegment. More...
 
static void swapLeafData (DataType const &type, std::shared_ptr< ByteBuffer > &srcBuf, std::shared_ptr< ByteBuffer > &destBuf, size_t srcPos, size_t destPos, size_t len)
 This method swaps the data of an evio leaf structure. More...
 
static void swapLeafData (DataType const &type, ByteBuffer &srcBuf, ByteBuffer &destBuf, size_t srcPos, size_t destPos, size_t len)
 This method swaps the data of an evio leaf structure. More...
 
static void swapData (uint32_t *src, uint32_t type, uint32_t length, bool toLocal, uint32_t *dst)
 Routine to swap any type of evio data. More...
 
static void swapData (std::shared_ptr< BaseStructure > strc)
 Routine to swap the endianness of an evio structure's (bank, seg, tagseg) data in place, including descendants' data. More...
 

Detailed Description

Class to hold static methods used to swap evio data.

Date
7/17/2020
Author
timmer

Member Function Documentation

◆ swapArray32()

static void evio::EvioSwap::swapArray32 ( uint8_t *  data,
uint32_t  dataLen 
)
inlinestatic

Swap byte array in place assuming bytes are 32 bit ints.

Number of array elements must be multiple of 4.

Parameters
databyte array to convert.
dataLennumber of bytes to convert.
Exceptions
EvioExceptionif data is null; dataLen is not a multiple of 4.

◆ swapBank()

static void evio::EvioSwap::swapBank ( uint32_t *  buf,
bool  toLocal,
uint32_t *  dest 
)
inlinestatic

Routine to swap the endianness of an evio bank.

Null buf argument does nothing.

Author
: Elliott Wolin, 21-nov-2003
: Carl Timmer, jan-2012
Parameters
bufbuffer of evio bank data to be swapped.
toLocalif false buf contains data of same endian as local host, else buf has data of opposite endian.
destbuffer to place swapped data into. If this is null, then dest = buf.

References evio::ByteOrder::byteSwap32(), and swapData().

Referenced by swapData(), and swapEvent().

◆ swapBankHeader()

static void evio::EvioSwap::swapBankHeader ( std::shared_ptr< EvioNode > &  node,
std::shared_ptr< ByteBuffer > &  srcBuffer,
std::shared_ptr< ByteBuffer > &  destBuffer,
size_t  srcPos = 0,
size_t  destPos = 0 
)
inlinestatic

This method reads and swaps an evio bank header. It can also return information about the bank. Position and limit of neither buffer argument is changed.

This only swaps data if buffer arguments have opposite byte order!

Parameters
nodeobject in which to store data about the bank in destBuffer after swap; may be null
srcBufferbuffer containing bank header to be swapped
destBufferbuffer in which to place swapped bank header
srcPosposition in srcBuffer to start reading bank header
destPosposition in destBuffer to start writing swapped bank header
Exceptions
EvioExceptionif srcBuffer too little data; if destBuffer is too small to contain swapped data

Referenced by swapEvent(), and swapStructure().

◆ swapData() [1/3]

static void evio::EvioSwap::swapData ( DataType const &  type,
std::shared_ptr< ByteBuffer > &  srcBuffer,
std::shared_ptr< ByteBuffer > &  destBuffer,
uint32_t  len,
bool  inPlace = false,
size_t  srcPos = 0,
size_t  destPos = 0 
)
inlinestatic

This method swaps the data of an evio leaf structure.

In other words the structure being swapped does not contain evio structures.

Parameters
typetype of data being swapped
srcBufferbuffer containing data to be swapped
destBufferbuffer in which to place swapped data
srcPosposition in srcBuffer to start reading data
destPosposition in destBuffer to start writing swapped data
lenlength of data in 32 bit words
inPlaceif true, data is swapped in srcBuffer
Exceptions
EvioExceptionif srcBuffer not in evio format; if destBuffer too small; if bad values for srcPos and/or destPos;

References evio::DataType::CHAR8, evio::DataType::CHARSTAR8, evio::DataType::COMPOSITE, evio::DataType::DOUBLE64, evio::DataType::FLOAT32, evio::DataType::INT32, evio::DataType::LONG64, evio::DataType::SHORT16, evio::CompositeData::swapAll(), evio::DataType::UCHAR8, evio::DataType::UINT32, evio::DataType::ULONG64, evio::DataType::UNKNOWN32, and evio::DataType::USHORT16.

Referenced by swapBank(), swapData(), swapEvent(), swapSegment(), swapStructure(), and swapTagsegment().

◆ swapData() [2/3]

static void evio::EvioSwap::swapData ( std::shared_ptr< BaseStructure strc)
inlinestatic

Routine to swap the endianness of an evio structure's (bank, seg, tagseg) data in place, including descendants' data.

The endianness of the given structure, obtained through BaseStructure#getByteOrder(), does NOT change. The caller must explicitly call BaseStructure#setByteOrder() to do that.

If this structure contains Composite data, and since it is stored as a vector of shared pointers to CompositeData objects, it is only serialized into bytes when written out. Thus the only way to switch it's endianness is for the user to call BaseStructure#setByteOrder() before writing it out as bytes. In other words, this method does NOT swap Composite data.

Parameters
strcevio structure in which to swap all data.
Author
: Carl Timmer, 7/28/2020

References evio::ByteOrder::byteSwap16(), evio::ByteOrder::byteSwap32(), evio::ByteOrder::byteSwap64(), evio::DataType::DOUBLE64, evio::DataType::FLOAT32, evio::DataType::INT32, evio::DataType::LONG64, evio::DataType::SHORT16, swapData(), evio::DataType::UINT32, evio::DataType::ULONG64, and evio::DataType::USHORT16.

◆ swapData() [3/3]

static void evio::EvioSwap::swapData ( uint32_t *  src,
uint32_t  type,
uint32_t  length,
bool  toLocal,
uint32_t *  dst 
)
inlinestatic

Routine to swap any type of evio data.

This only swaps data associated with an evio structure; i.e. it completely ignores the header associated with it. If this data consists of structures like banks & segments, it will swap them completely. Null src argument does nothing.

Author
: Elliott Wolin, 21-nov-2003
: Carl Timmer, jan-2012
Parameters
srcsource of evio data to be swapped (after evio header).
typetype of evio data.
lengthlength of evio data in 32 bit words
toLocalif false data is of same endian as local host, else data is of opposite endian.
dstdestination of swapped data. If this is null, then dst = src.

References evio::ByteOrder::byteNoSwap32(), evio::ByteOrder::byteSwap16(), evio::ByteOrder::byteSwap32(), evio::ByteOrder::byteSwap64(), evio::CompositeData::swapAll(), swapBank(), swapSegment(), and swapTagsegment().

◆ swapEvent() [1/4]

static void evio::EvioSwap::swapEvent ( ByteBuffer buf,
ByteBuffer dest 
)
inlinestatic

Method to swap the endianness of an evio event (bank).

Author
: Carl Timmer, mar-2025
Parameters
bufbuffer of evio event data to be swapped
destbuffer to place swapped data into. If this is null, then dest = buf.

References evio::ByteBuffer::array(), evio::ByteOrder::nativeOrder(), evio::ByteBuffer::order(), and swapBank().

◆ swapEvent() [2/4]

static void evio::EvioSwap::swapEvent ( std::shared_ptr< ByteBuffer > &  buf,
std::shared_ptr< ByteBuffer > &  dest 
)
inlinestatic

Method to swap the endianness of an evio event (bank).

Author
: Carl Timmer, mar-2025
Parameters
bufbuffer of evio event data to be swapped
destbuffer to place swapped data into. If this is null, then dest = buf.

References evio::ByteOrder::nativeOrder(), and swapBank().

◆ swapEvent() [3/4]

static void evio::EvioSwap::swapEvent ( std::shared_ptr< ByteBuffer > &  srcBuffer,
std::shared_ptr< ByteBuffer > &  destBuffer,
std::vector< std::shared_ptr< EvioNode >> &  nodeList,
bool  storeNodes = false,
bool  swapData = true,
size_t  srcPos = 0,
size_t  destPos = 0 
)
inlinestatic

This method swaps the byte order of an entire evio event or bank.

The byte order of the swapped buffer will be opposite to the byte order of the source buffer argument. If the swap is done in place, the byte order of the source buffer will be switched upon completion and the destPos arg will be set equal to the srcPos arg. The positions of the source and destination buffers are not changed. A ByteBuffer's current byte order can be found by calling java.nio.ByteBuffer#order().

The data to be swapped must not be in the evio file format (with record headers). Data must only consist of bytes representing a single event/bank. Position and limit of neither buffer is changed.

Parameters
srcBufferbuffer containing event to swap.
destBufferbuffer in which to place the swapped event. If null, or identical to srcBuffer, the data is swapped in place.
nodeListif not null, generate and store node objects here - one for each swapped evio structure in destBuffer.
storeNodesif true, store generated EvioNodes in nodeList.
swapDataif false, do NOT swap data, else swap data too.
srcPosposition in srcBuffer to start reading event.
destPosposition in destBuffer to start writing swapped event.
Exceptions
EvioExceptionif srcBuffer arg is null; if any buffer position is not zero

References evio::DataType::BANK, evio::EvioNode::createEvioNode(), evio::ByteOrder::getOppositeEndian(), evio::DataType::getValue(), swapBankHeader(), swapData(), and swapStructure().

◆ swapEvent() [4/4]

static void evio::EvioSwap::swapEvent ( uint32_t *  buf,
int  tolocal,
uint32_t *  dest 
)
inlinestatic

Method to swap the endianness of an evio event (bank).

Author
: Elliott Wolin, 21-nov-2003
: Carl Timmer, jan-2012
Parameters
bufbuffer of evio event data to be swapped
tolocalif 0 buf contains data of same endian as local host, else buf has data of opposite endian.
destbuffer to place swapped data into. If this is null, then dest = buf.

References swapBank().

◆ swapLeafData() [1/2]

static void evio::EvioSwap::swapLeafData ( DataType const &  type,
ByteBuffer srcBuf,
ByteBuffer destBuf,
size_t  srcPos,
size_t  destPos,
size_t  len 
)
inlinestatic

This method swaps the data of an evio leaf structure.

In other words the structure being swapped does not contain evio structures. It does nothing for container types.

Parameters
typetype of data being swapped
srcBufbuffer containing data to be swapped
destBufbuffer in which to place swapped data
srcPosposition in srcBuffer to start reading data
destPosposition in destBuffer to start writing swapped data
lenlength of data in 32 bit words
Exceptions
EvioExceptionif srcBuffer not in evio format; if destBuffer too small; if bad values for srcPos and/or destPos;

References evio::DataType::CHAR8, evio::DataType::CHARSTAR8, evio::DataType::COMPOSITE, evio::DataType::DOUBLE64, evio::DataType::FLOAT32, evio::ByteBuffer::getByte(), evio::ByteBuffer::getInt(), evio::ByteBuffer::getLong(), evio::ByteBuffer::getShort(), evio::DataType::INT32, evio::DataType::LONG64, evio::ByteBuffer::put(), evio::ByteBuffer::putInt(), evio::ByteBuffer::putLong(), evio::ByteBuffer::putShort(), evio::DataType::SHORT16, evio::CompositeData::swapAll(), evio::DataType::UCHAR8, evio::DataType::UINT32, evio::DataType::ULONG64, evio::DataType::UNKNOWN32, and evio::DataType::USHORT16.

◆ swapLeafData() [2/2]

static void evio::EvioSwap::swapLeafData ( DataType const &  type,
std::shared_ptr< ByteBuffer > &  srcBuf,
std::shared_ptr< ByteBuffer > &  destBuf,
size_t  srcPos,
size_t  destPos,
size_t  len 
)
inlinestatic

This method swaps the data of an evio leaf structure.

In other words the structure being swapped does not contain evio structures. It does nothing for container types.

Parameters
typetype of data being swapped
srcBufbuffer containing data to be swapped
destBufbuffer in which to place swapped data
srcPosposition in srcBuffer to start reading data
destPosposition in destBuffer to start writing swapped data
lenlength of data in 32 bit words
Exceptions
EvioExceptionif srcBuffer not in evio format; if destBuffer too small; if bad values for srcPos and/or destPos;

◆ swapSegment()

static void evio::EvioSwap::swapSegment ( uint32_t *  buf,
bool  toLocal,
uint32_t *  dest 
)
inlinestatic

Routine to swap the endianness of an evio segment.

Null buf argument does nothing.

Author
: Elliott Wolin, 21-nov-2003
: Carl Timmer, jan-2012
Parameters
bufbuffer of evio segment data to be swapped
toLocalif false buf contains data of same endian as local host, else buf has data of opposite endian
destbuffer to place swapped data into. If this is NULL, then dest = buf.

References evio::ByteOrder::byteSwap32(), and swapData().

Referenced by swapData().

◆ swapSegmentHeader()

static void evio::EvioSwap::swapSegmentHeader ( std::shared_ptr< EvioNode > &  node,
std::shared_ptr< ByteBuffer > &  srcBuffer,
std::shared_ptr< ByteBuffer > &  destBuffer,
size_t  srcPos = 0,
size_t  destPos = 0 
)
inlinestatic

This method reads and swaps an evio segment header. It can also return information about the segment. Position and limit of neither buffer argument is changed.

This only swaps data if buffer arguments have opposite byte order!

Parameters
nodeobject in which to store data about the segment in destBuffer after swap; may be null
srcBufferbuffer containing segment header to be swapped
destBufferbuffer in which to place swapped segment header
srcPosposition in srcBuffer to start reading segment header
destPosposition in destBuffer to start writing swapped segment header
Exceptions
EvioExceptionif srcBuffer too little data; if destBuffer is too small to contain swapped data

Referenced by swapStructure().

◆ swapStructure()

static void evio::EvioSwap::swapStructure ( std::shared_ptr< EvioNode > &  node,
std::shared_ptr< ByteBuffer > &  srcBuffer,
std::shared_ptr< ByteBuffer > &  destBuffer,
std::vector< std::shared_ptr< EvioNode >> &  nodeList,
bool  storeNodes = false,
bool  swapData = true,
bool  inPlace = false,
size_t  srcPos = 0,
size_t  destPos = 0 
)
inlinestatic

Swap an evio structure.

If it is a structure of structures, such as a bank of banks, swap recursively.

Parameters
nodeinfo from parsed header
srcBufferbuffer containing structure to swap.
destBufferbuffer in which to place the swapped structure.
nodeListif not null, store all node objects here - one for each swapped evio structure in destBuffer.
storeNodesif true, store generated EvioNodes in nodeList.
swapDataif false, do NOT swap data, else swap data too.
inPlaceif true, data is swapped in srcBuffer
srcPosposition in srcBuffer to start reading structure
destPosposition in destBuffer to start writing swapped structure
Exceptions
EvioExceptionif args are null; IF srcBuffer not in evio format; if destBuffer too small; if bad values for srcPos and/or destPos;

References evio::DataType::BANK, evio::EvioNode::createEvioNode(), evio::DataType::getValue(), evio::DataType::isBank(), evio::DataType::isSegment(), evio::DataType::isStructure(), evio::DataType::isTagSegment(), evio::DataType::SEGMENT, swapBankHeader(), swapData(), swapSegmentHeader(), swapTagSegmentHeader(), and evio::DataType::TAGSEGMENT.

Referenced by swapEvent().

◆ swapTagsegment()

static void evio::EvioSwap::swapTagsegment ( uint32_t *  buf,
bool  toLocal,
uint32_t *  dest 
)
inlinestatic

Routine to swap the endianness of an evio tagsegment.

Null buf argument does nothing.

Author
: Elliott Wolin, 21-nov-2003
: Carl Timmer, jan-2012
Parameters
bufbuffer of evio tagsegment data to be swapped
toLocalif false buf contains data of same endian as local host, else buf has data of opposite endian
destbuffer to place swapped data into. If this is NULL, then dest = buf.

References evio::ByteOrder::byteSwap32(), and swapData().

Referenced by swapData().

◆ swapTagSegmentHeader()

static void evio::EvioSwap::swapTagSegmentHeader ( std::shared_ptr< EvioNode > &  node,
std::shared_ptr< ByteBuffer > &  srcBuffer,
std::shared_ptr< ByteBuffer > &  destBuffer,
size_t  srcPos = 0,
size_t  destPos = 0 
)
inlinestatic

This method reads and swaps an evio tagsegment header. It can also return information about the tagsegment. Position and limit of neither buffer argument is changed.

This only swaps data if buffer arguments have opposite byte order!

Parameters
nodeobject in which to store data about the tagsegment in destBuffer after swap; may be null
srcBufferbuffer containing tagsegment header to be swapped
destBufferbuffer in which to place swapped tagsegment header
srcPosposition in srcBuffer to start reading tagsegment header
destPosposition in destBuffer to start writing swapped tagsegment header
Exceptions
EvioExceptionif srcBuffer too little data; if destBuffer is too small to contain swapped data

Referenced by swapStructure().


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