11 #ifndef EVIO_6_0_COMPOSITEDATA_H
12 #define EVIO_6_0_COMPOSITEDATA_H
41 #undef COMPOSITE_DEBUG
42 #undef COMPOSITE_PRINT
192 uint32_t dataBytes = 0;
195 uint32_t paddingBytes = 0;
198 uint32_t pads[4] = {0,3,2,1};
201 std::vector<DataItem> dataItems;
204 std::vector<DataType> dataTypes;
208 std::vector<int32_t> Nlist;
212 std::vector<int16_t> nlist;
216 std::vector<int8_t> mlist;
219 uint16_t formatTag = 0;
222 uint16_t dataTag = 0;
231 dataItems.reserve(200);
232 dataTypes.reserve(200);
245 void addBytesToData(uint32_t bytes) {
248 paddingBytes = pads[dataBytes%4];
309 dataItems.push_back(mem);
323 dataItems.push_back(mem);
337 dataItems.push_back(mem);
351 dataItems.push_back(mem);
360 void addInt(std::vector<int32_t>
const & i) {
364 dataItems.push_back(mem);
367 addBytesToData(4 * i.size());
377 dataItems.push_back(mem);
386 void addUint(std::vector<uint32_t>
const & i) {
390 dataItems.push_back(mem);
393 addBytesToData(4 * i.size());
405 dataItems.push_back(mem);
418 dataItems.push_back(mem);
421 addBytesToData(2 * s.size());
431 dataItems.push_back(mem);
444 dataItems.push_back(mem);
447 addBytesToData(2 * s.size());
459 dataItems.push_back(mem);
468 void addLong(std::vector<int64_t>
const & l) {
472 dataItems.push_back(mem);
475 addBytesToData(8 * l.size());
485 dataItems.push_back(mem);
498 dataItems.push_back(mem);
501 addBytesToData(8 * l.size());
513 dataItems.push_back(mem);
526 dataItems.push_back(mem);
529 addBytesToData(b.size());
540 dataItems.push_back(mem);
553 dataItems.push_back(mem);
556 addBytesToData(b.size());
568 dataItems.push_back(mem);
581 dataItems.push_back(mem);
584 addBytesToData(4 * f.size());
594 dataItems.push_back(mem);
607 dataItems.push_back(mem);
610 addBytesToData(8 * d.size());
620 std::vector<std::string> v {s};
624 dataItems.push_back(mem);
637 dataItems.push_back(mem);
650 std::vector<uint16_t> formatInts;
653 std::vector<DataItem> items;
656 std::vector<DataType> types;
659 std::vector<int32_t> NList;
662 std::vector<int16_t> nList;
665 std::vector<int8_t> mList;
668 std::shared_ptr<TagSegmentHeader> tsHeader;
671 std::shared_ptr<BankHeader> bHeader;
674 std::vector<uint8_t> rawBytes;
677 uint32_t dataBytes = 0;
680 uint32_t dataPadding = 0;
683 uint32_t dataOffset = 0;
690 uint32_t getIndex = 0;
697 CompositeData() =
default;
699 CompositeData(std::string
const & format,
const Data & data);
701 CompositeData(std::string
const & format,
704 uint16_t dataTag, uint8_t dataNum,
707 CompositeData(uint8_t *bytes, ByteOrder
const & byteOrder);
709 CompositeData(ByteBuffer & bytes);
711 static std::shared_ptr<CompositeData> getInstance();
717 static std::shared_ptr<CompositeData> getInstance(std::string & format,
const Data & data);
719 static std::shared_ptr<CompositeData> getInstance(std::string & format,
722 uint16_t dataTag, uint8_t dataNum,
725 static std::shared_ptr<CompositeData> getInstance(uint8_t *bytes,
728 static std::shared_ptr<CompositeData> getInstance(ByteBuffer & bytes);
730 static void parse(uint8_t *bytes,
size_t bytesSize, ByteOrder
const & order,
731 std::vector<std::shared_ptr<CompositeData>> & list);
733 static void generateRawBytes(std::vector<std::shared_ptr<CompositeData>> & data,
734 std::vector<uint8_t> & rawBytes, ByteOrder & order);
758 uint32_t
index()
const;
792 static void swapAll(uint8_t *src, uint8_t *dest,
size_t length,
bool srcIsLocal);
796 static void swapAll(ByteBuffer & buf, uint32_t srcPos, uint32_t len);
797 static void swapAll(std::shared_ptr<ByteBuffer> & buf, uint32_t srcPos, uint32_t len);
802 static void swapAll(std::shared_ptr<ByteBuffer> & srcBuf,
803 std::shared_ptr<ByteBuffer> & destBuf,
804 uint32_t srcPos, uint32_t destPos, uint32_t len);
805 static void swapAll(ByteBuffer & srcBuffer, ByteBuffer & destBuffer,
806 uint32_t srcPos, uint32_t destPos, uint32_t len);
810 static void swapData(ByteBuffer & srcBuf, ByteBuffer & destBuf,
811 size_t nBytes,
const std::vector<uint16_t> & ifmt);
812 static void swapData(std::shared_ptr<ByteBuffer> & srcBuf,
813 std::shared_ptr<ByteBuffer> & destBuf,
814 size_t srcPos,
size_t destPos,
size_t nBytes,
815 const std::vector<uint16_t> & ifmt);
816 static void swapData(ByteBuffer & srcBuf, ByteBuffer & destBuf,
817 size_t srcPos,
size_t destPos,
size_t nBytes,
818 const std::vector<uint16_t> & ifmt);
819 static void swapData(int32_t *src, int32_t *dest,
size_t nwrd,
820 const std::vector<uint16_t> & ifmt,
821 uint32_t padding,
bool srcIsLocal);
825 static void swapData(int32_t *iarr,
int nwrd,
const std::vector<uint16_t> & ifmt,
829 static void dataToRawBytes(ByteBuffer & rawBuf, Data
const & data,
830 std::vector<uint16_t> & ifmt);
837 std::string
toString(
const std::string & indent,
bool hex);
838 std::string
toString(
bool hex)
const;
845 #endif //EVIO_6_0_COMPOSITEDATA_H
int32_t getNValue()
This method gets the next N value data item if it's the correct type.
Definition: CompositeData.cpp:576
uint32_t getPadding() const
Get the data padding (0, 1, 2, or 3 bytes).
Definition: CompositeData.cpp:491
void addLong(int64_t l)
Add a 64 bit long to the data.
Definition: CompositeData.h:456
static const DataType LONG64
64 bit int.
Definition: DataType.h:45
uint8_t getUChar()
This method gets the next data item as an unsigned byte/char if it's the correct type.
Definition: CompositeData.cpp:641
uint16_t getDataTag() const
This method gets the tag in the bank containing the data.
Definition: CompositeData.h:280
int32_t getInt()
This method gets the next data item as an int if it's the correct type.
Definition: CompositeData.cpp:680
static const DataType UCHAR8
Unsigned 8 bit int.
Definition: DataType.h:43
std::vector< uint8_t > & getRawBytes()
This method gets a vector of the raw byte representation of this object's data.
Definition: CompositeData.cpp:513
static const DataType INT32
32 bit int.
Definition: DataType.h:47
static void swapData(ByteBuffer &srcBuf, ByteBuffer &destBuf, size_t nBytes, const std::vector< uint16_t > &ifmt)
This method converts (swaps) EVIO composite type data between Big endian and Little endian...
Definition: CompositeData.cpp:1345
uint32_t ui32
Unsigned int value.
Definition: CompositeData.h:129
void addChar(std::vector< int8_t > const &b)
Add an vector of 8 bit bytes (chars) to the data.
Definition: CompositeData.h:522
uint32_t getDataSize() const
This method gets the raw data size in bytes.
Definition: CompositeData.h:292
void addFloat(std::vector< float > const &f)
Add an vector of 32 bit floats to the data.
Definition: CompositeData.h:577
double dbl
Double value.
Definition: CompositeData.h:123
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
uint32_t getUInt()
This method gets the next data item as an unsigned int if it's the correct type.
Definition: CompositeData.cpp:693
DataItem(DataItem const &other)
Copy constructor.
Definition: CompositeData.h:169
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 array, not including header.
Definition: Util.h:729
void addUShort(std::vector< uint16_t > const &s)
Add an vector of unsigned 16 bit shorts to the data.
Definition: CompositeData.h:440
void addLong(std::vector< int64_t > const &l)
Add an vector of 64 bit longs to the data.
Definition: CompositeData.h:468
uint64_t getULong()
This method gets the next data item as an unsigned long if it's the correct type. ...
Definition: CompositeData.cpp:719
void addUChar(uint8_t b)
Add an unsigned 8 bit byte (uchar) to the data.
Definition: CompositeData.h:537
void addN(uint32_t N)
This method adds an "N" or multiplier value to the data.
Definition: CompositeData.h:305
void addInt(int32_t i)
Add a signed 32 bit integer to the data.
Definition: CompositeData.h:348
void addUint(uint32_t i)
Add an unsigned 32 bit integer to the data.
Definition: CompositeData.h:374
static void dataToRawBytes(ByteBuffer &rawBuf, Data const &data, std::vector< uint16_t > &ifmt)
This method converts (swaps) an array of EVIO composite type data between IEEE (big endian) and DECS ...
Definition: CompositeData.cpp:2480
Numerical values associated with endian byte order.
Definition: ByteOrder.h:53
void addShort(std::vector< int16_t > const &s)
Add an vector of 16 bit shorts to the data.
Definition: CompositeData.h:414
static const DataType CHARSTAR8
ASCII characters.
Definition: DataType.h:39
uint64_t ul64
Unsigned long value.
Definition: CompositeData.h:125
void setFormatTag(uint16_t tag)
This method sets the tag in the segment containing the format string.
Definition: CompositeData.h:256
uint16_t getFormatTag() const
This method gets the tag in the segment containing the format string.
Definition: CompositeData.h:274
uint32_t index() const
This methods returns the index of the data item to be returned on the next call to one of the get<Typ...
Definition: CompositeData.cpp:558
std::vector< std::string > & getStrings()
This method gets the next data item as a vector of strings if it's the correct type.
Definition: CompositeData.cpp:758
void swap()
This method swaps the data of this composite type between big & little endian.
Definition: CompositeData.cpp:998
std::vector< DataType > & getTypes()
This method gets a vector of all the types of the data items inside the composite.
Definition: CompositeData.cpp:528
void addn(uint16_t n)
This method adds an "n" or multiplier value to the data.
Definition: CompositeData.h:319
static const DataType DOUBLE64
64 bit double.
Definition: DataType.h:44
void addString(std::string const &s)
Add a single string to the data.
Definition: CompositeData.h:619
void setDataNum(uint8_t num)
This method sets the num in the bank containing the data.
Definition: CompositeData.h:268
void addm(uint8_t m)
This method adds an "m" or multiplier value to the data.
Definition: CompositeData.h:333
This class defines an individual data item.
Definition: CompositeData.h:153
std::vector< DataItem > & getItems()
This method gets a vector of all the data items inside the composite.
Definition: CompositeData.cpp:521
void setDataTag(uint16_t tag)
This method sets the tag in the bank containing the data.
Definition: CompositeData.h:262
static const DataType FLOAT32
32 bit float.
Definition: DataType.h:38
void addDouble(double d)
Add a 64 bit double to the data.
Definition: CompositeData.h:591
std::vector< int16_t > & getnValues()
This method gets a vector of all the n values of the data items inside the composite.
Definition: CompositeData.cpp:542
int16_t getnValue()
This method gets the next n value data item if it's the correct type.
Definition: CompositeData.cpp:589
uint8_t getDataNum() const
This method gets the num in the bank containing the data.
Definition: CompositeData.h:286
int16_t s16
Signed int value.
Definition: CompositeData.h:135
static std::string stringsToFormat(std::vector< std::string > strings)
This method helps the CompositeData object creator by finding the proper format string parameter for ...
Definition: CompositeData.cpp:475
std::string getFormat() const
This method gets the format string.
Definition: CompositeData.cpp:498
static const DataType SHORT16
16 bit int.
Definition: DataType.h:40
Definition: CompositeData.h:97
void addChar(int8_t b)
Add an 8 bit byte (char) to the data.
Definition: CompositeData.h:510
static const DataType UINT32
Unsigned 32 bit int.
Definition: DataType.h:37
void addULong(std::vector< uint64_t > const &l)
Add an vector of unsigned 64 bit longs to the data.
Definition: CompositeData.h:494
static void generateRawBytes(std::vector< std::shared_ptr< CompositeData >> &data, std::vector< uint8_t > &rawBytes, ByteOrder &order)
This method generates raw bytes of evio format from a vector of CompositeData objects.
Definition: CompositeData.cpp:426
uint16_t us16
Unsigned short value.
Definition: CompositeData.h:133
Data()
Constructor.
Definition: CompositeData.h:230
static int compositeFormatToInt(const std::string &formatStr, std::vector< uint16_t > &ifmt)
Definition: CompositeData.cpp:814
void addUint(std::vector< uint32_t > const &i)
Add an vector of unsigned 32 bit integers to the data.
Definition: CompositeData.h:386
uint16_t getUShort()
This method gets the next data item as an unsigned short if it's the correct type.
Definition: CompositeData.cpp:667
static const DataType CHAR8
8 bit int.
Definition: DataType.h:42
int8_t getmValue()
This method gets the next m value data item if it's the correct type.
Definition: CompositeData.cpp:602
std::string toString() const
Obtain a string representation of the composite data.
Definition: CompositeData.cpp:3137
float flt
Float value.
Definition: CompositeData.h:121
int8_t b8
Signed byte value.
Definition: CompositeData.h:139
void addFloat(float f)
Add a 32 bit float to the data.
Definition: CompositeData.h:565
int32_t i32
Signed int value.
Definition: CompositeData.h:131
bool str
Are we storing strings?
Definition: CompositeData.h:141
double getDouble()
This method gets the next data item as a double if it's the correct type.
Definition: CompositeData.cpp:745
This class holds a single, primitive type data item.
Definition: CompositeData.h:114
DataItem()=default
No arg constructor.
int8_t getChar()
This method gets the next data item as a byte/char if it's the correct type.
Definition: CompositeData.cpp:628
int64_t getLong()
This method gets the next data item as a long if it's the correct type.
Definition: CompositeData.cpp:706
uint32_t getPadding() const
This method gets the padding (in bytes).
Definition: CompositeData.h:298
static void parse(uint8_t *bytes, size_t bytesSize, ByteOrder const &order, std::vector< std::shared_ptr< CompositeData >> &list)
This method parses an array of raw bytes into an vector of CompositeData objects. ...
Definition: CompositeData.cpp:299
SingleMember item
Place for holding a primitive type.
Definition: CompositeData.h:158
uint8_t ub8
Unsigned byte value.
Definition: CompositeData.h:137
int64_t l64
Long value.
Definition: CompositeData.h:127
void addShort(int16_t s)
Add a 16 bit short to the data.
Definition: CompositeData.h:402
void addString(std::vector< std::string > const &s)
Add an vector of strings to the data.
Definition: CompositeData.h:633
float getFloat()
This method gets the next data item as a float if it's the correct type.
Definition: CompositeData.cpp:732
std::vector< int32_t > & getNValues()
This method gets a vector of all the N values of the data items inside the composite.
Definition: CompositeData.cpp:535
void process()
This method extracts and stores all the data items and their types in various lists.
Definition: CompositeData.cpp:2823
void addInt(std::vector< int32_t > const &i)
Add an vector of signed 32 bit integers to the data.
Definition: CompositeData.h:360
int32_t getHollerit()
This method gets the next HOLLERIT data item if it's the correct type.
Definition: CompositeData.cpp:615
static const DataType USHORT16
Unsigned 16 bit int.
Definition: DataType.h:41
std::vector< std::string > strVec
Place for holding strings, NOT a primitive type.
Definition: CompositeData.h:160
void addULong(uint64_t l)
Add an unsigned 64 bit long to the data.
Definition: CompositeData.h:482
This class is used to provide all data when constructing a CompositeData object.
Definition: CompositeData.h:182
void addUShort(uint16_t s)
Add an unsigned 16 bit short to the data.
Definition: CompositeData.h:428
void addDouble(std::vector< double > const &d)
Add an vector of 64 bit doubles to the data.
Definition: CompositeData.h:603
static const DataType ULONG64
Unsigned 64 bit int.
Definition: DataType.h:46
void addUChar(std::vector< uint8_t > const &b)
Add an vector of unsigned 8 bit bytes (uchars) to the data.
Definition: CompositeData.h:549
int16_t getShort()
This method gets the next data item as a short if it's the correct type.
Definition: CompositeData.cpp:654
ByteOrder getByteOrder() const
This method gets the raw data byte order.
Definition: CompositeData.cpp:505
std::vector< int8_t > & getmValues()
This method gets a vector of all the m values of the data items inside the composite.
Definition: CompositeData.cpp:549
static const ByteOrder ENDIAN_LOCAL
Local host's byte order.
Definition: ByteOrder.h:61