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

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< ByteBuffergetByteBuffer ()
 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...
 

Detailed Description

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.

Author
Carl Timmer.
Date
5/14/24.

Constructor & Destructor Documentation

◆ EventWriterV4() [1/5]

evio::EventWriterV4::EventWriterV4 ( std::string &  filename,
const ByteOrder byteOrder = ByteOrder::nativeOrder(),
bool  append = false 
)
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.

Parameters
filenamename of the file to write to.
appendif true and the file already exists, all events to be written will be appended to the end of the file.
byteOrderthe byte order in which to write the file.
Exceptions
EvioExceptionfile cannot be created, or if appending and file is too small to be evio format;

◆ EventWriterV4() [2/5]

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.

Parameters
filenamethe file object to write to.
xmlDictionarydictionary in xml format or empty if none.
byteOrderthe byte order in which to write the file.
appendif true and the file already exists, all events to be written will be appended to the end of the file.
Exceptions
EvioExceptionfile cannot be created, or if appending and file is too small to be evio format;

◆ EventWriterV4() [3/5]

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.

Parameters
baseNamebase file name used to generate complete file name (may not be empty)
directorydirectory in which file is to be placed
runTypename of run type configuration to be used in naming files
runNumbernumber of the CODA run, used in naming files
splitif < 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.
maxBlockSizethe 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.
maxEventCountthe max number of events (including dictionary) in a single block which must be >= #MIN_BLOCK_COUNT and <= #MAX_BLOCK_COUNT.
byteOrderthe byte order in which to write the file. This is ignored if appending to existing file.
xmlDictionarydictionary in xml format or empty if none.
overWriteOKif false and the file already exists, an exception is thrown rather than overwriting it.
appendif true append written data to given file.
firstEventthe 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.
streamIdstreamId number (100 > id > -1) for file name
splitNumbernumber at which to start the split numbers
splitIncrementamount to increment split number each time another file is created.
streamCounttotal number of streams in DAQ.
bufferSizenumber 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.
bitInfoset of bits to include in first block header.
Exceptions
EvioExceptionif 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().

◆ EventWriterV4() [4/5]

evio::EventWriterV4::EventWriterV4 ( std::shared_ptr< ByteBuffer > &  buf,
const std::string &  xmlDictionary = "",
bool  append = false 
)
explicit

Create an EventWriterV4 for writing events to a ByteBuffer.

Uses the default number and size of blocks in buffer.

Parameters
bufthe buffer to write to.
xmlDictionarydictionary in xml format or null if none.
appendif true, all events to be written will be appended to the end of the buffer.
Exceptions
EvioExceptionif appending and buffer is too small to be evio format;

◆ EventWriterV4() [5/5]

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.

Parameters
bufthe buffer to write to.
maxBlockSizethe 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.
maxEventCountthe max number of events (including dictionary) in a single block which must be >= #MIN_BLOCK_COUNT and <= #MAX_BLOCK_COUNT.
xmlDictionarydictionary in xml format or null if none.
bitInfoset of bits to include in first block header.
reserved1set the value of the first "reserved" int in first block header. NOTE: only CODA (i.e. EMU) software should use this.
blockNumbernumber at which to start block number counting.
appendif true, all events to be written will be appended to the end of the buffer.
firstEventthe 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.
Exceptions
EvioExceptionif maxBlockSize or maxEventCount exceed limits; if appending and buffer is too small to be evio format; if defined dictionary while appending;

Member Function Documentation

◆ close()

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.

◆ examineFirstBlockHeader()

void evio::EventWriterV4::examineFirstBlockHeader ( )
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.

Exceptions
EvioExceptionif 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().

◆ flush()

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.

◆ getBlockNumber()

uint32_t evio::EventWriterV4::getBlockNumber ( ) const

Get the current block number.

Warning, this value may be changing.

Returns
the current block number.

◆ getByteBuffer()

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.

Returns
buffer being written into, made ready for reading; null if writing to file

References isToFile().

◆ getByteOrder()

ByteOrder evio::EventWriterV4::getByteOrder ( ) const

Get the byte order of the buffer/file being written into.

Returns
byte order of the buffer/file being written into.

◆ getBytesWrittenToBuffer()

uint64_t evio::EventWriterV4::getBytesWrittenToBuffer ( ) const

If writing to a buffer, get the number of bytes written to it including the ending header.

Returns
number of bytes written to buffer

◆ getCurrentFilename()

std::string evio::EventWriterV4::getCurrentFilename ( ) const

Get the name of the current file being written to.

Returns empty string if no file.

Returns
the name of the current file being written to.

◆ getCurrentFilePath()

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.

Returns
the absolute name or path of the current file being written to.

◆ getEventsWritten()

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.

Returns
number of events written to a file/buffer.

◆ getSplitCount()

uint32_t evio::EventWriterV4::getSplitCount ( ) const

Get the number of split files produced by this writer.

Returns
number of split files produced by this writer.

◆ getSplitNumber()

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.

Returns
the current split count which is the number of files created by this object.

◆ hasRoom()

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.

Parameters
bytesnumber of bytes to write
Returns
true
if there still room in the output buffer, else
false
.

References isToFile().

◆ isClosed()

bool evio::EventWriterV4::isClosed ( )

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

Returns
true
if this object closed, else
false
.

◆ isDiskFull()

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.

Returns
true if the partition the file resides on is full, else false.

◆ isToFile()

bool evio::EventWriterV4::isToFile ( ) const

Is this object writing to file?

Returns
true
if writing to file, else
false
.

Referenced by getByteBuffer(), and hasRoom().

◆ setBuffer() [1/2]

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.

Parameters
bufthe buffer to write to.
Exceptions
EvioExceptionif this object was not closed prior to resetting the buffer, buffer arg is null, or in appending mode.

◆ setBuffer() [2/2]

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.

Parameters
bufthe buffer to write to.
bitInfoset of bits to include in first block header.
blockNumbernumber at which to start block number counting.
Exceptions
EvioExceptionif this object was not closed prior to resetting the buffer, buffer arg is null, or in appending mode.

◆ setFirstEvent() [1/3]

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.

Parameters
bufferbuffer containing event to be placed first in each file written including all splits. If null, no more first events are written to any files.
Exceptions
IOExceptionif error writing file
EvioExceptionif 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().

◆ setFirstEvent() [2/3]

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.

Parameters
bankevent to be placed first in each file written including all splits. If null, no more first events are written to any files.
Exceptions
IOExceptionif error writing file
EvioExceptionif 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().

◆ setFirstEvent() [3/3]

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.

Parameters
nodenode representing event to be placed first in each file written including all splits. If null, no more first events are written to any files.
Exceptions
IOExceptionif error writing file
EvioExceptionif 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().

◆ setStartingBlockNumber()

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.

Parameters
startingBlockNumberthe number with which to start block numbers.

◆ writeEvent() [1/3]

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.

Parameters
bankBufferthe bank (as a ByteBuffer object) to write.
forceif writing to disk, force it to write event to the disk.
Returns
if writing to buffer: true if event was added to record, false if buffer full, or bank and bankBuffer args are both null. If there is an InterruptedException.
Exceptions
IOExceptionif error writing file
EvioExceptionif 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().

◆ writeEvent() [2/3]

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.

Parameters
bankthe bank to write.
forceif writing to disk, force it to write event to the disk.
Returns
if writing to buffer: true if event was added to record, false if buffer full, or bank and bankBuffer args are both null. If there is an InterruptedException.
Exceptions
IOExceptionif error writing file
EvioExceptionif close() already called; if file could not be opened for writing; if file exists but user requested no over-writing;

References writeEvent().

◆ writeEvent() [3/3]

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.

Parameters
nodeobject representing the event to write in buffer form
forceif writing to disk, force it to write event to the disk.
duplicateif true, duplicate node's buffer so its position and limit can be changed without issue.
Returns
if writing to buffer: true if event was added to record, false if buffer full, or bank and bankBuffer args are both null. If there is an InterruptedException.
Exceptions
IOExceptionif error writing file
EvioExceptionif 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().

◆ writeEventToFile() [1/2]

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.

Parameters
bankthe bank (as an EvioBank object) to write.
bankBufferthe bank (as a ByteBuffer object) to write.
forceif writing to disk, force it to write event to the disk.
Returns
true if event was added to block. If splitting files, false if disk partition too full to write the complete, next split file. False if interrupted. If force arg is true, write anyway.
Exceptions
EvioExceptionif 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().

◆ writeEventToFile() [2/2]

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.

Parameters
nodeobject representing the event to write in buffer form
forceif writing to disk, force it to write event to the disk.
duplicateif true, duplicate node's buffer so its position and limit can be changed without issue.
Returns
true if event was added to record. If splitting files, false if disk partition too full to write the complete, next split file. False if interrupted. If force arg is true, write anyway.
Exceptions
IOExceptionif error writing file
EvioExceptionif 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;

Member Data Documentation

◆ DEFAULT_BLOCK_COUNT

const int evio::EventWriterV4::DEFAULT_BLOCK_COUNT = 10000
static

The default maximum event count for a single block used for writing.

◆ DEFAULT_BLOCK_SIZE

const int evio::EventWriterV4::DEFAULT_BLOCK_SIZE = 16777216
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.

◆ DEFAULT_BUFFER_SIZE

const size_t evio::EventWriterV4::DEFAULT_BUFFER_SIZE = DEFAULT_BLOCK_SIZE + 1024
static

The default byte size of internal buffer.

It's enforced to be, at a minimum, DEFAULT_BLOCK_SIZE + a little.


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