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
ec650f08
Commit
ec650f08
authored
3 years ago
by
Wuttke, Joachim
Browse files
Options
Downloads
Patches
Plain Diff
anon. namespace to top
parent
165d3b70
No related branches found
No related tags found
1 merge request
!53
copy edit in axis and converter context
Pipeline
#35688
passed
3 years ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Device/InputOutput/DataFormatUtils.cpp
+69
-74
69 additions, 74 deletions
Device/InputOutput/DataFormatUtils.cpp
with
69 additions
and
74 deletions
Device/InputOutput/DataFormatUtils.cpp
+
69
−
74
View file @
ec650f08
...
@@ -23,13 +23,76 @@
...
@@ -23,13 +23,76 @@
#include
<iterator>
#include
<iterator>
namespace
{
namespace
{
s
td
::
istr
ing
st
rea
m
getAxisStringRepresentation
(
std
::
istream
&
input_stream
)
;
u
sing
c
rea
teAxisFun
=
std
::
function
<
std
::
unique_ptr
<
IAxis
>
(
std
::
istringstream
iss
)
>
;
template
<
class
Axis
>
std
::
unique_ptr
<
IAxis
>
createFixedBinLikeAxis
(
std
::
istringstream
iss
);
const
std
::
string
GzipExtension
=
".gz"
;
std
::
unique_ptr
<
IAxis
>
createVariableBinAxis
(
std
::
istringstream
iss
);
const
std
::
string
BzipExtension
=
".bz2"
;
std
::
unique_ptr
<
IAxis
>
createPointwiseAxis
(
std
::
istringstream
iss
);
const
std
::
string
IntExtension
=
".int"
;
const
std
::
string
NicosExtension
=
".001"
;
const
std
::
string
TiffExtension
=
".tif"
;
const
std
::
string
TiffExtension2
=
".tiff"
;
std
::
istringstream
getAxisStringRepresentation
(
std
::
istream
&
input_stream
)
{
std
::
string
line
;
std
::
getline
(
input_stream
,
line
);
const
std
::
vector
<
std
::
string
>
to_replace
=
{
","
,
"
\"
"
,
"("
,
")"
,
"["
,
"]"
};
StringUtils
::
replaceItemsFromString
(
line
,
to_replace
,
" "
);
return
std
::
istringstream
(
line
);
}
//! Creates one of FixedBinAxis from string representation
//! FixedBinAxis("axis0", 10, -1, 1)
//! ConstKBinAxis("axis0", 10, -1, 1)
//! CustomBinAxis("axis0", 10, -1, 1)
template
<
class
Axis
>
std
::
unique_ptr
<
IAxis
>
createFixedBinLikeAxis
(
std
::
istringstream
iss
)
{
std
::
string
name
;
size_t
nbins
(
0
);
if
(
!
(
iss
>>
name
>>
nbins
))
throw
std
::
runtime_error
(
"createFixedBinLikeAxis() -> Error. Can't parse the string."
);
std
::
vector
<
double
>
boundaries
;
DataFormatUtils
::
readLineOfDoubles
(
boundaries
,
iss
);
if
(
boundaries
.
size
()
!=
2
)
throw
std
::
runtime_error
(
"Error in createFixedBinLikeAxis: Can't parse the string while "
"reading boundaries."
);
return
std
::
make_unique
<
Axis
>
(
name
,
nbins
,
boundaries
[
0
],
boundaries
[
1
]);
}
//! Creates VariableBinAxis from string representation
//! VariableBinAxis("axis0", 4, [-1, -0.5, 0.5, 1, 2])
std
::
unique_ptr
<
IAxis
>
createVariableBinAxis
(
std
::
istringstream
iss
)
{
std
::
string
name
;
size_t
nbins
(
0
);
if
(
!
(
iss
>>
name
>>
nbins
))
throw
std
::
runtime_error
(
"Error in createVariableBinAxis: Can't parse the string."
);
std
::
vector
<
double
>
boundaries
;
DataFormatUtils
::
readLineOfDoubles
(
boundaries
,
iss
);
if
(
boundaries
.
size
()
!=
nbins
+
1
)
throw
std
::
runtime_error
(
"Error in createVariableBinAxis: wrong number of boundaries read."
);
return
std
::
make_unique
<
VariableBinAxis
>
(
name
,
nbins
,
boundaries
);
}
//! Creates createPointwiseAxis from string representation
//! PointwiseAxis("axis0", [-0.5, 0.5, 1, 2])
std
::
unique_ptr
<
IAxis
>
createPointwiseAxis
(
std
::
istringstream
iss
)
{
std
::
string
name
;
if
(
!
(
iss
>>
name
))
throw
std
::
runtime_error
(
"Error in createPointwiseAxis:Can't parse the string."
);
std
::
vector
<
double
>
coordinates
;
DataFormatUtils
::
readLineOfDoubles
(
coordinates
,
iss
);
return
std
::
make_unique
<
PointwiseAxis
>
(
name
,
coordinates
);
}
using
createAxisFun
=
std
::
function
<
std
::
unique_ptr
<
IAxis
>
(
std
::
istringstream
iss
)
>
;
const
std
::
vector
<
std
::
pair
<
std
::
string
,
createAxisFun
>>
type_map
=
{
const
std
::
vector
<
std
::
pair
<
std
::
string
,
createAxisFun
>>
type_map
=
{
{
"ConstKBinAxis"
,
createFixedBinLikeAxis
<
ConstKBinAxis
>
},
{
"ConstKBinAxis"
,
createFixedBinLikeAxis
<
ConstKBinAxis
>
},
{
"CustomBinAxis"
,
createFixedBinLikeAxis
<
CustomBinAxis
>
},
{
"CustomBinAxis"
,
createFixedBinLikeAxis
<
CustomBinAxis
>
},
...
@@ -37,14 +100,9 @@ const std::vector<std::pair<std::string, createAxisFun>> type_map = {
...
@@ -37,14 +100,9 @@ const std::vector<std::pair<std::string, createAxisFun>> type_map = {
{
"PointwiseAxis"
,
createPointwiseAxis
},
{
"PointwiseAxis"
,
createPointwiseAxis
},
{
"VariableBinAxis"
,
createVariableBinAxis
}};
{
"VariableBinAxis"
,
createVariableBinAxis
}};
const
std
::
string
GzipExtension
=
".gz"
;
const
std
::
string
BzipExtension
=
".bz2"
;
const
std
::
string
IntExtension
=
".int"
;
const
std
::
string
NicosExtension
=
".001"
;
const
std
::
string
TiffExtension
=
".tif"
;
const
std
::
string
TiffExtension2
=
".tiff"
;
}
// namespace
}
// namespace
bool
DataFormatUtils
::
isCompressed
(
const
std
::
string
&
name
)
bool
DataFormatUtils
::
isCompressed
(
const
std
::
string
&
name
)
{
{
return
isGZipped
(
name
)
||
isBZipped
(
name
);
return
isGZipped
(
name
)
||
isBZipped
(
name
);
...
@@ -160,66 +218,3 @@ void DataFormatUtils::readLineOfDoubles(std::vector<double>& buffer, std::istrin
...
@@ -160,66 +218,3 @@ void DataFormatUtils::readLineOfDoubles(std::vector<double>& buffer, std::istrin
std
::
copy
(
std
::
istream_iterator
<
double
>
(
iss
),
std
::
istream_iterator
<
double
>
(),
std
::
copy
(
std
::
istream_iterator
<
double
>
(
iss
),
std
::
istream_iterator
<
double
>
(),
back_inserter
(
buffer
));
back_inserter
(
buffer
));
}
}
namespace
{
std
::
istringstream
getAxisStringRepresentation
(
std
::
istream
&
input_stream
)
{
std
::
string
line
;
std
::
getline
(
input_stream
,
line
);
const
std
::
vector
<
std
::
string
>
to_replace
=
{
","
,
"
\"
"
,
"("
,
")"
,
"["
,
"]"
};
StringUtils
::
replaceItemsFromString
(
line
,
to_replace
,
" "
);
return
std
::
istringstream
(
line
);
}
//! Creates one of FixedBinAxis from string representation
//! FixedBinAxis("axis0", 10, -1, 1)
//! ConstKBinAxis("axis0", 10, -1, 1)
//! CustomBinAxis("axis0", 10, -1, 1)
template
<
class
Axis
>
std
::
unique_ptr
<
IAxis
>
createFixedBinLikeAxis
(
std
::
istringstream
iss
)
{
std
::
string
name
;
size_t
nbins
(
0
);
if
(
!
(
iss
>>
name
>>
nbins
))
throw
std
::
runtime_error
(
"createFixedBinLikeAxis() -> Error. Can't parse the string."
);
std
::
vector
<
double
>
boundaries
;
DataFormatUtils
::
readLineOfDoubles
(
boundaries
,
iss
);
if
(
boundaries
.
size
()
!=
2
)
throw
std
::
runtime_error
(
"Error in createFixedBinLikeAxis: Can't parse the string while "
"reading boundaries."
);
return
std
::
make_unique
<
Axis
>
(
name
,
nbins
,
boundaries
[
0
],
boundaries
[
1
]);
}
//! Creates VariableBinAxis from string representation
//! VariableBinAxis("axis0", 4, [-1, -0.5, 0.5, 1, 2])
std
::
unique_ptr
<
IAxis
>
createVariableBinAxis
(
std
::
istringstream
iss
)
{
std
::
string
name
;
size_t
nbins
(
0
);
if
(
!
(
iss
>>
name
>>
nbins
))
throw
std
::
runtime_error
(
"Error in createVariableBinAxis: Can't parse the string."
);
std
::
vector
<
double
>
boundaries
;
DataFormatUtils
::
readLineOfDoubles
(
boundaries
,
iss
);
if
(
boundaries
.
size
()
!=
nbins
+
1
)
throw
std
::
runtime_error
(
"Error in createVariableBinAxis: wrong number of boundaries read."
);
return
std
::
make_unique
<
VariableBinAxis
>
(
name
,
nbins
,
boundaries
);
}
//! Creates createPointwiseAxis from string representation
//! PointwiseAxis("axis0", [-0.5, 0.5, 1, 2])
std
::
unique_ptr
<
IAxis
>
createPointwiseAxis
(
std
::
istringstream
iss
)
{
std
::
string
name
;
if
(
!
(
iss
>>
name
))
throw
std
::
runtime_error
(
"Error in createPointwiseAxis:Can't parse the string."
);
std
::
vector
<
double
>
coordinates
;
DataFormatUtils
::
readLineOfDoubles
(
coordinates
,
iss
);
return
std
::
make_unique
<
PointwiseAxis
>
(
name
,
coordinates
);
}
}
// namespace
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