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
b32622af
Commit
b32622af
authored
Feb 16, 2016
by
Tom Perkins
Browse files
Refactor some in-and-out functions in API
re #15286
parent
b931aef7
Changes
36
Hide whitespace changes
Inline
Side-by-side
Framework/API/inc/MantidAPI/IMDHistoWorkspace.h
View file @
b32622af
...
...
@@ -91,11 +91,9 @@ public:
virtual
size_t
getLinearIndex
(
size_t
index1
,
size_t
index2
,
size_t
index3
,
size_t
index4
)
const
=
0
;
virtual
void
getLineData
(
const
Mantid
::
Kernel
::
VMD
&
start
,
const
Mantid
::
Kernel
::
VMD
&
end
,
Mantid
::
API
::
MDNormalization
normalize
,
std
::
vector
<
coord_t
>
&
x
,
std
::
vector
<
signal_t
>
&
y
,
std
::
vector
<
signal_t
>
&
e
)
const
=
0
;
virtual
LinePlot
getLineData
(
const
Mantid
::
Kernel
::
VMD
&
start
,
const
Mantid
::
Kernel
::
VMD
&
end
,
Mantid
::
API
::
MDNormalization
normalize
)
const
=
0
;
virtual
double
&
operator
[](
const
size_t
&
index
)
=
0
;
...
...
Framework/API/inc/MantidAPI/IMDWorkspace.h
View file @
b32622af
...
...
@@ -74,6 +74,15 @@ public:
IMDWorkspace
();
~
IMDWorkspace
()
override
;
/**
* Holds X, Y, E for a line plot
*/
struct
LinePlot
{
std
::
vector
<
coord_t
>
x
;
std
::
vector
<
signal_t
>
y
;
std
::
vector
<
signal_t
>
e
;
};
/// Returns a clone of the workspace
std
::
unique_ptr
<
IMDWorkspace
>
clone
()
const
{
return
std
::
unique_ptr
<
IMDWorkspace
>
(
doClone
());
...
...
@@ -110,11 +119,9 @@ public:
const
Mantid
::
API
::
MDNormalization
&
normalization
)
const
=
0
;
/// Method to generate a line plot through a MD-workspace
virtual
void
getLinePlot
(
const
Mantid
::
Kernel
::
VMD
&
start
,
const
Mantid
::
Kernel
::
VMD
&
end
,
Mantid
::
API
::
MDNormalization
normalize
,
std
::
vector
<
coord_t
>
&
x
,
std
::
vector
<
signal_t
>
&
y
,
std
::
vector
<
signal_t
>
&
e
)
const
;
virtual
LinePlot
getLinePlot
(
const
Mantid
::
Kernel
::
VMD
&
start
,
const
Mantid
::
Kernel
::
VMD
&
end
,
Mantid
::
API
::
MDNormalization
normalize
)
const
;
IMDIterator
*
createIterator
(
Mantid
::
Geometry
::
MDImplicitFunction
*
function
=
NULL
)
const
;
...
...
Framework/API/inc/MantidAPI/MatrixWorkspace.h
View file @
b32622af
...
...
@@ -127,18 +127,18 @@ public:
spec2index_map
getSpectrumToWorkspaceIndexMap
()
const
;
detid2index_map
getDetectorIDToWorkspaceIndexMap
(
bool
throwIfMultipleDets
=
false
)
const
;
virtual
void
getDetectorIDToWorkspaceIndexVector
(
std
::
vector
<
size_t
>
&
out
,
detid_t
&
offset
,
virtual
std
::
vector
<
size_t
>
getDetectorIDToWorkspaceIndexVector
(
detid_t
&
offset
,
bool
throwIfMultipleDets
=
false
)
const
;
virtual
void
getSpectrumToWorkspaceIndexVector
(
std
::
vector
<
size_t
>
&
out
,
specid_t
&
offset
)
const
;
void
getIndicesFromSpectra
(
const
std
::
vector
<
specid_t
>
&
spectraList
,
std
::
vector
<
size_t
>
&
index
List
)
const
;
virtual
std
::
vector
<
size_t
>
getSpectrumToWorkspaceIndexVector
(
specid_t
&
offset
)
const
;
std
::
vector
<
size_t
>
getIndicesFromSpectra
(
const
std
::
vector
<
specid_t
>
&
spectra
List
)
const
;
size_t
getIndexFromSpectrumNumber
(
const
specid_t
specNo
)
const
;
void
getIndicesFromDetectorIDs
(
const
std
::
vector
<
detid_t
>
&
detIdList
,
std
::
vector
<
size_t
>
&
index
List
)
const
;
void
getSpectraFromDetectorIDs
(
const
std
::
vector
<
det
id_t
>
&
detIdList
,
std
::
vector
<
spec
id_t
>
&
spectra
List
)
const
;
std
::
vector
<
size_t
>
getIndicesFromDetectorIDs
(
const
std
::
vector
<
detid_t
>
&
detId
List
)
const
;
std
::
vector
<
spec
id_t
>
getSpectraFromDetectorIDs
(
const
std
::
vector
<
det
id_t
>
&
detId
List
)
const
;
bool
hasGroupedDetectors
()
const
;
...
...
@@ -405,11 +405,9 @@ public:
/// Dimensin id for y-dimension.
static
const
std
::
string
yDimensionId
;
/// Generate a line plot through the matrix workspace.
void
getLinePlot
(
const
Mantid
::
Kernel
::
VMD
&
start
,
const
Mantid
::
Kernel
::
VMD
&
end
,
Mantid
::
API
::
MDNormalization
normalize
,
std
::
vector
<
coord_t
>
&
x
,
std
::
vector
<
signal_t
>
&
y
,
std
::
vector
<
signal_t
>
&
e
)
const
override
;
LinePlot
getLinePlot
(
const
Mantid
::
Kernel
::
VMD
&
start
,
const
Mantid
::
Kernel
::
VMD
&
end
,
Mantid
::
API
::
MDNormalization
normalize
)
const
override
;
/// Get the signal at a coordinate in the workspace.
signal_t
getSignalAtCoord
(
const
coord_t
*
coords
,
...
...
Framework/API/inc/MantidAPI/SpectraAxis.h
View file @
b32622af
...
...
@@ -63,8 +63,8 @@ public:
specid_t
spectraNo
(
const
std
::
size_t
&
index
)
const
override
;
// Get a map that contains the spectra index as the key and the index in the
// array as t
e
h value
void
getSpectraIndexMap
(
spec2index_map
&
)
const
;
// array as th
e
value
spec2index_map
getSpectraIndexMap
()
const
;
double
getMin
()
const
override
;
double
getMax
()
const
override
;
...
...
Framework/API/src/IMDWorkspace.cpp
View file @
b32622af
...
...
@@ -134,41 +134,36 @@ const std::string IMDWorkspace::toString() const {
* @param start :: coordinates of the start point of the line
* @param end :: coordinates of the end point of the line
* @param normalize :: how to normalize the signal
* @param x :: is set to the boundaries of the bins, relative to start of the
*line.
* @param y :: is set to the normalized signal for each bin. Length = length(x)
*- 1
* @param e :: is set to the normalized errors for each bin. Length = length(x)
*- 1
* @returns :: a LinePlot in which x is set to the boundaries of the bins,
* relative to start of the line, y is set to the normalized signal for
* each bin with Length = length(x) - 1 and e is set to the normalized
* errors for each bin with Length = length(x) - 1.
*/
void
IMDWorkspace
::
getLinePlot
(
const
Mantid
::
Kernel
::
VMD
&
start
,
const
Mantid
::
Kernel
::
VMD
&
end
,
Mantid
::
API
::
MDNormalization
normalize
,
std
::
vector
<
coord_t
>
&
x
,
std
::
vector
<
signal_t
>
&
y
,
std
::
vector
<
signal_t
>
&
e
)
const
{
IMDWorkspace
::
LinePlot
IMDWorkspace
::
getLinePlot
(
const
Mantid
::
Kernel
::
VMD
&
start
,
const
Mantid
::
Kernel
::
VMD
&
end
,
Mantid
::
API
::
MDNormalization
normalize
)
const
{
// TODO: Don't use a fixed number of points later
size_t
numPoints
=
200
;
VMD
step
=
(
end
-
start
)
/
double
(
numPoints
);
double
stepLength
=
step
.
norm
();
// These will be the curve as plotted
x
.
clear
();
y
.
clear
();
e
.
clear
();
// This will be the curve as plotted
LinePlot
line
;
for
(
size_t
i
=
0
;
i
<
numPoints
;
i
++
)
{
// Coordinate along the line
VMD
coord
=
start
+
step
*
double
(
i
);
// Record the position along the line
x
.
push_back
(
static_cast
<
coord_t
>
(
stepLength
*
double
(
i
)));
line
.
x
.
push_back
(
static_cast
<
coord_t
>
(
stepLength
*
double
(
i
)));
signal_t
yVal
=
this
->
getSignalAtCoord
(
coord
.
getBareArray
(),
normalize
);
y
.
push_back
(
yVal
);
e
.
push_back
(
0.0
);
line
.
y
.
push_back
(
yVal
);
line
.
e
.
push_back
(
0.0
);
}
// And the last point
x
.
push_back
((
end
-
start
).
norm
());
line
.
x
.
push_back
((
end
-
start
).
norm
());
return
line
;
}
/**
...
...
Framework/API/src/MatrixWorkspace.cpp
View file @
b32622af
...
...
@@ -296,9 +296,8 @@ MatrixWorkspace::getNeighbours(const Geometry::IDetector *comp,
buildNearestNeighbours
(
ignoreMaskedDetectors
);
}
// Find the spectrum number
std
::
vector
<
specid_t
>
spectra
;
this
->
getSpectraFromDetectorIDs
(
std
::
vector
<
detid_t
>
(
1
,
comp
->
getID
()),
spectra
);
std
::
vector
<
specid_t
>
spectra
=
this
->
getSpectraFromDetectorIDs
(
std
::
vector
<
detid_t
>
(
1
,
comp
->
getID
()));
if
(
spectra
.
empty
())
{
throw
Kernel
::
Exception
::
NotFoundError
(
"MatrixWorkspace::getNeighbours - "
"Cannot find spectrum number for "
...
...
@@ -363,14 +362,13 @@ spec2index_map MatrixWorkspace::getSpectrumToWorkspaceIndexMap() const {
throw
std
::
runtime_error
(
"MatrixWorkspace::getSpectrumToWorkspaceIndexMap: "
"axis[1] is not a SpectraAxis, so I cannot "
"generate a map."
);
spec2index_map
map
;
try
{
ax
->
getSpectraIndexMap
(
map
);
return
ax
->
getSpectraIndexMap
();
}
catch
(
std
::
runtime_error
&
)
{
throw
std
::
runtime_error
(
"MatrixWorkspace::getSpectrumToWorkspaceIndexMap: no elements!"
);
g_log
.
error
()
<<
"MatrixWorkspace::getSpectrumToWorkspaceIndexMap: no elements!"
;
throw
;
}
return
map
;
}
//---------------------------------------------------------------------------------------
...
...
@@ -378,12 +376,12 @@ spec2index_map MatrixWorkspace::getSpectrumToWorkspaceIndexMap() const {
* The index into the vector = spectrum number + offset
* The value at that index = the corresponding Workspace Index
*
* @
param out
:: vector set to above definition
* @
returns
:: vector set to above definition
* @param offset :: add this to the detector ID to get the index into the
*vector.
*/
void
MatrixWorkspace
::
getSpectrumToWorkspaceIndexVector
(
std
::
vector
<
size_t
>
&
out
,
specid_t
&
offset
)
const
{
std
::
vector
<
size_t
>
MatrixWorkspace
::
getSpectrumToWorkspaceIndexVector
(
specid_t
&
offset
)
const
{
SpectraAxis
*
ax
=
dynamic_cast
<
SpectraAxis
*>
(
this
->
m_axes
[
1
]);
if
(
!
ax
)
throw
std
::
runtime_error
(
"MatrixWorkspace::getSpectrumToWorkspaceIndexMap: "
...
...
@@ -408,14 +406,16 @@ void MatrixWorkspace::getSpectrumToWorkspaceIndexVector(
// Offset so that the "min" value goes to index 0
offset
=
-
min
;
//
Res
ize correctly
out
.
resize
(
max
-
min
+
1
,
0
);
//
S
ize correctly
std
::
vector
<
size_t
>
out
(
max
-
min
+
1
,
0
);
// Make the vector
for
(
size_t
i
=
0
;
i
<
length
;
i
++
)
{
specid_t
spec
=
ax
->
spectraNo
(
i
);
out
[
spec
+
offset
]
=
i
;
}
return
out
;
}
//---------------------------------------------------------------------------------------
...
...
@@ -486,19 +486,18 @@ detid2index_map MatrixWorkspace::getDetectorIDToWorkspaceIndexMap(
* The index into the vector = DetectorID (pixel ID) + offset
* The value at that index = the corresponding Workspace Index
*
* @param out :: vector set to above definition
* @param offset :: add this to the detector ID to get the index into the
*vector.
* @param throwIfMultipleDets :: set to true to make the algorithm throw an
*error
* if there is more than one detector for a specific workspace index.
*error if there is more than one detector for a specific workspace index.
* @throw runtime_error if there is more than one detector per spectrum (if
*throwIfMultipleDets is true)
* @returns :: vector set to above definition
*/
void
MatrixWorkspace
::
getDetectorIDToWorkspaceIndexVector
(
std
::
vector
<
size_t
>
&
out
,
detid_t
&
offset
,
bool
throwIfMultipleDets
)
const
{
std
::
vector
<
size_t
>
MatrixWorkspace
::
getDetectorIDToWorkspaceIndexVector
(
detid_t
&
offset
,
bool
throwIfMultipleDets
)
const
{
// Make a correct initial size
out
.
clear
()
;
std
::
vector
<
size_t
>
out
;
detid_t
minId
=
0
;
detid_t
maxId
=
0
;
this
->
getInstrument
()
->
getMinMaxDetectorIDs
(
minId
,
maxId
);
...
...
@@ -534,6 +533,7 @@ void MatrixWorkspace::getDetectorIDToWorkspaceIndexVector(
}
}
// (for each workspace index)
return
out
;
}
//---------------------------------------------------------------------------------------
...
...
@@ -541,14 +541,12 @@ void MatrixWorkspace::getDetectorIDToWorkspaceIndexVector(
* Not a very efficient operation, but unfortunately it's sometimes required.
*
* @param spectraList :: The list of spectrum numbers required
* @param indexList :: Returns a reference to the vector of indices (empty if
*not a Workspace2D)
* @returns :: the vector of indices (empty if not a Workspace2D)
*/
void
MatrixWorkspace
::
getIndicesFromSpectra
(
const
std
::
vector
<
specid_t
>
&
spectraList
,
std
::
vector
<
size_t
>
&
indexList
)
const
{
std
::
vector
<
size_t
>
MatrixWorkspace
::
getIndicesFromSpectra
(
const
std
::
vector
<
specid_t
>
&
spectraList
)
const
{
// Clear the output index list
indexList
.
clear
()
;
std
::
vector
<
size_t
>
indexList
;
indexList
.
reserve
(
this
->
getNumberHistograms
());
auto
iter
=
spectraList
.
cbegin
();
...
...
@@ -561,6 +559,7 @@ void MatrixWorkspace::getIndicesFromSpectra(
}
++
iter
;
}
return
indexList
;
}
//---------------------------------------------------------------------------------------
...
...
@@ -589,11 +588,10 @@ MatrixWorkspace::getIndexFromSpectrumNumber(const specid_t specNo) const {
* effectively a set (i.e. there are no duplicates).
*
* @param detIdList :: The list of detector IDs required
* @
param indexList :: Returns a reference to the
vector of indices
* @
returns :: a
vector of indices
*/
void
MatrixWorkspace
::
getIndicesFromDetectorIDs
(
const
std
::
vector
<
detid_t
>
&
detIdList
,
std
::
vector
<
size_t
>
&
indexList
)
const
{
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
();
...
...
@@ -602,7 +600,7 @@ void MatrixWorkspace::getIndicesFromDetectorIDs(
}
}
indexList
.
clear
()
;
std
::
vector
<
size_t
>
indexList
;
indexList
.
reserve
(
detIdList
.
size
());
for
(
const
auto
detId
:
detIdList
)
{
auto
wsIndices
=
detectorIDtoWSIndices
.
find
(
detId
);
...
...
@@ -612,6 +610,7 @@ void MatrixWorkspace::getIndicesFromDetectorIDs(
}
}
}
return
indexList
;
}
//---------------------------------------------------------------------------------------
...
...
@@ -619,14 +618,13 @@ void MatrixWorkspace::getIndicesFromDetectorIDs(
*be slow!
*
* @param detIdList :: The list of detector IDs required
* @
param spectraList :: Returns
a reference to the vector of spectrum numbers.
* @
returns ::
a reference to the vector of spectrum numbers.
* 0 for not-found detectors
*/
void
MatrixWorkspace
::
getSpectraFromDetectorIDs
(
const
std
::
vector
<
detid_t
>
&
detIdList
,
std
::
vector
<
specid_t
>
&
spectraList
)
const
{
std
::
vector
<
specid_t
>
MatrixWorkspace
::
getSpectraFromDetectorIDs
(
const
std
::
vector
<
detid_t
>
&
detIdList
)
const
{
spectraList
.
clear
()
;
std
::
vector
<
specid_t
>
spectraList
;
// Try every detector in the list
for
(
auto
detId
:
detIdList
)
{
...
...
@@ -645,6 +643,7 @@ void MatrixWorkspace::getSpectraFromDetectorIDs(
if
(
foundDet
)
spectraList
.
push_back
(
foundSpecNum
);
}
// for each detector ID in the list
return
spectraList
;
}
double
MatrixWorkspace
::
getXMin
()
const
{
...
...
@@ -1508,20 +1507,16 @@ std::vector<IMDIterator *> MatrixWorkspace::createIterators(
* @param start :: coordinates of the start point of the line
* @param end :: coordinates of the end point of the line
* @param normalize :: how to normalize the signal
* @param x :: is set to the boundaries of the bins, relative to start of the
*line.
* @param y :: is set to the normalized signal for each bin. Length = length(x) -
*1
* @param e :: is set to the normalized errors for each bin. Length = length(x) -
*1
* @returns :: a LinePlot in which x is set to the boundaries of the bins,
* relative to start of the line, y is set to the normalized signal for
* each bin with Length = length(x) - 1 and e is set to the normalized
* errors for each bin with Length = length(x) - 1.
*/
void
MatrixWorkspace
::
getLinePlot
(
const
Mantid
::
Kernel
::
VMD
&
start
,
const
Mantid
::
Kernel
::
VMD
&
end
,
Mantid
::
API
::
MDNormalization
normalize
,
std
::
vector
<
coord_t
>
&
x
,
std
::
vector
<
signal_t
>
&
y
,
std
::
vector
<
signal_t
>
&
e
)
const
{
IMDWorkspace
::
getLinePlot
(
start
,
end
,
normalize
,
x
,
y
,
e
);
IMDWorkspace
::
LinePlot
MatrixWorkspace
::
getLinePlot
(
const
Mantid
::
Kernel
::
VMD
&
start
,
const
Mantid
::
Kernel
::
VMD
&
end
,
Mantid
::
API
::
MDNormalization
normalize
)
const
{
return
IMDWorkspace
::
getLinePlot
(
start
,
end
,
normalize
);
}
//------------------------------------------------------------------------------------
...
...
Framework/API/src/SpectraAxis.cpp
View file @
b32622af
...
...
@@ -120,17 +120,18 @@ specid_t SpectraAxis::spectraNo(const std::size_t &index) const {
/** Returns a map where spectra is the key and index is the value
* This is used for efficient search of spectra number within a workspace
* @
param map Reference to the map
* @
returns :: map of spectra to index
*/
void
SpectraAxis
::
getSpectraIndexMap
(
spec2index_map
&
map
)
const
{
spec2index_map
SpectraAxis
::
getSpectraIndexMap
()
const
{
size_t
nel
=
length
();
if
(
nel
==
0
)
throw
std
::
runtime_error
(
"getSpectraIndexMap(), zero elements"
);
map
.
clear
()
;
spec2index_map
map
;
for
(
size_t
i
=
0
;
i
<
nel
;
++
i
)
{
map
.
emplace
(
m_parentWS
->
getSpectrum
(
i
)
->
getSpectrumNo
(),
i
);
}
return
map
;
}
/** Check if two axis defined as spectra or numeric axis are equivalent
...
...
Framework/API/test/MatrixWorkspaceTest.h
View file @
b32622af
...
...
@@ -109,8 +109,7 @@ public:
dets
.
push_back
(
60
);
dets
.
push_back
(
20
);
dets
.
push_back
(
90
);
std
::
vector
<
size_t
>
indices
;
ws
.
getIndicesFromDetectorIDs
(
dets
,
indices
);
std
::
vector
<
size_t
>
indices
=
ws
.
getIndicesFromDetectorIDs
(
dets
);
TS_ASSERT_EQUALS
(
indices
.
size
(),
3
);
TS_ASSERT_EQUALS
(
indices
[
0
],
6
);
TS_ASSERT_EQUALS
(
indices
[
1
],
2
);
...
...
@@ -604,7 +603,7 @@ public:
std
::
vector
<
size_t
>
out
;
detid_t
offset
=
-
1234
;
TS_ASSERT_THROWS_NOTHING
(
ws
->
getDetectorIDToWorkspaceIndexVector
(
out
,
offset
));
out
=
ws
->
getDetectorIDToWorkspaceIndexVector
(
offset
));
TS_ASSERT_EQUALS
(
offset
,
0
);
TS_ASSERT_EQUALS
(
out
.
size
(),
100
);
TS_ASSERT_EQUALS
(
out
[
0
],
0
);
...
...
@@ -634,7 +633,7 @@ public:
ws
->
getSpectrum
(
66
)
->
clearDetectorIDs
();
TS_ASSERT_THROWS_NOTHING
(
ws
->
getDetectorIDToWorkspaceIndexVector
(
out
,
offset
));
out
=
ws
->
getDetectorIDToWorkspaceIndexVector
(
offset
));
TS_ASSERT_EQUALS
(
offset
,
1
);
TS_ASSERT_EQUALS
(
out
.
size
(),
112
);
TS_ASSERT_EQUALS
(
out
[
66
+
offset
],
std
::
numeric_limits
<
size_t
>::
max
());
...
...
@@ -647,8 +646,8 @@ public:
auto
ws
=
makeWorkspaceWithDetectors
(
100
,
10
);
std
::
vector
<
size_t
>
out
;
detid_t
offset
=
-
1234
;
TS_ASSERT_THROWS_NOTHING
(
ws
->
getSpectrumToWorkspaceIndexVector
(
out
,
offset
));
TS_ASSERT_THROWS_NOTHING
(
out
=
ws
->
getSpectrumToWorkspaceIndexVector
(
offset
));
TS_ASSERT_EQUALS
(
offset
,
-
1
);
TS_ASSERT_EQUALS
(
out
.
size
(),
100
);
TS_ASSERT_EQUALS
(
out
[
0
],
0
);
...
...
Framework/Algorithms/src/AsymmetryCalc.cpp
View file @
b32622af
...
...
@@ -46,19 +46,18 @@ std::map<std::string, std::string> AsymmetryCalc::validateInputs() {
std
::
map
<
std
::
string
,
std
::
string
>
result
;
std
::
vector
<
size_t
>
list
;
std
::
vector
<
int
>
forwd
=
getProperty
(
"ForwardSpectra"
);
std
::
vector
<
int
>
backwd
=
getProperty
(
"BackwardSpectra"
);
API
::
MatrixWorkspace_sptr
inputWS
=
getProperty
(
"InputWorkspace"
);
inputWS
->
getIndicesFromSpectra
(
forwd
,
list
);
auto
list
=
inputWS
->
getIndicesFromSpectra
(
forwd
);
if
(
forwd
.
size
()
!=
list
.
size
())
{
result
[
"ForwardSpectra"
]
=
"Some of the spectra can not be found in the input workspace"
;
}
inputWS
->
getIndicesFromSpectra
(
backwd
,
list
);
list
=
inputWS
->
getIndicesFromSpectra
(
backwd
);
if
(
backwd
.
size
()
!=
list
.
size
())
{
result
[
"BackwardSpectra"
]
=
"Some of the spectra can not be found in the input workspace"
;
...
...
@@ -117,8 +116,7 @@ void AsymmetryCalc::exec() {
std
::
vector
<
specid_t
>
specIDs
(
2
);
specIDs
[
0
]
=
forward
;
specIDs
[
1
]
=
backward
;
std
::
vector
<
size_t
>
indices
;
tmpWS
->
getIndicesFromSpectra
(
specIDs
,
indices
);
std
::
vector
<
size_t
>
indices
=
tmpWS
->
getIndicesFromSpectra
(
specIDs
);
forward
=
static_cast
<
int
>
(
indices
[
0
]);
backward
=
static_cast
<
int
>
(
indices
[
1
]);
...
...
Framework/Algorithms/src/CalculateTransmission.cpp
View file @
b32622af
...
...
@@ -48,9 +48,7 @@ const detid_t LOQ_TRANSMISSION_MONITOR_UDET = 3;
*/
size_t
getIndexFromDetectorID
(
MatrixWorkspace_sptr
ws
,
detid_t
detid
)
{
const
std
::
vector
<
detid_t
>
input
=
boost
::
assign
::
list_of
(
detid
);
std
::
vector
<
size_t
>
result
;
ws
->
getIndicesFromDetectorIDs
(
input
,
result
);
std
::
vector
<
size_t
>
result
=
ws
->
getIndicesFromDetectorIDs
(
input
);
if
(
result
.
empty
())
throw
std
::
invalid_argument
(
"Could not find the spectra corresponding to detector ID "
+
...
...
@@ -172,7 +170,7 @@ void CalculateTransmission::exec() {
transmissionIndices
.
push_back
(
transmissionMonitorIndex
);
logIfNotMonitor
(
sampleWS
,
directWS
,
transmissionMonitorIndex
);
}
else
if
(
usingROI
)
{
sampleWS
->
getIndicesFromDetectorIDs
(
transDetList
,
transmissionIndices
);
transmissionIndices
=
sampleWS
->
getIndicesFromDetectorIDs
(
transDetList
);
}
else
assert
(
false
);
...
...
Framework/Algorithms/src/CalculateTransmissionBeamSpreader.cpp
View file @
b32622af
...
...
@@ -112,12 +112,12 @@ void CalculateTransmissionBeamSpreader::exec() {
// Extract the required spectra into separate workspaces
std
::
vector
<
detid_t
>
udets
{
getProperty
(
"IncidentBeamMonitor"
)};
std
::
vector
<
size_t
>
indices
;
// Convert UDETs to workspace indices
// Get monitors (assume that the detector mapping is the same for all data
// sets)
sample_scatterWS
->
getIndicesFromDetectorIDs
(
udets
,
indices
);
std
::
vector
<
size_t
>
indices
=
sample_scatterWS
->
getIndicesFromDetectorIDs
(
udets
);
if
(
indices
.
size
()
!=
1
)
{
g_log
.
error
()
<<
"Could not find the incident monitor spectra
\n
"
;
throw
std
::
invalid_argument
(
...
...
Framework/Algorithms/src/ExtractSpectra.cpp
View file @
b32622af
...
...
@@ -421,8 +421,8 @@ void ExtractSpectra::checkProperties() {
// 3. Start and stop index
std
::
vector
<
detid_t
>
detectorList
=
getProperty
(
"DetectorList"
);
if
(
!
detectorList
.
empty
())
{
m_
inputW
orkspace
->
getIndicesFromDetectorIDs
(
detector
List
,
m_
w
orkspace
Index
List
);
m_
w
orkspace
Index
List
=
m_
inputW
orkspace
->
getIndicesFromDetectorIDs
(
detector
List
);
}
else
{
m_workspaceIndexList
=
getProperty
(
"WorkspaceIndexList"
);
...
...
Framework/Algorithms/src/GetEi.cpp
View file @
b32622af
...
...
@@ -213,11 +213,10 @@ std::vector<size_t> GetEi::getMonitorSpecIndexs(
// hard because the map works the other way,
// getting index numbers from spectra numbers has
// the same problem and we are about to do both
std
::
vector
<
size_t
>
specInds
;
// get the index number of the histogram for the first monitor
std
::
vector
<
specid_t
>
specNumTemp
(
&
specNum1
,
&
specNum1
+
1
);
WS
->
getIndicesFromSpectra
(
specNumTemp
,
specInds
);
auto
specInds
=
WS
->
getIndicesFromSpectra
(
specNumTemp
);
if
(
specInds
.
size
()
!=
1
)
{
// the monitor spectrum isn't present in the
// workspace, we can't continue from here
g_log
.
error
()
<<
"Couldn't find the first monitor spectrum, number "
...
...
@@ -226,9 +225,8 @@ std::vector<size_t> GetEi::getMonitorSpecIndexs(
}
// nowe the second monitor
std
::
vector
<
size_t
>
specIndexTemp
;
specNumTemp
[
0
]
=
specNum2
;
WS
->
getIndicesFromSpectra
(
specNumTemp
,
specIndexTemp
);
auto
specIndexTemp
=
WS
->
getIndicesFromSpectra
(
specNumTemp
);
if
(
specIndexTemp
.
size
()
!=
1
)
{
// the monitor spectrum isn't present in the
// workspace, we can't continue from here
g_log
.
error
()
<<
"Couldn't find the second monitor spectrum, number "
...
...
Framework/Algorithms/src/GetEi2.cpp
View file @
b32622af
...
...
@@ -203,10 +203,8 @@ double GetEi2::calculateEi(const double initial_guess) {
// Covert spectrum numbers to workspace indices
std
::
vector
<
specid_t
>
spec_nums
(
2
,
mon1
);
spec_nums
[
1
]
=
mon2
;
std
::
vector
<
size_t
>
mon_indices
;
mon_indices
.
reserve
(
2
);
// get the index number of the histogram for the first monitor
m_input_ws
->
getIndicesFromSpectra
(
spec_nums
,
mon_indices
);
auto
mon_indices
=
m_input_ws
->
getIndicesFromSpectra
(
spec_nums
);
if
(
mon_indices
.
size
()
!=
2
)
{
g_log
.
error
()
<<
"Error retrieving monitor spectra from input workspace. "
...
...
Framework/Algorithms/src/MuonGroupDetectors.cpp
View file @
b32622af
...
...
@@ -98,8 +98,8 @@ void MuonGroupDetectors::exec() {
std
::
vector
<
int
>
&
detectorIDs
=
table
->
cell
<
std
::
vector
<
int
>>
(
*
rowIt
,
0
);
// Recieve detector IDs, but need workspace indices to group, so convert
std
::
vector
<
size_t
>
wsIndices
;
inWS
->
getIndicesFromDetectorIDs
(
detectorIDs
,
wsIndices
);
std
::
vector
<
size_t
>
wsIndices
=
inWS
->
getIndicesFromDetectorIDs
(
detectorIDs
);
if
(
wsIndices
.
size
()
!=
detectorIDs
.
size
())
throw
std
::
invalid_argument
(
"Some of the detector IDs were not found"
);
...
...
Framework/Algorithms/src/NormaliseToMonitor.cpp
View file @
b32622af
...
...
@@ -117,8 +117,7 @@ bool MonIDPropChanger::monitorIdReader(
}
// are these monitors really there?
// got the index of correspondent spectra.
std
::
vector
<
size_t
>
indexList
;
inputWS
->
getIndicesFromDetectorIDs
(
mon
,
indexList
);
std
::
vector
<
size_t
>
indexList
=
inputWS
->
getIndicesFromDetectorIDs
(
mon
);
if
(
indexList
.
empty
())
{
if
(
iExistingAllowedValues
.
empty
())
{
return
false
;
...
...
@@ -385,8 +384,7 @@ API::MatrixWorkspace_sptr NormaliseToMonitor::getInWSMonitorSpectrum(
// set spectra of detector's ID of one selected monitor ID
std
::
vector
<
detid_t
>
detID
(
1
,
monitorID
);
// got the index of correspondent spectra (should be only one).
std
::
vector
<
size_t
>
indexList
;
inputWorkspace
->
getIndicesFromDetectorIDs
(
detID
,
indexList
);
auto
indexList
=
inputWorkspace
->
getIndicesFromDetectorIDs
(
detID
);
if
(
indexList
.
empty
())
{
throw
std
::
runtime_error
(
"Can not find spectra, corresponding to the requested monitor ID"
);
...
...
@@ -397,14 +395,13 @@ API::MatrixWorkspace_sptr NormaliseToMonitor::getInWSMonitorSpectrum(
}
spectra_num
=
static_cast
<
int
>
(
indexList
[
0
]);
}
else
{
// monitor spectrum is specified.
spec2index_map
specs
;
const
SpectraAxis
*
axis
=
dynamic_cast
<
const
SpectraAxis
*>
(
inputWorkspace
->
getAxis
(
1
));
if
(
!
axis
)
{