Skip to content
Snippets Groups Projects
Commit 43a47f48 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

improve error handling in data readers

parent 56e3634e
No related branches found
No related tags found
1 merge request!474Restore subroutine to read Nicos/SANSDRaw files, check for Nicos file type, provide unit test
......@@ -76,7 +76,7 @@ IHistogram* IntensityDataIOFactory::readIntensityData(const std::string& file_na
{
std::unique_ptr<OutputData<double>> data(readOutputData(file_name));
if (!data)
throw std::runtime_error("Could not read " + file_name);
throw std::runtime_error("Cannot read intensity data from file: " + file_name);
return IHistogram::createHistogram(*data);
}
......@@ -115,12 +115,9 @@ void IntensityDataIOFactory::writeOutputData(const std::string& file_name,
#endif
if (!fout.is_open())
throw std::runtime_error("IntensityDataIOFactory::writeOutputData() -> Error. "
"Can't open file '"
+ file_name + "' for writing.");
throw std::runtime_error("Cannot open file for writing: " + file_name);
if (!fout.good())
throw std::runtime_error("IntensityDataIOFactory::writeOutputData() -> Error! "
"File is not good, probably it is a directory.");
throw std::runtime_error("File is not good, probably it is a directory: " + file_name);
std::stringstream ss;
writeData(ss);
......@@ -173,7 +170,7 @@ IntensityDataIOFactory::readOutputData(const std::string& file_name,
{
if (!BaseUtils::Filesystem::IsFileExists(file_name))
return nullptr;
throw std::runtime_error("File does not exist: " + file_name);
using namespace DataUtils::Format;
std::ifstream input_stream;
......@@ -188,12 +185,9 @@ IntensityDataIOFactory::readOutputData(const std::string& file_name,
#endif
if (!input_stream.is_open())
throw std::runtime_error(
"IntensityDataIOFactory::getFromFilteredStream() -> Error. Can't open file '"
+ file_name + "' for reading.");
throw std::runtime_error("Cannot open file for reading: " + file_name);
if (!input_stream.good())
throw std::runtime_error("IntensityDataIOFactory::getFromFilteredStream() -> Error! "
"File is not good, probably it is a directory.");
throw std::runtime_error("File is not good, probably it is a directory:" + file_name);
boost::iostreams::filtering_streambuf<boost::iostreams::input> input_filtered;
if (DataUtils::Format::isGZipped(file_name))
......
......@@ -2,16 +2,22 @@
#include "Device/Data/OutputData.h"
#include "BATesting.h"
#include "Tests/GTestWrapper/google_test.h"
#include <cstdio>
class ReadSANSDRawTest : public ::testing::Test {
};
TEST_F(ReadSANSDRawTest, Read)
{
const auto fname = BATesting::ExampleDataDir() + "SANSDRaw.001";
const auto fname = BATesting::ExampleDataDir() + "/SANSDRaw.001";
OutputData<double>* data =
IntensityDataIOFactory::readOutputData(fname, IntensityDataIOFactory::automatic);
EXPECT_NE(data, nullptr);
if (!data)
return;
EXPECT_EQ(data->rank(), 2);
EXPECT_EQ(data->getAllocatedSize(), 16384);
EXPECT_EQ((*data)[128*128-1], 3);
for(int i=0; i<16384; ++i)
printf("%5i %5i\n", i, (int)(*data)[i]);
EXPECT_EQ((*data)[64*64-1], 3);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment