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
33e2b304
Commit
33e2b304
authored
May 14, 2010
by
Peterson, Peter
Browse files
Set a single eol for files that needed it, then set the eol property. Refs #1256.
parent
d69fce27
Changes
46
Expand all
Hide whitespace changes
Inline
Side-by-side
Code/Mantid/Algorithms/src/BinaryOperation.cpp
View file @
33e2b304
...
...
@@ -2,7 +2,7 @@
// Includes
//----------------------------------------------------------------------
#include
"MantidAlgorithms/BinaryOperation.h"
#include
"MantidAPI/WorkspaceProperty.h"
#include
"MantidAPI/WorkspaceProperty.h"
#include
"MantidAPI/FrameworkManager.h"
using
namespace
Mantid
::
API
;
...
...
@@ -275,8 +275,8 @@ namespace Mantid
* @param rhs The workspace which is the right hand operand
* @param out The result workspace
*/
void
BinaryOperation
::
propagateMasking
(
const
API
::
MatrixWorkspace_const_sptr
rhs
,
API
::
MatrixWorkspace_sptr
out
)
{
void
BinaryOperation
::
propagateMasking
(
const
API
::
MatrixWorkspace_const_sptr
rhs
,
API
::
MatrixWorkspace_sptr
out
)
{
const
int
outHists
=
out
->
getNumberHistograms
();
const
int
rhsHists
=
rhs
->
getNumberHistograms
();
for
(
int
i
=
0
;
i
<
outHists
;
++
i
)
...
...
@@ -290,8 +290,8 @@ namespace Mantid
for
(
it
=
masks
.
begin
();
it
!=
masks
.
end
();
++
it
)
out
->
maskBin
(
i
,
it
->
first
,
it
->
second
);
}
}
}
}
}
}
// namespace Algorithms
}
// namespace Mantid
}
// namespace Algorithms
}
// namespace Mantid
Code/Mantid/Algorithms/src/CommutativeBinaryOperation.cpp
View file @
33e2b304
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include
"MantidAlgorithms/CommutativeBinaryOperation.h"
namespace
Mantid
{
namespace
Algorithms
{
/** Performs a simple check to see if the sizes of two workspaces are compatible for a binary operation
* In order to be size compatible then the larger workspace
* must divide be the size of the smaller workspace leaving no remainder
* @param rhs the first workspace to compare
* @param lhs the second workspace to compare
* @retval true The two workspaces are size compatible
* @retval false The two workspaces are NOT size compatible
*/
bool
CommutativeBinaryOperation
::
checkSizeCompatibility
(
const
API
::
MatrixWorkspace_const_sptr
rhs
,
const
API
::
MatrixWorkspace_const_sptr
lhs
)
const
{
//get the largest workspace
API
::
MatrixWorkspace_const_sptr
wsLarger
;
API
::
MatrixWorkspace_const_sptr
wsSmaller
;
if
(
rhs
->
size
()
>
lhs
->
size
())
{
wsLarger
=
rhs
;
wsSmaller
=
lhs
;
}
else
{
wsLarger
=
lhs
;
wsSmaller
=
rhs
;
}
//call the base routine
return
BinaryOperation
::
checkSizeCompatibility
(
wsLarger
,
wsSmaller
);
}
}
}
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include
"MantidAlgorithms/CommutativeBinaryOperation.h"
namespace
Mantid
{
namespace
Algorithms
{
/** Performs a simple check to see if the sizes of two workspaces are compatible for a binary operation
* In order to be size compatible then the larger workspace
* must divide be the size of the smaller workspace leaving no remainder
* @param rhs the first workspace to compare
* @param lhs the second workspace to compare
* @retval true The two workspaces are size compatible
* @retval false The two workspaces are NOT size compatible
*/
bool
CommutativeBinaryOperation
::
checkSizeCompatibility
(
const
API
::
MatrixWorkspace_const_sptr
rhs
,
const
API
::
MatrixWorkspace_const_sptr
lhs
)
const
{
//get the largest workspace
API
::
MatrixWorkspace_const_sptr
wsLarger
;
API
::
MatrixWorkspace_const_sptr
wsSmaller
;
if
(
rhs
->
size
()
>
lhs
->
size
())
{
wsLarger
=
rhs
;
wsSmaller
=
lhs
;
}
else
{
wsLarger
=
lhs
;
wsSmaller
=
rhs
;
}
//call the base routine
return
BinaryOperation
::
checkSizeCompatibility
(
wsLarger
,
wsSmaller
);
}
}
}
Code/Mantid/Algorithms/src/ConvertSpectrumAxis.cpp
View file @
33e2b304
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include
"MantidAlgorithms/ConvertSpectrumAxis.h"
#include
"MantidDataObjects/Workspace2D.h"
/// @cond
// Don't document this very long winded way of getting "radians" to print on the axis.
namespace
{
class
Degrees
:
public
Mantid
::
Kernel
::
Unit
{
const
std
::
string
unitID
()
const
{
return
""
;
}
const
std
::
string
caption
()
const
{
return
"Scattering angle"
;
}
const
std
::
string
label
()
const
{
return
"degrees"
;
}
#include
"MantidAlgorithms/ConvertSpectrumAxis.h"
#include
"MantidDataObjects/Workspace2D.h"
/// @cond
// Don't document this very long winded way of getting "radians" to print on the axis.
namespace
{
class
Degrees
:
public
Mantid
::
Kernel
::
Unit
{
const
std
::
string
unitID
()
const
{
return
""
;
}
const
std
::
string
caption
()
const
{
return
"Scattering angle"
;
}
const
std
::
string
label
()
const
{
return
"degrees"
;
}
void
toTOF
(
std
::
vector
<
double
>&
xdata
,
std
::
vector
<
double
>&
ydata
,
const
double
&
l1
,
const
double
&
l2
,
const
double
&
twoTheta
,
const
int
&
emode
,
const
double
&
efixed
,
const
double
&
delta
)
const
{}
void
fromTOF
(
std
::
vector
<
double
>&
xdata
,
std
::
vector
<
double
>&
ydata
,
const
double
&
l1
,
const
double
&
l2
,
const
double
&
twoTheta
,
const
int
&
emode
,
const
double
&
efixed
,
const
double
&
delta
)
const
{}
};
};
}
// end anonynmous namespace
/// @endcond
/// @endcond
namespace
Mantid
{
namespace
Algorithms
{
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM
(
ConvertSpectrumAxis
)
using
namespace
Kernel
;
using
namespace
API
;
using
namespace
Geometry
;
using
DataObjects
::
Workspace2D
;
using
DataObjects
::
Workspace2D_const_sptr
;
void
ConvertSpectrumAxis
::
init
()
{
declareProperty
(
new
WorkspaceProperty
<
Workspace2D
>
(
"InputWorkspace"
,
""
,
Direction
::
Input
));
declareProperty
(
new
WorkspaceProperty
<>
(
"OutputWorkspace"
,
""
,
Direction
::
Output
));
declareProperty
(
"Target"
,
""
,
new
ListValidator
(
std
::
vector
<
std
::
string
>
(
1
,
"theta"
)),
"The detector attribute to convert the spectrum axis to"
);
}
void
ConvertSpectrumAxis
::
exec
()
{
// Get the input workspace
Workspace2D_const_sptr
inputWS
=
getProperty
(
"InputWorkspace"
);
// Check that the input workspace has a spectrum axis for axis 1
// Could put this in a validator later
const
Axis
*
const
specAxis
=
inputWS
->
getAxis
(
1
);
if
(
!
specAxis
->
isSpectra
()
)
{
g_log
.
error
(
"The input workspace must have spectrum numbers along one axis"
);
throw
std
::
runtime_error
(
"The input workspace must have spectrum numbers along one axis"
);
}
// Loop over the original spectrum axis, finding the theta (n.b. not 2theta!) for each spectrum
// and storing it's corresponding workspace index
// Map will be sorted on theta, so resulting axis will be ordered as well
std
::
multimap
<
double
,
int
>
theta2indexMap
;
const
int
axisLength
=
inputWS
->
getNumberHistograms
();
bool
warningGiven
=
false
;
for
(
int
i
=
0
;
i
<
axisLength
;
++
i
)
{
try
{
IDetector_const_sptr
det
=
inputWS
->
getDetector
(
i
);
theta2indexMap
.
insert
(
std
::
make_pair
(
inputWS
->
detectorTwoTheta
(
det
)
*
180.0
/
M_PI
,
i
)
);
}
catch
(
Exception
::
NotFoundError
)
{
if
(
!
warningGiven
)
g_log
.
warning
(
"The instrument definition is incomplete - spectra dropped from output"
);
warningGiven
=
true
;
}
}
// Create the output workspace. Can't re-use the input one because we'll be re-ordering the spectra.
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM
(
ConvertSpectrumAxis
)
using
namespace
Kernel
;
using
namespace
API
;
using
namespace
Geometry
;
using
DataObjects
::
Workspace2D
;
using
DataObjects
::
Workspace2D_const_sptr
;
void
ConvertSpectrumAxis
::
init
()
{
declareProperty
(
new
WorkspaceProperty
<
Workspace2D
>
(
"InputWorkspace"
,
""
,
Direction
::
Input
));
declareProperty
(
new
WorkspaceProperty
<>
(
"OutputWorkspace"
,
""
,
Direction
::
Output
));
declareProperty
(
"Target"
,
""
,
new
ListValidator
(
std
::
vector
<
std
::
string
>
(
1
,
"theta"
)),
"The detector attribute to convert the spectrum axis to"
);
}
void
ConvertSpectrumAxis
::
exec
()
{
// Get the input workspace
Workspace2D_const_sptr
inputWS
=
getProperty
(
"InputWorkspace"
);
// Check that the input workspace has a spectrum axis for axis 1
// Could put this in a validator later
const
Axis
*
const
specAxis
=
inputWS
->
getAxis
(
1
);
if
(
!
specAxis
->
isSpectra
()
)
{
g_log
.
error
(
"The input workspace must have spectrum numbers along one axis"
);
throw
std
::
runtime_error
(
"The input workspace must have spectrum numbers along one axis"
);
}
// Loop over the original spectrum axis, finding the theta (n.b. not 2theta!) for each spectrum
// and storing it's corresponding workspace index
// Map will be sorted on theta, so resulting axis will be ordered as well
std
::
multimap
<
double
,
int
>
theta2indexMap
;
const
int
axisLength
=
inputWS
->
getNumberHistograms
();
bool
warningGiven
=
false
;
for
(
int
i
=
0
;
i
<
axisLength
;
++
i
)
{
try
{
IDetector_const_sptr
det
=
inputWS
->
getDetector
(
i
);
theta2indexMap
.
insert
(
std
::
make_pair
(
inputWS
->
detectorTwoTheta
(
det
)
*
180.0
/
M_PI
,
i
)
);
}
catch
(
Exception
::
NotFoundError
)
{
if
(
!
warningGiven
)
g_log
.
warning
(
"The instrument definition is incomplete - spectra dropped from output"
);
warningGiven
=
true
;
}
}
// Create the output workspace. Can't re-use the input one because we'll be re-ordering the spectra.
MatrixWorkspace_sptr
outputWS
=
WorkspaceFactory
::
Instance
().
create
(
inputWS
,
theta2indexMap
.
size
(),
inputWS
->
readX
(
0
).
size
(),
inputWS
->
blocksize
());
setProperty
(
"OutputWorkspace"
,
outputWS
);
// Now set up a new, numeric axis holding the theta values corresponding to each spectrum
Axis
*
const
newAxis
=
new
Axis
(
AxisType
::
Numeric
,
theta2indexMap
.
size
());
outputWS
->
replaceAxis
(
1
,
newAxis
);
// The unit of this axis is radians. Use the 'radians' unit defined above.
newAxis
->
unit
()
=
boost
::
shared_ptr
<
Unit
>
(
new
Degrees
);
std
::
multimap
<
double
,
int
>::
const_iterator
it
;
int
currentIndex
=
0
;
for
(
it
=
theta2indexMap
.
begin
();
it
!=
theta2indexMap
.
end
();
++
it
)
{
// Set the axis value
newAxis
->
setValue
(
currentIndex
,
it
->
first
);
// Now copy over the data
outputWS
->
dataX
(
currentIndex
)
=
inputWS
->
dataX
(
it
->
second
);
outputWS
->
dataY
(
currentIndex
)
=
inputWS
->
dataY
(
it
->
second
);
outputWS
->
dataE
(
currentIndex
)
=
inputWS
->
dataE
(
it
->
second
);
++
currentIndex
;
}
}
setProperty
(
"OutputWorkspace"
,
outputWS
);
// Now set up a new, numeric axis holding the theta values corresponding to each spectrum
Axis
*
const
newAxis
=
new
Axis
(
AxisType
::
Numeric
,
theta2indexMap
.
size
());
outputWS
->
replaceAxis
(
1
,
newAxis
);
// The unit of this axis is radians. Use the 'radians' unit defined above.
newAxis
->
unit
()
=
boost
::
shared_ptr
<
Unit
>
(
new
Degrees
);
std
::
multimap
<
double
,
int
>::
const_iterator
it
;
int
currentIndex
=
0
;
for
(
it
=
theta2indexMap
.
begin
();
it
!=
theta2indexMap
.
end
();
++
it
)
{
// Set the axis value
newAxis
->
setValue
(
currentIndex
,
it
->
first
);
// Now copy over the data
outputWS
->
dataX
(
currentIndex
)
=
inputWS
->
dataX
(
it
->
second
);
outputWS
->
dataY
(
currentIndex
)
=
inputWS
->
dataY
(
it
->
second
);
outputWS
->
dataE
(
currentIndex
)
=
inputWS
->
dataE
(
it
->
second
);
++
currentIndex
;
}
}
}
// namespace Algorithms
}
// namespace Mantid
}
// namespace Mantid
Code/Mantid/Algorithms/src/ConvertUnits.cpp
View file @
33e2b304
...
...
@@ -481,9 +481,9 @@ void ConvertUnits::reverse(API::MatrixWorkspace_sptr WS)
API
::
MatrixWorkspace_sptr
ConvertUnits
::
removeUnphysicalBins
(
const
Mantid
::
API
::
MatrixWorkspace_const_sptr
workspace
)
{
MatrixWorkspace_sptr
result
;
// If this is a Workspace2D, get the spectra axes for copying in the spectraNo later
Axis
*
specAxis
=
NULL
,
*
outAxis
=
NULL
;
if
(
workspace
->
axes
()
>
1
)
specAxis
=
workspace
->
getAxis
(
1
);
// If this is a Workspace2D, get the spectra axes for copying in the spectraNo later
Axis
*
specAxis
=
NULL
,
*
outAxis
=
NULL
;
if
(
workspace
->
axes
()
>
1
)
specAxis
=
workspace
->
getAxis
(
1
);
const
int
numSpec
=
workspace
->
getNumberHistograms
();
const
std
::
string
emode
=
getProperty
(
"Emode"
);
...
...
@@ -513,7 +513,7 @@ API::MatrixWorkspace_sptr ConvertUnits::removeUnphysicalBins(const Mantid::API::
MantidVec
::
difference_type
first
=
start
-
X0
.
begin
();
result
=
WorkspaceFactory
::
Instance
().
create
(
workspace
,
numSpec
,
bins
,
bins
-
1
);
if
(
specAxis
)
outAxis
=
result
->
getAxis
(
1
);
if
(
specAxis
)
outAxis
=
result
->
getAxis
(
1
);
for
(
int
i
=
0
;
i
<
numSpec
;
++
i
)
{
...
...
@@ -523,7 +523,7 @@ API::MatrixWorkspace_sptr ConvertUnits::removeUnphysicalBins(const Mantid::API::
result
->
dataX
(
i
).
assign
(
X
.
begin
()
+
first
,
X
.
end
());
result
->
dataY
(
i
).
assign
(
Y
.
begin
()
+
first
,
Y
.
end
());
result
->
dataE
(
i
).
assign
(
E
.
begin
()
+
first
,
E
.
end
());
if
(
specAxis
)
outAxis
->
spectraNo
(
i
)
=
specAxis
->
spectraNo
(
i
);
if
(
specAxis
)
outAxis
->
spectraNo
(
i
)
=
specAxis
->
spectraNo
(
i
);
}
}
else
if
(
emode
==
"Indirect"
)
...
...
@@ -545,7 +545,7 @@ API::MatrixWorkspace_sptr ConvertUnits::removeUnphysicalBins(const Mantid::API::
g_log
.
debug
()
<<
maxBins
<<
std
::
endl
;
// Now create an output workspace large enough for the longest 'good' range
result
=
WorkspaceFactory
::
Instance
().
create
(
workspace
,
numSpec
,
maxBins
,
maxBins
-
1
);
if
(
specAxis
)
outAxis
=
result
->
getAxis
(
1
);
if
(
specAxis
)
outAxis
=
result
->
getAxis
(
1
);
// Next, loop again copying in the correct range for each spectrum
for
(
int
j
=
0
;
j
<
numSpec
;
++
j
)
{
...
...
Code/Mantid/Algorithms/src/CreateCalFileByNames.cpp
View file @
33e2b304
This diff is collapsed.
Click to expand it.
Code/Mantid/Algorithms/src/CropWorkspace.cpp
View file @
33e2b304
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include
"MantidAlgorithms/CropWorkspace.h"
#include
"MantidAPI/WorkspaceValidators.h"
namespace
Mantid
{
namespace
Algorithms
{
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM
(
CropWorkspace
)
using
namespace
Kernel
;
using
namespace
API
;
using
DataObjects
::
Workspace2D
;
/// Default constructor
CropWorkspace
::
CropWorkspace
()
:
Algorithm
(),
m_minX
(
0
),
m_maxX
(
0
),
m_minSpec
(
-
1
),
m_maxSpec
(
-
1
),
m_commonBoundaries
(
false
),
m_histogram
(
false
),
m_croppingInX
(
false
)
{}
/// Destructor
CropWorkspace
::~
CropWorkspace
()
{}
void
CropWorkspace
::
init
()
{
declareProperty
(
new
WorkspaceProperty
<
Workspace2D
>
(
"InputWorkspace"
,
""
,
Direction
::
Input
),
"The input Workspace2D"
);
declareProperty
(
new
WorkspaceProperty
<>
(
"OutputWorkspace"
,
""
,
Direction
::
Output
),
"Name of the output workspace2D"
);
declareProperty
(
"XMin"
,
0.0
,
"An X value that is within the first (lowest X value) bin that will be retained
\n
"
"(default: workspace min)"
);
declareProperty
(
"XMax"
,
EMPTY_DBL
(),
"An X value that is in the highest X value bin to be retained (default: max X)"
);
BoundedValidator
<
int
>
*
mustBePositive
=
new
BoundedValidator
<
int
>
();
mustBePositive
->
setLower
(
0
);
declareProperty
(
"StartWorkspaceIndex"
,
0
,
mustBePositive
,
"The index number of the first entry in the Workspace that will be loaded
\n
"
"(default: first entry in the Workspace)"
);
// As the property takes ownership of the validator pointer, have to take care to pass in a unique
// pointer to each property.
declareProperty
(
"EndWorkspaceIndex"
,
EMPTY_INT
(),
mustBePositive
->
clone
(),
"The index number of the last entry in the Workspace to be loaded
\n
"
"(default: last entry in the Workspace)"
);
}
/** Executes the algorithm
* @throw std::out_of_range If a property is set to an invalid value for the input workspace
*/
void
CropWorkspace
::
exec
()
{
// Get the input workspace
m_inputWorkspace
=
getProperty
(
"InputWorkspace"
);
m_histogram
=
m_inputWorkspace
->
isHistogramData
();
// Check for common boundaries in input workspace
m_commonBoundaries
=
WorkspaceHelpers
::
commonBoundaries
(
m_inputWorkspace
);
// Retrieve and validate the input properties
this
->
checkProperties
();
// Create the output workspace
MatrixWorkspace_sptr
outputWorkspace
=
WorkspaceFactory
::
Instance
().
create
(
m_inputWorkspace
,
m_maxSpec
-
m_minSpec
+
1
,
m_maxX
-
m_minX
,
m_maxX
-
m_minX
-
m_histogram
);
// If this is a Workspace2D, get the spectra axes for copying in the spectraNo later
Axis
*
specAxis
=
NULL
,
*
outAxis
=
NULL
;
if
(
m_inputWorkspace
->
axes
()
>
1
)
{
specAxis
=
m_inputWorkspace
->
getAxis
(
1
);
outAxis
=
outputWorkspace
->
getAxis
(
1
);
}
DataObjects
::
Histogram1D
::
RCtype
newX
;
if
(
m_commonBoundaries
)
{
const
MantidVec
&
oldX
=
m_inputWorkspace
->
readX
(
m_minSpec
);
newX
.
access
().
assign
(
oldX
.
begin
()
+
m_minX
,
oldX
.
begin
()
+
m_maxX
);
}
Progress
prog
(
this
,
0.0
,
1.0
,(
m_maxSpec
-
m_minSpec
));
// Loop over the required spectra, copying in the desired bins
for
(
int
i
=
m_minSpec
,
j
=
0
;
i
<=
m_maxSpec
;
++
i
,
++
j
)
{
// Preserve/restore sharing if X vectors are the same
if
(
m_commonBoundaries
)
{
outputWorkspace
->
setX
(
j
,
newX
);
}
else
{
// Safe to just copy whole vector 'cos can't be cropping in X if not common
outputWorkspace
->
setX
(
j
,
m_inputWorkspace
->
refX
(
i
));
}
const
MantidVec
&
oldY
=
m_inputWorkspace
->
readY
(
i
);
outputWorkspace
->
dataY
(
j
).
assign
(
oldY
.
begin
()
+
m_minX
,
oldY
.
begin
()
+
(
m_maxX
-
m_histogram
));
const
MantidVec
&
oldE
=
m_inputWorkspace
->
readE
(
i
);
outputWorkspace
->
dataE
(
j
).
assign
(
oldE
.
begin
()
+
m_minX
,
oldE
.
begin
()
+
(
m_maxX
-
m_histogram
));
if
(
specAxis
)
outAxis
->
spectraNo
(
j
)
=
specAxis
->
spectraNo
(
i
);
if
(
!
m_commonBoundaries
)
this
->
cropRagged
(
outputWorkspace
,
i
,
j
);
// Propagate bin masking if there is any
if
(
m_inputWorkspace
->
hasMaskedBins
(
i
)
)
{
const
MatrixWorkspace
::
MaskList
&
inputMasks
=
m_inputWorkspace
->
maskedBins
(
i
);
MatrixWorkspace
::
MaskList
::
const_iterator
it
;
for
(
it
=
inputMasks
.
begin
();
it
!=
inputMasks
.
end
();
++
it
)
{
const
int
maskIndex
=
(
*
it
).
first
;
if
(
maskIndex
>=
m_minX
&&
maskIndex
<
m_maxX
-
m_histogram
)
outputWorkspace
->
maskBin
(
j
,
maskIndex
-
m_minX
,(
*
it
).
second
);
}
}
prog
.
report
();
}
setProperty
(
"OutputWorkspace"
,
outputWorkspace
);
}
/** Retrieves the optional input properties and checks that they have valid values.
* Assigns to the defaults if any property has not been set.
* @throw std::invalid_argument If the input workspace does not have common binning
* @throw std::out_of_range If a property is set to an invalid value for the input workspace
*/
void
CropWorkspace
::
checkProperties
()
{
m_minX
=
this
->
getXMin
();
m_maxX
=
this
->
getXMax
();
const
int
xSize
=
m_inputWorkspace
->
readX
(
0
).
size
();
if
(
m_minX
>
0
||
m_maxX
<
xSize
)
{
if
(
m_minX
>
m_maxX
)
{
g_log
.
error
(
"XMin must be less than XMax"
);
throw
std
::
out_of_range
(
"XMin must be less than XMax"
);
}
if
(
m_minX
==
m_maxX
&&
m_commonBoundaries
)
{
g_log
.
error
(
"The X range given lies entirely within a single bin"
);
throw
std
::
out_of_range
(
"The X range given lies entirely within a single bin"
);
}
m_croppingInX
=
true
;
}
if
(
m_minX
<
0
||
!
m_commonBoundaries
)
m_minX
=
0
;
if
(
!
m_commonBoundaries
)
m_maxX
=
m_inputWorkspace
->
readX
(
0
).
size
();
m_minSpec
=
getProperty
(
"StartWorkspaceIndex"
);
const
int
numberOfSpectra
=
m_inputWorkspace
->
getNumberHistograms
();
m_maxSpec
=
getProperty
(
"EndWorkspaceIndex"
);
if
(
isEmpty
(
m_maxSpec
)
)
m_maxSpec
=
numberOfSpectra
-
1
;
// Check 'StartSpectrum' is in range 0-numberOfSpectra
if
(
m_minSpec
>
numberOfSpectra
-
1
)
{
g_log
.
error
(
"StartWorkspaceIndex out of range!"
);
throw
std
::
out_of_range
(
"StartSpectrum out of range!"
);
}
if
(
m_maxSpec
>
numberOfSpectra
-
1
)
{
g_log
.
error
(
"EndWorkspaceIndex out of range!"
);
throw
std
::
out_of_range
(
"EndWorkspaceIndex out of range!"
);
}
if
(
m_maxSpec
<
m_minSpec
)
{
g_log
.
error
(
"StartWorkspaceIndex must be less than or equal to EndWorkspaceIndex"
);
throw
std
::
out_of_range
(
"StartWorkspaceIndex must be less than or equal to EndWorkspaceIndex"
);
}
}
/** Find the X index corresponding to (or just within) the value given in the XMin property.
* Sets the default if the property has not been set.
* @param wsIndex The workspace index to check (default 0).
* @return The X index corresponding to the XMin value.
*/
int
CropWorkspace
::
getXMin
(
const
int
wsIndex
)
{
Property
*
minX
=
getProperty
(
"XMin"
);
const
bool
def
=
minX
->
isDefault
();
int
xIndex
=
-
1
;
if
(
!
def
)
{
//A value has been passed to the algorithm, check it and maybe store it
const
double
minX_val
=
getProperty
(
"XMin"
);
const
MantidVec
&
X
=
m_inputWorkspace
->
readX
(
wsIndex
);
if
(
m_commonBoundaries
&&
minX_val
>
X
.
back
()
)
{
g_log
.
error
(
"XMin is greater than the largest X value"
);
throw
std
::
out_of_range
(
"XMin is greater than the largest X value"
);
}
xIndex
=
std
::
lower_bound
(
X
.
begin
(),
X
.
end
(),
minX_val
)
-
X
.
begin
();
}
return
xIndex
;
}
/** Find the X index corresponding to (or just within) the value given in the XMax property.
* Sets the default if the property has not been set.
* @param wsIndex The workspace index to check (default 0).
* @return The X index corresponding to the XMax value.
*/
int
CropWorkspace
::
getXMax
(
const
int
wsIndex
)
{
const
MantidVec
&
X
=
m_inputWorkspace
->
readX
(
wsIndex
);
int
xIndex
=
X
.
size
();
//get the value that the user entered if they entered one at all
const
double
maxX_val
=
getProperty
(
"XMax"
);
if
(
!
isEmpty
(
maxX_val
)
)
{
//we have a user value, check it and maybe store it
if
(
m_commonBoundaries
&&
maxX_val
<
X
.
front
()
)
{
g_log
.
error
(
"XMax is less than the smallest X value"
);
throw
std
::
out_of_range
(
"XMax is less than the smallest X value"
);
}
xIndex
=
std
::
upper_bound
(
X
.
begin
(),
X
.
end
(),
maxX_val
)
-
X
.
begin
();
}
return
xIndex
;
}
/** Zeroes all data points outside the X values given
* @param outputWorkspace The output workspace - data has already been copied
* @param inIndex The workspace index of the spectrum in the input workspace
* @param outIndex The workspace index of the spectrum in the output workspace
*/
void
CropWorkspace
::
cropRagged
(
API
::
MatrixWorkspace_sptr
outputWorkspace
,
int
inIndex
,
int
outIndex
)
{
MantidVec
&
Y
=
outputWorkspace
->
dataY
(
outIndex
);
MantidVec
&
E
=
outputWorkspace
->
dataE
(
outIndex
);
const
int
size
=
Y
.
size
();
int
startX
=
this
->
getXMin
(
inIndex
);
if
(
startX
>
size
)
startX
=
size
;