25 bufferIndex.resize(4*defaultNumberOfEvents);
26 bufferEvents.resize(defaultRecordSize);
27 bufferData.resize(defaultRecordSize+4*defaultNumberOfEvents);
28 bufferRecord.resize(defaultRecordSize+4*defaultNumberOfEvents+512*1024);
29 bufferIndexEntries = 0;
30 bufferEventsPosition = 0;
37 bufferIndex.resize(4*maxEvents);
38 bufferEvents.resize(maxLength);
39 bufferData.resize( maxLength+4*maxEvents + 1024);
40 bufferRecord.resize(maxLength+4*maxEvents+512*1024);
41 bufferIndexEntries = 0;
42 bufferEventsPosition = 0;
57 if((bufferEventsPosition+length)>=bufferEvents.size())
return false;
58 if((bufferIndexEntries+1)*4>=bufferIndex.size())
return false;
59 *
reinterpret_cast<int*
>(&bufferIndex[bufferIndexEntries*4]) = length;
61 memcpy(&bufferEvents[bufferEventsPosition],&vec[start],length);
62 bufferEventsPosition += length;
71 bufferIndexEntries = 0;
72 bufferEventsPosition = 0;
78 int recordbuilder::getRecordLengthRounding(
int bufferSize){
79 if(bufferSize%4==0)
return 0;
80 int nwords = bufferSize/4;
81 int nbytes = 4*(nwords+1);
82 return (nbytes-bufferSize);
110 bufferUserWordOne = userWordOne;
114 bufferUserWordTwo = userWordTwo;
118 int indexSize = bufferIndexEntries*4;
119 int eventsSize = bufferEventsPosition;
120 memcpy(&bufferData[0],&bufferIndex[0],indexSize);
121 memcpy(&bufferData[indexSize],&bufferEvents[0],eventsSize);
122 int uncompressedSize = indexSize+eventsSize;
123 int compressedSize = compressRecord(uncompressedSize);
124 int rounding = getRecordLengthRounding(compressedSize);
125 int compressedSizeToWrite = compressedSize + rounding;
126 int compressedSizeToWriteWords = compressedSizeToWrite/4;
151 int recordbuilder::compressRecord(
int src_size){
155 int result = LZ4_compress_fast(&bufferData[0],&bufferRecord[
RECORD_HEADER_SIZE],src_size,bufferRecord.size(),1);
167 printf(
"\n >>>>> LZ4 compression is not supported.");
168 printf(
"\n >>>>> check if libz4 is installed on your system.");
169 printf(
"\n >>>>> recompile the library with liblz4 installed.\n");
Represents a HIPO event, a container for multiple structures/banks.
std::vector< char > & getEventBuffer()
void build()
Compresses accumulated events and builds the final record.
void setUserWordOne(long userWordOne)
Sets the first user-defined word in the record header.
int getRecordSize()
Returns the total size of the built record in bytes.
recordbuilder()
Default constructor with default capacity.
void reset()
Resets the builder, clearing all accumulated events.
long getUserWordTwo()
Returns the second user-defined word stored in the record header.
void setUserWordTwo(long userWordTwo)
Sets the second user-defined word in the record header.
long getUserWordOne()
Returns the first user-defined word stored in the record header.
bool addEvent(std::vector< char > &vec, int start, int length)
Adds an event from a raw byte vector.
int getEntries()
Returns the number of events currently in the record.
static void writeLong(char *buffer, int position, long value)
Writes a 64-bit long into a byte buffer at the given position.
static void writeInt(char *buffer, int position, int value)
Writes a 32-bit integer into a byte buffer at the given position.
constexpr uint32_t COMP_LENGTH_MASK
constexpr int BITINFO_PAD3_SHIFT
constexpr int RECORD_HEADER_SIZE
constexpr int RECORD_HEADER_WORDS
constexpr int RH_INDEX_ARRAY_LEN_OFFSET
constexpr int RH_EVENT_COUNT_OFFSET
constexpr int RH_USER_WORD2_OFFSET
constexpr int RH_BIT_INFO_OFFSET
constexpr int RH_USER_HEADER_LEN_OFFSET
constexpr int RH_RECORD_NUMBER_OFFSET
constexpr int COMP_TYPE_SHIFT
constexpr int RH_HEADER_LENGTH_OFFSET
constexpr int RH_MAGIC_NUMBER_OFFSET
constexpr int RH_RECORD_LENGTH_OFFSET
constexpr uint32_t HEADER_MAGIC
constexpr int RH_USER_WORD1_OFFSET
constexpr int RH_COMP_WORD_OFFSET
constexpr int HIPO_VERSION
constexpr int RH_DATA_LENGTH_OFFSET
HIPO record builder for accumulating and compressing events.