Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
mantidproject
mantid
Commits
61755a3d
Commit
61755a3d
authored
May 27, 2016
by
Simon Heybrock
Browse files
Re #16454. getSpectrum as reference.
parent
8fe3898d
Changes
245
Hide whitespace changes
Inline
Side-by-side
Framework/API/inc/MantidAPI/MatrixWorkspace.h
View file @
61755a3d
...
...
@@ -173,68 +173,68 @@ public:
//----------------------------------------------------------------------
/// Return the underlying ISpectrum ptr at the given workspace index.
virtual
ISpectrum
*
getSpectrum
(
const
size_t
index
)
=
0
;
virtual
ISpectrum
&
getSpectrum
(
const
size_t
index
)
=
0
;
/// Return the underlying ISpectrum ptr (const version) at the given workspace
/// index.
virtual
const
ISpectrum
*
getSpectrum
(
const
size_t
index
)
const
=
0
;
virtual
const
ISpectrum
&
getSpectrum
(
const
size_t
index
)
const
=
0
;
// Methods for getting read-only access to the data.
// Just passes through to the virtual dataX/Y/E function (const version)
/// Returns a read-only (i.e. const) reference to the specified X array
/// @param index :: workspace index to retrieve.
const
MantidVec
&
readX
(
std
::
size_t
const
index
)
const
{
return
getSpectrum
(
index
)
->
dataX
();
return
getSpectrum
(
index
)
.
dataX
();
}
/// Returns a read-only (i.e. const) reference to the specified Y array
/// @param index :: workspace index to retrieve.
const
MantidVec
&
readY
(
std
::
size_t
const
index
)
const
{
return
getSpectrum
(
index
)
->
dataY
();
return
getSpectrum
(
index
)
.
dataY
();
}
/// Returns a read-only (i.e. const) reference to the specified E array
/// @param index :: workspace index to retrieve.
const
MantidVec
&
readE
(
std
::
size_t
const
index
)
const
{
return
getSpectrum
(
index
)
->
dataE
();
return
getSpectrum
(
index
)
.
dataE
();
}
/// Returns a read-only (i.e. const) reference to the specified X error array
/// @param index :: workspace index to retrieve.
const
MantidVec
&
readDx
(
size_t
const
index
)
const
{
return
getSpectrum
(
index
)
->
dataDx
();
return
getSpectrum
(
index
)
.
dataDx
();
}
/// Returns the x data
virtual
MantidVec
&
dataX
(
const
std
::
size_t
index
)
{
invalidateCommonBinsFlag
();
return
getSpectrum
(
index
)
->
dataX
();
return
getSpectrum
(
index
)
.
dataX
();
}
/// Returns the y data
virtual
MantidVec
&
dataY
(
const
std
::
size_t
index
)
{
return
getSpectrum
(
index
)
->
dataY
();
return
getSpectrum
(
index
)
.
dataY
();
}
/// Returns the error data
virtual
MantidVec
&
dataE
(
const
std
::
size_t
index
)
{
return
getSpectrum
(
index
)
->
dataE
();
return
getSpectrum
(
index
)
.
dataE
();
}
/// Returns the x error data
virtual
MantidVec
&
dataDx
(
const
std
::
size_t
index
)
{
return
getSpectrum
(
index
)
->
dataDx
();
return
getSpectrum
(
index
)
.
dataDx
();
}
/// Returns the x data const
virtual
const
MantidVec
&
dataX
(
const
std
::
size_t
index
)
const
{
return
getSpectrum
(
index
)
->
dataX
();
return
getSpectrum
(
index
)
.
dataX
();
}
/// Returns the y data const
virtual
const
MantidVec
&
dataY
(
const
std
::
size_t
index
)
const
{
return
getSpectrum
(
index
)
->
dataY
();
return
getSpectrum
(
index
)
.
dataY
();
}
/// Returns the error const
virtual
const
MantidVec
&
dataE
(
const
std
::
size_t
index
)
const
{
return
getSpectrum
(
index
)
->
dataE
();
return
getSpectrum
(
index
)
.
dataE
();
}
/// Returns the error const
virtual
const
MantidVec
&
dataDx
(
const
std
::
size_t
index
)
const
{
return
getSpectrum
(
index
)
->
dataDx
();
return
getSpectrum
(
index
)
.
dataDx
();
}
virtual
double
getXMin
()
const
;
...
...
@@ -243,48 +243,48 @@ public:
/// Returns a pointer to the x data
virtual
Kernel
::
cow_ptr
<
MantidVec
>
refX
(
const
std
::
size_t
index
)
const
{
return
getSpectrum
(
index
)
->
ptrX
();
return
getSpectrum
(
index
)
.
ptrX
();
}
/// Returns a pointer to the dX (X Error) data
virtual
Kernel
::
cow_ptr
<
MantidVec
>
refDx
(
const
std
::
size_t
index
)
const
{
return
getSpectrum
(
index
)
->
ptrDx
();
return
getSpectrum
(
index
)
.
ptrDx
();
}
/// Set the specified X array to point to the given existing array
virtual
void
setX
(
const
std
::
size_t
index
,
const
MantidVec
&
X
)
{
getSpectrum
(
index
)
->
setX
(
X
);
getSpectrum
(
index
)
.
setX
(
X
);
invalidateCommonBinsFlag
();
}
/// Set the specified X array to point to the given existing array
virtual
void
setX
(
const
std
::
size_t
index
,
const
MantidVecPtr
&
X
)
{
getSpectrum
(
index
)
->
setX
(
X
);
getSpectrum
(
index
)
.
setX
(
X
);
invalidateCommonBinsFlag
();
}
/// Set the specified X array to point to the given existing array
virtual
void
setX
(
const
std
::
size_t
index
,
const
MantidVecPtr
::
ptr_type
&
X
)
{
getSpectrum
(
index
)
->
setX
(
X
);
getSpectrum
(
index
)
.
setX
(
X
);
invalidateCommonBinsFlag
();
}
/// Set the specified Dx (X Error) array to point to the given existing array
virtual
void
setDx
(
const
std
::
size_t
index
,
const
MantidVec
&
Dx
)
{
getSpectrum
(
index
)
->
setDx
(
Dx
);
getSpectrum
(
index
)
.
setDx
(
Dx
);
invalidateCommonBinsFlag
();
}
/// Set the specified Dx (X Error) array to point to the given existing array
virtual
void
setDx
(
const
std
::
size_t
index
,
const
MantidVecPtr
&
Dx
)
{
getSpectrum
(
index
)
->
setDx
(
Dx
);
getSpectrum
(
index
)
.
setDx
(
Dx
);
invalidateCommonBinsFlag
();
}
/// Set the specified Dx (X Error) array to point to the given existing array
virtual
void
setDx
(
const
std
::
size_t
index
,
const
MantidVecPtr
::
ptr_type
&
Dx
)
{
getSpectrum
(
index
)
->
setDx
(
Dx
);
getSpectrum
(
index
)
.
setDx
(
Dx
);
invalidateCommonBinsFlag
();
}
...
...
@@ -292,7 +292,7 @@ public:
@param index :: the workspace index to set.
@param Y :: Y vector */
virtual
void
setData
(
const
std
::
size_t
index
,
const
MantidVecPtr
&
Y
)
{
getSpectrum
(
index
)
->
setData
(
Y
);
getSpectrum
(
index
)
.
setData
(
Y
);
}
/** Sets the data in the workspace
...
...
@@ -301,7 +301,7 @@ public:
@param E :: Error vector */
virtual
void
setData
(
const
std
::
size_t
index
,
const
MantidVecPtr
&
Y
,
const
MantidVecPtr
&
E
)
{
getSpectrum
(
index
)
->
setData
(
Y
,
E
);
getSpectrum
(
index
)
.
setData
(
Y
,
E
);
}
/** Sets the data in the workspace
...
...
@@ -310,7 +310,7 @@ public:
@param E :: Error vector */
virtual
void
setData
(
const
std
::
size_t
index
,
const
MantidVecPtr
::
ptr_type
&
Y
,
const
MantidVecPtr
::
ptr_type
&
E
)
{
getSpectrum
(
index
)
->
setData
(
Y
,
E
);
getSpectrum
(
index
)
.
setData
(
Y
,
E
);
}
/**
...
...
@@ -318,7 +318,7 @@ public:
* @param index: the workspace index
*/
virtual
bool
hasDx
(
const
std
::
size_t
index
)
const
{
return
getSpectrum
(
index
)
->
hasDx
();
return
getSpectrum
(
index
)
.
hasDx
();
}
/// Generate the histogram or rebin the existing histogram.
...
...
Framework/API/src/GeometryInfoFactory.cpp
View file @
61755a3d
...
...
@@ -23,7 +23,7 @@ GeometryInfo GeometryInfoFactory::create(const size_t index) const {
// current (2016) instrument code there are memory allocations when getting
// the detector, so this additional allocation may be negligible, but we want
// this class to be future proof. GeometryInfo should be kept small.
return
{
*
this
,
*
(
m_workspace
.
getSpectrum
(
index
)
)
};
return
{
*
this
,
m_workspace
.
getSpectrum
(
index
)};
}
const
Geometry
::
Instrument
&
GeometryInfoFactory
::
getInstrument
()
const
{
...
...
Framework/API/src/IFunction.cpp
View file @
61755a3d
...
...
@@ -717,7 +717,7 @@ void IFunction::setMatrixWorkspace(
const
Geometry
::
ParameterMap
&
paramMap
=
workspace
->
instrumentParameters
();
Geometry
::
IDetector_const_sptr
det
;
size_t
numDetectors
=
workspace
->
getSpectrum
(
wi
)
->
getDetectorIDs
().
size
();
size_t
numDetectors
=
workspace
->
getSpectrum
(
wi
)
.
getDetectorIDs
().
size
();
if
(
numDetectors
>
1
)
{
// If several detectors are on this workspace index, just use the ID of
// the first detector
...
...
@@ -725,7 +725,7 @@ void IFunction::setMatrixWorkspace(
// and not the group. Ask Roman.
Instrument_const_sptr
inst
=
workspace
->
getInstrument
();
det
=
inst
->
getDetector
(
*
workspace
->
getSpectrum
(
wi
)
->
getDetectorIDs
().
begin
());
*
workspace
->
getSpectrum
(
wi
)
.
getDetectorIDs
().
begin
());
}
else
// Get the detector (single) at this workspace index
det
=
workspace
->
getDetector
(
wi
);
...
...
Framework/API/src/MatrixWorkspace.cpp
View file @
61755a3d
...
...
@@ -183,18 +183,18 @@ const std::string MatrixWorkspace::getTitle() const {
void
MatrixWorkspace
::
updateSpectraUsing
(
const
SpectrumDetectorMapping
&
map
)
{
for
(
size_t
j
=
0
;
j
<
getNumberHistograms
();
++
j
)
{
auto
spec
=
getSpectrum
(
j
);
auto
&
spec
=
getSpectrum
(
j
);
try
{
if
(
map
.
indexIsSpecNumber
())
spec
->
setDetectorIDs
(
map
.
getDetectorIDsForSpectrumNo
(
spec
->
getSpectrumNo
()));
spec
.
setDetectorIDs
(
map
.
getDetectorIDsForSpectrumNo
(
spec
.
getSpectrumNo
()));
else
spec
->
setDetectorIDs
(
map
.
getDetectorIDsForSpectrumIndex
(
j
));
spec
.
setDetectorIDs
(
map
.
getDetectorIDsForSpectrumIndex
(
j
));
}
catch
(
std
::
out_of_range
&
e
)
{
// Get here if the spectrum number is not in the map.
spec
->
clearDetectorIDs
();
spec
.
clearDetectorIDs
();
g_log
.
debug
(
e
.
what
());
g_log
.
debug
()
<<
"Spectrum number "
<<
spec
->
getSpectrumNo
()
g_log
.
debug
()
<<
"Spectrum number "
<<
spec
.
getSpectrumNo
()
<<
" not in map.
\n
"
;
}
}
...
...
@@ -227,9 +227,9 @@ void MatrixWorkspace::rebuildSpectraMapping(const bool includeMonitors) {
const
specnum_t
specNo
=
specnum_t
(
index
+
1
);
if
(
index
<
this
->
getNumberHistograms
())
{
ISpectrum
*
spec
=
getSpectrum
(
index
);
spec
->
setSpectrumNo
(
specNo
);
spec
->
setDetectorID
(
detId
);
auto
&
spec
=
getSpectrum
(
index
);
spec
.
setSpectrumNo
(
specNo
);
spec
.
setDetectorID
(
detId
);
}
index
++
;
...
...
@@ -428,7 +428,7 @@ bool MatrixWorkspace::hasGroupedDetectors() const {
// Loop through the workspace index
for
(
size_t
workspaceIndex
=
0
;
workspaceIndex
<
this
->
getNumberHistograms
();
workspaceIndex
++
)
{
auto
detList
=
getSpectrum
(
workspaceIndex
)
->
getDetectorIDs
();
auto
detList
=
getSpectrum
(
workspaceIndex
)
.
getDetectorIDs
();
if
(
detList
.
size
()
>
1
)
{
retVal
=
true
;
break
;
...
...
@@ -456,7 +456,7 @@ detid2index_map MatrixWorkspace::getDetectorIDToWorkspaceIndexMap(
// Loop through the workspace index
for
(
size_t
workspaceIndex
=
0
;
workspaceIndex
<
this
->
getNumberHistograms
();
++
workspaceIndex
)
{
auto
detList
=
getSpectrum
(
workspaceIndex
)
->
getDetectorIDs
();
auto
detList
=
getSpectrum
(
workspaceIndex
)
.
getDetectorIDs
();
if
(
throwIfMultipleDets
)
{
if
(
detList
.
size
()
>
1
)
{
...
...
@@ -509,8 +509,7 @@ std::vector<size_t> MatrixWorkspace::getDetectorIDToWorkspaceIndexVector(
for
(
size_t
workspaceIndex
=
0
;
workspaceIndex
<
getNumberHistograms
();
++
workspaceIndex
)
{
// Get the list of detectors from the WS index
const
std
::
set
<
detid_t
>
&
detList
=
this
->
getSpectrum
(
workspaceIndex
)
->
getDetectorIDs
();
const
auto
&
detList
=
this
->
getSpectrum
(
workspaceIndex
).
getDetectorIDs
();
if
(
throwIfMultipleDets
&&
(
detList
.
size
()
>
1
))
throw
std
::
runtime_error
(
...
...
@@ -552,7 +551,7 @@ std::vector<size_t> MatrixWorkspace::getIndicesFromSpectra(
auto
iter
=
spectraList
.
cbegin
();
while
(
iter
!=
spectraList
.
cend
())
{
for
(
size_t
i
=
0
;
i
<
this
->
getNumberHistograms
();
++
i
)
{
if
(
this
->
getSpectrum
(
i
)
->
getSpectrumNo
()
==
*
iter
)
{
if
(
this
->
getSpectrum
(
i
)
.
getSpectrumNo
()
==
*
iter
)
{
indexList
.
push_back
(
i
);
break
;
}
...
...
@@ -572,7 +571,7 @@ std::vector<size_t> MatrixWorkspace::getIndicesFromSpectra(
size_t
MatrixWorkspace
::
getIndexFromSpectrumNumber
(
const
specnum_t
specNo
)
const
{
for
(
size_t
i
=
0
;
i
<
this
->
getNumberHistograms
();
++
i
)
{
if
(
this
->
getSpectrum
(
i
)
->
getSpectrumNo
()
==
specNo
)
if
(
this
->
getSpectrum
(
i
)
.
getSpectrumNo
()
==
specNo
)
return
i
;
}
throw
std
::
runtime_error
(
"Could not find spectrum number in any spectrum."
);
...
...
@@ -594,7 +593,7 @@ std::vector<size_t> MatrixWorkspace::getIndicesFromDetectorIDs(
const
std
::
vector
<
detid_t
>
&
detIdList
)
const
{
std
::
map
<
detid_t
,
std
::
set
<
size_t
>>
detectorIDtoWSIndices
;
for
(
size_t
i
=
0
;
i
<
getNumberHistograms
();
++
i
)
{
auto
detIDs
=
getSpectrum
(
i
)
->
getDetectorIDs
();
auto
detIDs
=
getSpectrum
(
i
)
.
getDetectorIDs
();
for
(
auto
detID
:
detIDs
)
{
detectorIDtoWSIndices
[
detID
].
insert
(
i
);
}
...
...
@@ -632,9 +631,9 @@ std::vector<specnum_t> MatrixWorkspace::getSpectraFromDetectorIDs(
// Go through every histogram
for
(
size_t
i
=
0
;
i
<
this
->
getNumberHistograms
();
i
++
)
{
if
(
this
->
getSpectrum
(
i
)
->
hasDetectorID
(
detId
))
{
if
(
this
->
getSpectrum
(
i
)
.
hasDetectorID
(
detId
))
{
foundDet
=
true
;
foundSpecNum
=
this
->
getSpectrum
(
i
)
->
getSpectrumNo
();
foundSpecNum
=
this
->
getSpectrum
(
i
)
.
getSpectrumNo
();
break
;
}
}
...
...
@@ -752,14 +751,7 @@ requested workspace index does not have any associated detectors
*/
Geometry
::
IDetector_const_sptr
MatrixWorkspace
::
getDetector
(
const
size_t
workspaceIndex
)
const
{
const
ISpectrum
*
spec
=
this
->
getSpectrum
(
workspaceIndex
);
if
(
!
spec
)
throw
Kernel
::
Exception
::
NotFoundError
(
"MatrixWorkspace::getDetector(): "
"NULL spectrum found at the given "
"workspace index."
,
""
);
const
auto
&
dets
=
spec
->
getDetectorIDs
();
const
auto
&
dets
=
getSpectrum
(
workspaceIndex
).
getDetectorIDs
();
Instrument_const_sptr
localInstrument
=
getInstrument
();
if
(
!
localInstrument
)
{
g_log
.
debug
()
<<
"No instrument defined.
\n
"
;
...
...
@@ -999,15 +991,12 @@ void MatrixWorkspace::maskWorkspaceIndex(const std::size_t index) {
"MatrixWorkspace::maskWorkspaceIndex,index"
);
}
ISpectrum
*
spec
=
this
->
getSpectrum
(
index
);
if
(
!
spec
)
throw
std
::
invalid_argument
(
"MatrixWorkspace::maskWorkspaceIndex() got a null Spectrum."
);
auto
&
spec
=
this
->
getSpectrum
(
index
);
// Virtual method clears the spectrum as appropriate
spec
->
clearData
();
spec
.
clearData
();
const
auto
dets
=
spec
->
getDetectorIDs
();
const
auto
dets
=
spec
.
getDetectorIDs
();
for
(
auto
detId
:
dets
)
{
try
{
if
(
const
Geometry
::
Detector
*
det
=
...
...
@@ -1613,7 +1602,7 @@ void MatrixWorkspace::saveSpectraMapNexus(
std
::
size_t
nDetectors
=
0
;
for
(
auto
index
:
spec
)
{
nDetectors
+=
this
->
getSpectrum
(
static_cast
<
size_t
>
(
index
))
->
getDetectorIDs
().
size
();
this
->
getSpectrum
(
static_cast
<
size_t
>
(
index
))
.
getDetectorIDs
().
size
();
}
if
(
nDetectors
<
1
)
{
...
...
@@ -1643,11 +1632,11 @@ void MatrixWorkspace::saveSpectraMapNexus(
// Workspace index
int
si
=
spec
[
i
];
// Spectrum there
const
ISpectrum
*
spectrum
=
this
->
getSpectrum
(
si
);
spectra
[
i
]
=
int32_t
(
spectrum
->
getSpectrumNo
());
const
auto
&
spectrum
=
this
->
getSpectrum
(
si
);
spectra
[
i
]
=
int32_t
(
spectrum
.
getSpectrumNo
());
// The detectors in this spectrum
const
auto
&
detectorgroup
=
spectrum
->
getDetectorIDs
();
const
auto
&
detectorgroup
=
spectrum
.
getDetectorIDs
();
const
int
ndet1
=
static_cast
<
int
>
(
detectorgroup
.
size
());
detector_index
[
i
+
1
]
=
int32_t
(
...
...
Framework/API/src/SpectraAxis.cpp
View file @
61755a3d
...
...
@@ -67,7 +67,7 @@ double SpectraAxis::operator()(const std::size_t &index,
"SpectraAxis: Index out of range."
);
}
return
static_cast
<
double
>
(
m_parentWS
->
getSpectrum
(
index
)
->
getSpectrumNo
());
return
static_cast
<
double
>
(
m_parentWS
->
getSpectrum
(
index
)
.
getSpectrumNo
());
}
/** Sets the axis value at a given position
...
...
@@ -115,7 +115,7 @@ specnum_t SpectraAxis::spectraNo(const std::size_t &index) const {
"SpectraAxis: Index out of range."
);
}
return
m_parentWS
->
getSpectrum
(
index
)
->
getSpectrumNo
();
return
m_parentWS
->
getSpectrum
(
index
)
.
getSpectrumNo
();
}
/** Returns a map where spectra is the key and index is the value
...
...
@@ -129,7 +129,7 @@ spec2index_map SpectraAxis::getSpectraIndexMap() const {
throw
std
::
runtime_error
(
"getSpectraIndexMap(), zero elements"
);
spec2index_map
map
;
for
(
size_t
i
=
0
;
i
<
nel
;
++
i
)
{
map
.
emplace
(
m_parentWS
->
getSpectrum
(
i
)
->
getSpectrumNo
(),
i
);
map
.
emplace
(
m_parentWS
->
getSpectrum
(
i
)
.
getSpectrumNo
(),
i
);
}
return
map
;
}
...
...
@@ -165,12 +165,12 @@ std::string SpectraAxis::label(const std::size_t &index) const {
/// returns min value defined on axis
double
SpectraAxis
::
getMin
()
const
{
return
m_parentWS
->
getSpectrum
(
0
)
->
getSpectrumNo
();
return
m_parentWS
->
getSpectrum
(
0
)
.
getSpectrumNo
();
}
/// returns max value defined on axis
double
SpectraAxis
::
getMax
()
const
{
return
m_parentWS
->
getSpectrum
(
length
()
-
1
)
->
getSpectrumNo
();
return
m_parentWS
->
getSpectrum
(
length
()
-
1
)
.
getSpectrumNo
();
}
}
// namespace API
...
...
Framework/API/src/SpectrumDetectorMapping.cpp
View file @
61755a3d
...
...
@@ -16,15 +16,15 @@ SpectrumDetectorMapping::SpectrumDetectorMapping(
}
for
(
size_t
i
=
0
;
i
<
workspace
->
getNumberHistograms
();
++
i
)
{
auto
spectrum
=
workspace
->
getSpectrum
(
i
);
auto
&
spectrum
=
workspace
->
getSpectrum
(
i
);
int
index
;
if
(
m_indexIsSpecNo
)
index
=
spectrum
->
getSpectrumNo
();
index
=
spectrum
.
getSpectrumNo
();
else
index
=
static_cast
<
int
>
(
i
);
m_mapping
[
index
]
=
spectrum
->
getDetectorIDs
();
m_mapping
[
index
]
=
spectrum
.
getDetectorIDs
();
}
}
...
...
Framework/API/src/WorkspaceFactory.cpp
View file @
61755a3d
...
...
@@ -115,10 +115,10 @@ void WorkspaceFactoryImpl::initializeFromParent(
// Same number of histograms = copy over the spectra data
if
(
parent
->
getNumberHistograms
()
==
child
->
getNumberHistograms
())
{
for
(
size_t
wi
=
0
;
wi
<
parent
->
getNumberHistograms
();
wi
++
)
{
ISpectrum
*
childSpec
=
child
->
getSpectrum
(
wi
);
const
ISpectrum
*
parentSpec
=
parent
->
getSpectrum
(
wi
);
auto
&
childSpec
=
child
->
getSpectrum
(
wi
);
const
auto
&
parentSpec
=
parent
->
getSpectrum
(
wi
);
// Copy spectrum number and detector IDs
childSpec
->
copyInfoFrom
(
*
parentSpec
);
childSpec
.
copyInfoFrom
(
parentSpec
);
}
}
...
...
Framework/API/test/CompositeFunctionTest.h
View file @
61755a3d
...
...
@@ -65,14 +65,14 @@ public:
std
::
size_t
getNumberHistograms
()
const
override
{
return
m_spectra
.
size
();
}
/// Return the underlying ISpectrum ptr at the given workspace index.
ISpectrum
*
getSpectrum
(
const
size_t
index
)
override
{
return
&
m_spectra
[
index
];
ISpectrum
&
getSpectrum
(
const
size_t
index
)
override
{
return
m_spectra
[
index
];
}
/// Return the underlying ISpectrum ptr (const version) at the given workspace
/// index.
const
ISpectrum
*
getSpectrum
(
const
size_t
index
)
const
override
{
return
&
m_spectra
[
index
];
const
ISpectrum
&
getSpectrum
(
const
size_t
index
)
const
override
{
return
m_spectra
[
index
];
}
const
std
::
string
id
(
void
)
const
override
{
return
""
;
}
void
init
(
const
size_t
&
,
const
size_t
&
,
const
size_t
&
)
override
{}
...
...
Framework/API/test/FunctionTest.h
View file @
61755a3d
...
...
@@ -64,14 +64,14 @@ public:
std
::
size_t
getNumberHistograms
()
const
override
{
return
m_spectra
.
size
();
}
/// Return the underlying ISpectrum ptr at the given workspace index.
ISpectrum
*
getSpectrum
(
const
size_t
index
)
override
{
return
&
m_spectra
[
index
];
ISpectrum
&
getSpectrum
(
const
size_t
index
)
override
{
return
m_spectra
[
index
];
}
/// Return the underlying ISpectrum ptr (const version) at the given workspace
/// index.
const
ISpectrum
*
getSpectrum
(
const
size_t
index
)
const
override
{
return
&
m_spectra
[
index
];
const
ISpectrum
&
getSpectrum
(
const
size_t
index
)
const
override
{
return
m_spectra
[
index
];
}
const
std
::
string
id
(
void
)
const
override
{
return
""
;
}
void
init
(
const
size_t
&
,
const
size_t
&
,
const
size_t
&
)
override
{}
...
...
Framework/API/test/GeometryInfoTest.h
View file @
61755a3d
...
...
@@ -44,48 +44,41 @@ public:
void
test_constructor
()
{
TS_ASSERT_THROWS_NOTHING
(
GeometryInfo
(
*
m_factory
,
*
(
m_workspace
.
getSpectrum
(
0
)))
)
;
GeometryInfo
(
*
m_factory
,
m_workspace
.
getSpectrum
(
0
)));
}
void
test_isMonitor
()
{
TS_ASSERT_EQUALS
(
GeometryInfo
(
*
m_factory
,
*
(
m_workspace
.
getSpectrum
(
0
))
)
.
isMonitor
(),
GeometryInfo
(
*
m_factory
,
m_workspace
.
getSpectrum
(
0
)).
isMonitor
(),
false
);
TS_ASSERT_EQUALS
(
GeometryInfo
(
*
m_factory
,
*
(
m_workspace
.
getSpectrum
(
1
))
)
.
isMonitor
(),
GeometryInfo
(
*
m_factory
,
m_workspace
.
getSpectrum
(
1
)).
isMonitor
(),
false
);
TS_ASSERT_EQUALS
(
GeometryInfo
(
*
m_factory
,
*
(
m_workspace
.
getSpectrum
(
2
))
)
.
isMonitor
(),
GeometryInfo
(
*
m_factory
,
m_workspace
.
getSpectrum
(
2
)).
isMonitor
(),
false
);
TS_ASSERT_EQUALS
(
GeometryInfo
(
*
m_factory
,
*
(
m_workspace
.
getSpectrum
(
3
))).
isMonitor
(),
true
);
GeometryInfo
(
*
m_factory
,
m_workspace
.
getSpectrum
(
3
)).
isMonitor
(),
true
);
TS_ASSERT_EQUALS
(
GeometryInfo
(
*
m_factory
,
*
(
m_workspace
.
getSpectrum
(
4
))).
isMonitor
(),
true
);
GeometryInfo
(
*
m_factory
,
m_workspace
.
getSpectrum
(
4
)).
isMonitor
(),
true
);
}
void
test_isMasked
()
{
GeometryInfoFactory
factory
(
m_workspace
);
TS_ASSERT_EQUALS
(
GeometryInfo
(
*
m_factory
,
*
(
m_workspace
.
getSpectrum
(
0
))).
isMasked
(),
true
);
GeometryInfo
(
*
m_factory
,
m_workspace
.
getSpectrum
(
0
)).
isMasked
(),
true
);
TS_ASSERT_EQUALS
(
GeometryInfo
(
*
m_factory
,
*
(
m_workspace
.
getSpectrum
(
1
))).
isMasked
(),
false
);
GeometryInfo
(
*
m_factory
,
m_workspace
.
getSpectrum
(
1
)).
isMasked
(),
false
);
TS_ASSERT_EQUALS
(
GeometryInfo
(
*
m_factory
,
*
(
m_workspace
.
getSpectrum
(
2
))).
isMasked
(),
false
);
GeometryInfo
(
*
m_factory
,
m_workspace
.
getSpectrum
(
2
)).
isMasked
(),
false
);
TS_ASSERT_EQUALS
(
GeometryInfo
(
*
m_factory
,
*
(
m_workspace
.
getSpectrum
(
3
))).
isMasked
(),
true
);
GeometryInfo
(
*
m_factory
,
m_workspace
.
getSpectrum
(
3
)).
isMasked
(),
true
);
TS_ASSERT_EQUALS
(
GeometryInfo
(
*
m_factory
,
*
(
m_workspace
.
getSpectrum
(
4
))).
isMasked
(),
false
);
GeometryInfo
(
*
m_factory
,
m_workspace
.
getSpectrum
(
4
)).
isMasked
(),
false
);
}
void
test_getL1
()
{
auto
info
=
GeometryInfo
(
*
m_factory
,
*
(
m_workspace
.
getSpectrum
(
0
))
)
;
auto
info
=
GeometryInfo
(
*
m_factory
,
m_workspace
.
getSpectrum
(
0
));
TS_ASSERT_EQUALS
(
info
.
getL1
(),
20.0
);
}
...
...
@@ -93,48 +86,48 @@ public:
double
x2
=
5.0
*
5.0
;
double
y2
=
2.0
*
2.0
*
0.05
*
0.05
;
TS_ASSERT_EQUALS
(
GeometryInfo
(
*
m_factory
,
*
(
m_workspace
.
getSpectrum
(
0
))
)
.
getL2
(),
GeometryInfo
(
*
m_factory
,
m_workspace
.
getSpectrum
(
0
)).
getL2
(),
sqrt
(
x2
+
1
*
1
*
y2
));
TS_ASSERT_EQUALS
(
GeometryInfo
(
*
m_factory
,
*
(
m_workspace
.
getSpectrum
(
1
))
)
.
getL2
(),
GeometryInfo
(
*
m_factory
,
m_workspace
.
getSpectrum
(
1
)).
getL2
(),
sqrt
(
x2
+
0
*
0
*
y2
));
TS_ASSERT_EQUALS
(
GeometryInfo
(
*
m_factory
,
*
(
m_workspace
.
getSpectrum
(
2
))
)
.
getL2
(),
GeometryInfo
(
*
m_factory
,
m_workspace
.
getSpectrum
(
2
)).
getL2
(),
sqrt
(
x2
+
1
*
1
*
y2
));
TS_ASSERT_EQUALS
(
GeometryInfo
(
*
m_factory
,
*
(
m_workspace
.
getSpectrum
(
3
))
)
.
getL2
(),
-
9.0
);
GeometryInfo
(
*
m_factory
,
m_workspace
.
getSpectrum
(
3
)).
getL2
(),
-
9.0
);
TS_ASSERT_EQUALS
(
GeometryInfo
(
*
m_factory
,
*
(
m_workspace
.
getSpectrum
(
4
))
)
.
getL2
(),
-
2.0
);
GeometryInfo
(
*
m_factory
,
m_workspace
.
getSpectrum
(
4
)).
getL2
(),
-
2.0
);
}
void
test_getTwoTheta
()
{
TS_ASSERT_DELTA
(
GeometryInfo
(
*
m_factory
,
*
(
m_workspace
.
getSpectrum
(
0
))
)
.
getTwoTheta
(),
GeometryInfo
(
*
m_factory
,
m_workspace
.
getSpectrum
(
0
)).
getTwoTheta
(),
0.0199973
,
1e-6
);
TS_ASSERT_DELTA
(
GeometryInfo
(
*
m_factory
,
*
(
m_workspace
.
getSpectrum
(
1
))
)
.
getTwoTheta
(),
0.0
,
1e-6
);
GeometryInfo
(
*
m_factory
,
m_workspace
.
getSpectrum
(
1
)).
getTwoTheta
(),
0.0
,
1e-6
);
TS_ASSERT_DELTA
(
GeometryInfo
(
*
m_factory
,
*
(
m_workspace
.
getSpectrum
(
2
))
)
.
getTwoTheta
(),
GeometryInfo
(
*
m_factory
,
m_workspace
.
getSpectrum
(
2
)).
getTwoTheta
(),
0.0199973
,
1e-6
);
}
// Legacy test via the workspace method detectorTwoTheta(), which might be
// removed at some point.
void
test_getTwoThetaLegacy
()
{
auto
info
=
GeometryInfo
(
*
m_factory
,
*
(
m_workspace
.
getSpectrum
(
2
))
)
;
auto
info
=
GeometryInfo
(
*
m_factory
,
m_workspace
.
getSpectrum
(
2
));
auto
det
=
info
.
getDetector
();
TS_ASSERT_EQUALS
(
info
.
getTwoTheta
(),
m_workspace
.
detectorTwoTheta
(
*
det
));
}
void
test_getSignedTwoTheta
()
{
TS_ASSERT_DELTA
(
GeometryInfo
(
*
m_factory
,
*
(
m_workspace
.
getSpectrum
(
0
))
)
TS_ASSERT_DELTA
(
GeometryInfo
(
*
m_factory
,
m_workspace
.
getSpectrum
(
0
))
.
getSignedTwoTheta
(),
-
0.0199973
,
1e-6
);