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
cee29dc7
Commit
cee29dc7
authored
Mar 16, 2015
by
Gigg, Martyn Anthony
Browse files
Load and save coordinate field in PeaksWorkspace.
It is still backwards compatible with the old log-entry format. Refs #11359
parent
c97d33c7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Code/Mantid/Framework/DataHandling/src/LoadNexusProcessed.cpp
View file @
cee29dc7
...
...
@@ -37,6 +37,8 @@
#include
"MantidDataObjects/PeakShapeSphericalFactory.h"
#include
"MantidDataObjects/PeakShapeEllipsoidFactory.h"
#include
<nexus/NeXusException.hpp>
namespace
Mantid
{
namespace
DataHandling
{
...
...
@@ -714,7 +716,8 @@ LoadNexusProcessed::loadEventEntry(NXData &wksp_cls, NXDouble &xbins,
boost
::
shared_array
<
int64_t
>
indices
=
indices_data
.
sharedBuffer
();
// Create all the event lists
PARALLEL_FOR_NO_WSP_CHECK
()
for
(
int64_t
j
=
0
;
j
<
static_cast
<
int64_t
>
(
m_filtered_spec_idxs
.
size
());
j
++
)
{
for
(
int64_t
j
=
0
;
j
<
static_cast
<
int64_t
>
(
m_filtered_spec_idxs
.
size
());
j
++
)
{
PARALLEL_START_INTERUPT_REGION
size_t
wi
=
m_filtered_spec_idxs
[
j
]
-
1
;
int64_t
index_start
=
indices
[
wi
];
...
...
@@ -754,8 +757,8 @@ LoadNexusProcessed::loadEventEntry(NXData &wksp_cls, NXDouble &xbins,
}
}
progress
(
progressStart
+
progressRange
*
(
1.0
/
static_cast
<
double
>
(
numspec
)));
progress
(
progressStart
+
progressRange
*
(
1.0
/
static_cast
<
double
>
(
numspec
)));
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
...
...
@@ -1005,8 +1008,8 @@ API::Workspace_sptr LoadNexusProcessed::loadPeaksEntry(NXEntry &entry) {
// Get information from all but data group
std
::
string
parameterStr
;
// Hop to the right point
m_cppFile
->
openPath
(
entry
.
path
());
// Hop to the right point
/mantid_workspace_1
m_cppFile
->
openPath
(
entry
.
path
());
// This is
try
{
// This loads logs, sample, and instrument.
peakWS
->
loadExperimentInfoNexus
(
m_cppFile
,
parameterStr
);
...
...
@@ -1015,7 +1018,30 @@ API::Workspace_sptr LoadNexusProcessed::loadPeaksEntry(NXEntry &entry) {
g_log
.
information
(
e
.
what
());
}
// std::vector<API::IPeak*> p;
// Coordinates - Older versions did not have the separate field but used a log
// value
uint32_t
loadCoord
(
0
);
m_cppFile
->
openGroup
(
"peaks_workspace"
,
"NXentry"
);
try
{
m_cppFile
->
readData
(
"coordinate_system"
,
loadCoord
);
peakWS
->
setCoordinateSystem
(
static_cast
<
Kernel
::
SpecialCoordinateSystem
>
(
loadCoord
));
}
catch
(
::
NeXus
::
Exception
&
)
{
// Check for a log value
auto
logs
=
peakWS
->
logs
();
if
(
logs
->
hasProperty
(
"CoordinateSystem"
))
{
auto
*
prop
=
dynamic_cast
<
PropertyWithValue
<
int
>
*>
(
logs
->
getProperty
(
"CoordinateSystem"
));
if
(
prop
)
{
int
value
((
*
prop
)());
peakWS
->
setCoordinateSystem
(
static_cast
<
Kernel
::
SpecialCoordinateSystem
>
(
value
));
}
}
}
// peaks_workspace
m_cppFile
->
closeGroup
();
for
(
int
r
=
0
;
r
<
numberPeaks
;
r
++
)
{
Kernel
::
V3D
v3d
;
v3d
[
2
]
=
1.0
;
...
...
@@ -1137,9 +1163,12 @@ API::Workspace_sptr LoadNexusProcessed::loadPeaksEntry(NXEntry &entry) {
// Read shape information
using
namespace
Mantid
::
DataObjects
;
PeakShapeFactory_sptr
peakFactoryEllipsoid
=
boost
::
make_shared
<
PeakShapeEllipsoidFactory
>
();
PeakShapeFactory_sptr
peakFactorySphere
=
boost
::
make_shared
<
PeakShapeSphericalFactory
>
();
PeakShapeFactory_sptr
peakFactoryNone
=
boost
::
make_shared
<
PeakNoShapeFactory
>
();
PeakShapeFactory_sptr
peakFactoryEllipsoid
=
boost
::
make_shared
<
PeakShapeEllipsoidFactory
>
();
PeakShapeFactory_sptr
peakFactorySphere
=
boost
::
make_shared
<
PeakShapeSphericalFactory
>
();
PeakShapeFactory_sptr
peakFactoryNone
=
boost
::
make_shared
<
PeakNoShapeFactory
>
();
peakFactoryEllipsoid
->
setSuccessor
(
peakFactorySphere
);
peakFactorySphere
->
setSuccessor
(
peakFactoryNone
);
...
...
@@ -1157,16 +1186,16 @@ API::Workspace_sptr LoadNexusProcessed::loadPeaksEntry(NXEntry &entry) {
boost
::
trim_right
(
shapeJSON
);
// Make the shape
Mantid
::
Geometry
::
PeakShape
*
peakShape
=
peakFactoryEllipsoid
->
create
(
shapeJSON
);
Mantid
::
Geometry
::
PeakShape
*
peakShape
=
peakFactoryEllipsoid
->
create
(
shapeJSON
);
// Set the shape
peakWS
->
getPeak
(
i
).
setPeakShape
(
peakShape
);
}
}
}
return
boost
::
static_pointer_cast
<
API
::
Workspace
>
(
peakWS
);
return
boost
::
static_pointer_cast
<
API
::
Workspace
>
(
peakWS
);
}
//-------------------------------------------------------------------------------------------------
...
...
@@ -1179,18 +1208,15 @@ return boost::static_pointer_cast<API::Workspace>(peakWS);
* @param progressRange progress made after loading an entry
* @param mtd_entry Nexus entry for "mantid_workspace_..."
* @param xlength bins in the "X" axis (xbins)
* @param workspaceType Takes values like "Workspace2D", "RebinnedOutput", etc.
* @param workspaceType Takes values like "Workspace2D", "RebinnedOutput",
*etc.
*
* @return workspace object containing loaded data
*/
API
::
MatrixWorkspace_sptr
LoadNexusProcessed
::
loadNonEventEntry
(
NXData
&
wksp_cls
,
NXDouble
&
xbins
,
const
double
&
progressStart
,
const
double
&
progressRange
,
const
NXEntry
&
mtd_entry
,
const
int
xlength
,
std
::
string
&
workspaceType
)
{
API
::
MatrixWorkspace_sptr
LoadNexusProcessed
::
loadNonEventEntry
(
NXData
&
wksp_cls
,
NXDouble
&
xbins
,
const
double
&
progressStart
,
const
double
&
progressRange
,
const
NXEntry
&
mtd_entry
,
const
int
xlength
,
std
::
string
&
workspaceType
)
{
// Filter the list of spectra to process, applying min/max/list options
NXDataSetTyped
<
double
>
data
=
wksp_cls
.
openDoubleData
();
int64_t
nchannels
=
data
.
dim1
();
...
...
@@ -1212,8 +1238,8 @@ LoadNexusProcessed::loadNonEventEntry(NXData &wksp_cls,
API
::
MatrixWorkspace_sptr
local_workspace
=
boost
::
dynamic_pointer_cast
<
API
::
MatrixWorkspace
>
(
WorkspaceFactory
::
Instance
().
create
(
workspaceType
,
total_specs
,
xlength
,
nchannels
));
WorkspaceFactory
::
Instance
().
create
(
workspaceType
,
total_specs
,
xlength
,
nchannels
));
try
{
local_workspace
->
setTitle
(
mtd_entry
.
getString
(
"title"
));
}
catch
(
std
::
runtime_error
&
)
{
...
...
@@ -1264,16 +1290,16 @@ LoadNexusProcessed::loadNonEventEntry(NXData &wksp_cls,
for
(;
hist_index
<
read_stop
;)
{
progress
(
progressBegin
+
progressScaler
*
static_cast
<
double
>
(
hist_index
)
/
static_cast
<
double
>
(
read_stop
),
progressScaler
*
static_cast
<
double
>
(
hist_index
)
/
static_cast
<
double
>
(
read_stop
),
"Reading workspace data..."
);
loadBlock
(
data
,
errors
,
fracarea
,
hasFracArea
,
blocksize
,
nchannels
,
hist_index
,
wsIndex
,
local_workspace
);
}
int64_t
finalblock
=
m_spec_max
-
1
-
read_stop
;
if
(
finalblock
>
0
)
{
loadBlock
(
data
,
errors
,
fracarea
,
hasFracArea
,
finalblock
,
nchannels
,
hist_index
,
wsIndex
,
local_workspace
);
loadBlock
(
data
,
errors
,
fracarea
,
hasFracArea
,
finalblock
,
nchannels
,
hist_index
,
wsIndex
,
local_workspace
);
}
}
// if spectrum list property is set read each spectrum separately by
...
...
@@ -1283,8 +1309,8 @@ LoadNexusProcessed::loadNonEventEntry(NXData &wksp_cls,
for
(;
itr
!=
m_spec_list
.
end
();
++
itr
)
{
int64_t
specIndex
=
(
*
itr
)
-
1
;
progress
(
progressBegin
+
progressScaler
*
static_cast
<
double
>
(
specIndex
)
/
static_cast
<
double
>
(
m_spec_list
.
size
()),
progressScaler
*
static_cast
<
double
>
(
specIndex
)
/
static_cast
<
double
>
(
m_spec_list
.
size
()),
"Reading workspace data..."
);
loadBlock
(
data
,
errors
,
fracarea
,
hasFracArea
,
static_cast
<
int64_t
>
(
1
),
nchannels
,
specIndex
,
wsIndex
,
...
...
@@ -1294,8 +1320,8 @@ LoadNexusProcessed::loadNonEventEntry(NXData &wksp_cls,
}
else
{
for
(;
hist_index
<
read_stop
;)
{
progress
(
progressBegin
+
progressScaler
*
static_cast
<
double
>
(
hist_index
)
/
static_cast
<
double
>
(
read_stop
),
progressScaler
*
static_cast
<
double
>
(
hist_index
)
/
static_cast
<
double
>
(
read_stop
),
"Reading workspace data..."
);
loadBlock
(
data
,
errors
,
fracarea
,
hasFracArea
,
blocksize
,
nchannels
,
hist_index
,
wsIndex
,
local_workspace
);
...
...
@@ -1322,8 +1348,8 @@ LoadNexusProcessed::loadNonEventEntry(NXData &wksp_cls,
for
(;
hist_index
<
read_stop
;)
{
progress
(
progressBegin
+
progressScaler
*
static_cast
<
double
>
(
hist_index
)
/
static_cast
<
double
>
(
read_stop
),
progressScaler
*
static_cast
<
double
>
(
hist_index
)
/
static_cast
<
double
>
(
read_stop
),
"Reading workspace data..."
);
loadBlock
(
data
,
errors
,
fracarea
,
hasFracArea
,
xbins
,
blocksize
,
nchannels
,
hist_index
,
wsIndex
,
local_workspace
);
...
...
@@ -1340,8 +1366,8 @@ LoadNexusProcessed::loadNonEventEntry(NXData &wksp_cls,
for
(;
itr
!=
m_spec_list
.
end
();
++
itr
)
{
int64_t
specIndex
=
(
*
itr
)
-
1
;
progress
(
progressBegin
+
progressScaler
*
static_cast
<
double
>
(
specIndex
)
/
static_cast
<
double
>
(
read_stop
),
progressScaler
*
static_cast
<
double
>
(
specIndex
)
/
static_cast
<
double
>
(
read_stop
),
"Reading workspace data..."
);
loadBlock
(
data
,
errors
,
fracarea
,
hasFracArea
,
xbins
,
1
,
nchannels
,
specIndex
,
wsIndex
,
local_workspace
);
...
...
@@ -1350,8 +1376,8 @@ LoadNexusProcessed::loadNonEventEntry(NXData &wksp_cls,
}
else
{
for
(;
hist_index
<
read_stop
;)
{
progress
(
progressBegin
+
progressScaler
*
static_cast
<
double
>
(
hist_index
)
/
static_cast
<
double
>
(
read_stop
),
progressScaler
*
static_cast
<
double
>
(
hist_index
)
/
static_cast
<
double
>
(
read_stop
),
"Reading workspace data..."
);
loadBlock
(
data
,
errors
,
fracarea
,
hasFracArea
,
xbins
,
blocksize
,
nchannels
,
hist_index
,
wsIndex
,
local_workspace
);
...
...
@@ -1372,7 +1398,8 @@ LoadNexusProcessed::loadNonEventEntry(NXData &wksp_cls,
*
* @param root :: The opened root node
* @param entry_name :: The entry name
* @param progressStart :: The percentage value to start the progress reporting
* @param progressStart :: The percentage value to start the progress
*reporting
* for this entry
* @param progressRange :: The percentage range that the progress reporting
* should cover
...
...
@@ -1457,7 +1484,8 @@ API::Workspace_sptr LoadNexusProcessed::loadEntry(NXRoot &root,
label
->
setLabel
(
ax
.
attributes
(
"caption"
),
ax
.
attributes
(
"label"
));
}
// If this doesn't throw then it is a numeric access so grab the data so we
// If this doesn't throw then it is a numeric access so grab the data so
// we
// can set it later
axis2
.
load
();
if
(
static_cast
<
size_t
>
(
axis2
.
size
())
==
nspectra
+
1
)
...
...
@@ -1593,7 +1621,8 @@ void LoadNexusProcessed::readInstrumentGroup(
//-------------------------------------------------------------------------------------------------
/**
* Loads the information contained in non-Spectra (ie, Text or Numeric) axis in
* Loads the information contained in non-Spectra (ie, Text or Numeric) axis
* in
* the Nexus
* file into the workspace.
* @param local_workspace :: pointer to workspace object
...
...
@@ -1713,7 +1742,8 @@ void LoadNexusProcessed::getWordsInString(const std::string &words4,
//-------------------------------------------------------------------------------------------------
/**
* Read the bin masking information from the mantid_workspace_i/workspace group.
* Read the bin masking information from the mantid_workspace_i/workspace
* group.
* @param wksp_cls :: The data group
* @param local_workspace :: The workspace to read into
*/
...
...
@@ -1742,7 +1772,8 @@ LoadNexusProcessed::readBinMasking(NXData &wksp_cls,
}
/**
* Perform a call to nxgetslab, via the NexusClasses wrapped methods for a given
* Perform a call to nxgetslab, via the NexusClasses wrapped methods for a
* given
* blocksize. This assumes that the
* xbins have alread been cached
* @param data :: The NXDataSet object of y values
...
...
@@ -1797,7 +1828,8 @@ void LoadNexusProcessed::loadBlock(NXDataSetTyped<double> &data,
}
/**
* Perform a call to nxgetslab, via the NexusClasses wrapped methods for a given
* Perform a call to nxgetslab, via the NexusClasses wrapped methods for a
* given
* blocksize. This assumes that the
* xbins have alread been cached
* @param data :: The NXDataSet object of y values
...
...
@@ -1855,7 +1887,8 @@ void LoadNexusProcessed::loadBlock(NXDataSetTyped<double> &data,
}
/**
* Perform a call to nxgetslab, via the NexusClasses wrapped methods for a given
* Perform a call to nxgetslab, via the NexusClasses wrapped methods for a
* given
* blocksize. The xbins are read along with
* each call to the data/error loading
* @param data :: The NXDataSet object of y values
...
...
@@ -1993,7 +2026,7 @@ LoadNexusProcessed::calculateWorkspaceSize(const std::size_t numberofspectra,
if
(
gen_filtered_list
)
{
m_filtered_spec_idxs
.
resize
(
total_specs
);
size_t
j
=
0
;
for
(
int64_t
si
=
m_spec_min
;
si
<
m_spec_max
;
si
++
,
j
++
)
for
(
int64_t
si
=
m_spec_min
;
si
<
m_spec_max
;
si
++
,
j
++
)
m_filtered_spec_idxs
[
j
]
=
si
;
}
}
else
{
...
...
@@ -2018,8 +2051,7 @@ LoadNexusProcessed::calculateWorkspaceSize(const std::size_t numberofspectra,
// example: min: 2, max: 8, list: 3,4,5,10,12;
// result: 2,3,...,7,8,10,12
m_filtered_spec_idxs
.
insert
(
m_filtered_spec_idxs
.
end
(),
m_spec_list
.
begin
(),
m_spec_list
.
end
());
m_spec_list
.
begin
(),
m_spec_list
.
end
());
}
}
}
else
{
...
...
@@ -2029,8 +2061,8 @@ LoadNexusProcessed::calculateWorkspaceSize(const std::size_t numberofspectra,
if
(
gen_filtered_list
)
{
m_filtered_spec_idxs
.
resize
(
total_specs
,
0
);
for
(
int64_t
j
=
0
;
j
<
total_specs
;
j
++
)
m_filtered_spec_idxs
[
j
]
=
m_spec_min
+
j
;
for
(
int64_t
j
=
0
;
j
<
total_specs
;
j
++
)
m_filtered_spec_idxs
[
j
]
=
m_spec_min
+
j
;
}
}
return
total_specs
;
...
...
Code/Mantid/Framework/DataHandling/test/LoadNexusProcessedTest.h
View file @
cee29dc7
...
...
@@ -2,26 +2,34 @@
#define LOADNEXUSPROCESSEDTEST_H_
#include
"MantidAPI/AlgorithmManager.h"
#include
"MantidAPI/FileFinder.h"
#include
"MantidAPI/AnalysisDataService.h"
#include
"MantidAPI/MatrixWorkspace.h"
#include
"MantidAPI/WorkspaceGroup.h"
#include
"MantidDataHandling/LoadInstrument.h"
#include
"MantidDataObjects/EventWorkspace.h"
#include
"MantidDataObjects/PeakShapeSpherical.h"
#include
"MantidDataObjects/Peak.h"
#include
"MantidDataObjects/PeaksWorkspace.h"
#include
"MantidGeometry/IDTypes.h"
#include
"MantidGeometry/Instrument.h"
#include
"MantidGeometry/Instrument/InstrumentDefinitionParser.h"
#include
"MantidDataHandling/LoadNexusProcessed.h"
#include
"MantidDataHandling/SaveNexusProcessed.h"
#include
"MantidDataHandling/Load.h"
#include
"MantidDataHandling/LoadInstrument.h"
#include
"MantidTestHelpers/WorkspaceCreationHelper.h"
#include
"SaveNexusProcessedTest.h"
#include
<boost/lexical_cast.hpp>
#include
<cxxtest/TestSuite.h>
#include
<iostream>
#include
<hdf5.h>
#include
<Poco/File.h>
#include
<boost/lexical_cast.hpp>
#include
"MantidGeometry/IDTypes.h"
#include
"MantidTestHelpers/WorkspaceCreationHelper.h"
#include
"MantidDataObjects/PeakShapeSpherical.h"
#include
"MantidDataObjects/Peak.h"
#include
"MantidDataObjects/PeaksWorkspace.h"
using
namespace
Mantid
::
Geometry
;
using
namespace
Mantid
::
Kernel
;
using
namespace
Mantid
::
DataObjects
;
using
namespace
Mantid
::
API
;
...
...
@@ -813,9 +821,111 @@ public:
Workspace_sptr
ws
=
loadAlg
.
getProperty
(
"OutputWorkspace"
);
auto
peakWS
=
boost
::
dynamic_pointer_cast
<
Mantid
::
DataObjects
::
PeaksWorkspace
>
(
ws
);
TS_ASSERT
(
peakWS
);
}
void
test_coordinates_saved_and_loaded_on_peaks_workspace
()
{
auto
peaksTestWS
=
WorkspaceCreationHelper
::
createPeaksWorkspace
();
// Loading a peaks workspace without a instrument from an IDF doesn't work ...
const
std
::
string
filename
=
FileFinder
::
Instance
().
getFullPath
(
"IDFs_for_UNIT_TESTING/MINITOPAZ_Definition.xml"
);
InstrumentDefinitionParser
parser
;
parser
.
initialize
(
filename
,
"MINITOPAZ"
,
Strings
::
loadFile
(
filename
));
auto
instrument
=
parser
.
parseXML
(
NULL
);
peaksTestWS
->
populateInstrumentParameters
();
peaksTestWS
->
setInstrument
(
instrument
);
const
SpecialCoordinateSystem
appliedCoordinateSystem
=
QSample
;
peaksTestWS
->
setCoordinateSystem
(
appliedCoordinateSystem
);
SaveNexusProcessed
saveAlg
;
saveAlg
.
setChild
(
true
);
saveAlg
.
initialize
();
saveAlg
.
setProperty
(
"InputWorkspace"
,
peaksTestWS
);
saveAlg
.
setPropertyValue
(
"Filename"
,
"LoadAndSaveNexusProcessedCoordinateSystem.nxs"
);
saveAlg
.
execute
();
std
::
string
filePath
=
saveAlg
.
getPropertyValue
(
"Filename"
);
LoadNexusProcessed
loadAlg
;
loadAlg
.
setChild
(
true
);
loadAlg
.
initialize
();
loadAlg
.
setPropertyValue
(
"Filename"
,
filePath
);
loadAlg
.
setPropertyValue
(
"OutputWorkspace"
,
"__unused"
);
loadAlg
.
execute
();
Mantid
::
API
::
Workspace_sptr
loadedWS
=
loadAlg
.
getProperty
(
"OutputWorkspace"
);
auto
loadedPeaksWS
=
boost
::
dynamic_pointer_cast
<
Mantid
::
API
::
IPeaksWorkspace
>
(
loadedWS
);
Poco
::
File
testFile
(
filePath
);
if
(
testFile
.
exists
())
{
testFile
.
remove
();
}
TS_ASSERT_EQUALS
(
appliedCoordinateSystem
,
loadedPeaksWS
->
getSpecialCoordinateSystem
());
}
// backwards compatability check
void
test_coordinates_saved_and_loaded_on_peaks_workspace_from_expt_info
()
{
auto
peaksTestWS
=
WorkspaceCreationHelper
::
createPeaksWorkspace
();
// Loading a peaks workspace without a instrument from an IDF doesn't work ...
const
std
::
string
filename
=
FileFinder
::
Instance
().
getFullPath
(
"IDFs_for_UNIT_TESTING/MINITOPAZ_Definition.xml"
);
InstrumentDefinitionParser
parser
;
parser
.
initialize
(
filename
,
"MINITOPAZ"
,
Strings
::
loadFile
(
filename
));
auto
instrument
=
parser
.
parseXML
(
NULL
);
peaksTestWS
->
populateInstrumentParameters
();
peaksTestWS
->
setInstrument
(
instrument
);
// simulate old-style file with "CoordinateSystem" log
const
SpecialCoordinateSystem
appliedCoordinateSystem
=
QSample
;
peaksTestWS
->
logs
()
->
addProperty
(
"CoordinateSystem"
,
static_cast
<
int
>
(
appliedCoordinateSystem
));
SaveNexusProcessed
saveAlg
;
saveAlg
.
setChild
(
true
);
saveAlg
.
initialize
();
saveAlg
.
setProperty
(
"InputWorkspace"
,
peaksTestWS
);
saveAlg
.
setPropertyValue
(
"Filename"
,
"LoadAndSaveNexusProcessedCoordinateSystemOldFormat.nxs"
);
saveAlg
.
execute
();
std
::
string
filePath
=
saveAlg
.
getPropertyValue
(
"Filename"
);
// Remove the coordinate_system entry so it falls back on the log. NeXus
// can't do this so use the HDF5 API directly
auto
fid
=
H5Fopen
(
filePath
.
c_str
(),
H5F_ACC_RDWR
,
H5P_DEFAULT
);
auto
mantid_id
=
H5Gopen
(
fid
,
"mantid_workspace_1"
,
H5P_DEFAULT
);
auto
peaks_id
=
H5Gopen
(
mantid_id
,
"peaks_workspace"
,
H5P_DEFAULT
);
if
(
peaks_id
>
0
)
{
H5Ldelete
(
peaks_id
,
"coordinate_system"
,
H5P_DEFAULT
);
H5Gclose
(
peaks_id
);
H5Gclose
(
mantid_id
);
}
else
{
TS_FAIL
(
"Cannot unlink coordinate_system group. Test file has unexpected "
"structure."
);
}
H5Fclose
(
fid
);
LoadNexusProcessed
loadAlg
;
loadAlg
.
setChild
(
true
);
loadAlg
.
initialize
();
loadAlg
.
setPropertyValue
(
"Filename"
,
filePath
);
loadAlg
.
setPropertyValue
(
"OutputWorkspace"
,
"__unused"
);
loadAlg
.
execute
();
Mantid
::
API
::
Workspace_sptr
loadedWS
=
loadAlg
.
getProperty
(
"OutputWorkspace"
);
auto
loadedPeaksWS
=
boost
::
dynamic_pointer_cast
<
Mantid
::
API
::
IPeaksWorkspace
>
(
loadedWS
);
Poco
::
File
testFile
(
filePath
);
if
(
testFile
.
exists
())
{
testFile
.
remove
();
}
TS_ASSERT_EQUALS
(
appliedCoordinateSystem
,
loadedPeaksWS
->
getSpecialCoordinateSystem
());
}
void
testTableWorkspace_vectorColumn
()
{
// Create a table we will save
...
...
Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/PeaksWorkspace.h
View file @
cee29dc7
...
...
@@ -273,6 +273,9 @@ private:
/** Column names */
std
::
vector
<
std
::
string
>
columnNames
;
/// Coordinates
Kernel
::
SpecialCoordinateSystem
m_coordSystem
;
// adapter for logs() function, which create reference to this class itself
// and does not allow to delete the shared pointers,
...
...
Code/Mantid/Framework/DataObjects/src/PeaksWorkspace.cpp
View file @
cee29dc7
...
...
@@ -38,15 +38,16 @@ namespace DataObjects {
/// Register the workspace as a type
DECLARE_WORKSPACE
(
PeaksWorkspace
);
// Kernel::Logger& PeaksWorkspace::g_log =
// Kernel::Logger::get("PeaksWorkspace");
//---------------------------------------------------------------------------------------------
/** Constructor. Create a table with all the required columns.
*
* @return PeaksWorkspace object
*/
PeaksWorkspace
::
PeaksWorkspace
()
:
IPeaksWorkspace
()
{
initColumns
();
}
PeaksWorkspace
::
PeaksWorkspace
()
:
IPeaksWorkspace
(),
peaks
(),
columns
(),
columnNames
(),
m_coordSystem
(
None
)
{
initColumns
();
}
//---------------------------------------------------------------------------------------------
/** Virtual constructor. Clone method to duplicate the peaks workspace.
...
...
@@ -65,7 +66,8 @@ PeaksWorkspace *PeaksWorkspace::clone() const {
* @return
*/
PeaksWorkspace
::
PeaksWorkspace
(
const
PeaksWorkspace
&
other
)
:
IPeaksWorkspace
(
other
),
peaks
(
other
.
peaks
)
{
:
IPeaksWorkspace
(
other
),
peaks
(
other
.
peaks
),
columns
(),
columnNames
(),
m_coordSystem
(
other
.
m_coordSystem
)
{
initColumns
();
}
...
...
@@ -668,6 +670,9 @@ void PeaksWorkspace::saveNexus(::NeXus::File *file) const {
file
->
makeGroup
(
"peaks_workspace"
,
"NXentry"
,
true
);
// For when peaksWorkspace can be loaded
// Coordinate system
file
->
writeData
(
"coordinate_system"
,
static_cast
<
uint32_t
>
(
m_coordSystem
));
// Detectors column
file
->
writeData
(
"column_1"
,
detectorID
);
file
->
openData
(
"column_1"
);
...
...
@@ -827,25 +832,16 @@ void PeaksWorkspace::saveNexus(::NeXus::File *file) const {
* @param coordinateSystem : Option to set.
*/
void
PeaksWorkspace
::
setCoordinateSystem
(
const
Mantid
::
Kernel
::
SpecialCoordinateSystem
coordinateSystem
)
{
this
->
mutableRun
().
addProperty
(
"CoordinateSystem"
,
(
int
)
coordinateSystem
,
true
);
const
Kernel
::
SpecialCoordinateSystem
coordinateSystem
)
{
m_coordSystem
=
coordinateSystem
;
}
/**
* @return the special Q3D coordinate system.
*/
Mantid
::
Kernel
::
SpecialCoordinateSystem
Kernel
::
SpecialCoordinateSystem
PeaksWorkspace
::
getSpecialCoordinateSystem
()
const
{
Mantid
::
Kernel
::
SpecialCoordinateSystem
result
=
None
;
try
{
Property
*
prop
=
this
->
run
().
getProperty
(
"CoordinateSystem"
);
PropertyWithValue
<
int
>
*
p
=
dynamic_cast
<
PropertyWithValue
<
int
>
*>
(
prop
);
int
temp
=
*
p
;
result
=
(
SpecialCoordinateSystem
)
temp
;
}
catch
(
Mantid
::
Kernel
::
Exception
::
NotFoundError
&
)
{
}
return
result
;
return
m_coordSystem
;
}
// prevent shared pointer from deleting this
...
...
Code/Mantid/Framework/MDAlgorithms/test/LoadMDTest.h
View file @
cee29dc7
...
...
@@ -605,7 +605,7 @@ public:
Mantid
::
API
::
IMDWorkspace_sptr
testSaveAndLoadWorkspace
(
Mantid
::
API
::
IMDWorkspace_sptr
inputWS
,
const
std
::
string
&
rootGroup
,
const
char
*
rootGroup
,
const
bool
rmCoordField
=
false
)
{
const
std
::
string
fileName
=
"SaveMDSpecialCoordinatesTest.nxs"
;
SaveMD
saveAlg
;
...
...
@@ -622,7 +622,7 @@ public:
// can't do this
// so use the HDF5 API directly
auto
fid
=
H5Fopen
(
fileName
.
c_str
(),
H5F_ACC_RDWR
,
H5P_DEFAULT
);
auto
gid
=
H5Gopen
(
fid
,
rootGroup
.
c_str
()
,
H5P_DEFAULT
);
auto
gid
=
H5Gopen
(
fid
,
rootGroup
,
H5P_DEFAULT
);
if
(
gid
>
0
)
{
H5Ldelete
(
gid
,
"coordinate_system"
,
H5P_DEFAULT
);
H5Gclose
(
gid
);
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment