rogue
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
rogue::utilities::fileio::StreamWriter Class Reference

Coordinates channelized frame capture into Rogue stream data files. More...

#include <StreamWriter.h>

Inheritance diagram for rogue::utilities::fileio::StreamWriter:
rogue::EnableSharedFromThis< rogue::utilities::fileio::StreamWriter > rogue::EnableSharedFromThisBase

Public Member Functions

 StreamWriter ()
 Constructs a stream writer.
 
virtual ~StreamWriter ()
 Destroys the stream writer and closes open resources.
 
void open (std::string file)
 Opens a data file.
 
void close ()
 Closes the currently open data file.
 
bool isOpen ()
 Returns whether a data file is open.
 
void setRaw (bool raw)
 Sets raw output mode.
 
bool getRaw ()
 Gets raw output mode state.
 
void setBufferSize (uint32_t size)
 Sets write buffering size.
 
void setMaxSize (uint64_t size)
 Sets automatic file rollover size.
 
void setDropErrors (bool drop)
 Configures whether errored frames are dropped.
 
std::shared_ptr< rogue::utilities::fileio::StreamWriterChannelgetChannel (uint8_t channel)
 Gets or creates a channel writer endpoint.
 
uint64_t getTotalSize ()
 Returns cumulative bytes written across all files.
 
uint64_t getCurrentSize ()
 Returns current output file size.
 
double getBandwidth ()
 Returns recent write bandwidth estimate.
 
uint32_t getFrameCount ()
 Returns number of frames written to the current file session.
 
bool waitFrameCount (uint32_t count, uint64_t timeout)
 Blocks until a target frame count is reached or timeout expires.
 
- Public Member Functions inherited from rogue::EnableSharedFromThis< rogue::utilities::fileio::StreamWriter >
std::shared_ptr< rogue::utilities::fileio::StreamWritershared_from_this ()
 Returns a shared_ptr<T> for this instance.
 
- Public Member Functions inherited from rogue::EnableSharedFromThisBase
virtual ~EnableSharedFromThisBase ()
 Virtual destructor for polymorphic base usage.
 

Static Public Member Functions

static std::shared_ptr< rogue::utilities::fileio::StreamWritercreate ()
 Creates a stream writer instance.
 
static void setup_python ()
 Registers Python bindings for this class.
 

Protected Member Functions

void intWrite (void *data, uint32_t size)
 Internal method for file writing with buffer and auto close and reopen.
 
void checkSize (uint32_t size)
 Check file size for next write.
 
void flush ()
 Flush file.
 
void recordBandwidth (uint32_t size)
 
void pruneBandwidth (std::chrono::steady_clock::time_point now)
 
virtual void writeFile (uint8_t channel, std::shared_ptr< rogue::interfaces::stream::Frame > frame)
 Write data to file. Called from StreamWriterChannel.
 

Protected Attributes

std::shared_ptr< rogue::Logginglog_
 
int32_t fd_
 
std::string baseName_
 
bool isOpen_
 
uint32_t fdIdx_
 
uint64_t sizeLimit_
 
uint64_t currSize_
 
uint64_t totSize_
 
uint32_t buffSize_
 
uint8_t * buffer_
 
uint32_t currBuffer_
 
bool dropErrors_
 
std::mutex mtx_
 
uint32_t frameCount_
 
uint64_t bandwidthBytes_
 
std::deque< std::pair< std::chrono::steady_clock::time_point, uint32_t > > bandwidthHistory_
 
bool raw_
 
std::condition_variable cond_
 
std::map< uint32_t, std::shared_ptr< rogue::utilities::fileio::StreamWriterChannel > > channelMap_
 

Friends

class StreamWriterChannel
 

Detailed Description

Coordinates channelized frame capture into Rogue stream data files.

StreamWriter accepts frames through StreamWriterChannel instances and serializes them into a shared output file (or indexed file set when setMaxSize() is enabled).

Default banked format:

Raw mode (setRaw(true)) bypasses bank headers and writes only payload bytes. This is useful for tools that expect a byte stream without Rogue framing metadata.

Definition at line 76 of file StreamWriter.h.

Constructor & Destructor Documentation

◆ StreamWriter()

rogue::utilities::fileio::StreamWriter::StreamWriter ( )

Constructs a stream writer.

Creator.

This constructor is a low-level C++ allocation path. Prefer create() when shared ownership or Python exposure is required.

Definition at line 90 of file StreamWriter.cpp.

◆ ~StreamWriter()

rogue::utilities::fileio::StreamWriter::~StreamWriter ( )
virtual

Destroys the stream writer and closes open resources.

Deconstructor.

Definition at line 109 of file StreamWriter.cpp.

Member Function Documentation

◆ checkSize()

void rogue::utilities::fileio::StreamWriter::checkSize ( uint32_t  size)
protected

Check file size for next write.

Definition at line 380 of file StreamWriter.cpp.

◆ close()

void rogue::utilities::fileio::StreamWriter::close ( )

Closes the currently open data file.

Close a data file.

Definition at line 153 of file StreamWriter.cpp.

◆ create()

rogue::utilities::fileio::StreamWriterPtr rogue::utilities::fileio::StreamWriter::create ( )
static

Creates a stream writer instance.

Class creation.

This static factory is the preferred construction path when the object is shared across Rogue graph connections or exposed to Python. It returns std::shared_ptr ownership compatible with Rogue pointer typedefs.

Returns
Shared pointer to the created writer.

Company : SLAC National Accelerator Laboratory

Description : Class to coordinate data file writing. This class supports multiple stream slaves, each with the ability to write to a common data file. The data file is a series of banks. Each bank has a channel and frame flags. The channel is per source and the lower 24 bits of the frame flags are used as the flags. The bank is proceeded by 2 - 32-bit headers to indicate bank information and length:

headerA: [31:0] = Length of data block in bytes headerB 31:24 = Channel ID 23:16 = Frame error 15:0 = Frame flags


This file is part of the rogue software platform. It is subject to the license terms in the LICENSE.txt file found in the top-level directory of this distribution and at: https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. No part of the rogue software platform, including this file, may be copied, modified, propagated, or distributed except according to the terms

contained in the LICENSE.txt file.

Definition at line 63 of file StreamWriter.cpp.

◆ flush()

void rogue::utilities::fileio::StreamWriter::flush ( )
protected

Flush file.

Definition at line 411 of file StreamWriter.cpp.

◆ getBandwidth()

double rogue::utilities::fileio::StreamWriter::getBandwidth ( )

Returns recent write bandwidth estimate.

Get instantaneous bandwidth in bytes per second over the last second.

Returns
Bandwidth in bytes per second.

Definition at line 242 of file StreamWriter.cpp.

◆ getChannel()

rogue::utilities::fileio::StreamWriterChannelPtr rogue::utilities::fileio::StreamWriter::getChannel ( uint8_t  channel)

Gets or creates a channel writer endpoint.

Get a slave port.

The returned StreamWriterChannel is a stream::Slave that routes frames into this writer with the specified channel ID.

Parameters
channelChannel ID.
Returns
Channel writer object bound to channel.

Definition at line 218 of file StreamWriter.cpp.

◆ getCurrentSize()

uint64_t rogue::utilities::fileio::StreamWriter::getCurrentSize ( )

Returns current output file size.

Get current file size.

Returns
Current file size in bytes.

Definition at line 235 of file StreamWriter.cpp.

◆ getFrameCount()

uint32_t rogue::utilities::fileio::StreamWriter::getFrameCount ( )

Returns number of frames written to the current file session.

Get current frame count.

Returns
Frame count.

Definition at line 258 of file StreamWriter.cpp.

◆ getRaw()

bool rogue::utilities::fileio::StreamWriter::getRaw ( )

Gets raw output mode state.

Get raw mode flag.

Returns
True when raw output mode is enabled.

Definition at line 175 of file StreamWriter.cpp.

◆ getTotalSize()

uint64_t rogue::utilities::fileio::StreamWriter::getTotalSize ( )

Returns cumulative bytes written across all files.

Get total file size.

Returns
Total written bytes.

Definition at line 228 of file StreamWriter.cpp.

◆ intWrite()

void rogue::utilities::fileio::StreamWriter::intWrite ( void *  data,
uint32_t  size 
)
protected

Internal method for file writing with buffer and auto close and reopen.

Definition at line 353 of file StreamWriter.cpp.

◆ isOpen()

bool rogue::utilities::fileio::StreamWriter::isOpen ( )

Returns whether a data file is open.

Get open status.

Returns
True if a file is open.

Definition at line 165 of file StreamWriter.cpp.

◆ open()

void rogue::utilities::fileio::StreamWriter::open ( std::string  file)

Opens a data file.

Open a data file.

Resets counters and bandwidth history. If a max size is configured, the first opened file is <file>.1 and rollover continues with .2, .3, etc.

Parameters
fileOutput file path.

Definition at line 114 of file StreamWriter.cpp.

◆ pruneBandwidth()

void rogue::utilities::fileio::StreamWriter::pruneBandwidth ( std::chrono::steady_clock::time_point  now)
protected

Definition at line 292 of file StreamWriter.cpp.

◆ recordBandwidth()

void rogue::utilities::fileio::StreamWriter::recordBandwidth ( uint32_t  size)
protected

Definition at line 300 of file StreamWriter.cpp.

◆ setBufferSize()

void rogue::utilities::fileio::StreamWriter::setBufferSize ( uint32_t  size)

Sets write buffering size.

Set buffering size, 0 to disable.

Changing size flushes pending data and reallocates internal buffer. A value of 0 disables staging and writes directly to the file.

Parameters
sizeBuffer size in bytes, 0 disables buffering.

Definition at line 180 of file StreamWriter.cpp.

◆ setDropErrors()

void rogue::utilities::fileio::StreamWriter::setDropErrors ( bool  drop)

Configures whether errored frames are dropped.

Set drop errors flag.

When enabled, frames with non-zero frame->getError() are skipped.

Parameters
dropTrue to drop errored frames instead of writing them.

Definition at line 213 of file StreamWriter.cpp.

◆ setMaxSize()

void rogue::utilities::fileio::StreamWriter::setMaxSize ( uint64_t  size)

Sets automatic file rollover size.

Set max file size, 0 for unlimited.

When non-zero, writes are split into indexed files (.1, .2, ...), and rollover occurs before a write that would exceed the limit.

Parameters
sizeMaximum file size in bytes, 0 for unlimited.

Definition at line 206 of file StreamWriter.cpp.

◆ setRaw()

void rogue::utilities::fileio::StreamWriter::setRaw ( bool  raw)

Sets raw output mode.

Set raw mode.

  • false (default): write banked Rogue format with length/header words.
  • true: write frame payload bytes only.
Parameters
rawTrue to write raw frame payload only.

Definition at line 170 of file StreamWriter.cpp.

◆ setup_python()

void rogue::utilities::fileio::StreamWriter::setup_python ( )
static

Registers Python bindings for this class.

Setup class in python.

Definition at line 69 of file StreamWriter.cpp.

◆ waitFrameCount()

bool rogue::utilities::fileio::StreamWriter::waitFrameCount ( uint32_t  count,
uint64_t  timeout 
)

Blocks until a target frame count is reached or timeout expires.

Parameters
countTarget frame count threshold.
timeoutTimeout in microseconds. 0 waits indefinitely.
Returns
True if threshold reached before timeout.

Definition at line 262 of file StreamWriter.cpp.

◆ writeFile()

void rogue::utilities::fileio::StreamWriter::writeFile ( uint8_t  channel,
std::shared_ptr< rogue::interfaces::stream::Frame frame 
)
protectedvirtual

Write data to file. Called from StreamWriterChannel.

Definition at line 309 of file StreamWriter.cpp.

Friends And Related Symbol Documentation

◆ StreamWriterChannel

friend class StreamWriterChannel
friend

Definition at line 77 of file StreamWriter.h.

Member Data Documentation

◆ bandwidthBytes_

uint64_t rogue::utilities::fileio::StreamWriter::bandwidthBytes_
protected

Definition at line 123 of file StreamWriter.h.

◆ bandwidthHistory_

std::deque<std::pair<std::chrono::steady_clock::time_point, uint32_t> > rogue::utilities::fileio::StreamWriter::bandwidthHistory_
protected

Definition at line 126 of file StreamWriter.h.

◆ baseName_

std::string rogue::utilities::fileio::StreamWriter::baseName_
protected

Definition at line 87 of file StreamWriter.h.

◆ buffer_

uint8_t* rogue::utilities::fileio::StreamWriter::buffer_
protected

Definition at line 108 of file StreamWriter.h.

◆ buffSize_

uint32_t rogue::utilities::fileio::StreamWriter::buffSize_
protected

Definition at line 105 of file StreamWriter.h.

◆ channelMap_

std::map<uint32_t, std::shared_ptr<rogue::utilities::fileio::StreamWriterChannel> > rogue::utilities::fileio::StreamWriter::channelMap_
protected

Definition at line 149 of file StreamWriter.h.

◆ cond_

std::condition_variable rogue::utilities::fileio::StreamWriter::cond_
protected

Definition at line 147 of file StreamWriter.h.

◆ currBuffer_

uint32_t rogue::utilities::fileio::StreamWriter::currBuffer_
protected

Definition at line 111 of file StreamWriter.h.

◆ currSize_

uint64_t rogue::utilities::fileio::StreamWriter::currSize_
protected

Definition at line 99 of file StreamWriter.h.

◆ dropErrors_

bool rogue::utilities::fileio::StreamWriter::dropErrors_
protected

Definition at line 114 of file StreamWriter.h.

◆ fd_

int32_t rogue::utilities::fileio::StreamWriter::fd_
protected

Definition at line 84 of file StreamWriter.h.

◆ fdIdx_

uint32_t rogue::utilities::fileio::StreamWriter::fdIdx_
protected

Definition at line 93 of file StreamWriter.h.

◆ frameCount_

uint32_t rogue::utilities::fileio::StreamWriter::frameCount_
protected

Definition at line 120 of file StreamWriter.h.

◆ isOpen_

bool rogue::utilities::fileio::StreamWriter::isOpen_
protected

Definition at line 90 of file StreamWriter.h.

◆ log_

std::shared_ptr<rogue::Logging> rogue::utilities::fileio::StreamWriter::log_
protected

Definition at line 81 of file StreamWriter.h.

◆ mtx_

std::mutex rogue::utilities::fileio::StreamWriter::mtx_
protected

Definition at line 117 of file StreamWriter.h.

◆ raw_

bool rogue::utilities::fileio::StreamWriter::raw_
protected

Definition at line 144 of file StreamWriter.h.

◆ sizeLimit_

uint64_t rogue::utilities::fileio::StreamWriter::sizeLimit_
protected

Definition at line 96 of file StreamWriter.h.

◆ totSize_

uint64_t rogue::utilities::fileio::StreamWriter::totSize_
protected

Definition at line 102 of file StreamWriter.h.


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