diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/SaveGSS.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/SaveGSS.h index df0bb80abe46f131a560755d18f1b6e92cd40ee4..5e62be0f0fe4f3485f68a9f5b5f45fe4cd889473 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/SaveGSS.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/SaveGSS.h @@ -87,6 +87,9 @@ private: const MantidVec& X, const MantidVec& Y, const MantidVec& E) const; /// sets non workspace properties for the algorithm void setOtherProperties(IAlgorithm* alg,const std::string & propertyName,const std::string &propertyValue,int periodNum); + + bool m_useSpecAsBank; + }; } diff --git a/Code/Mantid/Framework/DataHandling/src/LoadGSS.cpp b/Code/Mantid/Framework/DataHandling/src/LoadGSS.cpp index 4de3843a9cce6eaf62ab55885c1df610f273c8ae..f66b9b613ab797993061f45f92cd01d2bde65554 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadGSS.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadGSS.cpp @@ -90,6 +90,8 @@ namespace Mantid "The input filename of the stored data"); declareProperty(new API::WorkspaceProperty<>("OutputWorkspace", "", Kernel::Direction::Output), "Workspace name to load into."); + + declareProperty("UseBankIDasSpectrumNumber", false, "If true, spectrum number corresponding to one bank should be its bank ID. "); } /** @@ -100,6 +102,8 @@ namespace Mantid using namespace Mantid::API; std::string filename = getPropertyValue("Filename"); + bool m_useBankAsSpectrum = getProperty("UseBankIDasSpectrumNumber"); + std::vector<MantidVec*> gsasDataX; std::vector<MantidVec*> gsasDataY; std::vector<MantidVec*> gsasDataE; @@ -408,6 +412,10 @@ namespace Mantid } // 2.2 Put data from MatidVec's into outputWorkspace + if (detectorIDs.size() != static_cast<size_t>(nHist)) + { + throw std::runtime_error("It seems not possible to have mismatch spectrum numbers and nHist."); + } for (int i = 0; i < nHist; ++i) { // Move data across @@ -418,6 +426,13 @@ namespace Mantid delete gsasDataX[i]; delete gsasDataY[i]; delete gsasDataE[i]; + + // Reset spectrum number if + if (m_useBankAsSpectrum) + { + specid_t specno = static_cast<specid_t>(detectorIDs[i]); + outputWorkspace->getSpectrum(i)->setSpectrumNo(specno); + } } // 2.3 Build instrument geometry diff --git a/Code/Mantid/Framework/DataHandling/src/SaveGSS.cpp b/Code/Mantid/Framework/DataHandling/src/SaveGSS.cpp index 22b72bd5b553812ed24ec9cf7bf0e0cf0cedb150..b9d4dbc4b4b29f4207e784a429c8cc13b66df224 100644 --- a/Code/Mantid/Framework/DataHandling/src/SaveGSS.cpp +++ b/Code/Mantid/Framework/DataHandling/src/SaveGSS.cpp @@ -76,6 +76,9 @@ namespace Mantid declareProperty("MultiplyByBinWidth", true, "Multiply the intensity (Y) by the bin width; default TRUE."); declareProperty("ExtendedHeader", false, "Add information to the header about iparm file and normalization"); + + declareProperty("UseSpectrumNumberAsBankID", false, "If true, then each bank's bank ID is equal to the spectrum number; " + "otherwise, the continous bank IDs is applied. "); } /** @@ -133,6 +136,8 @@ namespace Mantid bool split = (split_string == "True"); std::string outputFormat = getProperty("Format"); + m_useSpecAsBank = getProperty("UseSpectrumNumberAsBankID"); + std::ostringstream number; std::ofstream out; // Check whether to append to an already existing file or overwrite @@ -210,14 +215,25 @@ namespace Mantid / (PhysicalConstants::h * 1e4)) << "\n"; } out << "# Data for spectrum :" << i << std::endl; + + int bankid; + if (m_useSpecAsBank) + { + bankid = static_cast<int>(inputWS->getSpectrum(i)->getSpectrumNo()); + } + else + { + bankid = bank + i; + } + if (RALF.compare(outputFormat) == 0) { - this->writeRALFdata(bank + i, MultiplyByBinWidth, out, inputWS->readX(i), inputWS->readY(i), + this->writeRALFdata(bankid, MultiplyByBinWidth, out, inputWS->readX(i), inputWS->readY(i), inputWS->readE(i)); } else if (SLOG.compare(outputFormat) == 0) { - this->writeSLOGdata(bank + i, MultiplyByBinWidth, out, inputWS->readX(i), inputWS->readY(i), + this->writeSLOGdata(bankid, MultiplyByBinWidth, out, inputWS->readX(i), inputWS->readY(i), inputWS->readE(i)); } else diff --git a/Code/Mantid/Framework/DataHandling/test/LoadGSSTest.h b/Code/Mantid/Framework/DataHandling/test/LoadGSSTest.h index 16e8605a9400f37593a9c3727ce3eefb1b94540d..be74e7532776f739ab4d720f976f12463da59731 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadGSSTest.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadGSSTest.h @@ -9,6 +9,7 @@ //#include <fstream> using namespace Mantid; +using Mantid::DataHandling::LoadGSS; class LoadGSSTest : public CxxTest::TestSuite { @@ -41,6 +42,38 @@ public: checkWorkspace( loader->getProperty("OutputWorkspace"), 1, 6); } + /** Test LoadGSS with setting spectrum ID as bank ID + */ + void test_load_gss_use_spec() + { + // Set property and execute + LoadGSS loader; + loader.initialize(); + + loader.setPropertyValue("Filename","gss1.txt"); + loader.setProperty("OutputWorkspace", "TestWS"); + loader.setProperty("UseBankIDasSpectrumNumber", true); + + TS_ASSERT( loader.execute() ); + + // Check result + API::MatrixWorkspace_sptr outws = boost::dynamic_pointer_cast<API::MatrixWorkspace>( + API::AnalysisDataService::Instance().retrieve("TestWS")); + TS_ASSERT(outws); + if (!outws) + return; + + TS_ASSERT_EQUALS(outws->getNumberHistograms(), 3); + if (outws->getNumberHistograms() != 3) + return; + + TS_ASSERT_EQUALS(outws->getSpectrum(0)->getSpectrumNo(), 1); + TS_ASSERT_EQUALS(outws->getSpectrum(1)->getSpectrumNo(), 3); + TS_ASSERT_EQUALS(outws->getSpectrum(2)->getSpectrumNo(), 5); + + API::AnalysisDataService::Instance().remove("TestWS"); + } + void test_fails_gracefully_if_passed_wrong_filetype() { API::IAlgorithm_sptr loader = createAlgorithm(); diff --git a/Test/AutoTestData/gss1.txt b/Test/AutoTestData/gss1.txt new file mode 100644 index 0000000000000000000000000000000000000000..f362981536e8f480469bc1318582e77923d64cd9 --- /dev/null +++ b/Test/AutoTestData/gss1.txt @@ -0,0 +1,315 @@ +direct beam +# File generated by Mantid: +# Instrument: LOQ +# Data for spectrum :0 +BANK 1 102 102 RALF 112000 2800 112000 0.02500 FXYE + 3543.75000 9750125.00000000 29208.49084599 + 3632.34375 11058917.18750000 31493.59673416 + 3723.15625 12247976.12500000 33555.21744347 + 3816.23438 13600981.79062500 35799.37167451 + 3911.64063 14832149.32500000 37848.94033979 + 4009.43750 16219607.00468750 40071.38318461 + 4109.67188 17438717.60156250 42066.21709427 + 4212.40625 18413438.01171875 43762.82171774 + 4317.71875 19460298.09140625 45548.49525721 + 4425.67188 20319612.97187500 47121.56175467 + 4536.31250 20983767.60937500 48480.36621081 + 4649.71875 22083741.96562500 50352.61767662 + 4765.96875 22974182.66562500 51995.75693745 + 4885.12500 23784757.56093750 53562.34581996 + 5007.25000 24531348.17500000 55072.28186443 + 5132.42188 25432753.82812500 56771.51986293 + 5260.73438 26307929.09765625 58457.30166795 + 5392.26563 27015082.41250000 59973.72064407 + 5527.07813 28018607.31562500 61836.31607490 + 5665.25000 28819636.21093750 63493.08441407 + 5806.87500 29737950.84531250 65297.91803030 + 5952.04688 30638185.96562500 67102.25239989 + 6100.84375 31633285.87109375 69030.31083453 + 6253.35938 32492603.62734375 70830.67784721 + 6409.68750 33256502.24531250 72548.66745767 + 6569.92188 34779710.55937500 75113.08484945 + 6734.17188 36490384.12578125 77893.94795892 + 6902.53125 37730927.32968750 80190.94751299 + 7075.09375 38961073.59375000 82500.03666737 + 7251.96875 40382538.86875001 85034.90617663 + 7433.26563 39518560.35000000 85165.35545771 + 7619.09375 42296695.65000001 89202.57234772 + 7809.57813 45219342.66015625 93378.77910158 + 8004.82813 46485303.50000000 95853.11803366 + 8204.95313 47507887.35703126 98105.50294264 + 8410.07813 48171889.21875000 100015.96807801 + 8620.32813 48500744.03906250 101603.49253395 + 8835.82813 48650540.40625000 103024.40287260 + 9056.71875 49010930.32500000 104689.80095769 + 9283.14063 49135305.03515625 106124.75909197 + 9515.21875 49126973.06875000 107434.05083548 + 9753.09375 48899615.64218751 108516.67110994 + 9996.92188 48484562.26250000 109397.47774729 + 10246.84375 48272774.64453125 110514.37385799 + 10503.01563 47721011.92031250 111245.95057206 + 10765.59375 47089248.94843750 111879.98800930 + 11034.73438 46377476.90000001 112410.51240817 + 11310.60938 45590119.83984375 112836.80738567 + 11593.37500 45034692.01875000 113540.57449737 + 11883.20313 43616354.95000000 113126.40605432 + 12180.28125 42761504.75625000 113403.80211071 + 12484.79688 41740504.47187500 113433.66038618 + 12796.92188 40305255.71406250 112851.18606948 + 13116.84375 39021473.11562500 112418.80691746 + 13444.76563 37804026.27968750 112025.82239569 + 13780.89063 36520704.66875000 111475.80242705 + 14125.42188 34878624.45234375 110294.24052185 + 14478.56250 33760069.83593750 109859.30418504 + 14840.53125 32655026.51875000 109388.63382238 + 15211.54688 31488277.62500000 108751.09320929 + 15591.82813 30065678.73750000 107586.21216911 + 15981.60938 29059708.52812500 107084.95699290 + 16381.14063 28061099.47265625 106536.13209142 + 16790.67188 26996905.33125000 105794.58929308 + 17210.43750 26085082.84375000 105284.54575806 + 17640.68750 25285428.26796875 104945.89632329 + 18081.70313 24229031.01484375 104006.41725650 + 18533.75000 23792757.76250000 104346.17192250 + 18997.09375 22917531.96562500 103681.19716839 + 19472.01563 22062039.40937500 102991.36719361 + 19958.81250571519330.35546875 530707.57531090 + 20457.78125135172408.30703124 261303.84989548 + 20969.21875 23745444.62656250 110880.15159539 + 21493.45313 23589719.17968750 111888.87012149 + 22030.79688 40766223.15937500 148914.79158045 + 22581.56250 95503297.16015625 230759.02719161 + 23146.09375214529466.87031251 350150.58750342 + 23724.75000375589609.26484376 469061.75069007 + 24317.87500464349560.19921875 528029.07393210 + 24925.82813467145561.57187504 536195.70190540 + 25548.98438451622731.55625004 533761.42664924 + 26187.71875436878272.40937501 531497.81559745 + 26842.42188434663601.18671876 536735.04437242 + 27513.48438423956311.79062504 536668.17785271 + 28201.32813423754437.54296875 543205.72899490 + 28906.37500390671358.00000000 528049.99609935 + 29629.04688351279710.90625000 506941.46605346 + 30369.78125310543366.18359375 482563.46075609 + 31129.03125274770931.79453129 459558.34827305 + 31907.26563239121676.70781252 434036.96836127 + 32704.95313205941873.61406252 407804.09125305 + 33522.57813175814746.02421877 381477.42325787 + 34360.64063150088985.30937502 356843.29436708 + 35219.65625129209171.73046875 335205.93855536 + 36100.15625111719712.38125001 315567.22714250 + 37002.67188 97529893.21562500 298509.30632111 + 37927.75000 86284212.30000001 284260.59569750 + 38875.95313 76524187.90000001 271026.87683182 + 39847.859381317443881.20703120 1138520.94708903 + 40844.06250145304004.62500000 382803.35363185 + 41865.17188116963005.27656251 347714.78589192 + 42941.01563609793725.17578125 803808.07280802 +# Data for spectrum :1 +BANK 3 102 102 RALF 112000 2800 112000 0.02500 FXYE + 3543.75000 525.00000000 214.33035249 + 3632.34375 807.18750000 269.06250000 + 3723.15625 2206.31250000 450.36165318 + 3816.23438 2261.47500000 461.62165134 + 3911.64063 2511.17343750 492.48162922 + 4009.43750 3860.93906250 618.24504403 + 4109.67188 5682.51250000 759.35767397 + 4212.40625 6864.67031250 844.98250385 + 4317.71875 6716.43984375 846.19188201 + 4425.67188 9397.71718750 1013.38190611 + 4536.31250 9408.65625000 1026.56855842 + 4649.71875 23650.40937500 1647.80210131 + 4765.96875 90259.12187500 3259.06799966 + 4885.12500 249322.18593750 5483.91465843 + 5007.25000 478841.98593750 7694.28865105 + 5132.42188 789506.48437500 10002.57181110 + 5260.73438 1146579.02734375 12203.86599803 + 5392.26563 1435272.78125000 13823.72445309 + 5527.07813 1668495.59218750 15089.77860616 + 5665.25000 1974166.13281250 16617.81908074 + 5806.87500 2315151.81406250 18219.37824448 + 5952.04688 2645940.98125000 19719.48872917 + 6100.84375 2970134.99140625 21152.21099994 + 6253.35938 3342381.35859375 22717.32242022 + 6409.68750 3685336.95937500 24150.70182980 + 6569.92188 4073838.70781250 25707.18553743 + 6734.17188 4377043.66562500 26977.70107083 + 6902.53125 4645316.73750000 28137.41986262 + 7075.09375 4792373.64375000 28934.36923847 + 7251.96875 4971447.86875000 29836.08747994 + 7433.26563 5185484.98750000 30850.13696717 + 7619.09375 5458469.54296875 32044.95041657 + 7809.57813 5688067.07656250 33118.32956310 + 8004.82813 5910723.25000000 34179.73742384 + 8204.95313 5978067.21562500 34800.93452582 + 8410.07813 6135411.56250000 35693.92885738 + 8620.32813 6179393.15625000 36266.64239153 + 8835.82813 6334529.65625000 37175.21239942 + 9056.71875 6424902.53671875 37904.53497154 + 9283.14063 6490861.69843750 38571.90309071 + 9515.21875 6573021.29375000 39297.45884384 + 9753.09375 6690383.10312500 40139.24815180 + 9996.92188 6731999.13750000 40764.07532500 + 10246.84375 6798340.91406250 41473.34896654 + 10503.01563 6750453.44531250 41840.40333714 + 10765.59375 6939689.31406250 42949.83929642 + 11034.73438 7225160.57500000 44368.74252406 + 11310.60938 7457738.73750000 45637.20148691 + 11593.37500 7724624.90625000 47023.63403991 + 11883.20313 7933874.00000000 48248.29328614 + 12180.28125 7577938.69453125 47739.36846656 + 12484.79688 8025099.35390625 49737.99893068 + 12796.92188 8876957.75312500 52961.14477423 + 13116.84375 9173369.11562500 54506.91169236 + 13444.76563 9186260.86875000 55222.80973057 + 13780.89063 9323023.48125000 56323.47242656 + 14125.42188 9616097.06484375 57912.53548556 + 14478.56250 9669890.70781250 58795.75325166 + 14840.53125 9503801.42500000 59012.75019523 + 15211.54688 9514165.28125000 59778.43270030 + 15591.82813 9286574.24843750 59792.79829369 + 15981.60938 9176210.07187500 60174.78029460 + 16381.14063 8910128.14453125 60032.51783947 + 16790.67188 8685542.65625000 60007.41848869 + 17210.43750 8349827.19921875 59567.21031747 + 17640.68750 8047204.82421875 59204.24292796 + 18081.70313 7782274.21953125 58944.78368639 + 18533.75000 7387872.77500000 58145.19528825 + 18997.09375 6958565.36718750 57131.54067855 + 19472.01563 6666162.01562500 56612.96849525 + 19958.81250 6286779.16328125 55661.37459465 + 20457.78125 5891336.65703125 54551.75200789 + 20969.21875 5499114.02421875 53359.28732705 + 21493.45313 5292163.77187500 52995.88396511 + 22030.79688 4807609.62187500 51138.99596579 + 22581.56250 4452192.70703125 49823.75939945 + 23146.09375 4113147.34921875 48484.00826498 + 23724.75000 3841064.98671875 47435.01728744 + 24317.87500 3502975.16406250 45862.09037504 + 24925.82813 3169579.57031250 44167.01456122 + 25548.98438 2829313.19531250 42247.38197391 + 26187.71875 1275115.22812500 28714.15081270 + 26842.42188 11267.18828125 2732.69455220 + 27513.48438 6114.10781250 2038.03593750 + 28201.32813 6963.28906250 2201.98534436 + 28906.37500 4996.16250000 1888.37192638 + 29629.04688 3657.90625000 1635.86540606 + 30369.78125 11997.93750000 2999.48437500 + 31129.03125 6917.56171875 2305.85390625 + 31907.26563 4727.00156250 1929.79030691 + 32704.95313 8075.29687500 2553.63309070 + 33522.57813 4138.58984375 1850.83364432 + 34360.64063 5938.87656250 2244.68435021 + 35219.65625 6087.34765625 2300.80114892 + 36100.15625 891.36171875 891.36171875 + 37002.67188 4568.23046875 2042.97477300 + 37927.75000 0.00000000 0.00000000 + 38875.95313 0.00000000 0.00000000 + 39847.85938 14758.46484375 3810.61923703 + 40844.06250 0.00000000 0.00000000 + 41865.17188 0.00000000 0.00000000 + 42941.01563 2119.10156250 1498.43108487 +# Data for spectrum :2 +BANK 5 102 102 RALF 112000 2800 112000 0.02500 FXYE + 3543.75000 0.00000000 0.00000000 + 3632.34375 0.00000000 0.00000000 + 3723.15625 91.92968750 91.92968750 + 3816.23438 282.68437500 163.20790000 + 3911.64063 386.33437500 193.16718750 + 4009.43750 791.98750000 280.00986593 + 4109.67188 1014.73437500 320.88718451 + 4212.40625 936.09140625 312.03046875 + 4317.71875 1385.93203125 384.38838484 + 4425.67188 2404.06718750 512.54884654 + 4536.31250 2912.20312500 571.13002161 + 4649.71875 2870.19531250 574.03906250 + 4765.96875 3530.34375000 644.54963587 + 4885.12500 4583.57187500 743.55354342 + 5007.25000 7294.52031250 949.66565561 + 5132.42188 10898.48437500 1175.21379387 + 5260.73438 49619.71093750 2538.76526938 + 5392.26563 147654.68593750 4433.85474281 + 5527.07813 345681.28046875 6868.44250427 + 5665.25000 571840.93750000 8943.75305116 + 5806.87500 810525.37343750 10780.20754690 + 5952.04688 988480.28437500 12052.84523641 + 6100.84375 1134155.61953125 13070.85510578 + 6253.35938 1343468.38828125 14402.66527675 + 6409.68750 1584856.32187500 15837.48085962 + 6569.92188 1790750.02968750 17043.94406894 + 6734.17188 1940272.09140625 17961.63293902 + 6902.53125 2165348.88281250 19210.58302451 + 7075.09375 2338275.84375000 20210.94197901 + 7251.96875 2588504.91250000 21529.05284390 + 7433.26563 2831616.55000000 22797.10118734 + 7619.09375 2946614.11171875 23544.30041028 + 7809.57813 3066365.26718750 24316.32909456 + 8004.82813 3141844.40000000 24919.58157072 + 8204.95313 3207629.73515625 25491.92457965 + 8410.07813 3408262.03125000 26603.51315948 + 8620.32813 3559664.20312500 27525.73673260 + 8835.82813 3611129.15000000 28068.40809066 + 9056.71875 3639905.97578125 28530.07961441 + 9283.14063 3690563.04140625 29084.80813725 + 9515.21875 3780244.93750000 29801.76037644 + 9753.09375 3768788.98437500 30126.22053126 + 9996.92188 3752917.35000000 30436.17479876 + 10246.84375 3749334.35078125 30799.57486054 + 10503.01563 3787826.47031250 31341.83547668 + 10765.59375 3701770.15312500 31368.68073214 + 11034.73438 3808208.36250000 32211.70549610 + 11310.60938 3796453.72968750 32561.50563747 + 11593.37500 3721617.50625000 32639.48944566 + 11883.20313 3820230.75000000 33479.89628022 + 12180.28125 3993026.63203125 34653.90888381 + 12484.79688 4134777.30703125 35701.72182238 + 12796.92188 4293763.04218750 36833.61329344 + 13116.84375 4472681.38281250 38060.20493917 + 13444.76563 4204726.08281250 37360.95484253 + 13780.89063 4531018.67500000 39265.30352320 + 14125.42188 4879024.40390625 41251.49146649 + 14478.56250 5075003.45625000 42594.48258320 + 14840.53125 5077293.05000000 43133.36031656 + 15211.54688 5010045.03125000 43379.04564368 + 15591.82813 5260030.84140625 45000.28418311 + 15981.60938 5195406.45937500 45278.55980464 + 16381.14063 5142465.35156250 45606.87032038 + 16790.67188 5051710.60937500 45764.18125203 + 17210.43750 4960432.23046875 45912.21842821 + 17640.68750 4780409.90234375 45631.30328106 + 18081.70313 4757496.07500000 46087.30708764 + 18533.75000 4575319.12812500 45757.76728679 + 18997.09375 4399820.90625000 45429.04212679 + 19472.01563 4182397.64687500 44842.58666312 + 19958.81250 4998573.41484375 49632.12412940 + 20457.78125 3969315.22343750 44777.47267803 + 20969.21875 3672461.70546875 43605.60294531 + 21493.45313 3399148.51171875 42472.76871036 + 22030.79688 3223024.10156250 41871.58257962 + 22581.56250 3010875.46875000 40972.82543056 + 23146.09375 2671231.16718750 39072.13288190 + 23724.75000 2672401.77968750 39566.17903553 + 24317.87500 2365138.69921875 37684.57518051 + 24925.82813 2252555.57812500 37233.59517941 + 25548.98438 2004175.70156250 35557.16975040 + 26187.71875 1871936.40234375 34790.99150081 + 26842.42188 1713938.17031250 33703.95688703 + 27513.48438 1517657.42812500 32109.39830918 + 28201.32813 1294475.43671875 30023.00226523 + 28906.37500 501043.72500000 18910.67676399 + 29629.04688 9510.55625000 2637.75370904 + 30369.78125 5998.96875000 2120.95574163 + 31129.03125 7686.17968750 2430.58343178 + 31907.26563 7090.50234375 2363.50078125 + 32704.95313 7267.76718750 2422.58906250 + 33522.57813 7449.46171875 2483.15390625 + 34360.64063 5938.87656250 2244.68435021 + 35219.65625 7826.58984375 2608.86328125 + 36100.15625 7130.89375000 2521.15166327 + 37002.67188 10963.75312500 3164.96290902 + 37927.75000 7491.90000000 2648.78664699 + 38875.95313 10558.90000000 3183.62813626 + 39847.85938 2054378.30625000 44958.84785635 + 40844.06250 51433.26093750 7202.09709474 + 41865.17188 9303.37031250 3101.12343750 + 42941.01563 12714.60937500 3670.39157265