Relacs Core Library  0.9.8
Classes | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
SaveFiles Class Reference

#include <savefiles.h>

Inheritance diagram for SaveFiles:
Inheritance graph
[legend]
Collaboration diagram for SaveFiles:
Collaboration graph
[legend]

Classes

class  ODMLFiles
 
class  RelacsFiles
 

Public Member Functions

 SaveFiles (RELACSWidget *rw, int height, QWidget *parent=0)
 
 ~SaveFiles (void)
 
bool saving (void) const
 
bool filesOpen (void) const
 
void holdOn (void)
 
void holdOff (void)
 
string path (void) const
 
void setPath (const string &path)
 
string addPath (const string &file) const
 
void storeFile (const string &file) const
 
string pathTemplate (void) const
 
void setPathTemplate (const string &path)
 
string defaultPath (void) const
 
void setDefaultPath (const string &defaultpath)
 
string addDefaultPath (const string &file) const
 
void setWriteRelacsFiles (bool write)
 
void setWriteODMLFiles (bool write)
 
void setWriteNIXFiles (bool write)
 
virtual void notify (void)
 
void lock (void) const
 
void unlock (void) const
 
QMutex * mutex (void)
 
void setTracesEvents (const InList &il, const EventList &el)
 
void save (bool on)
 
void saveTraces (void)
 
void save (const OutData &signal)
 
void save (const OutList &signal)
 
void save (const RePro &rp)
 
bool signalPending (void) const
 
void clearSignal (void)
 
void openFiles (void)
 
void deleteFiles (void)
 
void completeFiles (void)
 
DataIndexdataIndex (void)
 

Static Public Attributes

static const int SaveTrace = 0x0010
 
static const int SaveMeanQuality = 0x0400
 
static const int TraceFlag = 32768
 

Protected Member Functions

void setThePath (const string &path)
 
bool isSaving (void) const
 
void writeToggle (void)
 
void writeTraces (bool stimulus)
 
void writeEvents (bool stimulus)
 
void writeStimulus (void)
 
void writeRePro (void)
 
void closeFiles (void)
 
bool removeDir (const QString &dirname)
 
string pathName (void) const
 
void addFile (const string &filename)
 
ofstream * openFile (const string &filename, int type)
 
void addRemoveFile (const string &filename)
 
void clearRemoveFiles (void)
 
void removeFiles (void)
 
void createRelacsFiles (void)
 
void createODMLFiles (void)
 
void createNIXFile (void)
 
virtual void customEvent (QEvent *qce)
 

Protected Attributes

bool WriteRelacsFiles
 
bool WriteODMLFiles
 
bool WriteNIXFiles
 
bool FilesOpen
 
bool Saving
 
bool Hold
 
string Path
 
string PrevPath
 
string PathTemplate
 
string DefaultPath
 
int PathNumber
 
time_t PathTime
 
double SessionTime
 
InList IL
 
EventList EL
 
double SignalTime
 
double PrevSignalTime
 
Options StimulusData
 
deque< OutDataInfoStimuli
 
map< string, map< Options,
string > > 
ReProStimuli
 
string ReProName
 
map< string, int > ReProStimulusCount
 
Options ReProInfo
 
deque< string > ReProFiles
 
bool ReProData
 
bool ToggleOn
 
bool ToggleData
 
DataIndex DI
 
deque< string > RemoveFiles
 
RelacsFiles RelacsIO
 
ODMLFiles OdmlIO
 
RELACSWidgetRW
 
QLabel * FileLabel
 
QFont NormalFont
 
QFont HighlightFont
 
QPalette NormalPalette
 
QPalette HighlightPalette
 
SpikeTraceSaveLabel
 
QHBoxLayout * StatusInfoLayout
 
QMutex SaveMutex
 
QMutex StimulusDataLock
 

Detailed Description

Save data to files.

Author
Jan Benda

is owned by RELACSWidget and used by RELACSPlugin (path() and stimulusData()) Settings (defaultPath()) and MetaData (path() only)

SaveFile sets the following environment variables:

Todo:

platform independent mkdir in openFiles()!

saveStimulus: adaptive time for calculating the mean rate

check it carefully!

warning on Disk full (or even before!)

File formats:

  • .wav: enough flexibility, compression possible, but file size limited to 2GB has to be known in advance,
  • .au: raw data with unlimited file size und minimal header information allows for float and double

Constructor & Destructor Documentation

SaveFiles ( RELACSWidget rw,
int  height,
QWidget *  parent = 0 
)
~SaveFiles ( void  )

Member Function Documentation

bool saving ( void  ) const

The current status of saving data to files.

Returns
true if files are opened and data are currently written into the files.
See Also
filesOpen(), save(bool), holdOn(), holdOff()

References SaveFiles::isSaving(), and SaveFiles::SaveMutex.

Referenced by RELACSWidget::directWrite(), RELACSPlugin::saving(), and RELACSWidget::write().

bool filesOpen ( void  ) const

The current status of having files opened for saving data.

Returns
true if files are open.
See Also
writing()

References SaveFiles::FilesOpen, and SaveFiles::SaveMutex.

Referenced by RELACSWidget::startSession(), and RELACSWidget::stopSession().

void holdOn ( void  )

Do not update Saving.

References SaveFiles::Hold, and SaveFiles::SaveMutex.

Referenced by RELACSWidget::startRePro().

void holdOff ( void  )

Allow updating Saving.

References SaveFiles::Hold, and SaveFiles::SaveMutex.

string path ( void  ) const
void setPath ( const string &  path)

Set the base path for all data to be stored and the corresponding environment variable RELACSDATAPATH

Parameters
[in]paththe base path for storing data. path(), setPathTemplate()

References SaveFiles::SaveMutex, and SaveFiles::setThePath().

Referenced by RELACSWidget::startFirstAcquisition(), and RELACSWidget::stopSession().

string addPath ( const string &  file) const

Expand file name by the current base path for storing data.

Parameters
[in]filethe name of the file
Returns
file added to the current path for storing data.
See Also
path()

References SaveFiles::Path, and SaveFiles::SaveMutex.

Referenced by RePro::addPath(), RELACSPlugin::addPath(), MetaData::save(), and RELACSWidget::startSession().

void storeFile ( const string &  file) const

Stores file in the list of files of the currently running RePro.

References SaveFiles::ReProFiles, and SaveFiles::SaveMutex.

Referenced by RePro::addPath().

string pathTemplate ( void  ) const
Returns
the template for the base path where data are to stored.
See Also
setPathTemplate(), path()

References SaveFiles::PathTemplate, and SaveFiles::SaveMutex.

void setPathTemplate ( const string &  path)

Set the template for the base path for all data to be stored. Also adjusts the width of the widget accordingly.

Parameters
[in]paththe template for the base path.
Note
The template is only set if path is not an empty string. pathTemplate()

References SaveFiles::FileLabel, Str::format(), SaveFiles::HighlightFont, SaveFiles::path(), SaveFiles::PathTemplate, SaveFiles::PathTime, and SaveFiles::SaveMutex.

Referenced by Settings::notify(), and SaveFiles::SaveFiles().

string defaultPath ( void  ) const
Returns
the default base path where data are stored if no session is running.
See Also
addDefaultPath(), setDefaultPath(), path()

References SaveFiles::DefaultPath, and SaveFiles::SaveMutex.

Referenced by RELACSPlugin::defaultPath(), RELACSWidget::startFirstAcquisition(), and RELACSWidget::stopSession().

void setDefaultPath ( const string &  defaultpath)

Set the default base path for all data to be stored and the corresponding environment variable RELACSDEFAULTPATH. If the current path() equals defaultPath() then the current base path is alse set via setPath().

Parameters
[in]defaultpaththe base path for storing data.
Note
The pathes are only set if defaultpath is not an empty string. defaultPath()

References SaveFiles::DefaultPath, SaveFiles::Path, SaveFiles::SaveMutex, and SaveFiles::setThePath().

Referenced by Settings::notify().

string addDefaultPath ( const string &  file) const

Expand file name by the default base path for storing data.

Parameters
[in]filethe name of the file
Returns
file added to the default base path for storing data.
See Also
defaultPath()

References SaveFiles::DefaultPath, and SaveFiles::SaveMutex.

Referenced by RELACSPlugin::addDefaultPath().

void setWriteRelacsFiles ( bool  write)

Should data be written in RELACS format?

References SaveFiles::WriteRelacsFiles.

Referenced by Settings::notify().

void setWriteODMLFiles ( bool  write)

Should metadata be written in ODML format?

References SaveFiles::WriteODMLFiles.

Referenced by Settings::notify().

void setWriteNIXFiles ( bool  write)

Should data be written in NIX format?

References SaveFiles::WriteNIXFiles.

Referenced by Settings::notify().

void notify ( void  )
virtual

React to settings of the stimulus options. This function calls notifyStimulusData() in all RELACSPlugins.

References RELACSWidget::notifyStimulusData(), and SaveFiles::RW.

void lock ( void  ) const

Lock the stimulus data.

References SaveFiles::StimulusDataLock.

Referenced by RELACSPlugin::lockStimulusData(), and SaveFiles::openFiles().

void unlock ( void  ) const

Unlock the stimulus data mutex.

References SaveFiles::StimulusDataLock.

Referenced by SaveFiles::openFiles(), and RELACSPlugin::unlockStimulusData().

QMutex * mutex ( void  )

The mutex of the stimulus data.

References SaveFiles::StimulusDataLock.

Referenced by RELACSPlugin::stimulusDataMutex().

void setTracesEvents ( const InList il,
const EventList el 
)

Copies pointers of each element of il and el to this.

References InList::add(), EventList::add(), InList::clear(), EventList::clear(), SaveFiles::EL, SaveFiles::IL, and SaveFiles::SaveMutex.

Referenced by RELACSWidget::startFirstAcquisition().

void save ( bool  on)

Switch writing data to file on or off. Call this only at the very beginning of your RePro::main() code, i.e. before writing any stimulus.

References SaveFiles::FilesOpen, SaveFiles::SaveMutex, SaveFiles::Saving, SaveFiles::ToggleData, and SaveFiles::ToggleOn.

Referenced by RELACSWidget::directWrite(), RePro::setSaving(), RELACSWidget::startRePro(), and RELACSWidget::write().

void saveTraces ( void  )
void save ( const OutData signal)
void save ( const OutList signal)
void save ( const RePro rp)
bool signalPending ( void  ) const
Returns
true if there is still a stimulus pending that needs to be written into the index files.

References SaveFiles::SaveMutex, and SaveFiles::Stimuli.

Referenced by RELACSWidget::directWrite(), RELACSWidget::stopRePro(), and RELACSWidget::write().

void clearSignal ( void  )

Clear a pending signal.

References SaveFiles::SaveMutex, and SaveFiles::Stimuli.

Referenced by RELACSWidget::stopRePro().

void openFiles ( void  )
void deleteFiles ( void  )
void completeFiles ( void  )
DataIndex * dataIndex ( void  )
Returns
a pointer to the index of all recording, repro, and stimulus data.

References SaveFiles::DI.

Referenced by RELACSWidget::RELACSWidget().

void setThePath ( const string &  path)
protected

Set the base path for all data to be stored and the corresponding environment variable RELACSDATAPATH

Parameters
[in]paththe base path for storing data. This is the not-locked variant of setPath()

References SaveFiles::path(), and SaveFiles::Path.

Referenced by SaveFiles::completeFiles(), SaveFiles::deleteFiles(), SaveFiles::openFiles(), SaveFiles::setDefaultPath(), and SaveFiles::setPath().

bool isSaving ( void  ) const
protected

The current status of saving data to files.

Returns
true if files are opened and data are currently written into the files. This is the not-locked variant of saving().

References SaveFiles::FilesOpen, and SaveFiles::Saving.

Referenced by SaveFiles::save(), SaveFiles::saveTraces(), SaveFiles::saving(), SaveFiles::writeEvents(), SaveFiles::writeRePro(), SaveFiles::writeStimulus(), SaveFiles::writeToggle(), and SaveFiles::writeTraces().

void writeToggle ( void  )
protected
void writeTraces ( bool  stimulus)
protected
void writeEvents ( bool  stimulus)
protected
void writeStimulus ( void  )
protected
void writeRePro ( void  )
protected
void closeFiles ( void  )
protected
bool removeDir ( const QString &  dirname)
protected

Remove the directory dirname with all its files and all its sub-directories.

References RELACSWidget::printlog(), and SaveFiles::RW.

Referenced by SaveFiles::deleteFiles().

string pathName ( void  ) const
protected

Generate new pathname using PathTemplate, PathTime, and PathNumber.

References Str::format(), SaveFiles::PathNumber, SaveFiles::PathTemplate, SaveFiles::PathTime, and Str::upper().

Referenced by SaveFiles::openFiles().

void addFile ( const string &  filename)
protected

Add the file filename to the list of files to be removed and to the metadata.

References SaveFiles::addRemoveFile(), Parameter::ListAlways, MetaData::lock(), SaveFiles::Path, SaveFiles::RW, MetaData::standardFlag(), and MetaData::unlock().

Referenced by SaveFiles::openFile().

ofstream * openFile ( const string &  filename,
int  type 
)
protected

Open the file path() + filename as specified by type (ios::out, ios::in, ios::binary, ...). Add it to the list of files to be removed and to the metadata and print an error message if opening of the file failed.

References SaveFiles::addFile(), SaveFiles::Path, RELACSWidget::printlog(), and SaveFiles::RW.

Referenced by SaveFiles::ODMLFiles::open(), SaveFiles::RelacsFiles::openEventFiles(), SaveFiles::RelacsFiles::openStimulusFiles(), and SaveFiles::RelacsFiles::openTraceFiles().

void addRemoveFile ( const string &  filename)
protected

The file filename will be removed if the session is not saved.

References SaveFiles::RemoveFiles.

Referenced by SaveFiles::addFile(), and SaveFiles::createNIXFile().

void clearRemoveFiles ( void  )
protected

Reset the list of files that have to be deleted if the session is not to be saved.

References SaveFiles::RemoveFiles.

Referenced by SaveFiles::completeFiles(), SaveFiles::openFiles(), SaveFiles::removeFiles(), SaveFiles::SaveFiles(), and SaveFiles::~SaveFiles().

void removeFiles ( void  )
protected

Remove all files from the list and clear the list of files that have to be deleted if the session is not to be saved.

References SaveFiles::clearRemoveFiles(), and SaveFiles::RemoveFiles.

Referenced by SaveFiles::deleteFiles().

void createRelacsFiles ( void  )
protected

Open and initialize the native RELACS data files that contain all information.

References SaveFiles::EL, SaveFiles::FilesOpen, SaveFiles::IL, SaveFiles::RelacsFiles::open(), SaveFiles::Path, SaveFiles::RelacsIO, SaveFiles::RW, and SaveFiles::WriteRelacsFiles.

Referenced by SaveFiles::openFiles().

void createODMLFiles ( void  )
protected

Open and initialize the ODML files that contain metadata only.

References SaveFiles::FilesOpen, SaveFiles::OdmlIO, SaveFiles::ODMLFiles::open(), SaveFiles::Path, SaveFiles::RW, and SaveFiles::WriteODMLFiles.

Referenced by SaveFiles::openFiles().

void createNIXFile ( void  )
protected
void customEvent ( QEvent *  qce)
protectedvirtual

Member Data Documentation

const int SaveTrace = 0x0010
static
const int SaveMeanQuality = 0x0400
static

Flag for the modes of events, indicating that their mean quality should be saved.

Referenced by FilterDetectors::createFilters(), SaveFiles::RelacsFiles::openStimulusFiles(), SaveFiles::RelacsFiles::writeRePro(), and SaveFiles::RelacsFiles::writeStimulus().

const int TraceFlag = 32768
static

Flag for the Options to mark the last values of the output traces.

Referenced by RELACSPlugin::stimulusDataTraceFlag().

bool WriteRelacsFiles
protected

Should data be written in RELACS format?

Referenced by SaveFiles::createRelacsFiles(), SaveFiles::SaveFiles(), and SaveFiles::setWriteRelacsFiles().

bool WriteODMLFiles
protected

Should metadata be written in ODML format?

Referenced by SaveFiles::createODMLFiles(), SaveFiles::SaveFiles(), and SaveFiles::setWriteODMLFiles().

bool WriteNIXFiles
protected
bool FilesOpen
protected
bool Saving
protected
bool Hold
protected
string Path
protected
string PrevPath
protected

The path from the previous session.

Referenced by SaveFiles::completeFiles(), SaveFiles::openFiles(), and SaveFiles::SaveFiles().

string PathTemplate
protected

The template from which Path is generated.

Referenced by SaveFiles::pathName(), SaveFiles::pathTemplate(), SaveFiles::SaveFiles(), and SaveFiles::setPathTemplate().

string DefaultPath
protected
int PathNumber
protected

Identification number for pathes used to create a base path from PathFormat.

Referenced by SaveFiles::deleteFiles(), SaveFiles::openFiles(), SaveFiles::pathName(), and SaveFiles::SaveFiles().

time_t PathTime
protected

The time used to generate the previous base path.

Referenced by SaveFiles::openFiles(), SaveFiles::pathName(), SaveFiles::SaveFiles(), and SaveFiles::setPathTemplate().

double SessionTime
protected

Time of start of the session.

Referenced by SaveFiles::openFiles(), SaveFiles::writeRePro(), and SaveFiles::writeStimulus().

InList IL
protected
EventList EL
protected
double SignalTime
protected
double PrevSignalTime
protected
Options StimulusData
protected

The options of SaveFiles at the time of writing a stimulus. Contains values of all output traces right before writing the new stimulus and additional information.

Referenced by SaveFiles::save(), and SaveFiles::writeStimulus().

deque< OutDataInfo > Stimuli
protected
map< string, map < Options, string > > ReProStimuli
protected
string ReProName
protected
map< string, int > ReProStimulusCount
protected

Number of stimuli written by the current RePro, keys are the names of the RePros.

Referenced by SaveFiles::openFiles(), SaveFiles::SaveFiles(), SaveFiles::writeRePro(), SaveFiles::writeStimulus(), and SaveFiles::~SaveFiles().

Options ReProInfo
protected
deque< string > ReProFiles
mutableprotected
bool ReProData
protected
bool ToggleOn
protected
bool ToggleData
protected
DataIndex DI
protected
deque<string> RemoveFiles
protected

A list of files which have to be deleted if the session is not to be saved.

Referenced by SaveFiles::addRemoveFile(), SaveFiles::clearRemoveFiles(), and SaveFiles::removeFiles().

RelacsFiles RelacsIO
protected
ODMLFiles OdmlIO
protected
RELACSWidget* RW
protected
QLabel* FileLabel
protected
QFont NormalFont
protected
QFont HighlightFont
protected
QPalette NormalPalette
protected
QPalette HighlightPalette
protected
SpikeTrace* SaveLabel
protected
QHBoxLayout* StatusInfoLayout
protected

Referenced by SaveFiles::SaveFiles().

QMutex SaveMutex
mutableprotected
QMutex StimulusDataLock
mutableprotected

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