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
053d89a3
Commit
053d89a3
authored
1 year ago
by
Wuttke, Joachim
Browse files
Options
Downloads
Patches
Plain Diff
rm functional_read
parent
f01d5d34
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1629
IO further cleanup
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Device/IO/IOFactory.cpp
+46
-10
46 additions, 10 deletions
Device/IO/IOFactory.cpp
with
46 additions
and
10 deletions
Device/IO/IOFactory.cpp
+
46
−
10
View file @
053d89a3
...
@@ -39,6 +39,45 @@
...
@@ -39,6 +39,45 @@
#include
"Device/IO/boost_streams.h"
#include
"Device/IO/boost_streams.h"
#endif
#endif
namespace
{
std
::
stringstream
file2stream
(
const
std
::
string
&
file_name
)
{
if
(
!
BaseUtil
::
Filesystem
::
IsFileExists
(
file_name
))
throw
std
::
runtime_error
(
"File does not exist: "
+
file_name
);
using
namespace
DataUtil
::
Format
;
std
::
ifstream
input_stream
;
std
::
ios_base
::
openmode
openmode
=
std
::
ios
::
in
;
if
(
isTiffFile
(
file_name
)
||
isCompressed
(
file_name
))
openmode
=
std
::
ios
::
in
|
std
::
ios_base
::
binary
;
#ifdef _WIN32
input_stream
.
open
(
BaseUtil
::
Filesystem
::
convert_utf8_to_utf16
(
file_name
),
openmode
);
#else
input_stream
.
open
(
file_name
,
openmode
);
#endif
if
(
!
input_stream
.
is_open
())
throw
std
::
runtime_error
(
"Cannot open file for reading: "
+
file_name
);
if
(
!
input_stream
.
good
())
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
(
DataUtil
::
Format
::
isGZipped
(
file_name
))
input_filtered
.
push
(
boost
::
iostreams
::
gzip_decompressor
());
else
if
(
DataUtil
::
Format
::
isBZipped
(
file_name
))
input_filtered
.
push
(
boost
::
iostreams
::
bzip2_decompressor
());
input_filtered
.
push
(
input_stream
);
// we use stringstream since it provides random access which is important for tiff files
std
::
stringstream
str
;
boost
::
iostreams
::
copy
(
input_filtered
,
str
);
return
str
;
}
}
// namespace
Datafield
*
IOFactory
::
readDatafield
(
const
std
::
string
&
file_name
,
LoaderSelector
selector
)
Datafield
*
IOFactory
::
readDatafield
(
const
std
::
string
&
file_name
,
LoaderSelector
selector
)
{
{
const
auto
readAs
=
[
=
](
LoaderSelector
testForSelector
)
{
const
auto
readAs
=
[
=
](
LoaderSelector
testForSelector
)
{
...
@@ -47,33 +86,30 @@ Datafield* IOFactory::readDatafield(const std::string& file_name, LoaderSelector
...
@@ -47,33 +86,30 @@ Datafield* IOFactory::readDatafield(const std::string& file_name, LoaderSelector
&&
fileTypeMatchesLoaderSelector
(
file_name
,
testForSelector
));
&&
fileTypeMatchesLoaderSelector
(
file_name
,
testForSelector
));
};
};
Datafield
*
result
=
nullptr
;
auto
s
=
::
file2stream
(
file_name
)
;
if
(
readAs
(
bornagain
))
if
(
readAs
(
bornagain
))
result
=
functional_read
(
file_name
,
[](
std
::
istream
&
s
)
{
return
IO
::
readBAInt
(
s
);
});
return
IO
::
readBAInt
(
s
);
else
if
(
readAs
(
nicos
))
else
if
(
readAs
(
nicos
))
result
=
functional_read
(
file_name
,
[](
std
::
istream
&
s
)
{
return
IO
::
readNicos
(
s
);
});
return
IO
::
readNicos
(
s
);
#ifdef BA_TIFF_SUPPORT
#ifdef BA_TIFF_SUPPORT
else
if
(
readAs
(
tiff
))
else
if
(
readAs
(
tiff
))
result
=
functional_read
(
file_name
,
[](
std
::
istream
&
s
)
{
return
IO
::
readTiff
(
s
);
});
return
IO
::
readTiff
(
s
);
#endif
#endif
else
else
// Try to read ASCII by default. Binary maps to ASCII.
// Try to read ASCII by default. Binary maps to ASCII.
// If the file is not actually a matrix of numbers,
// If the file is not actually a matrix of numbers,
// the error will be thrown during the reading.
// the error will be thrown during the reading.
result
=
functional_read
(
file_name
,
[](
std
::
istream
&
s
)
{
return
IO
::
readNumpyTxt
(
s
);
});
return
IO
::
readNumpyTxt
(
s
);
ASSERT
(
result
);
return
result
;
}
}
Datafield
*
IOFactory
::
readReflectometryData
(
const
std
::
string
&
file_name
)
Datafield
*
IOFactory
::
readReflectometryData
(
const
std
::
string
&
file_name
)
{
{
return
functional_
rea
d
(
file_name
,
auto
s
=
file2st
rea
m
(
file_name
);
[](
std
::
istream
&
s
)
{
return
IO
::
readReflectometryTable
(
s
);
});
return
IO
::
readReflectometryTable
(
s
);
}
}
void
IOFactory
::
writeDatafield
(
const
Datafield
&
data
,
const
std
::
string
&
file_name
)
void
IOFactory
::
writeDatafield
(
const
Datafield
&
data
,
const
std
::
string
&
file_name
)
...
...
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