diff --git a/Code/Mantid/Framework/Algorithms/src/ConvertUnits.cpp b/Code/Mantid/Framework/Algorithms/src/ConvertUnits.cpp index 985841dbdb29..742e9c3705af 100644 --- a/Code/Mantid/Framework/Algorithms/src/ConvertUnits.cpp +++ b/Code/Mantid/Framework/Algorithms/src/ConvertUnits.cpp @@ -357,20 +357,59 @@ void ConvertUnits::convertViaTOF(Kernel::Unit_const_sptr fromUnit, API::MatrixWo // Let's see if we are using a TableWorkspace to override parameters ITableWorkspace_sptr paramWS = getProperty("DetectorParameters"); + + // Some bool usingDetPars = false; bool usingDetParsL1 = false; + Column_const_sptr l1Column; + Column_const_sptr l2Column; + Column_const_sptr spectraColumn; + Column_const_sptr twoThetaColumn; + Column_const_sptr efixedColumn; + Column_const_sptr emodeColumn; + + // See if we have supplied a DetectorParameters Workspace + if ( paramWS != NULL ) + { + usingDetPars = true; + + // First lets see if the table includes L1 ? + try { + l1Column = paramWS->getColumn("l1"); + if ( l1Column != NULL ) + { + usingDetParsL1 = true; + g_log.notice() << "Overriding L1 from IDF with parameter table." << std::endl; + } + + } catch (...) { + // make sure we know we are using L1 from the IDF + usingDetParsL1 = false; + g_log.debug() << "Could not find L1 in parameter table supplied - using values from IDF."; + } + + + // Now lets read the rest of the parameters + try { + l2Column = paramWS->getColumn("l2"); + spectraColumn = paramWS->getColumn("spectra"); + twoThetaColumn = paramWS->getColumn("twotheta"); + efixedColumn = paramWS->getColumn("efixed"); + emodeColumn = paramWS->getColumn("emode"); + } catch (...) { + throw Exception::NotFoundError("DetectorParameter TableWorkspace is not defined correctly."); + } + + } + + ColumnVector detPars_spectra = paramWS->getVector("spectra"); ColumnVector detPars_l2 = paramWS->getVector("l2"); ColumnVector detPars_twotheta = paramWS->getVector("twotheta"); ColumnVector detPars_efixed = paramWS->getVector("efixed"); ColumnVector detPars_emode = paramWS->getVector("emode"); - if ( paramWS != NULL ) - { - usingDetPars = true; - g_log.notice() << "Size of table == " << paramWS->rowCount() << std::endl; - } EventWorkspace_sptr eventWS = boost::dynamic_pointer_cast(outputWS); assert ( static_cast(eventWS) == m_inputEvents ); // Sanity check diff --git a/Code/Mantid/Framework/Algorithms/test/ConvertUnitsTest.h b/Code/Mantid/Framework/Algorithms/test/ConvertUnitsTest.h index 18527c001e63..4f71338c28a7 100644 --- a/Code/Mantid/Framework/Algorithms/test/ConvertUnitsTest.h +++ b/Code/Mantid/Framework/Algorithms/test/ConvertUnitsTest.h @@ -233,6 +233,51 @@ class ConvertUnitsTest : public CxxTest::TestSuite AnalysisDataService::Instance().remove(workspaceName); } + void testConvertUsingDetectorTablewithoutL1() + { + ConvertUnits myAlg; + myAlg.initialize(); + TS_ASSERT(myAlg.isInitialized()); + + const std::string workspaceName("_ws_testConvertUsingDetectorTable"); + int nBins = 10; + MatrixWorkspace_sptr WS = WorkspaceCreationHelper::Create2DWorkspaceBinned(2, nBins, 0.0, 10.0); + WS->getAxis(0)->unit() = UnitFactory::Instance().create("TOF"); + + AnalysisDataService::Instance().add(workspaceName,WS); + + // Create TableWorkspace with values in it + + ITableWorkspace_sptr pars = WorkspaceFactory::Instance().createTable("TableWorkspace"); + pars->addColumn("int", "spectra"); + pars->addColumn("double", "l2"); + pars->addColumn("double", "twotheta"); + pars->addColumn("double", "efixed"); + pars->addColumn("int", "emode"); + + API::TableRow row0 = pars->appendRow(); + row0 << 1 << 10.0 << 90.0 << 7.0 << 1; + + API::TableRow row1 = pars->appendRow(); + row1 << 2 << 10.0 << 90.0 << 7.0 << 1; + + // Set the properties + myAlg.setRethrows(true); + myAlg.setPropertyValue("InputWorkspace", workspaceName); + myAlg.setPropertyValue("OutputWorkspace", workspaceName); + myAlg.setPropertyValue("Target", "Wavelength"); + myAlg.setProperty("DetectorParameters", pars); + + myAlg.execute(); + + auto outWS = AnalysisDataService::Instance().retrieveWS(workspaceName); + + // TODO: test that output workspace values + + + AnalysisDataService::Instance().remove(workspaceName); + } + void testConvertQuickly() { ConvertUnits quickly;