|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jlab.coda.jevio.EvioReader
public class EvioReader
This is a class of interest to the user. It is used to read an evio version 4 or earlier
format file or buffer. Create an EvioReader
from a File
object corresponding to an event file, and from this class you can test the file
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. The same can be done by creating an EvioReader
from a ByteBuffer
.
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.
NOTE: Even though this class has a constructor that accepts an i/o mode, that is for backwards
compatibility only. An EvioReader
is used for reading and parsing events only.
To write an event file or buffer, use an EventWriter
object.
Nested Class Summary | |
---|---|
static class |
EvioReader.ReadStatus
This enum denotes the status of a read. |
static class |
EvioReader.WriteStatus
This enum denotes the status of a write.SUCCESS indicates a successful write. |
Constructor Summary | |
---|---|
EvioReader(java.nio.ByteBuffer byteBuffer)
Constructor for reading a buffer. |
|
EvioReader(java.nio.ByteBuffer byteBuffer,
boolean checkBlkNumSeq)
Constructor for reading a buffer. |
|
EvioReader(java.io.File file)
Constructor for reading an event file. |
|
EvioReader(java.io.File file,
boolean checkBlkNumSeq)
Constructor for reading an event file. |
|
EvioReader(java.lang.String path)
Constructor for reading an event file. |
|
EvioReader(java.lang.String path,
boolean checkBlkNumSeq)
Constructor for reading an event file. |
Method Summary | |
---|---|
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 equivalent to closing the file. |
static boolean |
compareEventFiles(java.io.File evFile1,
java.io.File evFile2)
Method used for diagnostics. |
int |
fileSize()
Obtain the file size using the memory mapped buffer's capacity, which should be the same. |
java.nio.ByteBuffer |
getByteBuffer()
Get the byte buffer being read directly or corresponding to the event file. |
IBlockHeader |
getCurrentBlockHeader()
This returns the current (active) block (physical record) header. |
java.lang.String |
getDictionaryXML()
Get the XML format dictionary is there is one. |
EvioEvent |
getEvent(int index)
Get the event in the file/buffer at a given index (starting at 1). |
int |
getEventCount()
This is the number of events in the file. |
int |
getEvioVersion()
Get the evio version number. |
java.nio.MappedByteBuffer |
getMappedByteBuffer()
Get the memory mapped buffer corresponding to the event file. |
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? |
EvioEvent |
nextEvent()
Get the next event in the file. |
void |
parseEvent(EvioEvent evioEvent)
This will parse an event, SAX-like. |
EvioEvent |
parseEvent(int index)
This is the workhorse method. |
EvioEvent |
parseNextEvent()
This is the workhorse method. |
int |
position()
This is equivalent to obtaining the current position in the file. |
void |
position(int position)
This is equivalent to setting the current position in the file. |
void |
rewind()
The equivalent of rewinding the file. |
void |
setParser(EventParser parser)
Set the file/buffer parser. |
EvioReader.WriteStatus |
toXMLFile(java.lang.String path)
Rewrite the file to XML (not including dictionary). |
EvioReader.WriteStatus |
toXMLFile(java.lang.String path,
IEvioProgressListener progressListener)
Rewrite the file to XML (not including dictionary). |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public EvioReader(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 failure
EvioException
- if file arg is nullEventWriter
public EvioReader(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 1
java.io.IOException
- if read failure
EvioException
- if file arg is null;
if first block number != 1 when checkBlkNumSeq arg is trueEventWriter
public EvioReader(java.io.File file) throws EvioException, java.io.IOException
file
- the file that contains events.
java.io.IOException
- if read failure
EvioException
- if file arg is nullEventWriter
public EvioReader(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 1
java.io.IOException
- if read failure
EvioException
- if file arg is null;
if first block number != 1 when checkBlkNumSeq arg is trueEventWriter
public EvioReader(java.nio.ByteBuffer byteBuffer) throws EvioException, java.io.IOException
byteBuffer
- the buffer that contains events.
java.io.IOException
- if read failure
EvioException
- if file arg is nullEventWriter
public EvioReader(java.nio.ByteBuffer byteBuffer, boolean checkBlkNumSeq) throws EvioException, java.io.IOException
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 1
java.io.IOException
- if read failure
EvioException
- if file arg is null;
if first block number != 1 when checkBlkNumSeq arg is trueEventWriter
Method Detail |
---|
public boolean checkBlockNumberSequence()
true
if checking block number sequence, else false
public int getEvioVersion()
public java.lang.String getPath()
public EventParser getParser()
public void setParser(EventParser parser)
parser
- file/buffer parser.public java.lang.String getDictionaryXML()
public boolean hasDictionaryXML()
true
if this evio file has an associated XML dictionary,
else false
public int getNumEventsRemaining() throws EvioException
EvioException
- if failed reading from coda v3 filepublic int fileSize()
public java.nio.MappedByteBuffer getMappedByteBuffer()
public java.nio.ByteBuffer getByteBuffer()
public EvioEvent getEvent(int index) throws EvioException
parseEvent(int)
instead, since it combines combines
getting the event with parsing it.
index
- number of event desired, starting at 1, from beginning of file/buffer
EvioException
- if failed read due to bad file/buffer format;
if out of memory; if index < 1public EvioEvent parseEvent(int index) throws EvioException
index
- number of event desired, starting at 1, from beginning of file/buffer
EvioException
- if failed read due to bad file/buffer format;
if out of memory; if index < 1public EvioEvent nextEvent() throws EvioException
parseNextEvent()
instead, since it combines combines getting the next
event with parsing the next event.In evio version 4, events no longer cross block boundaries. There are only one or more complete events in each block. 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.
null
.
EvioException
- if failed read due to bad buffer formatpublic EvioEvent parseNextEvent() throws EvioException
null
.
EvioException
- if read failure or bad formatpublic void parseEvent(EvioEvent evioEvent) throws EvioException
parseNextEvent()
instead,
since it combines combines getting the next event with parsing the next event .
evioEvent
- the event to parse.
EvioException
- if bad formatpublic void rewind()
position()
and the close()
method, allows applications to treat files in a normal random
access manner.
public int position()
rewind()
, position(int)
and the close()
method, allows applications to treat files
in a normal random access manner.
public void position(int position)
rewind()
, position()
and the close()
method, allows applications to treat files
in a normal random access manner.
position
- the new position of the buffer.public void close()
rewind()
and the two
position()
methods, allows applications to treat files
in a normal random access manner.
public IBlockHeader getCurrentBlockHeader()
EvioReaderTest
class.
public EvioEvent gotoEventNumber(int evNumber)
getEvent(int)
.
evNumber
- the event number in a 1..N counting sense, from the start of the file.
public EvioReader.WriteStatus toXMLFile(java.lang.String path)
path
- the path to the XML file.
public EvioReader.WriteStatus toXMLFile(java.lang.String path, IEvioProgressListener progressListener)
path
- the path to the XML file.progressListener
- and optional progress listener, can be null
.
IEvioProgressListener
public int getEventCount() throws EvioException
EvioException
- if read failurepublic static boolean compareEventFiles(java.io.File evFile1, java.io.File evFile2)
evFile1
- first file to be comparedevFile2
- second file to be compared
true
if the files are, byte-by-byte, identical.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |