libGDF
gdf::Writer Class Reference

Class for writing GDF files to disc. More...

#include <Writer.h>

+ Inheritance diagram for gdf::Writer:
+ Collaboration diagram for gdf::Writer:

Public Member Functions

 Writer ()
 Constructor.
virtual ~Writer ()
 Destructor.
void open (const int flags=writer_ev_file)
 Opens file for writing and writes Header.
void open (const std::string filename, const int flags=writer_ev_file)
 Opens file for writing and writes Header.
void close ()
 Close file.
bool isOpen ()
 Check if file is open.
void setFilename (std::string filename)
 set filename for later opening
void setMaxFullRecords (size_t num)
 Set number of full records that are kept in memory before the buffer is flushed.
bool createSignal (size_t index, bool throwexc=false)
 Create a signal.
void swapSignals (size_t a, size_t b)
 Swap to signals.
void relocateSignal (size_t src, size_t dst)
 Change signal index.
size_t getFirstFreeSignalIndex ()
 get lowest signal index that can be created
void blitFromSerialBufferPhys (const double *buf, const std::vector< size_t > &samples_per_channel)
 Blit data from a serial buffer.
void addSamplePhys (const size_t channel_idx, const float64 value)
 Add sample in physical units to a channel.
template<typename T >
void addSampleRaw (const size_t channel_idx, const T value)
 Add a raw sample to channel.
void blitSamplesPhys (const size_t channel_idx, const float64 *values, size_t num)
 Blit a number of samples in physical units to channel.
void blitSamplesPhys (const size_t channel_idx, const std::vector< float64 > &values)
 Blit a number of samples in physical units to channel.
template<typename T >
void blitSamplesRaw (const size_t channel_idx, const T *values, size_t num)
 Blit a number of raw samples to channel.
template<typename T >
void blitSamplesRaw (const size_t channel_idx, const std::vector< T > &values)
 Blit a number of raw samples to channel.
void addRecord (Record *r)
 Add a complete Record.
RecordacquireRecord ()
 Get pointer to a fresh Record.
void writeRecordDirect (Record *r)
 writes record to disc
void flush ()
 writes all full records from buffer to disc
void setEventMode (uint8 mode)
 Set Event Mode.
void setEventSamplingRate (float32 fs=-1)
 Set Sampling Rate associated with event positions.
void addEvent (const Mode1Event &ev)
 Add a Mode 1 Event.
void addEvent (uint32 position, uint16 type)
 Add a Mode 1 Event.
void addEvent (const Mode3Event &ev)
 Add a Mode 3 Event.
void addEvent (uint32 position, uint16 type, uint16 channel, uint32 duration)
 Add a Mode 3 Event.
void addEvent (uint32 position, uint16 type, uint16 channel, float32 value)
 Add a Mode 3 Event.
const GDFHeaderAccessgetHeaderAccess_readonly () const
 get Constant reference to header access
GDFHeaderAccessgetHeaderAccess ()
 get reference to main header
const MainHeadergetMainHeader_readonly () const
 get Constant reference to main header
MainHeadergetMainHeader ()
 get reference to main header
const SignalHeadergetSignalHeader_readonly (size_t idx) const
 get constant reference to a signal's header
size_t getNumSignals () const
SignalHeadergetSignalHeader (size_t idx)
 get reference to a signal's header

Detailed Description

Class for writing GDF files to disc.

Events are buffered and appended to the file when calling close( ). By default events are buffered in a separate file named filename.events. Thus, information may be recovered after computer crashes during long online recordings. The user may chose to buffer events in memory instead (see open()).

Definition at line 44 of file Writer.h.


Member Function Documentation

void gdf::Writer::addSamplePhys ( const size_t  channel_idx,
const float64  value 
)

Add sample in physical units to a channel.

The sample value is converted from the channels [physmin,physmax] to the range of [digmin,digmax] and then cast to the correct data type.

Parameters:
[in]channel_idxindex of the channel written to
[in]valuesample value in physical units

Definition at line 249 of file Writer.cpp.

+ Here is the call graph for this function:

template<typename T >
void gdf::Writer::addSampleRaw ( const size_t  channel_idx,
const T  value 
) [inline]

Add a raw sample to channel.

The sample value is cast to the correct data type, but no range checking is performed

Parameters:
[in]channel_idxindex of the channel written to
[in]valueraw sample value in physical units

Definition at line 140 of file Writer.h.

+ Here is the call graph for this function:

void gdf::Writer::blitFromSerialBufferPhys ( const double *  buf,
const std::vector< size_t > &  samples_per_channel 
)

Blit data from a serial buffer.

Instead of streaming samples as they come, the complete data is provided in an array of type double. In the buffer channels have to be arranged sequentially. I.e. all samples from channel 1 are followed by all samles from channel 2, and so on. This function attempts to keep memory overhead low by filling record by record whenever possible.

Parameters:
[in]bufBuffer
[in]samples_per_channelA vector containing the number of samples in each channel.

Definition at line 218 of file Writer.cpp.

+ Here is the call graph for this function:

void gdf::Writer::blitSamplesPhys ( const size_t  channel_idx,
const float64 *  values,
size_t  num 
)

Blit a number of samples in physical units to channel.

The sample values are converted from the channels [physmin,physmax] to the range of [digmin,digmax] and then cast to the correct data type.

Parameters:
[in]channel_idxindex of the channel written to
[in]valuesarray of sample values in physical units
[in]numnumber of samples to blit

Definition at line 259 of file Writer.cpp.

+ Here is the call graph for this function:

void gdf::Writer::blitSamplesPhys ( const size_t  channel_idx,
const std::vector< float64 > &  values 
)

Blit a number of samples in physical units to channel.

The sample values are converted from the channels [physmin,physmax] to the range of [digmin,digmax] and then cast to the correct data type.

Parameters:
[in]channel_idxindex of the channel written to
[in]valuesvector of sample values in physical units

Definition at line 269 of file Writer.cpp.

+ Here is the call graph for this function:

template<typename T >
void gdf::Writer::blitSamplesRaw ( const size_t  channel_idx,
const T *  values,
size_t  num 
) [inline]

Blit a number of raw samples to channel.

The sample values are cast to the correct data type, but no range checking is performed

Parameters:
[in]channel_idxindex of the channel written to
[in]valuesarray of raw sample value
[in]numnumber of samples to blit

Definition at line 171 of file Writer.h.

+ Here is the call graph for this function:

template<typename T >
void gdf::Writer::blitSamplesRaw ( const size_t  channel_idx,
const std::vector< T > &  values 
) [inline]

Blit a number of raw samples to channel.

The sample values are cast to the correct data type, but no range checking is performed

Parameters:
[in]channel_idxindex of the channel written to
[in]valuesvector of raw sample value

Definition at line 182 of file Writer.h.

+ Here is the call graph for this function:

Close file.

File is closed if open. Prior to closing, events are written to the file.

Definition at line 122 of file Writer.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool gdf::Writer::createSignal ( size_t  index,
bool  throwexc = false 
)

Create a signal.

Signals have to be created before they can be configured and stored.

Parameters:
[in]indexindex of the signal
[in]throwexcif true, exception::signal_exists may be thrown
Returns:
true on success

Definition at line 186 of file Writer.cpp.

void gdf::Writer::open ( const int  flags = writer_ev_file)

Opens file for writing and writes Header.

Prior to opening the file, GDFHeaderAccess::sanitize() is called. Exceptions thrown by GDFHeaderAccess::sanitize() are checked if there are errors and/or warnings. In the presence of errors the exception is forwarded immediately, and in case of warnings the file is opened but the exception is still forwarded. If the file exists, it is not opened unless the file_overwrite flag is set.

Parameters:
[in]flagsFlags...
Exceptions:
exception::header_issues
exception::file_exists

Definition at line 47 of file Writer.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void gdf::Writer::open ( const std::string  filename,
const int  flags = writer_ev_file 
)

Opens file for writing and writes Header.

Convenience function. Calls setFilename prior to opening the file

Parameters:
[in]filenameFull path name to the file.
[in]flagsFlags...
Exceptions:
exception::header_issues
exception::file_exists

Definition at line 113 of file Writer.cpp.

+ Here is the call graph for this function:

void gdf::Writer::relocateSignal ( size_t  src,
size_t  dst 
)

Change signal index.

The new index must not exist

Parameters:
[in]srcold index of first signal
[in]dstnew index of second signal

Definition at line 202 of file Writer.cpp.

void gdf::Writer::setEventMode ( uint8  mode)

Set Event Mode.

mode can be 1 or 3 1: (default) Events are stored as position,type pairs 3: Events are stored with position and type, associated to a channel and have a duration or value.

Parameters:
[in]modeevent mode

Definition at line 334 of file Writer.cpp.

+ Here is the call graph for this function:

void gdf::Writer::setEventSamplingRate ( float32  fs = -1)

Set Sampling Rate associated with event positions.

Events are not actually sampled, but their position is stored in samples rather than seconds. In order to convert event positions between time and sample, this sampling rate is used. If Sampling rate is not set (or set to <= 0 ), fs is set to the highest signal sampling rate.

Parameters:
[in]fssampling rate

Definition at line 344 of file Writer.cpp.

+ Here is the call graph for this function:

void gdf::Writer::setFilename ( std::string  filename)

set filename for later opening

Parameters:
[in]filenameFull path name to the file

Definition at line 170 of file Writer.cpp.

+ Here is the caller graph for this function:

void gdf::Writer::setMaxFullRecords ( size_t  num)

Set number of full records that are kept in memory before the buffer is flushed.

Parameters:
[in]numnumber of records

Definition at line 178 of file Writer.cpp.

+ Here is the caller graph for this function:

void gdf::Writer::swapSignals ( size_t  a,
size_t  b 
)

Swap to signals.

Both signals must exist.

Parameters:
[in]aindex of first signal
[in]bindex of second signal

Definition at line 194 of file Writer.cpp.


The documentation for this class was generated from the following files:
 All Data Structures Functions Variables Friends