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

Public Member Functions

 OutputDataReader (const std::string &file_name)
 
OutputData< double > * getOutputData ()
 
void setStrategy (IOutputDataReadStrategy *read_strategy)
 

Private Attributes

std::string m_file_name
 
std::unique_ptr< IOutputDataReadStrategym_read_strategy
 

Detailed Description

Reads OutputData from file using different reading strategies.

Definition at line 26 of file OutputDataReader.h.

Constructor & Destructor Documentation

◆ OutputDataReader()

OutputDataReader::OutputDataReader ( const std::string &  file_name)

Definition at line 50 of file OutputDataReader.cpp.

50 : m_file_name(file_name) {}
std::string m_file_name

Member Function Documentation

◆ getOutputData()

OutputData< double > * OutputDataReader::getOutputData ( )

read output data from file (file name was set already from OutputDataIOFactory)

Definition at line 52 of file OutputDataReader.cpp.

53 {
54  using namespace DataFormatUtils;
55  if (!m_read_strategy)
57  "OutputDataReader::getOutputData() -> Error! No read strategy defined");
58 
59  std::ifstream fin;
60  std::ios_base::openmode openmode = std::ios::in;
62  openmode = std::ios::in | std::ios_base::binary;
63 
64 #ifdef _WIN32
66 #else
67  fin.open(m_file_name, openmode);
68 #endif
69 
70  if (!fin.is_open())
72  "OutputDataReader::getOutputData() -> Error. Can't open file '" + m_file_name
73  + "' for reading.");
74  if (!fin.good())
75  throw Exceptions::FileIsBadException("OutputDataReader::getOutputData() -> Error! "
76  "File is not good, probably it is a directory.");
77 
78  std::stringstream strstream = getFromFilteredStream(fin, m_file_name);
79 
80  OutputData<double>* result = m_read_strategy->readOutputData(strstream);
81 
82  return result;
83 }
std::unique_ptr< IOutputDataReadStrategy > m_read_strategy
Utility functions for data input and output.
bool isCompressed(const std::string &name)
Returns true if name contains *.gz extension.
bool isTiffFile(const std::string &file_name)
returns true if file name corresponds to tiff file (can be also compressed)
std::wstring convert_utf8_to_utf16(const std::string &str)
Converts utf8 string represented by std::string to utf16 string represented by std::wstring.
std::stringstream getFromFilteredStream(std::istream &input_stream, const std::string &fname)

References FileSystemUtils::convert_utf8_to_utf16(), anonymous_namespace{OutputDataReader.cpp}::getFromFilteredStream(), DataFormatUtils::isCompressed(), DataFormatUtils::isTiffFile(), m_file_name, and m_read_strategy.

Here is the call graph for this function:

◆ setStrategy()

void OutputDataReader::setStrategy ( IOutputDataReadStrategy read_strategy)

Sets concrete reading strategy.

Definition at line 85 of file OutputDataReader.cpp.

86 {
87  m_read_strategy.reset(read_strategy);
88 }

References m_read_strategy.

Referenced by OutputDataReadFactory::getReader(), and OutputDataReadFactory::getReflectometryReader().

Member Data Documentation

◆ m_file_name

std::string OutputDataReader::m_file_name
private

Definition at line 38 of file OutputDataReader.h.

Referenced by getOutputData().

◆ m_read_strategy

std::unique_ptr<IOutputDataReadStrategy> OutputDataReader::m_read_strategy
private

Definition at line 39 of file OutputDataReader.h.

Referenced by getOutputData(), and setStrategy().


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