Skip to content

Commit

Permalink
refs #6449 BoxControllerNeXusIO reads/writes double and float events
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts authored and martyngigg committed Apr 10, 2013
1 parent 21639cd commit a93f8de
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 175 deletions.
10 changes: 5 additions & 5 deletions Code/Mantid/Framework/MDAlgorithms/src/LoadMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ and used by other algorithms, they should not be needed in daily use.
#include "MantidMDEvents/MDEventFactory.h"
#include "MantidMDEvents/MDBoxFlatTree.h"
#include "MantidMDEvents/MDHistoWorkspace.h"
#include "MantidMDEvents/BoxControllerNxSIO.h"
#include "MantidMDEvents/BoxControllerNeXusIO.h"
#include <nexus/NeXusException.hpp>
#include <boost/algorithm/string.hpp>
#include <vector>
Expand Down Expand Up @@ -357,8 +357,8 @@ namespace Mantid
// ---------------------------------------- DEAL WITH BOXES ------------------------------------
if (FileBackEnd)
{ // TODO:: call to the file format factory
auto loader = boost::shared_ptr<API::IBoxControllerIO>(new MDEvents::BoxControllerNxSIO(bc.get()));
loader->setDataType(sizeof(size_t),MDE::getTypeName());
auto loader = boost::shared_ptr<API::IBoxControllerIO>(new MDEvents::BoxControllerNeXusIO(bc.get()));
loader->setDataType(sizeof(coord_t),MDE::getTypeName());
bc->setFileBacked(loader,m_filename);
// boxes have been already made file-backed when restoring the boxTree;
// How much memory for the cache?
Expand All @@ -381,8 +381,8 @@ namespace Mantid
{
// ---------------------------------------- READ IN THE BOXES ------------------------------------
// TODO:: call to the file format factory
auto loader = file_holder_type(new MDEvents::BoxControllerNxSIO(bc.get()));
loader->setDataType(sizeof(size_t),MDE::getTypeName());
auto loader = file_holder_type(new MDEvents::BoxControllerNeXusIO(bc.get()));
loader->setDataType(sizeof(coord_t),MDE::getTypeName());

loader->openFile(m_filename,"r");

Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/MDAlgorithms/src/LoadSQW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Parts of the code were written with the idea of generalising functionality at a
#include <iostream>
#include <cfloat>
#include "MantidMDEvents/MDBox.h"
#include "MantidMDEvents/BoxControllerNxSIO.h"
#include "MantidMDEvents/BoxControllerNeXusIO.h"
#include "MantidKernel/Memory.h"


Expand Down Expand Up @@ -268,7 +268,7 @@ namespace Mantid
// set file backed;
if(!m_outputFile.empty())
{
auto Saver = boost::shared_ptr<API::IBoxControllerIO>(new MDEvents::BoxControllerNxSIO(bc.get()));
auto Saver = boost::shared_ptr<API::IBoxControllerIO>(new MDEvents::BoxControllerNeXusIO(bc.get()));
bc->setFileBacked(Saver,m_outputFile);
pWs->getBox()->setFileBacked();
bc->getFileIO()->setWriteBufferSize(1000000);
Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/Framework/MDAlgorithms/src/MergeMDFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ See also: [[MergeMD]], for merging any MDWorkspaces in system memory (faster, bu
#include "MantidKernel/System.h"
#include "MantidMDEvents/MDBoxBase.h"
#include "MantidMDEvents/MDEventFactory.h"
#include "MantidMDEvents/BoxControllerNxSIO.h"
#include "MantidMDEvents/BoxControllerNeXusIO.h"
#include "MantidMDAlgorithms/MergeMDFiles.h"
#include "MantidAPI/MemoryManager.h"

Expand Down Expand Up @@ -132,7 +132,7 @@ namespace MDAlgorithms
auto bc = boost::shared_ptr<API::BoxController>(new API::BoxController(nd));
bc->fromXMLString(m_fileComponentsStructure[i].getBCXMLdescr());

m_EventLoader[i] = new BoxControllerNxSIO(bc.get());
m_EventLoader[i] = new BoxControllerNeXusIO(bc.get());
m_EventLoader[i]->setDataType(sizeof(coord_t),MDE::getTypeName());
m_EventLoader[i]->openFile(m_Filenames[i],"r");

Expand Down Expand Up @@ -218,7 +218,7 @@ namespace MDAlgorithms
// Fix the max depth to something bigger.
bc->setMaxDepth(20);
bc->setSplitThreshold(5000);
auto saver = boost::shared_ptr<API::IBoxControllerIO>(new MDEvents::BoxControllerNxSIO(bc.get()));
auto saver = boost::shared_ptr<API::IBoxControllerIO>(new MDEvents::BoxControllerNeXusIO(bc.get()));
saver->setDataType(sizeof(coord_t),MDE::getTypeName());
if(m_fileBasedTargetWS)
{
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/MDAlgorithms/src/SaveMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ If you specify UpdateFileBackEnd, then any changes (e.g. events added using the
#include <Poco/File.h>
#include "MantidMDEvents/MDHistoWorkspace.h"
#include "MantidMDEvents/MDBoxFlatTree.h"
#include "MantidMDEvents/BoxControllerNxSIO.h"
#include "MantidMDEvents/BoxControllerNeXusIO.h"


#if defined (__INTEL_COMPILER)
Expand Down Expand Up @@ -171,7 +171,7 @@ namespace MDAlgorithms
// the boxes file positions are unknown and we need to calculate it.
BoxFlatStruct.initFlatStructure(ws,filename);
// create saver class
auto Saver = boost::shared_ptr<API::IBoxControllerIO>(new MDEvents::BoxControllerNxSIO(bc.get()));
auto Saver = boost::shared_ptr<API::IBoxControllerIO>(new MDEvents::BoxControllerNeXusIO(bc.get()));
Saver->setDataType(sizeof(coord_t),MDE::getTypeName());
if(MakeFileBacked)
{
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/MDAlgorithms/test/LoadMDTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "MantidMDEvents/MDGridBox.h"
#include "MantidMDEvents/MDEventFactory.h"
#include "MantidMDEvents/MDEventWorkspace.h"
#include "MantidMDEvents/BoxControllerNxSIO.h"
#include "MantidMDEvents/BoxControllerNeXusIO.h"
#include "SaveMDTest.h"
#include <cxxtest/TestSuite.h>
#include <iomanip>
Expand Down Expand Up @@ -332,7 +332,7 @@ class LoadMDTest : public CxxTest::TestSuite
TS_ASSERT( saver.isExecuted() );

// Now we look at the file that's currently open
auto loader = dynamic_cast<BoxControllerNxSIO *>( ws2->getBoxController()->getFileIO());
auto loader = dynamic_cast<BoxControllerNeXusIO *>( ws2->getBoxController()->getFileIO());
TS_ASSERT(loader);
if(!loader)return;

Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/MDAlgorithms/test/PlusMDTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <Poco/File.h>
#include "MantidTestHelpers/BinaryOperationMDTestHelper.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidMDEvents/BoxControllerNxSIO.h"
#include "MantidMDEvents/BoxControllerNeXusIO.h"

using namespace Mantid;
using namespace Mantid::MDEvents;
Expand Down Expand Up @@ -81,7 +81,7 @@ class PlusMDTest : public CxxTest::TestSuite
Mantid::API::BoxController_sptr bc = ws->getBoxController();
std::cout << bc->getFileIO()->getFreeSpaceMap().size() << " entries in the free space map" << std::endl;

auto loader = dynamic_cast<MDEvents::BoxControllerNxSIO *>( bc->getFileIO());
auto loader = dynamic_cast<MDEvents::BoxControllerNeXusIO *>( bc->getFileIO());
TS_ASSERT(loader);
if(!loader)return;
std::vector<uint64_t> freeSpaceMap;
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/MDEvents/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set ( SRC_FILES
#
src/AffineMatrixParameter.cpp
src/AffineMatrixParameterParser.cpp
src/BoxControllerNxSIO.cpp
src/BoxControllerNeXusIO.cpp
src/BoxControllerSettingsAlgorithm.cpp
src/ConvToMDBase.cpp
src/ConvToMDEventsWS.cpp
Expand Down Expand Up @@ -69,7 +69,7 @@ set ( INC_FILES
#
inc/MantidMDEvents/AffineMatrixParameter.h
inc/MantidMDEvents/AffineMatrixParameterParser.h
inc/MantidMDEvents/BoxControllerNxSIO.h
inc/MantidMDEvents/BoxControllerNeXusIO.h
inc/MantidMDEvents/BoxControllerSettingsAlgorithm.h
# inc/MantidMDEvents/BoxCtrlChangesList.h
inc/MantidMDEvents/ConvToMDBase.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ namespace MDEvents
File change history is stored at: <https://github.com/mantidproject/mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport BoxControllerNxSIO : public API::IBoxControllerIO
class DLLExport BoxControllerNeXusIO : public API::IBoxControllerIO
{
public:
BoxControllerNxSIO(API::BoxController *const theBC);
BoxControllerNeXusIO(API::BoxController *const theBC);

///@return true if the file to write events is opened and false otherwise
virtual bool isOpened()const
Expand All @@ -60,21 +60,21 @@ namespace MDEvents
}

virtual bool openFile(const std::string &fileName,const std::string &mode);

virtual void saveBlock(const std::vector<float> & /* DataBlock */, const uint64_t /*blockPosition*/)const;
virtual void saveBlock(const std::vector<double> & /* DataBlock */, const uint64_t /*blockPosition*/)const
{throw Kernel::Exception::NotImplementedError("Saving double presision events blocks is not supported at the moment");}
virtual void loadBlock(std::vector<float> & /* Block */, const uint64_t /*blockPosition*/,const size_t /*BlockSize*/)const;
virtual void loadBlock(std::vector<double> & /* Block */, const uint64_t /*blockPosition*/,const size_t /*BlockSize*/)const
{throw Kernel::Exception::NotImplementedError("Loading double presision events blocks is not supported at the moment");}
virtual void saveBlock(const std::vector<double> & /* DataBlock */, const uint64_t /*blockPosition*/)const;
virtual void loadBlock(std::vector<double> & /* Block */, const uint64_t /*blockPosition*/,const size_t /*BlockSize*/)const;

virtual void flushData()const;
virtual void closeFile();

virtual ~BoxControllerNxSIO();
virtual ~BoxControllerNeXusIO();
//Auxiliary functions. Used to change default state of this object which is not fully supported. Should be replaced by some IBoxControllerIO factory
virtual void setDataType(const size_t coordSize, const std::string &typeName);
virtual void getDataType(size_t &coordSize, std::string &typeName)const;
//------------------------------------------------------------------------------------------------------------------------
//Auxiliary functions (non-virtual, used at testing)
//Auxiliary functions (non-virtual, used for testing)
int64_t getNDataColums()const
{
return m_BlockSize[1];
Expand Down Expand Up @@ -111,10 +111,10 @@ namespace MDEvents
enum EventType
{
LeanEvent=0, //< the event consisting of signal error and event coordinate
FatEvent=1 //< the event havint the same as lean event plus RunID and detID
};
/// the type of event (currently MD event or MDLean event this class is deals with.
EventType m_EventType;
FatEvent=1 //< the event having the same as lean event plus RunID and detID
/// the type of event (currently MD event or MDLean event this class deals with. )
}m_EventType;



/// The version of the MDEvents data block
Expand All @@ -124,8 +124,6 @@ namespace MDEvents
/// data headers used for different events types
std::vector<std::string> m_EventsTypeHeaders;

/// the name of the MD workspace group. Should be common with save/load, who uses this group to put other pieces of information about the workspace.
static std::string g_EventWSGroupName;
/// the name of the Nexus data group for saving the events
static std::string g_EventGroupName;
/// the group name to save disk buffer data
Expand All @@ -140,7 +138,20 @@ namespace MDEvents
void prepareNxSdata_CurVersion();
// get the event type from event name
static EventType TypeFromString(const std::vector<std::string> &typesSupported,const std::string typeName);
/// the enum, which suggests the way (currently)two possible data types are converted to each other
enum CoordConversion
{
noConversion,
floatToDouble,
doubleToFolat
/// conversion btween fload/double requested by the client
}m_ReadConversion;


template<typename Type>
void saveGenericBlock(const std::vector<Type> & DataBlock, const uint64_t blockPosition)const ;
template<typename Type>
void loadGenericBlock(std::vector<Type> & DataBlock, const uint64_t blockPosition,const size_t blockSize)const ;

};

Expand Down

0 comments on commit a93f8de

Please sign in to comment.