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
159f8616
Commit
159f8616
authored
5 years ago
by
Anthony Lim
Browse files
Options
Downloads
Patches
Plain Diff
refs #28155 LoadMuonLogs keeps processing when duplicate is found
parent
80acf94a
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
Framework/DataHandling/inc/MantidDataHandling/LoadMuonLog.h
+5
-1
5 additions, 1 deletion
Framework/DataHandling/inc/MantidDataHandling/LoadMuonLog.h
Framework/DataHandling/src/LoadMuonLog.cpp
+65
-34
65 additions, 34 deletions
Framework/DataHandling/src/LoadMuonLog.cpp
with
70 additions
and
35 deletions
Framework/DataHandling/inc/MantidDataHandling/LoadMuonLog.h
+
5
−
1
View file @
159f8616
...
...
@@ -11,6 +11,8 @@
// Includes
//----------------------------------------------------------------------
#include
"MantidAPI/Algorithm.h"
#include
"MantidAPI/MatrixWorkspace.h"
#include
"MantidNexus/MuonNexusReader.h"
namespace
Mantid
{
...
...
@@ -65,7 +67,9 @@ private:
/// Overwrites Algorithm method
void
exec
()
override
;
/// Adds a log to the workspace
void
addLogValueFromIndex
(
MuonNexusReader
&
nxload
,
const
int
&
index
,
API
::
MatrixWorkspace_sptr
&
localWorkspace
,
std
::
set
<
std
::
string
>
&
logNames
);
/// The name and path of an input file. This may be the filename of a raw
/// datafile or the name of a specific log file.
std
::
string
m_filename
;
...
...
This diff is collapsed.
Click to expand it.
Framework/DataHandling/src/LoadMuonLog.cpp
+
65
−
34
View file @
159f8616
...
...
@@ -10,10 +10,17 @@
#include
"MantidAPI/Sample.h"
#include
"MantidDataObjects/Workspace2D.h"
#include
"MantidKernel/TimeSeriesProperty.h"
#include
"MantidNexus/MuonNexusReader.h"
#include
<algorithm>
#include
<ctime>
namespace
{
void
toLower
(
std
::
string
&
name
)
{
std
::
transform
(
name
.
begin
(),
name
.
end
(),
name
.
begin
(),
[](
unsigned
char
c
)
{
return
std
::
tolower
(
c
);
});
}
}
// namespace
namespace
Mantid
{
namespace
DataHandling
{
...
...
@@ -56,7 +63,6 @@ void LoadMuonLog::exec() {
// on the filename
m_filename
=
getPropertyValue
(
"Filename"
);
MuonNexusReader
nxload
;
nxload
.
readLogData
(
m_filename
);
...
...
@@ -65,49 +71,74 @@ void LoadMuonLog::exec() {
// Also set the sample name at this point, as part of the sample related log
// data.
const
MatrixWorkspace_sptr
localWorkspace
=
getProperty
(
"Workspace"
);
MatrixWorkspace_sptr
localWorkspace
=
getProperty
(
"Workspace"
);
localWorkspace
->
mutableSample
().
setName
(
nxload
.
getSampleName
());
std
::
set
<
std
::
string
>
logNames
;
auto
logs
=
localWorkspace
->
mutableRun
().
getLogData
();
// need to remove case
for
(
auto
log
:
logs
)
{
std
::
string
name
=
log
->
name
();
toLower
(
name
);
logNames
.
insert
(
name
);
}
// Attempt to load the content of each NXlog section into the Sample object
// Assumes that MuonNexusReader has read all log data
// Two cases of double or string data allowed
Progress
prog
(
this
,
0.0
,
1.0
,
nxload
.
numberOfLogs
());
for
(
int
i
=
0
;
i
<
nxload
.
numberOfLogs
();
i
++
)
{
std
::
string
logName
=
nxload
.
getLogName
(
i
);
auto
l_PropertyDouble
=
std
::
make_unique
<
TimeSeriesProperty
<
double
>>
(
logName
);
auto
l_PropertyString
=
std
::
make_unique
<
TimeSeriesProperty
<
std
::
string
>>
(
logName
);
// Read log file into Property which is then stored in Sample object
if
(
!
nxload
.
logTypeNumeric
(
i
))
{
std
::
string
logValue
;
std
::
time_t
logTime
;
for
(
int
j
=
0
;
j
<
nxload
.
getLogLength
(
i
);
j
++
)
{
nxload
.
getLogStringValues
(
i
,
j
,
logTime
,
logValue
);
l_PropertyString
->
addValue
(
logTime
,
logValue
);
}
}
else
{
double
logValue
;
std
::
time_t
logTime
;
for
(
int
j
=
0
;
j
<
nxload
.
getLogLength
(
i
);
j
++
)
{
nxload
.
getLogValues
(
i
,
j
,
logTime
,
logValue
);
l_PropertyDouble
->
addValue
(
logTime
,
logValue
);
}
}
// store Property in Sample object and delete unused object
if
(
nxload
.
logTypeNumeric
(
i
))
{
localWorkspace
->
mutableRun
().
addLogData
(
std
::
move
(
l_PropertyDouble
));
}
else
{
localWorkspace
->
mutableRun
().
addLogData
(
std
::
move
(
l_PropertyString
));
}
addLogValueFromIndex
(
nxload
,
i
,
localWorkspace
,
logNames
);
prog
.
report
();
}
// end for
}
// operation was a success and ended normally
}
void
LoadMuonLog
::
addLogValueFromIndex
(
MuonNexusReader
&
nxload
,
const
int
&
index
,
API
::
MatrixWorkspace_sptr
&
localWorkspace
,
std
::
set
<
std
::
string
>
&
logNames
)
{
std
::
string
newLogName
=
nxload
.
getLogName
(
index
);
// want to keep the original case for the logs
std
::
string
logNameLower
=
nxload
.
getLogName
(
index
);
toLower
(
logNameLower
);
// check if log name already exists
if
(
logNames
.
find
(
logNameLower
)
!=
logNames
.
end
())
{
g_log
.
warning
(
"The log "
+
newLogName
+
" is already in the nexus file. The sample log names are case insensitive."
);
return
;
}
logNames
.
insert
(
newLogName
);
auto
l_PropertyDouble
=
std
::
make_unique
<
TimeSeriesProperty
<
double
>>
(
newLogName
);
auto
l_PropertyString
=
std
::
make_unique
<
TimeSeriesProperty
<
std
::
string
>>
(
newLogName
);
// Read log file into Property which is then stored in Sample object
if
(
!
nxload
.
logTypeNumeric
(
index
))
{
std
::
string
logValue
;
std
::
time_t
logTime
;
for
(
int
j
=
0
;
j
<
nxload
.
getLogLength
(
index
);
j
++
)
{
nxload
.
getLogStringValues
(
index
,
j
,
logTime
,
logValue
);
l_PropertyString
->
addValue
(
logTime
,
logValue
);
}
}
else
{
double
logValue
;
std
::
time_t
logTime
;
for
(
int
j
=
0
;
j
<
nxload
.
getLogLength
(
index
);
j
++
)
{
nxload
.
getLogValues
(
index
,
j
,
logTime
,
logValue
);
l_PropertyDouble
->
addValue
(
logTime
,
logValue
);
}
}
// store Property in Sample object and delete unused object
if
(
nxload
.
logTypeNumeric
(
index
))
{
localWorkspace
->
mutableRun
().
addLogData
(
std
::
move
(
l_PropertyDouble
));
}
else
{
localWorkspace
->
mutableRun
().
addLogData
(
std
::
move
(
l_PropertyString
));
}
}
/** change each element of the string to lower case
* @param strToConvert :: The input string
* @returns The string but with all characters in lower case
...
...
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