BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
IntensityDataIOFactory.h
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Device/Histo/IntensityDataIOFactory.h
6 //! @brief Defines class IntensityDataIOFactory.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************** //
14 
15 #ifndef BORNAGAIN_CORE_INPUTOUTPUT_INTENSITYDATAIOFACTORY_H
16 #define BORNAGAIN_CORE_INPUTOUTPUT_INTENSITYDATAIOFACTORY_H
17 
18 #include <string>
19 
20 template <class T> class OutputData;
21 class IHistogram;
22 class SimulationResult;
23 
24 //! Provides users with possibility to read and write IntensityData from/to files
25 //! in different format. Type of the file will be deduced from file name.
26 //! *.txt - ASCII file with 2D array [nrow][ncol], layout as in numpy.
27 //! *.int - BornAgain internal ASCII format.
28 //! *.tif - 32-bits tiff file.
29 //! If file name ends woth "*.gz" or "*.bz2" the file will be zipped on the fly using
30 //! appropriate algorithm.
31 
32 //! @ingroup input_output
33 
34 /*! Usage:
35 \code{.py}
36 # reading from ASCII file or g-zipped ASCII file
37 histogram = IntensityDataIOFactory.readIntensityData("filename.txt")
38 histogram = IntensityDataIOFactory.readIntensityData("filename.txt.gz")
39 
40 # writing to 32-bits tiff file or b-zipped tiff file
41 IntensityDataIOFactory.writeIntensityData(histogram, "filename.tif")
42 IntensityDataIOFactory.writeIntensityData(histogram, "filename.tif.bz2")
43 \endcode
44 */
45 
47 {
48 public:
49  //! Reads file and returns newly created OutputData object
50  static OutputData<double>* readOutputData(const std::string& file_name);
51  static OutputData<double>* readReflectometryData(const std::string& file_name);
52 
53  //! Reads file and returns newly created Histogram object
54  static IHistogram* readIntensityData(const std::string& file_name);
55 
56  //! Writes OutputData in file
57  static void writeOutputData(const OutputData<double>& data, const std::string& file_name);
58 
59  //! Writes histogram in file
60  static void writeIntensityData(const IHistogram& histogram, const std::string& file_name);
61 
62  //! Writes OutputData contained in the given SimulationResult object
63  static void writeSimulationResult(const SimulationResult& result, const std::string& file_name);
64 };
65 
66 #endif // BORNAGAIN_CORE_INPUTOUTPUT_INTENSITYDATAIOFACTORY_H
Base class for 1D and 2D histograms holding values of double type.
Definition: IHistogram.h:27
Provides users with possibility to read and write IntensityData from/to files in different format.
static OutputData< double > * readOutputData(const std::string &file_name)
Reads file and returns newly created OutputData object.
static void writeOutputData(const OutputData< double > &data, const std::string &file_name)
Writes OutputData in file.
static IHistogram * readIntensityData(const std::string &file_name)
Reads file and returns newly created Histogram object.
static void writeIntensityData(const IHistogram &histogram, const std::string &file_name)
Writes histogram in file.
static OutputData< double > * readReflectometryData(const std::string &file_name)
static void writeSimulationResult(const SimulationResult &result, const std::string &file_name)
Writes OutputData contained in the given SimulationResult object.
Template class to store data of any type in multi-dimensional space.
Definition: OutputData.h:33
Wrapper around OutputData<double> that also provides unit conversions.