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
369a931b
Commit
369a931b
authored
9 years ago
by
Federico Montesino Pouzols
Browse files
Options
Downloads
Plain Diff
Merge pull request #13088 from mantidproject/12880_CropWorkspace_memory_usage
Nice refactoring and it saves memory.
parents
d52521fa
2fdc0698
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Code/Mantid/Framework/Algorithms/src/ExtractSpectra.cpp
+29
-26
29 additions, 26 deletions
Code/Mantid/Framework/Algorithms/src/ExtractSpectra.cpp
with
29 additions
and
26 deletions
Code/Mantid/Framework/Algorithms/src/ExtractSpectra.cpp
+
29
−
26
View file @
369a931b
...
...
@@ -8,6 +8,7 @@
#include
"MantidKernel/BoundedValidator.h"
#include
"MantidKernel/VectorHelper.h"
#include
<algorithm>
#include
<iostream>
namespace
{
...
...
@@ -202,6 +203,30 @@ void ExtractSpectra::execHistogram() {
setProperty
(
"OutputWorkspace"
,
outputWorkspace
);
}
namespace
{
// anonymous namespace
template
<
class
T
>
struct
eventFilter
{
eventFilter
(
const
double
minValue
,
const
double
maxValue
)
:
minValue
(
minValue
),
maxValue
(
maxValue
)
{}
bool
operator
()(
const
T
&
value
)
{
const
double
tof
=
value
.
tof
();
return
(
tof
<=
maxValue
&&
tof
>=
minValue
);
}
double
minValue
;
double
maxValue
;
};
template
<
class
T
>
void
copyEventsHelper
(
const
std
::
vector
<
T
>
&
inputEvents
,
std
::
vector
<
T
>
&
outputEvents
,
const
double
xmin
,
const
double
xmax
)
{
copy_if
(
inputEvents
.
begin
(),
inputEvents
.
end
(),
std
::
back_inserter
(
outputEvents
),
eventFilter
<
T
>
(
xmin
,
xmax
));
}
}
/** Executes the algorithm
* @throw std::out_of_range If a property is set to an invalid value for the
* input workspace
...
...
@@ -272,45 +297,23 @@ void ExtractSpectra::execEvent() {
switch
(
el
.
getEventType
())
{
case
TOF
:
{
std
::
vector
<
TofEvent
>::
const_iterator
itev
=
el
.
getEvents
().
begin
();
std
::
vector
<
TofEvent
>::
const_iterator
end
=
el
.
getEvents
().
end
();
std
::
vector
<
TofEvent
>
moreevents
;
moreevents
.
reserve
(
el
.
getNumberEvents
());
// assume all will make it
for
(;
itev
!=
end
;
++
itev
)
{
const
double
tof
=
itev
->
tof
();
if
(
tof
<=
maxX_val
&&
tof
>=
minX_val
)
moreevents
.
push_back
(
*
itev
);
}
copyEventsHelper
(
el
.
getEvents
(),
moreevents
,
minX_val
,
maxX_val
);
outEL
+=
moreevents
;
break
;
}
case
WEIGHTED
:
{
std
::
vector
<
WeightedEvent
>::
const_iterator
itev
=
el
.
getWeightedEvents
().
begin
();
std
::
vector
<
WeightedEvent
>::
const_iterator
end
=
el
.
getWeightedEvents
().
end
();
std
::
vector
<
WeightedEvent
>
moreevents
;
moreevents
.
reserve
(
el
.
getNumberEvents
());
// assume all will make it
for
(;
itev
!=
end
;
++
itev
)
{
const
double
tof
=
itev
->
tof
();
if
(
tof
<=
maxX_val
&&
tof
>=
minX_val
)
moreevents
.
push_back
(
*
itev
);
}
copyEventsHelper
(
el
.
getWeightedEvents
(),
moreevents
,
minX_val
,
maxX_val
);
outEL
+=
moreevents
;
break
;
}
case
WEIGHTED_NOTIME
:
{
std
::
vector
<
WeightedEventNoTime
>::
const_iterator
itev
=
el
.
getWeightedEventsNoTime
().
begin
();
std
::
vector
<
WeightedEventNoTime
>::
const_iterator
end
=
el
.
getWeightedEventsNoTime
().
end
();
std
::
vector
<
WeightedEventNoTime
>
moreevents
;
moreevents
.
reserve
(
el
.
getNumberEvents
());
// assume all will make it
for
(;
itev
!=
end
;
++
itev
)
{
const
double
tof
=
itev
->
tof
();
if
(
tof
<=
maxX_val
&&
tof
>=
minX_val
)
moreevents
.
push_back
(
*
itev
);
}
copyEventsHelper
(
el
.
getWeightedEventsNoTime
(),
moreevents
,
minX_val
,
maxX_val
);
outEL
+=
moreevents
;
break
;
}
...
...
@@ -507,4 +510,4 @@ void ExtractSpectra::cropRagged(API::MatrixWorkspace_sptr outputWorkspace,
}
}
// namespace Algorithms
}
// namespace Mantid
\ No newline at end of file
}
// namespace Mantid
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