From e6014ee4d33d3c31c9ea76bf0af17b6fee14538c Mon Sep 17 00:00:00 2001 From: Wenduo Zhou Date: Wed, 3 Jun 2015 00:20:15 -0400 Subject: [PATCH] Refs #11847. Added property directory to save memory. --- .../ConvertCWSDExpToMomentum.h | 12 ++-- .../src/ConvertCWSDExpToMomentum.cpp | 58 ++++++++++++++++--- 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/ConvertCWSDExpToMomentum.h b/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/ConvertCWSDExpToMomentum.h index f1494ac05257..1ad69784e6a6 100644 --- a/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/ConvertCWSDExpToMomentum.h +++ b/Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/ConvertCWSDExpToMomentum.h @@ -65,10 +65,11 @@ class DLLExport ConvertCWSDExpToMomentum : public API::Algorithm { const detid_t &startdetid, const int runnumber); - void convertToMomentum(const std::vector &detPos, - const double &wavelength, - std::vector &qSample, - const Kernel::DblMatrix &rotationMatrix); + /// Convert |Q| with detector position to Q_sample + Kernel::V3D convertToMomentum(const std::vector &detPos, + const double &momentum, + std::vector &qSample, + const Kernel::DblMatrix &rotationMatrix); API::IMDEventWorkspace_sptr createExperimentMDWorkspace(); @@ -99,6 +100,9 @@ class DLLExport ConvertCWSDExpToMomentum : public API::Algorithm { std::vector m_extentMins; std::vector m_extentMaxs; std::vector m_numBins; + + /// Data directory + std::string m_dataDir; }; } // namespace MDAlgorithms diff --git a/Code/Mantid/Framework/MDAlgorithms/src/ConvertCWSDExpToMomentum.cpp b/Code/Mantid/Framework/MDAlgorithms/src/ConvertCWSDExpToMomentum.cpp index 7a5859d7970c..0a3e9debd30c 100644 --- a/Code/Mantid/Framework/MDAlgorithms/src/ConvertCWSDExpToMomentum.cpp +++ b/Code/Mantid/Framework/MDAlgorithms/src/ConvertCWSDExpToMomentum.cpp @@ -7,6 +7,7 @@ #include "MantidGeometry/Instrument/ComponentHelper.h" #include "MantidMDAlgorithms/MDWSDescription.h" #include "MantidMDAlgorithms/MDWSTransform.h" +#include "MantidAPI/FileProperty.h" using namespace Mantid::API; using namespace Mantid::Kernel; @@ -53,6 +54,11 @@ void ConvertCWSDExpToMomentum::init() { declareProperty(new ArrayProperty("PixelDimension"), "A vector of 8 doubles to determine a cubic pixel's size."); + + declareProperty( + new FileProperty("Directory", ".", FileProperty::Directory), + "Directory where data files are if InputWorkspace gives data file name " + "as the base file name."); } /** @@ -142,6 +148,7 @@ ConvertCWSDExpToMomentum::createExperimentMDWorkspace() { static_cast(m_extentMaxs[i]), m_numBins[i]))); } + /*----- No use... just examples??? // Add events // Creates a new instance of the MDEventInserter. MDEventWorkspace, 3>::sptr MDEW_MDEVENT_3 = @@ -151,6 +158,7 @@ ConvertCWSDExpToMomentum::createExperimentMDWorkspace() { MDEW_MDEVENT_3); // FIXME - Add instrument? + -------------------------------*/ mdws->setCoordinateSystem(coordinateSystem); @@ -166,13 +174,40 @@ void ConvertCWSDExpToMomentum::addMDEvents() { size_t numrows = m_expDataTableWS->rowCount(); size_t numFileNotLoaded(0); for (size_t ir = 0; ir < numrows; ++ir) { - std::string filename = + std::string rawfilename = m_expDataTableWS->cell(ir, m_iColFilename); detid_t start_detid = m_expDataTableWS->cell(ir, m_iColStartDetID); // Load data bool loaded; std::string errmsg; + + // FIXME - Identify windows or linux + bool isWindows = true; + bool needSep = true; + if (m_dataDir.size() == 0) { + needSep = false; + } else { + if (m_dataDir.find('/') != std::string::npos) { + isWindows = false; + if (m_dataDir.back() != '/') + needSep = true; + } else { + if (m_dataDir.back() != '\\') + needSep = true; + } + } + + std::stringstream filess; + filess << m_dataDir; + if (needSep) + if (isWindows) + filess << "\\"; + else + filess << "/"; + filess << rawfilename; + std::string filename(filess.str()); + spicews = loadSpiceData(filename, loaded, errmsg); if (!loaded) { g_log.error(errmsg); @@ -225,11 +260,12 @@ void ConvertCWSDExpToMomentum::convertSpiceMatrixToMomentumMDEvents( // Get detector positions and signal double signal = dataws->readY(iws)[0]; double error = dataws->readE(iws)[0]; - double wavelength = dataws->readX(iws)[0]; + double magQ = 0.5 * (dataws->readX(iws)[0] + dataws->readX(iws)[1]); // Create the MDEvent Kernel::V3D detpos = dataws->getDetector(iws)->getPos(); std::vector momentum(3); - convertToMomentum(detpos, wavelength, momentum, rotationMatrix); + Kernel::V3D qsample = + convertToMomentum(detpos, magQ, momentum, rotationMatrix); detid_t detid = dataws->getDetector(iws)->getID() + startdetid; // Insert inserter.insertMDEvent( @@ -295,21 +331,27 @@ bool ConvertCWSDExpToMomentum::getInputs(std::string &errmsg) { m_samplePos.setZ(samplepos[2]); } + m_dataDir = getPropertyValue("Directory"); + errmsg = errss.str(); return (errmsg.size() > 0); } -void ConvertCWSDExpToMomentum::convertToMomentum( - const std::vector &detPos, const double &wavelength, +/// Convert to momentum +Kernel::V3D ConvertCWSDExpToMomentum::convertToMomentum( + const std::vector &detPos, const double &momentum, std::vector &qSample, const Kernel::DblMatrix &rotationMatrix) { - // TODO - Use detector position and wavelength/Q to calcualte Q_lab - Kernel::V3D q_lab; + // Use detector position and wavelength/Q to calcualte Q_lab + double x = detPos[0] * momentum; + double y = detPos[1] * momentum; + double z = detPos[2] * momentum; + Kernel::V3D q_lab(x, y, z); // TODO - Use matrix workspace Kernel::V3D q_sample = rotationMatrix * q_lab; - return; + return q_lab; } API::MatrixWorkspace_sptr