Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mantid
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mantidproject
mantid
Commits
102ab896
Commit
102ab896
authored
12 years ago
by
Zhou, Wenduo
Browse files
Options
Downloads
Patches
Plain Diff
More flexible in input of MaskBinsFromTable. Refs #5450.
parent
80b98689
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Code/Mantid/Framework/Algorithms/src/MaskBinsFromTable.cpp
+42
-3
42 additions, 3 deletions
Code/Mantid/Framework/Algorithms/src/MaskBinsFromTable.cpp
Code/Mantid/Framework/Algorithms/test/MaskBinsFromTableTest.h
+48
-0
48 additions, 0 deletions
.../Mantid/Framework/Algorithms/test/MaskBinsFromTableTest.h
with
90 additions
and
3 deletions
Code/Mantid/Framework/Algorithms/src/MaskBinsFromTable.cpp
+
42
−
3
View file @
102ab896
...
...
@@ -55,13 +55,45 @@ namespace Algorithms
// 1. Check input table workspace and column order
g_log
.
debug
()
<<
"Lines of parameters workspace = "
<<
paramWS
->
rowCount
()
<<
std
::
endl
;
bool
colname_specx
=
false
;
if
(
!
paramWS
)
{
throw
std
::
invalid_argument
(
"Input table workspace is not accepted."
);
throw
std
::
invalid_argument
(
"Input table workspace is not accepted."
);
}
else
{
std
::
vector
<
std
::
string
>
colnames
=
paramWS
->
getColumnNames
();
// check colum name order
if
(
colnames
.
size
()
<
3
)
{
g_log
.
error
()
<<
"Input MaskingInformation table workspace has fewer than 3 columns. "
<<
colnames
.
size
()
<<
" columns indeed"
<<
std
::
endl
;
throw
std
::
invalid_argument
(
"MaskingInformation (TableWorkspace) has too few columns."
);
}
if
(
colnames
[
0
].
compare
(
"XMin"
)
==
0
)
{
// 1. Style XMin, XMax, SpectraList. Check rest
if
(
colnames
[
1
].
compare
(
"XMax"
)
!=
0
||
colnames
[
2
].
compare
(
"SpectraList"
)
!=
0
)
{
g_log
.
error
()
<<
"INput MaskingInformation table workspace has wrong column order. "
<<
std
::
endl
;
throw
std
::
invalid_argument
(
"MaskingInformation (TableWorkspace) has too few columns."
);
}
}
else
if
(
colnames
[
0
].
compare
(
"SpectraList"
)
==
0
)
{
// 2. Style SpectraList, XMin, XMax
colname_specx
=
true
;
if
(
colnames
[
1
].
compare
(
"XMin"
)
!=
0
||
colnames
[
2
].
compare
(
"XMax"
)
!=
0
)
{
g_log
.
error
()
<<
"INput MaskingInformation table workspace has wrong column order. "
<<
std
::
endl
;
throw
std
::
invalid_argument
(
"MaskingInformation (TableWorkspace) has too few columns."
);
}
}
else
{
g_log
.
error
()
<<
"INput MaskingInformation table workspace has wrong column order. "
<<
std
::
endl
;
throw
std
::
invalid_argument
(
"MaskingInformation (TableWorkspace) has too few columns."
);
}
}
// 2. Loop over all rows
...
...
@@ -73,7 +105,14 @@ namespace Algorithms
API
::
TableRow
therow
=
paramWS
->
getRow
(
ib
);
double
xmin
,
xmax
;
std
::
string
speclist
;
therow
>>
xmin
>>
xmax
>>
speclist
;
if
(
colname_specx
)
{
therow
>>
speclist
>>
xmin
>>
xmax
;
}
else
{
therow
>>
xmin
>>
xmax
>>
speclist
;
}
g_log
.
debug
()
<<
"Row "
<<
ib
<<
" XMin = "
<<
xmin
<<
" XMax = "
<<
xmax
<<
" SpectraList = "
<<
speclist
<<
std
::
endl
;
...
...
This diff is collapsed.
Click to expand it.
Code/Mantid/Framework/Algorithms/test/MaskBinsFromTableTest.h
+
48
−
0
View file @
102ab896
...
...
@@ -221,6 +221,54 @@ public:
return
;
}
/*
* In-place single mask test.
* Same as the test in MaskBins()
* With TableWorkspace of column in different order
*/
void
test_MaskBinWithSingleLine2
()
{
// 1. Create a dummy workspace
const
std
::
string
workspaceName
(
"raggedMask"
);
int
nBins
=
10
;
MatrixWorkspace_sptr
WS
=
WorkspaceCreationHelper
::
Create2DWorkspaceBinned
(
5
,
nBins
,
0.0
);
AnalysisDataService
::
Instance
().
add
(
workspaceName
,
WS
);
// 2. Generate a TableWorskpace
DataObjects
::
TableWorkspace_sptr
tablews
=
boost
::
shared_ptr
<
DataObjects
::
TableWorkspace
>
(
new
DataObjects
::
TableWorkspace
());
tablews
->
addColumn
(
"str"
,
"SpectraList"
);
tablews
->
addColumn
(
"double"
,
"XMin"
);
tablews
->
addColumn
(
"double"
,
"XMax"
);
API
::
TableRow
row0
=
tablews
->
appendRow
();
row0
<<
"1-3"
<<
3.0
<<
6.0
;
// 3. Execute
MaskBinsFromTable
maskalg
;
TS_ASSERT_THROWS_NOTHING
(
maskalg
.
initialize
());
maskalg
.
setPropertyValue
(
"InputWorkspace"
,
workspaceName
);
maskalg
.
setPropertyValue
(
"OutputWorkspace"
,
workspaceName
);
maskalg
.
setProperty
(
"MaskingInformation"
,
tablews
);
TS_ASSERT_THROWS_NOTHING
(
maskalg
.
execute
());
TS_ASSERT
(
maskalg
.
isExecuted
());
// 4. Check
WS
=
boost
::
dynamic_pointer_cast
<
API
::
MatrixWorkspace
>
(
AnalysisDataService
::
Instance
().
retrieve
(
workspaceName
));
TS_ASSERT
(
WS
);
for
(
int
wi
=
1
;
wi
<=
3
;
wi
++
)
{
for
(
int
bin
=
3
;
bin
<
6
;
bin
++
)
{
TS_ASSERT_EQUALS
(
WS
->
dataY
(
wi
)[
bin
],
0.0
);
}
}
// 5. Clean
AnalysisDataService
::
Instance
().
remove
(
workspaceName
);
return
;
}
};
...
...
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