CFEL - ASG Software Suite  2.5.0
CASS
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
jocassview::FileHandler Class Reference

read and write data to files More...

#include <file_handler.h>

+ Inheritance diagram for jocassview::FileHandler:
+ Collaboration diagram for jocassview::FileHandler:

Public Member Functions

 FileHandler (const QString &filename=QString())
 constructor More...
 
result_t::shared_pointer result (const QString &key, quint64 id=0)
 retrieve an result from the file More...
 
QStringList resultNames ()
 retrieve the list of names that an be displayed from the file More...
 
QString type () const
 retrieve the type of source More...
 
void setFilename (const QString &filename)
 set the filename More...
 

Static Public Member Functions

static QString getBaseName (const QString &filename)
 return the basename of the filename More...
 
static bool isContainerFile (const QString &filename)
 return whether the file is a container file More...
 
static void saveData (const QString &filename, result_t::shared_pointer data)
 save data to a given file More...
 
static void createContainer (const QString &filename)
 create the container file More...
 

Private Member Functions

QImage loadImage (const QString &filename)
 read the data from an image file More...
 
void saveImage (const QString &filename, const QImage &image)
 save image data More...
 
result_t::shared_pointer loadDataFromHist ()
 read the data from a hist file More...
 
void saveDataToHist (const QString &filename, result_t::shared_pointer data)
 save the data from a hist file More...
 
result_t::shared_pointer loadDataFromCSV ()
 read the data from a CSV file More...
 
void saveDataToCSV (const QString &filename, result_t::shared_pointer data)
 save the data from a CSV file More...
 
result_t::shared_pointer loadDataFromH5 (const QString &key="")
 read the data from a hdf5 file More...
 
void saveDataToH5 (const QString &filename, result_t::shared_pointer data, const QString &mode="w")
 write the data to a hdf5 file More...
 
result_t::shared_pointer loadDataFromCBF ()
 read the data from a cbf file More...
 
void saveDataToCBF (const QString &filename, result_t::shared_pointer data)
 save the data to a cbf file More...
 

Private Attributes

QString _filename
 the filename of the file to work on More...
 

Additional Inherited Members

- Public Types inherited from jocassview::DataSource
typedef cass::Result< float > result_t
 define the result type More...
 

Detailed Description

read and write data to files

Author
Lutz Foucar

Definition at line 30 of file file_handler.h.

Constructor & Destructor Documentation

FileHandler::FileHandler ( const QString filename = QString())

constructor

Parameters
filenamethe filename that the handler handels

Definition at line 40 of file file_handler.cpp.

Member Function Documentation

void FileHandler::createContainer ( const QString filename)
static

create the container file

Parameters
filenameThe filename to save the data to

Definition at line 95 of file file_handler.cpp.

References QFileInfo::exists().

Referenced by jocassview::JoCASSViewer::saveFile().

QString FileHandler::getBaseName ( const QString filename)
static

return the basename of the filename

Returns
basename of filename
Parameters
filenamethe filename whos basename should be extracted

Definition at line 46 of file file_handler.cpp.

References QFileInfo::baseName(), and QFileInfo::exists().

Referenced by resultNames().

bool FileHandler::isContainerFile ( const QString filename)
static

return whether the file is a container file

Returns
true when the file is a container file (e.g. hdf5 file)
Parameters
filenamethe name of the file

Definition at line 55 of file file_handler.cpp.

References QFileInfo::suffix(), and QString::toUpper().

Referenced by jocassview::JoCASSViewer::autoSave(), resultNames(), jocassview::OneDViewer::saveData(), and jocassview::JoCASSViewer::saveFile().

DataSource::result_t::shared_pointer FileHandler::loadDataFromCBF ( )
private

read the data from a cbf file

Returns
pointer to the data

try to retrieve the center from the header

Definition at line 439 of file file_handler.cpp.

References _filename, QString::contains(), QString::fromStdString(), QString::isNull(), cass::CBF::read(), QTextStream::readLine(), QString::remove(), result(), QString::split(), and QString::toDouble().

Referenced by result().

DataSource::result_t::shared_pointer FileHandler::loadDataFromCSV ( )
private

read the data from a CSV file

Returns
pointer to the data

Definition at line 213 of file file_handler.cpp.

References QMessageBox::information(), and QObject::tr().

Referenced by result().

cass::HistogramBackend * FileHandler::loadDataFromH5 ( const QString key = "")
private

read the data from a hdf5 file

Returns
pointer to the data
Parameters
keyin case of a hdf5 file the key to the requested data. Default is ""

Definition at line 427 of file file_handler.cpp.

Referenced by result().

DataSource::result_t::shared_pointer FileHandler::loadDataFromHist ( )
private

read the data from a hist file

Returns
pointer to the data

use a file serializer to deserialize the data in the file to a hist object and get the dimension from the object.

Definition at line 193 of file file_handler.cpp.

References _filename, and result().

Referenced by result().

QImage FileHandler::loadImage ( const QString filename)
private

read the data from an image file

Returns
the image
Parameters
filenamethe name of the file that contains the image data

Definition at line 178 of file file_handler.cpp.

References QImageReader::canRead().

DataSource::result_t::shared_pointer FileHandler::result ( const QString key,
quint64  id = 0 
)
virtual

retrieve an result from the file

Parameters
keythe key of the result
idthe eventid of the result

Implements jocassview::DataSource.

Definition at line 106 of file file_handler.cpp.

References _filename, QMessageBox::critical(), QFileInfo::exists(), loadDataFromCBF(), loadDataFromCSV(), loadDataFromH5(), loadDataFromHist(), QFileInfo::suffix(), QString::toUpper(), and QObject::tr().

Referenced by loadDataFromCBF(), and loadDataFromHist().

QStringList FileHandler::resultNames ( )
virtual

retrieve the list of names that an be displayed from the file

Returns
list of names of displayable items

Implements jocassview::DataSource.

Definition at line 141 of file file_handler.cpp.

References _filename, QMessageBox::critical(), QFileInfo::exists(), QString::fromStdString(), getBaseName(), isContainerFile(), and QObject::tr().

void FileHandler::saveData ( const QString filename,
result_t::shared_pointer  data 
)
static

save data to a given file

Parameters
filenameThe filename to save the data to
datathe data to save

Definition at line 67 of file file_handler.cpp.

References QFileInfo::exists(), saveDataToCBF(), saveDataToCSV(), saveDataToH5(), saveDataToHist(), QFileInfo::suffix(), and QString::toUpper().

Referenced by jocassview::ZeroDViewer::saveData(), jocassview::TwoDViewer::saveData(), and jocassview::OneDViewer::saveData().

void FileHandler::saveDataToCBF ( const QString filename,
result_t::shared_pointer  data 
)
private

save the data to a cbf file

Parameters
filenamethe name of the file
datapointer to the data

Definition at line 487 of file file_handler.cpp.

References QString::begin(), and cass::CBF::write().

Referenced by saveData().

void FileHandler::saveDataToCSV ( const QString filename,
result_t::shared_pointer  data 
)
private

save the data from a CSV file

Parameters
filenamethe name of the file
datapointer to the data to save

Definition at line 219 of file file_handler.cpp.

References QFile::open(), QTextStream::pos(), cass::Result< float >::xAxis, and cass::Result< float >::yAxis.

Referenced by saveData().

void FileHandler::saveDataToH5 ( const QString filename,
result_t::shared_pointer  data,
const QString mode = "w" 
)
private

write the data to a hdf5 file

The key under which name the data is saved in the file is given provided as part of the data.

See also
hdf5::Handler::open for options how the file will be opened
Parameters
filenamethe name of the file
datapointer to the data
modeThe mode in which the file will be opened. Default is "w".

Definition at line 432 of file file_handler.cpp.

Referenced by saveData().

void FileHandler::saveDataToHist ( const QString filename,
result_t::shared_pointer  data 
)
private

save the data from a hist file

Parameters
filenamethe name of the file
datapointer to the data to save

Definition at line 206 of file file_handler.cpp.

References cass::SerializerWriteFile::close().

Referenced by saveData().

void FileHandler::saveImage ( const QString filename,
const QImage image 
)
private

save image data

Parameters
filenamethe name of the file to save the image in
imagethe image to save

Definition at line 186 of file file_handler.cpp.

References QMessageBox::critical(), QImage::save(), and QObject::tr().

void FileHandler::setFilename ( const QString filename)

set the filename

Parameters
filenamethe filename to work on

Definition at line 173 of file file_handler.cpp.

References _filename.

QString FileHandler::type ( ) const
virtual

retrieve the type of source

Returns
"File"

Implements jocassview::DataSource.

Definition at line 168 of file file_handler.cpp.

Member Data Documentation

QString jocassview::FileHandler::_filename
private

the filename of the file to work on

Definition at line 167 of file file_handler.h.

Referenced by loadDataFromCBF(), loadDataFromHist(), result(), resultNames(), and setFilename().


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