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

File writer with a pool of page-aligned buffers and a writer thread: writeEvent() fills buffers and queues full ones, and the thread writes them to the file. More...

#include <FileWriter.hh>

Inherits Drp::FileWriterBase.

Public Member Functions

 BufferedFileWriterMT (size_t bufferSize)
 Create 64 buffers of bufferSize bytes rounded up to whole pages and start the writer thread.
 
 BufferedFileWriterMT (size_t bufferSize, bool dio)
 Like BufferedFileWriterMT(bufferSize).
 
 ~BufferedFileWriterMT () override
 Close the file, stop and join the writer thread, and free the buffers in the free queue.
 
int open (const std::string &fileName) override
 Like BufferedFileWriter::open(), adding O_DIRECT when direct I/O was requested.
 
int close () override
 If a file is open, call flush() (which waits until all queued buffers are written) and close the file.
 
void flush ()
 Queue the current buffer if it holds data, then block until the writer thread has written everything queued.
 
void writeEvent (const void *data, size_t size, XtcData::TimeStamp ts) override
 Copy size bytes from data into the current free buffer, first queueing that buffer if data does not fit or the batch is more than 2 s old; a datagram larger than the free space is split across buffers.
 
void run ()
 Writer thread body started by the constructor: name the thread drp/FileWriter, write each queued buffer to the file and return it to the free queue, until terminated with nothing queued.
 
uint64_t depth () const
 Return the number of free buffers recorded at the last queue operation.
 
uint64_t size () const
 Return the number of buffers in the pool.
 
uint64_t freeBlocked () const
 Return the counter that is raised while writeEvent() waits for a free buffer.
 
uint64_t pendBlocked () const
 Return the counter that is raised while flush() or the writer thread waits on the pending queue.
 
- 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

File writer with a pool of page-aligned buffers and a writer thread: writeEvent() fills buffers and queues full ones, and the thread writes them to the file.

Constructor & Destructor Documentation

◆ BufferedFileWriterMT() [1/2]

Drp::BufferedFileWriterMT::BufferedFileWriterMT ( size_t  bufferSize)

Create 64 buffers of bufferSize bytes rounded up to whole pages and start the writer thread.

◆ BufferedFileWriterMT() [2/2]

Drp::BufferedFileWriterMT::BufferedFileWriterMT ( size_t  bufferSize,
bool  dio 
)

Like BufferedFileWriterMT(bufferSize).

With dio true there are 2 buffers, each the smallest multiple of bufferSize that is at least 512 MiB (then rounded up to whole pages), and files are opened with O_DIRECT.

◆ ~BufferedFileWriterMT()

Drp::BufferedFileWriterMT::~BufferedFileWriterMT ( )
override

Close the file, stop and join the writer thread, and free the buffers in the free queue.

Member Function Documentation

◆ close()

int Drp::BufferedFileWriterMT::close ( )
overridevirtual

If a file is open, call flush() (which waits until all queued buffers are written) and close the file.

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

Implements Drp::FileWriterBase.

◆ depth()

uint64_t Drp::BufferedFileWriterMT::depth ( ) const
inline

Return the number of free buffers recorded at the last queue operation.

◆ flush()

void Drp::BufferedFileWriterMT::flush ( )

Queue the current buffer if it holds data, then block until the writer thread has written everything queued.

◆ freeBlocked()

uint64_t Drp::BufferedFileWriterMT::freeBlocked ( ) const
inline

Return the counter that is raised while writeEvent() waits for a free buffer.

◆ open()

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

Like BufferedFileWriter::open(), adding O_DIRECT when direct I/O was requested.

Implements Drp::FileWriterBase.

◆ pendBlocked()

uint64_t Drp::BufferedFileWriterMT::pendBlocked ( ) const
inline

Return the counter that is raised while flush() or the writer thread waits on the pending queue.

◆ run()

void Drp::BufferedFileWriterMT::run ( )

Writer thread body started by the constructor: name the thread drp/FileWriter, write each queued buffer to the file and return it to the free queue, until terminated with nothing queued.

Aborts if a write fails.

◆ size()

uint64_t Drp::BufferedFileWriterMT::size ( ) const
inline

Return the number of buffers in the pool.

◆ writeEvent()

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

Copy size bytes from data into the current free buffer, first queueing that buffer if data does not fit or the batch is more than 2 s old; a datagram larger than the free space is split across buffers.

Blocks while no free buffer is available.

Implements Drp::FileWriterBase.


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