11 #ifndef EVIO_6_0_EVIOSWAP_H
12 #define EVIO_6_0_EVIOSWAP_H
51 static void swapEvent(uint32_t *buf,
int tolocal, uint32_t *dest) {
69 static void swapBank(uint32_t *buf,
bool toLocal, uint32_t *dest) {
70 if (buf ==
nullptr)
return;
72 uint32_t dataLength, dataType;
80 dataLength = p[0] - 1;
81 dataType = (p[1] >> 8) & 0x3f;
89 swapData(&buf[2], dataType, dataLength, toLocal, ((dest ==
nullptr) ?
nullptr : &dest[2]));
106 static void swapSegment(uint32_t *buf,
bool toLocal, uint32_t *dest) {
107 if (buf ==
nullptr)
return;
109 uint32_t dataLength, dataType;
117 dataLength = p[0] & 0xffff;
118 dataType = (p[0] >> 16) & 0x3f;
126 swapData(&buf[1], dataType, dataLength, toLocal, ((dest ==
nullptr) ?
nullptr : &dest[1]));
144 if (buf ==
nullptr)
return;
146 uint32_t dataLength, dataType;
154 dataLength = p[0] & 0xffff;
155 dataType = (p[0] >> 16) & 0xf;
163 swapData(&buf[1], dataType, dataLength, toLocal, ((dest ==
nullptr) ?
nullptr : &dest[1]));
185 std::shared_ptr<ByteBuffer> & srcBuf,
186 std::shared_ptr<ByteBuffer> & destBuf,
187 size_t srcPos,
size_t destPos,
size_t len) {
188 swapLeafData(type, *(srcBuf.get()), *(destBuf.get()), srcPos, destPos, len);
209 ByteBuffer & destBuf,
size_t srcPos,
size_t destPos,
213 size_t endPos = srcPos + 4*len;
221 for (; srcPos < endPos; srcPos += 8, destPos += 8) {
231 for (; srcPos < endPos; srcPos += 4, destPos += 4) {
238 for (; srcPos < endPos; srcPos += 2, destPos += 2) {
248 for (; srcPos < endPos; srcPos++, destPos++) {
277 static void swapData(uint32_t *src, uint32_t type, uint32_t length,
bool toLocal, uint32_t *dst) {
278 if (src ==
nullptr)
return;
280 uint32_t fraglen, l = 0;
304 reinterpret_cast<uint16_t *>(dst));
312 reinterpret_cast<uint64_t *>(dst));
318 reinterpret_cast<uint8_t *>(dst),
329 swapBank(&src[l], toLocal, (dst ==
nullptr) ?
nullptr : &dst[l]);
331 fraglen = (dst ==
nullptr) ? src[l] + 1 : dst[l] + 1;
334 fraglen = src[l] + 1;
335 swapBank(&src[l], toLocal, (dst ==
nullptr) ?
nullptr : &dst[l]);
346 swapSegment(&src[l], toLocal, (dst ==
nullptr) ?
nullptr : &dst[l]);
347 fraglen = (dst ==
nullptr) ? (src[l] & 0xffff) + 1 : (dst[l] & 0xffff) + 1;
350 fraglen = (src[l] & 0xffff) + 1;
351 swapSegment(&src[l], toLocal, (dst ==
nullptr) ?
nullptr : &dst[l]);
361 swapTagsegment(&src[l], toLocal, (dst ==
nullptr) ?
nullptr : &dst[l]);
362 fraglen = (dst ==
nullptr) ? (src[l] & 0xffff) + 1 : (dst[l] & 0xffff) + 1;
365 fraglen = (src[l] & 0xffff) + 1;
366 swapTagsegment(&src[l], toLocal, (dst ==
nullptr) ?
nullptr : &dst[l]);
394 static void swapData(std::shared_ptr<BaseStructure> strc) {
395 auto type = strc->getHeader()->getDataType();
396 uint32_t length = strc->getHeader()->getDataLength();
397 bool srcIsLocal = strc->getByteOrder().isLocalEndian();
400 auto & vec = strc->getUIntData();
402 strc->updateUIntData();
405 auto & vec = strc->getIntData();
407 strc->updateIntData();
410 auto & vec = strc->getFloatData();
412 strc->updateFloatData();
415 auto & vec = strc->getShortData();
417 strc->updateShortData();
420 auto & vec = strc->getUShortData();
422 strc->updateUShortData();
425 auto & vec = strc->getLongData();
427 strc->updateLongData();
430 auto & vec = strc->getULongData();
432 strc->updateULongData();
435 auto & vec = strc->getDoubleData();
437 strc->updateDoubleData();
442 else if (type.isBank() || type.isSegment() || type.isTagSegment()) {
443 for (
auto kid : strc->getChildren()) {
456 #endif //EVIO_6_0_EVIOSWAP_H
ByteBuffer & putShort(uint16_t val)
Relative put method for writing a short value.
Definition: ByteBuffer.cpp:1525
This class is copied from one of the same name in the Java programming language.
Definition: ByteBuffer.h:42
static const DataType LONG64
64 bit int.
Definition: DataType.h:45
static const DataType UCHAR8
Unsigned 8 bit int.
Definition: DataType.h:43
static const DataType INT32
32 bit int.
Definition: DataType.h:47
static void swapAll(uint8_t *src, uint8_t *dest, size_t length, bool srcIsLocal)
This method converts (swaps) a buffer of EVIO composite type between big & little endian...
Definition: CompositeData.cpp:1018
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.
Definition: EvioSwap.h:184
ByteBuffer & put(const ByteBuffer &src)
Relative bulk put method.
Definition: ByteBuffer.cpp:1325
ByteBuffer & putLong(uint64_t val)
Relative put method for writing a long long value.
Definition: ByteBuffer.cpp:1615
static uint64_t * byteSwap64(uint64_t *src, size_t elements, uint64_t *dst)
This method swaps an array of 8-byte data.
Definition: ByteOrder.cpp:132
static const DataType CHARSTAR8
ASCII characters.
Definition: DataType.h:39
static void swapSegment(uint32_t *buf, bool toLocal, uint32_t *dest)
Routine to swap the endianness of an evio segment.
Definition: EvioSwap.h:106
static void swapData(std::shared_ptr< BaseStructure > strc)
Routine to swap the endianness of an evio structure's (bank, seg, tagseg) data in place...
Definition: EvioSwap.h:394
ByteBuffer & putInt(uint32_t val)
Relative put method for writing an int value.
Definition: ByteBuffer.cpp:1570
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.
Definition: EvioSwap.h:208
static const DataType DOUBLE64
64 bit double.
Definition: DataType.h:44
static const DataType COMPOSITE
Composite data type.
Definition: DataType.h:51
Class to hold static methods used to swap evio data.
Definition: EvioSwap.h:35
static const DataType FLOAT32
32 bit float.
Definition: DataType.h:38
static void swapEvent(uint32_t *buf, int tolocal, uint32_t *dest)
Method to swap the endianness of an evio event (bank).
Definition: EvioSwap.h:51
static void byteNoSwap32(const uint32_t *src, size_t elements, uint32_t *dst)
This routine swaps nothing, it just copies the given number of 32 bit ints.
Definition: ByteOrder.cpp:155
static const DataType SHORT16
16 bit int.
Definition: DataType.h:40
static const DataType UINT32
Unsigned 32 bit int.
Definition: DataType.h:37
static const DataType CHAR8
8 bit int.
Definition: DataType.h:42
int64_t getLong() const
Relative get method for reading a long long value.
Definition: ByteBuffer.cpp:1156
int32_t getInt() const
Relative get method for reading an int value.
Definition: ByteBuffer.cpp:1074
static void swapTagsegment(uint32_t *buf, bool toLocal, uint32_t *dest)
Routine to swap the endianness of an evio tagsegment.
Definition: EvioSwap.h:143
Numerical values associated with evio data types.
Definition: DataType.h:32
static uint32_t * byteSwap32(uint32_t *src, size_t elements, uint32_t *dst)
This method swaps an array of 4-byte data.
Definition: ByteOrder.cpp:109
static const DataType UNKNOWN32
Unknown data type.
Definition: DataType.h:36
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.
Definition: EvioSwap.h:277
static const DataType USHORT16
Unsigned 16 bit int.
Definition: DataType.h:41
uint8_t getByte() const
Relative get method.
Definition: ByteBuffer.cpp:936
static void swapBank(uint32_t *buf, bool toLocal, uint32_t *dest)
Routine to swap the endianness of an evio bank.
Definition: EvioSwap.h:69
static uint16_t * byteSwap16(uint16_t *src, size_t elements, uint16_t *dst)
This method swaps an array of 2-byte data.
Definition: ByteOrder.cpp:86
static const DataType ULONG64
Unsigned 64 bit int.
Definition: DataType.h:46
int16_t getShort() const
Relative get method for reading a short value.
Definition: ByteBuffer.cpp:989