public class EventWriterUnsync
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
EventWriterUnsync.IOStatus
This
enum denotes the status of a read. |
Constructor and Description |
---|
EventWriterUnsync(java.nio.ByteBuffer buf)
Create an
EventWriterUnsync for writing events to a ByteBuffer. |
EventWriterUnsync(java.nio.ByteBuffer buf,
boolean append)
Create an
EventWriterUnsync for writing events to a ByteBuffer. |
EventWriterUnsync(java.nio.ByteBuffer buf,
int blockSizeMax,
int blockCountMax,
java.lang.String xmlDictionary,
java.util.BitSet bitInfo)
Create an
EventWriterUnsync for writing events to a ByteBuffer. |
EventWriterUnsync(java.nio.ByteBuffer buf,
int blockSizeMax,
int blockCountMax,
java.lang.String xmlDictionary,
java.util.BitSet bitInfo,
boolean append)
Create an
EventWriterUnsync for writing events to a ByteBuffer. |
EventWriterUnsync(java.nio.ByteBuffer buf,
int blockSizeMax,
int blockCountMax,
java.lang.String xmlDictionary,
java.util.BitSet bitInfo,
int reserved1,
boolean append)
Create an
EventWriterUnsync for writing events to a ByteBuffer. |
EventWriterUnsync(java.nio.ByteBuffer buf,
int blockSizeMax,
int blockCountMax,
java.lang.String xmlDictionary,
java.util.BitSet bitInfo,
int reserved1,
int blockNumber)
Create an
EventWriterUnsync for writing events to a ByteBuffer. |
EventWriterUnsync(java.nio.ByteBuffer buf,
int blockSizeMax,
int blockCountMax,
java.lang.String xmlDictionary,
java.util.BitSet bitInfo,
int reserved1,
int blockNumber,
boolean append,
EvioBank firstEvent)
Create an
EventWriterUnsync for writing events to a ByteBuffer. |
EventWriterUnsync(java.nio.ByteBuffer buf,
java.lang.String xmlDictionary,
boolean append)
Create an
EventWriterUnsync for writing events to a ByteBuffer. |
EventWriterUnsync(java.io.File file)
Creates an
EventWriterUnsync for writing to a file in native byte order. |
EventWriterUnsync(java.io.File file,
boolean append)
Creates an
EventWriterUnsync for writing to a file in native byte order. |
EventWriterUnsync(java.io.File file,
int blockSizeMax,
int blockCountMax,
java.nio.ByteOrder byteOrder,
java.lang.String xmlDictionary,
java.util.BitSet bitInfo)
Create an
EventWriterUnsync for writing events to a file. |
EventWriterUnsync(java.io.File file,
int blockSizeMax,
int blockCountMax,
java.nio.ByteOrder byteOrder,
java.lang.String xmlDictionary,
java.util.BitSet bitInfo,
boolean overWriteOK)
Create an
EventWriterUnsync for writing events to a file. |
EventWriterUnsync(java.io.File file,
int blockSizeMax,
int blockCountMax,
java.nio.ByteOrder byteOrder,
java.lang.String xmlDictionary,
java.util.BitSet bitInfo,
boolean overWriteOK,
boolean append)
Create an
EventWriterUnsync for writing events to a file. |
EventWriterUnsync(java.io.File file,
java.lang.String dictionary,
boolean append)
Creates an
EventWriterUnsync for writing to a file in native byte order. |
EventWriterUnsync(java.lang.String filename)
Creates an
EventWriterUnsync for writing to a file in native byte order. |
EventWriterUnsync(java.lang.String filename,
boolean append)
Creates an
EventWriterUnsync for writing to a file in native byte order. |
EventWriterUnsync(java.lang.String filename,
boolean append,
java.nio.ByteOrder byteOrder)
Creates an
EventWriterUnsync for writing to a file in the
specified byte order. |
EventWriterUnsync(java.lang.String baseName,
java.lang.String directory,
java.lang.String runType,
int runNumber,
long split,
java.nio.ByteOrder byteOrder,
java.lang.String xmlDictionary)
Create an
EventWriterUnsync for writing events to a file. |
EventWriterUnsync(java.lang.String baseName,
java.lang.String directory,
java.lang.String runType,
int runNumber,
long split,
java.nio.ByteOrder byteOrder,
java.lang.String xmlDictionary,
boolean overWriteOK)
Create an
EventWriterUnsync for writing events to a file. |
EventWriterUnsync(java.lang.String baseName,
java.lang.String directory,
java.lang.String runType,
int runNumber,
long split,
java.nio.ByteOrder byteOrder,
java.lang.String xmlDictionary,
int streamId)
Create an
EventWriterUnsync for writing events to a file. |
EventWriterUnsync(java.lang.String baseName,
java.lang.String directory,
java.lang.String runType,
int runNumber,
long split,
int blockSizeMax,
int blockCountMax,
int bufferSize,
java.nio.ByteOrder byteOrder,
java.lang.String xmlDictionary,
java.util.BitSet bitInfo,
boolean overWriteOK,
boolean append)
Create an
EventWriterUnsync for writing events to a file. |
EventWriterUnsync(java.lang.String baseName,
java.lang.String directory,
java.lang.String runType,
int runNumber,
long split,
int blockSizeMax,
int blockCountMax,
int bufferSize,
java.nio.ByteOrder byteOrder,
java.lang.String xmlDictionary,
java.util.BitSet bitInfo,
boolean overWriteOK,
boolean append,
EvioBank firstEvent)
Create an
EventWriterUnsync for writing events to a file. |
EventWriterUnsync(java.lang.String baseName,
java.lang.String directory,
java.lang.String runType,
int runNumber,
long split,
int blockSizeMax,
int blockCountMax,
int bufferSize,
java.nio.ByteOrder byteOrder,
java.lang.String xmlDictionary,
java.util.BitSet bitInfo,
boolean overWriteOK,
boolean append,
EvioBank firstEvent,
int streamId)
Create an
EventWriterUnsync for writing events to a file. |
EventWriterUnsync(java.lang.String baseName,
java.lang.String directory,
java.lang.String runType,
int runNumber,
long split,
int blockSizeMax,
int blockCountMax,
int bufferSize,
java.nio.ByteOrder byteOrder,
java.lang.String xmlDictionary,
java.util.BitSet bitInfo,
boolean overWriteOK,
boolean append,
EvioBank firstEvent,
int streamId,
int splitNumber,
int splitIncrement,
int streamCount)
Create an
EventWriterUnsync for writing events to a file. |
Modifier and Type | Method and Description |
---|---|
void |
close()
This method flushes any remaining data to file and disables this object.
|
void |
flush()
This method flushes any remaining internally buffered data to file.
|
int |
getBlockNumber()
Get the current block number.
|
java.nio.ByteBuffer |
getByteBuffer()
If writing to a file, return null.
|
java.nio.ByteOrder |
getByteOrder()
Get the byte order of the buffer/file being written into.
|
long |
getBytesWrittenToBuffer()
If writing to a buffer, get the number of bytes written to it
including the ending header.
|
java.lang.String |
getCurrentFilename()
Get the name of the current file being written to.
|
java.lang.String |
getCurrentFilePath()
Get the full name or path of the current file being written to.
|
int |
getEventsWritten()
Get the number of events written to a file/buffer.
|
int |
getSplitCount()
Get the number of split files produced by this writer.
|
int |
getSplitNumber()
Get the current split count which is the number of files
created by this object.
|
boolean |
hasRoom(int bytes)
Is there room to write this many bytes to an output buffer as a single event?
Will always return true when writing to a file.
|
boolean |
isClosed()
Has
close() been called (without reopening by calling
setBuffer(ByteBuffer) ) ? |
boolean |
isDiskFull()
If writing file, is the partition it resides on full?
Not full, in this context, means there's enough space to write
a full split file + a full record + an extra 10MB as a safety factor.
|
void |
setBuffer(java.nio.ByteBuffer buf)
Set the buffer being written into (initially set in constructor).
|
void |
setBuffer(java.nio.ByteBuffer buf,
java.util.BitSet bitInfo,
int blockNumber)
Set the buffer being written into (initially set in constructor).
|
void |
setFirstEvent(java.nio.ByteBuffer buffer)
Set an event which will be written to the file/buffer as
well as to all split files.
|
void |
setFirstEvent(EvioBank bank)
Set an event which will be written to the file/buffer as
well as to all split files.
|
void |
setFirstEvent(EvioNode node)
Set an event which will be written to the file/buffer as
well as to all split files.
|
void |
setStartingBlockNumber(int startingBlockNumber)
Set the number with which to start block numbers.
|
boolean |
toFile()
Is this object writing to file?
|
void |
writeEvent(java.nio.ByteBuffer eventBuffer)
Write an event (bank) to the buffer in evio version 4 format.
|
void |
writeEvent(java.nio.ByteBuffer bankBuffer,
boolean force)
Write an event (bank) to the buffer in evio version 4 format.
|
void |
writeEvent(EvioBank bank)
Write an event (bank) to a buffer containing evio version 4 format blocks.
|
void |
writeEvent(EvioBank bank,
boolean force)
Write an event (bank) to a buffer containing evio version 4 format blocks.
|
void |
writeEvent(EvioNode node,
boolean force)
Write an event (bank) to the buffer in evio version 4 format.
|
void |
writeEvent(EvioNode node,
boolean force,
boolean duplicate)
Write an event (bank) to the buffer in evio version 4 format.
|
boolean |
writeEventToFile(EvioBank bank,
java.nio.ByteBuffer bankBuffer,
boolean force)
Write an event (bank) into a block and eventually to a file in evio
version 4 format.
|
boolean |
writeEventToFile(EvioNode node,
boolean force,
boolean duplicate)
Write an event (bank) into a record and eventually to a file in evio
version 4 format.
|
public EventWriterUnsync(java.io.File file) throws EvioException
EventWriterUnsync
for writing to a file in native byte order.
If the file already exists, its contents will be overwritten.
If it doesn't exist, it will be created.file
- the file object to write to.EvioException
- file cannot be createdpublic EventWriterUnsync(java.io.File file, boolean append) throws EvioException
EventWriterUnsync
for writing to a file in native byte order.
If the file already exists, its contents will be overwritten unless
it is being appended to. If it doesn't exist, it will be created.file
- the file object to write to.append
- if true
and the file already exists,
all events to be written will be appended to the
end of the file.EvioException
- file cannot be createdpublic EventWriterUnsync(java.io.File file, java.lang.String dictionary, boolean append) throws EvioException
EventWriterUnsync
for writing to a file in native byte order.
If the file already exists, its contents will be overwritten unless
it is being appended to. If it doesn't exist, it will be created.file
- the file object to write to.dictionary
- dictionary in xml format or null if none.append
- if true
and the file already exists,
all events to be written will be appended to the
end of the file.EvioException
- file cannot be createdpublic EventWriterUnsync(java.lang.String filename) throws EvioException
EventWriterUnsync
for writing to a file in native byte order.
If the file already exists, its contents will be overwritten.
If it doesn't exist, it will be created.filename
- name of the file to write to.EvioException
- file cannot be createdpublic EventWriterUnsync(java.lang.String filename, boolean append) throws EvioException
EventWriterUnsync
for writing to a file in native byte order.
If the file already exists, its contents will be overwritten unless
it is being appended to. If it doesn't exist, it will be created.filename
- name of the file to write to.append
- if true
and the file already exists,
all events to be written will be appended to the
end of the file.EvioException
- file cannot be createdpublic EventWriterUnsync(java.lang.String filename, boolean append, java.nio.ByteOrder byteOrder) throws EvioException
EventWriterUnsync
for writing to a file in the
specified byte order.
If the file already exists, its contents will be overwritten unless
it is being appended to. If it doesn't exist, it will be created.filename
- name of the file to write to.append
- if true
and the file already exists,
all events to be written will be appended to the
end of the file.byteOrder
- the byte order in which to write the file.EvioException
- file cannot be createdpublic EventWriterUnsync(java.io.File file, int blockSizeMax, int blockCountMax, java.nio.ByteOrder byteOrder, java.lang.String xmlDictionary, java.util.BitSet bitInfo) throws EvioException
EventWriterUnsync
for writing events to a file.
If the file already exists, its contents will be overwritten.
If it doesn't exist, it will be created.file
- the file object to write to.blockSizeMax
- the max blocksize to use which must be >= MIN_BLOCK_SIZE
and <= MAX_BLOCK_SIZE
ints.
The size of the block will not be larger than this size
unless a single event itself is larger.blockCountMax
- the max number of events (including dictionary) in a single block
which must be >= MIN_BLOCK_COUNT
and <= MAX_BLOCK_COUNT
.byteOrder
- the byte order in which to write the file.xmlDictionary
- dictionary in xml format or null if none.bitInfo
- set of bits to include in first block header.EvioException
- if blockSizeMax or blockCountMax exceed limits;
file cannot be createdpublic EventWriterUnsync(java.io.File file, int blockSizeMax, int blockCountMax, java.nio.ByteOrder byteOrder, java.lang.String xmlDictionary, java.util.BitSet bitInfo, boolean overWriteOK) throws EvioException
EventWriterUnsync
for writing events to a file.
If the file already exists, its contents will be overwritten
unless the "overWriteOK" argument is false
in
which case an exception will be thrown. If it doesn't exist,
it will be created.file
- the file to write to.blockSizeMax
- the max blocksize to use which must be >= MIN_BLOCK_SIZE
and <= MAX_BLOCK_SIZE
ints.
The size of the block will not be larger than this size
unless a single event itself is larger.blockCountMax
- the max number of events (including dictionary) in a single block
which must be >= MIN_BLOCK_COUNT
and <= MAX_BLOCK_COUNT
.byteOrder
- the byte order in which to write the file.xmlDictionary
- dictionary in xml format or null if none.bitInfo
- set of bits to include in first block header.overWriteOK
- if false
and the file already exists,
an exception is thrown rather than overwriting it.EvioException
- if blockSizeMax or blockCountMax exceed limits;
file exists and cannot be deleted;
file exists and user requested no deletion.public EventWriterUnsync(java.io.File file, int blockSizeMax, int blockCountMax, java.nio.ByteOrder byteOrder, java.lang.String xmlDictionary, java.util.BitSet bitInfo, boolean overWriteOK, boolean append) throws EvioException
EventWriterUnsync
for writing events to a file.
If the file already exists, its contents will be overwritten
unless the "overWriteOK" argument is false
in
which case an exception will be thrown. Unless ..., the option to
append these events to an existing file is true
,
in which case everything is fine. If the file doesn't exist,
it will be created. Byte order defaults to big endian if arg is null.file
- the file to write to.blockSizeMax
- the max blocksize to use which must be >= MIN_BLOCK_SIZE
and <= MAX_BLOCK_SIZE
ints.
The size of the block will not be larger than this size
unless a single event itself is larger.blockCountMax
- the max number of events (including dictionary) in a single block
which must be >= MIN_BLOCK_COUNT
and <= MAX_BLOCK_COUNT
.byteOrder
- the byte order in which to write the file. This is ignored
if appending to existing file.xmlDictionary
- dictionary in xml format or null if none.bitInfo
- set of bits to include in first block header.overWriteOK
- if false
and the file already exists,
an exception is thrown rather than overwriting it.append
- if true
and the file already exists,
all events to be written will be appended to the
end of the file.EvioException
- if blockSizeMax or blockCountMax exceed limits;
if defined dictionary while appending;
if file arg is null;
if file could not be opened or positioned;
if file exists but user requested no over-writing or appending.public EventWriterUnsync(java.lang.String baseName, java.lang.String directory, java.lang.String runType, int runNumber, long split, java.nio.ByteOrder byteOrder, java.lang.String xmlDictionary) throws EvioException
EventWriterUnsync
for writing events to a file.
This constructor is useful when splitting and automatically naming
the split files. If any of the generated files already exist,
it will NOT be overwritten. Byte order defaults to big endian.baseName
- base file name used to generate complete file name (may not be null)directory
- directory in which file is to be placedrunType
- name of run type configuration to be used in naming filesrunNumber
- number of the CODA run, used in naming filessplit
- if < 1, do not split file, write to only one file of unlimited size.
Else this is max size in bytes to make a file
before closing it and starting writing another.byteOrder
- the byte order in which to write the file.
Defaults to big endian if null.xmlDictionary
- dictionary in xml format or null if none.EvioException
- if baseName arg is null;
if file could not be opened, positioned, or written to;
if file exists.public EventWriterUnsync(java.lang.String baseName, java.lang.String directory, java.lang.String runType, int runNumber, long split, java.nio.ByteOrder byteOrder, java.lang.String xmlDictionary, int streamId) throws EvioException
EventWriterUnsync
for writing events to a file.
This constructor is useful when splitting and automatically naming
the split files. If any of the generated files already exist,
it will NOT be overwritten. Byte order defaults to big endian.baseName
- base file name used to generate complete file name (may not be null)directory
- directory in which file is to be placedrunType
- name of run type configuration to be used in naming filesrunNumber
- number of the CODA run, used in naming filessplit
- if < 1, do not split file, write to only one file of unlimited size.
Else this is max size in bytes to make a file
before closing it and starting writing another.byteOrder
- the byte order in which to write the file.
Defaults to big endian if null.xmlDictionary
- dictionary in xml format or null if none.streamId
- streamId number (100 > id > -1) for file nameEvioException
- if baseName arg is null;
if file could not be opened, positioned, or written to;
if file exists.public EventWriterUnsync(java.lang.String baseName, java.lang.String directory, java.lang.String runType, int runNumber, long split, java.nio.ByteOrder byteOrder, java.lang.String xmlDictionary, boolean overWriteOK) throws EvioException
EventWriterUnsync
for writing events to a file.
This constructor is useful when splitting and automatically naming
the split files. Byte order defaults to big endian.baseName
- base file name used to generate complete file name (may not be null)directory
- directory in which file is to be placedrunType
- name of run type configuration to be used in naming filesrunNumber
- number of the CODA run, used in naming filessplit
- if < 1, do not split file, write to only one file of unlimited size.
Else this is max size in bytes to make a file
before closing it and starting writing another.byteOrder
- the byte order in which to write the file.
Defaults to big endian if null.xmlDictionary
- dictionary in xml format or null if none.overWriteOK
- if false
and the file already exists,
an exception is thrown rather than overwriting it.EvioException
- if baseName arg is null;
if file could not be opened, positioned, or written to;
if file exists.public EventWriterUnsync(java.lang.String baseName, java.lang.String directory, java.lang.String runType, int runNumber, long split, int blockSizeMax, int blockCountMax, int bufferSize, java.nio.ByteOrder byteOrder, java.lang.String xmlDictionary, java.util.BitSet bitInfo, boolean overWriteOK, boolean append) throws EvioException
EventWriterUnsync
for writing events to a file.
If the file already exists, its contents will be overwritten
unless the "overWriteOK" argument is false
in
which case an exception will be thrown. Unless ..., the option to
append these events to an existing file is true
,
in which case everything is fine. If the file doesn't exist,
it will be created. Byte order defaults to big endian if arg is null.
File can be split while writing.The base file name may contain up to 2, C-style integer format specifiers using "d" and "x" (such as %03d, or %x). If more than 2 are found, an exception will be thrown. If no "0" precedes any integer between the "%" and the "d" or "x" of the format specifier, it will be added automatically in order to avoid spaces in the file name. The first specifier will be substituted with the given runNumber value. If the file is being split, the second will be substituted with the split number which starts at 0. If 2 specifiers exist and the file is not being split, no substitutions are made. If no specifier for the splitNumber exists, it is tacked onto the end of the file name after a dot (.).
The base file name may contain characters of the form $(ENV_VAR) which will be substituted with the value of the associated environmental variable or a blank string if none is found.
The base file name may also contain occurrences of the string "%s" which will be substituted with the value of the runType arg or nothing if the runType is null.
baseName
- base file name used to generate complete file name (may not be null)directory
- directory in which file is to be placedrunType
- name of run type configuration to be used in naming filesrunNumber
- number of the CODA run, used in naming filessplit
- if < 1, do not split file, write to only one file of unlimited size.
Else this is max size in bytes to make a file
before closing it and starting writing another.blockSizeMax
- the max blocksize to use which must be >= MIN_BLOCK_SIZE
and <= MAX_BLOCK_SIZE
ints.
The size of the block will not be larger than this size
unless a single event itself is larger.blockCountMax
- the max number of events (including dictionary) in a single block
which must be >= MIN_BLOCK_COUNT
and <= MAX_BLOCK_COUNT
.bufferSize
- number of bytes to make the internal buffer which will
be storing events before writing them to a file. Must be at least
4*blockSizeMax + 32. If not, it is set to that.byteOrder
- the byte order in which to write the file. This is ignored
if appending to existing file.xmlDictionary
- dictionary in xml format or null if none.bitInfo
- set of bits to include in first block header.overWriteOK
- if false
and the file already exists,
an exception is thrown rather than overwriting it.append
- if true
and the file already exists,
all events to be written will be appended to the
end of the file.EvioException
- if blockSizeMax or blockCountMax exceed limits;
if defined dictionary while appending;
if splitting file while appending;
if file name arg is null;
if file could not be opened, positioned, or written to;
if file exists but user requested no over-writing or appending.public EventWriterUnsync(java.lang.String baseName, java.lang.String directory, java.lang.String runType, int runNumber, long split, int blockSizeMax, int blockCountMax, int bufferSize, java.nio.ByteOrder byteOrder, java.lang.String xmlDictionary, java.util.BitSet bitInfo, boolean overWriteOK, boolean append, EvioBank firstEvent) throws EvioException
EventWriterUnsync
for writing events to a file.
If the file already exists, its contents will be overwritten
unless the "overWriteOK" argument is false
in
which case an exception will be thrown. Unless ..., the option to
append these events to an existing file is true
,
in which case everything is fine. If the file doesn't exist,
it will be created. Byte order defaults to big endian if arg is null.
File can be split while writing.The base file name may contain up to 2, C-style integer format specifiers using "d" and "x" (such as %03d, or %x). If more than 2 are found, an exception will be thrown. If no "0" precedes any integer between the "%" and the "d" or "x" of the format specifier, it will be added automatically in order to avoid spaces in the file name. The first specifier will be substituted with the given runNumber value. If the file is being split, the second will be substituted with the split number which starts at 0. If 2 specifiers exist and the file is not being split, no substitutions are made. If no specifier for the splitNumber exists, it is tacked onto the end of the file name after a dot (.).
The base file name may contain characters of the form $(ENV_VAR) which will be substituted with the value of the associated environmental variable or a blank string if none is found.
The base file name may also contain occurrences of the string "%s" which will be substituted with the value of the runType arg or nothing if the runType is null.
baseName
- base file name used to generate complete file name (may not be null)directory
- directory in which file is to be placedrunType
- name of run type configuration to be used in naming filesrunNumber
- number of the CODA run, used in naming filessplit
- if < 1, do not split file, write to only one file of unlimited size.
Else this is max size in bytes to make a file
before closing it and starting writing another.blockSizeMax
- the max blocksize to use which must be >= MIN_BLOCK_SIZE
and <= MAX_BLOCK_SIZE
ints.
The size of the block will not be larger than this size
unless a single event itself is larger.blockCountMax
- the max number of events (including dictionary) in a single block
which must be >= MIN_BLOCK_COUNT
and <= MAX_BLOCK_COUNT
.bufferSize
- number of bytes to make the internal buffer which will
be storing events before writing them to a file. Must be at least
4*blockSizeMax + 32. If not, it is set to that.byteOrder
- the byte order in which to write the file. This is ignored
if appending to existing file.xmlDictionary
- dictionary in xml format or null if none.bitInfo
- set of bits to include in first block header.overWriteOK
- if false
and the file already exists,
an exception is thrown rather than overwriting it.append
- if true
and the file already exists,
all events to be written will be appended to the
end of the file.firstEvent
- the first event written into each file (after any dictionary)
including all split files; may be null. Useful for adding
common, static info into each split file.EvioException
- if blockSizeMax or blockCountMax exceed limits;
if defined dictionary while appending;
if splitting file while appending;
if file name arg is null;
if file could not be opened, positioned, or written to;
if file exists but user requested no over-writing or appending.public EventWriterUnsync(java.lang.String baseName, java.lang.String directory, java.lang.String runType, int runNumber, long split, int blockSizeMax, int blockCountMax, int bufferSize, java.nio.ByteOrder byteOrder, java.lang.String xmlDictionary, java.util.BitSet bitInfo, boolean overWriteOK, boolean append, EvioBank firstEvent, int streamId) throws EvioException
EventWriterUnsync
for writing events to a file.
If the file already exists, its contents will be overwritten
unless the "overWriteOK" argument is false
in
which case an exception will be thrown. Unless ..., the option to
append these events to an existing file is true
,
in which case everything is fine. If the file doesn't exist,
it will be created. Byte order defaults to big endian if arg is null.
File can be split while writing.The base file name may contain up to 2, C-style integer format specifiers using "d" and "x" (such as %03d, or %x). If more than 2 are found, an exception will be thrown. If no "0" precedes any integer between the "%" and the "d" or "x" of the format specifier, it will be added automatically in order to avoid spaces in the file name. The first specifier will be substituted with the given runNumber value. If the file is being split, the second will be substituted with the split number which starts at 0. If 2 specifiers exist and the file is not being split, no substitutions are made. If no specifier for the splitNumber exists, it is tacked onto the end of the file name after a dot (.).
The base file name may contain characters of the form $(ENV_VAR) which will be substituted with the value of the associated environmental variable or a blank string if none is found.
The base file name may also contain occurrences of the string "%s" which will be substituted with the value of the runType arg or nothing if the runType is null.
If multiple streams of data, each writing a file, end up with the same file name, they can be differentiated by a stream id number. If the id is > 0, the string, ".strm" is appended to the very end of the file followed by the id number (e.g. filename.strm1). This is done after the run type, run number, split numbers, and env vars have been inserted into the file name.
baseName
- base file name used to generate complete file name (may not be null)directory
- directory in which file is to be placedrunType
- name of run type configuration to be used in naming filesrunNumber
- number of the CODA run, used in naming filessplit
- if < 1, do not split file, write to only one file of unlimited size.
Else this is max size in bytes to make a file
before closing it and starting writing another.blockSizeMax
- the max blocksize to use which must be >= MIN_BLOCK_SIZE
and <= MAX_BLOCK_SIZE
ints.
The size of the block will not be larger than this size
unless a single event itself is larger.blockCountMax
- the max number of events (including dictionary) in a single block
which must be >= MIN_BLOCK_COUNT
and <= MAX_BLOCK_COUNT
.bufferSize
- number of bytes to make the internal buffer which will
be storing events before writing them to a file. Must be at least
4*blockSizeMax + 32. If not, it is set to that.byteOrder
- the byte order in which to write the file. This is ignored
if appending to existing file.xmlDictionary
- dictionary in xml format or null if none.bitInfo
- set of bits to include in first block header.overWriteOK
- if false
and the file already exists,
an exception is thrown rather than overwriting it.append
- if true
and the file already exists,
all events to be written will be appended to the
end of the file.firstEvent
- the first event written into each file (after any dictionary)
including all split files; may be null. Useful for adding
common, static info into each split file.streamId
- streamId number (100 > id > -1) for file nameEvioException
- if blockSizeMax or blockCountMax exceed limits;
if defined dictionary or first event while appending;
if splitting file while appending;
if file name arg is null;
if file could not be opened, positioned, or written to;
if file exists but user requested no over-writing or appending.public EventWriterUnsync(java.lang.String baseName, java.lang.String directory, java.lang.String runType, int runNumber, long split, int blockSizeMax, int blockCountMax, int bufferSize, java.nio.ByteOrder byteOrder, java.lang.String xmlDictionary, java.util.BitSet bitInfo, boolean overWriteOK, boolean append, EvioBank firstEvent, int streamId, int splitNumber, int splitIncrement, int streamCount) throws EvioException
EventWriterUnsync
for writing events to a file.
If the file already exists, its contents will be overwritten
unless the "overWriteOK" argument is false
in
which case an exception will be thrown. Unless ..., the option to
append these events to an existing file is true
,
in which case everything is fine. If the file doesn't exist,
it will be created. Byte order defaults to big endian if arg is null.
File can be split while writing.The base file name may contain up to 2, C-style integer format specifiers using "d" and "x" (such as %03d, or %x). If more than 2 are found, an exception will be thrown. If no "0" precedes any integer between the "%" and the "d" or "x" of the format specifier, it will be added automatically in order to avoid spaces in the file name. The first specifier will be substituted with the given runNumber value. If the file is being split, the second will be substituted with the split number which starts at 0. If 2 specifiers exist and the file is not being split, no substitutions are made. If no specifier for the splitNumber exists, it is tacked onto the end of the file name after a dot (.). If streamCount > 1, the split number is calculated starting with streamId and incremented by streamCount each time. In this manner, all split files will have unique, sequential names even though there are multiple parallel ERs.
The base file name may contain characters of the form $(ENV_VAR) which will be substituted with the value of the associated environmental variable or a blank string if none is found.
The base file name may also contain occurrences of the string "%s" which will be substituted with the value of the runType arg or nothing if the runType is null.
If multiple streams of data, each writing a file, end up with the same file name, they can be differentiated by a stream id, starting split # and split increment.
baseName
- base file name used to generate complete file name (may not be null)directory
- directory in which file is to be placedrunType
- name of run type configuration to be used in naming filesrunNumber
- number of the CODA run, used in naming filessplit
- if < 1, do not split file, write to only one file of unlimited size.
Else this is max size in bytes to make a file
before closing it and starting writing another.blockSizeMax
- the max blocksize to use which must be >= MIN_BLOCK_SIZE
and <= MAX_BLOCK_SIZE
ints.
The size of the block will not be larger than this size
unless a single event itself is larger.blockCountMax
- the max number of events (including dictionary) in a single block
which must be >= MIN_BLOCK_COUNT
and <= MAX_BLOCK_COUNT
.bufferSize
- number of bytes to make the internal buffer which will
be storing events before writing them to a file. Must be at least
4*blockSizeMax + 32. If not, it is set to that.byteOrder
- the byte order in which to write the file. This is ignored
if appending to existing file.xmlDictionary
- dictionary in xml format or null if none.bitInfo
- set of bits to include in first block header.overWriteOK
- if false
and the file already exists,
an exception is thrown rather than overwriting it.append
- if true
and the file already exists,
all events to be written will be appended to the
end of the file.firstEvent
- the first event written into each file (after any dictionary)
including all split files; may be null. Useful for adding
common, static info into each split file.streamId
- streamId number (100 > id > -1) for file namesplitNumber
- number at which to start the split numberssplitIncrement
- amount to increment split number each time another
file is created.streamCount
- total number of streams in DAQ.EvioException
- if blockSizeMax or blockCountMax exceed limits;
if defined dictionary or first event while appending;
if splitting file while appending;
if file name arg is null;
if file could not be opened, positioned, or written to;
if file exists but user requested no over-writing or appending;
if streamId < 0, splitNumber < 0, or splitIncrement < 1.public EventWriterUnsync(java.nio.ByteBuffer buf) throws EvioException
EventWriterUnsync
for writing events to a ByteBuffer.
Uses the default number and size of blocks in buffer.
Will overwrite any existing data in buffer!buf
- the buffer to write to.EvioException
- if buf arg is nullpublic EventWriterUnsync(java.nio.ByteBuffer buf, boolean append) throws EvioException
EventWriterUnsync
for writing events to a ByteBuffer.
Uses the default number and size of blocks in buffer.buf
- the buffer to write to.append
- if true
, all events to be written will be
appended to the end of the buffer.EvioException
- if buf arg is nullpublic EventWriterUnsync(java.nio.ByteBuffer buf, java.lang.String xmlDictionary, boolean append) throws EvioException
EventWriterUnsync
for writing events to a ByteBuffer.
Uses the default number and size of blocks in buffer.buf
- the buffer to write to.xmlDictionary
- dictionary in xml format or null if none.append
- if true
, all events to be written will be
appended to the end of the buffer.EvioException
- if buf arg is nullpublic EventWriterUnsync(java.nio.ByteBuffer buf, int blockSizeMax, int blockCountMax, java.lang.String xmlDictionary, java.util.BitSet bitInfo) throws EvioException
EventWriterUnsync
for writing events to a ByteBuffer.
Will overwrite any existing data in buffer!buf
- the buffer to write to.blockSizeMax
- the max blocksize to use which must be >= MIN_BLOCK_SIZE
and <= MAX_BLOCK_SIZE
ints.
The size of the block will not be larger than this size
unless a single event itself is larger.blockCountMax
- the max number of events (including dictionary) in a single block
which must be >= MIN_BLOCK_COUNT
and <= MAX_BLOCK_COUNT
.xmlDictionary
- dictionary in xml format or null if none.bitInfo
- set of bits to include in first block header.EvioException
- if blockSizeMax or blockCountMax exceed limits; if buf arg is nullpublic EventWriterUnsync(java.nio.ByteBuffer buf, int blockSizeMax, int blockCountMax, java.lang.String xmlDictionary, java.util.BitSet bitInfo, boolean append) throws EvioException
EventWriterUnsync
for writing events to a ByteBuffer.
Block number starts at 0.buf
- the buffer to write to.blockSizeMax
- the max blocksize to use which must be >= MIN_BLOCK_SIZE
and <= MAX_BLOCK_SIZE
ints.
The size of the block will not be larger than this size
unless a single event itself is larger.blockCountMax
- the max number of events (including dictionary) in a single block
which must be >= MIN_BLOCK_COUNT
and <= MAX_BLOCK_COUNT
.xmlDictionary
- dictionary in xml format or null if none.bitInfo
- set of bits to include in first block header.append
- if true
, all events to be written will be
appended to the end of the buffer.EvioException
- if blockSizeMax or blockCountMax exceed limits;
if buf arg is null;
if defined dictionary while appending;public EventWriterUnsync(java.nio.ByteBuffer buf, int blockSizeMax, int blockCountMax, java.lang.String xmlDictionary, java.util.BitSet bitInfo, int reserved1, int blockNumber) throws EvioException
EventWriterUnsync
for writing events to a ByteBuffer.
Will overwrite any existing data in buffer!buf
- the buffer to write to.blockSizeMax
- the max blocksize to use which must be >= MIN_BLOCK_SIZE
and <= MAX_BLOCK_SIZE
ints.
The size of the block will not be larger than this size
unless a single event itself is larger.blockCountMax
- the max number of events (including dictionary) in a single block
which must be >= MIN_BLOCK_COUNT
and <= MAX_BLOCK_COUNT
.xmlDictionary
- dictionary in xml format or null if none.bitInfo
- set of bits to include in first block header.reserved1
- set the value of the first "reserved" int in first block header.
NOTE: only CODA (i.e. EMU) software should use this.blockNumber
- number at which to start block number counting.EvioException
- if blockSizeMax or blockCountMax exceed limits; if buf arg is nullpublic EventWriterUnsync(java.nio.ByteBuffer buf, int blockSizeMax, int blockCountMax, java.lang.String xmlDictionary, java.util.BitSet bitInfo, int reserved1, boolean append) throws EvioException
EventWriterUnsync
for writing events to a ByteBuffer.
Block number starts at 0.buf
- the buffer to write to.blockSizeMax
- the max blocksize to use which must be >= MIN_BLOCK_SIZE
and <= MAX_BLOCK_SIZE
ints.
The size of the block will not be larger than this size
unless a single event itself is larger.blockCountMax
- the max number of events (including dictionary) in a single block
which must be >= MIN_BLOCK_COUNT
and <= MAX_BLOCK_COUNT
.xmlDictionary
- dictionary in xml format or null if none.bitInfo
- set of bits to include in first block header.reserved1
- set the value of the first "reserved" int in first block header.
NOTE: only CODA (i.e. EMU) software should use this.append
- if true
, all events to be written will be
appended to the end of the buffer.EvioException
- if blockSizeMax or blockCountMax exceed limits;
if buf arg is null;
if defined dictionary while appending;public EventWriterUnsync(java.nio.ByteBuffer buf, int blockSizeMax, int blockCountMax, java.lang.String xmlDictionary, java.util.BitSet bitInfo, int reserved1, int blockNumber, boolean append, EvioBank firstEvent) throws EvioException
EventWriterUnsync
for writing events to a ByteBuffer.buf
- the buffer to write to.blockSizeMax
- the max blocksize to use which must be >= MIN_BLOCK_SIZE
and <= MAX_BLOCK_SIZE
ints.
The size of the block will not be larger than this size
unless a single event itself is larger.blockCountMax
- the max number of events (including dictionary) in a single block
which must be >= MIN_BLOCK_COUNT
and <= MAX_BLOCK_COUNT
.xmlDictionary
- dictionary in xml format or null if none.bitInfo
- set of bits to include in first block header.reserved1
- set the value of the first "reserved" int in first block header.
NOTE: only CODA (i.e. EMU) software should use this.blockNumber
- number at which to start block number counting.append
- if true
, all events to be written will be
appended to the end of the buffer.firstEvent
- the first event written into the buffer (after any dictionary).
May be null. Not useful when writing to a buffer as this
event may be written using normal means.EvioException
- if blockSizeMax or blockCountMax exceed limits;
if buf arg is null;
if defined dictionary while appending;public boolean isDiskFull()
public long getBytesWrittenToBuffer()
public void setBuffer(java.nio.ByteBuffer buf, java.util.BitSet bitInfo, int blockNumber) throws EvioException
Do not use this method unless you know what you are doing.
buf
- the buffer to write to.bitInfo
- set of bits to include in first block header.blockNumber
- number at which to start block number counting.EvioException
- if this object was not closed prior to resetting the buffer,
buffer arg is null, or in appending mode.public void setBuffer(java.nio.ByteBuffer buf) throws EvioException
Do not use this method unless you know what you are doing.
buf
- the buffer to write to.EvioException
- if this object was not closed prior to resetting the buffer,
buffer arg is null, or in appending mode.public java.nio.ByteBuffer getByteBuffer()
public boolean toFile()
true
if writing to file, else false
.public boolean isClosed()
close()
been called (without reopening by calling
setBuffer(ByteBuffer)
) ?true
if this object closed, else false
.public java.lang.String getCurrentFilename()
public java.lang.String getCurrentFilePath()
public int getSplitNumber()
public int getSplitCount()
public int getBlockNumber()
public int getEventsWritten()
public java.nio.ByteOrder getByteOrder()
public void setStartingBlockNumber(int startingBlockNumber)
startingBlockNumber
- the number with which to start block numbers.public void setFirstEvent(EvioNode node) throws EvioException, java.io.IOException
Since this method is always called after the constructor, the common block will have already been written with a dictionary and firstEvent if either was defined in the constructor. The event given here will be written immediately somewhere in the body of the file, with the forth-coming split files having that event in the first block along with any dictionary.
This means that if the firstEvent is given in the constructor, then the caller may end up with 2 copies of it in a single file (if this method is called once). It's also possible to get 2 copies in a file if this method is called immediately prior to the file splitting.
By its nature this method is not useful for writing to a buffer since it is never split and the event can be written to it as any other.
Do not call this while simultaneously calling close, flush, writeEvent, or getByteBuffer.
node
- node representing event to be placed first in each file written
including all splits. If null, no more first events are written
to any files.java.io.IOException
- if error writing fileEvioException
- if event is opposite byte order of internal buffer;
if event is bad format;
if close() already called;
if file could not be opened for writing;
if file exists but user requested no over-writing;
if no room when writing to user-given buffer;public void setFirstEvent(java.nio.ByteBuffer buffer) throws EvioException, java.io.IOException
Since this method is always called after the constructor, the common block will have already been written with a dictionary and firstEvent if either was defined in the constructor. The event given here will be written immediately somewhere in the body of the file, with the forth-coming split files having that event in the first block along with any dictionary.
This means that if the firstEvent is given in the constructor, then the caller may end up with 2 copies of it in a single file (if this method is called once). It's also possible to get 2 copies in a file if this method is called immediately prior to the file splitting.
By its nature this method is not useful for writing to a buffer since it is never split and the event can be written to it as any other.
The method writeEvent(org.jlab.coda.jevio.EvioNode, boolean)
calls writeCommonBlock() which, in turn,
only gets called when synchronized. So synchronizing this method will
make sure firstEvent only gets set while nothing is being written.
buffer
- buffer containing event to be placed first in each file written
including all splits. If null, no more first events are written
to any files.java.io.IOException
- if error writing fileEvioException
- if event is opposite byte order of internal buffer;
if event is bad format;
if close() already called;
if file could not be opened for writing;
if file exists but user requested no over-writing;
if no room when writing to user-given buffer;public void setFirstEvent(EvioBank bank) throws EvioException, java.io.IOException
Since this method is always called after the constructor, the common block will have already been written with a dictionary and firstEvent if either was defined in the constructor. The event given here will be written immediately somewhere in the body of the file, with the forth-coming split files having that event in the first block along with any dictionary.
This means that if the firstEvent is given in the constructor, then the caller may end up with 2 copies of it in a single file (if this method is called once). It's also possible to get 2 copies in a file if this method is called immediately prior to the file splitting.
By its nature this method is not useful for writing to a buffer since it is never split and the event can be written to it as any other.
Do not call this while simultaneously calling close, flush, writeEvent, or getByteBuffer.
bank
- event to be placed first in each file written including all splits.
If null, no more first events are written to any files.java.io.IOException
- if error writing fileEvioException
- if event is opposite byte order of internal buffer;
if event is bad format;
if close() already called;
if file could not be opened for writing;
if file exists but user requested no over-writing;
if no room when writing to user-given buffer;public void flush()
close()
automatically does this so it isn't necessary
to call before closing. This method should only be used when writing
events at such a low rate that it takes an inordinate amount of time
for internally buffered data to be written to the file.Calling this can kill performance. May not call this when simultaneously calling writeEvent, close, setFirstEvent, or getByteBuffer.
public void close()
public boolean hasRoom(int bytes)
bytes
- number of bytes to writetrue
if there still room in the output buffer, else false
.public void writeEvent(EvioNode node, boolean force) throws EvioException, java.io.IOException
node
- object representing the event to write in buffer formforce
- if writing to disk, force it to write event to the disk.java.io.IOException
- if error writing fileEvioException
- if event is opposite byte order of internal buffer;
if close() already called;
if bad eventBuffer format;
if file could not be opened for writing;
if file exists but user requested no over-writing;
if no room when writing to user-given buffer;public void writeEvent(EvioNode node, boolean force, boolean duplicate) throws EvioException, java.io.IOException
node
- object representing the event to write in buffer formforce
- if writing to disk, force it to write event to the disk.duplicate
- if true, duplicate node's buffer so its position and limit
can be changed without issue.java.io.IOException
- if error writing fileEvioException
- if event is opposite byte order of internal buffer;
if close() already called;
if bad eventBuffer format;
if file could not be opened for writing;
if file exists but user requested no over-writing;
if no room when writing to user-given buffer;
if null node arg;public boolean writeEventToFile(EvioNode node, boolean force, boolean duplicate) throws EvioException, java.io.IOException
If splitting files, this method returns false if disk partition is too full
to write the complete, next split file. If force arg is true, write anyway.
DO NOT mix calling this method with calling writeEvent(EvioNode, boolean, boolean)
(or the methods which call it). Results are unpredictable as it messes up the
logic used to quit writing to full disk.
The buffer must contain only the event's data (event header and event data)
and must not be in complete evio file format.
Do not call this while simultaneously calling
close, flush, setFirstEvent, or getByteBuffer.
Be warned that injudicious use of a true 2nd arg, the force flag, will kill performance when writing to a file. A true 3rd arg can be used when the backing buffer of the node is accessed by multiple threads simultaneously. This allows that buffer's limit and position to be changed without interfering with the other threads.
node
- object representing the event to write in buffer formforce
- if writing to disk, force it to write event to the disk.duplicate
- if true, duplicate node's buffer so its position and limit
can be changed without issue.java.io.IOException
- if error writing fileEvioException
- if event is opposite byte order of internal buffer;
if close() already called;
if bad eventBuffer format;
if file could not be opened for writing;
if file exists but user requested no over-writing;
if null node arg;public void writeEvent(java.nio.ByteBuffer eventBuffer) throws EvioException, java.io.IOException
eventBuffer
- the event (bank) to write in buffer formjava.io.IOException
- if error writing fileEvioException
- if event is opposite byte order of internal buffer;
if close() already called;
if bad eventBuffer format;
if file could not be opened for writing;
if file exists but user requested no over-writing;
if no room when writing to user-given buffer;public void writeEvent(EvioBank bank) throws EvioException, java.io.IOException
bank
- the bank to write.java.io.IOException
- if error writing fileEvioException
- if close() already called;
if file could not be opened for writing;
if file exists but user requested no over-writing;
if no room when writing to user-given buffer;public void writeEvent(java.nio.ByteBuffer bankBuffer, boolean force) throws EvioException, java.io.IOException
Be warned that injudicious use of the 2nd arg, the force flag, will kill performance.
bankBuffer
- the bank (as a ByteBuffer object) to write.force
- if writing to disk, force it to write event to the disk.java.io.IOException
- if error writing fileEvioException
- if event is opposite byte order of internal buffer;
if close() already called;
if bad eventBuffer format;
if file could not be opened for writing;
if file exists but user requested no over-writing;
if no room when writing to user-given buffer;public void writeEvent(EvioBank bank, boolean force) throws EvioException, java.io.IOException
Be warned that injudicious use of the 2nd arg, the force flag, will kill performance.
bank
- the bank to write.force
- if writing to disk, force it to write event to the disk.java.io.IOException
- if error writing fileEvioException
- if close() already called;
if file could not be opened for writing;
if file exists but user requested no over-writing;
if no room when writing to user-given buffer;public boolean writeEventToFile(EvioBank bank, java.nio.ByteBuffer bankBuffer, boolean force) throws EvioException, java.io.IOException
writeEvent(EvioBank, ByteBuffer, boolean)
(or the methods which call it). Results are unpredictable as it messes up the
logic used to quit writing to full disk.
The event to be written may be in one of two forms. The first is as an EvioBank object and the second is as a ByteBuffer containing only the event's data (event header and event data) and must not be in complete evio file format. The first non-null of the bank arguments will be written. Do not call this while simultaneously calling close, flush, setFirstEvent, or getByteBuffer.
Be warned that injudicious use of a true 2nd arg, the force flag, will kill performance.
This method is not used to write the dictionary or the first event
(common block). That is only done with the method writeCommonBlock()
.
bank
- the bank (as an EvioBank object) to write.bankBuffer
- the bank (as a ByteBuffer object) to write.force
- if writing to disk, force it to write event to the disk.java.io.IOException
- if error writing fileEvioException
- if event is opposite byte order of internal buffer;
if bad bankBuffer format;
if close() already called;
if not writing to file;
if file could not be opened for writing;
if file exists but user requested no over-writing;