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
c9e59bdf
Commit
c9e59bdf
authored
13 years ago
by
Janik Zikovsky
Browse files
Options
Downloads
Patches
Plain Diff
Fixes #3124: AddSampleLog extended to create other log types (numbers and number series)
parent
021a2aa5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Code/Mantid/Framework/Algorithms/src/AddSampleLog.cpp
+40
-3
40 additions, 3 deletions
Code/Mantid/Framework/Algorithms/src/AddSampleLog.cpp
Code/Mantid/Framework/Algorithms/test/AddSampleLogTest.h
+75
-13
75 additions, 13 deletions
Code/Mantid/Framework/Algorithms/test/AddSampleLogTest.h
with
115 additions
and
16 deletions
Code/Mantid/Framework/Algorithms/src/AddSampleLog.cpp
+
40
−
3
View file @
c9e59bdf
...
@@ -3,6 +3,9 @@
...
@@ -3,6 +3,9 @@
//----------------------------------------------------------------------
//----------------------------------------------------------------------
#include
"MantidAlgorithms/AddSampleLog.h"
#include
"MantidAlgorithms/AddSampleLog.h"
#include
"MantidKernel/Exception.h"
#include
"MantidKernel/Exception.h"
#include
"MantidKernel/ListValidator.h"
#include
"MantidKernel/Strings.h"
#include
"MantidKernel/TimeSeriesProperty.h"
#include
<string>
#include
<string>
namespace
Mantid
namespace
Mantid
...
@@ -16,8 +19,8 @@ DECLARE_ALGORITHM(AddSampleLog)
...
@@ -16,8 +19,8 @@ DECLARE_ALGORITHM(AddSampleLog)
/// Sets documentation strings for this algorithm
/// Sets documentation strings for this algorithm
void
AddSampleLog
::
initDocs
()
void
AddSampleLog
::
initDocs
()
{
{
this
->
setWikiSummary
(
"Used to insert a
single string
into the sample in a workspace
"
);
this
->
setWikiSummary
(
"Used to insert a
value
into the sample
logs
in a workspace
.
"
);
this
->
setOptionalMessage
(
"Used to insert a
single string
into the sample in a workspace"
);
this
->
setOptionalMessage
(
"Used to insert a
value
into the sample
logs
in a workspace
.
"
);
}
}
using
namespace
Kernel
;
using
namespace
Kernel
;
...
@@ -29,6 +32,15 @@ void AddSampleLog::init()
...
@@ -29,6 +32,15 @@ void AddSampleLog::init()
"Workspace to add the log entry to"
);
"Workspace to add the log entry to"
);
declareProperty
(
"LogName"
,
""
,
new
MandatoryValidator
<
std
::
string
>
,
declareProperty
(
"LogName"
,
""
,
new
MandatoryValidator
<
std
::
string
>
,
"The name that will identify the log entry"
);
"The name that will identify the log entry"
);
std
::
vector
<
std
::
string
>
propOptions
;
propOptions
.
push_back
(
"String"
);
propOptions
.
push_back
(
"Number"
);
propOptions
.
push_back
(
"Number Series"
);
declareProperty
(
"LogType"
,
"String"
,
new
ListValidator
(
propOptions
),
"The type that the log data will be."
);
declareProperty
(
"LogText"
,
""
,
declareProperty
(
"LogText"
,
""
,
"The content of the log"
);
"The content of the log"
);
}
}
...
@@ -43,8 +55,33 @@ void AddSampleLog::exec()
...
@@ -43,8 +55,33 @@ void AddSampleLog::exec()
// get the data that the user wants to add
// get the data that the user wants to add
std
::
string
propName
=
getProperty
(
"LogName"
);
std
::
string
propName
=
getProperty
(
"LogName"
);
std
::
string
propValue
=
getProperty
(
"LogText"
);
std
::
string
propValue
=
getProperty
(
"LogText"
);
std
::
string
propType
=
getPropertyValue
(
"LogType"
);
// Remove any existing log
if
(
theRun
.
hasProperty
(
propName
))
theRun
.
removeLogData
(
propName
);
theRun
.
addLogData
(
new
PropertyWithValue
<
std
::
string
>
(
propName
,
propValue
));
if
(
propType
==
"String"
)
{
theRun
.
addLogData
(
new
PropertyWithValue
<
std
::
string
>
(
propName
,
propValue
));
}
else
if
(
propType
==
"Number"
)
{
double
val
;
if
(
!
Strings
::
convert
(
propValue
,
val
))
throw
std
::
invalid_argument
(
"Error interpreting string '"
+
propValue
+
"' as a number."
);
theRun
.
addLogData
(
new
PropertyWithValue
<
double
>
(
propName
,
val
));
}
else
if
(
propType
==
"Number Series"
)
{
double
val
;
if
(
!
Strings
::
convert
(
propValue
,
val
))
throw
std
::
invalid_argument
(
"Error interpreting string '"
+
propValue
+
"' as a number."
);
Kernel
::
DateAndTime
now
=
Kernel
::
DateAndTime
::
get_current_time
();
TimeSeriesProperty
<
double
>
*
tsp
=
new
TimeSeriesProperty
<
double
>
(
propName
);
tsp
->
addValue
(
now
,
val
);
theRun
.
addLogData
(
tsp
);
}
setProperty
(
"Workspace"
,
wSpace
);
setProperty
(
"Workspace"
,
wSpace
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Code/Mantid/Framework/Algorithms/test/AddSampleLogTest.h
+
75
−
13
View file @
c9e59bdf
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
#include
"MantidTestHelpers/WorkspaceCreationHelper.h"
#include
"MantidTestHelpers/WorkspaceCreationHelper.h"
#include
"MantidAPI/MatrixWorkspace.h"
#include
"MantidAPI/MatrixWorkspace.h"
#include
"MantidAlgorithms/AddSampleLog.h"
#include
"MantidAlgorithms/AddSampleLog.h"
#include
"MantidKernel/TimeSeriesProperty.h"
using
namespace
Mantid
::
Kernel
;
using
namespace
Mantid
::
Kernel
;
using
namespace
Mantid
::
API
;
using
namespace
Mantid
::
API
;
...
@@ -17,20 +18,56 @@ class AddSampleLogTest : public CxxTest::TestSuite
...
@@ -17,20 +18,56 @@ class AddSampleLogTest : public CxxTest::TestSuite
{
{
public:
public:
void
test
Insertion
2D
()
void
test
_Workspace
2D
()
{
{
ExecuteAlgorithm
(
WorkspaceCreationHelper
::
Create2DWorkspace
(
10
,
10
));
MatrixWorkspace_sptr
ws
=
WorkspaceCreationHelper
::
Create2DWorkspace
(
10
,
10
);
ExecuteAlgorithm
(
ws
,
"My Name"
,
"String"
,
"My Value"
,
0.0
);
}
}
void
test
InsertionEvent
()
void
test
_EventWorkspace
()
{
{
ExecuteAlgorithm
(
WorkspaceCreationHelper
::
CreateEventWorkspace
(
10
,
10
));
MatrixWorkspace_sptr
ws
=
WorkspaceCreationHelper
::
CreateEventWorkspace
(
10
,
10
);
ExecuteAlgorithm
(
ws
,
"My Name"
,
"String"
,
"My Value"
,
0.0
);
}
}
void
ExecuteAlgorithm
(
MatrixWorkspace_sptr
testWS
)
void
test_CanOverwrite
()
{
MatrixWorkspace_sptr
ws
=
WorkspaceCreationHelper
::
Create2DWorkspace
(
10
,
10
);
ExecuteAlgorithm
(
ws
,
"My Name"
,
"String"
,
"My Value"
,
0.0
);
ExecuteAlgorithm
(
ws
,
"My Name"
,
"String"
,
"My New Value"
,
0.0
);
}
void
test_Number
()
{
MatrixWorkspace_sptr
ws
=
WorkspaceCreationHelper
::
Create2DWorkspace
(
10
,
10
);
ExecuteAlgorithm
(
ws
,
"My Name"
,
"Number"
,
"1.234"
,
1.234
);
ExecuteAlgorithm
(
ws
,
"My Name"
,
"Number"
,
"2.456"
,
2.456
);
}
void
test_BadNumber
()
{
MatrixWorkspace_sptr
ws
=
WorkspaceCreationHelper
::
Create2DWorkspace
(
10
,
10
);
ExecuteAlgorithm
(
ws
,
"My Name"
,
"Number"
,
"OneTwoThreeFour"
,
0.0
,
true
);
}
void
test_BadNumberSeries
()
{
MatrixWorkspace_sptr
ws
=
WorkspaceCreationHelper
::
Create2DWorkspace
(
10
,
10
);
ExecuteAlgorithm
(
ws
,
"My Name"
,
"Number Series"
,
"FiveSixSeven"
,
0.0
,
true
);
}
void
test_NumberSeries
()
{
MatrixWorkspace_sptr
ws
=
WorkspaceCreationHelper
::
Create2DWorkspace
(
10
,
10
);
ExecuteAlgorithm
(
ws
,
"My Name"
,
"Number Series"
,
"1.234"
,
1.234
);
ExecuteAlgorithm
(
ws
,
"My Name"
,
"Number Series"
,
"2.456"
,
2.456
);
}
void
ExecuteAlgorithm
(
MatrixWorkspace_sptr
testWS
,
std
::
string
LogName
,
std
::
string
LogType
,
std
::
string
LogText
,
double
expectedValue
,
bool
fails
=
false
)
{
{
//add the workspace to the ADS
//add the workspace to the ADS
AnalysisDataService
::
Instance
().
add
(
"AddSampleLogTest_Temporary"
,
testWS
);
AnalysisDataService
::
Instance
().
add
OrReplace
(
"AddSampleLogTest_Temporary"
,
testWS
);
//execute algorithm
//execute algorithm
AddSampleLog
alg
;
AddSampleLog
alg
;
...
@@ -38,20 +75,45 @@ public:
...
@@ -38,20 +75,45 @@ public:
TS_ASSERT
(
alg
.
isInitialized
()
)
TS_ASSERT
(
alg
.
isInitialized
()
)
alg
.
setPropertyValue
(
"Workspace"
,
"AddSampleLogTest_Temporary"
);
alg
.
setPropertyValue
(
"Workspace"
,
"AddSampleLogTest_Temporary"
);
alg
.
setPropertyValue
(
"LogName"
,
"my n
ame
"
);
alg
.
setPropertyValue
(
"LogName"
,
LogN
ame
);
alg
.
setPropertyValue
(
"LogText"
,
"my data"
);
alg
.
setPropertyValue
(
"LogText"
,
LogText
);
alg
.
setPropertyValue
(
"LogType"
,
LogType
);
TS_ASSERT_THROWS_NOTHING
(
alg
.
execute
())
TS_ASSERT_THROWS_NOTHING
(
alg
.
execute
())
TS_ASSERT
(
alg
.
isExecuted
()
)
if
(
fails
)
{
TS_ASSERT
(
!
alg
.
isExecuted
()
)
return
;
}
else
{
TS_ASSERT
(
alg
.
isExecuted
()
)
}
//check output
//check output
MatrixWorkspace_sptr
output
=
boost
::
dynamic_pointer_cast
<
MatrixWorkspace
>
(
AnalysisDataService
::
Instance
().
retrieve
(
alg
.
getProperty
(
"Workspace"
)));
MatrixWorkspace_sptr
output
=
boost
::
dynamic_pointer_cast
<
MatrixWorkspace
>
(
AnalysisDataService
::
Instance
().
retrieve
(
alg
.
getProperty
(
"Workspace"
)));
const
Run
&
wSpaceRun
=
output
->
run
();
const
Run
&
wSpaceRun
=
output
->
run
();
PropertyWithValue
<
std
::
string
>
*
testProp
=
dynamic_cast
<
PropertyWithValue
<
std
::
string
>*>
(
wSpaceRun
.
getLogData
(
"my name"
));
Property
*
prop
;
TS_ASSERT_THROWS_NOTHING
(
prop
=
wSpaceRun
.
getLogData
(
LogName
);)
if
(
!
prop
)
return
;
if
(
LogType
==
"String"
)
{
TS_ASSERT_EQUALS
(
prop
->
value
(),
LogText
);
}
else
if
(
LogType
==
"Number"
)
{
PropertyWithValue
<
double
>
*
testProp
=
dynamic_cast
<
PropertyWithValue
<
double
>*>
(
prop
);
TS_ASSERT
(
testProp
);
TS_ASSERT_DELTA
((
*
testProp
)(),
expectedValue
,
1e-5
);
}
else
if
(
LogType
==
"Number Series"
)
{
TimeSeriesProperty
<
double
>
*
testProp
=
dynamic_cast
<
TimeSeriesProperty
<
double
>*>
(
prop
);
TS_ASSERT
(
testProp
);
TS_ASSERT_DELTA
(
testProp
->
firstValue
(),
expectedValue
,
1e-5
);
}
TS_ASSERT
(
testProp
)
TS_ASSERT_EQUALS
(
testProp
->
value
(),
"my data"
)
//cleanup
//cleanup
AnalysisDataService
::
Instance
().
remove
(
output
->
getName
());
AnalysisDataService
::
Instance
().
remove
(
output
->
getName
());
...
...
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