LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
MT::LCWriter Class Reference

LCWriter class. More...

#include <LCWriter.h>

Public Member Functions

 LCWriter ()=default
 Default constructor. More...
 
 LCWriter (const LCWriter &)=delete
 no copy constructor More...
 
LCWriteroperator= (const LCWriter &)=delete
 no assignment operator More...
 
 ~LCWriter ()=default
 Destructor. More...
 
void open (const std::string &filename)
 Opens a file for writing. More...
 
void open (const std::string &filename, int writeMode)
 Opens a file for writing. More...
 
void setCompressionLevel (int level)
 Set the compression level - needs to be called before open() otherwise call will have no effect. More...
 
void writeRunHeader (EVENT::LCRunHeader *hdr)
 Writes the given run header to file. More...
 
void writeEvent (EVENT::LCEvent *evt)
 Writes the given event to file. More...
 
void writeEvent (EVENT::LCEvent *evt, const std::set< std::string > &colsOnly)
 Writes the given event to file, but write only the spcified collections. More...
 
void close ()
 Closes the output file/stream. More...
 

Static Private Member Functions

static std::string getSIOFileName (const std::string &filename)
 

Private Attributes

std::ofstream _stream {}
 The output file stream. More...
 
std::atomic< unsigned int > _maxBufferSize {2*1204*1024}
 The compression level. More...
 
std::atomic< int > _compressionLevel {-1}
 The compression level. More...
 
std::shared_ptr
< SIO::LCIORandomAccessMgr
_raMgr {nullptr}
 The random access manager for event/run random access in the file. More...
 
std::mutex _mutex {}
 Synchronization mutex. More...
 

Detailed Description

LCWriter class.

    Implement a writer for events and run headers using SIO.
    Thread safety specifications:
    - Writing two events from different threads is safe
    - Writing an event and a run header from different threads is safe
    - Opening/closing a file and writing might throw an exception depending on the scheduling
    A mutex ensures that no data race will occur but won't protect
    against race conditions
Author
R. Ete, DESY

Definition at line 42 of file LCWriter.h.

Constructor & Destructor Documentation

MT::LCWriter::LCWriter ( )
default

Default constructor.

MT::LCWriter::LCWriter ( const LCWriter )
delete

no copy constructor

MT::LCWriter::~LCWriter ( )
default

Destructor.

Member Function Documentation

void MT::LCWriter::close ( )

Closes the output file/stream.

Definition at line 202 of file LCWriter.cc.

References _mutex, _raMgr, _stream, and std::ofstream::close().

std::string MT::LCWriter::getSIOFileName ( const std::string filename)
staticprivate

Definition at line 212 of file LCWriter.cc.

References SIO::LCSIO::FileExtension, std::string::length(), and std::string::rfind().

Referenced by open().

void MT::LCWriter::open ( const std::string filename)

Opens a file for writing.

If file with given name exists, an exception is thrown. Use append or new mode instead.

Definition at line 21 of file LCWriter.cc.

References getSIOFileName().

void MT::LCWriter::open ( const std::string filename,
int  writeMode 
)

Opens a file for writing.

Possible write modes are: LCIO::WRITE_NEW (existing files are replaced) and LCIO::WRITE_APPEND.

Definition at line 37 of file LCWriter.cc.

References _mutex, _raMgr, _stream, getSIOFileName(), std::ofstream::good(), std::ofstream::is_open(), std::ofstream::open(), SIO::LCSIO::RandomAccessSize, std::ofstream::seekp(), std::stringstream::str(), and std::ofstream::tellp().

LCWriter& MT::LCWriter::operator= ( const LCWriter )
delete

no assignment operator

void MT::LCWriter::setCompressionLevel ( int  level)

Set the compression level - needs to be called before open() otherwise call will have no effect.

If not called the Writer will use default compression.
Valid compression levels are:

  • level < 0 : default compression
  • level == 0 : no compression
  • level > 0 : compression level (typically 1 (fastest) - 9 (best compression)) No data race expected (atomic variable in use) but a race condition can occur if the compression level is set while write a record
Parameters
levelcompression level

Definition at line 84 of file LCWriter.cc.

References _compressionLevel.

void MT::LCWriter::writeEvent ( EVENT::LCEvent evt)

Writes the given event to file.

Definition at line 140 of file LCWriter.cc.

void MT::LCWriter::writeEvent ( EVENT::LCEvent evt,
const std::set< std::string > &  colsOnly 
)
void MT::LCWriter::writeRunHeader ( EVENT::LCRunHeader hdr)

Member Data Documentation

std::atomic<int> MT::LCWriter::_compressionLevel {-1}
private

The compression level.

Definition at line 109 of file LCWriter.h.

Referenced by setCompressionLevel(), writeEvent(), and writeRunHeader().

std::atomic<unsigned int> MT::LCWriter::_maxBufferSize {2*1204*1024}
private

The compression level.

Definition at line 107 of file LCWriter.h.

Referenced by writeEvent(), and writeRunHeader().

std::mutex MT::LCWriter::_mutex {}
private

Synchronization mutex.

Definition at line 113 of file LCWriter.h.

Referenced by close(), open(), writeEvent(), and writeRunHeader().

std::shared_ptr<SIO::LCIORandomAccessMgr> MT::LCWriter::_raMgr {nullptr}
private

The random access manager for event/run random access in the file.

Definition at line 111 of file LCWriter.h.

Referenced by close(), open(), writeEvent(), and writeRunHeader().

std::ofstream MT::LCWriter::_stream {}
private

The output file stream.

Definition at line 105 of file LCWriter.h.

Referenced by close(), open(), writeEvent(), and writeRunHeader().


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