diff --git a/Code/Mantid/Algorithms/Algorithms.vcproj b/Code/Mantid/Algorithms/Algorithms.vcproj index e879d9efd293dac605653316aac96cf0cc3f3dc7..b1cef1a23f91dd7e6e0c4c946897c05aac5e85bd 100644 --- a/Code/Mantid/Algorithms/Algorithms.vcproj +++ b/Code/Mantid/Algorithms/Algorithms.vcproj @@ -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" > diff --git a/Code/Mantid/Algorithms/inc/MantidAlgorithms/AddSampleLog.h b/Code/Mantid/Algorithms/inc/MantidAlgorithms/AddSampleLog.h new file mode 100644 index 0000000000000000000000000000000000000000..5a9d64161607bb0e6422ed4ff5b35640269f7f86 --- /dev/null +++ b/Code/Mantid/Algorithms/inc/MantidAlgorithms/AddSampleLog.h @@ -0,0 +1,72 @@ +#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 © 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_*/ diff --git a/Code/Mantid/Algorithms/src/AddSampleLog.cpp b/Code/Mantid/Algorithms/src/AddSampleLog.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f56a2cc8f3ae9806182c8bd015d44227513b86fb --- /dev/null +++ b/Code/Mantid/Algorithms/src/AddSampleLog.cpp @@ -0,0 +1,46 @@ +//---------------------------------------------------------------------- +// 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 diff --git a/Code/Mantid/Algorithms/test/AddSampleLogTest.h b/Code/Mantid/Algorithms/test/AddSampleLogTest.h new file mode 100644 index 0000000000000000000000000000000000000000..a3e7075002d579edc789a33c68282a80abd79396 --- /dev/null +++ b/Code/Mantid/Algorithms/test/AddSampleLogTest.h @@ -0,0 +1,56 @@ +#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_*/ diff --git a/Code/Mantid/PythonAPI/scripts/SANS/SANSReduction.py b/Code/Mantid/PythonAPI/scripts/SANS/SANSReduction.py index a227f769e5b67e66445e1e12e61ba4eae7dfa791..b13ae6649a3bf7e1c84154055bf25f8ec338b076 100644 --- a/Code/Mantid/PythonAPI/scripts/SANS/SANSReduction.py +++ b/Code/Mantid/PythonAPI/scripts/SANS/SANSReduction.py @@ -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 ##