6 #include "EVENT/LCIO.h"
11 #include <sio/exception.h>
13 #include <sio/compression/zlib.h>
23 struct stat fileinfo ;
25 if ( ::stat( sioFilename.
c_str(), &fileinfo ) == 0 ) {
28 +
" \n open it in append or new mode !\n"
32 open( filename, EVENT::LCIO::WRITE_NEW ) ;
45 sioFilename = filename ;
56 case EVENT::LCIO::WRITE_NEW :
57 _stream.open( sioFilename , std::ios::binary ) ;
59 case EVENT::LCIO::WRITE_APPEND :
61 SIO_DEBUG(
"SIOWriter::open: Opening in write append mode" );
63 istr.open( sioFilename, std::ios::binary ) ;
65 if( not istr.is_open() ) {
68 SIO_DEBUG(
"SIOWriter::open: Opening in write append mode 1" );
71 SIO_DEBUG(
"SIOWriter::open: Opening in write append mode 2" );
72 if( hasRandomAccess ) {
73 _stream.open( sioFilename.
c_str() , std::ios::binary | std::ios::out | std::ios::in ) ;
75 _stream.seekp( 0 , std::ios_base::end ) ;
82 _stream.seekp( endg - tpos , std::ios_base::beg ) ;
85 _stream.open( sioFilename.
c_str() , std::ios::binary | std::ios::out | std::ios::ate ) ;
87 SIO_DEBUG(
"SIOWriter::open: Opening in write append mode ... OK" );
91 SIO_THROW( sio::error_code::not_open,
"[SIOWriter::open()] Couldn't open file: '" + sioFilename +
"'" ) ;
107 throw IO::IOException(
"[SIOWriter::writeRunHeader] stream not opened") ;
109 sio::record_info recinfo {} ;
131 sio::record_info rechdrinfo {} ;
145 sio::record_info recinfo {} ;
void getSIOFileName(const std::string &filename, std::string &sioFilename)
Creates a proper filename with extension 'slcio' in sioFilename.
SIOHandlerMgr _eventHandlerMgr
The collection block handler manager for events.
static constexpr int RandomAccessSize
virtual void close()
Closes the output file/stream etc.
bool initAppend(sio::ifstream &stream)
Initialize random access for append mode: read last LCIORandomAccess record if it exists - recreate t...
Helper struct that stores run and event positions in the file.
sio::ofstream _stream
The output file stream.
virtual int getRunNumber() const =0
Return the run number off this event.
static void writeRecord(sio::buffer &outbuf, EVENT::LCEvent *event, const SIOHandlerMgr &handlerMgr, sio::record_info &rec_info, sio::options_type opts=0)
Write an event record.
sio::buffer _rawBuffer
The raw buffer for writing bytes to the stream.
sio::buffer _compBuffer
The raw buffer for compression.
virtual void flush()
Flushes the output file/stream etc.
virtual void writeRunHeader(const EVENT::LCRunHeader *hdr)
Writes the given run header to file.
virtual void setCompressionLevel(int level)
Set the compression level - needs to be called before open() otherwise call will have no effect...
void add(const RunEvent &re, long64 pos)
Add a new entry to the event map - if the RunEvent already exists the new position will be stored...
sio::zlib_compression _compressor
The compression in use.
IOException used for reading/writing errors.
static constexpr const char * FileExtension
The lcio file extension name.
The main event interface.
virtual int getEventNumber() const =0
Returns this event's number .
void writeRandomAccessRecords(sio::ofstream &stream)
Write the current random access records LCIOIndex and LCIORandomAccess to the stream.
pair< int, string > level
virtual void writeEvent(const EVENT::LCEvent *evt)
Writes the given event to file.
virtual void open(const std::string &filename)
Opens a file for writing.
void clear()
Clear all lists and maps before closing a file.
LCIORandomAccessMgr _raMgr
The random access manager.