diff --git a/Framework/MDAlgorithms/src/LoadDNSSCD.cpp b/Framework/MDAlgorithms/src/LoadDNSSCD.cpp index 0ece0a41ee136197a08373cb15b00b8e21b8e701..9065ec8b9dc8b3e675ff463f1efed40f42ef7e70 100644 --- a/Framework/MDAlgorithms/src/LoadDNSSCD.cpp +++ b/Framework/MDAlgorithms/src/LoadDNSSCD.cpp @@ -316,6 +316,12 @@ void LoadDNSSCD::exec() { throw std::runtime_error( "No valid DNS files have been provided. Nothing to load."); + // merge data with different time channel number is not allowed + auto ch_n = m_data.front().nchannels; + bool same_channel_number = std::all_of(m_data.begin(), m_data.end(), [ch_n](ExpData &d) {return (d.nchannels==ch_n);}); + if (!same_channel_number) + throw std::runtime_error("Error: cannot merge data with different TOF channel numbers."); + m_OutWS = MDEventFactory::CreateMDWorkspace(m_nDims, "MDEvent"); m_OutWS->addExperimentInfo(expinfo); @@ -668,9 +674,6 @@ void LoadDNSSCD::read_data(const std::string fname, std::map<std::string, double>::const_iterator w = num_metadata.lower_bound("Time"); g_log.debug() << "Channel width: " << w->second << std::endl; -// if (m->second != 1) -// throw std::runtime_error( -// "Algorithm does not support TOF data. TOF Channels number must be 1."); ExpData ds; ds.deterota = num_metadata["DeteRota"]; @@ -689,10 +692,6 @@ void LoadDNSSCD::read_data(const std::string fname, const int cols = splitIntoColumns(columns, line); if (cols > 0){ g_log.debug() << "Number of columns = " << cols << std::endl; - g_log.debug() << "Data: " ; -// for (std::string s : columns) { -// g_log.debug() << s << ",\t"; -// } g_log.debug() << std::endl; ds.detID.push_back(std::stoi(columns.front())); columns.pop_front(); diff --git a/Framework/MDAlgorithms/test/LoadDNSSCDTest.h b/Framework/MDAlgorithms/test/LoadDNSSCDTest.h index 014917501b63e3435916ba6915c95f59be7a7e86..b866465b7622115d8b5bc2b0b6ce1e8a491037e2 100644 --- a/Framework/MDAlgorithms/test/LoadDNSSCDTest.h +++ b/Framework/MDAlgorithms/test/LoadDNSSCDTest.h @@ -1044,62 +1044,30 @@ public: AnalysisDataService::Instance().remove(normWSName); } -// void test_Load2() { -// // algorithm should load one file and skip the TOF file - -// std::string outWSName("LoadDNSSCDTest_OutputWS"); -// std::string normWSName("LoadDNSSCDTest_OutputWS_norm"); -// std::string filenames = "dn134011vana.d_dat,dnstof.d_dat"; - -// LoadDNSSCD alg; -// alg.setRethrows(true); -// TS_ASSERT_THROWS_NOTHING(alg.initialize()); -// TS_ASSERT(alg.isInitialized()); -// TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filenames", filenames)); -// TS_ASSERT_THROWS_NOTHING( -// alg.setPropertyValue("OutputWorkspace", outWSName)); -// TS_ASSERT_THROWS_NOTHING( -// alg.setPropertyValue("NormalizationWorkspace", normWSName)); -// TS_ASSERT_THROWS_NOTHING(alg.setProperty("Normalization", "monitor")); - -// // algorithm should throw only if no valid files is provided -// TS_ASSERT_THROWS_NOTHING(alg.execute()); -// TS_ASSERT(alg.isExecuted()); - -// // Retrieve the workspace from data service. -// IMDEventWorkspace_sptr iws; -// TS_ASSERT_THROWS_NOTHING( -// iws = AnalysisDataService::Instance().retrieveWS<IMDEventWorkspace>( -// outWSName)); -// TS_ASSERT(iws); - -// TS_ASSERT_EQUALS(iws->getNumDims(), 3); -// TS_ASSERT_EQUALS(iws->getNPoints(), 24); -// AnalysisDataService::Instance().remove(outWSName); -// } //-------------------- Test failure -------------------------------------- -// void test_failTOF() { -// // algorithm does not load TOF files - -// std::string outWSName("LoadDNSSCDTest_OutputWS"); -// std::string normWSName("LoadDNSSCDTest_OutputWS_norm"); - -// LoadDNSSCD alg; -// alg.setRethrows(true); -// TS_ASSERT_THROWS_NOTHING(alg.initialize()); -// TS_ASSERT(alg.isInitialized()); -// TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filenames", "dnstof.d_dat")); -// TS_ASSERT_THROWS_NOTHING( -// alg.setPropertyValue("OutputWorkspace", outWSName)); -// TS_ASSERT_THROWS_NOTHING( -// alg.setPropertyValue("NormalizationWorkspace", normWSName)); -// TS_ASSERT_THROWS_NOTHING(alg.setProperty("Normalization", "monitor")); - -// // algorithm should throw if no valid files is provided -// TS_ASSERT_THROWS(alg.execute(), std::runtime_error); -// TS_ASSERT(!alg.isExecuted()); -// } + void test_failTOF() { + // algorithm does not load files with different number of time channels + + std::string outWSName("LoadDNSSCDTest_OutputWS"); + std::string normWSName("LoadDNSSCDTest_OutputWS_norm"); + std::string filenames = "dn134011vana.d_dat,dnstof.d_dat"; + + LoadDNSSCD alg; + alg.setRethrows(true); + TS_ASSERT_THROWS_NOTHING(alg.initialize()); + TS_ASSERT(alg.isInitialized()); + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filenames", filenames)); + TS_ASSERT_THROWS_NOTHING( + alg.setPropertyValue("OutputWorkspace", outWSName)); + TS_ASSERT_THROWS_NOTHING( + alg.setPropertyValue("NormalizationWorkspace", normWSName)); + TS_ASSERT_THROWS_NOTHING(alg.setProperty("Normalization", "monitor")); + + // algorithm should throw if no valid files is provided + TS_ASSERT_THROWS(alg.execute(), std::runtime_error); + TS_ASSERT(!alg.isExecuted()); + } private: std::string m_fileName;