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
525f0ed7
Commit
525f0ed7
authored
9 years ago
by
Anton Piccardo-Selg
Browse files
Options
Downloads
Patches
Plain Diff
Refs #13872 Refactor mdevent workspaces helpers
parent
8553a2b0
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Framework/TestHelpers/inc/MantidTestHelpers/MDEventsTestHelper.h
+58
-98
58 additions, 98 deletions
...rk/TestHelpers/inc/MantidTestHelpers/MDEventsTestHelper.h
with
58 additions
and
98 deletions
Framework/TestHelpers/inc/MantidTestHelpers/MDEventsTestHelper.h
+
58
−
98
View file @
525f0ed7
...
@@ -18,7 +18,6 @@
...
@@ -18,7 +18,6 @@
#include
"MantidKernel/DateAndTime.h"
#include
"MantidKernel/DateAndTime.h"
#include
"MantidKernel/Utils.h"
#include
"MantidKernel/Utils.h"
namespace
{
namespace
{
template
<
typename
MDE
,
size_t
nd
>
template
<
typename
MDE
,
size_t
nd
>
boost
::
shared_ptr
<
Mantid
::
DataObjects
::
MDEventWorkspace
<
MDE
,
nd
>>
boost
::
shared_ptr
<
Mantid
::
DataObjects
::
MDEventWorkspace
<
MDE
,
nd
>>
...
@@ -28,16 +27,54 @@ createOutputWorkspace(size_t splitInto) {
...
@@ -28,16 +27,54 @@ createOutputWorkspace(size_t splitInto) {
Mantid
::
API
::
BoxController_sptr
bc
=
out
->
getBoxController
();
Mantid
::
API
::
BoxController_sptr
bc
=
out
->
getBoxController
();
bc
->
setSplitThreshold
(
100
);
bc
->
setSplitThreshold
(
100
);
bc
->
setSplitInto
(
splitInto
);
bc
->
setSplitInto
(
splitInto
);
return
out
;
}
}
template
<
typename
MDE
,
size_t
nd
>
template
<
typename
MDE
,
size_t
nd
>
void
processOutputWorkspace
(
void
addMDDimensions
(
boost
::
shared_ptr
<
Mantid
::
DataObjects
::
MDEventWorkspace
<
MDE
,
nd
>>
out
,
boost
::
shared_ptr
<
Mantid
::
DataObjects
::
MDEventWorkspace
<
MDE
,
nd
>>
out
,
size_t
splitInto
,
Mantid
::
coord_t
min
,
Mantid
::
coord_t
max
,
size_t
numEventsPerBox
,
Mantid
::
coord_t
min
,
Mantid
::
coord_t
max
,
std
::
string
axisNameFormat
,
std
::
string
wsName
)
{
std
::
string
axisIdFormat
)
{
// Create dimensions
for
(
size_t
d
=
0
;
d
<
nd
;
d
++
)
{
char
name
[
200
];
sprintf
(
name
,
axisNameFormat
.
c_str
(),
d
);
char
id
[
200
];
sprintf
(
id
,
axisIdFormat
.
c_str
(),
d
);
Mantid
::
Geometry
::
MDHistoDimension_sptr
dim
(
new
Mantid
::
Geometry
::
MDHistoDimension
(
std
::
string
(
name
),
std
::
string
(
id
),
"m"
,
min
,
max
,
10
));
out
->
addDimension
(
dim
);
}
out
->
initialize
();
out
->
initialize
();
}
template
<
typename
MDE
,
size_t
nd
>
void
addMDDimensionsWithFrames
(
boost
::
shared_ptr
<
Mantid
::
DataObjects
::
MDEventWorkspace
<
MDE
,
nd
>>
out
,
Mantid
::
coord_t
min
,
Mantid
::
coord_t
max
,
const
Mantid
::
Geometry
::
MDFrame
&
frame
,
std
::
string
axisNameFormat
,
std
::
string
axisIdFormat
)
{
for
(
size_t
d
=
0
;
d
<
nd
;
d
++
)
{
char
name
[
200
];
sprintf
(
name
,
axisNameFormat
.
c_str
(),
d
);
char
id
[
200
];
sprintf
(
id
,
axisIdFormat
.
c_str
(),
d
);
// Use the same frame for all dimensions
auto
dim
=
boost
::
make_shared
<
MDHistoDimension
>
(
axisNameFormat
,
axisIdFormat
,
frame
,
min
,
max
,
10
);
out
->
addDimension
(
dim
);
}
out
->
initialize
();
}
template
<
typename
MDE
,
size_t
nd
>
void
addData
(
boost
::
shared_ptr
<
Mantid
::
DataObjects
::
MDEventWorkspace
<
MDE
,
nd
>>
out
,
size_t
splitInto
,
Mantid
::
coord_t
min
,
Mantid
::
coord_t
max
,
size_t
numEventsPerBox
,
std
::
string
wsName
)
{
if
(
numEventsPerBox
>
0
)
{
if
(
numEventsPerBox
>
0
)
{
out
->
splitBox
();
out
->
splitBox
();
size_t
index
[
nd
];
size_t
index
[
nd
];
...
@@ -51,8 +88,9 @@ void processOutputWorkspace(
...
@@ -51,8 +88,9 @@ void processOutputWorkspace(
Mantid
::
coord_t
centers
[
nd
];
Mantid
::
coord_t
centers
[
nd
];
for
(
size_t
d
=
0
;
d
<
nd
;
d
++
)
for
(
size_t
d
=
0
;
d
<
nd
;
d
++
)
centers
[
d
]
=
min
+
centers
[
d
]
=
min
+
(
static_cast
<
coord_t
>
(
index
[
d
])
+
0.5
f
)
*
(
max
-
min
)
/
(
static_cast
<
Mantid
::
coord_t
>
(
index
[
d
])
+
0.5
f
)
*
static_cast
<
coord_t
>
(
splitInto
);
(
max
-
min
)
/
static_cast
<
Mantid
::
coord_t
>
(
splitInto
);
out
->
addEvent
(
MDE
(
1.0
,
1.0
,
centers
));
out
->
addEvent
(
MDE
(
1.0
,
1.0
,
centers
));
}
}
...
@@ -61,16 +99,11 @@ void processOutputWorkspace(
...
@@ -61,16 +99,11 @@ void processOutputWorkspace(
}
}
out
->
refreshCache
();
out
->
refreshCache
();
}
}
auto
ei
=
API
::
ExperimentInfo_sptr
(
new
API
::
ExperimentInfo
());
auto
ei
=
Mantid
::
API
::
ExperimentInfo_sptr
(
new
Mantid
::
API
::
ExperimentInfo
());
out
->
addExperimentInfo
(
ei
);
out
->
addExperimentInfo
(
ei
);
// Add to ADS on option
if
(
!
wsName
.
empty
())
Mantid
::
API
::
AnalysisDataService
::
Instance
().
addOrReplace
(
wsName
,
out
);
}
}
}
}
namespace
Mantid
{
namespace
Mantid
{
namespace
DataObjects
{
namespace
DataObjects
{
...
@@ -138,50 +171,14 @@ makeAnyMDEW(size_t splitInto, coord_t min, coord_t max,
...
@@ -138,50 +171,14 @@ makeAnyMDEW(size_t splitInto, coord_t min, coord_t max,
size_t
numEventsPerBox
=
0
,
std
::
string
wsName
=
""
,
size_t
numEventsPerBox
=
0
,
std
::
string
wsName
=
""
,
std
::
string
axisNameFormat
=
"Axis%d"
,
std
::
string
axisNameFormat
=
"Axis%d"
,
std
::
string
axisIdFormat
=
"Axis%d"
)
{
std
::
string
axisIdFormat
=
"Axis%d"
)
{
boost
::
shared_ptr
<
Mantid
::
DataObjects
::
MDEventWorkspace
<
MDE
,
nd
>>
out
(
// Create bare workspace
new
Mantid
::
DataObjects
::
MDEventWorkspace
<
MDE
,
nd
>
());
auto
out
=
createOutputWorkspace
<
MDE
,
nd
>
(
splitInto
);
Mantid
::
API
::
BoxController_sptr
bc
=
out
->
getBoxController
();
bc
->
setSplitThreshold
(
100
);
bc
->
setSplitInto
(
splitInto
);
for
(
size_t
d
=
0
;
d
<
nd
;
d
++
)
{
char
name
[
200
];
sprintf
(
name
,
axisNameFormat
.
c_str
(),
d
);
char
id
[
200
];
sprintf
(
id
,
axisIdFormat
.
c_str
(),
d
);
Mantid
::
Geometry
::
MDHistoDimension_sptr
dim
(
new
Mantid
::
Geometry
::
MDHistoDimension
(
std
::
string
(
name
),
std
::
string
(
id
),
"m"
,
min
,
max
,
10
));
out
->
addDimension
(
dim
);
}
out
->
initialize
();
if
(
numEventsPerBox
>
0
)
{
// Add standard dimensions
out
->
splitBox
();
addMDDimensions
<
MDE
,
nd
>
(
out
,
min
,
max
,
axisNameFormat
,
axisIdFormat
);
size_t
index
[
nd
];
Mantid
::
Kernel
::
Utils
::
NestedForLoop
::
SetUp
(
nd
,
index
);
size_t
index_max
[
nd
];
Mantid
::
Kernel
::
Utils
::
NestedForLoop
::
SetUp
(
nd
,
index_max
,
splitInto
);
bool
allDone
=
false
;
while
(
!
allDone
)
{
for
(
size_t
i
=
0
;
i
<
numEventsPerBox
;
i
++
)
{
// Put an event in the middle of each box
Mantid
::
coord_t
centers
[
nd
];
for
(
size_t
d
=
0
;
d
<
nd
;
d
++
)
centers
[
d
]
=
min
+
(
static_cast
<
coord_t
>
(
index
[
d
])
+
0.5
f
)
*
(
max
-
min
)
/
static_cast
<
coord_t
>
(
splitInto
);
out
->
addEvent
(
MDE
(
1.0
,
1.0
,
centers
));
}
allDone
=
// Add data
Mantid
::
Kernel
::
Utils
::
NestedForLoop
::
Increment
(
nd
,
index
,
index_max
);
addData
<
MDE
,
nd
>
(
out
,
splitInto
,
min
,
max
,
numEventsPerBox
,
wsName
);
}
out
->
refreshCache
();
}
auto
ei
=
API
::
ExperimentInfo_sptr
(
new
API
::
ExperimentInfo
());
out
->
addExperimentInfo
(
ei
);
// Add to ADS on option
// Add to ADS on option
if
(
!
wsName
.
empty
())
if
(
!
wsName
.
empty
())
...
@@ -191,7 +188,7 @@ makeAnyMDEW(size_t splitInto, coord_t min, coord_t max,
...
@@ -191,7 +188,7 @@ makeAnyMDEW(size_t splitInto, coord_t min, coord_t max,
}
}
/** Create a test MDEventWorkspace<nd> . Dimensions are names Axis0, Axis1, etc.
/** Create a test MDEventWorkspace<nd> . Dimensions are names Axis0, Axis1, etc.
* But you can set
the
an MDFrame. For now the same frame
along
all dimensions
* But you can set an MDFrame. For now the same frame
for
all dimensions
* is used.
* is used.
*
*
* @param splitInto :: each dimension will split into this many subgrids
* @param splitInto :: each dimension will split into this many subgrids
...
@@ -214,51 +211,14 @@ makeAnyMDEWWithFrames(size_t splitInto, coord_t min, coord_t max,
...
@@ -214,51 +211,14 @@ makeAnyMDEWWithFrames(size_t splitInto, coord_t min, coord_t max,
size_t
numEventsPerBox
=
0
,
std
::
string
wsName
=
""
,
size_t
numEventsPerBox
=
0
,
std
::
string
wsName
=
""
,
std
::
string
axisNameFormat
=
"Axis%d"
,
std
::
string
axisNameFormat
=
"Axis%d"
,
std
::
string
axisIdFormat
=
"Axis%d"
)
{
std
::
string
axisIdFormat
=
"Axis%d"
)
{
boost
::
shared_ptr
<
Mantid
::
DataObjects
::
MDEventWorkspace
<
MDE
,
nd
>>
out
(
// Create bare workspace
new
Mantid
::
DataObjects
::
MDEventWorkspace
<
MDE
,
nd
>
());
auto
out
=
createOutputWorkspace
<
MDE
,
nd
>
(
splitInto
);
Mantid
::
API
::
BoxController_sptr
bc
=
out
->
getBoxController
();
bc
->
setSplitThreshold
(
100
);
bc
->
setSplitInto
(
splitInto
);
for
(
size_t
d
=
0
;
d
<
nd
;
d
++
)
{
// Add standard dimensions
char
name
[
200
];
addMDDimensionsWithFrames
<
MDE
,
nd
>
(
out
,
min
,
max
,
frame
,
axisNameFormat
,
axisIdFormat
);
sprintf
(
name
,
axisNameFormat
.
c_str
(),
d
);
char
id
[
200
];
sprintf
(
id
,
axisIdFormat
.
c_str
(),
d
);
// Use the same frame for all dimensions
// Add data
auto
dim
=
boost
::
make_shared
<
MDHistoDimension
>
(
"QSampleX"
,
"QSampleX"
,
addData
<
MDE
,
nd
>
(
out
,
splitInto
,
min
,
max
,
numEventsPerBox
,
wsName
);
frame
,
min
,
max
,
10
);
out
->
addDimension
(
dim
);
}
out
->
initialize
();
if
(
numEventsPerBox
>
0
)
{
out
->
splitBox
();
size_t
index
[
nd
];
Mantid
::
Kernel
::
Utils
::
NestedForLoop
::
SetUp
(
nd
,
index
);
size_t
index_max
[
nd
];
Mantid
::
Kernel
::
Utils
::
NestedForLoop
::
SetUp
(
nd
,
index_max
,
splitInto
);
bool
allDone
=
false
;
while
(
!
allDone
)
{
for
(
size_t
i
=
0
;
i
<
numEventsPerBox
;
i
++
)
{
// Put an event in the middle of each box
Mantid
::
coord_t
centers
[
nd
];
for
(
size_t
d
=
0
;
d
<
nd
;
d
++
)
centers
[
d
]
=
min
+
(
static_cast
<
coord_t
>
(
index
[
d
])
+
0.5
f
)
*
(
max
-
min
)
/
static_cast
<
coord_t
>
(
splitInto
);
out
->
addEvent
(
MDE
(
1.0
,
1.0
,
centers
));
}
allDone
=
Mantid
::
Kernel
::
Utils
::
NestedForLoop
::
Increment
(
nd
,
index
,
index_max
);
}
out
->
refreshCache
();
}
auto
ei
=
API
::
ExperimentInfo_sptr
(
new
API
::
ExperimentInfo
());
out
->
addExperimentInfo
(
ei
);
// Add to ADS on option
// Add to ADS on option
if
(
!
wsName
.
empty
())
if
(
!
wsName
.
empty
())
...
...
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