Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
BornAgain
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mlz
BornAgain
Commits
43a47f48
Commit
43a47f48
authored
3 years ago
by
Wuttke, Joachim
Browse files
Options
Downloads
Patches
Plain Diff
improve error handling in data readers
parent
56e3634e
No related branches found
No related tags found
1 merge request
!474
Restore subroutine to read Nicos/SANSDRaw files, check for Nicos file type, provide unit test
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Device/Histo/IntensityDataIOFactory.cpp
+6
-12
6 additions, 12 deletions
Device/Histo/IntensityDataIOFactory.cpp
Tests/Unit/Device/ReadSANSDRawTest.cpp
+8
-2
8 additions, 2 deletions
Tests/Unit/Device/ReadSANSDRawTest.cpp
with
14 additions
and
14 deletions
Device/Histo/IntensityDataIOFactory.cpp
+
6
−
12
View file @
43a47f48
...
...
@@ -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
(
"C
ould not read
"
+
file_name
);
throw
std
::
runtime_error
(
"C
annot 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
))
...
...
This diff is collapsed.
Click to expand it.
Tests/Unit/Device/ReadSANSDRawTest.cpp
+
8
−
2
View file @
43a47f48
...
...
@@ -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
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment