Developer documentation
Version 3.0.3-105-gd3941f44
MR::DWI::Tractography::Writer< ValueType > Class Template Reference

class to handle writing tracks to file, with RAM buffer More...

#include "dwi/tractography/file.h"

Inheritance diagram for MR::DWI::Tractography::Writer< ValueType >:
MR::DWI::Tractography::WriterUnbuffered< float > MR::DWI::Tractography::WriterInterface< float >

Public Types

using vector_type = typename WriterUnbuffered< ValueType >::vector_type
 
- Public Types inherited from MR::DWI::Tractography::WriterUnbuffered< float >
using vector_type = Eigen::Matrix< float, 3, 1 >
 

Public Member Functions

 Writer (const std::string &file, const Properties &properties, size_t default_buffer_capacity=16777216)
 create new RAM-buffered track file with specified properties More...
 
 Writer (const Writer &W)=delete
 
 ~Writer ()
 commits any remaining data to file More...
 
bool operator() (const Streamline< ValueType > &tck)
 append track to file More...
 
- Public Member Functions inherited from MR::DWI::Tractography::WriterUnbuffered< float >
 WriterUnbuffered (const std::string &file, const Properties &properties)
 create a new track file with the specified properties More...
 
bool operator() (const Streamline< float > &tck)
 append track to file More...
 
void set_weights_path (const std::string &path)
 set the path to the track weights More...
 
- Public Member Functions inherited from MR::DWI::Tractography::WriterInterface< float >
virtual bool operator() (const Streamline< float > &)=0
 
virtual ~WriterInterface ()
 

Protected Member Functions

void add_point (const vector_type &p)
 add point to buffer and increment buffer_size accordingly More...
 
void commit ()
 
- Protected Member Functions inherited from MR::DWI::Tractography::WriterUnbuffered< float >
 WriterUnbuffered (const WriterUnbuffered &)=delete
 copy construction explicitly disabled More...
 
vector_type delimiter () const
 indicates end of track and start of new track More...
 
vector_type barrier () const
 indicates end of data More...
 
void format_point (const vector_type &src, vector_type &dest)
 perform per-point byte-swapping if required More...
 
void write_weights (const std::string &contents)
 write track weights data to file More...
 
void commit (vector_type *data, size_t num_points)
 write track point data to file More...
 

Protected Attributes

const size_t buffer_capacity
 
std::unique_ptr< vector_type[]> buffer
 
size_t buffer_size
 
std::string weights_buffer
 
- Protected Attributes inherited from MR::DWI::Tractography::WriterUnbuffered< float >
std::string weights_name
 
int64_t barrier_addr
 

Detailed Description

template<typename ValueType = float>
class MR::DWI::Tractography::Writer< ValueType >

class to handle writing tracks to file, with RAM buffer

writes track header as specified in properties and individual tracks to the file specified in file. Writing individual tracks is done using the append() method.

This class implements a large write-back RAM buffer to hold the track data in RAM, and only commits to file when the buffer capacity is reached. This minimises the number of write() calls, which can otherwise become a bottleneck on distributed or network filesystems. It also helps reduce file fragmentation when multiple processes write to file concurrently. The size of the write-back buffer defaults to 16MB, and can be set in the config file using the TrackWriterBufferSize field (in bytes).

Definition at line 352 of file file.h.

Member Typedef Documentation

◆ vector_type

template<typename ValueType = float>
using MR::DWI::Tractography::Writer< ValueType >::vector_type = typename WriterUnbuffered<ValueType>::vector_type

Definition at line 361 of file file.h.

Constructor & Destructor Documentation

◆ Writer() [1/2]

template<typename ValueType = float>
MR::DWI::Tractography::Writer< ValueType >::Writer ( const std::string &  file,
const Properties properties,
size_t  default_buffer_capacity = 16777216 
)
inline

create new RAM-buffered track file with specified properties

the capacity of the RAM buffer can be specified as a config file option (TrackWriterBufferSize), or in the constructor by specifying a value in bytes for default_buffer_capacity (default is 16M).

Definition at line 374 of file file.h.

◆ Writer() [2/2]

template<typename ValueType = float>
MR::DWI::Tractography::Writer< ValueType >::Writer ( const Writer< ValueType > &  W)
delete

◆ ~Writer()

template<typename ValueType = float>
MR::DWI::Tractography::Writer< ValueType >::~Writer ( )
inline

commits any remaining data to file

Definition at line 383 of file file.h.

Member Function Documentation

◆ add_point()

template<typename ValueType = float>
void MR::DWI::Tractography::Writer< ValueType >::add_point ( const vector_type p)
inlineprotected

add point to buffer and increment buffer_size accordingly

Definition at line 414 of file file.h.

◆ commit()

template<typename ValueType = float>
void MR::DWI::Tractography::Writer< ValueType >::commit ( )
inlineprotected

Definition at line 418 of file file.h.

◆ operator()()

template<typename ValueType = float>
bool MR::DWI::Tractography::Writer< ValueType >::operator() ( const Streamline< ValueType > &  tck)
inline

append track to file

Definition at line 388 of file file.h.

Member Data Documentation

◆ buffer

template<typename ValueType = float>
std::unique_ptr<vector_type[]> MR::DWI::Tractography::Writer< ValueType >::buffer
protected

Definition at line 409 of file file.h.

◆ buffer_capacity

template<typename ValueType = float>
const size_t MR::DWI::Tractography::Writer< ValueType >::buffer_capacity
protected

Definition at line 408 of file file.h.

◆ buffer_size

template<typename ValueType = float>
size_t MR::DWI::Tractography::Writer< ValueType >::buffer_size
protected

Definition at line 410 of file file.h.

◆ weights_buffer

template<typename ValueType = float>
std::string MR::DWI::Tractography::Writer< ValueType >::weights_buffer
protected

Definition at line 411 of file file.h.


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