lcls2
C++ API: public headers of xtcdata, psalg, psdaq and psana
Loading...
Searching...
No Matches
Drp::BufferedFileWriter Class Reference

Single-threaded file writer that collects events in one memory buffer and writes the buffer when the next event does not fit or the batch is more than 2 s old (by timestamp seconds). More...

#include <FileWriter.hh>

Inherits Drp::FileWriterBase.

Public Member Functions

 BufferedFileWriter (size_t bufferSize)
 Allocate a buffer of bufferSize bytes; no file is open yet.
 
 ~BufferedFileWriter () override
 Call close().
 
int open (const std::string &fileName) override
 Close any open file (with a warning), create or truncate fileName with read permission for owner and group, and wait for a write lock on it.
 
int close () override
 If a file is open, write the buffered bytes and close it.
 
void writeEvent (const void *data, size_t size, XtcData::TimeStamp ts) override
 Append size bytes from data to the buffer.
 
- Public Member Functions inherited from Drp::FileWriterBase
 FileWriterBase ()
 Start with the writing counter at 0.
 
virtual ~FileWriterBase ()
 Does nothing; empty body.
 
virtual uint64_t writing () const
 Return the writing counter (non-zero while an implementation is inside a write).
 

Additional Inherited Members

- Protected Attributes inherited from Drp::FileWriterBase
volatile uint64_t m_writing
 

Detailed Description

Single-threaded file writer that collects events in one memory buffer and writes the buffer when the next event does not fit or the batch is more than 2 s old (by timestamp seconds).

Constructor & Destructor Documentation

◆ BufferedFileWriter()

Drp::BufferedFileWriter::BufferedFileWriter ( size_t  bufferSize)

Allocate a buffer of bufferSize bytes; no file is open yet.

◆ ~BufferedFileWriter()

Drp::BufferedFileWriter::~BufferedFileWriter ( )
override

Call close().

Member Function Documentation

◆ close()

int Drp::BufferedFileWriter::close ( )
overridevirtual

If a file is open, write the buffered bytes and close it.

Returns the close() result, or 0 if no file was open.

Implements Drp::FileWriterBase.

◆ open()

int Drp::BufferedFileWriter::open ( const std::string &  fileName)
overridevirtual

Close any open file (with a warning), create or truncate fileName with read permission for owner and group, and wait for a write lock on it.

Returns 0, or -1 if the file cannot be created or locked.

Implements Drp::FileWriterBase.

◆ writeEvent()

void Drp::BufferedFileWriter::writeEvent ( const void *  data,
size_t  size,
XtcData::TimeStamp  ts 
)
overridevirtual

Append size bytes from data to the buffer.

The buffer is written out first if data does not fit or the batch started more than 2 s earlier; a datagram larger than the free space is written through the buffer in chunks. Aborts if a write fails.

Implements Drp::FileWriterBase.


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