67 if(inputStream.is_open()==
true){
83 if(inputStream.is_open()==
true){
88 inputStream.open(filename, std::ios::binary);
89 inputStream.seekg(0,std::ios_base::end);
90 inputStreamSize = inputStream.tellg();
91 inputStream.seekg(0,std::ios_base::beg);
92 if(inputStream.is_open()==
false){
93 printf(
"[ERROR] something went wrong with openning file : %s\n",
105 void reader::readHeader(){
107 std::vector<char> headerBuffer;
108 headerBuffer.resize(80);
109 inputStream.read(&headerBuffer[0],80);
126 printf(
" THIS FILE IS BIG ENDIAN: SWAPPING BYTES\n");
133 word_8 = __builtin_bswap32(word_8);
142 printf(
"----------------------------------------\n");
143 printf(
"**** reader:: header version : %d \n",header.
version);
144 printf(
"**** reader:: header length : %d \n",header.
headerLength*4);
146 printf(
"**** reader:: trailer position : %lu\n",header.
trailerPosition);
147 printf(
"**** reader:: file size : %lu\n",inputStreamSize);
148 printf(
"----------------------------------------\n");
162 void reader::readIndex(){
165 if(_verbose)printf(
"*** reader:: trailer record event count : %d\n",inputRecord.
getEventCount());
173 if(_verbose)
event.show();
176 if(_verbose)base.
show();
177 readerEventIndex.
clear();
181 for(
int i = 0; i < rows; i++){
183 int entries = base.
getIntAt ( rows*12 + i*4);
184 long uid1 = base.
getLongAt( rows*16 + i*8);
185 if(tagsToRead.size()==0){
186 readerEventIndex.
addSize(entries);
190 for(
long jr : tagsToRead){
191 if(jr==uid1) accept =
true;
194 readerEventIndex.
addSize(entries);
199 readerEventIndex.
rewind();
201 if(_verbose)printf(
"**** reader:: # of events : %d \n",readerEventIndex.
getMaxEvents());
214 if(readerEventIndex.
canAdvance()==
false)
return false;
218 if(recordToBeRead!=recordNumber){
219 long position = readerEventIndex.
getPosition(recordToBeRead);
220 inputRecord.
readRecord(inputStream,position,0);
262 bool status =
next();
263 if(status==
false)
return false;
267 for(
size_t k = 0; k < list.size(); k++){
274 std::vector<hipo::bank> list;
276 for(
size_t k = 0; k < names.size(); k++){
285 if(inputStream.is_open()==
false){
290 dictRecord.
readRecord(inputStream,position,0);
295 for(
int i = 0; i < nevents; i++){
312 if(inputStream.is_open()==
false){
317 dictRecord.
readRecord(inputStream,position,0);
321 for(
int i = 0; i < nevents; i++){
335 if(readerEventIndex.
canAdvance()==
false)
return false;
339 if(recordToBeRead!=recordNumber){
340 long position = readerEventIndex.
getPosition(recordToBeRead);
341 inputRecord.
readRecord(inputStream,position,0);
357 if(readerEventIndex.
gotoEvent(eventNumber)==
false){
358 printf(
"[WARNING] hipo::reader::gotoEvent event %d greater than max events = %d, will stay at current event\n",
365 if(recordToBeRead!=recordNumber){
367 long position = readerEventIndex.
getPosition(recordToBeRead);
368 inputRecord.
readRecord(inputStream,position,0);
380 bool status = readerEventIndex.
gotoRecord(irec);
381 if(status==
false)
return false;
382 long position = readerEventIndex.
getPosition(irec);
383 inputRecord.
readRecord(inputStream,position,0);
391 long position = readerEventIndex.
getPosition(irec);
392 inputRecord.
readRecord(inputStream,position,0);
397 long position = readerEventIndex.
getPosition(irec);
403 std::vector<int> rowvec;
405 int item = b[0].getSchema().getEntryOrder(column);
407 while(
next(b)==
true){
408 for(
int row = 0 ; row < b[0].getRows();row++){
409 rowvec.push_back(b[0].
getInt(item,row));
412 if(max>0&&counter>max)
break;
418 std::vector<float> rowvec;
420 int item = b[0].getSchema().getEntryOrder(column);
422 while(
next(b)==
true){
423 for(
int row = 0 ; row < b[0].getRows();row++){
424 rowvec.push_back(b[0].
getFloat(item,row));
427 if(max>0&&counter>max)
break;
444 std::cout <<
"******************************************************" << std::endl;
445 std::cout <<
"* WARNING: *" << std::endl;
446 std::cout <<
"* This library war compiled without LZ4 support. *" << std::endl;
447 std::cout <<
"* Reading and writing compressed buffers will not *" << std::endl;
448 std::cout <<
"* work. However un-compressed file I/O will work. *" << std::endl;
449 std::cout <<
"******************************************************" << std::endl;
463 if(recordEvents.size()==0){
464 recordEvents.push_back(0);
465 recordEvents.push_back(size);
467 int cz = recordEvents[recordEvents.size()-1] + size;
468 recordEvents.push_back(cz);
485 if(recordEvents.size()==0)
return false;
486 if(currentEvent+1<recordEvents[currentRecord+1]){
488 currentRecordEvent++;
491 if(recordEvents.size() < currentRecord + 2 + 1){
492 printf(
"advance(): Warning, reached the limit of events.\n");
497 currentRecordEvent = 0;
514 std::vector<int>::iterator l_bound =
515 std::lower_bound(recordEvents.begin(), recordEvents.end(), eventNumber+1);
518 long position = (l_bound - recordEvents.begin()) - 1;
520 currentRecord = position;
521 currentRecordEvent = eventNumber - recordEvents[currentRecord];
522 currentEvent = eventNumber;
528 for(
size_t i = 0; i < recordEvents.size(); i++){
529 printf(
"record = %8zu, %8d\n",i,recordEvents[i]);
537 if(recordEvents.size()==0)
return 0;
538 return recordEvents[recordEvents.size()-1];
547 currentEvent=-1; currentRecord=0; currentRecordEvent = -1;
550 if(irec+1>(
int)recordEvents.size())
552 currentEvent = recordEvents[irec]-1; currentRecord=irec;
553 currentRecordEvent = -1;
564 currentRecordEvent = -1;
567 if(irec+1>(
int)recordEvents.size())
570 currentEvent = recordEvents[irec]-1;
572 currentRecordEvent = -1;
582 return (currentEvent<recordEvents[currentRecord+1]-1);
Represents a HIPO bank, a tabular data structure with rows and typed columns.
Lightweight wrapper for a raw data pointer with type, size, and offset metadata.
const char * getDataPtr()
Return the raw data pointer.
Collection of schema definitions, typically read from a HIPO file header.
bool parse(const char *schemaString)
Parse a full schema string and add it to the dictionary.
schema & getSchema(const char *name)
Retrieve a schema by name.
Represents a HIPO event, a container for multiple structures/banks.
static void getStructureNoCopy(const char *buffer, hipo::structure &str, int group, int item)
Extract a structure from a raw buffer without copying the data.
void getStructure(hipo::structure &str, int group, int item)
Extract a structure from the event by group and item identifiers.
Exception thrown for HIPO file I/O errors (e.g., file not found, read failure).
void addPosition(long position)
Register a record position.
bool gotoRecord(int irec)
Jump to a specific record.
bool loadRecord(int irec)
Load a specific record by index.
void clear()
Remove all record entries from the index.
void show()
Print index information to stdout.
bool canAdvanceInRecord()
Check if more events remain in the current record.
void rewind()
Reset the index to the beginning (before the first event).
int getRecordEventNumber()
bool canAdvance()
Check if there are more events to read.
bool advance()
Advance to the next event, loading new records as needed.
void addSize(int size)
Register a record with the given number of events.
bool gotoEvent(int eventNumber)
Jump to a specific event number.
long getPosition(int index)
void read(hipo::event &dataevent)
Read the current event into the given event object.
std::vector< hipo::bank > getBanks(std::vector< std::string > names)
Create bank objects for the given bank names.
void readDictionary(hipo::dictionary &dict)
Read the schema dictionary from the file header.
void getStructureNoCopy(hipo::structure &structure, int group, int item)
Extract a structure without copying (zero-copy).
bool nextInRecord()
Advance to the next event within the current record.
void printWarning()
Print a warning message (e.g., end of file).
reader()
Default constructor.
bool loadRecord(int irec)
Load a specific record by index into the internal buffer.
void getStructure(hipo::structure &structure, int group, int item)
Extract a structure from the current event by group and item.
bool next()
Advance to the next event.
std::vector< int > getInt(const char *bank, const char *column, int max=-1)
Read all integer values from a bank column across events.
void open(const char *filename)
Open a HIPO file for reading.
bool hasNext()
Check if more events are available without advancing.
void about()
Print file information to stdout.
bool gotoRecord(int irec)
Jump to a specific record.
bool gotoEvent(int eventNumber)
Jump to a specific event number.
std::vector< float > getFloat(const char *bank, const char *column, int max=-1)
Read all float values from a bank column across events.
void readUserConfig(std::map< std::string, std::string > &mapConfig)
Read user configuration key-value pairs from the file header.
Represents a single HIPO record containing multiple events.
int getEventCount()
Return the number of events stored in this record.
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.
Low-level data structure representing a HIPO structure.
int getSize() const noexcept
virtual void show() const
Display the structure contents to standard output.
long getLongAt(int index) const noexcept
int getIntAt(int index) const noexcept
std::string getStringAt(int index)
static void printLogo()
Prints the HIPO library logo to standard output.
Exception classes for HIPO library error handling.
constexpr uint32_t HEADER_MAGIC_BE
constexpr int FILE_INDEX_ITEM
constexpr int FH_USER_HEADER_LEN_OFFSET
constexpr int FH_INDEX_ARRAY_LEN_OFFSET
constexpr int CONFIG_GROUP
constexpr int CONFIG_KEY_ITEM
constexpr int FH_RECORD_COUNT_OFFSET
constexpr int FH_FILE_NUMBER_OFFSET
constexpr int FILE_INDEX_GROUP
constexpr int FH_UNIQUE_WORD_OFFSET
constexpr uint32_t BITINFO_VERSION_MASK
constexpr int FH_BIT_INFO_OFFSET
constexpr int FH_HEADER_LENGTH_OFFSET
constexpr int BITINFO_VERSION_BITS
constexpr int FH_USER_REGISTER_OFFSET
constexpr int FH_MAGIC_NUMBER_OFFSET
constexpr int FH_TRAILER_POS_OFFSET
constexpr uint32_t STRUCT_SIZE_MASK
constexpr int CONFIG_STRING_ITEM
Sequential and random-access reader for HIPO files with event filtering and dictionary support.
HIPO record reading and event extraction.