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
41b6a2b7
Commit
41b6a2b7
authored
7 years ago
by
Simon Heybrock
Browse files
Options
Downloads
Patches
Plain Diff
Re #0. Tests for IndexInfo detector -> spectrum mapper.
parent
1b698aea
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Framework/Indexing/src/IndexInfo.cpp
+17
-6
17 additions, 6 deletions
Framework/Indexing/src/IndexInfo.cpp
Framework/Indexing/test/IndexInfoTest.h
+84
-0
84 additions, 0 deletions
Framework/Indexing/test/IndexInfoTest.h
with
101 additions
and
6 deletions
Framework/Indexing/src/IndexInfo.cpp
+
17
−
6
View file @
41b6a2b7
...
...
@@ -202,14 +202,18 @@ SpectrumIndexSet IndexInfo::makeIndexSet(
std
::
vector
<
GlobalSpectrumIndex
>
IndexInfo
::
globalSpectrumIndicesFromDetectorIndices
(
const
std
::
vector
<
size_t
>
&
detectorIndices
)
const
{
std
::
vector
<
bool
>
detectorMap
;
if
(
!
m_spectrumDefinitions
)
throw
std
::
runtime_error
(
"IndexInfo::"
"globalSpectrumIndicesFromDetectorIndices -- no "
"spectrum definitions available"
);
std
::
vector
<
char
>
detectorMap
;
for
(
const
auto
&
index
:
detectorIndices
)
{
// IndexInfo has no knowledge of the maximum detector index so we workaround
// this knowledge gap by assuming below that any index beyond the end of the
// map is
`false`
.
// map is
0
.
if
(
index
>=
detectorMap
.
size
())
detectorMap
.
resize
(
index
+
1
,
false
);
detectorMap
[
index
]
=
true
;
detectorMap
.
resize
(
index
+
1
,
0
);
detectorMap
[
index
]
=
1
;
}
std
::
vector
<
GlobalSpectrumIndex
>
spectrumIndices
;
...
...
@@ -217,13 +221,20 @@ IndexInfo::globalSpectrumIndicesFromDetectorIndices(
const
auto
&
spectrumDefinition
=
m_spectrumDefinitions
->
operator
[](
i
);
if
(
spectrumDefinition
.
size
()
==
1
)
{
const
auto
detectorIndex
=
spectrumDefinition
[
0
].
first
;
if
(
detectorMap
.
size
()
>
detectorIndex
&&
detectorMap
[
detectorIndex
])
if
(
detectorMap
.
size
()
>
detectorIndex
&&
detectorMap
[
detectorIndex
]
!=
0
)
{
if
(
detectorMap
[
detectorIndex
]
>
1
)
throw
std
::
runtime_error
(
"Multiple spectra correspond to the same detector"
);
// Increment flag to catch two spectra mapping to same detector.
++
detectorMap
[
detectorIndex
];
spectrumIndices
.
push_back
(
i
);
}
}
if
(
spectrumDefinition
.
size
()
>
1
)
throw
std
::
runtime_error
(
"SpectrumDefinition containes multiple entries. "
"No unique mapping from detector to spectrum "
"possible
.
"
);
"possible"
);
}
if
(
detectorIndices
.
size
()
!=
spectrumIndices
.
size
())
throw
std
::
runtime_error
(
...
...
This diff is collapsed.
Click to expand it.
Framework/Indexing/test/IndexInfoTest.h
+
84
−
0
View file @
41b6a2b7
...
...
@@ -187,6 +187,90 @@ public:
TS_ASSERT_EQUALS
(
info
.
spectrumDefinitions
().
get
(),
defs
.
get
());
}
void
test_globalSpectrumIndicesFromDetectorIndices_fails_without_spec_defs
()
{
IndexInfo
info
(
3
);
std
::
vector
<
size_t
>
detectorIndices
{
6
,
8
};
TS_ASSERT_THROWS_EQUALS
(
info
.
globalSpectrumIndicesFromDetectorIndices
(
detectorIndices
),
const
std
::
runtime_error
&
e
,
std
::
string
(
e
.
what
()),
"IndexInfo::globalSpectrumIndicesFromDetectorIndices -- no spectrum "
"definitions available"
);
}
void
test_globalSpectrumIndicesFromDetectorIndices_fails_multiple
()
{
IndexInfo
info
(
3
);
std
::
vector
<
size_t
>
detectorIndices
{
6
,
8
};
std
::
vector
<
SpectrumDefinition
>
specDefs
(
3
);
specDefs
[
0
].
add
(
6
);
specDefs
[
1
].
add
(
7
);
specDefs
[
1
].
add
(
77
);
specDefs
[
2
].
add
(
8
);
info
.
setSpectrumDefinitions
(
specDefs
);
TS_ASSERT_THROWS_EQUALS
(
info
.
globalSpectrumIndicesFromDetectorIndices
(
detectorIndices
),
const
std
::
runtime_error
&
e
,
std
::
string
(
e
.
what
()),
"SpectrumDefinition containes multiple entries. No unique mapping from "
"detector to spectrum possible"
);
}
void
test_globalSpectrumIndicesFromDetectorIndices_fails_missing
()
{
IndexInfo
info
(
3
);
std
::
vector
<
size_t
>
detectorIndices
{
6
,
8
};
std
::
vector
<
SpectrumDefinition
>
specDefs
(
3
);
// Nothing maps to 8
specDefs
[
0
].
add
(
6
);
specDefs
[
1
].
add
(
7
);
info
.
setSpectrumDefinitions
(
specDefs
);
TS_ASSERT_THROWS_EQUALS
(
info
.
globalSpectrumIndicesFromDetectorIndices
(
detectorIndices
),
const
std
::
runtime_error
&
e
,
std
::
string
(
e
.
what
()),
"Some of the requested detectors do not have a corresponding spectrum"
);
}
void
test_globalSpectrumIndicesFromDetectorIndices_fails_conflict
()
{
IndexInfo
info
(
3
);
std
::
vector
<
size_t
>
detectorIndices
{
6
,
8
};
std
::
vector
<
SpectrumDefinition
>
specDefs
(
3
);
// Two indices map to same detector.
specDefs
[
0
].
add
(
6
);
specDefs
[
1
].
add
(
6
);
specDefs
[
2
].
add
(
8
);
info
.
setSpectrumDefinitions
(
specDefs
);
TS_ASSERT_THROWS_EQUALS
(
info
.
globalSpectrumIndicesFromDetectorIndices
(
detectorIndices
),
const
std
::
runtime_error
&
e
,
std
::
string
(
e
.
what
()),
"Multiple spectra correspond to the same detector"
);
}
void
test_globalSpectrumIndicesFromDetectorIndices_fails_conflict_miss
()
{
IndexInfo
info
(
3
);
std
::
vector
<
size_t
>
detectorIndices
{
6
,
8
};
std
::
vector
<
SpectrumDefinition
>
specDefs
(
3
);
// Two indices map to same detector, but additionally one is missing.
specDefs
[
0
].
add
(
6
);
specDefs
[
1
].
add
(
6
);
info
.
setSpectrumDefinitions
(
specDefs
);
TS_ASSERT_THROWS_EQUALS
(
info
.
globalSpectrumIndicesFromDetectorIndices
(
detectorIndices
),
const
std
::
runtime_error
&
e
,
std
::
string
(
e
.
what
()),
"Multiple spectra correspond to the same detector"
);
}
void
test_globalSpectrumIndicesFromDetectorIndices
()
{
IndexInfo
info
(
3
);
std
::
vector
<
size_t
>
detectorIndices
{
6
,
8
};
std
::
vector
<
SpectrumDefinition
>
specDefs
(
3
);
specDefs
[
0
].
add
(
6
);
specDefs
[
1
].
add
(
7
);
specDefs
[
2
].
add
(
8
);
info
.
setSpectrumDefinitions
(
specDefs
);
const
auto
&
indices
=
info
.
globalSpectrumIndicesFromDetectorIndices
(
detectorIndices
);
TS_ASSERT_EQUALS
(
indices
.
size
(),
detectorIndices
.
size
());
TS_ASSERT_EQUALS
(
indices
[
0
],
0
);
TS_ASSERT_EQUALS
(
indices
[
1
],
2
);
}
void
test_StorageMode_Cloned
()
{
runParallel
(
run_StorageMode_Cloned
);
// Trivial: Run with one partition.
...
...
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