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
647e008c
Commit
647e008c
authored
6 years ago
by
Matthew Andrew
Browse files
Options
Downloads
Patches
Plain Diff
Added const's and changed to use isGroup Re #23642
parent
f370cd7f
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
Framework/Muon/src/MuonPairingAsymmetry.cpp
+29
-31
29 additions, 31 deletions
Framework/Muon/src/MuonPairingAsymmetry.cpp
Framework/Muon/test/MuonPairingAsymmetryTest.h
+29
-29
29 additions, 29 deletions
Framework/Muon/test/MuonPairingAsymmetryTest.h
with
58 additions
and
60 deletions
Framework/Muon/src/MuonPairingAsymmetry.cpp
+
29
−
31
View file @
647e008c
...
...
@@ -23,25 +23,26 @@ using namespace Mantid::Kernel;
namespace
{
bool
checkPeriodInWorkspaceGroup
(
const
int
&
period
,
WorkspaceGroup_sptr
workspace
)
{
WorkspaceGroup_
const_
sptr
workspace
)
{
return
period
<=
workspace
->
getNumberOfEntries
();
}
bool
isMultiPeriod
(
Workspace_sptr
ws
)
{
if
(
auto
tmp
=
boost
::
dynamic_pointer_cast
<
WorkspaceGroup
>
(
ws
))
{
return
true
;
}
return
false
;
bool
isMultiPeriod
(
Workspace_const_sptr
ws
)
{
return
ws
->
isGroup
();
}
int
countPeriods
(
Workspace_sptr
ws
)
{
auto
tmp
=
boost
::
dynamic_pointer_cast
<
WorkspaceGroup
>
(
ws
);
return
tmp
->
getNumberOfEntries
();
if
(
auto
tmp
=
boost
::
dynamic_pointer_cast
<
WorkspaceGroup
>
(
ws
)){
return
tmp
->
getNumberOfEntries
();
}
else
{
return
1
;
}
}
bool
checkConsistentPeriods
(
Workspace_sptr
ws1
,
Workspace_sptr
ws2
)
{
if
(
isMultiPeriod
(
ws1
))
{
if
(
!
isMultiPeriod
(
ws2
))
{
if
(
ws1
->
isGroup
(
))
{
if
(
!
ws2
->
isGroup
(
))
{
return
false
;
}
if
(
countPeriods
(
ws1
)
!=
countPeriods
(
ws2
))
{
...
...
@@ -89,7 +90,7 @@ MatrixWorkspace_sptr groupDetectors(MatrixWorkspace_sptr workspace,
WorkspaceGroup_sptr
workspaceToWorkspaceGroup
(
Workspace_sptr
workspace
)
{
WorkspaceGroup_sptr
ws1
;
if
(
isMultiPeriod
(
workspace
))
{
if
(
workspace
->
isGroup
(
))
{
ws1
=
boost
::
dynamic_pointer_cast
<
WorkspaceGroup
>
(
workspace
);
}
else
{
ws1
=
boost
::
make_shared
<
WorkspaceGroup
>
();
...
...
@@ -108,8 +109,8 @@ DECLARE_ALGORITHM(MuonPairingAsymmetry)
void
MuonPairingAsymmetry
::
init
()
{
std
::
string
emptyString
(
""
);
std
::
vector
<
int
>
defaultGrouping1
=
{
1
};
std
::
vector
<
int
>
defaultGrouping2
=
{
2
};
const
std
::
vector
<
int
>
defaultGrouping1
=
{
1
};
const
std
::
vector
<
int
>
defaultGrouping2
=
{
2
};
declareProperty
(
Mantid
::
Kernel
::
make_unique
<
WorkspaceProperty
<
MatrixWorkspace
>>
(
...
...
@@ -160,7 +161,6 @@ void MuonPairingAsymmetry::init() {
setPropertySettings
(
"InputWorkspace"
,
make_unique
<
Kernel
::
EnabledWhenProperty
>
(
"SpecifyGroupsManually"
,
Kernel
::
IS_EQUAL_TO
,
"1"
));
declareProperty
(
make_unique
<
ArrayProperty
<
int
>>
(
"Group1"
,
defaultGrouping1
,
IValidator_sptr
(
new
NullValidator
),
Direction
::
Input
),
...
...
@@ -192,16 +192,16 @@ void MuonPairingAsymmetry::init() {
"SpecifyGroupsManually"
,
Kernel
::
IS_EQUAL_TO
,
"1"
));
// Group common entries in the interface for clarity.
std
::
string
workspaceGrp
(
"Specify Group Workspaces"
);
const
std
::
string
workspaceGrp
(
"Specify Group Workspaces"
);
setPropertyGroup
(
"InputWorkspace1"
,
workspaceGrp
);
setPropertyGroup
(
"InputWorkspace2"
,
workspaceGrp
);
std
::
string
manualGroupGrp
(
"Specify Detector ID Groups Manually"
);
const
std
::
string
manualGroupGrp
(
"Specify Detector ID Groups Manually"
);
setPropertyGroup
(
"InputWorkspace"
,
manualGroupGrp
);
setPropertyGroup
(
"Group1"
,
manualGroupGrp
);
setPropertyGroup
(
"Group2"
,
manualGroupGrp
);
std
::
string
periodGrp
(
"Multi-period Data"
);
const
std
::
string
periodGrp
(
"Multi-period Data"
);
setPropertyGroup
(
"SummedPeriods"
,
periodGrp
);
setPropertyGroup
(
"SubtractedPeriods"
,
periodGrp
);
}
...
...
@@ -210,7 +210,7 @@ std::map<std::string, std::string> MuonPairingAsymmetry::validateInputs() {
std
::
map
<
std
::
string
,
std
::
string
>
errors
;
// Pair name must be given, and must only contain characters, digits and "_"
std
::
string
pairName
=
this
->
getProperty
(
"PairName"
);
const
std
::
string
pairName
=
this
->
getProperty
(
"PairName"
);
if
(
pairName
.
empty
())
{
errors
[
"PairName"
]
=
"Pair name must be specified."
;
}
...
...
@@ -249,9 +249,8 @@ void MuonPairingAsymmetry::validateManualGroups(
errors
[
"Group2"
]
=
"A valid grouping must be supplied (e.g.
\"
1,2,3,4,5
\"
)."
;
}
std
::
sort
(
group1
.
begin
(),
group1
.
end
());
std
::
sort
(
group2
.
begin
(),
group2
.
end
());
if
(
group1
==
group2
)
{
if
(
std
::
is_permutation
(
group1
.
begin
(),
group1
.
end
(),
group2
.
begin
()))
{
errors
[
"Group1"
]
=
"The two groups must be different."
;
}
...
...
@@ -263,11 +262,11 @@ void MuonPairingAsymmetry::validateGroupsWorkspaces(
std
::
map
<
std
::
string
,
std
::
string
>
&
errors
)
{
Workspace_sptr
ws1
=
this
->
getProperty
(
"InputWorkspace1"
);
Workspace_sptr
ws2
=
this
->
getProperty
(
"InputWorkspace2"
);
if
(
isMultiPeriod
(
ws1
)
&&
!
isMultiPeriod
(
ws2
))
{
if
(
ws1
->
isGroup
()
&&
!
ws2
->
isGroup
()
))
{
errors
[
"InputWorkspace1"
]
=
"InputWorkspace2 should be multi period to match InputWorkspace1"
;
}
if
(
isMultiPeriod
(
ws2
)
&&
!
isMultiPeriod
(
ws1
))
{
if
(
ws2
->
isGroup
()
&&
!
ws1
->
isGroup
(
))
{
errors
[
"InputWorkspace2"
]
=
"InputWorkspace1 should be multi period to match InputWorkspace2"
;
}
...
...
@@ -275,7 +274,7 @@ void MuonPairingAsymmetry::validateGroupsWorkspaces(
errors
[
"InputWorkspace1"
]
=
"InputWorkspace1 and InputWorkspace2 have "
"inconsistent numbers of periods."
;
}
if
(
isMultiPeriod
(
ws1
)
&&
isMultiPeriod
(
ws2
))
{
if
(
ws1
->
isGroup
()
&&
ws2
->
isGroup
(
))
{
validatePeriods
(
boost
::
dynamic_pointer_cast
<
WorkspaceGroup
>
(
ws1
),
errors
);
validatePeriods
(
boost
::
dynamic_pointer_cast
<
WorkspaceGroup
>
(
ws2
),
errors
);
}
...
...
@@ -328,8 +327,8 @@ MatrixWorkspace_sptr MuonPairingAsymmetry::execSpecifyGroupsManually() {
auto
groupedPeriods
=
createGroupWorkspace
(
inputWS
);
// Do the asymmetry calculation
std
::
vector
<
int
>
summedPeriods
=
getProperty
(
"SummedPeriods"
);
std
::
vector
<
int
>
subtractedPeriods
=
getProperty
(
"SubtractedPeriods"
);
const
std
::
vector
<
int
>
summedPeriods
=
getProperty
(
"SummedPeriods"
);
const
std
::
vector
<
int
>
subtractedPeriods
=
getProperty
(
"SubtractedPeriods"
);
const
double
alpha
=
static_cast
<
double
>
(
getProperty
(
"Alpha"
));
return
calcPairAsymmetryWithSummedAndSubtractedPeriods
(
...
...
@@ -395,11 +394,10 @@ MuonPairingAsymmetry::pairAsymmetryCalc(MatrixWorkspace_sptr inputWS,
// Ensure our specified spectra definitely point to the data
inputWS
->
getSpectrum
(
0
).
setSpectrumNo
(
0
);
inputWS
->
getSpectrum
(
1
).
setSpectrumNo
(
1
);
std
::
vector
<
int
>
fwdSpectra
=
{
0
};
std
::
vector
<
int
>
bwdSpectra
=
{
1
};
const
std
::
vector
<
int
>
fwdSpectra
=
{
0
};
const
std
::
vector
<
int
>
bwdSpectra
=
{
1
};
IAlgorithm_sptr
alg
=
this
->
createChildAlgorithm
(
"AsymmetryCalc"
);
alg
->
setChild
(
true
);
alg
->
setProperty
(
"InputWorkspace"
,
inputWS
);
alg
->
setProperty
(
"ForwardSpectra"
,
fwdSpectra
);
alg
->
setProperty
(
"BackwardSpectra"
,
bwdSpectra
);
...
...
@@ -442,8 +440,8 @@ MuonPairingAsymmetry::appendSpectra(MatrixWorkspace_sptr inputWS1,
void
MuonPairingAsymmetry
::
validatePeriods
(
WorkspaceGroup_sptr
inputWS
,
std
::
map
<
std
::
string
,
std
::
string
>
&
errors
)
{
std
::
vector
<
int
>
summedPeriods
=
getProperty
(
"SummedPeriods"
);
std
::
vector
<
int
>
subtractedPeriods
=
getProperty
(
"SubtractedPeriods"
);
const
std
::
vector
<
int
>
summedPeriods
=
getProperty
(
"SummedPeriods"
);
const
std
::
vector
<
int
>
subtractedPeriods
=
getProperty
(
"SubtractedPeriods"
);
if
(
summedPeriods
.
empty
()
&&
subtractedPeriods
.
empty
())
{
errors
[
"SummedPeriods"
]
=
"At least one period must be specified"
;
}
...
...
This diff is collapsed.
Click to expand it.
Framework/Muon/test/MuonPairingAsymmetryTest.h
+
29
−
29
View file @
647e008c
...
...
@@ -58,8 +58,8 @@ IAlgorithm_sptr algorithmWithoutOptionalPropertiesSet(
IAlgorithm_sptr
setUpAlgorithmWithoutOptionalProperties
(
WorkspaceGroup_sptr
ws
,
const
std
::
string
&
name
)
{
std
::
vector
<
int
>
group1
=
{
1
,
2
};
std
::
vector
<
int
>
group2
=
{
3
,
4
};
const
std
::
vector
<
int
>
group1
=
{
1
,
2
};
const
std
::
vector
<
int
>
group2
=
{
3
,
4
};
setUpADSWithWorkspace
setup
(
ws
);
IAlgorithm_sptr
alg
=
algorithmWithoutOptionalPropertiesSet
(
...
...
@@ -222,8 +222,8 @@ public:
}
void
test_that_non_empty_pair_name_must_be_supplied
()
{
std
::
vector
<
int
>
group1
=
{
1
,
2
};
std
::
vector
<
int
>
group2
=
{
3
,
4
};
const
std
::
vector
<
int
>
group1
=
{
1
,
2
};
const
std
::
vector
<
int
>
group2
=
{
3
,
4
};
auto
ws
=
createMultiPeriodWorkspaceGroup
(
2
,
1
,
10
,
"pair1"
);
setUpADSWithWorkspace
setup
(
ws
);
...
...
@@ -235,8 +235,8 @@ public:
void
test_that_pair_names_with_alphanumeric_characters_or_underscores_are_allowed
()
{
std
::
vector
<
int
>
group1
=
{
1
,
2
};
std
::
vector
<
int
>
group2
=
{
3
,
4
};
const
std
::
vector
<
int
>
group1
=
{
1
,
2
};
const
std
::
vector
<
int
>
group2
=
{
3
,
4
};
auto
ws
=
createMultiPeriodWorkspaceGroup
(
2
,
1
,
10
,
"pairWS"
);
std
::
vector
<
std
::
string
>
validNames
=
{
"fwd"
,
"fwd2"
,
"bwd_2"
};
...
...
@@ -248,8 +248,8 @@ public:
}
void
test_that_exec_throws_if_pair_name_is_not_alphanumeric_or_underscored
()
{
std
::
vector
<
int
>
group1
=
{
1
,
2
};
std
::
vector
<
int
>
group2
=
{
3
,
4
};
const
std
::
vector
<
int
>
group1
=
{
1
,
2
};
const
std
::
vector
<
int
>
group2
=
{
3
,
4
};
auto
ws
=
createMultiPeriodWorkspaceGroup
(
2
,
1
,
10
,
"pair1"
);
std
::
vector
<
std
::
string
>
invalidNames
=
{
"@"
,
"fwd!"
,
"#1"
,
"fwd @"
,
" "
};
...
...
@@ -265,8 +265,8 @@ public:
// --------------------------------------------------------------------------
void
test_that_exec_throws_if_alpha_is_negative
()
{
std
::
vector
<
int
>
group1
=
{
1
,
2
};
std
::
vector
<
int
>
group2
=
{
3
,
4
};
const
std
::
vector
<
int
>
group1
=
{
1
,
2
};
const
std
::
vector
<
int
>
group2
=
{
3
,
4
};
auto
ws
=
createMultiPeriodWorkspaceGroup
(
2
,
1
,
10
,
"pairWS"
);
auto
alg
=
algorithmWithoutOptionalPropertiesSet
(
"pairWS"
,
"pair"
,
group1
,
group2
);
...
...
@@ -312,7 +312,7 @@ public:
void
test_that_at_least_one_period_must_be_specified
()
{
auto
ws
=
createMultiPeriodWorkspaceGroup
(
2
,
3
,
10
,
"group"
);
std
::
vector
<
int
>
detectors
=
{
1
,
2
};
const
std
::
vector
<
int
>
detectors
=
{
1
,
2
};
auto
alg
=
setUpAlgorithmWithoutOptionalProperties
(
ws
,
"pair1"
);
std
::
vector
<
int
>
summedPeriods
=
{};
...
...
@@ -353,8 +353,8 @@ public:
test_that_single_period_data_combines_detectors_correctly_for_manually_specified_detectors
()
{
// 4 spectra per period, 10 bins
auto
ws
=
createMultiPeriodAsymmetryData
(
1
,
4
,
10
,
"pairWS"
);
std
::
vector
<
int
>
group1
=
{
1
,
2
};
std
::
vector
<
int
>
group2
=
{
3
,
4
};
const
std
::
vector
<
int
>
group1
=
{
1
,
2
};
const
std
::
vector
<
int
>
group2
=
{
3
,
4
};
auto
alg
=
setUpAlgorithmWithGroups
(
ws
,
group1
,
group2
);
alg
->
execute
();
...
...
@@ -376,8 +376,8 @@ public:
void
test_that_single_period_data_combines_detectors_correctly_for_two_group_workspaces
()
{
std
::
vector
<
int
>
group1
=
{
1
,
2
};
std
::
vector
<
int
>
group2
=
{
3
,
4
};
const
std
::
vector
<
int
>
group1
=
{
1
,
2
};
const
std
::
vector
<
int
>
group2
=
{
3
,
4
};
auto
ws1
=
createGroupWorkspace
(
"fwd"
,
group1
,
1
);
auto
ws2
=
createGroupWorkspace
(
"bwd"
,
group2
,
1
);
...
...
@@ -409,8 +409,8 @@ public:
test_that_multi_period_data_combines_detectors_correctly_for_manually_specified_detectors_and_summed_periods
()
{
auto
ws
=
createMultiPeriodAsymmetryData
(
2
,
4
,
10
,
"pairWS"
);
std
::
vector
<
int
>
group1
=
{
1
,
2
};
std
::
vector
<
int
>
group2
=
{
3
,
4
};
const
std
::
vector
<
int
>
group1
=
{
1
,
2
};
const
std
::
vector
<
int
>
group2
=
{
3
,
4
};
auto
alg
=
setUpAlgorithmWithGroups
(
ws
,
group1
,
group2
);
alg
->
setProperty
(
"SummedPeriods"
,
group1
);
alg
->
execute
();
...
...
@@ -434,11 +434,11 @@ public:
test_that_multi_period_data_combines_detectors_correctly_for_manually_specified_detectors_and_subtracted_periods
()
{
auto
ws
=
createMultiPeriodAsymmetryData
(
2
,
4
,
10
,
"pairWS"
);
std
::
vector
<
int
>
group1
=
{
1
,
2
};
std
::
vector
<
int
>
group2
=
{
3
,
4
};
const
std
::
vector
<
int
>
group1
=
{
1
,
2
};
const
std
::
vector
<
int
>
group2
=
{
3
,
4
};
auto
alg
=
setUpAlgorithmWithGroups
(
ws
,
group1
,
group2
);
std
::
vector
<
int
>
summedPeriods
=
{
1
};
std
::
vector
<
int
>
subtractedPeriods
=
{
2
};
const
std
::
vector
<
int
>
summedPeriods
=
{
1
};
const
std
::
vector
<
int
>
subtractedPeriods
=
{
2
};
alg
->
setProperty
(
"SummedPeriods"
,
summedPeriods
);
alg
->
setProperty
(
"SubtractedPeriods"
,
subtractedPeriods
);
alg
->
execute
();
...
...
@@ -461,11 +461,11 @@ public:
test_that_multi_period_data_combines_detectors_correctly_for_manually_specified_detectors_summed_and_subtracted_periods
()
{
auto
ws
=
createMultiPeriodAsymmetryData
(
3
,
4
,
10
,
"pairWS"
);
std
::
vector
<
int
>
group1
=
{
1
,
2
};
std
::
vector
<
int
>
group2
=
{
3
,
4
};
const
std
::
vector
<
int
>
group1
=
{
1
,
2
};
const
std
::
vector
<
int
>
group2
=
{
3
,
4
};
auto
alg
=
setUpAlgorithmWithGroups
(
ws
,
group1
,
group2
);
std
::
vector
<
int
>
summedPeriods
=
{
1
,
2
};
std
::
vector
<
int
>
subtractedPeriods
=
{
3
};
const
std
::
vector
<
int
>
summedPeriods
=
{
1
,
2
};
const
std
::
vector
<
int
>
subtractedPeriods
=
{
3
};
alg
->
setProperty
(
"SummedPeriods"
,
summedPeriods
);
alg
->
setProperty
(
"SubtractedPeriods"
,
subtractedPeriods
);
alg
->
execute
();
...
...
@@ -487,14 +487,14 @@ public:
void
test_that_multi_period_data_combines_detectors_correctly_for_group_workspaces_summed_and_subtracted_periods
()
{
std
::
vector
<
int
>
group1
=
{
1
,
2
};
std
::
vector
<
int
>
group2
=
{
3
,
4
};
const
std
::
vector
<
int
>
group1
=
{
1
,
2
};
const
std
::
vector
<
int
>
group2
=
{
3
,
4
};
auto
ws1
=
createMultiPeriodGroupedWorkspace
(
"fwd"
,
group1
,
3
);
auto
ws2
=
createMultiPeriodGroupedWorkspace
(
"bwd"
,
group2
,
3
);
auto
alg
=
setUpAlgorithmWithGroupWorkspaceGroups
(
ws1
,
ws2
);
std
::
vector
<
int
>
summedPeriods
=
{
1
,
2
};
std
::
vector
<
int
>
subtractedPeriods
=
{
3
};
const
std
::
vector
<
int
>
summedPeriods
=
{
1
,
2
};
const
std
::
vector
<
int
>
subtractedPeriods
=
{
3
};
alg
->
setProperty
(
"SummedPeriods"
,
summedPeriods
);
alg
->
setProperty
(
"SubtractedPeriods"
,
subtractedPeriods
);
alg
->
execute
();
...
...
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