BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
IntensityDataIOFactory Class Reference
Collaboration diagram for IntensityDataIOFactory:

Static Public Member Functions

static OutputData< double > * readOutputData (const std::string &file_name)
 
static OutputData< double > * readReflectometryData (const std::string &file_name)
 
static IHistogramreadIntensityData (const std::string &file_name)
 
static void writeOutputData (const OutputData< double > &data, const std::string &file_name)
 
static void writeIntensityData (const IHistogram &histogram, const std::string &file_name)
 
static void writeSimulationResult (const SimulationResult &result, const std::string &file_name)
 

Detailed Description

Provides users with possibility to read and write IntensityData from/to files in different format.

Type of the file will be deduced from file name. *.txt - ASCII file with 2D array [nrow][ncol], layout as in numpy. *.int - BornAgain internal ASCII format. *.tif - 32-bits tiff file. If file name ends woth "*.gz" or "*.bz2" the file will be zipped on the fly using appropriate algorithm.

Usage:

# reading from ASCII file or g-zipped ASCII file
histogram = IntensityDataIOFactory.readIntensityData("filename.txt")
histogram = IntensityDataIOFactory.readIntensityData("filename.txt.gz")
# writing to 32-bits tiff file or b-zipped tiff file
IntensityDataIOFactory.writeIntensityData(histogram, "filename.tif.bz2")
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.

Definition at line 46 of file IntensityDataIOFactory.h.

Member Function Documentation

◆ readOutputData()

OutputData< double > * IntensityDataIOFactory::readOutputData ( const std::string &  file_name)
static

Reads file and returns newly created OutputData object.

Definition at line 25 of file IntensityDataIOFactory.cpp.

26 {
27  if (!FileSystemUtils::IsFileExists(file_name))
28  return nullptr;
29  std::unique_ptr<OutputDataReader> reader(OutputDataReadFactory::getReader(file_name));
30  if (reader)
31  return reader->getOutputData();
32  return nullptr;
33 }
static OutputDataReader * getReader(const std::string &file_name)
bool IsFileExists(const std::string &str)
Returns true if file with given name exists on disk.

References OutputDataReadFactory::getReader(), and FileSystemUtils::IsFileExists().

Referenced by readIntensityData().

Here is the call graph for this function:

◆ readReflectometryData()

OutputData< double > * IntensityDataIOFactory::readReflectometryData ( const std::string &  file_name)
static

Definition at line 35 of file IntensityDataIOFactory.cpp.

36 {
37  if (!FileSystemUtils::IsFileExists(file_name))
38  return nullptr;
39  std::unique_ptr<OutputDataReader> reader(
41  if (reader)
42  return reader->getOutputData();
43  return nullptr;
44 }
static OutputDataReader * getReflectometryReader(const std::string &file_name)

References OutputDataReadFactory::getReflectometryReader(), and FileSystemUtils::IsFileExists().

Here is the call graph for this function:

◆ readIntensityData()

IHistogram * IntensityDataIOFactory::readIntensityData ( const std::string &  file_name)
static

Reads file and returns newly created Histogram object.

Definition at line 46 of file IntensityDataIOFactory.cpp.

47 {
48  std::unique_ptr<OutputData<double>> data(readOutputData(file_name));
49  if (!data)
50  throw std::runtime_error("Could not read " + file_name);
51  return IHistogram::createHistogram(*data);
52 }
static IHistogram * createHistogram(const OutputData< double > &source)
Definition: IHistogram.cpp:233
static OutputData< double > * readOutputData(const std::string &file_name)
Reads file and returns newly created OutputData object.

References IHistogram::createHistogram(), and readOutputData().

Referenced by IHistogram::createFrom(), and IHistogram::load().

Here is the call graph for this function:

◆ writeOutputData()

void IntensityDataIOFactory::writeOutputData ( const OutputData< double > &  data,
const std::string &  file_name 
)
static

Writes OutputData in file.

Definition at line 54 of file IntensityDataIOFactory.cpp.

56 {
57  auto* writer = OutputDataWriteFactory::getWriter(file_name);
58  writer->writeOutputData(data);
59  delete writer;
60 }
static OutputDataWriter * getWriter(const std::string &file_name)

References OutputDataWriteFactory::getWriter().

Referenced by writeIntensityData(), and writeSimulationResult().

Here is the call graph for this function:

◆ writeIntensityData()

void IntensityDataIOFactory::writeIntensityData ( const IHistogram histogram,
const std::string &  file_name 
)
static

Writes histogram in file.

Definition at line 62 of file IntensityDataIOFactory.cpp.

64 {
65  std::unique_ptr<OutputData<double>> data(histogram.createOutputData());
66  writeOutputData(*data, file_name);
67 }
OutputData< double > * createOutputData(DataType dataType=DataType::INTEGRAL) const
creates new OutputData with histogram's shape and values corresponding to DataType
Definition: IHistogram.cpp:334
static void writeOutputData(const OutputData< double > &data, const std::string &file_name)
Writes OutputData in file.

References IHistogram::createOutputData(), and writeOutputData().

Referenced by IHistogram::save().

Here is the call graph for this function:

◆ writeSimulationResult()

void IntensityDataIOFactory::writeSimulationResult ( const SimulationResult result,
const std::string &  file_name 
)
static

Writes OutputData contained in the given SimulationResult object.

Definition at line 69 of file IntensityDataIOFactory.cpp.

71 {
72  auto data = result.data();
73  writeOutputData(*data, file_name);
74 }
std::unique_ptr< OutputData< double > > data(Axes::Units units=Axes::Units::DEFAULT) const

References SimulationResult::data(), and writeOutputData().

Here is the call graph for this function:

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