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
c6794b3f
Commit
c6794b3f
authored
9 years ago
by
Owen Arnold
Browse files
Options
Downloads
Patches
Plain Diff
refs #13989. Test Nexus loading.
parent
ea8ef80f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
MantidQt/CustomInterfaces/src/ReflNexusMeasurementSource.cpp
+57
-32
57 additions, 32 deletions
MantidQt/CustomInterfaces/src/ReflNexusMeasurementSource.cpp
MantidQt/CustomInterfaces/test/ReflNexusMeasurementSourceTest.h
+19
-8
19 additions, 8 deletions
...Qt/CustomInterfaces/test/ReflNexusMeasurementSourceTest.h
with
76 additions
and
40 deletions
MantidQt/CustomInterfaces/src/ReflNexusMeasurementSource.cpp
+
57
−
32
View file @
c6794b3f
#include
"MantidQtCustomInterfaces/ReflNexusMeasurementSource.h"
#include
<Poco/File.h>
#include
"MantidAPI/AlgorithmManager.h"
#include
"MantidAPI/Workspace.h"
#include
"MantidAPI/MatrixWorkspace.h"
#include
"MantidKernel/TimeSeriesProperty.h"
#include
<iostream>
#include
<string>
#include
<sstream>
using
namespace
Mantid
::
API
;
using
namespace
Mantid
::
Kernel
;
namespace
MantidQt
{
namespace
MantidQt
{
namespace
CustomInterfaces
{
//----------------------------------------------------------------------------------------------
...
...
@@ -24,19 +25,20 @@ ReflNexusMeasurementSource::ReflNexusMeasurementSource() {}
*/
ReflNexusMeasurementSource
::~
ReflNexusMeasurementSource
()
{}
Measurement
ReflNexusMeasurementSource
::
obtain
(
const
std
::
string
&
definedPath
,
const
std
::
string
&
fuzzyName
)
const
{
std
::
string
filenameArg
=
fuzzyName
;
if
(
!
definedPath
.
empty
())
{
Measurement
ReflNexusMeasurementSource
::
obtain
(
const
std
::
string
&
definedPath
,
const
std
::
string
&
fuzzyName
)
const
{
std
::
string
filenameArg
=
fuzzyName
;
if
(
!
definedPath
.
empty
())
{
Poco
::
File
file
(
definedPath
);
if
(
file
.
exists
()
&&
file
.
isFile
()){
// Load the exact path
filenameArg
=
definedPath
;
}
}
try
{
const
std
::
string
filenameArg
=
fuzzyName
;
IAlgorithm_sptr
algLoadRun
=
AlgorithmManager
::
Instance
().
create
(
"LoadISISNexus"
);
if
(
file
.
exists
()
&&
file
.
isFile
())
{
// Load the exact path
filenameArg
=
definedPath
;
}
}
try
{
IAlgorithm_sptr
algLoadRun
=
AlgorithmManager
::
Instance
().
create
(
"LoadISISNexus"
);
algLoadRun
->
setChild
(
true
);
algLoadRun
->
setRethrows
(
true
);
algLoadRun
->
initialize
();
...
...
@@ -44,29 +46,52 @@ Measurement ReflNexusMeasurementSource::obtain(const std::string &definedPath, c
algLoadRun
->
setPropertyValue
(
"OutputWorkspace"
,
"dummy"
);
algLoadRun
->
execute
();
Workspace_sptr
temp
=
algLoadRun
->
getProperty
(
"OutputWorkspace"
);
MatrixWorkspace_sptr
outWS
=
boost
::
dynamic_pointer_cast
<
MatrixWorkspace
>
(
temp
);
return
Measurement
::
InvalidMeasurement
(
"Not yet implemented"
);
MatrixWorkspace_sptr
outWS
=
boost
::
dynamic_pointer_cast
<
MatrixWorkspace
>
(
temp
);
if
(
outWS
.
get
()
==
NULL
)
{
WorkspaceGroup_sptr
tempGroup
=
boost
::
dynamic_pointer_cast
<
WorkspaceGroup
>
(
temp
);
outWS
=
boost
::
dynamic_pointer_cast
<
MatrixWorkspace
>
(
tempGroup
->
getItem
(
0
));
}
catch
(
std
::
runtime_error
&
ex
){
std
::
stringstream
buffer
;
buffer
<<
"Meta-data load attemped a load using: "
<<
filenameArg
<<
std
::
endl
;
buffer
<<
ex
.
what
();
const
std
::
string
message
=
buffer
.
str
();
return
Measurement
::
InvalidMeasurement
(
message
);
auto
run
=
outWS
->
run
();
const
std
::
string
measurementId
=
run
.
getPropertyValueAsType
<
std
::
string
>
(
"measurement_id"
);
const
std
::
string
measurementSubId
=
run
.
getPropertyValueAsType
<
std
::
string
>
(
"measurement_subid"
);
const
std
::
string
measurementLabel
=
run
.
getPropertyValueAsType
<
std
::
string
>
(
"measurement_label"
);
const
std
::
string
measurementType
=
run
.
getPropertyValueAsType
<
std
::
string
>
(
"measurement_type"
);
const
std
::
string
runNumber
=
run
.
getPropertyValueAsType
<
std
::
string
>
(
"run_number"
);
double
theta
=
-
1.0
;
try
{
Property
*
prop
=
run
.
getProperty
(
"stheta"
);
if
(
TimeSeriesProperty
<
double
>
*
tsp
=
dynamic_cast
<
TimeSeriesProperty
<
double
>
*>
(
prop
))
{
theta
=
tsp
->
valuesAsVector
().
back
();
}
}
catch
(
Exception
::
NotFoundError
&
)
{
}
return
Measurement
(
measurementId
,
measurementSubId
,
measurementLabel
,
measurementType
,
theta
,
runNumber
);
}
catch
(
std
::
runtime_error
&
ex
)
{
std
::
stringstream
buffer
;
buffer
<<
"Meta-data load attemped a load using: "
<<
filenameArg
<<
std
::
endl
;
buffer
<<
ex
.
what
();
const
std
::
string
message
=
buffer
.
str
();
return
Measurement
::
InvalidMeasurement
(
message
);
}
}
ReflNexusMeasurementSource
*
ReflNexusMeasurementSource
::
clone
()
const
{
return
new
ReflNexusMeasurementSource
(
*
this
);
ReflNexusMeasurementSource
*
ReflNexusMeasurementSource
::
clone
()
const
{
return
new
ReflNexusMeasurementSource
(
*
this
);
}
}
// namespace CustomInterfaces
}
// namespace MantidQt
This diff is collapsed.
Click to expand it.
MantidQt/CustomInterfaces/test/ReflNexusMeasurementSourceTest.h
+
19
−
8
View file @
c6794b3f
...
...
@@ -15,26 +15,37 @@ public:
static
ReflNexusMeasurementSourceTest
*
createSuite
()
{
return
new
ReflNexusMeasurementSourceTest
();
}
static
void
destroySuite
(
ReflNexusMeasurementSourceTest
*
suite
)
{
delete
suite
;
}
void
x
test_obatin_via_full_path
(){
void
test_obatin_via_full_path
()
{
std
::
string
path
=
Mantid
::
API
::
FileFinder
::
Instance
().
getFullPath
(
"POLREF14966"
);
std
::
string
path
=
Mantid
::
API
::
FileFinder
::
Instance
().
findRun
(
"POLREF14966"
);
Poco
::
File
file
(
path
);
TSM_ASSERT
(
"Test setup incorrect"
,
!
path
.
empty
()
&&
file
.
exists
());
ReflNexusMeasurementSource
source
;
Measurement
measurement
=
source
.
obtain
(
path
,
"made_up"
);
TS_ASSERT
(
measurement
.
isUseable
());
TS_ASSERT
(
measurement
.
isUseable
());
TS_ASSERT_EQUALS
(
"34"
,
measurement
.
id
());
TS_ASSERT_EQUALS
(
"0"
,
measurement
.
subId
());
TS_ASSERT_EQUALS
(
"14966"
,
measurement
.
run
());
TS_ASSERT_EQUALS
(
""
,
measurement
.
label
());
TS_ASSERT_EQUALS
(
""
,
measurement
.
label
());
}
void
test_obtain_via_fuzzy_path
()
{
//ReflNexusMeasurementSource source;
//Measurement measurement = source.obtain("made_up", "POLREF14966");
ReflNexusMeasurementSource
source
;
Measurement
measurement
=
source
.
obtain
(
"made_up"
,
"POLREF14966"
);
TS_ASSERT
(
measurement
.
isUseable
());
TS_ASSERT_EQUALS
(
"34"
,
measurement
.
id
());
TS_ASSERT_EQUALS
(
"0"
,
measurement
.
subId
());
TS_ASSERT_EQUALS
(
"14966"
,
measurement
.
run
());
TS_ASSERT_EQUALS
(
""
,
measurement
.
label
());
TS_ASSERT_EQUALS
(
""
,
measurement
.
label
());
}
};
...
...
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