12 #include <QtCore/QString>
13 #include <QtCore/QFileInfo>
14 #include <QtCore/QObject>
15 #include <QtCore/QDebug>
17 #if QT_VERSION >= 0x050000
18 #include <QtWidgets/QMessageBox>
19 #include <QtWidgets/QInputDialog>
21 #include <QtGui/QMessageBox>
22 #include <QtGui/QInputDialog>
24 #include <QtGui/QImage>
25 #include <QtGui/QImageReader>
151 list<string> dataset(h5handle.datasets());
152 for (list<string>::const_iterator it=dataset.begin(); it != dataset.end(); ++it)
188 if(! image.
save(filename,
"PNG"))
200 serializer >> (*result);
209 serializer << (*data);
221 QFile file(filename);
222 if (!file.
open(QIODevice::WriteOnly | QIODevice::Text))
229 for (
size_t i(0); i < data->size(); ++i)
230 out << (*data)[i] << endl;
236 out<<
"x-axis value, y-axis value"<<endl;
237 for (
size_t i(0); i < xaxis.nBins; ++i)
238 out <<xaxis.
pos(i)<<
";"<< (*data)[i] << endl;
245 out<<
"x-axis value, y-axis value, z-axis value"<<endl;
246 for (
size_t yy(0); yy < yaxis.nBins; ++yy)
247 for (
size_t xx(0); xx < xaxis.nBins; ++xx)
248 out << xaxis.
pos(xx) <<
";" << yaxis.pos(yy) <<
";"<<(*data)[yy*xaxis.nBins + xx] << endl;
262 list<string> dataset(h5handle.datasets());
264 for (list<string>::const_iterator it=dataset.begin(); it != dataset.end(); ++it)
272 if (key ==
"" || key.isEmpty() || !items.contains(key))
277 if (ok && !item.isEmpty())
283 switch (h5handle.dimension(key.toStdString()))
287 float value(h5handle.readScalar<
float>(key.toStdString()));
290 result->name(key.toStdString());
299 h5handle.readArray(array,length,key.toStdString());
302 try { xlow = h5handle.readScalarAttribute<
float>(
"xLow",key.toStdString()); }
303 catch(
const invalid_argument & what) { xlow = 0; }
304 try { xup = h5handle.readScalarAttribute<
float>(
"xUp",key.toStdString()); }
305 catch(
const invalid_argument & what) { xup = length; }
307 copy(array.begin(),array.end(),
result->begin());
308 result->name(key.toStdString());
314 result->setValue(array[0]);
315 result->name(key.toStdString());
322 vector<float> matrix;
323 pair<size_t,size_t> shape;
324 h5handle.readMatrix(matrix,shape,key.toStdString());
325 float xlow,xup,ylow,yup;
326 try { xlow = h5handle.readScalarAttribute<
float>(
"xLow",key.toStdString()); }
327 catch(
const invalid_argument & what) { xlow = 0; }
328 try { xup = h5handle.readScalarAttribute<
float>(
"xUp",key.toStdString()); }
329 catch(
const invalid_argument & what) { xup = shape.first; }
330 try { ylow = h5handle.readScalarAttribute<
float>(
"yLow",key.toStdString()); }
331 catch(
const invalid_argument & what) { ylow = 0; }
332 try { yup = h5handle.readScalarAttribute<
float>(
"yUp",key.toStdString()); }
333 catch(
const invalid_argument & what) { yup = shape.second; }
337 copy(matrix.begin(),matrix.end(),
result->begin());
338 result->name(key.toStdString());
355 catch(
const invalid_argument & err)
359 catch(
const logic_error& err)
363 catch(
const runtime_error & err)
370 _filename +
"'. Unknown error occured"));
379 hdf5::Handler h5handle(filename.toStdString(),mode.toStdString());
390 h5handle.writeArray(data->storage(),data->shape().first, data->name());
391 h5handle.writeScalarAttribute(xaxis.low,
"xLow", data->name());
392 h5handle.writeScalarAttribute(xaxis.up,
"xUp", data->name());
399 h5handle.writeMatrix(data->storage(),data->shape(),data->name(),9);
400 h5handle.writeScalarAttribute(xaxis.low,
"xLow", data->name());
401 h5handle.writeScalarAttribute(xaxis.up,
"xUp", data->name());
402 h5handle.writeScalarAttribute(yaxis.low,
"yLow", data->name());
403 h5handle.writeScalarAttribute(yaxis.up,
"yUp", data->name());
408 catch(
const invalid_argument & err)
412 catch(
const logic_error& err)
416 catch(
const runtime_error & err)
423 filename +
"'. Unknown error occured"));
441 vector<float> matrix;
442 pair<int,int> shape(0,0);
449 pair<double,double> center(0,0);
467 center.first = ccol.toDouble();
473 double xmin = -center.first;
474 double xmax = shape.first - center.first;
475 double ymin = -center.second;
476 double ymax = shape.second - center.second;
481 copy(matrix.begin(), matrix.end(), result->begin());
FileHandler(const QString &filename=QString())
constructor
readLine(qint64 maxlen=0)
result_t::shared_pointer loadDataFromCBF()
read the data from a cbf file
save(const QString &fileName, const char *format=0, int quality=-1)
A file output serializer.
split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive)
std::tr1::shared_ptr< self_type > shared_pointer
a shared pointer of this class
static void saveData(const QString &filename, result_t::shared_pointer data)
save data to a given file
read and write data to files
an axis of a more than 0 dimensional container
result_t::shared_pointer loadDataFromHist()
read the data from a hist file
remove(int position, int n)
tr(const char *sourceText, const char *disambiguation=0, int n=-1)
QImage loadImage(const QString &filename)
read the data from an image file
Axis< double > axe_t
the axis descriptions of this container
result_t::shared_pointer result(const QString &key, quint64 id=0)
retrieve an result from the file
void saveDataToCBF(const QString &filename, result_t::shared_pointer data)
save the data to a cbf file
void saveDataToH5(const QString &filename, result_t::shared_pointer data, const QString &mode="w")
write the data to a hdf5 file
fromStdString(const std::string &str)
static bool isContainerFile(const QString &filename)
return whether the file is a container file
QStringList resultNames()
retrieve the list of names that an be displayed from the file
A file input deserializer.
void read(const std::string &filename, std::string &headerstring, std::vector< float > &matrix, std::pair< int, int > &shape)
read the cbf data into a linearized 2d array
void saveDataToCSV(const QString &filename, result_t::shared_pointer data)
save the data from a CSV file
result_t::shared_pointer loadDataFromH5(const QString &key="")
read the data from a hdf5 file
void saveDataToHist(const QString &filename, result_t::shared_pointer data)
save the data from a hist file
contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive)
auxiliary data[Processor]
void setFilename(const QString &filename)
set the filename
cass::Result< float > result_t
define the result type
QString type() const
retrieve the type of source
QString _filename
the filename of the file to work on
result_t::shared_pointer loadDataFromCSV()
read the data from a CSV file
critical(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void saveImage(const QString &filename, const QImage &image)
save image data
void writeScalar(const type value, const std::string &valname)
write an scalar value with a given name as part of a given group
check if there is some light in the chamber based upon the GMD value
easier api for hdf5 file writing
static void createContainer(const QString &filename)
create the container file
static QString getBaseName(const QString &filename)
return the basename of the filename
void write(const std::string &filename, std::vector< float >::const_iterator data, const std::pair< int, int > &shape)
write cbf file