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
1b268b54
Commit
1b268b54
authored
10 years ago
by
Federico Montesino Pouzols
Browse files
Options
Downloads
Patches
Plain Diff
use fstream rather than FILE - so avoid leaks, re #10231
parent
1731035b
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Code/Mantid/Framework/DataHandling/src/LoadFITS.cpp
+14
-19
14 additions, 19 deletions
Code/Mantid/Framework/DataHandling/src/LoadFITS.cpp
Code/Mantid/Framework/DataHandling/test/LoadFITSTest.h
+5
-6
5 additions, 6 deletions
Code/Mantid/Framework/DataHandling/test/LoadFITSTest.h
with
19 additions
and
25 deletions
Code/Mantid/Framework/DataHandling/src/LoadFITS.cpp
+
14
−
19
View file @
1b268b54
#include
"MantidDataHandling/LoadFITS.h"
#include
"MantidAPI/MultipleFileProperty.h"
#include
"MantidAPI/FileProperty.h"
#include
"MantidAPI/RegisterFileLoader.h"
#include
"MantidDataHandling/LoadFITS.h"
#include
"MantidDataObjects/Workspace2D.h"
#include
"MantidKernel/UnitFactory.h"
#include
<boost/algorithm/string.hpp>
#include
<Poco/BinaryReader.h>
#include
<fstream>
#include
<Poco/FileStream.h>
using
namespace
Mantid
::
DataHandling
;
using
namespace
Mantid
::
DataObjects
;
...
...
@@ -479,29 +481,25 @@ void LoadFITS::readDataToWorkspace2D(Workspace2D_sptr ws,
const
FITSInfo
&
fileInfo
,
MantidImage
&
imageY
,
MantidImage
&
imageE
,
std
::
vector
<
char
>
&
buffer
)
{
// create pointer of correct data type to void pointer of the buffer:
uint8_t
*
buffer8
=
reinterpret_cast
<
uint8_t
*>
(
&
buffer
[
0
]);
// Read Data
std
::
string
filename
=
fileInfo
.
filePath
;
FILE
*
currFile
=
fopen
(
filename
.
c_str
(),
"rb"
);
if
(
currFile
==
NULL
)
throw
std
::
runtime_error
(
"Error opening file to read: "
+
filename
);
Poco
::
FileStream
file
(
filename
,
std
::
ios
::
in
);
size_t
bytesRead
=
0
;
size_t
bytespp
=
(
fileInfo
.
bitsPerPixel
/
8
);
size_t
len
=
m_spectraCount
*
bytespp
;
if
(
fseek
(
currFile
,
BASE_HEADER_SIZE
*
fileInfo
.
headerSizeMultiplier
,
SEEK_CUR
)
==
0
)
{
bytesRead
=
fread
(
buffer8
,
1
,
len
,
currFile
);
}
if
(
bytesRead
!=
len
)
{
file
.
seekg
(
BASE_HEADER_SIZE
*
fileInfo
.
headerSizeMultiplier
);
file
.
read
(
&
buffer
[
0
],
len
);
if
(
!
file
)
{
throw
std
::
runtime_error
(
"Error while reading file: "
+
filename
+
". Tried to read "
+
boost
::
lexical_cast
<
std
::
string
>
(
len
)
+
" bytes but got "
+
boost
::
lexical_cast
<
std
::
string
>
(
bytesRead
)
+
boost
::
lexical_cast
<
std
::
string
>
(
file
.
gcount
()
)
+
" bytes. The file and/or its headers may be wrong."
);
}
// all is loaded
file
.
close
();
// create pointer of correct data type to void pointer of the buffer:
uint8_t
*
buffer8
=
reinterpret_cast
<
uint8_t
*>
(
&
buffer
[
0
]);
std
::
vector
<
char
>
buf
(
bytespp
);
char
*
tmp
=
&
buf
.
front
();
...
...
@@ -551,9 +549,6 @@ void LoadFITS::readDataToWorkspace2D(Workspace2D_sptr ws,
// Set in WS
ws
->
setImageYAndE
(
imageY
,
imageE
,
0
,
false
);
// Clear memory associated with the file load
fclose
(
currFile
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
Code/Mantid/Framework/DataHandling/test/LoadFITSTest.h
+
5
−
6
View file @
1b268b54
...
...
@@ -33,12 +33,11 @@ public:
TS_ASSERT
(
a
=
boost
::
make_shared
<
LoadFITS
>
());
// can cast to inherited interfaces and base classes
LoadFITS
alg
;
TS_ASSERT
(
dynamic_cast
<
Mantid
::
DataHandling
::
LoadFITS
*>
(
&
alg
));
TS_ASSERT
(
dynamic_cast
<
Mantid
::
API
::
Algorithm
*>
(
&
alg
));
TS_ASSERT
(
dynamic_cast
<
Mantid
::
Kernel
::
PropertyManagerOwner
*>
(
&
alg
));
TS_ASSERT
(
dynamic_cast
<
Mantid
::
API
::
IAlgorithm
*>
(
&
alg
));
TS_ASSERT
(
dynamic_cast
<
Mantid
::
Kernel
::
IPropertyManager
*>
(
&
alg
));
TS_ASSERT
(
dynamic_cast
<
Mantid
::
DataHandling
::
LoadFITS
*>
(
a
.
get
()));
TS_ASSERT
(
dynamic_cast
<
Mantid
::
API
::
Algorithm
*>
(
a
.
get
()));
TS_ASSERT
(
dynamic_cast
<
Mantid
::
Kernel
::
PropertyManagerOwner
*>
(
a
.
get
()));
TS_ASSERT
(
dynamic_cast
<
Mantid
::
API
::
IAlgorithm
*>
(
a
.
get
()));
TS_ASSERT
(
dynamic_cast
<
Mantid
::
Kernel
::
IPropertyManager
*>
(
a
.
get
()));
}
void
test_initAlgorithm
()
{
...
...
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