public class EvioReaderV4 extends java.lang.Object implements IEvioReader
EvioReader
object corresponding to an event
file or file-formatted buffer, and from this class you can test it
for consistency and, more importantly, you can call parseNextEvent()
or
parseEvent(int)
to get new events and to stream the embedded structures
to an IEvioListener.A word to the wise, constructors for reading a file in random access mode (by setting "sequential" arg to false), will memory map the file. This is not a good idea if the file is not on a local disk. Due to java restrictions, files over 2.1GB will require multiple memory maps.
The streaming effect of parsing an event is that the parser will read the event and hand off structures, such as banks, to any IEvioListeners. For those familiar with XML, the event is processed SAX-like. It is up to the listener to decide what to do with the structures.
As an alternative to stream processing, after an event is parsed, the user can use the events treeModel for access to the structures. For those familiar with XML, the event is processed DOM-like.
Constructor and Description |
---|
EvioReaderV4(java.nio.ByteBuffer byteBuffer)
Constructor for reading a buffer.
|
EvioReaderV4(java.nio.ByteBuffer byteBuffer,
boolean checkBlkNumSeq)
Constructor for reading a buffer.
|
EvioReaderV4(java.io.File file)
Constructor for reading an event file.
|
EvioReaderV4(java.io.File file,
boolean checkBlkNumSeq)
Constructor for reading an event file.
|
EvioReaderV4(java.io.File file,
boolean checkBlkNumSeq,
boolean sequential)
Constructor for reading an event file.
|
EvioReaderV4(java.lang.String path)
Constructor for reading an event file.
|
EvioReaderV4(java.lang.String path,
boolean checkBlkNumSeq)
Constructor for reading an event file.
|
EvioReaderV4(java.lang.String path,
boolean checkBlkNumSeq,
boolean sequential)
Constructor for reading an event file.
|
Modifier and Type | Method and Description |
---|---|
boolean |
checkBlockNumberSequence()
Is this reader checking the block number sequence and
throwing an exception is it's not sequential and starting with 1?
|
void |
close()
This is closes the file, but for buffers it only sets the position to 0.
|
long |
fileSize()
Get the size of the file being read, in bytes.
|
int |
getBlockCount()
This is the number of blocks in the file including the empty
block usually at the end of version 4 files/buffers.
|
java.nio.ByteBuffer |
getByteBuffer()
Get the byte buffer being read directly or corresponding to the event file.
|
java.nio.ByteOrder |
getByteOrder()
Get the byte order of the file/buffer being read.
|
IBlockHeader |
getCurrentBlockHeader()
This returns the current (active) block (physical record) header.
|
java.lang.String |
getDictionaryXML()
Get the XML format dictionary if there is one.
|
EvioEvent |
getEvent(int index)
Get the event in the file/buffer at a given index (starting at 1).
|
byte[] |
getEventArray(int eventNumber)
Get an evio bank or event in byte array form.
|
java.nio.ByteBuffer |
getEventBuffer(int eventNumber)
Get an evio bank or event in ByteBuffer form.
|
int |
getEventCount()
This is the number of events in the file.
|
int |
getEvioVersion()
Get the evio version number.
|
IBlockHeader |
getFirstBlockHeader()
This returns the FIRST block (physical record) header.
|
EvioEvent |
getFirstEvent()
Get the "first" event if there is one.
|
int |
getNumEventsRemaining()
Get the number of events remaining in the file.
|
EventParser |
getParser()
Get the file/buffer parser.
|
java.lang.String |
getPath()
Get the path to the file.
|
EvioEvent |
gotoEventNumber(int evNumber)
Go to a specific event in the file.
|
boolean |
hasDictionaryXML()
Does this evio file have an associated XML dictionary?
|
boolean |
hasFirstEvent()
Does this evio file have an associated first event?
It's also called the Beginning-Of-Run event.
|
boolean |
isClosed()
Has
close() been called (without reopening by calling
setBuffer(ByteBuffer) )? |
EvioEvent |
nextEvent()
Get the next event in the file/buffer.
|
void |
parseEvent(EvioEvent evioEvent)
This will parse an event, SAX-like.
|
EvioEvent |
parseEvent(int index)
This is a workhorse method.
|
protected void |
parseFirstHeader(java.nio.ByteBuffer headerBuf)
Reads 8 words of the first block (physical record) header in order to determine
the evio version # and endianness of the file or buffer in question.
|
EvioEvent |
parseNextEvent()
This is a workhorse method.
|
long |
position()
This is equivalent to obtaining the current position in the file.
|
protected ReadStatus |
processNextBlock()
Reads the block (physical record) header.
|
void |
rewind()
The equivalent of rewinding the file.
|
void |
setBuffer(java.nio.ByteBuffer buf)
This method can be used to avoid creating additional EvioReader
objects by reusing this one with another buffer.
|
void |
setParser(EventParser parser)
Set the file/buffer parser.
|
WriteStatus |
toXMLFile(java.lang.String path)
Rewrite the file to XML (not including dictionary).
|
WriteStatus |
toXMLFile(java.lang.String path,
boolean hex)
Rewrite the file to XML (not including dictionary).
|
WriteStatus |
toXMLFile(java.lang.String path,
IEvioProgressListener progressListener)
Rewrite the file to XML (not including dictionary).
|
WriteStatus |
toXMLFile(java.lang.String path,
IEvioProgressListener progressListener,
boolean hex)
Rewrite the file to XML (not including dictionary).
|
public EvioReaderV4(java.lang.String path) throws EvioException, java.io.IOException
path
- the full path to the file that contains events.
For writing event files, use an EventWriter
object.java.io.IOException
- if read failureEvioException
- if file arg is nullEventWriter
public EvioReaderV4(java.lang.String path, boolean checkBlkNumSeq) throws EvioException, java.io.IOException
path
- the full path to the file that contains events.
For writing event files, use an EventWriter
object.checkBlkNumSeq
- if true
check the block number sequence
and throw an exception if it is not sequential starting
with 1java.io.IOException
- if read failureEvioException
- if file arg is null;
if first block number != 1 when checkBlkNumSeq arg is trueEventWriter
public EvioReaderV4(java.io.File file) throws EvioException, java.io.IOException
file
- the file that contains events.java.io.IOException
- if read failureEvioException
- if file arg is nullEventWriter
public EvioReaderV4(java.io.File file, boolean checkBlkNumSeq) throws EvioException, java.io.IOException
file
- the file that contains events.checkBlkNumSeq
- if true
check the block number sequence
and throw an exception if it is not sequential starting
with 1java.io.IOException
- if read failureEvioException
- if file arg is null;
if first block number != 1 when checkBlkNumSeq arg is trueEventWriter
public EvioReaderV4(java.lang.String path, boolean checkBlkNumSeq, boolean sequential) throws EvioException, java.io.IOException
path
- the full path to the file that contains events.
For writing event files, use an EventWriter
object.checkBlkNumSeq
- if true
check the block number sequence
and throw an exception if it is not sequential starting
with 1sequential
- if true
read the file sequentially,
else use memory mapped buffers. If file > 2.1 GB,
reads are always sequential for the older evio format.java.io.IOException
- if read failureEvioException
- if file arg is null;
if first block number != 1 when checkBlkNumSeq arg is trueEventWriter
public EvioReaderV4(java.io.File file, boolean checkBlkNumSeq, boolean sequential) throws EvioException, java.io.IOException
file
- the file that contains events.checkBlkNumSeq
- if true
check the block number sequence
and throw an exception if it is not sequential starting
with 1sequential
- if true
read the file sequentially,
else use memory mapped buffers. If file > 2.1 GB,
reads are always sequential for the older evio format.java.io.IOException
- if read failureEvioException
- if file arg is null;
if file is too small to have valid evio format data
if first block number != 1 when checkBlkNumSeq arg is trueEventWriter
public EvioReaderV4(java.nio.ByteBuffer byteBuffer) throws EvioException
byteBuffer
- the buffer that contains events.EvioException
- if buffer arg is nullEventWriter
public EvioReaderV4(java.nio.ByteBuffer byteBuffer, boolean checkBlkNumSeq) throws EvioException
byteBuffer
- the buffer that contains events.checkBlkNumSeq
- if true
check the block number sequence
and throw an exception if it is not sequential starting
with 1EvioException
- if buffer arg is null;
if first block number != 1 when checkBlkNumSeq arg is trueEventWriter
public void setBuffer(java.nio.ByteBuffer buf) throws EvioException, java.io.IOException
close()
is called before anything else.setBuffer
in interface IEvioReader
buf
- ByteBuffer to be readjava.io.IOException
- if read failureEvioException
- if buf is null;
if first block number != 1 when checkBlkNumSeq arg is truepublic boolean isClosed()
close()
been called (without reopening by calling
setBuffer(ByteBuffer)
)?isClosed
in interface IEvioReader
true
if this object closed, else false
.public boolean checkBlockNumberSequence()
checkBlockNumberSequence
in interface IEvioReader
true
if checking block number sequence, else false
public java.nio.ByteOrder getByteOrder()
getByteOrder
in interface IEvioReader
public int getEvioVersion()
getEvioVersion
in interface IEvioReader
public java.lang.String getPath()
getPath
in interface IEvioReader
public EventParser getParser()
getParser
in interface IEvioReader
public void setParser(EventParser parser)
setParser
in interface IEvioReader
parser
- file/buffer parser.public java.lang.String getDictionaryXML()
getDictionaryXML
in interface IEvioReader
public boolean hasDictionaryXML()
hasDictionaryXML
in interface IEvioReader
true
if this evio file has an associated XML dictionary,
else false
public EvioEvent getFirstEvent()
getFirstEvent
in interface IEvioReader
public boolean hasFirstEvent()
hasFirstEvent
in interface IEvioReader
true
if this evio file has an associated first event,
else false
public int getNumEventsRemaining() throws java.io.IOException, EvioException
getNumEventsRemaining
in interface IEvioReader
java.io.IOException
- if failed file accessEvioException
- if failed reading from coda v3 filepublic java.nio.ByteBuffer getByteBuffer()
getByteBuffer
in interface IEvioReader
public long fileSize()
fileSize
in interface IEvioReader
public IBlockHeader getFirstBlockHeader()
getFirstBlockHeader
in interface IEvioReader
protected void parseFirstHeader(java.nio.ByteBuffer headerBuf) throws EvioException
headerBuf
- buffer to parse header from.EvioException
- if buffer too small, contains invalid data,
or bad block # sequenceprotected ReadStatus processNextBlock() throws java.io.IOException
A Bank header is 8, 32-bit ints. The first int is the size of the block in ints (not counting the length itself, i.e., the number of ints to follow). Most users should have no need for this method, since most applications do not care about the block (physical record) header.
java.io.IOException
- if file access problems, evio format problemspublic EvioEvent getEvent(int index) throws java.io.IOException, EvioException
parseNextEvent()
or parseEvent(int)
instead,
since it combines combines getting an event with parsing it.getEvent
in interface IEvioReader
index
- the event number in a 1,2,..N counting sense, from beginning of file/buffer.java.io.IOException
- if failed file accessEvioException
- if failed read due to bad file/buffer format;
if out of memory;
if index < 1;
if object closedpublic EvioEvent parseEvent(int index) throws java.io.IOException, EvioException
parseEvent
in interface IEvioReader
index
- number of event desired, starting at 1, from beginning of file/bufferjava.io.IOException
- if failed file accessEvioException
- if failed read due to bad file/buffer format;
if out of memory;
if index < 1;
if object closedpublic EvioEvent nextEvent() throws java.io.IOException, EvioException
parseNextEvent()
instead, since
it combines getting the next event with parsing the next event.Although this method can get events in versions 4+, it now delegates that to another method. No changes were made to this method from versions 1-3 in order to read the version 4 format as it is subset of versions 1-3 with variable block length.
nextEvent
in interface IEvioReader
null
.java.io.IOException
- if failed file accessEvioException
- if failed read due to bad buffer format;
if object closedpublic EvioEvent parseNextEvent() throws java.io.IOException, EvioException
parseNextEvent
in interface IEvioReader
null
.java.io.IOException
- if failed file accessEvioException
- if read failure or bad format
if object closedpublic void parseEvent(EvioEvent evioEvent) throws EvioException
As useful as this sounds, most applications will probably call parseNextEvent()
instead, since it combines combines getting the next event with parsing the next event.
This method is only called by synchronized methods and therefore is not synchronized.
parseEvent
in interface IEvioReader
evioEvent
- the event to parse.EvioException
- if bad formatpublic byte[] getEventArray(int eventNumber) throws EvioException, java.io.IOException
getEventArray
in interface IEvioReader
eventNumber
- number of event of interestjava.io.IOException
- if failed file accessEvioException
- if eventNumber < 1;
if the event number does not correspond to an existing event;
if object closedpublic java.nio.ByteBuffer getEventBuffer(int eventNumber) throws EvioException, java.io.IOException
getEventBuffer
in interface IEvioReader
eventNumber
- number of event of interestjava.io.IOException
- if failed file accessEvioException
- if eventNumber < 1;
if the event number does not correspond to an existing event;
if object closedpublic void rewind() throws java.io.IOException, EvioException
position()
and the
close()
method, allows applications to treat files
in a normal random access manner.rewind
in interface IEvioReader
java.io.IOException
- if failed file access or buffer/file readEvioException
- if object closedpublic long position() throws java.io.IOException, EvioException
rewind()
, position(int)
and the close()
method, allows applications to treat files
in a normal random access manner. Only meaningful to evio versions 1-3
and for sequential reading.position
in interface IEvioReader
java.io.IOException
- if error accessing fileEvioException
- if object closedpublic void close() throws java.io.IOException
rewind()
and the two
position()
methods, allows applications to treat files
in a normal random access manner.close
in interface IEvioReader
java.io.IOException
- if error accessing filepublic IBlockHeader getCurrentBlockHeader()
EvioReaderTest
class.getCurrentBlockHeader
in interface IEvioReader
public EvioEvent gotoEventNumber(int evNumber) throws java.io.IOException, EvioException
getEvent(int)
.gotoEventNumber
in interface IEvioReader
evNumber
- the event number in a 1..N counting sense, from the start of the file.java.io.IOException
- if failed file accessEvioException
- if object closedpublic WriteStatus toXMLFile(java.lang.String path) throws java.io.IOException, EvioException
toXMLFile
in interface IEvioReader
path
- the path to the XML file.java.io.IOException
- if failed file accessEvioException
- if object closedpublic WriteStatus toXMLFile(java.lang.String path, boolean hex) throws java.io.IOException, EvioException
toXMLFile
in interface IEvioReader
path
- the path to the XML file.hex
- if true, ints get displayed in hexadecimaljava.io.IOException
- if failed file accessEvioException
- if object closedpublic WriteStatus toXMLFile(java.lang.String path, IEvioProgressListener progressListener) throws java.io.IOException, EvioException
toXMLFile
in interface IEvioReader
path
- the path to the XML file.progressListener
- and optional progress listener, can be null
.java.io.IOException
- if failed file accessEvioException
- if object closedIEvioProgressListener
public WriteStatus toXMLFile(java.lang.String path, IEvioProgressListener progressListener, boolean hex) throws java.io.IOException, EvioException
toXMLFile
in interface IEvioReader
path
- the path to the XML file.progressListener
- and optional progress listener, can be null
.hex
- if true, ints get displayed in hexadecimaljava.io.IOException
- if failed file accessEvioException
- if object closedIEvioProgressListener
public int getEventCount() throws java.io.IOException, EvioException
getEventCount
in interface IEvioReader
java.io.IOException
- if failed file accessEvioException
- if read failure;
if object closedpublic int getBlockCount() throws EvioException
getBlockCount
in interface IEvioReader
EvioException
- if object closed