evio
6.0
|
Class to write data into a file or buffer in the evio version 4 format. More...
#include <EventWriterV4.h>
Public Member Functions | |
EventWriterV4 (std::string &filename, const ByteOrder &byteOrder=ByteOrder::nativeOrder(), bool append=false) | |
Creates an EventWriterV4 for writing to a file in the evio 4 format and in the specified byte order. More... | |
EventWriterV4 (std::string &filename, const std::string &xmlDictionary, const ByteOrder &byteOrder=ByteOrder::nativeOrder(), bool append=false) | |
Creates an EventWriterV4 for writing to a file in the evio 4 format and in the specified byte order. More... | |
EventWriterV4 (std::string &baseName, const std::string &directory, const std::string &runType, uint32_t runNumber=1, uint64_t split=0, uint32_t maxBlockSize=DEFAULT_BLOCK_SIZE, uint32_t maxEventCount=DEFAULT_BLOCK_COUNT, const ByteOrder &byteOrder=ByteOrder::nativeOrder(), const std::string &xmlDictionary="", bool overWriteOK=true, bool append=false, std::shared_ptr< EvioBank > firstEvent=nullptr, uint32_t streamId=0, uint32_t splitNumber=0, uint32_t splitIncrement=1, uint32_t streamCount=1, size_t bufferSize=DEFAULT_BUFFER_SIZE, std::bitset< 24 > *bitInfo=nullptr) | |
EventWriterV4 (std::shared_ptr< ByteBuffer > &buf, const std::string &xmlDictionary="", bool append=false) | |
Create an EventWriterV4 for writing events to a ByteBuffer. More... | |
EventWriterV4 (std::shared_ptr< ByteBuffer > &buf, int maxBlockSize, int maxEventCount, const std::string &xmlDictionary="", std::bitset< 24 > *bitInfo=nullptr, int reserved1=0, int blockNumber=1, bool append=false, std::shared_ptr< EvioBank > firstEvent=nullptr) | |
Create an EventWriterV4 for writing events to a ByteBuffer. More... | |
bool | isDiskFull () const |
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. More... | |
uint64_t | getBytesWrittenToBuffer () const |
If writing to a buffer, get the number of bytes written to it including the ending header. More... | |
void | setBuffer (std::shared_ptr< ByteBuffer > &buf, std::bitset< 24 > *bitInfo, int blockNumber) |
Set the buffer being written into (initially set in constructor). More... | |
void | setBuffer (std::shared_ptr< ByteBuffer > &buf) |
Set the buffer being written into (initially set in constructor). More... | |
std::shared_ptr< ByteBuffer > | getByteBuffer () |
If writing to a file, return null. More... | |
bool | isToFile () const |
Is this object writing to file? More... | |
bool | isClosed () |
Has close() been called (without reopening by calling setBuffer(std::shared_ptr<ByteBuffer>)) ? More... | |
std::string | getCurrentFilename () const |
Get the name of the current file being written to. More... | |
std::string | getCurrentFilePath () const |
Get the full or absolute name or path of the current file being written to. More... | |
uint32_t | getSplitNumber () const |
Get the current split count which is the number of files created by this object. More... | |
uint32_t | getSplitCount () const |
Get the number of split files produced by this writer. More... | |
uint32_t | getBlockNumber () const |
Get the current block number. More... | |
uint32_t | getEventsWritten () const |
Get the number of events written to a file/buffer. More... | |
ByteOrder | getByteOrder () const |
Get the byte order of the buffer/file being written into. More... | |
void | setStartingBlockNumber (int startingBlockNumber) |
Set the number with which to start block numbers. More... | |
void | setFirstEvent (std::shared_ptr< EvioNode > node) |
Set an event which will be written to the file/buffer as well as to all split files. More... | |
void | setFirstEvent (std::shared_ptr< ByteBuffer > buffer) |
Set an event which will be written to the file/buffer as well as to all split files. More... | |
void | setFirstEvent (std::shared_ptr< EvioBank > bank) |
Set an event which will be written to the file/buffer as well as to all split files. More... | |
void | flush () |
This method flushes any remaining internally buffered data to file. More... | |
void | close () |
This method flushes any remaining data to file and disables this object. More... | |
bool | hasRoom (size_t 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. More... | |
bool | writeEvent (std::shared_ptr< EvioNode > &node, bool force, bool duplicate=true) |
Write an event (bank) to the buffer in evio version 4 format. More... | |
bool | writeEventToFile (std::shared_ptr< EvioNode > &node, bool force, bool duplicate) |
Write an event (bank) into a record and eventually to a file in evio version 4 format. More... | |
bool | writeEvent (std::shared_ptr< ByteBuffer > &bankBuffer, bool force=false) |
Write an event (bank) to the buffer in evio version 4 format. More... | |
bool | writeEvent (std::shared_ptr< EvioBank > bank, bool force=false) |
Write an event (bank) to a buffer containing evio version 4 format blocks. More... | |
bool | writeEventToFile (std::shared_ptr< EvioBank > bank, std::shared_ptr< ByteBuffer > bankBuffer, bool force) |
Write an event (bank) into a block and eventually to a file in evio version 4 format. More... | |
Static Public Attributes | |
static const int | DEFAULT_BLOCK_SIZE = 16777216 |
The default maximum size, in bytes, for a single block used for writing. More... | |
static const int | DEFAULT_BLOCK_COUNT = 10000 |
The default maximum event count for a single block used for writing. More... | |
static const size_t | DEFAULT_BUFFER_SIZE = DEFAULT_BLOCK_SIZE + 1024 |
The default byte size of internal buffer. More... | |
Protected Member Functions | |
void | examineFirstBlockHeader () |
Reads part of the first block (physical record) header in order to determine the evio version # and endianness of the file or buffer in question. More... | |
Class to write data into a file or buffer in the evio version 4 format.
This is included so that CODA DAQ systems can avoid using the cumbersome evio version 6 format. This class is not thread-safe.
|
explicit |
Creates an EventWriterV4
for writing to a file in the evio 4 format and 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 created, or if appending and file is too small to be evio format; |
evio::EventWriterV4::EventWriterV4 | ( | std::string & | filename, |
const std::string & | xmlDictionary, | ||
const ByteOrder & | byteOrder = ByteOrder::nativeOrder() , |
||
bool | append = false |
||
) |
Creates an EventWriterV4
for writing to a file in the evio 4 format and 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 | the file object to write to. |
xmlDictionary | dictionary in xml format or empty if none. |
byteOrder | the byte order in which to write the file. |
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 created, or if appending and file is too small to be evio format; |
evio::EventWriterV4::EventWriterV4 | ( | std::string & | baseName, |
const std::string & | directory, | ||
const std::string & | runType, | ||
uint32_t | runNumber = 1 , |
||
uint64_t | split = 0 , |
||
uint32_t | maxBlockSize = DEFAULT_BLOCK_SIZE , |
||
uint32_t | maxEventCount = DEFAULT_BLOCK_COUNT , |
||
const ByteOrder & | byteOrder = ByteOrder::nativeOrder() , |
||
const std::string & | xmlDictionary = "" , |
||
bool | overWriteOK = true , |
||
bool | append = false , |
||
std::shared_ptr< EvioBank > | firstEvent = nullptr , |
||
uint32_t | streamId = 0 , |
||
uint32_t | splitNumber = 0 , |
||
uint32_t | splitIncrement = 1 , |
||
uint32_t | streamCount = 1 , |
||
size_t | bufferSize = DEFAULT_BUFFER_SIZE , |
||
std::bitset< 24 > * | bitInfo = nullptr |
||
) |
Create an EventWriterV4
for writing events to a file or files in the evio 4 format. If the given file already exists, its contents will be overwritten unless the "overWriteOK" argument is false
in which case an exception will be thrown. If the option to "append" these events to an existing file is true
, then the write proceeds. If the file doesn't exist, it will be created.
In order to keep files from getting too large, there is an option to continue writing but to multiple files instead of just one. That is, when a file gets to the size given by the "split" arg, it is closed and another is opened, with new writes going to the new file. The trick in this case is to automatically name the new files.
The baseName arg is the base string from which a final file name or names can be created. The baseName may contain up to 3, C-style integer format specifiers using "d" and "x" (such as %03d, or x). These specifiers dictate how the runNumber, streamId and splitNumber arguments are inserted into the filename.
If there are multiple streams of data each writing a file, to avoid ending up with the same file name, they can be differentiated by a stream id. Run number can differentiate data files from different runs of the same experiment. And of course, the split number tracks the number of files automatically created by this EventWriter object and is incremented at each split.
Back to the format specifiers, if more than 3 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 returned string. See the documentation at Util::generateFileName to understand exactly how substitutions of runNumber, streamId and splitNumber are done for these specifiers in order to create the split file names.
In addition, the baseName 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.
Finally, the baseName may 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 empty) |
directory | directory in which file is to be placed |
runType | name of run type configuration to be used in naming files |
runNumber | number of the CODA run, used in naming files |
split | 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. |
maxBlockSize | the max blocksize in bytes to use which must be >= #MIN_BLOCK_SIZE and <= #MAX_BLOCK_SIZE. The size of the block will not be larger than this size unless a single event itself is larger. |
maxEventCount | 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 empty if none. |
overWriteOK | if false and the file already exists, an exception is thrown rather than overwriting it. |
append | if true append written data to given 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 name |
splitNumber | number at which to start the split numbers |
splitIncrement | amount to increment split number each time another file is created. |
streamCount | total number of streams in DAQ. |
bufferSize | number of bytes to make the internal buffer which will be storing events before writing them to a file. Must be at least a max block size + 1kB (add a little extra). If not, it is set to that. |
bitInfo | set of bits to include in first block header. |
EvioException | if defined dictionary or first event while appending; if splitting file while appending; if appending and file is too small to be evio format; if file name arg is empty; if file could not be opened, positioned, or written to; if file exists but user requested no over-writing or appending. |
References examineFirstBlockHeader(), evio::Util::generateBaseFileName(), evio::Util::generateFileName(), and evio::BaseStructure::stringsToRawBytes().
|
explicit |
Create an EventWriterV4
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 appending and buffer is too small to be evio format; |
evio::EventWriterV4::EventWriterV4 | ( | std::shared_ptr< ByteBuffer > & | buf, |
int | maxBlockSize, | ||
int | maxEventCount, | ||
const std::string & | xmlDictionary = "" , |
||
std::bitset< 24 > * | bitInfo = nullptr , |
||
int | reserved1 = 0 , |
||
int | blockNumber = 1 , |
||
bool | append = false , |
||
std::shared_ptr< EvioBank > | firstEvent = nullptr |
||
) |
Create an EventWriterV4
for writing events to a ByteBuffer.
buf | the buffer to write to. |
maxBlockSize | 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. |
maxEventCount | 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 maxBlockSize or maxEventCount exceed limits; if appending and buffer is too small to be evio format; if defined dictionary while appending; |
void evio::EventWriterV4::close | ( | ) |
This method flushes any remaining data to file and disables this object.
May not call this when simultaneously calling writeEvent, flush, setFirstEvent, or getByteBuffer.
|
protected |
Reads part of the first block (physical record) header in order to determine the evio version # and endianness of the file or buffer in question.
These things do not need to be examined in subsequent block headers.
EvioException | if error reading file; if not in append mode; if file has bad format; |
References evio::ByteOrder::ENDIAN_BIG, evio::ByteOrder::ENDIAN_LITTLE, evio::BlockHeaderV4::hasDictionary(), evio::IBlockHeader::MAGIC_NUMBER, and throwEvioLine.
Referenced by EventWriterV4().
void evio::EventWriterV4::flush | ( | ) |
This method flushes any remaining internally buffered data to file.
Calling 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.
uint32_t evio::EventWriterV4::getBlockNumber | ( | ) | const |
Get the current block number.
Warning, this value may be changing.
std::shared_ptr< ByteBuffer > evio::EventWriterV4::getByteBuffer | ( | ) |
If writing to a file, return null.
If writing to a buffer, get a duplicate of the user-given buffer being written into. The buffer's position will be 0 and its limit will be the size of the valid data. Basically, it's ready to be read from. The returned buffer shares data with the original buffer but has separate limit, position, and mark. Useful if trying to send buffer over the network. Do not call this while simultaneously calling close, flush, setFirstEvent, or writeEvent.
References isToFile().
ByteOrder evio::EventWriterV4::getByteOrder | ( | ) | const |
Get the byte order of the buffer/file being written into.
uint64_t evio::EventWriterV4::getBytesWrittenToBuffer | ( | ) | const |
If writing to a buffer, get the number of bytes written to it including the ending header.
std::string evio::EventWriterV4::getCurrentFilename | ( | ) | const |
Get the name of the current file being written to.
Returns empty string if no file.
std::string evio::EventWriterV4::getCurrentFilePath | ( | ) | const |
Get the full or absolute name or path of the current file being written to.
Returns empty string if no file.
uint32_t evio::EventWriterV4::getEventsWritten | ( | ) | const |
Get the number of events written to a file/buffer.
Remember that a particular event may not yet be flushed to the file/buffer. If the file being written to is split, the returned value refers to all split files taken together.
uint32_t evio::EventWriterV4::getSplitCount | ( | ) | const |
Get the number of split files produced by this writer.
uint32_t evio::EventWriterV4::getSplitNumber | ( | ) | const |
Get the current split count which is the number of files created by this object.
Warning, this value may be changing.
bool evio::EventWriterV4::hasRoom | ( | size_t | 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.
bytes | number of bytes to write |
References isToFile().
bool evio::EventWriterV4::isClosed | ( | ) |
Has close() been called (without reopening by calling setBuffer(std::shared_ptr<ByteBuffer>)) ?
bool evio::EventWriterV4::isDiskFull | ( | ) | const |
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.
bool evio::EventWriterV4::isToFile | ( | ) | const |
Is this object writing to file?
Referenced by getByteBuffer(), and hasRoom().
void evio::EventWriterV4::setBuffer | ( | std::shared_ptr< ByteBuffer > & | buf | ) |
Set the buffer being written into (initially set in constructor).
This method allows the user to avoid having to create a new EventWriterV4 each time a bank needs to be written to a different buffer. This does nothing if writing to a file. Not for use if appending.
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. |
void evio::EventWriterV4::setBuffer | ( | std::shared_ptr< ByteBuffer > & | buf, |
std::bitset< 24 > * | bitInfo, | ||
int | blockNumber | ||
) |
Set the buffer being written into (initially set in constructor).
This method allows the user to avoid having to create a new EventWriterV4 each time a bank needs to be written to a different buffer. This does nothing if writing to a file. Not for use if appending.
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. |
void evio::EventWriterV4::setFirstEvent | ( | std::shared_ptr< ByteBuffer > | buffer | ) |
Set an event which will be written to the file/buffer as well as to all split files.
It's called the "first event" as it will be the first event written to each split file (after the dictionary) if this method is called early enough or the first event was defined in the constructor.
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.
Data is transferred byte for byte, so data better be in an endian compatible with the output of this writer.
The method writeEvent 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. |
IOException | if error writing file |
EvioException | 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; |
References writeEvent().
void evio::EventWriterV4::setFirstEvent | ( | std::shared_ptr< EvioBank > | bank | ) |
Set an event which will be written to the file/buffer as well as to all split files.
It's called the "first event" as it will be the first event written to each split file (after the dictionary) if this method is called early enough or the first event was defined in the constructor.
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. |
IOException | if error writing file |
EvioException | 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; |
References writeEvent().
void evio::EventWriterV4::setFirstEvent | ( | std::shared_ptr< EvioNode > | node | ) |
Set an event which will be written to the file/buffer as well as to all split files.
It's called the "first event" as it will be the first event written to each split file (after the dictionary) if this method is called early enough or the first event was defined in the constructor.
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.
Data is transferred byte for byte, so data better be in an endian compatible with the output of this writer.
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. |
IOException | if error writing file |
EvioException | 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; |
References writeEvent().
void evio::EventWriterV4::setStartingBlockNumber | ( | int | startingBlockNumber | ) |
Set the number with which to start block numbers.
This method does nothing if events have already been written.
startingBlockNumber | the number with which to start block numbers. |
bool evio::EventWriterV4::writeEvent | ( | std::shared_ptr< ByteBuffer > & | bankBuffer, |
bool | force = false |
||
) |
Write an event (bank) to the buffer in evio version 4 format.
The given event buffer must contain only the event's data (event header and event data) and must not be in complete evio file format. If the internal buffer is full, it will be flushed to the file if writing to a file. Otherwise an exception will be thrown. Do not call this while simultaneously calling close, flush, setFirstEvent, or getByteBuffer.
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. |
IOException | if error writing file |
EvioException | 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; |
References writeEvent().
bool evio::EventWriterV4::writeEvent | ( | std::shared_ptr< EvioBank > | bank, |
bool | force = false |
||
) |
Write an event (bank) to a buffer containing evio version 4 format blocks.
Each block has an integral number of events. There are limits to the number of events in each block and the total size of each block. If writing to a file, each full buffer is written - one at a time - and may contain multiple blocks. Dictionary is never written with this method. Do not call this while simultaneously calling close, flush, setFirstEvent, or getByteBuffer.
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. |
IOException | if error writing file |
EvioException | if close() already called; if file could not be opened for writing; if file exists but user requested no over-writing; |
References writeEvent().
bool evio::EventWriterV4::writeEvent | ( | std::shared_ptr< EvioNode > & | node, |
bool | force, | ||
bool | duplicate = true |
||
) |
Write an event (bank) to the buffer in evio version 4 format.
If the internal buffer is full, it will be flushed to the file if writing to a file. Otherwise an exception will be thrown. Do not call this while simultaneously calling close, flush, setFirstEvent, or getByteBuffer.
node | object representing the event to write in buffer form |
force | 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. |
IOException | if error writing file |
EvioException | 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; |
Referenced by setFirstEvent(), and writeEvent().
bool evio::EventWriterV4::writeEventToFile | ( | std::shared_ptr< EvioBank > | bank, |
std::shared_ptr< ByteBuffer > | bankBuffer, | ||
bool | force | ||
) |
Write an event (bank) into a block and eventually to a file in evio version 4 format.
This method will not work with this object setup to write into a buffer.
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(std::shared_ptr<EvioBank>, std::shared_ptr<ByteBuffer>, bool) (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. |
EvioException | 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; if error writing file; |
References evio::ByteOrder::getName(), and evio::Util::printBytes().
bool evio::EventWriterV4::writeEventToFile | ( | std::shared_ptr< EvioNode > & | node, |
bool | force, | ||
bool | duplicate | ||
) |
Write an event (bank) into a record and eventually to a file in evio version 4 format.
If the internal buffer is full, it will be flushed to the file. Otherwise an exception will be thrown.
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(std::shared_ptr<EvioNode>, bool, bool) (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 form |
force | 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. |
IOException | if error writing file |
EvioException | 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; |
|
static |
The default maximum event count for a single block used for writing.
|
static |
The default maximum size, in bytes, for a single block used for writing.
It's set to 16MB (2^24) since that's an efficient number for writing to modern disks. And it is consistent with the java version of this class. It is a soft limit since a single event larger than this limit may need to be written.
|
static |
The default byte size of internal buffer.
It's enforced to be, at a minimum, DEFAULT_BLOCK_SIZE + a little.