evio  6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
evio::Reader Class Reference

Reader class that reads files stored in the HIPO format. More...

#include <Reader.h>

Public Member Functions

 Reader ()
 Default constructor. More...
 
 Reader (std::string const &filename)
 Constructor with filename. More...
 
 Reader (std::string const &filename, bool forceScan)
 Constructor with filename. More...
 
 Reader (std::shared_ptr< ByteBuffer > &buffer, bool checkRecordNumSeq=false)
 Constructor for reading buffer with evio data. More...
 
 ~Reader ()=default
 
void open (std::string const &filename, bool scan=true)
 Opens an input stream in binary mode. More...
 
void close ()
 This closes the file. More...
 
bool isClosed () const
 Has close() been called (without reopening by calling setBuffer(std::shared_ptr<ByteBuffer> &))? More...
 
bool isFile () const
 Is a file being read? More...
 
std::string getFileName () const
 Get the name of the file being read. More...
 
size_t getFileSize () const
 Get the size of the file being read, in bytes. More...
 
void setBuffer (std::shared_ptr< ByteBuffer > &buf)
 This method can be used to avoid creating additional Reader objects by reusing this one with another buffer. More...
 
std::shared_ptr< ByteBuffergetBuffer ()
 Get the buffer being read, if any. More...
 
size_t getBufferOffset () const
 Get the beginning position of the buffer being read. More...
 
FileHeadergetFileHeader ()
 Get the file header from reading a file. More...
 
std::shared_ptr< RecordHeader > & getFirstRecordHeader ()
 Get the first record header from reading a file/buffer. More...
 
ByteOrdergetByteOrder ()
 Get the byte order of the file/buffer being read. More...
 
uint32_t getVersion () const
 Get the Evio format version number of the file/buffer being read. More...
 
bool isCompressed () const
 Is the data in the file/buffer compressed? More...
 
bool isEvioFormat () const
 Does this file/buffer contain non-evio format events? More...
 
std::string getDictionary ()
 Get the XML format dictionary if there is one. More...
 
bool hasDictionary () const
 Does this evio file/buffer have an associated XML dictionary? More...
 
std::shared_ptr< uint8_t > & getFirstEvent (uint32_t *size)
 Get a byte array representing the first event. More...
 
uint32_t getFirstEventSize ()
 Get size, in bytes, of byte array representing the first event. More...
 
bool hasFirstEvent () const
 Does this evio file/buffer have an associated first event? More...
 
uint32_t getEventCount () const
 Get the number of events in file/buffer. More...
 
uint32_t getRecordCount () const
 Get the number of records read from the file/buffer. More...
 
std::vector< RecordPosition > & getRecordPositions ()
 Returns a reference to the list of record positions in the file. More...
 
std::vector< std::shared_ptr
< EvioNode > > & 
getEventNodes ()
 Get a reference to the list of EvioNode objects contained in the buffer being read. More...
 
bool getCheckRecordNumberSequence () const
 Get whether or not record numbers are enforced to be sequential. More...
 
uint32_t getNumEventsRemaining () const
 Get the number of events remaining in the file/buffer. More...
 
std::shared_ptr< uint8_t > getNextEvent (uint32_t *len)
 Get a byte array representing the next event from the file/buffer while sequentially reading. More...
 
std::shared_ptr< uint8_t > getPrevEvent (uint32_t *len)
 Get a byte array representing the previous event from the sequential queue. More...
 
std::shared_ptr< EvioNodegetNextEventNode ()
 Get an EvioNode representing the next event from the buffer while sequentially reading. More...
 
std::shared_ptr< ByteBufferreadUserHeader ()
 Reads user header of the file header/first record header of buffer. More...
 
std::shared_ptr< uint8_t > getEvent (uint32_t index, uint32_t *len)
 Get a byte array representing the specified event from the file/buffer. More...
 
ByteBuffergetEvent (ByteBuffer &buf, uint32_t index)
 Get a byte array representing the specified event from the file/buffer and place it in the given buf. More...
 
std::shared_ptr< ByteBuffergetEvent (std::shared_ptr< ByteBuffer > &buf, uint32_t index)
 Get a byte array representing the specified event from the file/buffer and place it in the given buf. More...
 
uint32_t getEventLength (uint32_t index)
 Returns the length of the event with given index. More...
 
std::shared_ptr< EvioNodegetEventNode (uint32_t index)
 Get an EvioNode representing the specified event from the buffer. More...
 
bool hasNext () const
 Checks if the file has an event to read next. More...
 
bool hasPrev () const
 Checks if the stream has previous event to be accessed through, getPrevEvent() More...
 
uint32_t getRecordEventCount () const
 Get the number of events in current record. More...
 
uint32_t getCurrentRecord () const
 Get the index of the current record. More...
 
RecordInputgetCurrentRecordStream ()
 Get the current record stream. More...
 
bool readRecord (uint32_t index)
 Reads record from the file/buffer at the given record index. More...
 

Protected Member Functions

void extractDictionaryAndFirstEvent ()
 Extract dictionary and first event from file/buffer if possible, else do nothing. More...
 
void extractDictionaryFromBuffer ()
 Extract dictionary and first event from buffer if possible, else do nothing. More...
 
void extractDictionaryFromFile ()
 Extract dictionary and first event from file if possible, else do nothing. More...
 
std::shared_ptr< ByteBufferscanBuffer ()
 This method scans a buffer to find all records and store their position, length, and event count. More...
 
void scanUncompressedBuffer ()
 Scan buffer containing uncompressed data to find all records and store their position, length, and event count. More...
 
void forceScanFile ()
 Scan file to find all records and store their position, length, and event count. More...
 
void scanFile (bool force)
 Scans the file to index all the record positions. More...
 
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 an event. More...
 
std::shared_ptr< ByteBuffer > & removeStructure (std::shared_ptr< EvioNode > &removeNode)
 This method removes the data, represented by the given node, from the buffer. More...
 
void show () const
 Print out all record position information. More...
 

Static Protected Member Functions

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. More...
 
static void findRecordInfo (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. More...
 

Friends

class EvioCompactReaderV6
 

Detailed Description

Reader class that reads files stored in the HIPO format.


File has this structure:
   +----------------------------------+
   |      General File Header         |
   +----------------------------------+
   +----------------------------------+
   |         Index (optional)         |
   +----------------------------------+
   +----------------------------------+
   |     User Header (optional)       |
   +----------------------------------+
   +----------------------------------+
   |                                  |
   |            Record 1              |
   |                                  |
   |                                  |
   |                                  |
   +----------------------------------+
                  ...
   +----------------------------------+
   |                                  |
   |            Record N              |
   |                                  |
   |                                  |
   |                                  |
   +----------------------------------+
   +----------------------------------+
   |       Trailer (optional)         |
   +----------------------------------+
   +----------------------------------+
   |    Trailer's Index (optional)    |
   +----------------------------------+
Buffer or streamed data has this structure:
   +----------------------------------+
   |                                  |
   |            Record 1              |
   |                                  |
   |                                  |
   |                                  |
   +----------------------------------+
                  ...
   +----------------------------------+
   |                                  |
   |            Record N              |
   |                                  |
   |                                  |
   |                                  |
   +----------------------------------+
   +----------------------------------+
   |       Trailer (optional)         |
   +----------------------------------+
The important thing with a buffer or streaming is for the last header or
trailer to set the "last record" bit.

Something to keep in mind is one can intersperse sequential calls (getNextEvent, getPrevEvent, or getNextEventNode) with random access calls (getEvent or getEventNode), and the sequence remains unchanged after the random access.

Version
6.0
Since
6.0 08/10/2017
Author
gavalian (original Java)
timmer
See Also
FileHeader
RecordInput

Constructor & Destructor Documentation

evio::Reader::Reader ( )

Default constructor.

Does nothing. The open(std::string const &, bool) method has to be called to open the input stream. Also forceScanFile() needs to be called to find records.

evio::Reader::Reader ( std::string const &  filename)
explicit

Constructor with filename.

Creates instance and opens the input stream with given name. Uses existing indexes in file before scanning.

Parameters
filenameinput file name.
Exceptions
IOExceptionif error reading file
EvioExceptionif file is not in the proper format or earlier than version 6

References open().

evio::Reader::Reader ( std::string const &  filename,
bool  forceScan 
)

Constructor with filename.

Creates instance and opens the input stream with given name.

Parameters
filenameinput file name.
forceScanif true, force a scan of file, else use existing indexes first.
Exceptions
IOExceptionif error reading file
EvioExceptionif file is not in the proper format or earlier than version 6

References open(), and scanFile().

evio::Reader::Reader ( std::shared_ptr< ByteBuffer > &  buffer,
bool  checkRecordNumSeq = false 
)
explicit

Constructor for reading buffer with evio data.

Buffer must be ready to read with position and limit set properly. If the given buffer contains compressed data, it is uncompressed into another buffer. The buffer containing the newly uncompressed data then becomes the internal buffer of this object. It can be obtained by calling getBuffer.

Parameters
bufferbuffer with evio data.
checkRecordNumSeqif true, check to see if all record numbers are in order, if not throw exception.
Exceptions
EvioExceptionif buffer too small, not in the proper format, or earlier than version 6; if checkRecordNumSeq is true and records are out of sequence.

References scanBuffer().

evio::Reader::~Reader ( )
default

Member Function Documentation

std::shared_ptr< ByteBuffer > & evio::Reader::addStructure ( uint32_t  eventNumber,
ByteBuffer addBuffer 
)
protected

This method adds an evio container (bank, segment, or tag segment) as the last structure contained in an event.

It is the responsibility of the caller to make sure that the buffer argument contains valid evio data (only data representing the structure to be added - not in file format with record header and the like) which is compatible with the type of data stored in the given event.

To produce such evio data use EvioBank#write(ByteBuffer &), EvioSegment#write(ByteBuffer &) or EvioTagSegment#write(ByteBuffer &) depending on whether a bank, seg, or tagseg is being added.

The given buffer argument must be ready to read with its position and limit defining the limits of the data to copy.

Parameters
eventNumbernumber of event to which addBuffer is to be added
addBufferbuffer containing evio data to add (not evio file format, i.e. no record headers)
Returns
a new ByteBuffer object which is created and filled with all the data including what was just added.
Exceptions
EvioExceptionif eventNumber out of bounds; if addBuffer arg is empty or has non-evio format; if addBuffer is opposite endian to current event buffer; if added data is not the proper length (i.e. multiple of 4 bytes); if the event number does not correspond to an existing event; if there is an internal programming error; if object closed

References evio::ByteBuffer::order(), evio::ByteBuffer::remaining(), scanBuffer(), and evio::RecordHeader::UNCOMPRESSED_LENGTH_OFFSET.

Referenced by evio::EvioCompactReaderV6::addStructure().

void evio::Reader::close ( )

This closes the file.

Referenced by setBuffer().

void evio::Reader::extractDictionaryAndFirstEvent ( )
protected

Extract dictionary and first event from file/buffer if possible, else do nothing.

References extractDictionaryFromBuffer(), and extractDictionaryFromFile().

Referenced by getDictionary(), getFirstEvent(), and getFirstEventSize().

void evio::Reader::extractDictionaryFromBuffer ( )
protected

Extract dictionary and first event from buffer if possible, else do nothing.

References evio::RecordInput::getEvent(), and evio::RecordInput::readRecord().

Referenced by extractDictionaryAndFirstEvent().

void evio::Reader::findRecordInfo ( std::shared_ptr< ByteBuffer > &  buf,
uint32_t  offset,
uint32_t *  info,
uint32_t  infoLen 
)
staticprotected

Reads data from a record header in order to determine things like the bitInfo word, various lengths, etc.

Does not change the position or limit of buffer.

Parameters
bufbuffer containing evio header.
offsetbyte offset into buffer.
infoarray in which to store header info. Elements are:
  1. bit info word
  2. record length in bytes (inclusive)
  3. compression type
  4. header length in bytes
  5. index array length in bytes
  6. user header length in bytes (no padding included)
  7. uncompressed data length in bytes (no padding, w/o record header)
infoLenlen in 32-bit words of array at info.
Exceptions
underflow_errorif not enough data in buffer.
EvioExceptionnull info arg or info.length < 7.
void evio::Reader::findRecordInfo ( ByteBuffer buf,
uint32_t  offset,
uint32_t *  info,
uint32_t  infoLen 
)
staticprotected

Reads data from a record header in order to determine things like the bitInfo word, various lengths, etc.

Does not change the position or limit of buffer.

Parameters
bufbuffer containing evio header.
offsetbyte offset into buffer.
infoarray in which to store header info. Elements are:
  1. bit info word
  2. record length in bytes (inclusive)
  3. compression type
  4. header length in bytes
  5. index array length in bytes
  6. user header length in bytes (no padding included)
  7. uncompressed data length in bytes (no padding, w/o record header)
infoLenlen in 32-bit words of array at info.
Exceptions
underflow_errorif not enough data in buffer.
EvioExceptionnull info arg or info.length < 7.

References evio::RecordHeader::BIT_INFO_OFFSET, evio::ByteBuffer::capacity(), evio::RecordHeader::COMPRESSION_TYPE_OFFSET, evio::RecordHeader::EVENT_COUNT_OFFSET, evio::ByteBuffer::getInt(), evio::RecordHeader::HEADER_LENGTH_OFFSET, evio::RecordHeader::INDEX_ARRAY_OFFSET, evio::ByteBuffer::limit(), evio::RecordHeader::RECORD_LENGTH_OFFSET, evio::RecordHeader::UNCOMPRESSED_LENGTH_OFFSET, and evio::RecordHeader::USER_LENGTH_OFFSET.

void evio::Reader::forceScanFile ( )
protected

Scan file to find all records and store their position, length, and event count.

Safe to call this method successively.

Exceptions
IOExceptionif error reading file
EvioExceptionif file is not in the proper format or earlier than version 6; if checkRecordNumberSequence is true and records are out of sequence.

References evio::FileEventIndex::addEventSize(), evio::FileEventIndex::clear(), evio::FileHeader::getByteOrder(), evio::RecordHeader::getEntries(), evio::FileHeader::getHeaderLength(), evio::FileHeader::getIndexLength(), evio::RecordHeader::getLength(), evio::RecordHeader::getRecordNumber(), evio::FileHeader::getUserHeaderLength(), evio::FileHeader::getUserHeaderLengthPadding(), evio::FileHeader::getVersion(), evio::RecordHeader::HEADER_SIZE_BYTES, evio::FileHeader::readHeader(), evio::RecordHeader::readHeader(), and evio::Compressor::UNCOMPRESSED.

Referenced by scanFile().

std::shared_ptr< ByteBuffer > evio::Reader::getBuffer ( )

Get the buffer being read, if any.

This may not be the buffer given in the constructor or in setBuffer if the original data was compressed. All data in the returned buffer is uncompressed.

Returns
buffer being read, if any.

Referenced by evio::EvioCompactReaderV6::close(), evio::EvioCompactReaderV6::getByteBuffer(), and evio::EvioCompactReaderV6::toFile().

size_t evio::Reader::getBufferOffset ( ) const

Get the beginning position of the buffer being read.

Returns
the beginning position of the buffer being read.

Referenced by evio::EvioCompactReaderV6::close().

ByteOrder & evio::Reader::getByteOrder ( )

Get the byte order of the file/buffer being read.

Returns
byte order of the file/buffer being read.

Referenced by evio::EvioCompactReaderV6::getByteOrder(), and evio::EvioCompactReaderV6::getFileByteOrder().

bool evio::Reader::getCheckRecordNumberSequence ( ) const

Get whether or not record numbers are enforced to be sequential.

Returns
true
if record numbers are enforced to be sequential.
uint32_t evio::Reader::getCurrentRecord ( ) const

Get the index of the current record.

Returns
index of the current record.
RecordInput & evio::Reader::getCurrentRecordStream ( )

Get the current record stream.

Returns
current record stream.
std::string evio::Reader::getDictionary ( )

Get the XML format dictionary if there is one.

Returns
XML format dictionary, else null.

References extractDictionaryAndFirstEvent().

Referenced by evio::EvioCompactReaderV6::getDictionary(), and evio::EvioCompactReaderV6::getDictionaryXML().

std::shared_ptr< uint8_t > evio::Reader::getEvent ( uint32_t  index,
uint32_t *  len 
)

Get a byte array representing the specified event from the file/buffer.

If index is out of bounds, null is returned.

Parameters
indexindex of specified event within the entire file/buffer, contiguous starting at 0.
lenpointer to int that gets filled with the returned event's len in bytes.
Returns
byte array representing the specified event or null if index is out of bounds.
Exceptions
EvioExceptionif file/buffer not in hipo format

References evio::RecordInput::getEntries(), evio::RecordInput::getEvent(), evio::FileEventIndex::getMaxEvents(), evio::FileEventIndex::getRecordEventNumber(), evio::FileEventIndex::getRecordNumber(), readRecord(), and evio::FileEventIndex::setEvent().

Referenced by getEvent(), getNextEvent(), and getPrevEvent().

ByteBuffer & evio::Reader::getEvent ( ByteBuffer buf,
uint32_t  index 
)

Get a byte array representing the specified event from the file/buffer and place it in the given buf.

If no buf is given (arg is null), create a buffer internally and return it. If index is out of bounds, null is returned.

Parameters
bufbuffer in which to place event data.
indexindex of specified event within the entire file/buffer, contiguous starting at 0.
Returns
buf.
Exceptions
EvioExceptionif file/buffer not in hipo format, if buf has insufficient space to contain event (buf.capacity() < event size), or index too large.

References evio::RecordInput::getEntries(), evio::RecordInput::getEvent(), evio::FileEventIndex::getMaxEvents(), evio::FileEventIndex::getRecordEventNumber(), evio::FileEventIndex::getRecordNumber(), readRecord(), and evio::FileEventIndex::setEvent().

std::shared_ptr< ByteBuffer > evio::Reader::getEvent ( std::shared_ptr< ByteBuffer > &  buf,
uint32_t  index 
)

Get a byte array representing the specified event from the file/buffer and place it in the given buf.

If no buf is given (arg is null), create a buffer internally and return it. If index is out of bounds, null is returned.

Parameters
bufbuffer in which to place event data.
indexindex of specified event within the entire file/buffer, contiguous starting at 0.
Returns
buf or null if buf is null.
Exceptions
EvioExceptionif file/buffer not in hipo format, if buf has insufficient space to contain event (buf.capacity() < event size), or index too large.

References getEvent().

uint32_t evio::Reader::getEventCount ( ) const

Get the number of events in file/buffer.

Returns
number of events in file/buffer.

References evio::FileEventIndex::getMaxEvents().

Referenced by evio::EvioCompactReaderV6::getEventCount(), and evio::EvioCompactReaderV6::searchEvent().

uint32_t evio::Reader::getEventLength ( uint32_t  index)

Returns the length of the event with given index.

Parameters
indexindex of the event
Returns
length of the data in bytes or zero if index does not correspond to a valid event.

References evio::RecordInput::getEntries(), evio::RecordInput::getEventLength(), evio::FileEventIndex::getMaxEvents(), evio::FileEventIndex::getRecordEventNumber(), evio::FileEventIndex::getRecordNumber(), readRecord(), and evio::FileEventIndex::setEvent().

std::shared_ptr< EvioNode > evio::Reader::getEventNode ( uint32_t  index)

Get an EvioNode representing the specified event from the buffer.

If index is out of bounds, nullptr is returned.

Parameters
indexindex of specified event within the entire buffer, starting at 0.
Returns
EvioNode representing the specified event or null if index is out of bounds, reading a file or data is compressed.
Exceptions
EvioExceptionindex too large or reading from file.

References evio::FileEventIndex::getMaxEvents().

Referenced by evio::EvioCompactReaderV6::getEvent(), evio::EvioCompactReaderV6::getEventBuffer(), and evio::EvioCompactReaderV6::removeEvent().

std::vector< std::shared_ptr< EvioNode > > & evio::Reader::getEventNodes ( )

Get a reference to the list of EvioNode objects contained in the buffer being read.

To be used internally to evio.

Returns
list of EvioNode objects contained in the buffer being read.
FileHeader & evio::Reader::getFileHeader ( )

Get the file header from reading a file.

Returns
file header from reading a file.
std::string evio::Reader::getFileName ( ) const

Get the name of the file being read.

Returns
name of the file being read or null if none.
size_t evio::Reader::getFileSize ( ) const

Get the size of the file being read, in bytes.

Returns
size of the file being read, in bytes, or 0 if none.

Referenced by evio::EvioCompactReaderV6::fileSize().

std::shared_ptr< uint8_t > & evio::Reader::getFirstEvent ( uint32_t *  size)

Get a byte array representing the first event.

Parameters
sizepointer filled with the size, in bytes, of the first event (0 if none). If null, this is ignored.
Returns
byte array representing the first event. Null if none.

References extractDictionaryAndFirstEvent().

uint32_t evio::Reader::getFirstEventSize ( )

Get size, in bytes, of byte array representing the first event.

Returns
size, in bytes, of byte array representing the first event. 0 if none.

References extractDictionaryAndFirstEvent().

std::shared_ptr< RecordHeader > & evio::Reader::getFirstRecordHeader ( )

Get the first record header from reading a file/buffer.

Returns
first record header from reading a file/buffer.

Referenced by evio::EvioCompactReaderV6::getFirstBlockHeader().

std::shared_ptr< uint8_t > evio::Reader::getNextEvent ( uint32_t *  len)

Get a byte array representing the next event from the file/buffer while sequentially reading.

If the previous call was to getPrevEvent, this will get the event past what that returned. Once the last event is returned, this will return null.

Parameters
lenpointer to int that gets filled with the returned event's len in bytes.
Returns
byte array representing the next event or null if there is none.
Exceptions
EvioExceptionif file/buffer not in hipo format

References getEvent().

std::shared_ptr< EvioNode > evio::Reader::getNextEventNode ( )

Get an EvioNode representing the next event from the buffer while sequentially reading.

Calling this and calling getNextEvent() have the same effect in terms of advancing the same internal counter. If the previous call was to getPrevEvent, this will get the event past what that returned. Once the last event is returned, this will return null.

Returns
EvioNode representing the next event or null if no more events, reading a file or data is compressed.

References evio::FileEventIndex::getMaxEvents().

uint32_t evio::Reader::getNumEventsRemaining ( ) const

Get the number of events remaining in the file/buffer.

Useful only if doing a sequential read.

Returns
number of events remaining in the file/buffer

References evio::FileEventIndex::getMaxEvents().

std::shared_ptr< uint8_t > evio::Reader::getPrevEvent ( uint32_t *  len)

Get a byte array representing the previous event from the sequential queue.

If the previous call was to getNextEvent, this will get the event previous to what that returned. If this is called before getNextEvent, it will always return null. Once the first event is returned, this will return null.

Parameters
lenpointer to int that gets filled with the returned event's len in bytes.
Returns
byte array representing the previous event or null if there is none.
Exceptions
EvioExceptionif the file/buffer is not in HIPO format

References getEvent().

uint32_t evio::Reader::getRecordCount ( ) const

Get the number of records read from the file/buffer.

Returns
number of records read from the file/buffer.

Referenced by evio::EvioCompactReaderV6::getBlockCount().

uint32_t evio::Reader::getRecordEventCount ( ) const

Get the number of events in current record.

Returns
number of events in current record.

References evio::RecordInput::getEntries().

std::vector< Reader::RecordPosition > & evio::Reader::getRecordPositions ( )

Returns a reference to the list of record positions in the file.

Returns
uint32_t evio::Reader::getVersion ( ) const

Get the Evio format version number of the file/buffer being read.

Returns
Evio format version number of the file/buffer being read.

Referenced by evio::EvioCompactReaderV6::getEvioVersion().

bool evio::Reader::hasDictionary ( ) const

Does this evio file/buffer have an associated XML dictionary?

Returns
true if this evio file/buffer has an associated XML dictionary, else false.

References evio::FileHeader::hasDictionary().

Referenced by evio::EvioCompactReaderV6::hasDictionary().

bool evio::Reader::hasFirstEvent ( ) const

Does this evio file/buffer have an associated first event?

Returns
true if this evio file/buffer has an associated first event, else false.

References evio::FileHeader::hasFirstEvent().

bool evio::Reader::hasNext ( ) const

Checks if the file has an event to read next.

Returns
true if the next event is available, false otherwise

References evio::FileEventIndex::canAdvance().

bool evio::Reader::hasPrev ( ) const

Checks if the stream has previous event to be accessed through, getPrevEvent()

Returns
true if previous event is accessible, false otherwise

References evio::FileEventIndex::canRetreat().

bool evio::Reader::isClosed ( ) const

Has close() been called (without reopening by calling setBuffer(std::shared_ptr<ByteBuffer> &))?

Returns
true
if this object closed, else
false
.
bool evio::Reader::isCompressed ( ) const

Is the data in the file/buffer compressed?

Returns
true if data is compressed.

Referenced by evio::EvioCompactReaderV6::isCompressed().

bool evio::Reader::isEvioFormat ( ) const

Does this file/buffer contain non-evio format events?

Returns
true if all events are in evio format, else false.

Referenced by evio::EvioCompactReaderV6::EvioCompactReaderV6(), and evio::EvioCompactReaderV6::setBuffer().

bool evio::Reader::isFile ( ) const

Is a file being read?

Returns
true
if a file is being read,
false
if it's a buffer.

Referenced by evio::EvioCompactReaderV6::isFile().

void evio::Reader::open ( std::string const &  filename,
bool  scan = true 
)

Opens an input stream in binary mode.

Scans for records in the file and stores record information in internal array. Each record can be read from the file.

Parameters
filenameinput file name
scanif true, call scanFile(false).
Exceptions
EvioExceptionif error handling file

References scanFile().

Referenced by evio::EvioCompactReaderV6::EvioCompactReaderV6(), and Reader().

bool evio::Reader::readRecord ( uint32_t  index)

Reads record from the file/buffer at the given record index.

Parameters
indexrecord index (starting at 0).
Returns
true if valid index and successful reading record, else false.
Exceptions
EvioExceptionif file/buffer not in hipo format

References evio::RecordInput::readRecord().

Referenced by getEvent(), and getEventLength().

std::shared_ptr< ByteBuffer > evio::Reader::readUserHeader ( )

Reads user header of the file header/first record header of buffer.

The returned ByteBuffer also contains endianness of the file/buffer.

Returns
ByteBuffer containing the user header of the file/buffer.
Exceptions
IOExceptionif error reading file

References evio::FileHeader::getByteOrder(), evio::FileHeader::getHeaderLength(), evio::FileHeader::getIndexLength(), and evio::FileHeader::getUserHeaderLength().

std::shared_ptr< ByteBuffer > & evio::Reader::removeStructure ( std::shared_ptr< EvioNode > &  removeNode)
protected

This method removes the data, represented by the given node, from the buffer.

It also marks all nodes taken from that buffer as obsolete. They must not be used anymore.

Parameters
removeNodeevio structure to remove from buffer
Returns
ByteBuffer updated to reflect the node removal
Exceptions
EvioExceptionif object closed; if node was not found in any event; if internal programming error; if buffer has compressed data;

References evio::ByteBuffer::limit(), scanBuffer(), evio::Compressor::UNCOMPRESSED, and evio::RecordHeader::UNCOMPRESSED_LENGTH_OFFSET.

Referenced by evio::EvioCompactReaderV6::removeStructure().

std::shared_ptr< ByteBuffer > evio::Reader::scanBuffer ( )
protected

This method scans a buffer to find all records and store their position, length, and event count.

It also finds all events and creates & stores their associated EvioNode objects. The difficulty with doing this is that the buffer may contain compressed data. It must then be uncompressed into a different buffer.

Returns
buffer containing uncompressed data. This buffer is different than the internal buffer. Ready to read.
Exceptions
EvioExceptionif buffer not in the proper format or earlier than version 6; if checkRecordNumberSequence is true and records are out of sequence.
underflow_errorif not enough data in buffer.

References evio::FileEventIndex::addEventSize(), evio::ByteBuffer::array(), evio::ByteBuffer::arrayOffset(), evio::FileEventIndex::clear(), evio::HeaderType::EVIO_RECORD, evio::EvioNode::extractEventNode(), evio::RecordHeader::getByteOrder(), evio::RecordHeader::getEntries(), evio::RecordHeader::getHeaderLength(), evio::RecordHeader::getLength(), evio::RecordHeader::getRecordNumber(), evio::RecordHeader::getUncompressedRecordLength(), evio::RecordHeader::getVersion(), evio::RecordHeader::HEADER_SIZE_BYTES, evio::RecordHeader::isCompressed(), evio::RecordHeader::isLastRecord(), evio::ByteBuffer::order(), evio::ByteBuffer::position(), scanUncompressedBuffer(), and evio::RecordInput::uncompressRecord().

Referenced by addStructure(), Reader(), removeStructure(), and setBuffer().

void evio::Reader::scanFile ( bool  force)
protected
void evio::Reader::scanUncompressedBuffer ( )
protected

Scan buffer containing uncompressed data to find all records and store their position, length, and event count.

Also finds all events and creates & stores their associated EvioNode objects.

Exceptions
EvioExceptionif buffer too small, not in the proper format, or earlier than version 6; if checkRecordNumberSequence is true and records are out of sequence.

References evio::FileEventIndex::addEventSize(), evio::ByteBuffer::array(), evio::FileEventIndex::clear(), evio::EvioNode::extractEventNode(), evio::RecordHeader::getByteOrder(), evio::RecordHeader::getCompressionType(), evio::RecordHeader::getEntries(), evio::RecordHeader::getHeaderLength(), evio::RecordHeader::getIndexLength(), evio::RecordHeader::getLength(), evio::RecordHeader::getRecordNumber(), evio::RecordHeader::getUserHeaderLengthWords(), evio::RecordHeader::getVersion(), evio::RecordHeader::HEADER_SIZE_BYTES, evio::RecordHeader::readHeader(), and evio::Compressor::UNCOMPRESSED.

Referenced by scanBuffer().

void evio::Reader::setBuffer ( std::shared_ptr< ByteBuffer > &  buf)

This method can be used to avoid creating additional Reader objects by reusing this one with another buffer.

If the given buffer contains compressed data, it is uncompressed into another buffer. The buffer containing the newly uncompressed data then becomes the internal buffer of this object. It can be obtained by calling getBuffer.

Parameters
bufByteBuffer to be read
Exceptions
underflow_errorif not enough data in buffer.
EvioExceptionif buf arg is null, not in the proper format, or earlier than version 6

References evio::FileEventIndex::clear(), close(), and scanBuffer().

Referenced by evio::EvioCompactReaderV6::EvioCompactReaderV6(), and evio::EvioCompactReaderV6::setBuffer().

void evio::Reader::show ( ) const
protected

Print out all record position information.

Friends And Related Function Documentation

friend class EvioCompactReaderV6
friend

The documentation for this class was generated from the following files: