63 recordHeaderBuffer.resize(80);
64 stream.seekg(position,std::ios::beg);
66 stream.read( (
char *) &recordHeaderBuffer[0],80);
86 compressedWord = __builtin_bswap32(compressedWord);
91 int dataBufferLengthBytes = recordHeader.
recordLength * 4 - headerLengthBytes;
105 if(dataBufferLengthBytes>recordCompressedBuffer.size()){
106 int newSize = dataBufferLengthBytes + 5*1024;
109 recordCompressedBuffer.resize(newSize);
112 long dataposition = position + headerLengthBytes;
114 stream.seekg(dataposition,std::ios::beg);
116 stream.read( (&recordCompressedBuffer[0]), dataBufferLengthBytes);
124 if(recordBuffer.size()<decompressedLength){
126 recordBuffer.resize(decompressedLength+1024);
135 memcpy((&recordBuffer[0]),(&recordCompressedBuffer[0]),decompressedLength);
137 getUncompressed((&recordCompressedBuffer[0]) , (&recordBuffer[0]),
138 dataBufferLengthBytes-compressedDataLengthPadding,
153 int eventPosition = 0;
155 auto *ptr =
reinterpret_cast<int*
>(&recordBuffer[i*4]);
157 if(recordHeader.
dataEndianness==1) size = __builtin_bswap32(size);
158 eventPosition += size;
159 *ptr = eventPosition;
167 if((position+80)>=inputSize)
return false;
169 recordHeaderBuffer.resize(80);
170 stream.seekg(position,std::ios::beg);
172 stream.read( (
char *) &recordHeaderBuffer[0],80);
192 compressedWord = __builtin_bswap32(compressedWord);
197 int dataBufferLengthBytes = recordHeader.
recordLength * 4 - headerLengthBytes;
211 if(dataBufferLengthBytes>recordCompressedBuffer.size()){
214 int newSize = dataBufferLengthBytes + 500*1024;
218 recordCompressedBuffer.resize(newSize);
221 long dataposition = position + headerLengthBytes;
222 stream.seekg(dataposition,std::ios::beg);
224 if(position+dataBufferLengthBytes+recordHeader.
headerLength>inputSize){
225 printf(
"**** warning : record at position %ld is incomplete.",position);
229 stream.read( (&recordCompressedBuffer[0]), dataBufferLengthBytes);
236 if(recordBuffer.size()<decompressedLength){
238 int resize_fraction = (int) (decompressedLength*0.2);
240 recordBuffer.resize(decompressedLength + resize_fraction);
245 readBenchmark.
pause();
249 memcpy((&recordBuffer[0]),(&recordCompressedBuffer[0]),decompressedLength);
251 getUncompressed((&recordCompressedBuffer[0]) , (&recordBuffer[0]),
252 dataBufferLengthBytes-compressedDataLengthPadding,
255 unzipBenchmark.
pause();
267 int eventPosition = 0;
269 auto *ptr =
reinterpret_cast<int*
>(&recordBuffer[i*4]);
271 if(recordHeader.
dataEndianness==1) size = __builtin_bswap32(size);
272 eventPosition += size;
273 *ptr = eventPosition;
275 indexBenchmark.
pause();
285 stream.seekg(position,std::ios::beg);
287 if(recordLength>recordCompressedBuffer.size()){
288 int newSize = recordLength + 5*1024;
292 recordCompressedBuffer.resize(newSize);
295 stream.seekg( position,std::ios::beg);
297 stream.read( (&recordCompressedBuffer[0]), recordLength);
307 int compressedWord = *(
reinterpret_cast<int *
>(&recordCompressedBuffer[
RH_COMP_WORD_OFFSET]));
319 compressedWord = __builtin_bswap32(compressedWord);
324 int dataBufferLengthBytes = recordHeader.
recordLength * 4 - headerLengthBytes;
341 long dataposition = position + headerLengthBytes;
353 if(recordBuffer.size()<decompressedLength){
355 recordBuffer.resize(decompressedLength+1024);
362 memcpy((&recordBuffer[0]),(&recordCompressedBuffer[0]),decompressedLength);
366 dataBufferLengthBytes-compressedDataLengthPadding,
380 int eventPosition = dataposition;
382 auto *ptr =
reinterpret_cast<int*
>(&recordBuffer[i*4]);
384 if(recordHeader.
dataEndianness==1) size = __builtin_bswap32(size);
385 eventPosition += size;
386 *ptr = eventPosition;
412 int first_position = 0;
414 first_position = *(
reinterpret_cast<uint32_t *
>(&recordBuffer[(index -1)*4]));
416 int last_position = *(
reinterpret_cast<uint32_t *
>(&recordBuffer[index*4]));
450 int size = *
reinterpret_cast<const uint32_t *
>(&event_data.
getDataPtr()[pos.first+4]);
476 for(
int index = 0; index < nevents; index++){
477 int first_position = 0;
479 first_position = *(
reinterpret_cast<uint32_t *
>(&recordBuffer[(index -1)*4]));
481 int last_position = *(
reinterpret_cast<uint32_t *
>(&recordBuffer[index*4]));
482 emap.push_back(std::make_pair(first_position+offset,last_position+offset));
493 void record::showBuffer(
const char *
data,
int wrapping,
int maxsize)
495 for(
int i = 0; i < maxsize; i++){
496 printf(
"%X ", 0x000000FF&((
unsigned int)
data[i]));
497 if( (i+1)%wrapping==0) printf(
"\n");
507 int record::getUncompressed(
const char *data,
char *dest,
int dataLength,
int dataLengthUncompressed){
509 int result = LZ4_decompress_safe(data,dest,dataLength,dataLengthUncompressed);
515 printf(
"\n >>>>> LZ4 compression is not supported.");
516 printf(
"\n >>>>> check if libz4 is installed on your system.");
517 printf(
"\n >>>>> recompile the library with liblz4 installed.\n");
526 char *record::getUncompressed(
const char *data,
int dataLength,
527 int dataLengthUncompressed){
530 char *output = (
char *) malloc(dataLengthUncompressed);
531 LZ4_decompress_safe(data,output,dataLength,dataLengthUncompressed);
540 printf(
"\n >>>>> LZ4 compression is not supported.");
541 printf(
"\n >>>>> check if libz4 is installed on your system.");
542 printf(
"\n >>>>> recompile the library with liblz4 installed.\n");
551 maxEvents = max_events; maxSize = max_size;
572 int evCount =
count();
573 if(evCount>=maxEvents)
return false;
584 int eventsize = *(
reinterpret_cast<int *
>(&dataBuffer[pos+4]));
585 event.init(&dataBuffer[pos],eventsize);
586 return pos+eventsize;
590 int size = *(
reinterpret_cast<const int *
>(ptr));
592 memcpy(&dataBuffer[0],ptr,
size);
599 printf(
"## data frame summary:\n");
Represents a HIPO bank, a tabular data structure with rows and typed columns.
void resume()
Starts or resumes the timer.
void pause()
Pauses the timer and accumulates elapsed time.
Lightweight wrapper for a raw data pointer with type, size, and offset metadata.
void setDataSize(int __size)
Set the data size in bytes.
void setDataOffset(int __offset)
Set the byte offset into the source buffer.
void setDataPtr(const char *__ptr)
Set the raw data pointer.
const char * getDataPtr()
Return the raw data pointer.
void setDataType(int __type)
Set the data type identifier.
int getDataSize()
Return the data size in bytes.
bool addEvent(hipo::event &event)
Append an event to the dataframe.
void reset()
Clear all events and reset the dataframe to an empty state.
int getEventAt(int pos, hipo::event &event)
Retrieve the event at the given position.
void init(const char *ptr)
Initialize the dataframe from an existing raw buffer.
int count()
Return the number of events currently stored in the frame.
dataframe()
Construct an empty dataframe with default limits.
void summary()
Print a summary of the dataframe contents to standard output.
int size()
Return the total size of the internal buffer in bytes.
Represents a HIPO event, a container for multiple structures/banks.
std::vector< char > & getEventBuffer()
void getStructure(hipo::structure &str, int group, int item)
Extract a structure from the event by group and item identifiers.
std::pair< int, int > getStructurePosition(int group, int item)
Find the position and length of a structure in the event buffer.
void readEvent(std::vector< char > &vec, int index)
Read raw event bytes into a vector.
record()
Construct an empty record.
int getEventCount()
Return the number of events stored in this record.
void getEventsMap(std::vector< std::pair< int, int >> &emap)
Build a map of event positions (offset, length pairs).
void read(hipo::bank &b, int event)
Read a specific bank from a given event in this record.
int getRecordSizeCompressed()
Return the compressed size of this record in bytes.
void readRecord(std::ifstream &stream, long position, int dataOffset)
Read a record from a file stream at the specified position.
void readHipoEvent(hipo::event &event, int index)
Read an event and populate a hipo::event object.
void getData(hipo::data &data, int index)
Get a lightweight data handle for a specific event.
void getColumn(hipo::data &data, int column, hipo::bank &bank, int event)
Extract a single column from a bank for a given event.
void readRecord__(std::ifstream &stream, long position, long recordLength)
Read a record using its total length (internal variant).
int getEntryOrder(const char *name) const
Get the column index for a given column name.
int getOffset(int item, int order, int rows) const
Compute the byte offset for a column value by column index.
int getRowLength() const noexcept
Get the size of a single row in bytes.
int getItem()
Get the item identifier.
int getGroup()
Get the group identifier.
int getEntryType(int item) const noexcept
Get the type identifier of a column by index.
constexpr uint32_t COMP_LENGTH_MASK
constexpr uint32_t HEADER_MAGIC_BE
constexpr int BITINFO_PAD3_SHIFT
constexpr uint32_t BITINFO_PAD_MASK
constexpr int BITINFO_PAD1_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_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_COMP_WORD_OFFSET
constexpr int RH_DATA_LENGTH_OFFSET
HIPO record reading and event extraction.