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
5e8c6cdb
Commit
5e8c6cdb
authored
Feb 16, 2016
by
Tom Perkins
Browse files
Refactor some in-and-out functions in Kernel
re #15286
parent
b32622af
Changes
11
Hide whitespace changes
Inline
Side-by-side
Framework/Crystal/src/FindClusterFaces.cpp
View file @
5e8c6cdb
...
...
@@ -115,9 +115,8 @@ void findFacesAtIndex(const size_t linearIndex, IMDIterator *mdIterator,
const
int
&
emptyLabelId
,
const
std
::
vector
<
size_t
>
&
imageShape
,
ClusterFaces
&
localClusterFaces
)
{
std
::
vector
<
size_t
>
indexes
;
Mantid
::
Kernel
::
Utils
::
getIndicesFromLinearIndex
(
linearIndex
,
imageShape
,
indexes
);
auto
indexes
=
Mantid
::
Kernel
::
Utils
::
getIndicesFromLinearIndex
(
linearIndex
,
imageShape
);
const
auto
neighbours
=
mdIterator
->
findNeighbourIndexesFaceTouching
();
for
(
auto
neighbourLinearIndex
:
neighbours
)
{
...
...
@@ -128,9 +127,8 @@ void findFacesAtIndex(const size_t linearIndex, IMDIterator *mdIterator,
// We have an edge!
// In which dimension is the edge?
std
::
vector
<
size_t
>
neighbourIndexes
;
Mantid
::
Kernel
::
Utils
::
getIndicesFromLinearIndex
(
neighbourLinearIndex
,
imageShape
,
neighbourIndexes
);
auto
neighbourIndexes
=
Mantid
::
Kernel
::
Utils
::
getIndicesFromLinearIndex
(
neighbourLinearIndex
,
imageShape
);
for
(
size_t
j
=
0
;
j
<
imageShape
.
size
();
++
j
)
{
if
(
indexes
[
j
]
!=
neighbourIndexes
[
j
])
{
const
bool
maxEdge
=
neighbourLinearIndex
>
linearIndex
;
...
...
Framework/DataHandling/src/FilterEventsByLogValuePreNexus.cpp
View file @
5e8c6cdb
...
...
@@ -2339,7 +2339,6 @@ void FilterEventsByLogValuePreNexus::setProtonCharge(
*/
void
FilterEventsByLogValuePreNexus
::
loadPixelMap
(
const
std
::
string
&
filename
)
{
this
->
m_usingMappingFile
=
false
;
this
->
m_pixelmap
.
clear
();
// check that there is a mapping file
if
(
filename
.
empty
())
{
...
...
@@ -2355,7 +2354,7 @@ void FilterEventsByLogValuePreNexus::loadPixelMap(const std::string &filename) {
BinaryFile
<
PixelType
>
pixelmapFile
(
filename
);
PixelType
max_pid
=
static_cast
<
PixelType
>
(
pixelmapFile
.
getNumElements
());
// Load all the data
pixelmapFile
.
loadAllInto
(
this
->
m_pixelmap
);
this
->
m_pixelmap
=
pixelmapFile
.
loadAllInto
Vector
(
);
// Check for funky file
if
(
std
::
find_if
(
m_pixelmap
.
begin
(),
m_pixelmap
.
end
(),
...
...
Framework/DataHandling/src/LoadEventPreNexus.cpp
View file @
5e8c6cdb
...
...
@@ -841,7 +841,6 @@ void LoadEventPreNexus::setProtonCharge(
*/
void
LoadEventPreNexus
::
loadPixelMap
(
const
std
::
string
&
filename
)
{
this
->
using_mapping_file
=
false
;
this
->
pixelmap
.
clear
();
// check that there is a mapping file
if
(
filename
.
empty
())
{
...
...
@@ -856,7 +855,7 @@ void LoadEventPreNexus::loadPixelMap(const std::string &filename) {
BinaryFile
<
PixelType
>
pixelmapFile
(
filename
);
PixelType
max_pid
=
static_cast
<
PixelType
>
(
pixelmapFile
.
getNumElements
());
// Load all the data
pixelmapFile
.
loadAllInto
(
this
->
pixelmap
);
this
->
pixelmap
=
pixelmapFile
.
loadAllInto
Vector
(
);
// Check for funky file
if
(
std
::
find_if
(
pixelmap
.
begin
(),
pixelmap
.
end
(),
...
...
Framework/DataHandling/src/LoadEventPreNexus2.cpp
View file @
5e8c6cdb
...
...
@@ -1248,7 +1248,6 @@ void LoadEventPreNexus2::setProtonCharge(
*/
void
LoadEventPreNexus2
::
loadPixelMap
(
const
std
::
string
&
filename
)
{
this
->
using_mapping_file
=
false
;
this
->
pixelmap
.
clear
();
// check that there is a mapping file
if
(
filename
.
empty
())
{
...
...
@@ -1263,7 +1262,7 @@ void LoadEventPreNexus2::loadPixelMap(const std::string &filename) {
BinaryFile
<
PixelType
>
pixelmapFile
(
filename
);
PixelType
max_pid
=
static_cast
<
PixelType
>
(
pixelmapFile
.
getNumElements
());
// Load all the data
pixelmapFile
.
loadAllInto
(
this
->
pixelmap
);
this
->
pixelmap
=
pixelmapFile
.
loadAllInto
Vector
(
);
// Check for funky file
if
(
std
::
find_if
(
pixelmap
.
begin
(),
pixelmap
.
end
(),
...
...
Framework/DataHandling/src/LoadPreNexusMonitors.cpp
View file @
5e8c6cdb
...
...
@@ -177,9 +177,6 @@ void LoadPreNexusMonitors::exec() {
MatrixWorkspace_sptr
localWorkspace
=
WorkspaceFactory
::
Instance
().
create
(
"Workspace2D"
,
nMonitors
,
numberTimeBins
,
tchannels
);
// temp buffer for file reading
std
::
vector
<
uint32_t
>
buffer
;
for
(
int
i
=
0
;
i
<
nMonitors
;
i
++
)
{
// Now lets actually read the monitor files..
Poco
::
Path
pMonitorFilename
(
dirPath
,
monitorFilenames
[
i
]);
...
...
@@ -188,7 +185,8 @@ void LoadPreNexusMonitors::exec() {
<<
std
::
endl
;
Kernel
::
BinaryFile
<
uint32_t
>
monitorFile
(
pMonitorFilename
.
toString
());
monitorFile
.
loadAllInto
(
buffer
);
// temp buffer for file reading
std
::
vector
<
uint32_t
>
buffer
=
monitorFile
.
loadAllIntoVector
();
MantidVec
intensity
(
buffer
.
begin
(),
buffer
.
end
());
// Copy the same data into the error array
...
...
Framework/DataObjects/src/FakeMD.cpp
View file @
5e8c6cdb
...
...
@@ -331,12 +331,12 @@ void FakeMD::addFakeRegularData(const std::vector<double> ¶ms,
gridSize
*=
indexMax
[
d
];
}
// Create all the requested events
std
::
vector
<
size_t
>
indexes
;
size_t
cellCount
(
0
);
for
(
size_t
i
=
0
;
i
<
num
;
++
i
)
{
coord_t
centers
[
nd
];
Kernel
::
Utils
::
getIndicesFromLinearIndex
(
cellCount
,
indexMax
,
indexes
);
auto
indexes
=
Kernel
::
Utils
::
getIndicesFromLinearIndex
(
cellCount
,
indexMax
);
++
cellCount
;
if
(
cellCount
>=
gridSize
)
cellCount
=
0
;
...
...
Framework/Kernel/inc/MantidKernel/BinaryFile.h
View file @
5e8c6cdb
...
...
@@ -140,14 +140,13 @@ public:
* Loads the entire contents of the file into a std::vector.
* The file is closed once done.
* @param data :: The contents to load into the file
* @returns :: vector with contents of the file
*/
void
loadAllInto
(
std
::
vector
<
T
>
&
data
)
{
std
::
vector
<
T
>
loadAllIntoVector
(
)
{
if
(
!
handle
)
{
throw
std
::
runtime_error
(
"BinaryFile: file is not open."
);
}
// Clear the vector
data
.
clear
();
std
::
vector
<
T
>
data
;
// A buffer to load from
size_t
buffer_size
=
getBufferSize
(
num_elements
);
...
...
@@ -169,6 +168,8 @@ public:
this
->
close
();
// Free memory
delete
[]
buffer
;
return
data
;
}
//-----------------------------------------------------------------------------
...
...
Framework/Kernel/inc/MantidKernel/Utils.h
View file @
5e8c6cdb
...
...
@@ -254,21 +254,20 @@ inline void getIndicesFromLinearIndex(const size_t linear_index,
* @param num_bins :: a vector of [numDims] size, where numDims is the loop
*depth and each element equal to number of bins in the correspondent dimension
*
* @
param[out] out_indice
s ::
the
vector, sized numDims, which will be
* @
return
s ::
a
vector, sized numDims, which will be
* filled with the index for each dimension, given the linear index
*/
inline
void
getIndicesFromLinearIndex
(
const
size_t
linear_index
,
const
std
::
vector
<
size_t
>
&
num_bins
,
std
::
vector
<
size_t
>
&
out_indices
)
{
if
(
num_bins
.
empty
())
{
out_indices
.
clear
();
return
;
}
else
{
inline
std
::
vector
<
size_t
>
getIndicesFromLinearIndex
(
const
size_t
linear_index
,
const
std
::
vector
<
size_t
>
&
num_bins
)
{
std
::
vector
<
size_t
>
out_indices
;
if
(
!
num_bins
.
empty
())
{
size_t
nBins
=
num_bins
.
size
();
out_indices
.
resize
(
nBins
);
getIndicesFromLinearIndex
(
linear_index
,
&
num_bins
[
0
],
nBins
,
&
out_indices
[
0
]);
}
return
out_indices
;
}
/**
...
...
Framework/Kernel/test/BinaryFileTest.h
View file @
5e8c6cdb
...
...
@@ -94,7 +94,7 @@ public:
Poco
::
File
(
dummy_file
).
remove
();
}
void
testLoadAllInto
()
{
void
testLoadAllInto
Vector
()
{
MakeDummyFile
(
dummy_file
,
20
*
8
);
file
.
open
(
dummy_file
);
...
...
@@ -103,7 +103,7 @@ public:
TS_ASSERT_EQUALS
(
file
.
getNumElements
(),
num
);
// Get it
std
::
vector
<
DasEvent
>
data
;
TS_ASSERT_THROWS_NOTHING
(
file
.
loadAllInto
(
data
));
TS_ASSERT_THROWS_NOTHING
(
data
=
file
.
loadAllInto
Vector
(
));
TS_ASSERT_EQUALS
(
data
.
size
(),
num
);
// Check the first event
TS_ASSERT_EQUALS
(
data
.
at
(
0
).
tof
,
0
);
...
...
@@ -187,7 +187,7 @@ public:
DasEvent
*
buffer
=
NULL
;
TS_ASSERT_EQUALS
(
file2
.
getNumElements
(),
0
);
TS_ASSERT_THROWS
(
file2
.
loadAll
(),
std
::
runtime_error
);
TS_ASSERT_THROWS
(
file2
.
loadAllInto
(
data
),
std
::
runtime_error
);
TS_ASSERT_THROWS
(
data
=
file2
.
loadAllInto
Vector
(
),
std
::
runtime_error
);
TS_ASSERT_THROWS
(
file2
.
loadBlock
(
buffer
,
10
),
std
::
runtime_error
);
}
};
...
...
Framework/Kernel/test/UtilsTest.h
View file @
5e8c6cdb
...
...
@@ -150,13 +150,12 @@ public:
numBins
[
1
]
=
20
;
numBins
[
2
]
=
5
;
std
::
vector
<
size_t
>
indexes
;
size_t
ic
(
0
);
for
(
size_t
k
=
0
;
k
<
numBins
[
2
];
k
++
)
{
for
(
size_t
j
=
0
;
j
<
numBins
[
1
];
j
++
)
{
for
(
size_t
i
=
0
;
i
<
numBins
[
0
];
i
++
)
{
Utils
::
getIndicesFromLinearIndex
(
ic
,
numBins
,
indexes
);
auto
indexes
=
Utils
::
getIndicesFromLinearIndex
(
ic
,
numBins
);
ic
++
;
TS_ASSERT_EQUALS
(
indexes
[
0
],
i
);
...
...
@@ -172,13 +171,12 @@ public:
numBins
[
1
]
=
1
;
// there can not be 0, shluld be at least 1
numBins
[
2
]
=
5
;
std
::
vector
<
size_t
>
indexes
;
size_t
ic
(
0
);
for
(
size_t
k
=
0
;
k
<
numBins
[
2
];
k
++
)
{
for
(
size_t
j
=
0
;
j
<
numBins
[
1
];
j
++
)
{
for
(
size_t
i
=
0
;
i
<
numBins
[
0
];
i
++
)
{
Utils
::
getIndicesFromLinearIndex
(
ic
,
numBins
,
indexes
);
auto
indexes
=
Utils
::
getIndicesFromLinearIndex
(
ic
,
numBins
);
ic
++
;
TS_ASSERT_EQUALS
(
indexes
[
0
],
i
);
...
...
Framework/MDAlgorithms/test/BinMDTest.h
View file @
5e8c6cdb
...
...
@@ -313,13 +313,13 @@ public:
TS_ASSERT_EQUALS
(
out
->
getNEvents
(),
1000
);
double
expected_signal
(
2.
);
std
::
vector
<
size_t
>
nBins
(
3
)
,
indexes
(
3
)
;
std
::
vector
<
size_t
>
nBins
(
3
);
nBins
[
0
]
=
40
;
nBins
[
1
]
=
5
;
nBins
[
2
]
=
20
;
for
(
size_t
i
=
0
;
i
<
out
->
getNPoints
();
i
++
)
{
Utils
::
getIndicesFromLinearIndex
(
i
,
nBins
,
indexes
);
auto
indexes
=
Utils
::
getIndicesFromLinearIndex
(
i
,
nBins
);
if
(
etta
(
int
(
indexes
[
0
]),
4
)
&&
etta
(
int
(
indexes
[
2
]),
2
))
{
TS_ASSERT_DELTA
(
out
->
getSignalAt
(
i
),
expected_signal
,
1e-5
);
TS_ASSERT_DELTA
(
out
->
getNumEventsAt
(
i
),
expected_signal
,
1e-5
);
...
...
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