LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
UTIL::LCSplitWriter Class Reference

LCWriter wrapper that automatically splits files if a given number of bytes is exceeded. More...

#include <LCSplitWriter.h>

+ Inheritance diagram for UTIL::LCSplitWriter:

Public Member Functions

 LCSplitWriter (IO::LCWriter *wrt, EVENT::long64 maxBytes)
 The constructor. More...
 
 LCSplitWriter (const LCSplitWriter &)=delete
 no copy constructor More...
 
LCSplitWriteroperator= (const LCSplitWriter &)=delete
 no assignment operator More...
 
virtual ~LCSplitWriter ()
 Destructor. More...
 
virtual void open (const std::string &filename)
 Opens a file for writing where the filename has to include the extension but not the number, e.g. More...
 
virtual void open (const std::string &filename, int writeMode)
 Not implemented - will throw an Exception if called. More...
 
virtual void writeRunHeader (const EVENT::LCRunHeader *hdr)
 Writes the given run header to file. More...
 
virtual void setCompressionLevel (int level)
 Set CompressionLevel. More...
 
virtual void writeEvent (const EVENT::LCEvent *evt)
 Writes the given file to file. More...
 
virtual void close ()
 Closes the output file/stream. More...
 
virtual void flush ()
 Flushes the output file/stream. More...
 
EVENT::long64 fileSize ()
 Return the current file size in bytes. More...
 
- Public Member Functions inherited from IO::LCWriter
virtual ~LCWriter ()
 Destructor. More...
 

Protected Member Functions

 LCSplitWriter ()
 
EVENT::long64 file_size (const char *fname)
 Helper function that returns the file size in bytes - o if the file does not exist. More...
 
const std::stringgetFilename ()
 Get the complete filename w/o extensiomn,e.g. More...
 
void setBaseFilename (const std::string &filename)
 Helper function to determine base file name, i.e. More...
 
std::string getCountingString (unsigned count)
 Returns the string representation of the file number, e.g. More...
 

Protected Attributes

IO::LCWriter_wrt
 
EVENT::long64 _maxBytes
 
std::string _baseFilename
 
std::string _filename
 
std::string _extension
 
unsigned _count
 
unsigned _lastCount
 

Detailed Description

LCWriter wrapper that automatically splits files if a given number of bytes is exceeded.

File names are extended by a file number of the form .000 - .999 ...

Author
gaede
Version
Id:
LCSplitWriter.h,v 1.2 2007-11-09 21:00:55 gaede Exp

Definition at line 16 of file LCSplitWriter.h.

Constructor & Destructor Documentation

UTIL::LCSplitWriter::LCSplitWriter ( IO::LCWriter wrt,
EVENT::long64  maxBytes 
)
inline

The constructor.

Takes a pointer to a valid LCWriter instance and the file size in bytes that causes a new file to be opened if exceeded. example:
// replace LCWriter* lcWrt = LCFactory::getInstance()->createLCWriter() ; // with LCSplitWriter* lcWrt = new LCSplitWriter( LCFactory::getInstance()->createLCWriter() , 2040109465 ) ;
to automatically split files after 1.9 GByte file size has been exceeded.

Definition at line 28 of file LCSplitWriter.h.

UTIL::LCSplitWriter::LCSplitWriter ( const LCSplitWriter )
delete

no copy constructor

virtual UTIL::LCSplitWriter::~LCSplitWriter ( )
inlinevirtual

Destructor.

Definition at line 45 of file LCSplitWriter.h.

UTIL::LCSplitWriter::LCSplitWriter ( )
protected

Member Function Documentation

void UTIL::LCSplitWriter::close ( )
virtual

Closes the output file/stream.

Exceptions
IO::IOException

Implements IO::LCWriter.

Definition at line 73 of file LCSplitWriter.cc.

long64 UTIL::LCSplitWriter::file_size ( const char *  fname)
protected

Helper function that returns the file size in bytes - o if the file does not exist.

Definition at line 96 of file LCSplitWriter.cc.

References STAT64.

long64 UTIL::LCSplitWriter::fileSize ( )

Return the current file size in bytes.

Definition at line 108 of file LCSplitWriter.cc.

void UTIL::LCSplitWriter::flush ( )
virtual

Flushes the output file/stream.

Exceptions
IO::IOException

Implements IO::LCWriter.

Definition at line 77 of file LCSplitWriter.cc.

std::string UTIL::LCSplitWriter::getCountingString ( unsigned  count)
protected

Returns the string representation of the file number, e.g.

"007".

Definition at line 142 of file LCSplitWriter.cc.

References NDIGITS, std::setfill(), std::setw(), and std::stringstream::str().

const std::string & UTIL::LCSplitWriter::getFilename ( )
protected

Get the complete filename w/o extensiomn,e.g.

MyFilename.007

Definition at line 84 of file LCSplitWriter.cc.

void UTIL::LCSplitWriter::open ( const std::string filename)
virtual

Opens a file for writing where the filename has to include the extension but not the number, e.g.

myfile.slcio. Note that this is different from the LCWriter specification.

Exceptions
IO::IOException

Implements IO::LCWriter.

Definition at line 31 of file LCSplitWriter.cc.

void UTIL::LCSplitWriter::open ( const std::string filename,
int  writeMode 
)
virtual

Not implemented - will throw an Exception if called.

Overwriting of or appending to split files is not straight forward. Pleas use the default write mode and remove exisiting files.

Exceptions
IO::IOException

Implements IO::LCWriter.

Definition at line 37 of file LCSplitWriter.cc.

LCSplitWriter& UTIL::LCSplitWriter::operator= ( const LCSplitWriter )
delete

no assignment operator

void UTIL::LCSplitWriter::setBaseFilename ( const std::string filename)
protected

Helper function to determine base file name, i.e.

w/o extension.

Definition at line 123 of file LCSplitWriter.cc.

References std::string::find_last_of(), std::string::length(), std::string::rfind(), and std::string::substr().

virtual void UTIL::LCSplitWriter::setCompressionLevel ( int  level)
inlinevirtual

Set CompressionLevel.

See Also
LCWriter::setCompressionLevel()

Implements IO::LCWriter.

Definition at line 76 of file LCSplitWriter.h.

References _wrt, and IO::LCWriter::setCompressionLevel().

void UTIL::LCSplitWriter::writeEvent ( const EVENT::LCEvent evt)
virtual

Writes the given file to file.

Opens a new file if the given file size is already exceeded before the execution of the write access.

Exceptions
IO::IOException

Implements IO::LCWriter.

Definition at line 54 of file LCSplitWriter.cc.

void UTIL::LCSplitWriter::writeRunHeader ( const EVENT::LCRunHeader hdr)
virtual

Writes the given run header to file.

Opens a new file if the given file size is already exceeded before the execution of the write access.

Exceptions
IO::IOException

Implements IO::LCWriter.

Definition at line 42 of file LCSplitWriter.cc.

Member Data Documentation

std::string UTIL::LCSplitWriter::_baseFilename
protected

Definition at line 131 of file LCSplitWriter.h.

unsigned UTIL::LCSplitWriter::_count
protected

Definition at line 134 of file LCSplitWriter.h.

std::string UTIL::LCSplitWriter::_extension
protected

Definition at line 133 of file LCSplitWriter.h.

std::string UTIL::LCSplitWriter::_filename
protected

Definition at line 132 of file LCSplitWriter.h.

unsigned UTIL::LCSplitWriter::_lastCount
protected

Definition at line 135 of file LCSplitWriter.h.

EVENT::long64 UTIL::LCSplitWriter::_maxBytes
protected

Definition at line 130 of file LCSplitWriter.h.

IO::LCWriter* UTIL::LCSplitWriter::_wrt
protected

Definition at line 129 of file LCSplitWriter.h.

Referenced by setCompressionLevel().


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