From c595e7fa242470a3d6b5cfbfa25a51bd6a509d24 Mon Sep 17 00:00:00 2001 From: Russell Taylor <taylorrj@ornl.gov> Date: Mon, 28 Apr 2014 13:40:14 -0400 Subject: [PATCH] Re #9357. Remove Managed Workspaces along with associated classes and references thereto. Now that we only support 64 bit we can just fall back on swap when memory runs out. --- .../Framework/API/inc/MantidAPI/ISpectrum.h | 2 - .../API/inc/MantidAPI/MemoryManager.h | 2 - .../Framework/API/src/MemoryManager.cpp | 74 -- .../Framework/API/src/WorkspaceFactory.cpp | 43 +- .../Framework/API/test/WorkspaceFactoryTest.h | 16 - .../inc/MantidDataHandling/LoadRaw3.h | 5 - .../Framework/DataHandling/src/LoadRaw3.cpp | 87 --- .../DataHandling/test/LoadMappingTableTest.h | 2 - .../DataHandling/test/LoadMuonNexus1Test.h | 1 - .../DataHandling/test/LoadMuonNexus2Test.h | 1 - .../DataHandling/test/LoadRaw3Test.h | 52 -- .../DataHandling/test/LoadRawBin0Test.h | 1 - .../DataHandling/test/LoadRawSpectrum0Test.h | 1 - .../Framework/DataObjects/CMakeLists.txt | 11 - .../MantidDataObjects/AbsManagedWorkspace2D.h | 158 ----- .../inc/MantidDataObjects/Histogram1D.h | 19 +- .../MantidDataObjects/ManagedDataBlock2D.h | 109 --- .../MantidDataObjects/ManagedHistogram1D.h | 207 ------ .../MantidDataObjects/ManagedWorkspace2D.h | 98 --- .../DataObjects/src/AbsManagedWorkspace2D.cpp | 199 ------ .../DataObjects/src/ManagedDataBlock2D.cpp | 206 ------ .../DataObjects/src/ManagedHistogram1D.cpp | 89 --- .../DataObjects/src/ManagedWorkspace2D.cpp | 322 --------- .../DataObjects/test/ManagedDataBlock2DTest.h | 267 -------- .../DataObjects/test/ManagedHistogram1DTest.h | 120 ---- .../DataObjects/test/ManagedWorkspace2DTest.h | 639 ------------------ .../Framework/Kernel/src/ConfigService.cpp | 1 - .../Framework/Kernel/test/ConfigServiceTest.h | 13 +- .../Properties/Mantid.properties.template | 14 - .../api/src/Exports/MatrixWorkspace.cpp | 5 +- .../Mantid/MantidPlot/src/Mantid/MantidUI.cpp | 2 +- .../MantidPlot/src/Mantid/WorkspaceIcons.cpp | 1 - 32 files changed, 15 insertions(+), 2752 deletions(-) delete mode 100644 Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/AbsManagedWorkspace2D.h delete mode 100644 Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/ManagedDataBlock2D.h delete mode 100644 Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/ManagedHistogram1D.h delete mode 100644 Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/ManagedWorkspace2D.h delete mode 100644 Code/Mantid/Framework/DataObjects/src/AbsManagedWorkspace2D.cpp delete mode 100644 Code/Mantid/Framework/DataObjects/src/ManagedDataBlock2D.cpp delete mode 100644 Code/Mantid/Framework/DataObjects/src/ManagedHistogram1D.cpp delete mode 100644 Code/Mantid/Framework/DataObjects/src/ManagedWorkspace2D.cpp delete mode 100644 Code/Mantid/Framework/DataObjects/test/ManagedDataBlock2DTest.h delete mode 100644 Code/Mantid/Framework/DataObjects/test/ManagedHistogram1DTest.h delete mode 100644 Code/Mantid/Framework/DataObjects/test/ManagedWorkspace2DTest.h diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/ISpectrum.h b/Code/Mantid/Framework/API/inc/MantidAPI/ISpectrum.h index 3f37b5998c2..e535a7bfdb6 100644 --- a/Code/Mantid/Framework/API/inc/MantidAPI/ISpectrum.h +++ b/Code/Mantid/Framework/API/inc/MantidAPI/ISpectrum.h @@ -46,8 +46,6 @@ namespace API */ class DLLExport ISpectrum { - friend class ManagedDataBlock2D; - public: ISpectrum(); ISpectrum(const specid_t specNo); diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/MemoryManager.h b/Code/Mantid/Framework/API/inc/MantidAPI/MemoryManager.h index e058cab31e4..ec9cef64a1e 100644 --- a/Code/Mantid/Framework/API/inc/MantidAPI/MemoryManager.h +++ b/Code/Mantid/Framework/API/inc/MantidAPI/MemoryManager.h @@ -53,8 +53,6 @@ namespace Mantid public: /// Returns available physical memory in the system in KB. MemoryInfo getMemoryInfo(); - /// Returns true if there is not sufficient memory for a full Workspace2D. - bool goForManagedWorkspace(std::size_t NVectors,std::size_t XLength,std::size_t YLength); /// Release memory back to the system if we linked againsed tcmalloc void releaseFreeMemory(); /// Release memory back to the system if we linked againsed tcmalloc and are above this much use diff --git a/Code/Mantid/Framework/API/src/MemoryManager.cpp b/Code/Mantid/Framework/API/src/MemoryManager.cpp index ae06fee4e2e..28bdaabb6cb 100644 --- a/Code/Mantid/Framework/API/src/MemoryManager.cpp +++ b/Code/Mantid/Framework/API/src/MemoryManager.cpp @@ -39,8 +39,6 @@ MemoryManagerImpl::~MemoryManagerImpl() { } - - MemoryInfo MemoryManagerImpl::getMemoryInfo() { Kernel::MemoryStats mem_stats; @@ -51,78 +49,6 @@ MemoryInfo MemoryManagerImpl::getMemoryInfo() return info; } -/** Decides if a ManagedWorkspace2D sould be created for the current memory conditions - and workspace parameters NVectors, XLength,and YLength. - @param NVectors :: the number of vectors - @param XLength :: the size of the X vector - @param YLength :: the size of the Y vector - @return true is managed workspace is needed - */ -bool MemoryManagerImpl::goForManagedWorkspace(std::size_t NVectors, std::size_t XLength, std::size_t YLength) -{ - int AlwaysInMemory;// Check for disabling flag - if (Kernel::ConfigService::Instance().getValue("ManagedWorkspace.AlwaysInMemory", AlwaysInMemory) - && AlwaysInMemory) - return false; - - // check potential size to create and determine trigger - int availPercent; - if (!Kernel::ConfigService::Instance().getValue("ManagedWorkspace.LowerMemoryLimit", availPercent)) - { - // Default to 40% if missing - availPercent = 40; - } - if (availPercent > 150) - { - g_log.warning("ManagedWorkspace.LowerMemoryLimit is not allowed to be greater than 150%."); - availPercent = 150; - } - if (availPercent < 0) - { - g_log.warning("Negative value for ManagedWorkspace.LowerMemoryLimit. Setting to 0."); - availPercent = 0; - } - if (availPercent > 90) - { - g_log.warning("ManagedWorkspace.LowerMemoryLimit is greater than 90%. Danger of memory errors."); - } - MemoryInfo mi = getMemoryInfo(); - size_t triggerSize = mi.availMemory / 100 * availPercent / sizeof(double); - // Avoid int overflow - size_t wsSize = 0; - if (NVectors > 1024) - wsSize = NVectors / 1024 * (YLength * 2 + XLength); - else if (YLength * 2 + XLength > 1024) - wsSize = (YLength * 2 + XLength) / 1024 * NVectors; - else - wsSize = NVectors * (YLength * 2 + XLength) / 1024; - -// g_log.debug() << "Requested memory: " << (wsSize * sizeof(double))/1024 << " MB. " << std::endl; -// g_log.debug() << "Available memory: " << mi.availMemory << " KB.\n"; -// g_log.debug() << "MWS trigger memory: " << triggerSize * sizeof(double) << " KB.\n"; - - bool goManaged = (wsSize > triggerSize); - // If we're on the cusp of going managed, add in the reserved but unused memory - if( goManaged ) - { - // This is called separately as on some systems it is an expensive calculation. - // See Kernel/src/Memory.cpp - reservedMem() for more details - Kernel::MemoryStats mem_stats; - const size_t reserved = mem_stats.reservedMem(); -// g_log.debug() << "Windows - Adding reserved but unused memory of " << reserved << " KB\n"; - mi.availMemory += reserved; - triggerSize += reserved / 100 * availPercent / sizeof(double); - goManaged = (wsSize > triggerSize); - - g_log.debug() << "Requested memory: " << (wsSize * sizeof(double))/1024 << " MB." << std::endl; - g_log.debug() << "Available memory: " << (mi.availMemory)/1024 << " MB." << std::endl; - g_log.debug() << "ManagedWS trigger memory: " << (triggerSize * sizeof(double))/1024 << " MB." << std::endl; - } - - return goManaged; -} - - /** Release any free memory back to the system. * Calling this could help the system avoid going into swap. * NOTE: This only works if you linked against tcmalloc. diff --git a/Code/Mantid/Framework/API/src/WorkspaceFactory.cpp b/Code/Mantid/Framework/API/src/WorkspaceFactory.cpp index a584cf4bab8..7d8e5bacefe 100644 --- a/Code/Mantid/Framework/API/src/WorkspaceFactory.cpp +++ b/Code/Mantid/Framework/API/src/WorkspaceFactory.cpp @@ -149,9 +149,6 @@ void WorkspaceFactoryImpl::initializeFromParent(const MatrixWorkspace_const_sptr } /** Creates a new instance of the class with the given name, and allocates memory for the arrays - * where it creates and initialises either a Workspace2D or a ManagedWorkspace2D - * according to the size requested and the value of the configuration parameter - * ManagedWorkspace.LowerMemoryLimit (default 40% of available physical memory) Workspace2D only. * @param className The name of the class you wish to create * @param NVectors The number of vectors/histograms/detectors in the workspace * @param XLength The number of X data points/bin boundaries in each vector (must all be the same) @@ -163,46 +160,14 @@ void WorkspaceFactoryImpl::initializeFromParent(const MatrixWorkspace_const_sptr MatrixWorkspace_sptr WorkspaceFactoryImpl::create(const std::string& className, const size_t& NVectors, const size_t& XLength, const size_t& YLength) const { - MatrixWorkspace_sptr ws; - - // Creates a managed workspace if over the trigger size and a 2D workspace is being requested. - // Otherwise calls the vanilla create method. - bool is2D = className.find("2D") != std::string::npos; - if ( MemoryManager::Instance().goForManagedWorkspace(static_cast<size_t>(NVectors), static_cast<size_t>(XLength), - static_cast<size_t>(YLength)) && is2D ) - { - // check if there is enough memory for 100 data blocks - int blockMemory; - if ( ! Kernel::ConfigService::Instance().getValue("ManagedWorkspace.DataBlockSize", blockMemory) - || blockMemory <= 0 ) - { - // default to 1MB if property not found - blockMemory = 1024*1024; - } - - MemoryInfo mi = MemoryManager::Instance().getMemoryInfo(); - if ( static_cast<unsigned int>(blockMemory)*100/1024 > mi.availMemory ) - { - throw std::runtime_error("There is not enough memory to allocate the workspace"); - } - - ws = boost::dynamic_pointer_cast<MatrixWorkspace>(this->create("ManagedWorkspace2D")); - g_log.information("Created a ManagedWorkspace2D"); - } - else - { - // No need for a Managed Workspace - if ( is2D && ( className.substr(0,7) == "Managed" )) - ws = boost::dynamic_pointer_cast<MatrixWorkspace>(this->create("Workspace2D")); - else - ws = boost::dynamic_pointer_cast<MatrixWorkspace>(this->create(className)); - } + MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>(this->create(className)); if (!ws) { - g_log.error("Workspace was not created"); - throw std::runtime_error("Workspace was not created"); + g_log.error("Workspace was not created"); + throw std::runtime_error("Workspace was not created"); } + ws->initialize(NVectors,XLength,YLength); return ws; } diff --git a/Code/Mantid/Framework/API/test/WorkspaceFactoryTest.h b/Code/Mantid/Framework/API/test/WorkspaceFactoryTest.h index a28d8cf1dbf..67fc8db0583 100644 --- a/Code/Mantid/Framework/API/test/WorkspaceFactoryTest.h +++ b/Code/Mantid/Framework/API/test/WorkspaceFactoryTest.h @@ -41,13 +41,6 @@ class WorkspaceFactoryTest : public CxxTest::TestSuite std::vector<size_t> size; }; - class ManagedWorkspace2DTest: public Workspace2DTest - { - public: - const std::string id() const {return "ManagedWorkspace2DTest";} - size_t getNumberHistograms() const { return 2;} - }; - class NotInFactory : public WorkspaceTester { public: @@ -60,15 +53,6 @@ public: { WorkspaceFactory::Instance().subscribe<Workspace1DTest>("Workspace1DTest"); WorkspaceFactory::Instance().subscribe<Workspace2DTest>("Workspace2DTest"); - try - { - WorkspaceFactory::Instance().subscribe<ManagedWorkspace2DTest>("ManagedWorkspace2DTest"); - } - catch (std::runtime_error&) - { - // In theory, we shouldn't have the 'real' ManagedWorkspace2D when running this test, but - // in reality we do so need catch the error from trying to subscribe again - } } void testReturnType() diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRaw3.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRaw3.h index 49998b8b11e..11a57bae0d5 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRaw3.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRaw3.h @@ -80,11 +80,6 @@ namespace Mantid void validateWorkspaceSizes( bool bexcludeMonitors ,bool bseparateMonitors, const int64_t normalwsSpecs,const int64_t monitorwsSpecs); - /// This method is useful for separating or excluding monitors from the output workspace - void separateOrexcludeMonitors(DataObjects::Workspace2D_sptr localWorkspace, - bool binclude,bool bexclude,bool bseparate, - int64_t numberOfSpectra,const std::string &fileName); - /// creates output workspace, monitors excluded from this workspace void excludeMonitors(FILE* file,const int& period,const std::vector<specid_t>& monitorList, DataObjects::Workspace2D_sptr ws_sptr); diff --git a/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp b/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp index 559df364766..906379b2312 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp @@ -573,92 +573,5 @@ namespace Mantid return bMonitor; } - /** This method separates/excludes monitors from output workspace and creates a separate workspace for monitors - * THIS METHOD IS ONLY CALLED BY THE goManagedRaw METHOD ABOVE AND NOT IN THE GENERAL CASE - * @param localWorkspace :: shared pointer to workspace - * @param binclude :: boolean variable for including monitors - * @param bexclude :: boolean variable for excluding monitors - * @param bseparate :: boolean variable for separating the monitor workspace from output workspace - * @param m_numberOfSpectra :: number of spectra - * @param fileName :: raw file name - */ - void LoadRaw3::separateOrexcludeMonitors(DataObjects::Workspace2D_sptr localWorkspace, - bool binclude,bool bexclude,bool bseparate, - int64_t m_numberOfSpectra,const std::string &fileName) - { - (void) binclude; // Avoid compiler warning - - std::vector<specid_t> monitorwsList; - DataObjects::Workspace2D_sptr monitorWorkspace; - FILE *file(NULL); - std::vector<specid_t> monitorSpecList = getmonitorSpectrumList(SpectrumDetectorMapping(localWorkspace.get())); - if (bseparate && !monitorSpecList.empty()) - { - Property *ws = getProperty("OutputWorkspace"); - std::string localWSName = ws->value(); - std::string monitorWSName = localWSName + "_Monitors"; - - declareProperty(new WorkspaceProperty<Workspace> ("MonitorWorkspace", monitorWSName, - Direction::Output)); - //create monitor workspace - const int64_t nMons(static_cast<int64_t>(monitorSpecList.size())); - monitorWorkspace = boost::dynamic_pointer_cast<DataObjects::Workspace2D>( - WorkspaceFactory::Instance().create(localWorkspace,nMons,m_lengthIn,m_lengthIn-1)); - - setProperty("MonitorWorkspace", boost::dynamic_pointer_cast<Workspace>(monitorWorkspace)); - file =openRawFile(fileName); - ioRaw(file,true ); - } - // Now check whether there is more than one time regime in use - m_noTimeRegimes =getNumberofTimeRegimes(); - // Get the time channel array(s) and store in a vector inside a shared pointer - m_timeChannelsVec = getTimeChannels(m_noTimeRegimes,m_lengthIn); - //read raw file - if (bseparate && !monitorSpecList.empty()) - { - readData(file, 0); - } - int64_t monitorwsIndex = 0; - for (specid_t i = 0; i < m_numberOfSpectra; ++i) - { - int64_t histToRead = i + 1; - if (bseparate && !monitorSpecList.empty()) - { - if (!readData(file, histToRead)) - { - throw std::runtime_error("Error reading raw file"); - } - } - if ((bseparate && !monitorSpecList.empty()) || bexclude) - { - if (isMonitor(monitorSpecList, static_cast<specid_t>(i) + 1)) - { - spec2index_map wsIndexmap; - SpectraAxis* axis = dynamic_cast<SpectraAxis*>(localWorkspace->getAxis(1)); - axis->getSpectraIndexMap(wsIndexmap); - spec2index_map::const_iterator wsItr; - wsItr = wsIndexmap.find(static_cast<specid_t>(i + 1)); - if (wsItr != wsIndexmap.end()) - monitorwsList.push_back(static_cast<specid_t>(wsItr->second)); - if (bseparate) - { - monitorWorkspace->getSpectrum(monitorwsIndex)->setSpectrumNo(i+1); - setWorkspaceData(monitorWorkspace, m_timeChannelsVec, monitorwsIndex, i + 1, m_noTimeRegimes,m_lengthIn,1); - ++monitorwsIndex; - } - } - } - - } - if ((bseparate && !monitorwsList.empty()) || bexclude) - { - localWorkspace->setMonitorList(monitorwsList); - if (bseparate) - { - fclose(file); - } - } - } - } // namespace DataHandling } // namespace Mantid diff --git a/Code/Mantid/Framework/DataHandling/test/LoadMappingTableTest.h b/Code/Mantid/Framework/DataHandling/test/LoadMappingTableTest.h index be1cceae7a5..b95336f5746 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadMappingTableTest.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadMappingTableTest.h @@ -6,7 +6,6 @@ #include "MantidAPI/WorkspaceFactory.h" #include "MantidDataHandling/LoadInstrumentFromRaw.h" #include "MantidDataHandling/LoadMappingTable.h" -#include "MantidDataObjects/ManagedWorkspace2D.h" #include "MantidKernel/ConfigService.h" #include "MantidKernel/TimeSeriesProperty.h" #include <cxxtest/TestSuite.h> @@ -16,7 +15,6 @@ using namespace Mantid; using namespace Mantid::API; using namespace Mantid::Kernel; using namespace Mantid::DataHandling; -using namespace Mantid::DataObjects; class LoadMappingTableTest : public CxxTest::TestSuite { diff --git a/Code/Mantid/Framework/DataHandling/test/LoadMuonNexus1Test.h b/Code/Mantid/Framework/DataHandling/test/LoadMuonNexus1Test.h index f796c0d1b02..4e942bf6cc6 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadMuonNexus1Test.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadMuonNexus1Test.h @@ -16,7 +16,6 @@ #include "MantidDataHandling/LoadMuonNexus1.h" #include "MantidAPI/WorkspaceFactory.h" -#include "MantidDataObjects/ManagedWorkspace2D.h" #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/FrameworkManager.h" #include "MantidKernel/ConfigService.h" diff --git a/Code/Mantid/Framework/DataHandling/test/LoadMuonNexus2Test.h b/Code/Mantid/Framework/DataHandling/test/LoadMuonNexus2Test.h index 0d145fdbf48..e7841302387 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadMuonNexus2Test.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadMuonNexus2Test.h @@ -13,7 +13,6 @@ #include "MantidDataHandling/LoadMuonNexus2.h" #include "MantidAPI/WorkspaceFactory.h" -#include "MantidDataObjects/ManagedWorkspace2D.h" #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/FrameworkManager.h" #include "MantidKernel/ConfigService.h" diff --git a/Code/Mantid/Framework/DataHandling/test/LoadRaw3Test.h b/Code/Mantid/Framework/DataHandling/test/LoadRaw3Test.h index aca30ad8910..6114749f8c7 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadRaw3Test.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadRaw3Test.h @@ -6,7 +6,6 @@ #include "MantidAPI/WorkspaceFactory.h" #include "MantidAPI/WorkspaceGroup.h" #include "MantidDataHandling/LoadRaw3.h" -#include "MantidDataObjects/ManagedWorkspace2D.h" #include "MantidGeometry/Instrument.h" #include "MantidGeometry/Instrument/Detector.h" #include "MantidKernel/ConfigService.h" @@ -389,7 +388,6 @@ public: TS_ASSERT_THROWS_NOTHING( loader4.execute() ) TS_ASSERT( loader4.isExecuted() ) - // Get back workspace and check it really is a ManagedWorkspace2D Workspace_sptr output; TS_ASSERT_THROWS_NOTHING( output = AnalysisDataService::Instance().retrieve("parameterIDF") ); @@ -890,56 +888,6 @@ public: } - void testWithManagedWorkspace() - { - ConfigServiceImpl& conf = ConfigService::Instance(); - const std::string managed = "ManagedWorkspace.LowerMemoryLimit"; - const std::string oldValue = conf.getString(managed); - conf.setString(managed,"0"); - - LoadRaw3 loader4; - loader4.initialize(); - loader4.setPropertyValue("Filename", inputFile); - loader4.setPropertyValue("OutputWorkspace", "managedws2"); - TS_ASSERT_THROWS_NOTHING( loader4.execute() ) - TS_ASSERT( loader4.isExecuted() ) - - // Get back workspace and check it really is a ManagedWorkspace2D - Workspace_sptr output; - TS_ASSERT_THROWS_NOTHING( output = AnalysisDataService::Instance().retrieve("managedws2") ); - TS_ASSERT( dynamic_cast<ManagedWorkspace2D*>(output.get()) ) - - AnalysisDataService::Instance().remove("managedws2"); - conf.setString(managed,oldValue); - } - - void testSeparateMonitorsWithManagedWorkspace() - { - ConfigServiceImpl& conf = ConfigService::Instance(); - const std::string managed = "ManagedWorkspace.LowerMemoryLimit"; - const std::string oldValue = conf.getString(managed); - conf.setString(managed,"0"); - - LoadRaw3 loader8; - loader8.initialize(); - loader8.setPropertyValue("Filename", inputFile); - loader8.setPropertyValue("OutputWorkspace", "managedws2"); - loader8.setPropertyValue("LoadMonitors", "Separate"); - TS_ASSERT_THROWS_NOTHING( loader8.execute() ) - TS_ASSERT( loader8.isExecuted() ) - - // Get back workspace and check it really is a ManagedWorkspace2D - Workspace_sptr output; - TS_ASSERT_THROWS_NOTHING( output = AnalysisDataService::Instance().retrieve("managedws2") ); - TS_ASSERT( dynamic_cast<ManagedWorkspace2D*>(output.get()) ) - Workspace_sptr output1; - TS_ASSERT_THROWS_NOTHING( output1 = AnalysisDataService::Instance().retrieve("managedws2_Monitors") ); - // TS_ASSERT( dynamic_cast<ManagedWorkspace2D*>(output1.get()) ) - AnalysisDataService::Instance().remove("managedws2"); - AnalysisDataService::Instance().remove("managedws2_Monitors"); - conf.setString(managed,oldValue); - } - void testExecWithRawDatafile_s_type() { LoadRaw3 loader12; diff --git a/Code/Mantid/Framework/DataHandling/test/LoadRawBin0Test.h b/Code/Mantid/Framework/DataHandling/test/LoadRawBin0Test.h index e6014d57969..6a9528ee5a7 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadRawBin0Test.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadRawBin0Test.h @@ -5,7 +5,6 @@ #include "MantidDataHandling/LoadRawBin0.h" #include "MantidAPI/WorkspaceFactory.h" -#include "MantidDataObjects/ManagedWorkspace2D.h" #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/FrameworkManager.h" #include "MantidKernel/ConfigService.h" diff --git a/Code/Mantid/Framework/DataHandling/test/LoadRawSpectrum0Test.h b/Code/Mantid/Framework/DataHandling/test/LoadRawSpectrum0Test.h index b96665896b0..6fc2de8f379 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadRawSpectrum0Test.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadRawSpectrum0Test.h @@ -5,7 +5,6 @@ #include "MantidDataHandling/LoadRawSpectrum0.h" #include "MantidAPI/WorkspaceFactory.h" -#include "MantidDataObjects/ManagedWorkspace2D.h" #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/FrameworkManager.h" #include "MantidKernel/ConfigService.h" diff --git a/Code/Mantid/Framework/DataObjects/CMakeLists.txt b/Code/Mantid/Framework/DataObjects/CMakeLists.txt index 7bc5229f482..8a90f3cfe0d 100644 --- a/Code/Mantid/Framework/DataObjects/CMakeLists.txt +++ b/Code/Mantid/Framework/DataObjects/CMakeLists.txt @@ -1,5 +1,4 @@ set ( SRC_FILES - src/AbsManagedWorkspace2D.cpp src/EventList.cpp src/EventWorkspace.cpp src/EventWorkspaceHelpers.cpp @@ -7,9 +6,6 @@ set ( SRC_FILES src/Events.cpp src/GroupingWorkspace.cpp src/Histogram1D.cpp - src/ManagedDataBlock2D.cpp - src/ManagedHistogram1D.cpp - src/ManagedWorkspace2D.cpp src/MaskWorkspace.cpp src/MementoTableWorkspace.cpp src/OffsetsWorkspace.cpp @@ -33,7 +29,6 @@ set ( SRC_UNITY_IGNORE_FILES ) set ( INC_FILES - inc/MantidDataObjects/AbsManagedWorkspace2D.h inc/MantidDataObjects/DllConfig.h inc/MantidDataObjects/EventList.h inc/MantidDataObjects/EventWorkspace.h @@ -42,9 +37,6 @@ set ( INC_FILES inc/MantidDataObjects/Events.h inc/MantidDataObjects/GroupingWorkspace.h inc/MantidDataObjects/Histogram1D.h - inc/MantidDataObjects/ManagedDataBlock2D.h - inc/MantidDataObjects/ManagedHistogram1D.h - inc/MantidDataObjects/ManagedWorkspace2D.h inc/MantidDataObjects/MaskWorkspace.h inc/MantidDataObjects/MementoTableWorkspace.h inc/MantidDataObjects/OffsetsWorkspace.h @@ -69,9 +61,6 @@ set ( TEST_FILES GroupingWorkspaceTest.h Histogram1DTest.h LibraryManagerTest.h - ManagedDataBlock2DTest.h - ManagedHistogram1DTest.h - ManagedWorkspace2DTest.h MaskWorkspaceTest.h MementoTableWorkspaceTest.h OffsetsWorkspaceTest.h diff --git a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/AbsManagedWorkspace2D.h b/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/AbsManagedWorkspace2D.h deleted file mode 100644 index 4452e2f2356..00000000000 --- a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/AbsManagedWorkspace2D.h +++ /dev/null @@ -1,158 +0,0 @@ -#ifndef ABSMANAGEDWORKSPACE2D_H -#define ABSMANAGEDWORKSPACE2D_H - -#include "MantidDataObjects/Workspace2D.h" -#include "MantidKernel/MRUList.h" -#include "MantidDataObjects/ManagedDataBlock2D.h" - -namespace Mantid -{ -namespace DataObjects -{ - - /** For use in the AbsManagedWorkspace2D MRU list */ - class ManagedDataBlockMRUMarker - { - public: - /** Constructor - * @param dataBlockIndex :: index of the data block in the list of data blocks of the ManagedWorkspace2D - */ - ManagedDataBlockMRUMarker(size_t dataBlockIndex) - : m_index(dataBlockIndex) - { - } - - /// Function returns a unique index, used for hashing for MRU list - size_t hashIndexFunction() const - { - return m_index; - } - - /// @return index of the data block in the list of data blocks of the ManagedWorkspace2D - size_t getBlockIndex() const - { - return m_index; - } - - private: - size_t m_index; ///< unique index of a data block - - }; - - - - /** AbsManagedWorkspace2D - - This is an abstract class for a managed workspace. - Implementations must override init(..) which sets m_vectorsPerBlock and - readDataBlock(..) and writeDataBlock(..) - - Copyright © 2008-2012 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National 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://github.com/mantidproject/mantid>. - Code Documentation is available at: <http://doxygen.mantidproject.org> - */ - class DLLExport AbsManagedWorkspace2D : public Workspace2D - { - friend class ManagedHistogram1D; - - protected: - /// Most-Recently-Used list of markers of ManagedDataBlocks objects. - typedef Mantid::Kernel::MRUList<ManagedDataBlockMRUMarker> mru_list; - - public: - AbsManagedWorkspace2D(); - virtual ~AbsManagedWorkspace2D(); - - virtual const std::string id() const {return "AbsManagedWorkspace2D";} - - /// Return the underlying ISpectrum ptr at the given workspace index. - virtual Mantid::API::ISpectrum * getSpectrum(const size_t index); - - /// Return the underlying ISpectrum ptr (const version) at the given workspace index. - virtual const Mantid::API::ISpectrum * getSpectrum(const size_t index) const; - - //section required for iteration - virtual std::size_t size() const; - virtual std::size_t blocksize() const; - - /// Returns the size of physical memory the workspace takes - virtual size_t getMemorySize() const = 0; - - /// Managed workspaces are not really thread-safe (and parallel file access - /// would be silly anyway) - virtual bool threadSafe() const { return false; } - - protected: - /// Vector of the data blocks contained. All blocks are in memory but their contents might be empty - std::vector<ManagedDataBlock2D *> m_blocks; - - /// Initialize - virtual void init(const std::size_t &NVectors, const std::size_t &XLength, const std::size_t &YLength); - - /// Init the blocks alone - void initBlocks(); - - /// Number of blocks in temporary storage - std::size_t getNumberBlocks() const - { - return m_bufferedMarkers.size(); - } - - /// Get a data block for a workspace index - ManagedDataBlock2D* getDataBlock(const std::size_t index) const; - - /// Get and read in a data block only if required by the MRU lsit - void readDataBlockIfNeeded(const std::size_t index) const; - - /// Reads in a data block. - virtual void readDataBlock(ManagedDataBlock2D *newBlock,size_t startIndex)const = 0; - /// Saves the dropped data block to disk. - virtual void writeDataBlock(ManagedDataBlock2D *toWrite) const = 0; - - /// The number of vectors in each data block - std::size_t m_vectorsPerBlock; - /// The length of the X vector in each Histogram1D. Must all be the same. - std::size_t m_XLength; - /// The length of the Y & E vectors in each Histogram1D. Must all be the same. - std::size_t m_YLength; - /// The size in bytes of each vector - std::size_t m_vectorSize; - /// The size in bytes of one block - std::size_t m_blockSize; - - /// Markers used only to track which data blocks to release - mutable mru_list m_bufferedMarkers; - - private: - // Make copy constructor and copy assignment operator private (and without definition) unless they're needed - /// Private copy constructor - AbsManagedWorkspace2D(const AbsManagedWorkspace2D&); - /// Private copy assignment operator - AbsManagedWorkspace2D& operator=(const AbsManagedWorkspace2D&); - - virtual std::size_t getHistogramNumberHelper() const; - - public: - - }; - -} // namespace DataObjects -} // namespace Mantid - -#endif /* ABSMANAGEDWORKSPACE2D_H */ diff --git a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/Histogram1D.h b/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/Histogram1D.h index f6bb7b74f38..deeb407c215 100644 --- a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/Histogram1D.h +++ b/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/Histogram1D.h @@ -4,21 +4,15 @@ #include "MantidAPI/ISpectrum.h" #include "MantidKernel/cow_ptr.h" #include "MantidKernel/System.h" -#include <boost/shared_ptr.hpp> -#include <vector> namespace Mantid { namespace DataObjects { /** - 1D histogram implementation. + 1D histogram implementation. - \class Histogram1D Histogram1D.h - \author Laurent C Chapon, ISIS, RAL - \date 26/09/2007 - - Copyright © 2007-8 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory + Copyright © 2007-2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory This file is part of Mantid. @@ -40,15 +34,6 @@ namespace DataObjects */ class DLLExport Histogram1D : public Mantid::API::ISpectrum { - friend class ManagedDataBlock2D; - -public: - - // The data storage type used internally in a Histogram1D - // typedef std::vector<double> MantidVec; //Removed redundant typedef - // Data Store: NOTE:: CHANGED TO BREAK THE WRONG USEAGE OF SHARED_PTR - //typedef Kernel::cow_ptr<MantidVec > MantidVecPtr; - protected: MantidVecPtr refY; ///< RefCounted Y MantidVecPtr refE; ///< RefCounted Error diff --git a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/ManagedDataBlock2D.h b/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/ManagedDataBlock2D.h deleted file mode 100644 index b3339d32e59..00000000000 --- a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/ManagedDataBlock2D.h +++ /dev/null @@ -1,109 +0,0 @@ -#ifndef MANTID_DATAOBJECTS_MANAGEDDATABLOCK2D_H_ -#define MANTID_DATAOBJECTS_MANAGEDDATABLOCK2D_H_ - -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAPI/ISpectrum.h" -#include "MantidDataObjects/DllConfig.h" -#include "MantidDataObjects/Histogram1D.h" -#include "MantidDataObjects/ManagedHistogram1D.h" -#include "MantidKernel/cow_ptr.h" -#include <fstream> -#include <vector> - -namespace Mantid -{ - -namespace DataObjects -{ -/** Stores a block of 2D data. - The data storage is the same as that of a Workspace2D (i.e. a vector of Histogram1D's), - but no sample, instrument or history data is held here. - The class supports the Workspace iterators. - - Copyright © 2008-2012 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National 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://github.com/mantidproject/mantid>. - Code Documentation is available at: <http://doxygen.mantidproject.org> -*/ -class DLLExport ManagedDataBlock2D -{ - /// Output a string representation to a stream - friend DLLExport std::fstream& operator<<(std::fstream&, ManagedDataBlock2D&); - /// Input a string representation to a stream - friend DLLExport std::fstream& operator>>(std::fstream&, ManagedDataBlock2D&); - -public: - ManagedDataBlock2D(const std::size_t &minIndex, const std::size_t &noVectors, const std::size_t &XLength, const std::size_t &YLength, - AbsManagedWorkspace2D * parentWS, MantidVecPtr sharedDx); - virtual ~ManagedDataBlock2D(); - - void initialize(); - - int minIndex() const; - bool hasChanges() const; - void hasChanges(bool has); - - void releaseData(); - - size_t getNumSpectra() const - { return m_data.size(); } - - /// Return the underlying ISpectrum ptr at the given workspace index. - virtual Mantid::API::ISpectrum * getSpectrum(const size_t index); - - /// Return the underlying ISpectrum ptr (const version) at the given workspace index. - virtual const Mantid::API::ISpectrum * getSpectrum(const size_t index) const; - - //------------------------------------------------------------------------ - /// @return true if the data was loaded from disk - bool isLoaded() const - { return m_loaded; } - - /** Set the loaded flag - * @param loaded :: bool flag value */ - void setLoaded(bool loaded) - { m_loaded = loaded; } - - -private: - // Make copy constructor and copy assignment operator private (and without definition) unless they're needed - /// Private copy constructor - ManagedDataBlock2D(const ManagedDataBlock2D&); - /// Private copy assignment operator - ManagedDataBlock2D& operator=(const ManagedDataBlock2D&); - - /// The data 'chunk'. NOTE: These pointers are owned by Workspace2D! - std::vector<ManagedHistogram1D *> m_data; - - /// The length of the X vector in each Histogram1D. Must all be the same. - const std::size_t m_XLength; - /// The length of the Y & E vectors in each Histogram1D. Must all be the same. - const std::size_t m_YLength; - /// The index of the workspace that this datablock starts from. - const std::size_t m_minIndex; - - /// Is the data block initialized or loaded from disk? - bool m_loaded; -}; - -} // namespace DataObjects -} // namespace Mantid - -#endif /*MANTID_DATAOBJECTS_MANAGEDDATABLOCK2D_H_*/ diff --git a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/ManagedHistogram1D.h b/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/ManagedHistogram1D.h deleted file mode 100644 index d52a9517e1f..00000000000 --- a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/ManagedHistogram1D.h +++ /dev/null @@ -1,207 +0,0 @@ -#ifndef MANTID_DATAOBJECTS_MANAGEDHISTOGRAM1D_H_ -#define MANTID_DATAOBJECTS_MANAGEDHISTOGRAM1D_H_ - -#include "MantidKernel/System.h" -#include "MantidAPI/ISpectrum.h" -#include "MantidDataObjects/Histogram1D.h" -//#include "MantidDataObjects/AbsManagedWorkspace2D.h" -//#include "MantidDataObjects/ManagedDataBlock2D.h" - - -namespace Mantid -{ -namespace DataObjects -{ - - // Forward declaration - class AbsManagedWorkspace2D; - - /** A "managed" version of Histogram1D where the - * data is loaded only when required - - @author Janik Zikovsky - @date 2011-07-26 - - Copyright © 2011 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National 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://github.com/mantidproject/mantid> - Code Documentation is available at: <http://doxygen.mantidproject.org> - */ - class DLLExport ManagedHistogram1D : public Histogram1D //Mantid::API::ISpectrum - { - public: - friend class ManagedDataBlock2D; - - ManagedHistogram1D(AbsManagedWorkspace2D * parentWS, size_t workspaceIndex); - - ManagedHistogram1D(const ManagedHistogram1D&); - ManagedHistogram1D& operator=(const ManagedHistogram1D&); - virtual ~ManagedHistogram1D(); - - //------------------------------------------------------------------------ - /** Method that retrieves the data from the disk - * if needed. - */ - void retrieveData() const; - - /** Method that clears the data vectors to release - * memory when the spectrum can be released to disk. - */ - void releaseData(); - - // ------------ Y/E data setters ----------------------------- - /// Sets the data. - void setData(const MantidVec& Y) - { retrieveData(); refY.access()=Y; m_dirty=true; } - /// Sets the data and errors - void setData(const MantidVec& Y, const MantidVec& E) - { retrieveData(); refY.access()=Y; refE.access()=E; m_dirty=true; } - - /// Sets the data. - void setData(const MantidVecPtr& Y) - { retrieveData(); refY=Y; m_dirty=true; } - /// Sets the data and errors - void setData(const MantidVecPtr& Y, const MantidVecPtr& E) - { retrieveData(); refY=Y; refE=E; m_dirty=true; } - - /// Sets the data. - void setData(const MantidVecPtr::ptr_type& Y) - { retrieveData(); refY=Y; m_dirty=true; } - /// Sets the data and errors - void setData(const MantidVecPtr::ptr_type& Y, const MantidVecPtr::ptr_type& E) - { retrieveData(); refY=Y; refE=E; m_dirty=true; } - - /// Zero the data (Y&E) in this spectrum - void clearData(); - - // ------------ Y/E data accessors ----------------------------- - // Get the array data - /// Returns the y data const - virtual const MantidVec& dataY() const - { retrieveData(); return *refY; } - /// Returns the error data const - virtual const MantidVec& dataE() const - { retrieveData(); return *refE; } - - ///Returns the y data - virtual MantidVec& dataY() - { retrieveData(); m_dirty=true; return refY.access(); } - ///Returns the error data - virtual MantidVec& dataE() - { retrieveData(); m_dirty=true; return refE.access(); } - - /// Returns the y data const - virtual const MantidVec& readY() const - { retrieveData(); return *refY; } - /// Returns the error data const - virtual const MantidVec& readE() const - { retrieveData(); return *refE; } - - // ------------ X data accessors ----------------------------- - virtual void setX(const MantidVec& X) - { retrieveData(); refX.access()=X; m_dirty = true; } - - virtual void setX(const MantidVecPtr& X) - { retrieveData(); refX=X; m_dirty = true; } - - virtual void setX(const MantidVecPtr::ptr_type& X) - { retrieveData(); refX=X; m_dirty = true; } - - virtual MantidVec& dataX() - { retrieveData(); m_dirty = true; - return refX.access(); } - - virtual const MantidVec& dataX() const - { retrieveData(); - return *refX; } - - virtual const MantidVec& readX() const - { retrieveData(); - return *refX; } - - virtual MantidVecPtr ptrX() const - { retrieveData(); m_dirty = true; - return refX; } - - virtual std::size_t size() const - { retrieveData(); - return refY->size(); - } - - /// Checks for errors - bool isError() const - { retrieveData(); - return refE->empty(); - } - - /// Gets the memory size of the histogram - size_t getMemorySize() const - { return ((refX->size()+refY->size()+refE->size())*sizeof(double)); } - - //------------------------------------------------------------------------ - /// @return true if the data was modified. - bool isDirty() const - { return m_dirty; } - - /** Set the dirty flag - * @param dirty :: bool flag value */ - void setDirty(bool dirty) - { m_dirty = dirty; } - - //------------------------------------------------------------------------ - /// @return true if the data was loaded from disk - bool isLoaded() const - { return m_loaded; } - - /** Set the loaded flag - * @param loaded :: bool flag value */ - void setLoaded(bool loaded) - { m_loaded = loaded; } - - //------------------------------------------------------------------------ - /// @return m_workspaceIndex (for debugging mostly) - size_t getWorkspaceIndex() const - { return m_workspaceIndex; } - - protected: - /// Are the data vectors loaded from the disk? - mutable bool m_loaded; - - /// Was the data modified? - mutable bool m_dirty; - - /// Workspace that owns this histogram - AbsManagedWorkspace2D * m_parentWorkspace; - - /// Index in m_parentWorkspace - size_t m_workspaceIndex; - - public: - // ------------ Direct data accessors, for use by ManagedDataBlock2D ----------------------------- - MantidVec& directDataX() { return refX.access(); } - MantidVec& directDataY() { return refY.access(); } - MantidVec& directDataE() { return refE.access(); } - void directSetX(boost::shared_ptr<MantidVec> newX) { refX = newX; } - - }; - - -} // namespace DataObjects -} // namespace Mantid - -#endif /* MANTID_DATAOBJECTS_MANAGEDHISTOGRAM1D_H_ */ diff --git a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/ManagedWorkspace2D.h b/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/ManagedWorkspace2D.h deleted file mode 100644 index 8bbbd84b26b..00000000000 --- a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/ManagedWorkspace2D.h +++ /dev/null @@ -1,98 +0,0 @@ -#ifndef MANTID_DATAOBJECTS_MANAGEDWORKSPACE2D_H_ -#define MANTID_DATAOBJECTS_MANAGEDWORKSPACE2D_H_ - -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidDataObjects/AbsManagedWorkspace2D.h" - -namespace Mantid -{ -namespace DataObjects -{ -/** The ManagedWorkspace2D allows the framework to handle 2D datasets that are too - large to fit in the available system memory by making use of a temporary file. - It is a specialisation of Workspace2D. - - The optional configuration property ManagedWorkspace.DataBlockSize sets the size - (in bytes) of the blocks used to internally buffer data. The default is 1MB. - - @author Russell Taylor, Tessella Support Services plc - @date 22/01/2008 - - Copyright © 2008-2011 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National 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://github.com/mantidproject/mantid>. - Code Documentation is available at: <http://doxygen.mantidproject.org> -*/ -class DLLExport ManagedWorkspace2D : public AbsManagedWorkspace2D -{ -public: - ManagedWorkspace2D(); - virtual ~ManagedWorkspace2D(); - - virtual const std::string id() const {return "ManagedWorkspace2D";} - - virtual size_t getMemorySize() const; - virtual bool threadSafe() const { return false; } - - std::string get_filename() const; - - /// Get number of temporary files used to store the data. - size_t getNumberFiles() const {return m_datafile.size();} - -protected: - - /// Reads in a data block. - virtual void readDataBlock(ManagedDataBlock2D *newBlock,std::size_t startIndex)const; - /// Saves the dropped data block to disk. - virtual void writeDataBlock(ManagedDataBlock2D *toWrite) const; - -private: - // Make copy constructor and copy assignment operator private (and without definition) unless they're needed - /// Private copy constructor - ManagedWorkspace2D(const ManagedWorkspace2D&); - /// Private copy assignment operator - ManagedWorkspace2D& operator=(const ManagedWorkspace2D&); - - virtual void init(const std::size_t &NVectors, const std::size_t &XLength, const std::size_t &YLength); - - virtual std::size_t getHistogramNumberHelper() const; - - ManagedDataBlock2D* getDataBlock(const std::size_t index) const; - - /// The number of blocks per temporary file - std::size_t m_blocksPerFile; - /// Size of each temp file in bytes - long long m_fileSize; - - /// The name of the temporary file - std::string m_filename; - /// The stream handle to the temporary file used to store the data - mutable std::vector<std::fstream*> m_datafile; - /// Index written up to in temporary file - mutable int m_indexWrittenTo; - - /// Static instance count. Used to ensure temporary filenames are distinct. - static int g_uniqueID; -}; - -} // namespace DataObjects -} // namespace Mantid - -#endif /*MANTID_DATAOBJECTS_MANAGEDWORKSPACE2D_H_*/ diff --git a/Code/Mantid/Framework/DataObjects/src/AbsManagedWorkspace2D.cpp b/Code/Mantid/Framework/DataObjects/src/AbsManagedWorkspace2D.cpp deleted file mode 100644 index eb3b62ba560..00000000000 --- a/Code/Mantid/Framework/DataObjects/src/AbsManagedWorkspace2D.cpp +++ /dev/null @@ -1,199 +0,0 @@ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidDataObjects/AbsManagedWorkspace2D.h" -#include "MantidDataObjects/Workspace2D.h" -#include "MantidDataObjects/ManagedDataBlock2D.h" -#include "MantidAPI/ISpectrum.h" -#include "MantidAPI/RefAxis.h" -#include "MantidAPI/SpectraAxis.h" -#include "MantidKernel/ConfigService.h" - -#include <fstream> -#include <valarray> - -#include <boost/multi_index_container.hpp> -#include <boost/multi_index/sequenced_index.hpp> -#include <boost/multi_index/hashed_index.hpp> -#include <boost/multi_index/mem_fun.hpp> - -using Mantid::API::ISpectrum; - -namespace Mantid -{ -namespace DataObjects -{ - -using std::size_t; - - -/// Constructor -AbsManagedWorkspace2D::AbsManagedWorkspace2D() : -Workspace2D() -{ -} - - -//------------------------------------------------------------------------------ -/** Sets the size of the workspace and sets up the temporary file. - * The m_vectorsPerBlock value needs to be set by now. - * -* @param NVectors :: The number of vectors/histograms/detectors in the workspace -* @param XLength :: The number of X data points/bin boundaries in each vector (must all be the same) -* @param YLength :: The number of data/error points in each vector (must all be the same) -* @throw std::runtime_error if unable to open a temporary file -*/ -void AbsManagedWorkspace2D::init(const std::size_t &NVectors, const std::size_t &XLength, const std::size_t &YLength) -{ - m_noVectors = NVectors; - m_axes.resize(2); - m_axes[0] = new API::RefAxis(XLength, this); - m_axes[1] = new API::SpectraAxis(this); - m_XLength = XLength; - m_YLength = YLength; -} - -//------------------------------------------------------------------------------ -/** Create all the blocks and spectra in the workspace - * The m_vectorsPerBlock value needs to be set by now. - * Must be called AFTER init() - * - */ -void AbsManagedWorkspace2D::initBlocks() -{ - // Make a default-0 DX vector (X error vector). It will be shared by all spectra - MantidVecPtr sharedDx; - sharedDx.access().resize(m_XLength, 0.0); - - // Create all the data bloocks - m_blocks.clear(); - for (size_t i=0; i<m_noVectors; i += m_vectorsPerBlock) - { - // Ensure the last block has the right # of vectors - size_t numVectorsInThisBlock = m_vectorsPerBlock; - if ((i + numVectorsInThisBlock) > m_noVectors) numVectorsInThisBlock = m_noVectors - i; - // Each ManagedDataBlock2D will create its own vectors. - ManagedDataBlock2D * block = new ManagedDataBlock2D(i, numVectorsInThisBlock, m_XLength, m_YLength, this, sharedDx ); - m_blocks.push_back( block ); - } - - // Copy the pointers over into the Workspace2D thing - data.resize(m_noVectors, NULL); - for (size_t i=0; i<m_noVectors; i++) - data[i] = this->getSpectrum(i); -} - - - -/// Destructor. Clears the buffer and deletes the temporary file. -AbsManagedWorkspace2D::~AbsManagedWorkspace2D() -{ - // Clear MRU list (minor amount of memory) - m_bufferedMarkers.clear(); - // Delete the blocks (big memory); - for (size_t i=0; i<m_blocks.size(); i++) - delete m_blocks[i]; - m_blocks.clear(); -} - -/// Get pseudo size -size_t AbsManagedWorkspace2D::size() const -{ - return m_noVectors * blocksize(); -} - -/// Get the size of each vector -size_t AbsManagedWorkspace2D::blocksize() const -{ - return (m_noVectors > 0) ? m_YLength : 0; -} - - -//-------------------------------------------------------------------------------------------- -/// Return the underlying ISpectrum ptr at the given workspace index. -ISpectrum * AbsManagedWorkspace2D::getSpectrum(const size_t index) -{ - if (index>=m_noVectors) - throw std::range_error("AbsManagedWorkspace2D::getSpectrum, histogram number out of range"); - ISpectrum * spec = getDataBlock(index)->getSpectrum(index); - return spec; -} - - -const ISpectrum * AbsManagedWorkspace2D::getSpectrum(const size_t index) const -{ - if (index>=m_noVectors) - throw std::range_error("AbsManagedWorkspace2D::getSpectrum, histogram number out of range"); - - ISpectrum * spec = const_cast<ISpectrum*>(getDataBlock(index)->getSpectrum(index)); - return spec; -} - -//-------------------------------------------------------------------------------------------- -/** Returns the number of histograms. - * For some reason Visual Studio couldn't deal with the main getHistogramNumber() method - * being virtual so it now just calls this private (and virtual) method which does the work. - * @return the number of histograms associated with the workspace - */ -size_t AbsManagedWorkspace2D::getHistogramNumberHelper() const -{ - return m_noVectors; -} - - -//-------------------------------------------------------------------------------------------- -/** Get a pointer to the data block containing the data corresponding to a given index -* @param index :: The index to search for -* @return A pointer to the data block containing the index requested -*/ -// not really a const method, but need to pretend it is so that const data getters can call it -ManagedDataBlock2D* AbsManagedWorkspace2D::getDataBlock(const std::size_t index) const -{ - // Which clock does this correspond to? - size_t blockIndex = index / m_vectorsPerBlock; - // Address of that block - return const_cast<ManagedDataBlock2D*>(m_blocks[blockIndex]); -} - - -/** Get and read in a data block only if required by the MRU lsit - * - * @param index :: workspace index of the spectrum wanted - */ -void AbsManagedWorkspace2D::readDataBlockIfNeeded(const std::size_t index) const -{ - // Which block does this correspond to? - size_t blockIndex = index / m_vectorsPerBlock; - - // Read it in first. - ManagedDataBlock2D* readBlock = const_cast<ManagedDataBlock2D*>(m_blocks[blockIndex]); - this->readDataBlock(readBlock, readBlock->minIndex()); - - // Mark that this latest-read block was recently read into the MRU list - ManagedDataBlockMRUMarker * markerToDrop = m_bufferedMarkers.insert( - new ManagedDataBlockMRUMarker(blockIndex)); - - // Do we need to drop out a data block? - if (markerToDrop) - { - size_t dropIndex = markerToDrop->getBlockIndex(); - //std::cout << "Dropping block at " << dropIndex << " when asked to read block " << blockIndex << std::endl; - delete markerToDrop; - if (dropIndex < m_blocks.size()) - { - // Address of that block - ManagedDataBlock2D* droppedBlock = const_cast<ManagedDataBlock2D*>(m_blocks[dropIndex]); - // Write it to disk only when needed - if (droppedBlock->hasChanges()) - this->writeDataBlock(droppedBlock); - // Free up the memory - droppedBlock->releaseData(); - } - } - - -} - - -} // namespace DataObjects -} // namespace Mantid diff --git a/Code/Mantid/Framework/DataObjects/src/ManagedDataBlock2D.cpp b/Code/Mantid/Framework/DataObjects/src/ManagedDataBlock2D.cpp deleted file mode 100644 index f5e56b78689..00000000000 --- a/Code/Mantid/Framework/DataObjects/src/ManagedDataBlock2D.cpp +++ /dev/null @@ -1,206 +0,0 @@ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAPI/ISpectrum.h" -#include "MantidAPI/WorkspaceFactory.h" -#include "MantidDataObjects/ManagedDataBlock2D.h" -#include "MantidDataObjects/ManagedHistogram1D.h" -#include "MantidKernel/Exception.h" -#include <iostream> - -using Mantid::API::ISpectrum; - -namespace Mantid -{ -namespace DataObjects -{ - namespace - { - /// static logger - Kernel::Logger g_log("ManagedDataBlock2D"); - } - -using std::size_t; - - - -/** Constructor. - * @param minIndex :: The index of the workspace that this data block starts at - * @param NVectors :: The number of Histogram1D's in this data block - * @param XLength :: The number of elements in the X data - * @param YLength :: The number of elements in the Y/E data - * @param parentWS :: The workspace that owns this block - * @param sharedDx :: A cow-ptr to a correctly-sized DX vector that every spectrum will share (until written to). - */ -ManagedDataBlock2D::ManagedDataBlock2D(const std::size_t &minIndex, const std::size_t &NVectors, - const std::size_t &XLength, const std::size_t &YLength, AbsManagedWorkspace2D * parentWS, MantidVecPtr sharedDx) : - m_XLength(XLength), m_YLength(YLength), m_minIndex(minIndex), m_loaded(false) -{ -// MantidVecPtr t1; -// t1.access().resize(XLength); //this call initializes array to zero - - m_data.clear(); - for (size_t i=0; i<NVectors; i++) - { - m_data.push_back( new ManagedHistogram1D(parentWS, minIndex+i) ); - m_data[i]->setDx(sharedDx); - //TODO: Anything about Dx? - } - if (!parentWS) - this->initialize(); -} - -//----------------------------------------------------------------------- -/** Initialize the vectors to empty values */ -void ManagedDataBlock2D::initialize() -{ - for (size_t i=0; i<m_data.size(); i++) - { - // Initialize the vectors if no workspace is passed - m_data[i]->directDataX().resize(m_XLength, 0.0); - m_data[i]->directDataY().resize(m_YLength, 0.0); - m_data[i]->directDataE().resize(m_YLength, 0.0); - // It was 'loaded' so it won't get re-initialized in this block - m_data[i]->setLoaded(true); - } - this->m_loaded = true; -} - -/// Virtual destructor -ManagedDataBlock2D::~ManagedDataBlock2D() -{ - // Do nothing: Workspace2D owns the pointer!!! -} - -/// The minimum index of the workspace data that this data block contains -int ManagedDataBlock2D::minIndex() const // TODO this should return size_t but it breaks lots of things -{ - return static_cast<int>(m_minIndex); -} - -/** Flags whether the data has changed since being read in. - * In fact indicates whether the data has been accessed in a non-const fashion. - * @return True if the data has been changed. - */ -bool ManagedDataBlock2D::hasChanges() const -{ - bool hasChanges = false; - for (std::vector<ManagedHistogram1D*>::const_iterator iter = m_data.begin(); iter != m_data.end(); ++iter) - { - const ManagedHistogram1D * it = *iter; - hasChanges = hasChanges || it->isDirty(); - } - return hasChanges; -} - -/** Gives the possibility to drop the flag. Used in ManagedRawFileWorkspace2D atfer - * reading in from a raw file. - * @param has :: True if the data has been changed. - */ -void ManagedDataBlock2D::hasChanges(bool has) -{ - for (std::vector<ManagedHistogram1D*>::iterator iter = m_data.begin(); iter != m_data.end(); ++iter) - { - ManagedHistogram1D * it = *iter; - it->m_dirty = has; - } -} - - - -//-------------------------------------------------------------------------------------------- -/// Return the underlying ISpectrum ptr at the given workspace index. -ISpectrum * ManagedDataBlock2D::getSpectrum(const size_t index) -{ - if ( ( index < m_minIndex ) - || ( index >= m_minIndex + m_data.size() ) ) - throw std::range_error("ManagedDataBlock2D::getSpectrum, histogram number out of range"); - return m_data[index-m_minIndex]; -} - -const ISpectrum * ManagedDataBlock2D::getSpectrum(const size_t index) const -{ - if ( ( index < m_minIndex ) - || ( index >= m_minIndex + m_data.size() ) ) - throw std::range_error("ManagedDataBlock2D::getSpectrum, histogram number out of range"); - return m_data[index-m_minIndex]; -} - - -//-------------------------------------------------------------------------------------------- -/** Release the memory in the loaded data blocks */ -void ManagedDataBlock2D::releaseData() -{ - for (std::vector<ManagedHistogram1D*>::iterator iter = m_data.begin(); iter != m_data.end(); ++iter) - { - ManagedHistogram1D * it = *iter; - it->releaseData(); - } - this->m_loaded = false; -} - - - -/** Output file stream operator. - * @param fs :: The stream to write to - * @param data :: The object to write to file - * @return stream representation of data - */ -std::fstream& operator<<(std::fstream& fs, ManagedDataBlock2D& data) -{ - for (std::vector<ManagedHistogram1D*>::iterator iter = data.m_data.begin(); iter != data.m_data.end(); ++iter) - { - ManagedHistogram1D * it = *iter; - // If anyone's gone and changed the size of the vectors then get them back to the - // correct size, removing elements or adding zeroes as appropriate. - if (it->directDataX().size() != data.m_XLength) - { - it->directDataX().resize(data.m_XLength, 0.0); - g_log.warning() << "X vector resized to " << data.m_XLength << " elements."; - } - fs.write(reinterpret_cast<char *>(&(it->directDataX().front())), data.m_XLength * sizeof(double)); - if (it->directDataY().size() != data.m_YLength) - { - it->directDataY().resize(data.m_YLength, 0.0); - g_log.warning() << "Y vector resized to " << data.m_YLength << " elements."; - } - fs.write(reinterpret_cast<char *>(&(it->directDataY().front())), data.m_YLength * sizeof(double)); - if (it->directDataE().size() != data.m_YLength) - { - it->directDataE().resize(data.m_YLength, 0.0); - g_log.warning() << "E vector resized to " << data.m_YLength << " elements."; - } - fs.write(reinterpret_cast<char *>(&(it->directDataE().front())), data.m_YLength * sizeof(double)); - - // Clear the "dirty" flag since it was just written out. - it->setDirty(false); - } - return fs; -} - -/** Input file stream operator. - * @param fs :: The stream to read from - * @param data :: The object to fill with the read-in data - * @return stream representation of data - */ -std::fstream& operator>>(std::fstream& fs, ManagedDataBlock2D& data) -{ - // Assumes that the ManagedDataBlock2D passed in is the same size as the data to be read in - // Will be ManagedWorkspace2D's job to ensure that this is so - for (std::vector<ManagedHistogram1D*>::iterator iter = data.m_data.begin(); iter != data.m_data.end(); ++iter) - { - ManagedHistogram1D * it = *iter; - it->directDataX().resize(data.m_XLength, 0.0); - fs.read(reinterpret_cast<char *>(&(it->directDataX().front())), data.m_XLength * sizeof(double)); - it->directDataY().resize(data.m_YLength, 0.0); - fs.read(reinterpret_cast<char *>(&(it->directDataY().front())), data.m_YLength * sizeof(double)); - it->directDataE().resize(data.m_YLength, 0.0); - fs.read(reinterpret_cast<char *>(&(it->directDataE().front())), data.m_YLength * sizeof(double)); - // Yes, it is loaded - it->setLoaded(true); - } - return fs; -} - -} // namespace DataObjects -} // namespace Mantid diff --git a/Code/Mantid/Framework/DataObjects/src/ManagedHistogram1D.cpp b/Code/Mantid/Framework/DataObjects/src/ManagedHistogram1D.cpp deleted file mode 100644 index 4e060e5a8ac..00000000000 --- a/Code/Mantid/Framework/DataObjects/src/ManagedHistogram1D.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include "MantidDataObjects/ManagedHistogram1D.h" -#include "MantidKernel/System.h" -#include "MantidDataObjects/AbsManagedWorkspace2D.h" -#include "MantidDataObjects/ManagedWorkspace2D.h" - -namespace Mantid -{ -namespace DataObjects -{ - - - //---------------------------------------------------------------------------------------------- - /** Constructor - */ - ManagedHistogram1D::ManagedHistogram1D(AbsManagedWorkspace2D * parentWS, size_t workspaceIndex) - : m_loaded(false), m_dirty(false), - m_parentWorkspace(parentWS), m_workspaceIndex(workspaceIndex) - { - } - - //---------------------------------------------------------------------------------------------- - /** Destructor - */ - ManagedHistogram1D::~ManagedHistogram1D() - { - } - - - //------------------------------------------------------------------------ - /** Clear Y and E vectors */ - void ManagedHistogram1D::clearData() - { - retrieveData(); - m_dirty = true; - MantidVec & yValues = this->dataY(); - std::fill(yValues.begin(), yValues.end(), 0.0); - MantidVec & eValues = this->dataE(); - std::fill(eValues.begin(), eValues.end(), 0.0); - } - - - //------------------------------------------------------------------------ - /** Method that retrieves the data from the disk - * if needed. - */ - void ManagedHistogram1D::retrieveData() const - { - // Only load from disk when needed - if (!m_loaded) - { - if (m_parentWorkspace) - { - // This method will read in the data and fill in this (and other nearby) spectra - m_parentWorkspace->readDataBlockIfNeeded(m_workspaceIndex); - } - // OK, we're loaded - m_loaded = true; - // We have not modified anything yet. - m_dirty = false; - } - } - - - //------------------------------------------------------------------------ - /** Method that clears the data vectors to release - * memory when the spectrum can be released to disk. - * The data should have been saved already. - */ - void ManagedHistogram1D::releaseData() - { - if (m_loaded) - { - // Clear all the vectors to release the memory - refX.access().clear(); - MantidVec().swap(refX.access()); - refY.access().clear(); - MantidVec().swap(refY.access()); - refE.access().clear(); - MantidVec().swap(refE.access()); - // Note: we leave DX alone since it is kept in memory always. - // Reset Markers - m_loaded = false; - m_dirty = false; - } - } - -} // namespace Mantid -} // namespace DataObjects - diff --git a/Code/Mantid/Framework/DataObjects/src/ManagedWorkspace2D.cpp b/Code/Mantid/Framework/DataObjects/src/ManagedWorkspace2D.cpp deleted file mode 100644 index 07b69836b2e..00000000000 --- a/Code/Mantid/Framework/DataObjects/src/ManagedWorkspace2D.cpp +++ /dev/null @@ -1,322 +0,0 @@ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidDataObjects/ManagedWorkspace2D.h" -#include "MantidKernel/ConfigService.h" -#include "MantidAPI/RefAxis.h" -#include "MantidAPI/SpectraAxis.h" -#include "MantidAPI/WorkspaceFactory.h" -#include <limits> -#include <Poco/File.h> - -namespace Mantid -{ -namespace DataObjects -{ - - namespace - { - /// static logger - Kernel::Logger g_log("ManagedWorkspace2D"); - } - -using std::size_t; - -DECLARE_WORKSPACE(ManagedWorkspace2D) - -// Initialise the instance count -int ManagedWorkspace2D::g_uniqueID = 1; - -#ifdef _WIN32 -#pragma warning (push) -#pragma warning( disable:4355 ) -//Disable warning for using this in constructor. -//This is safe as long as the class that gets the pointer does not use any methods on it in it's constructor. -//In this case this is an inner class that is only used internally to this class, and is safe. -#endif //_WIN32 -/// Constructor -ManagedWorkspace2D::ManagedWorkspace2D() : - AbsManagedWorkspace2D(), m_indexWrittenTo(-1) -{ -} -#ifdef _WIN32 -#pragma warning (pop) -#endif //_WIN32 - -//------------------------------------------------------------------------------------------------------ -/** Sets the size of the workspace and sets up the temporary file - * @param NVectors :: The number of vectors/histograms/detectors in the workspace - * @param XLength :: The number of X data points/bin boundaries in each vector (must all be the same) - * @param YLength :: The number of data/error points in each vector (must all be the same) - * @throw std::runtime_error if unable to open a temporary file - */ -void ManagedWorkspace2D::init(const std::size_t &NVectors, const std::size_t &XLength, const std::size_t &YLength) -{ - AbsManagedWorkspace2D::init(NVectors,XLength,YLength); - - m_vectorSize = /*sizeof(int) +*/ ( m_XLength + ( 2*m_YLength ) ) * sizeof(double); - - // CALCULATE BLOCKSIZE - // Get memory size of a block from config file - int blockMemory; - if ( ! Kernel::ConfigService::Instance().getValue("ManagedWorkspace.DataBlockSize", blockMemory) - || blockMemory <= 0 ) - { - // default to 1MB if property not found - blockMemory = 1024*1024; - } - - - m_vectorsPerBlock = blockMemory / static_cast<int>(m_vectorSize); - // Should this ever come out to be zero, then actually set it to 1 - if ( m_vectorsPerBlock == 0 ) m_vectorsPerBlock = 1; - - // Create all the blocks - this->initBlocks(); - - - g_log.debug()<<"blockMemory: "<<blockMemory<<"\n"; - g_log.debug()<<"m_vectorSize: "<<m_vectorSize<<"\n"; - g_log.debug()<<"m_vectorsPerBlock: "<<m_vectorsPerBlock<<"\n"; - g_log.debug()<<"Memory: "<<getMemorySize()<<"\n"; - - - // Calculate the number of blocks that will go into a file - if ( ! Kernel::ConfigService::Instance().getValue("ManagedWorkspace.BlocksPerFile", m_blocksPerFile) - || m_blocksPerFile <= 0 ) - { - // default - m_blocksPerFile = std::numeric_limits<int>::max() / (m_vectorsPerBlock * static_cast<int>(m_vectorSize)); - if (std::numeric_limits<int>::max()%(m_vectorsPerBlock * m_vectorSize) != 0) ++m_blocksPerFile; - } - m_fileSize = m_vectorSize * m_vectorsPerBlock * m_blocksPerFile; - - // Now work out the number of files needed - size_t totalBlocks = m_noVectors / m_vectorsPerBlock; - if (m_noVectors%m_vectorsPerBlock != 0) ++totalBlocks; - size_t numberOfFiles = totalBlocks / m_blocksPerFile; - if (totalBlocks%m_blocksPerFile != 0) ++numberOfFiles; - m_datafile.resize(numberOfFiles); - - // Look for the (optional) path from the configuration file - std::string path = Kernel::ConfigService::Instance().getString("ManagedWorkspace.FilePath"); - if( path.empty() || !Poco::File(path).exists() || !Poco::File(path).canWrite() ) - { - path = Kernel::ConfigService::Instance().getUserPropertiesDir(); - g_log.debug() << "Temporary file written to " << path << std::endl; - } - // Append a slash if necessary - if( ( *(path.rbegin()) != '/' ) && ( *(path.rbegin()) != '\\' ) ) - { - path.push_back('/'); - } - - std::stringstream filestem; - filestem << "WS2D" << ManagedWorkspace2D::g_uniqueID; - m_filename = filestem.str() + this->getTitle() + ".tmp"; - // Increment the instance count - ++ManagedWorkspace2D::g_uniqueID; - std::string fullPath = path + m_filename; - - { - std::string fileToOpen = fullPath + "0"; - - // Create the temporary file - m_datafile[0] = new std::fstream(fileToOpen.c_str(), std::ios::in | std::ios::out | std::ios::binary | std::ios::trunc); - - if ( ! *m_datafile[0] ) - { - m_datafile[0]->clear(); - // Try to open in current working directory instead - std::string file = m_filename + "0"; - m_datafile[0]->open(file.c_str(), std::ios::in | std::ios::out | std::ios::binary | std::ios::trunc); - - // Throw an exception if it still doesn't work - if ( ! *m_datafile[0] ) - { - g_log.error("Unable to open temporary data file"); - throw std::runtime_error("ManagedWorkspace2D: Unable to open temporary data file"); - } - } - else - { - m_filename = fullPath; - } - } // block to restrict scope of fileToOpen - - // Set exception flags for fstream so that any problems from now on will throw - m_datafile[0]->exceptions( std::fstream::eofbit | std::fstream::failbit | std::fstream::badbit ); - - // Open the other temporary files (if any) - for (unsigned int i = 1; i < m_datafile.size(); ++i) - { - std::stringstream fileToOpen; - fileToOpen << m_filename << i; - m_datafile[i] = new std::fstream(fileToOpen.str().c_str(), std::ios::in | std::ios::out | std::ios::binary | std::ios::trunc); - if ( ! *m_datafile[i] ) - { - g_log.error("Unable to open temporary data file"); - throw std::runtime_error("ManagedWorkspace2D: Unable to open temporary data file"); - } - m_datafile[i]->exceptions( std::fstream::eofbit | std::fstream::failbit | std::fstream::badbit ); - } - -} - -/// Destructor. Clears the buffer and deletes the temporary file. -ManagedWorkspace2D::~ManagedWorkspace2D() -{ - // delete all ManagedDataBlock2D's - //m_bufferedData.clear(); - // delete the temporary file and fstream objects - for (unsigned int i = 0; i < m_datafile.size(); ++i) - { - m_datafile[i]->close(); - delete m_datafile[i]; - std::stringstream fileToRemove; - fileToRemove << m_filename << i; - remove(fileToRemove.str().c_str()); - } -} - - - -/** This function decides if ManagedDataBlock2D with given startIndex needs to - be loaded from storage and loads it. - @param newBlock :: Returned data block address - @param startIndex :: Starting spectrum index in the block -*/ -void ManagedWorkspace2D::readDataBlock(ManagedDataBlock2D *newBlock,std::size_t startIndex)const -{ - // You only need to read it if it hasn't been loaded before - if (!newBlock->isLoaded()) - { - // Check whether datablock has previously been saved. If so, read it in. - // @todo: Careful here. Without the (int)cast the m_indexWrittenTo variable is cast to a size_t and if it - // is at its default (-1) then this wraps around and the if evaluates to true when it should not, i.e. the - // first time the function is called with startIndex = 0 and m_indexWrittenTo = -1 - if ((int)startIndex <= m_indexWrittenTo) - { - long long seekPoint = startIndex * m_vectorSize; - - int fileIndex = 0; - //while (seekPoint > std::numeric_limits<int>::max()) - while (seekPoint >= m_fileSize) - { - seekPoint -= m_fileSize; - ++fileIndex; - } - - // Safe to cast seekPoint to int because the while loop above guarantees that - // it'll be in range by this point. - m_datafile[fileIndex]->seekg(static_cast<int>(seekPoint), std::ios::beg); - // The stream operator does the loading - *m_datafile[fileIndex] >> *newBlock; - } - else - { - // The block does not exist on file. - // It needs to be created with some empty vectors of the right length. - newBlock->initialize(); - } - } -} - -/** - * Write a data block to disk. - * @param toWrite :: pointer to the ManagedDataBlock2D to write. - */ -void ManagedWorkspace2D::writeDataBlock(ManagedDataBlock2D *toWrite) const -{ - //std::cout << "Writing " << toWrite->minIndex() << std::endl; - //std::cout << ">>> " << m_indexWrittenTo << std::endl; - //std::cout << ">>> " << m_vectorsPerBlock << std::endl; - size_t fileIndex = 0; - // Check whether we need to pad file with zeroes before writing data - if ( toWrite->minIndex() > static_cast<int>(m_indexWrittenTo+m_vectorsPerBlock) /*&& m_indexWrittenTo >= 0*/ ) - { - if ( m_indexWrittenTo < 0 ) - { - fileIndex = 0; - } - else - { - fileIndex = m_indexWrittenTo / (m_vectorsPerBlock * m_blocksPerFile); - } - - m_datafile[fileIndex]->seekp(0, std::ios::end); - //const int speczero = 0; - const std::vector<double> xzeroes(m_XLength); - const std::vector<double> yzeroes(m_YLength); - // if i is a workspace index the loop has to start with 1 because m_indexWrittenTo + 0 is the index - // of the last saved histogram. - for (int i = 1; i < (toWrite->minIndex() - m_indexWrittenTo); ++i) - { - size_t fi = (m_indexWrittenTo + i) / (m_blocksPerFile * m_vectorsPerBlock); - if ( fi > fileIndex ) - { - fileIndex = fi; - m_datafile[fileIndex]->seekp(0, std::ios::beg); - } - - //std::cerr << "Zeroes to " << fi << ' ' << m_indexWrittenTo + i << ' ' << m_datafile[fileIndex]->tellg() << std::endl; - - m_datafile[fileIndex]->write(reinterpret_cast<char *>(const_cast<double*>(&*xzeroes.begin())), - m_XLength * sizeof(double)); - m_datafile[fileIndex]->write(reinterpret_cast<char *>(const_cast<double*>(&*yzeroes.begin())), - m_YLength * sizeof(double)); - m_datafile[fileIndex]->write(reinterpret_cast<char *>(const_cast<double*>(&*yzeroes.begin())), - m_YLength * sizeof(double)); - // these don't match the ManagedWorkspace2D file stream operators. - //m_datafile[fileIndex]->write((char *) &*yzeroes.begin(), m_YLength * sizeof(double)); - //m_datafile[fileIndex]->write((char *) &speczero, sizeof(int) ); - } - //std::cout << "Here!!!!" << std::endl; - } - else - // If no padding needed, go to correct place in file - { - long long seekPoint = toWrite->minIndex() * m_vectorSize; - - //while (seekPoint > std::numeric_limits<int>::max()) - while (seekPoint >= m_fileSize) - { - seekPoint -= m_fileSize; - ++fileIndex; - } - - // Safe to cast seekPoint to int because the while loop above guarantees that - // it'll be in range by this point. - m_datafile[fileIndex]->seekp(static_cast<int>(seekPoint), std::ios::beg); - //std::cout << "Now here!!!!" << std::endl; - } - - *m_datafile[fileIndex] << *toWrite; - m_indexWrittenTo = std::max(m_indexWrittenTo, toWrite->minIndex()); -} - - -/** Returns the number of histograms. - * For some reason Visual Studio couldn't deal with the main getHistogramNumber() method - * being virtual so it now just calls this private (and virtual) method which does the work. - * @return the number of histograms assocaited with the workspace - */ -size_t ManagedWorkspace2D::getHistogramNumberHelper() const -{ - return m_noVectors; -} - -/// Return the size used in memory -size_t ManagedWorkspace2D::getMemorySize() const -{ - return size_t(m_vectorSize)*size_t(m_bufferedMarkers.size())*size_t(m_vectorsPerBlock); -} - -/// Return the full path to the file used. -std::string ManagedWorkspace2D::get_filename() const -{ - return this->m_filename; -} - -} // namespace DataObjects -} // namespace Mantid diff --git a/Code/Mantid/Framework/DataObjects/test/ManagedDataBlock2DTest.h b/Code/Mantid/Framework/DataObjects/test/ManagedDataBlock2DTest.h deleted file mode 100644 index bafc8bd0fcd..00000000000 --- a/Code/Mantid/Framework/DataObjects/test/ManagedDataBlock2DTest.h +++ /dev/null @@ -1,267 +0,0 @@ -#ifndef MANAGEDDATABLOCK2DTEST_H_ -#define MANAGEDDATABLOCK2DTEST_H_ - -#include <cxxtest/TestSuite.h> -#include "MantidDataObjects/ManagedDataBlock2D.h" -#include "MantidAPI/MatrixWorkspace.h" -#include "MantidKernel/cow_ptr.h" - -using namespace Mantid::DataObjects; -using Mantid::MantidVec; -using Mantid::MantidVecPtr; - -class ManagedDataBlock2DTest : public CxxTest::TestSuite -{ -public: - // This pair of boilerplate methods prevent the suite being created statically - // This means the constructor isn't called when running other tests - static ManagedDataBlock2DTest *createSuite() { return new ManagedDataBlock2DTest(); } - static void destroySuite( ManagedDataBlock2DTest *suite ) { delete suite; } - - ManagedDataBlock2DTest() - : data(0,2,4,3, NULL, MantidVecPtr() ) - { - for (int i = 0; i < 4; ++i) - { - data.getSpectrum(0)->dataX()[i] = i; - data.getSpectrum(1)->dataX()[i] = i+4; - } - - for (int i = 0; i < 3; ++i) - { - data.getSpectrum(0)->dataY()[i] = i*10; - data.getSpectrum(0)->dataE()[i] = sqrt(data.getSpectrum(0)->dataY()[i]); - data.getSpectrum(1)->dataY()[i] = i*100; - data.getSpectrum(1)->dataE()[i] = sqrt(data.getSpectrum(1)->dataY()[i]); - } - } - - void testConstructor() - { - ManagedDataBlock2D aBlock(0,2,2,2, NULL, MantidVecPtr()); - TS_ASSERT_EQUALS( aBlock.minIndex(), 0 ); - TS_ASSERT( ! aBlock.hasChanges() ); - TSM_ASSERT("When initialized the block says it is loaded", aBlock.isLoaded() ); - TS_ASSERT_EQUALS( aBlock.getSpectrum(0)->dataX().size(), 2 ); - TS_ASSERT_EQUALS( aBlock.getSpectrum(0)->dataY().size(), 2 ); - TS_ASSERT_EQUALS( aBlock.getSpectrum(0)->dataE().size(), 2 ); - TS_ASSERT_EQUALS( aBlock.getSpectrum(1)->dataX().size(), 2 ); - TS_ASSERT_EQUALS( aBlock.getSpectrum(1)->dataY().size(), 2 ); - TS_ASSERT_EQUALS( aBlock.getSpectrum(1)->dataE().size(), 2 ); - } - - void test_releaseData() - { - ManagedDataBlock2D aBlock(0,2,2,2, NULL, MantidVecPtr()); - TSM_ASSERT("When initialized the block says it is loaded", aBlock.isLoaded() ); - // Spectra start loaded too - ManagedHistogram1D * h0 = dynamic_cast<ManagedHistogram1D *>(aBlock.getSpectrum(0)); - ManagedHistogram1D * h1 = dynamic_cast<ManagedHistogram1D *>(aBlock.getSpectrum(1)); - TS_ASSERT(h0->isLoaded()); - TS_ASSERT(h1->isLoaded()); - - aBlock.releaseData(); - - // No longer loaded - TS_ASSERT(!h0->isLoaded()); - TS_ASSERT(!h1->isLoaded()); - } - - void testSetX() - { - ManagedDataBlock2D aBlock(0,1,1,1, NULL, MantidVecPtr()); - double aNumber = 5.5; - boost::shared_ptr<MantidVec > v( new MantidVec(1, aNumber) ); - TS_ASSERT_THROWS_NOTHING( aBlock.getSpectrum(0)->setX(v) ); - TS_ASSERT_EQUALS( aBlock.getSpectrum(0)->dataX()[0], aNumber ); - TS_ASSERT_THROWS( aBlock.getSpectrum(-1)->setX(v), std::range_error ); - TS_ASSERT_THROWS( aBlock.getSpectrum(1)->setX(v), std::range_error ); - TS_ASSERT( aBlock.hasChanges() ); - } - - void testSpectrumNo() - { - ManagedDataBlock2D aBlock(0,1,1,1, NULL, MantidVecPtr()); - TS_ASSERT_THROWS_NOTHING( aBlock.getSpectrum(0)->setSpectrumNo(1234) ); - // You don't need to save back to disk since that's in memory all the time - TS_ASSERT( !aBlock.hasChanges() ); - } - - void testDetectorIDs() - { - ManagedDataBlock2D aBlock(0,1,1,1, NULL, MantidVecPtr()); - TS_ASSERT_THROWS_NOTHING( aBlock.getSpectrum(0)->addDetectorID(1234) ); - // You don't need to save back to disk since that's in memory all the time - TS_ASSERT( !aBlock.hasChanges() ); - } - - void testSetData() - { - ManagedDataBlock2D aBlock(0,1,1,1, NULL, MantidVecPtr()); - double aNumber = 9.9; - boost::shared_ptr<MantidVec > v( new MantidVec(1, aNumber) ); - double anotherNumber = 3.3; - boost::shared_ptr<MantidVec > w( new MantidVec(1, anotherNumber) ); - TS_ASSERT_THROWS_NOTHING( aBlock.getSpectrum(0)->setData(v,v) ); - TS_ASSERT_EQUALS( aBlock.getSpectrum(0)->dataY()[0], aNumber ) ; - TS_ASSERT_THROWS( aBlock.getSpectrum(-1)->setData(v,v), std::range_error ); - TS_ASSERT_THROWS( aBlock.getSpectrum(1)->setData(v,v), std::range_error ); - - double yetAnotherNumber = 2.25; - (*v)[0] = yetAnotherNumber; - TS_ASSERT_THROWS_NOTHING( aBlock.getSpectrum(0)->setData(v,w) ); - TS_ASSERT_EQUALS( aBlock.getSpectrum(0)->dataY()[0], yetAnotherNumber ); - TS_ASSERT_EQUALS( aBlock.getSpectrum(0)->dataE()[0], anotherNumber ); - TS_ASSERT_THROWS( aBlock.getSpectrum(-1)->setData(v,w), std::range_error ); - TS_ASSERT_THROWS( aBlock.getSpectrum(1)->setData(v,w), std::range_error ); - TS_ASSERT( aBlock.hasChanges() ); - } - - void testDataX() - { - dataXTester(data); - } - - void testDataY() - { - dataYTester(data); - } - - void testDataE() - { - dataETester(data); - } - - void testStreamOperators() - { - std::fstream outfile("ManagedDataBlock2DTest.tmp", std::ios::binary | std::ios::out); - TS_ASSERT( outfile ); - outfile << data; - outfile.close(); - - std::fstream infile("ManagedDataBlock2DTest.tmp", std::ios::binary | std::ios::in); - TS_ASSERT( infile ); - - // Empty block - ManagedDataBlock2D readData(0,2,4,3, NULL, MantidVecPtr()); - - // The spectra say "loaded" because they were initialized - ManagedHistogram1D * h0 = dynamic_cast<ManagedHistogram1D *>(readData.getSpectrum(0)); - ManagedHistogram1D * h1 = dynamic_cast<ManagedHistogram1D *>(readData.getSpectrum(1)); - TS_ASSERT(h0->isLoaded()); - TS_ASSERT(h1->isLoaded()); - - infile >> readData; - // use const methods so that I can check the changes flag behaves as it should - TS_ASSERT( ! readData.hasChanges() ); - dataXTester(readData); - dataYTester(readData); - dataETester(readData); - TS_ASSERT( readData.hasChanges() ); - - // The spectra are now marked as loaded - TS_ASSERT(h0->isLoaded()); - TS_ASSERT(h1->isLoaded()); - - - remove("ManagedDataBlock2DTest.tmp"); - } - -private: - ManagedDataBlock2D data; - - void dataXTester(ManagedDataBlock2D &dataToTest) - { - MantidVec x; - TS_ASSERT_THROWS( dataToTest.getSpectrum(-1)->dataX(), std::range_error ); - TS_ASSERT_THROWS_NOTHING( x = dataToTest.getSpectrum(0)->dataX() ); - MantidVec xx; - TS_ASSERT_THROWS_NOTHING( xx = dataToTest.getSpectrum(1)->dataX() ); - TS_ASSERT_THROWS( dataToTest.getSpectrum(2)->dataX(), std::range_error ); - TS_ASSERT_EQUALS( x.size(), 4 ); - TS_ASSERT_EQUALS( xx.size(), 4 ); - for (unsigned int i = 0; i < x.size(); ++i) - { - TS_ASSERT_EQUALS( x[i], i ); - TS_ASSERT_EQUALS( xx[i], i+4 ); - } - - // test const version - const ManagedDataBlock2D &constRefToData = dataToTest; - TS_ASSERT_THROWS( const MantidVec v = constRefToData.getSpectrum(-1)->dataX(), std::range_error ); - const MantidVec xc = constRefToData.getSpectrum(0)->dataX(); - const MantidVec xxc = constRefToData.getSpectrum(1)->dataX(); - TS_ASSERT_THROWS( const MantidVec v = constRefToData.getSpectrum(2)->dataX(), std::range_error ); - TS_ASSERT_EQUALS( xc.size(), 4 ); - TS_ASSERT_EQUALS( xxc.size(), 4 ); - for (unsigned int i = 0; i < xc.size(); ++i) - { - TS_ASSERT_EQUALS( xc[i], i ); - TS_ASSERT_EQUALS( xxc[i], i+4 ); - } - } - - void dataYTester(ManagedDataBlock2D &dataToTest) - { - MantidVec y; - TS_ASSERT_THROWS( dataToTest.getSpectrum(-1)->dataY(), std::range_error ); - TS_ASSERT_THROWS_NOTHING( y = dataToTest.getSpectrum(0)->dataY() ); - MantidVec yy; - TS_ASSERT_THROWS_NOTHING( yy = dataToTest.getSpectrum(1)->dataY() ); - TS_ASSERT_THROWS( dataToTest.getSpectrum(2)->dataY(), std::range_error ); - TS_ASSERT_EQUALS( y.size(), 3 ); - TS_ASSERT_EQUALS( yy.size(), 3 ); - for (unsigned int i = 0; i < y.size(); ++i) - { - TS_ASSERT_EQUALS( y[i], i*10 ); - TS_ASSERT_EQUALS( yy[i], i*100 ); - } - - // test const version - const ManagedDataBlock2D &constRefToData = dataToTest; - TS_ASSERT_THROWS( const MantidVec v = constRefToData.getSpectrum(-1)->dataY(), std::range_error ); - const MantidVec yc = constRefToData.getSpectrum(0)->dataY(); - const MantidVec yyc = constRefToData.getSpectrum(1)->dataY(); - TS_ASSERT_THROWS( const MantidVec v = constRefToData.getSpectrum(2)->dataY(), std::range_error ); - TS_ASSERT_EQUALS( yc.size(), 3 ); - TS_ASSERT_EQUALS( yyc.size(), 3 ); - for (unsigned int i = 0; i < yc.size(); ++i) - { - TS_ASSERT_EQUALS( yc[i], i*10 ); - TS_ASSERT_EQUALS( yyc[i], i*100 ); - } - } - - void dataETester(ManagedDataBlock2D &dataToTest) - { - MantidVec e; - TS_ASSERT_THROWS( dataToTest.getSpectrum(-1)->dataE(), std::range_error ); - TS_ASSERT_THROWS_NOTHING( e = dataToTest.getSpectrum(0)->dataE() ); - MantidVec ee; - TS_ASSERT_THROWS_NOTHING( ee = dataToTest.getSpectrum(1)->dataE() ); - TS_ASSERT_THROWS( dataToTest.getSpectrum(2)->dataE(), std::range_error ); - TS_ASSERT_EQUALS( e.size(), 3 ); - TS_ASSERT_EQUALS( ee.size(), 3 ); - for (unsigned int i = 0; i < e.size(); ++i) - { - TS_ASSERT_EQUALS( e[i], sqrt(i*10.0) ); - TS_ASSERT_EQUALS( ee[i], sqrt(i*100.0) ); - } - - // test const version - const ManagedDataBlock2D &constRefToData = dataToTest; - TS_ASSERT_THROWS( const MantidVec v = constRefToData.getSpectrum(-1)->dataE(), std::range_error ); - const MantidVec ec = constRefToData.getSpectrum(0)->dataE(); - const MantidVec eec = constRefToData.getSpectrum(1)->dataE(); - TS_ASSERT_THROWS( const MantidVec v = constRefToData.getSpectrum(2)->dataE(), std::range_error ); - TS_ASSERT_EQUALS( ec.size(), 3 ); - TS_ASSERT_EQUALS( eec.size(), 3 ); - for (unsigned int i = 0; i < ec.size(); ++i) - { - TS_ASSERT_EQUALS( ec[i], sqrt(i*10.0) ); - TS_ASSERT_EQUALS( eec[i], sqrt(i*100.0) ); - } - } -}; - -#endif /*MANAGEDDATABLOCK2DTEST_H_*/ diff --git a/Code/Mantid/Framework/DataObjects/test/ManagedHistogram1DTest.h b/Code/Mantid/Framework/DataObjects/test/ManagedHistogram1DTest.h deleted file mode 100644 index 6bb220248ec..00000000000 --- a/Code/Mantid/Framework/DataObjects/test/ManagedHistogram1DTest.h +++ /dev/null @@ -1,120 +0,0 @@ -#ifndef MANTID_DATAOBJECTS_MANAGEDHISTOGRAM1DTEST_H_ -#define MANTID_DATAOBJECTS_MANAGEDHISTOGRAM1DTEST_H_ - -#include "MantidDataObjects/ManagedHistogram1D.h" -#include "MantidKernel/System.h" -#include "MantidKernel/Timer.h" -#include <cxxtest/TestSuite.h> -#include <iomanip> -#include <iostream> - -using namespace Mantid; -using namespace Mantid::DataObjects; -using namespace Mantid::API; - -class ManagedHistogram1DTest : public CxxTest::TestSuite -{ -public: - - void test_constructor() - { - ManagedHistogram1D h(NULL, 1234); - TS_ASSERT_EQUALS( h.getWorkspaceIndex(), 1234); - } - - /** Const access does not set the dirty flag */ - void test_dirtyFlag_const() - { - const ManagedHistogram1D h(NULL, 1234); - TS_ASSERT( !h.isDirty() ); - const MantidVec & x = h.dataX(); - TS_ASSERT( !h.isDirty() ); - const MantidVec & y = h.dataY(); - TS_ASSERT( !h.isDirty() ); - const MantidVec & e = h.dataE(); - TS_ASSERT( !h.isDirty() ); - const MantidVec & dx = h.dataDx(); - TS_ASSERT( !h.isDirty() ); - UNUSED_ARG(x);UNUSED_ARG(dx);UNUSED_ARG(y);UNUSED_ARG(e); - } - - - /** Non-const access does set the dirty flag (except for Dx)*/ - void test_dirtyFlag_isSet() - { - { - ManagedHistogram1D h(NULL, 1234); - TS_ASSERT( !h.isDirty() ); - h.dataX(); - TS_ASSERT( h.isDirty() ); - ManagedHistogram1D * h2 = new ManagedHistogram1D(NULL, 1234); - // Check that the method is properly overridden in ISpectrum - ISpectrum * spec = h2; - TS_ASSERT( !h2->isDirty() ); - spec->dataX(); - TS_ASSERT( h2->isDirty() ); - } - { - ManagedHistogram1D h(NULL, 1234); - TS_ASSERT( !h.isDirty() ); - h.ptrX(); - TS_ASSERT( h.isDirty() ); - } - { - ManagedHistogram1D h(NULL, 1234); - TS_ASSERT( !h.isDirty() ); - h.dataY(); - TS_ASSERT( h.isDirty() ); - } - { - ManagedHistogram1D h(NULL, 1234); - TS_ASSERT( !h.isDirty() ); - h.dataE(); - TS_ASSERT( h.isDirty() ); - } - { - ManagedHistogram1D h(NULL, 1234); - TS_ASSERT( !h.isDirty() ); - h.dataDx(); - // Dx does NOT dirty it - TS_ASSERT( !h.isDirty() ); - } - } - - /** setX or setData() makes it dirty */ - void test_dirtyFlag_isSet_whenUsingSetData() - { - MantidVec X, Y, E; - { - ManagedHistogram1D h(NULL, 1234); - TS_ASSERT( !h.isDirty() ); - h.setData(Y); - TS_ASSERT( h.isDirty() ); - } - { - ManagedHistogram1D h(NULL, 1234); - TS_ASSERT( !h.isDirty() ); - h.setData(Y, E); - TS_ASSERT( h.isDirty() ); - } - { - ManagedHistogram1D h(NULL, 1234); - TS_ASSERT( !h.isDirty() ); - h.setX(X); - TS_ASSERT( h.isDirty() ); - } - { - ManagedHistogram1D h(NULL, 1234); - TS_ASSERT( !h.isDirty() ); - h.setDx(X); - // Dx does NOT dirty it - TS_ASSERT( !h.isDirty() ); - } - } - - -}; - - -#endif /* MANTID_DATAOBJECTS_MANAGEDHISTOGRAM1DTEST_H_ */ - diff --git a/Code/Mantid/Framework/DataObjects/test/ManagedWorkspace2DTest.h b/Code/Mantid/Framework/DataObjects/test/ManagedWorkspace2DTest.h deleted file mode 100644 index 7812cd70c26..00000000000 --- a/Code/Mantid/Framework/DataObjects/test/ManagedWorkspace2DTest.h +++ /dev/null @@ -1,639 +0,0 @@ -#ifndef MANAGEDWORKSPACE2DTEST_H_ -#define MANAGEDWORKSPACE2DTEST_H_ - -#include "MantidAPI/MemoryManager.h" -#include "MantidAPI/WorkspaceFactory.h" -#include "MantidDataObjects/ManagedWorkspace2D.h" -#include "MantidGeometry/IDTypes.h" -#include "MantidKernel/ConfigService.h" -#include "MantidKernel/Memory.h" -#include <cxxtest/TestSuite.h> -#include <Poco/File.h> -#include <boost/lexical_cast.hpp> - -using Mantid::MantidVec; -using std::size_t; -using Mantid::DataObjects::ManagedWorkspace2D; - -class ManagedWorkspace2DTest : public CxxTest::TestSuite -{ -public: - static ManagedWorkspace2DTest *createSuite() { return new ManagedWorkspace2DTest(); } - static void destroySuite( ManagedWorkspace2DTest *suite ) { delete suite; } - - ManagedWorkspace2DTest() - { - smallWorkspace.setTitle("ManagedWorkspace2DTest_smallWorkspace"); - smallWorkspace.initialize(2,4,3); - for (size_t i = 0; i < 4; ++i) - { - smallWorkspace.dataX(0)[i] = static_cast<double>(i); - smallWorkspace.dataX(1)[i] = static_cast<double>(i+4); - } - - for (size_t i = 0; i < 3; ++i) - { - smallWorkspace.dataY(0)[i] = static_cast<double>(i*10); - smallWorkspace.dataE(0)[i] = sqrt(smallWorkspace.dataY(0)[i]); - smallWorkspace.dataY(1)[i] = static_cast<double>(i*100); - smallWorkspace.dataE(1)[i] = sqrt(smallWorkspace.dataY(1)[i]); - } - - bigWorkspace.setTitle("ManagedWorkspace2DTest_bigWorkspace"); - size_t nVec = 1250; - size_t vecLength = 25; - bigWorkspace.initialize(nVec, vecLength, vecLength); - for (size_t i=0; i< nVec; i++) - { - boost::shared_ptr<MantidVec > x1(new MantidVec(vecLength, static_cast<MantidVec::value_type>(1+i) ) ); - boost::shared_ptr<MantidVec > y1(new MantidVec(vecLength, static_cast<MantidVec::value_type>(5+i) ) ); - boost::shared_ptr<MantidVec > e1(new MantidVec(vecLength, static_cast<MantidVec::value_type>(4+i) ) ); - bigWorkspace.setX(i,x1); - bigWorkspace.setData(i,y1,e1); - // As of 20/7/2011, revision [13332], these calls have no (lasting) effect. - // When they do, the testSpectrumAndDetectorNumbers test will start to fail - bigWorkspace.getSpectrum(i)->setSpectrumNo((int)i); - bigWorkspace.getSpectrum(i)->setDetectorID((int)i*100); - } - } - - void testInit() - { - Mantid::DataObjects::ManagedWorkspace2D ws; - ws.setTitle("testInit"); - TS_ASSERT_THROWS_NOTHING( ws.initialize(5,5,5) );; - TS_ASSERT_EQUALS( ws.getNumberHistograms(), 5 );; - TS_ASSERT_EQUALS( ws.blocksize(), 5 );; - TS_ASSERT_EQUALS( ws.size(), 25 );; - - for (size_t i = 0; i < 5; ++i) - { - TS_ASSERT_EQUALS( ws.dataX(i).size(), 5 );; - TS_ASSERT_EQUALS( ws.dataY(i).size(), 5 );; - TS_ASSERT_EQUALS( ws.dataE(i).size(), 5 );; - } - - // Test all is as it should be with the temporary file - std::string filename = ws.get_filename() + "0"; - std::fstream file(filename.c_str(), std::ios::in | std::ios::binary); - TSM_ASSERT(filename, file);; - - double temp; - file.read((char *) &temp, sizeof(double)); - TS_ASSERT( file.fail() ); - file.close(); - } - - void testCast() - { - Mantid::DataObjects::ManagedWorkspace2D *ws = new Mantid::DataObjects::ManagedWorkspace2D; - TS_ASSERT( dynamic_cast<Mantid::DataObjects::Workspace2D*>(ws) ); - TS_ASSERT( dynamic_cast<Mantid::API::Workspace*>(ws) ); - delete ws; - } - - void testId() - { - TS_ASSERT( ! smallWorkspace.id().compare("ManagedWorkspace2D") ); - } - - void testgetNumberHistograms() - { - TS_ASSERT_EQUALS( smallWorkspace.getNumberHistograms(), 2 ); - TS_ASSERT_EQUALS( bigWorkspace.getNumberHistograms(), 1250 ); - - Mantid::DataObjects::Workspace2D &ws = dynamic_cast<Mantid::DataObjects::Workspace2D&>(smallWorkspace); - TS_ASSERT_EQUALS( ws.getNumberHistograms(), 2);; - } - - void testSetX() - { - Mantid::DataObjects::ManagedWorkspace2D ws; - ws.setTitle("testSetX"); - ws.initialize(1,1,1); - double aNumber = 5.5; - boost::shared_ptr<MantidVec > v(new MantidVec(1, aNumber)); - TS_ASSERT_THROWS_NOTHING( ws.setX(0,v) ); - TS_ASSERT_EQUALS( ws.dataX(0)[0], aNumber ); - TS_ASSERT_THROWS( ws.setX(-1,v), std::range_error ); - TS_ASSERT_THROWS( ws.setX(1,v), std::range_error ); - - double anotherNumber = 9.99; - boost::shared_ptr<MantidVec > vec(new MantidVec(25, anotherNumber)); - TS_ASSERT_THROWS_NOTHING( bigWorkspace.setX(10, vec) ); - TS_ASSERT_EQUALS( bigWorkspace.dataX(10)[7], anotherNumber ); - TS_ASSERT_EQUALS( bigWorkspace.dataX(10)[22], anotherNumber ); - } - - void testSetData() - { - Mantid::DataObjects::ManagedWorkspace2D ws; - ws.setTitle("testSetData"); - ws.initialize(1,1,1); - double aNumber = 9.9; - boost::shared_ptr<MantidVec > v(new MantidVec(1, aNumber)); - double anotherNumber = 3.3; - boost::shared_ptr<MantidVec > w(new MantidVec(1, anotherNumber)); - TS_ASSERT_THROWS_NOTHING( ws.setData(0,v,v) ); - TS_ASSERT_EQUALS( ws.dataY(0)[0], aNumber ) ; - TS_ASSERT_THROWS( ws.setData(-1,v,v), std::range_error ); - TS_ASSERT_THROWS( ws.setData(1,v,v), std::range_error ); - - double yetAnotherNumber = 2.25; - (*v)[0] = yetAnotherNumber; - TS_ASSERT_THROWS_NOTHING( ws.setData(0,v,w) ); - TS_ASSERT_EQUALS( ws.dataY(0)[0], yetAnotherNumber ); - TS_ASSERT_EQUALS( ws.dataE(0)[0], anotherNumber ); - TS_ASSERT_THROWS( ws.setData(-1,v,w), std::range_error ); - TS_ASSERT_THROWS( ws.setData(1,v,w), std::range_error ); - - double oneMoreNumber = 8478.6728; - boost::shared_ptr<MantidVec > vec(new MantidVec(25, oneMoreNumber)); - TS_ASSERT_THROWS_NOTHING( bigWorkspace.setData(49, vec, vec) ); - TS_ASSERT_EQUALS( bigWorkspace.dataY(49)[0], oneMoreNumber ); - TS_ASSERT_EQUALS( bigWorkspace.dataE(49)[9], oneMoreNumber ); - } - - void testSize() - { - TS_ASSERT_EQUALS( smallWorkspace.size(), 6 ); - TS_ASSERT_EQUALS( bigWorkspace.size(), 31250 ); - } - - void testBlocksize() - { - TS_ASSERT_EQUALS( smallWorkspace.blocksize(), 3 ); - TS_ASSERT_EQUALS( bigWorkspace.blocksize(), 25 ) ; - } - - void testDataX() - { - MantidVec x; - TS_ASSERT_THROWS( smallWorkspace.dataX(-1), std::range_error ); - TS_ASSERT_THROWS_NOTHING( x = smallWorkspace.dataX(0) ); - MantidVec xx; - TS_ASSERT_THROWS_NOTHING( xx = smallWorkspace.dataX(1) ); - TS_ASSERT_THROWS( smallWorkspace.dataX(2), std::range_error ); - TS_ASSERT_EQUALS( x.size(), 4 ); - TS_ASSERT_EQUALS( xx.size(), 4 ); - for (size_t i = 0; i < x.size(); ++i) - { - TS_ASSERT_EQUALS( x[i], i ); - TS_ASSERT_EQUALS( xx[i], i+4 ); - } - - // test const version - const Mantid::DataObjects::ManagedWorkspace2D &constRefToData = smallWorkspace; - TS_ASSERT_THROWS( const MantidVec v = constRefToData.dataX(-1), std::range_error ); - const MantidVec xc = constRefToData.dataX(0); - const MantidVec xxc = constRefToData.dataX(1); - TS_ASSERT_THROWS( const MantidVec v = constRefToData.dataX(2), std::range_error ); - TS_ASSERT_EQUALS( xc.size(), 4 ); - TS_ASSERT_EQUALS( xxc.size(), 4 ); - for (size_t i = 0; i < xc.size(); ++i) - { - TS_ASSERT_EQUALS( xc[i], i ); - TS_ASSERT_EQUALS( xxc[i], i+4 ); - } - - TS_ASSERT_EQUALS( bigWorkspace.dataX(101)[5], 102 ); - TS_ASSERT_EQUALS( bigWorkspace.dataX(201)[24], 202 ); - TS_ASSERT_THROWS_NOTHING( bigWorkspace.dataX(39)[10] = 2.22 ); - TS_ASSERT_EQUALS( bigWorkspace.dataX(39)[10], 2.22 ); - } - - void testDataDx() - { - TS_ASSERT_EQUALS( smallWorkspace.dataDx(0).size(), 4 ); - TS_ASSERT_EQUALS( smallWorkspace.readDx(1)[3], 0.0 ); - - TS_ASSERT_THROWS_NOTHING( smallWorkspace.dataDx(1)[3] = 9.9 ); - TS_ASSERT_EQUALS( smallWorkspace.readDx(1)[3], 9.9 ); - } - - void testDataY() - { - MantidVec y; - TS_ASSERT_THROWS( smallWorkspace.dataY(-1), std::range_error ); - TS_ASSERT_THROWS_NOTHING( y = smallWorkspace.dataY(0) ); - MantidVec yy; - TS_ASSERT_THROWS_NOTHING( yy = smallWorkspace.dataY(1) ); - TS_ASSERT_THROWS( smallWorkspace.dataY(2), std::range_error ); - TS_ASSERT_EQUALS( y.size(), 3 ); - TS_ASSERT_EQUALS( yy.size(), 3 ); - for (size_t i = 0; i < y.size(); ++i) - { - TS_ASSERT_EQUALS( y[i], i*10 ); - TS_ASSERT_EQUALS( yy[i], i*100 ); - } - - // test const version - const Mantid::DataObjects::ManagedWorkspace2D &constRefToData = smallWorkspace; - TS_ASSERT_THROWS( const MantidVec v = constRefToData.dataY(-1), std::range_error ); - const MantidVec yc = constRefToData.dataY(0); - const MantidVec yyc = constRefToData.dataY(1); - TS_ASSERT_THROWS( const MantidVec v = constRefToData.dataY(2), std::range_error ); - TS_ASSERT_EQUALS( yc.size(), 3 ); - TS_ASSERT_EQUALS( yyc.size(), 3 ); - for (size_t i = 0; i < yc.size(); ++i) - { - TS_ASSERT_EQUALS( yc[i], i*10 ); - TS_ASSERT_EQUALS( yyc[i], i*100 ); - } - - TS_ASSERT_EQUALS( bigWorkspace.dataY(178)[8], 183 ); - TS_ASSERT_EQUALS( bigWorkspace.dataY(64)[11], 69 ); - TS_ASSERT_THROWS_NOTHING( bigWorkspace.dataY(123)[8] = 3.33 ); - TS_ASSERT_EQUALS( bigWorkspace.dataY(123)[8], 3.33 ); - } - - void testDataE() - { - MantidVec e; - TS_ASSERT_THROWS( smallWorkspace.dataE(-1), std::range_error ); - TS_ASSERT_THROWS_NOTHING( e = smallWorkspace.dataE(0) ); - MantidVec ee; - TS_ASSERT_THROWS_NOTHING( ee = smallWorkspace.dataE(1) ); - TS_ASSERT_THROWS( smallWorkspace.dataE(2), std::range_error ); - TS_ASSERT_EQUALS( e.size(), 3 ); - TS_ASSERT_EQUALS( ee.size(), 3 ); - for (size_t i = 0; i < e.size(); ++i) - { - TS_ASSERT_EQUALS( e[i], sqrt(static_cast<double>(i)*10.0) ); - TS_ASSERT_EQUALS( ee[i], sqrt(static_cast<double>(i)*100.0) ); - } - - // test const version - const Mantid::DataObjects::ManagedWorkspace2D &constRefToData = smallWorkspace; - TS_ASSERT_THROWS( const MantidVec v = constRefToData.dataE(-1), std::range_error ); - const MantidVec ec = constRefToData.dataE(0); - const MantidVec eec = constRefToData.dataE(1); - TS_ASSERT_THROWS( const MantidVec v = constRefToData.dataE(2), std::range_error ); - TS_ASSERT_EQUALS( ec.size(), 3 ); - TS_ASSERT_EQUALS( eec.size(), 3 ); - for (size_t i = 0; i < ec.size(); ++i) - { - TS_ASSERT_EQUALS( ec[i], sqrt(static_cast<double>(i)*10.0) ); - TS_ASSERT_EQUALS( eec[i], sqrt(static_cast<double>(i)*100.0) ); - } - - TS_ASSERT_EQUALS( bigWorkspace.dataE(0)[23], 4 ); - TS_ASSERT_EQUALS( bigWorkspace.dataE(249)[2], 253 ); - TS_ASSERT_THROWS_NOTHING( bigWorkspace.dataE(11)[11] = 4.44 ); - TS_ASSERT_EQUALS( bigWorkspace.dataE(11)[11], 4.44 ); - } - - void testSpectrumAndDetectorNumbers() - { - for (size_t i = 0; i < bigWorkspace.getNumberHistograms(); ++i) - { - TS_ASSERT_EQUALS( bigWorkspace.getAxis(1)->spectraNo(i), i ); - // Values were set in the constructor - TS_ASSERT_EQUALS( bigWorkspace.getSpectrum(i)->getSpectrumNo(), i ); - TS_ASSERT( bigWorkspace.getSpectrum(i)->hasDetectorID((int)i*100) ); - } - } - - void testMultipleFiles() - { - const size_t NHist = 111; - const size_t NY = 9; - const size_t NX = NY + 1; - - double dBlockSize = 2 * ( sizeof(int) + ( NX + 2*NY ) * sizeof(double) ); - - // This will make sure 1 ManagedDataBlock = 2 Vectors - Mantid::Kernel::ConfigServiceImpl& conf = Mantid::Kernel::ConfigService::Instance(); - const std::string blocksize = "ManagedWorkspace.DataBlockSize"; - const std::string oldValue = conf.getString(blocksize); - conf.setString(blocksize,boost::lexical_cast<std::string>(dBlockSize)); - - const std::string blockPerFile = "ManagedWorkspace.BlocksPerFile"; - const std::string oldValueBlockPerFile = conf.getString(blockPerFile); - conf.setString(blockPerFile,"9"); - - Mantid::DataObjects::ManagedWorkspace2D ws; - ws.initialize(NHist, NX, NY); - - TS_ASSERT_EQUALS( ws.getNumberFiles(), NHist /( 2 * 9 ) + 1 ); - - for(size_t i = 0; i < ws.getNumberHistograms(); ++i ) - { - auto& y = ws.dataY( i ); - for(size_t j = 0; j < y.size(); ++j) - { - y[j] = double(1000*i) + double(j); - } - } - - for(size_t i = 0; i < ws.getNumberHistograms(); ++i ) - { - auto& y = ws.dataY( i ); - for(size_t j = 0; j < y.size(); ++j) - { - TS_ASSERT_EQUALS( y[j], double(1000*i) + double(j) ); - } - } - - conf.setString(blocksize,oldValue); - conf.setString(blockPerFile,oldValueBlockPerFile); - } - - void testMultipleFiles1() - { - - const size_t NHist = 211; - const size_t NY = 9; - const size_t NX = NY + 1; - const size_t StartHist = 90; - - double dBlockSize = /*sizeof(int) +*/ ( NX + 2*NY ) * sizeof(double); - - // This will make sure 1 ManagedDataBlock = 1 Vector - Mantid::Kernel::ConfigServiceImpl& conf = Mantid::Kernel::ConfigService::Instance(); - const std::string blocksize = "ManagedWorkspace.DataBlockSize"; - const std::string oldValue = conf.getString(blocksize); - conf.setString(blocksize,boost::lexical_cast<std::string>(dBlockSize)); - - const std::string blockPerFile = "ManagedWorkspace.BlocksPerFile"; - const std::string oldValueBlockPerFile = conf.getString(blockPerFile); - conf.setString(blockPerFile,"40"); - - Mantid::DataObjects::ManagedWorkspace2D ws; - ws.initialize(NHist, NX, NY); - - TS_ASSERT_EQUALS( ws.getNumberFiles(), NHist /( 40 ) + 1 ); - - // start writing from some index > 0 - for(size_t i = StartHist; i < ws.getNumberHistograms(); ++i ) - { - auto& y = ws.dataY( i ); - for(size_t j = 0; j < y.size(); ++j) - { - y[j] = double(1000*i) + double(j); - } - } - - for(size_t i = StartHist; i < ws.getNumberHistograms(); ++i ) - { - auto& y = ws.dataY( i ); - for(size_t j = 0; j < y.size(); ++j) - { - TS_ASSERT_EQUALS( y[j], double(1000*i) + double(j) ); - } - } - - // check that front spectra can be read and zero - TS_ASSERT_EQUALS( ws.readY( 0 )[0], 0.0 ); - TS_ASSERT_EQUALS( ws.readY( 1 )[0], 0.0 ); - - conf.setString(blocksize,oldValue); - conf.setString(blockPerFile,oldValueBlockPerFile); - } - - void testMultipleFiles2() - { - - const size_t NHist = 211; - const size_t NY = 9; - const size_t NX = NY + 1; - const size_t StartHist = 90; - - double dBlockSize = /*sizeof(int) +*/ ( NX + 2*NY ) * sizeof(double); - - // This will make sure 1 ManagedDataBlock = 1 Vector - Mantid::Kernel::ConfigServiceImpl& conf = Mantid::Kernel::ConfigService::Instance(); - const std::string blocksize = "ManagedWorkspace.DataBlockSize"; - const std::string oldValue = conf.getString(blocksize); - conf.setString(blocksize,boost::lexical_cast<std::string>(dBlockSize)); - - const std::string blockPerFile = "ManagedWorkspace.BlocksPerFile"; - const std::string oldValueBlockPerFile = conf.getString(blockPerFile); - conf.setString(blockPerFile,"40"); - - Mantid::DataObjects::ManagedWorkspace2D ws; - ws.initialize(NHist, NX, NY); - - TS_ASSERT_EQUALS( ws.getNumberFiles(), NHist /( 40 ) + 1 ); - - // write at front - ws.dataY( 0 )[0] = 1.0; - ws.dataY( 1 )[0] = 2.0; - - // leave a gap - for(size_t i = StartHist; i < ws.getNumberHistograms(); ++i ) - { - auto& y = ws.dataY( i ); - for(size_t j = 0; j < y.size(); ++j) - { - y[j] = double(1000*i) + double(j); - } - } - - // check the filled spectra - for(size_t i = StartHist; i < ws.getNumberHistograms(); ++i ) - { - auto& y = ws.dataY( i ); - for(size_t j = 0; j < y.size(); ++j) - { - TS_ASSERT_EQUALS( y[j], double(1000*i) + double(j) ); - } - } - - // check that front spectra weren't changed by padding - TS_ASSERT_EQUALS( ws.readY( 0 )[0], 1.0 ); - TS_ASSERT_EQUALS( ws.readY( 1 )[0], 2.0 ); - - conf.setString(blocksize,oldValue); - conf.setString(blockPerFile,oldValueBlockPerFile); - } - - void testPadding() - { - //std::cout << "Start!!!!" << std::endl; - - // This will make sure 1 ManagedDataBlock = 1 Vector - Mantid::Kernel::ConfigServiceImpl& conf = Mantid::Kernel::ConfigService::Instance(); - const std::string blocksize = "ManagedWorkspace.DataBlockSize"; - const std::string oldValue = conf.getString(blocksize); - conf.setString(blocksize,"1"); - - const std::string blockPerFile = "ManagedWorkspace.BlocksPerFile"; - const std::string oldValueBlockPerFile = conf.getString(blockPerFile); - conf.setString(blockPerFile,"10"); - - Mantid::DataObjects::ManagedWorkspace2D ws; - ws.initialize(111,10,9); - - MantidVec fours(10,4.0); - MantidVec fives(9,5.0); - MantidVec sixes(9,6.0); - for ( std::size_t i = 10; i < ws.getNumberHistograms(); ++i ) - { - ws.dataX(i) = fours; - ws.dataY(i) = fives; - ws.dataE(i) = sixes; - } - - // Get back a block that should have gone out to disk and check its values - MantidVec xvals = ws.dataX(50); - MantidVec yvals = ws.dataY(50); - MantidVec evals = ws.dataE(50); - TS_ASSERT_EQUALS( xvals.size(), 10 ); - TS_ASSERT_EQUALS( yvals.size(), 9 ); - TS_ASSERT_EQUALS( evals.size(), 9 ); - for ( std::size_t j = 0; j < 9; ++j ) - { - TS_ASSERT_EQUALS( xvals[j], 4.0 ); - TS_ASSERT_EQUALS( yvals[j], 5.0 ); - TS_ASSERT_EQUALS( evals[j], 6.0 ); - } - TS_ASSERT_EQUALS( xvals.back(), 4.0 ); - - conf.setString(blocksize,oldValue); - conf.setString(blockPerFile,oldValueBlockPerFile); - //std::cout << "End!!!! " << std::endl; - } - - void testDestructor() - { - std::string filename; - { // Scoping block - Mantid::DataObjects::ManagedWorkspace2D tmp; - tmp.initialize(1,1,1); - filename = tmp.get_filename() + "0"; - // File should exist - TS_ASSERT ( Poco::File(filename).exists() ); - } - TSM_ASSERT ( "File should have been deleted", ! Poco::File(filename).exists() ); - } - -private: - Mantid::DataObjects::ManagedWorkspace2D smallWorkspace; - Mantid::DataObjects::ManagedWorkspace2D bigWorkspace; -}; - -//------------------------------------------------------------------------------ -// Performance test -//------------------------------------------------------------------------------ - -class ManagedWorkspace2DTestPerformance : public CxxTest::TestSuite -{ -private: - Mantid::API::MatrixWorkspace_sptr inWS; - Mantid::API::MatrixWorkspace_sptr managedWS; - -public: - static ManagedWorkspace2DTestPerformance *createSuite() { return new ManagedWorkspace2DTestPerformance(); } - static void destroySuite( ManagedWorkspace2DTestPerformance *suite ) { delete suite; } - - ManagedWorkspace2DTestPerformance() - { - // Make sure the input workspace is NOT managed - Mantid::Kernel::ConfigServiceImpl& conf = Mantid::Kernel::ConfigService::Instance(); - conf.setString("ManagedWorkspace.AlwaysInMemory","1"); - // Workspace should use up around 800 MB of memory - inWS = Mantid::API::WorkspaceFactory::Instance().create("Workspace2D",7000,5000,5000); - conf.setString("ManagedWorkspace.AlwaysInMemory","0"); - } - - // This should take ~no time (nothing should be written to disk) - void testCreationViaFactory() - { - // Make sure we go managed - Mantid::Kernel::ConfigServiceImpl& conf = Mantid::Kernel::ConfigService::Instance(); - const std::string managed = "ManagedWorkspace.LowerMemoryLimit"; - const std::string oldValue = conf.getString(managed); - conf.setString(managed,"0"); - const std::string managed2 = "ManagedRawFileWorkspace.DoNotUse"; - const std::string oldValue2 = conf.getString(managed2); - conf.setString(managed2,"0"); - // 1 MB block size - conf.setString("ManagedWorkspace.DataBlockSize", "1000000"); - - Mantid::Kernel::MemoryStats stats; - stats.update(); - size_t memBefore = stats.availMem() ; - - managedWS = Mantid::API::WorkspaceFactory::Instance().create(inWS); - - stats.update(); - double memLoss = double(memBefore) - double(stats.availMem()); - TSM_ASSERT_LESS_THAN( "Memory used up in creating a ManagedWorkspace should be minimal", memLoss, 20*1024); - std::cout << memLoss/(1024.0) << " MB of memory used up in creating an empty ManagedWorkspace." << std::endl; - } - - // This should also take ~no time (nothing should be written to disk) - void testReadSpectrumNumber() - { - Mantid::Kernel::MemoryStats stats; - stats.update(); - size_t memBefore = stats.availMem() ; - - Mantid::specid_t num(0); - for ( std::size_t i = 0 ; i < managedWS->getNumberHistograms(); ++i ) - { - Mantid::API::ISpectrum * spec = managedWS->getSpectrum(i); - if ( ! spec->hasDetectorID(0) ) - { - num = spec->getSpectrumNo(); - } - } - TS_ASSERT ( num != 0 ); - - stats.update(); - double memLoss = double(memBefore) - double(stats.availMem()); - TSM_ASSERT_LESS_THAN( "Memory used up by looping only for spectrum numbers should be minimal", memLoss, 20*1024); - std::cout << memLoss/(1024.0) << " MB of memory used up in looping looking only for spectra." << std::endl; - } - - // This should take a while... - void testLoopOverHalf() - { - Mantid::Kernel::MemoryStats stats; - - // Temporary while I ensure that the memory-per-process code works on each platform -#if _WIN32 - size_t processMemBefore = stats.residentMem(); -#else - size_t memBefore = stats.availMem(); -#endif - - boost::shared_ptr<ManagedWorkspace2D> ws = boost::dynamic_pointer_cast<ManagedWorkspace2D>(managedWS); - TSM_ASSERT("Workspace is really managed", ws); - - for ( std::size_t i = 0; i < 3500; ++i ) - { - managedWS->dataX(i) = inWS->readX(i); - managedWS->dataY(i) = inWS->readY(i); - managedWS->dataE(i) = inWS->readE(i); - } - // For linux, make sure to release old memory - Mantid::API::MemoryManager::Instance().releaseFreeMemory(); - stats.update(); - -#if _WIN32 - size_t processMemNow = stats.residentMem(); - double memLoss = static_cast<double>(processMemNow) - static_cast<double>(processMemBefore); -#else - size_t memNow = stats.availMem(); - double memLoss = static_cast<double>(memBefore) - static_cast<double>(memNow); -#endif - - TSM_ASSERT_LESS_THAN( "MRU list should limit the amount of memory to around 100 MB used when accessing the data.", memLoss, 200*1024); - std::cout << memLoss/(1024.0) << " MB of memory used up in looping. Memory looped over = " << 3500.0*5000*24 / (1024.0*1024.0) << " MB." << std::endl; - } - - // ...but only about half as long as this - void testLoopOverWhole() - { - Mantid::API::MatrixWorkspace_sptr managedWS2 = Mantid::API::WorkspaceFactory::Instance().create(inWS); - for ( std::size_t i = 0 ; i < managedWS2->getNumberHistograms(); ++i ) - { - managedWS2->dataX(i) = inWS->readX(i); - managedWS2->dataY(i) = inWS->readY(i); - managedWS2->dataE(i) = inWS->readE(i); - } - } -}; -#endif /*MANAGEDWORKSPACE2DTEST_H_*/ diff --git a/Code/Mantid/Framework/Kernel/src/ConfigService.cpp b/Code/Mantid/Framework/Kernel/src/ConfigService.cpp index c829caa436b..86a330312a8 100644 --- a/Code/Mantid/Framework/Kernel/src/ConfigService.cpp +++ b/Code/Mantid/Framework/Kernel/src/ConfigService.cpp @@ -232,7 +232,6 @@ ConfigServiceImpl::ConfigServiceImpl() : m_ConfigPaths.insert(std::make_pair("user.python.plugins.directories", true)); m_ConfigPaths.insert(std::make_pair("datasearch.directories", true)); m_ConfigPaths.insert(std::make_pair("icatDownload.directory", true)); - m_ConfigPaths.insert(std::make_pair("ManagedWorkspace.FilePath", true)); //attempt to load the default properties file that resides in the directory of the executable std::string propertiesFilesList; diff --git a/Code/Mantid/Framework/Kernel/test/ConfigServiceTest.h b/Code/Mantid/Framework/Kernel/test/ConfigServiceTest.h index 1c9039fb0b3..5af09a06f00 100644 --- a/Code/Mantid/Framework/Kernel/test/ConfigServiceTest.h +++ b/Code/Mantid/Framework/Kernel/test/ConfigServiceTest.h @@ -191,21 +191,20 @@ public: void TestCustomProperty() { - //Mantid.legs is defined in the properties script as 6 - std::string countString = ConfigService::Instance().getString("ManagedWorkspace.DataBlockSize"); - TS_ASSERT_EQUALS(countString, "4000"); + std::string countString = ConfigService::Instance().getString("algorithms.retained"); + TS_ASSERT_EQUALS(countString, "50"); } void TestCustomPropertyAsValue() { //Mantid.legs is defined in the properties script as 6 int value = 0; - ConfigService::Instance().getValue("ManagedWorkspace.DataBlockSize",value); + ConfigService::Instance().getValue("algorithms.retained",value); double dblValue = 0; - ConfigService::Instance().getValue("ManagedWorkspace.DataBlockSize",dblValue); + ConfigService::Instance().getValue("algorithms.retained",dblValue); - TS_ASSERT_EQUALS(value, 4000); - TS_ASSERT_EQUALS(dblValue, 4000.0); + TS_ASSERT_EQUALS(value, 50); + TS_ASSERT_EQUALS(dblValue, 50.0); } void TestMissingProperty() diff --git a/Code/Mantid/Framework/Properties/Mantid.properties.template b/Code/Mantid/Framework/Properties/Mantid.properties.template index 9aa0919a994..ac2bfe7691a 100644 --- a/Code/Mantid/Framework/Properties/Mantid.properties.template +++ b/Code/Mantid/Framework/Properties/Mantid.properties.template @@ -95,20 +95,6 @@ icatDownload.directory = # The Number of algorithms properties to retain im memory for refence in scripts. algorithms.retained = 50 -# ManagedWorkspace.LowerMemoryLimit sets the memory limit to trigger the use of -# a ManagedWorkspace. A ManagedWorkspace will be used for a workspace requiring greater amount of memory -# than defined by LowerMemoryLimit. LowerMemoryLimit is a precentage of the physical memory available for -# the process. On Linux it is the free physical memory, on Windows it is the smaller of the free physical memory -# and the available virtual memory. The default value for LowerMemoryLimit is 40%. Setting the limit too high -# may lead to unrecoverable bad allocations. If this happens the advice is to close Mantid and relaunch it -# with a smaller LowerMemoryLimit. -# -ManagedWorkspace.LowerMemoryLimit = 80 -# Setting this to 1 will disable managed workspaces completely - use with care! -ManagedWorkspace.AlwaysInMemory = 0 -ManagedWorkspace.DataBlockSize = 4000 -ManagedWorkspace.FilePath = - # Defines the maximum number of cores to use for OpenMP # For machine default set to 0 MultiThreaded.MaxCores = 0 diff --git a/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/MatrixWorkspace.cpp b/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/MatrixWorkspace.cpp index 73714e1afa3..3ee289eeb29 100644 --- a/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/MatrixWorkspace.cpp +++ b/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/MatrixWorkspace.cpp @@ -239,10 +239,9 @@ void export_MatrixWorkspace() //------------------------------------------------------------------------------------------------- - static const int NUM_IDS = 8; + static const int NUM_IDS = 7; static const char * WORKSPACE_IDS[NUM_IDS] = {\ - "GroupingWorkspace", "ManagedWorkspace2D", - "MaskWorkspace", "OffsetsWorkspace", + "GroupingWorkspace", "MaskWorkspace", "OffsetsWorkspace", "RebinnedOutput", "SpecialWorkspace2D", "Workspace2D", "WorkspaceSingleValue" }; diff --git a/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp b/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp index d151fe48cf8..9b27e1eb040 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp @@ -1921,7 +1921,7 @@ void MantidUI::manageMantidWorkspaces() #ifdef _WIN32 memoryImage(); #else - QMessageBox::warning(appWindow(),tr("Mantid Workspace"),tr("Clicked on Managed Workspace"),tr("Ok"),tr("Cancel"),QString(),0,1); + QMessageBox::warning(appWindow(),tr("Mantid Workspace"),tr("Clicked on Manage Workspace"),tr("Ok"),tr("Cancel"),QString(),0,1); #endif } diff --git a/Code/Mantid/MantidPlot/src/Mantid/WorkspaceIcons.cpp b/Code/Mantid/MantidPlot/src/Mantid/WorkspaceIcons.cpp index 92dad1d753e..757413ba089 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/WorkspaceIcons.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/WorkspaceIcons.cpp @@ -40,7 +40,6 @@ void WorkspaceIcons::initInternalLookup() // MatrixWorkspace types m_idToPixmapName["EventWorkspace"] = "mantid_matrix_xpm"; m_idToPixmapName["GroupingWorkspace"] = "mantid_matrix_xpm"; - m_idToPixmapName["ManagedWorkspace2D"] = "mantid_matrix_xpm"; m_idToPixmapName["MaskWorkspace"] = "mantid_matrix_xpm"; m_idToPixmapName["OffsetsWorkspace"] = "mantid_matrix_xpm"; m_idToPixmapName["RebinnedOutput"] = "mantid_matrix_xpm"; -- GitLab