Skip to content
Snippets Groups Projects
Commit b3dc03c5 authored by Steve Williams's avatar Steve Williams
Browse files

AddSampleLog() takes a string and adds it to a workspace's sample logs. SANS...

AddSampleLog() takes a string and adds it to a workspace's sample logs. SANS scripts now save the name of the mask file which can be retrieved with Python like
pWS=mtd['992front_2D'];print pWS.getSampleDetails().getLogData('UserFile').value()
refs #1237
parent b7be9aed
No related merge requests found
......@@ -182,6 +182,10 @@
RelativePath=".\src\AbsorptionCorrection.cpp"
>
</File>
<File
RelativePath=".\src\AddSampleLog.cpp"
>
</File>
<File
RelativePath=".\src\AnyShapeAbsorption.cpp"
>
......@@ -512,6 +516,10 @@
RelativePath=".\inc\MantidAlgorithms\AbsorptionCorrection.h"
>
</File>
<File
RelativePath=".\inc\MantidAlgorithms\AddSampleLog.h"
>
</File>
<File
RelativePath=".\inc\MantidAlgorithms\AnyShapeAbsorption.h"
>
......
#ifndef MANTID_ALGORITHMS_ADDSAMPLELOG_H_
#define MANTID_ALGORITHMS_ADDSAMPLELOG_H_
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/Algorithm.h"
namespace Mantid
{
namespace Algorithms
{
/**
Used to insert a single string into the sample in a workspace
Required Properties:
<UL>
<LI> Workspace -The log data will be added to this workspace</LI>
<LI> LogName -The name the entry will be accessible through this name</LI>
Optional property:
<LI> LogText -The log data</LI>
</UL>
Workspaces contain information in logs. Often these detail what happened
to the sample during the experiment. This algorithm allows one named log
to be entered.
Copyright &copy; 2009-2010 STFC Rutherford Appleton Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport AddSampleLog : public API::Algorithm
{
public:
/// (Empty) Constructor
AddSampleLog() : API::Algorithm() {}
/// Virtual destructor
virtual ~AddSampleLog() {}
/// Algorithm's name
virtual const std::string name() const { return "AddSampleLog"; }
/// Algorithm's version
virtual const int version() const { return (1); }
/// Algorithm's category for identification
virtual const std::string category() const { return "DataHandling\\Logs"; }
private:
/// Initialisation code
void init();
/// Execution code
void exec();
};
} // namespace Algorithms
} // namespace Mantid
#endif /*MANTID_ALGORITHMS_ADDSAMPLELOG_H_*/
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAlgorithms/AddSampleLog.h"
#include "MantidKernel/Exception.h"
#include <string>
namespace Mantid
{
namespace Algorithms
{
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(AddSampleLog)
using namespace Kernel;
using namespace API;
void AddSampleLog::init()
{
declareProperty(new WorkspaceProperty<>("Workspace","",Direction::InOut),
"Workspace to add the log entry to");
declareProperty("LogName", "", new MandatoryValidator<std::string>,
"The name that will identify the log entry");
declareProperty("LogText", "",
"The content of the log");
}
void AddSampleLog::exec()
{
// A pointer to the workspace to add a log to
MatrixWorkspace_sptr wSpace = getProperty("Workspace");
// we're going to edit the workspaces sample so get a non-const reference to it
Sample &theSample = wSpace->mutableSample();
// get the data that the user wants to add
std::string propName = getProperty("LogName");
std::string propValue = getProperty("LogText");
theSample.addLogData(new PropertyWithValue<std::string>(propName, propValue));
setProperty("Workspace", wSpace);
}
} // namespace Algorithms
} // namespace Mantid
#ifndef ADDSAMPLELOGTEST_H_
#define ADDSAMPLELOGTEST_H_
#include <cxxtest/TestSuite.h>
#include <string>
#include "MantidDataObjects/Workspace2D.h"
#include "MantidAlgorithms/AddSampleLog.h"
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::DataObjects;
using namespace Mantid::Algorithms;
class AddSampleLogTest : public CxxTest::TestSuite
{
public:
void testInsertion()
{
AddSampleLog alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize());
TS_ASSERT( alg.isInitialized() )
Workspace2D_sptr testWS = makeDummyWorkspace2D();
alg.setPropertyValue("Workspace", "AddSampleLogTest_Temporary");
alg.setPropertyValue("LogName", "my name");
alg.setPropertyValue("LogText", "my data");
TS_ASSERT_THROWS_NOTHING(alg.execute())
TS_ASSERT( alg.isExecuted() )
MatrixWorkspace_sptr output = boost::dynamic_pointer_cast<MatrixWorkspace>(AnalysisDataService::Instance().retrieve(alg.getProperty("Workspace")));
Sample wSpaceSam = output->sample();
PropertyWithValue<std::string> *testProp =
dynamic_cast<PropertyWithValue<std::string>*>(wSpaceSam.getLogData("my name"));
TS_ASSERT(testProp)
TS_ASSERT_EQUALS(testProp->value(), "my data")
}
Workspace2D_sptr makeDummyWorkspace2D()
{
Workspace2D_sptr testWorkspace(new Workspace2D);
AnalysisDataService::Instance().add("AddSampleLogTest_Temporary", testWorkspace);
return testWorkspace;
}
};
#endif /*ADDSAMPLELOGTEST_H_*/
......@@ -38,6 +38,8 @@ DIRECT_SAMPLE = ''
DIRECT_CAN = ''
DIRECT_CAN = ''
#This is stored as UserFile in the output workspace
MASKFILE = '_ no file'
# Now the mask string (can be empty)
# These apply to both detectors
SPECMASKSTRING = ''
......@@ -922,6 +924,11 @@ def MaskFile(filename):
SetRearEfficiencyFile(DIRECT_BEAM_FILE_F)
if DIRECT_BEAM_FILE_F == None and DIRECT_BEAM_FILE_R != None:
SetFrontEfficiencyFile(DIRECT_BEAM_FILE_R)
# just print thhe name, remove the path
filename = os.path.basename(filename)
global MASKFILE
MASKFILE = filename
# Read a limit line of a mask file
def _readLimitValues(limit_line):
......@@ -1149,7 +1156,9 @@ def WavRangeReduction(wav_start = None, wav_end = None, use_def_trans = DefaultT
RenameWorkspace(final_workspace + '_4', 'Down')
# Revert the name change so that future calls with different wavelengths get the correct name
sample_setup.setReducedWorkspace(wsname_cache)
sample_setup.setReducedWorkspace(wsname_cache)
AddSampleLog(final_workspace, "UserFile", MASKFILE)
return final_workspace
##
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment