BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
OutputDataReadFactory.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Device/InputOutput/OutputDataReadFactory.cpp
6 //! @brief Implements class OutputDataReadFactory.
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 
16 #include "Base/Types/Exceptions.h"
18 
19 OutputDataReader* OutputDataReadFactory::getReader(const std::string& file_name)
20 {
21  OutputDataReader* result = new OutputDataReader(file_name);
22  result->setStrategy(getReadStrategy(file_name));
23  return result;
24 }
25 
27 {
28  OutputDataReader* result = new OutputDataReader(file_name);
30  return result;
31 }
32 
34 {
35  IOutputDataReadStrategy* result(nullptr);
36  if (DataFormatUtils::isIntFile(file_name))
37  result = new OutputDataReadINTStrategy();
38 #ifdef BORNAGAIN_TIFF_SUPPORT
39  else if (DataFormatUtils::isTiffFile(file_name))
40  result = new OutputDataReadTiffStrategy();
41 #endif // BORNAGAIN_TIFF_SUPPORT
42  else
43  // Try to read ASCII by default. Binary maps to ASCII.
44  // If the file is not actually a matrix of numbers,
45  // the error will be thrown during the reading.
46  result = new OutputDataReadNumpyTXTStrategy();
47  return result;
48 }
Defines class OutputDataIOFactory.
Defines many exception classes in namespace Exceptionss.
Defines class OutputDataReadFactory.
Interface for reading strategy of OutputData from file.
static OutputDataReader * getReflectometryReader(const std::string &file_name)
static OutputDataReader * getReader(const std::string &file_name)
static IOutputDataReadStrategy * getReadStrategy(const std::string &file_name)
Strategy to read BornAgain native IntensityData from ASCII file.
Strategy to read OutputData from simple ASCII file with the layout as in numpy.savetxt.
Strategy to read Reflectometry data from ASCII file.
Reads OutputData from file using different reading strategies.
void setStrategy(IOutputDataReadStrategy *read_strategy)
Sets concrete reading strategy.
bool isIntFile(const std::string &file_name)
returns true if file name corresponds to BornAgain native format (compressed or not)
bool isTiffFile(const std::string &file_name)
returns true if file name corresponds to tiff file (can be also compressed)