11 #ifndef EVIO_6_0_READER_H
12 #define EVIO_6_0_READER_H
129 class RecordPosition {
144 explicit RecordPosition(
size_t pos) {
149 RecordPosition(
size_t pos, uint32_t len, uint32_t cnt) {
155 RecordPosition setPosition(
size_t _pos) {
160 RecordPosition setLength(uint32_t _len) {
165 RecordPosition setCount(uint32_t _cnt) {
170 size_t getPosition()
const {
return position; }
172 uint32_t getLength()
const {
return length; }
174 uint32_t getCount()
const {
return count; }
176 std::string toString()
const {
177 std::stringstream ss;
178 ss <<
" POSITION = " << std::setw(16) << position <<
", LENGTH = " << std::setw(12) <<
179 length <<
", COUNT = " << std::setw(8) << count << std::endl;
186 static const uint32_t headerInfoLen = 8;
194 std::vector<RecordPosition> recordPositions;
196 std::ifstream inStreamRandom;
198 std::string fileName {
""};
202 FileHeader fileHeader;
204 bool fromFile =
true;
208 std::shared_ptr<ByteBuffer> buffer =
nullptr;
210 size_t bufferOffset = 0;
212 size_t bufferLimit = 0;
216 RecordInput inputRecordStream;
218 uint32_t currentRecordLoaded = 0;
221 std::shared_ptr<RecordHeader> firstRecordHeader =
nullptr;
223 uint32_t recordNumberExpected = 1;
225 bool checkRecordNumberSequence =
false;
227 FileEventIndex eventIndex;
231 std::string dictionaryXML {
""};
233 std::shared_ptr<uint8_t> firstEvent =
nullptr;
235 uint32_t firstEventSize = 0;
240 std::vector<std::shared_ptr<EvioNode>> eventNodes;
246 bool compressed =
false;
251 int32_t sequentialIndex = -1;
258 bool evioFormat =
true;
263 bool lastCalledSeqNext =
false;
265 uint32_t evioVersion = 6;
269 void setByteOrder(ByteOrder & order);
270 static uint32_t getTotalByteCounts(ByteBuffer & buf, uint32_t* info, uint32_t infoLen);
271 static uint32_t getTotalByteCounts(std::shared_ptr<ByteBuffer> & buf, uint32_t* info, uint32_t infoLen);
278 explicit Reader(std::string
const & filename);
279 Reader(std::string
const & filename,
bool forceScan);
280 explicit Reader(std::shared_ptr<ByteBuffer> & buffer,
bool checkRecordNumSeq =
false);
284 void open(std::string
const & filename,
bool scan =
true);
293 void setBuffer(std::shared_ptr<ByteBuffer> & buf);
327 std::shared_ptr<uint8_t>
getEvent(uint32_t index, uint32_t * len);
328 ByteBuffer &
getEvent(ByteBuffer & buf, uint32_t index);
329 std::shared_ptr<ByteBuffer>
getEvent(std::shared_ptr<ByteBuffer> & buf, uint32_t index);
349 static void findRecordInfo(std::shared_ptr<ByteBuffer> & buf, uint32_t offset,
350 uint32_t* info, uint32_t infoLen);
352 uint32_t* info, uint32_t infoLen);
365 std::shared_ptr<ByteBuffer> &
addStructure(uint32_t eventNumber, ByteBuffer & addBuffer);
366 std::shared_ptr<ByteBuffer> &
removeStructure(std::shared_ptr<EvioNode> & removeNode);
377 #endif //EVIO_6_0_READER_H
uint32_t getFirstEventSize()
Get size, in bytes, of byte array representing the first event.
Definition: Reader.cpp:336
std::vector< std::shared_ptr< EvioNode > > & getEventNodes()
Get a reference to the list of EvioNode objects contained in the buffer being read.
Definition: Reader.cpp:382
size_t getFileSize() const
Get the size of the file being read, in bytes.
Definition: Reader.cpp:224
bool getCheckRecordNumberSequence() const
Get whether or not record numbers are enforced to be sequential.
Definition: Reader.cpp:389
void forceScanFile()
Scan file to find all records and store their position, length, and event count.
Definition: Reader.cpp:1404
void close()
This closes the file.
Definition: Reader.cpp:129
uint32_t getEventLength(uint32_t index)
Returns the length of the event with given index.
Definition: Reader.cpp:645
std::shared_ptr< ByteBuffer > scanBuffer()
This method scans a buffer to find all records and store their position, length, and event count...
Definition: Reader.cpp:1049
bool isFile() const
Is a file being read?
Definition: Reader.cpp:155
Reader class that reads files stored in the HIPO format.
Definition: Reader.h:117
uint32_t getEventCount() const
Get the number of events in file/buffer.
Definition: Reader.cpp:360
void extractDictionaryAndFirstEvent()
Extract dictionary and first event from file/buffer if possible, else do nothing. ...
Definition: Reader.cpp:747
FileHeader & getFileHeader()
Get the file header from reading a file.
Definition: Reader.cpp:247
std::shared_ptr< ByteBuffer > & removeStructure(std::shared_ptr< EvioNode > &removeNode)
This method removes the data, represented by the given node, from the buffer.
Definition: Reader.cpp:1634
bool hasFirstEvent() const
Does this evio file/buffer have an associated first event?
Definition: Reader.cpp:348
std::shared_ptr< uint8_t > getNextEvent(uint32_t *len)
Get a byte array representing the next event from the file/buffer while sequentially reading...
Definition: Reader.cpp:412
uint32_t getVersion() const
Get the Evio format version number of the file/buffer being read.
Definition: Reader.cpp:275
bool hasDictionary() const
Does this evio file/buffer have an associated XML dictionary?
Definition: Reader.cpp:308
bool isClosed() const
Has close() been called (without reopening by calling setBuffer(std::shared_ptr<ByteBuffer> &))...
Definition: Reader.cpp:148
uint32_t getCurrentRecord() const
Get the index of the current record.
Definition: Reader.cpp:711
std::shared_ptr< EvioNode > getEventNode(uint32_t index)
Get an EvioNode representing the specified event from the buffer.
Definition: Reader.cpp:675
Reader()
Default constructor.
Definition: Reader.cpp:22
std::shared_ptr< uint8_t > getPrevEvent(uint32_t *len)
Get a byte array representing the previous event from the sequential queue.
Definition: Reader.cpp:454
std::shared_ptr< ByteBuffer > & addStructure(uint32_t eventNumber, ByteBuffer &addBuffer)
This method adds an evio container (bank, segment, or tag segment) as the last structure contained in...
Definition: Reader.cpp:1758
std::shared_ptr< uint8_t > getEvent(uint32_t index, uint32_t *len)
Get a byte array representing the specified event from the file/buffer.
Definition: Reader.cpp:563
ByteOrder & getByteOrder()
Get the byte order of the file/buffer being read.
Definition: Reader.cpp:261
bool isEvioFormat() const
Does this file/buffer contain non-evio format events?
Definition: Reader.cpp:289
std::vector< RecordPosition > & getRecordPositions()
Returns a reference to the list of record positions in the file.
Definition: Reader.cpp:374
void setBuffer(std::shared_ptr< ByteBuffer > &buf)
This method can be used to avoid creating additional Reader objects by reusing this one with another ...
Definition: Reader.cpp:170
void scanUncompressedBuffer()
Scan buffer containing uncompressed data to find all records and store their position, length, and event count.
Definition: Reader.cpp:1259
std::shared_ptr< ByteBuffer > readUserHeader()
Reads user header of the file header/first record header of buffer.
Definition: Reader.cpp:519
size_t getBufferOffset() const
Get the beginning position of the buffer being read.
Definition: Reader.cpp:240
static void findRecordInfo(std::shared_ptr< ByteBuffer > &buf, uint32_t offset, uint32_t *info, uint32_t infoLen)
Reads data from a record header in order to determine things like the bitInfo word, various lengths, etc.
Definition: Reader.cpp:899
std::shared_ptr< EvioNode > getNextEventNode()
Get an EvioNode representing the next event from the buffer while sequentially reading.
Definition: Reader.cpp:495
bool hasPrev() const
Checks if the stream has previous event to be accessed through, getPrevEvent()
Definition: Reader.cpp:697
std::string getFileName() const
Get the name of the file being read.
Definition: Reader.cpp:217
void extractDictionaryFromFile()
Extract dictionary and first event from file if possible, else do nothing.
Definition: Reader.cpp:818
void open(std::string const &filename, bool scan=true)
Opens an input stream in binary mode.
Definition: Reader.cpp:92
uint32_t getRecordEventCount() const
Get the number of events in current record.
Definition: Reader.cpp:704
bool readRecord(uint32_t index)
Reads record from the file/buffer at the given record index.
Definition: Reader.cpp:727
std::string getDictionary()
Get the XML format dictionary if there is one.
Definition: Reader.cpp:296
bool isCompressed() const
Is the data in the file/buffer compressed?
Definition: Reader.cpp:282
std::shared_ptr< RecordHeader > & getFirstRecordHeader()
Get the first record header from reading a file/buffer.
Definition: Reader.cpp:254
uint32_t getRecordCount() const
Get the number of records read from the file/buffer.
Definition: Reader.cpp:367
void scanFile(bool force)
Scans the file to index all the record positions.
Definition: Reader.cpp:1491
bool hasNext() const
Checks if the file has an event to read next.
Definition: Reader.cpp:690
This class is used to read an evio format version 6 formatted file or buffer.
Definition: EvioCompactReaderV6.h:52
void extractDictionaryFromBuffer()
Extract dictionary and first event from buffer if possible, else do nothing.
Definition: Reader.cpp:762
RecordInput & getCurrentRecordStream()
Get the current record stream.
Definition: Reader.cpp:718
static const ByteOrder ENDIAN_LOCAL
Local host's byte order.
Definition: ByteOrder.h:61
void show() const
Print out all record position information.
Definition: Reader.cpp:1841
std::shared_ptr< ByteBuffer > getBuffer()
Get the buffer being read, if any.
Definition: Reader.cpp:233
uint32_t getNumEventsRemaining() const
Get the number of events remaining in the file/buffer.
Definition: Reader.cpp:398
std::shared_ptr< uint8_t > & getFirstEvent(uint32_t *size)
Get a byte array representing the first event.
Definition: Reader.cpp:322