CFEL - ASG Software Suite  2.5.0
CASS
file_handler.h
Go to the documentation of this file.
1 // Copyright (C) 2013 Lutz Foucar
2 
3 /**
4  * @file file_handler.h contains a file handler
5  *
6  * @author Lutz Foucar
7  */
8 
9 #ifndef _FILE_HANDLER_
10 #define _FILE_HANDLER_
11 
12 #include "data_source.h"
13 
14 namespace cass
15 {
16 class HistogramBackend;
17 }//end namespace cass
18 
19 class QString;
20 class QImage;
21 class QStringList;
22 
23 namespace jocassview
24 {
25 
26 /** read and write data to files
27  *
28  * @author Lutz Foucar
29  */
30 class FileHandler : public DataSource
31 {
32 public:
33  /** constructor
34  *
35  * @param filename the filename that the handler handels
36  */
37  FileHandler(const QString &filename=QString());
38 
39  /** return the basename of the filename
40  *
41  * @return basename of filename
42  * @param filename the filename whos basename should be extracted
43  */
44  static QString getBaseName(const QString &filename);
45 
46  /** return whether the file is a container file
47  *
48  * @return true when the file is a container file (e.g. hdf5 file)
49  * @param filename the name of the file
50  */
51  static bool isContainerFile(const QString &filename);
52 
53  /** save data to a given file
54  *
55  * @param filename The filename to save the data to
56  * @param data the data to save
57  */
58  static void saveData(const QString &filename, result_t::shared_pointer data);
59 
60  /** create the container file
61  *
62  * @param filename The filename to save the data to
63  */
64  static void createContainer(const QString &filename);
65 
66  /** retrieve an result from the file
67  *
68  * @param key the key of the result
69  * @param id the eventid of the result
70  */
71  result_t::shared_pointer result(const QString &key, quint64 id=0);
72 
73  /** retrieve the list of names that an be displayed from the file
74  *
75  * @return list of names of displayable items
76  */
78 
79  /** retrieve the type of source
80  *
81  * @return "File"
82  */
83  QString type()const;
84 
85  /** set the filename
86  *
87  * @param filename the filename to work on
88  */
89  void setFilename(const QString &filename);
90 
91 private:
92  /** read the data from an image file
93  *
94  * @return the image
95  * @param filename the name of the file that contains the image data
96  */
97  QImage loadImage(const QString &filename);
98 
99  /** save image data
100  *
101  * @param filename the name of the file to save the image in
102  * @param image the image to save
103  */
104  void saveImage(const QString &filename,const QImage &image);
105 
106  /** read the data from a hist file
107  *
108  * @return pointer to the data
109  */
111 
112  /** save the data from a hist file
113  *
114  * @param filename the name of the file
115  * @param data pointer to the data to save
116  */
117  void saveDataToHist(const QString &filename, result_t::shared_pointer data);
118 
119  /** read the data from a CSV file
120  *
121  * @return pointer to the data
122  */
124 
125  /** save the data from a CSV file
126  *
127  * @param filename the name of the file
128  * @param data pointer to the data to save
129  */
130  void saveDataToCSV(const QString &filename, result_t::shared_pointer data);
131 
132  /** read the data from a hdf5 file
133  *
134  * @return pointer to the data
135  * @param key in case of a hdf5 file the key to the requested data. Default is ""
136  */
138 
139  /** write the data to a hdf5 file
140  *
141  * The key under which name the data is saved in the file is given provided as
142  * part of the data.
143  *
144  * @sa hdf5::Handler::open for options how the file will be opened
145  *
146  * @param filename the name of the file
147  * @param data pointer to the data
148  * @param mode The mode in which the file will be opened. Default is "w".
149  */
150  void saveDataToH5(const QString &filename, result_t::shared_pointer data, const QString& mode="w");
151 
152  /** read the data from a cbf file
153  *
154  * @return pointer to the data
155  */
157 
158  /** save the data to a cbf file
159  *
160  * @param filename the name of the file
161  * @param data pointer to the data
162  */
163  void saveDataToCBF(const QString &filename, result_t::shared_pointer data);
164 
165 private:
166  /** the filename of the file to work on */
168 };
169 }//end namespace jocassview
170 #endif
FileHandler(const QString &filename=QString())
constructor
result_t::shared_pointer loadDataFromCBF()
read the data from a cbf file
std::tr1::shared_ptr< self_type > shared_pointer
a shared pointer of this class
Definition: result.hpp:323
contains the base class data sources
static void saveData(const QString &filename, result_t::shared_pointer data)
save data to a given file
read and write data to files
Definition: file_handler.h:30
result_t::shared_pointer loadDataFromHist()
read the data from a hist file
QImage loadImage(const QString &filename)
read the data from an image file
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
base class for data sources
Definition: data_source.h:26
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
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
auxiliary data[Processor]
void setFilename(const QString &filename)
set the filename
QString type() const
retrieve the type of source
QString _filename
the filename of the file to work on
Definition: file_handler.h:167
result_t::shared_pointer loadDataFromCSV()
read the data from a CSV file
void saveImage(const QString &filename, const QImage &image)
save image data
static void createContainer(const QString &filename)
create the container file
static QString getBaseName(const QString &filename)
return the basename of the filename