Skip to content

Commit

Permalink
refs #7200 Added MDBox factory to MD events factory
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed May 29, 2013
1 parent 4bd6f1a commit 819bac0
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 19 deletions.
41 changes: 32 additions & 9 deletions Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDEventFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,31 @@ namespace MDEvents
*/
class DLLExport MDEventFactory
{
// definition which states how many dimensions to generate.
/// definition which states how many dimensions to generate. If this number changes, one has to run generate_mdevent_declarations to reinstantiate atogenerated code
enum {MAX_MD_DIMENSIONS_NUM = 9};
public:
/** enum defines fifferent box types generated by createBox factory
* We will use typecast from integer to these types so it is important to define consisten numbers to these types */
enum BoxType
{
MDBoxWithLean=0, //< MDBox generated for MDLeanEvent
MDBoxWithFat=1, //< MDBox generated for MDEvent
MDGridBoxWithLean=2, //< MDGridBox generated for MDLeanEvent
MDGridBoxWithFat=3, //< MDGridBox generated for MDEvent
NumBoxTypes=4 //< Number of different types of the events, used as metaloop splitter
};
MDEventFactory() {}
~MDEventFactory() {}
// create MD workspace factory call
static API::IMDEventWorkspace_sptr CreateMDWorkspace(size_t nd, const std::string & eventType="MDLeanEvent");

static API::IMDNode * createBox(size_t nDimensions, API::BoxController_sptr & splitter, const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t> > & extentsVector,
const uint32_t depth=0,const size_t nBoxEvents=UNDEF_SIZET,const size_t boxID=UNDEF_SIZET, const std::string & eventType="MDLeanEvent");
static API::IMDNode * createGridBox(size_t nd, API::BoxController_sptr & splitter, const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t> > & extentsVector,
const uint32_t depth=0,const size_t nBoxEvents=UNDEF_SIZET,const size_t boxID=UNDEF_SIZET, const std::string & eventType="MDLeanEvent");
private:
typedef API::IMDNode *(MDEventFactory::*fpCreateBox)(size_t nDim,API::BoxController_sptr & ,const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t> > & ,
const uint32_t,const size_t ,const size_t, const std::string &);
// create MDBox factory call
static API::IMDNode * createBox(size_t nDimensions,BoxType Type, API::BoxController_sptr & splitter,
const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t> > & extentsVector = std::vector<Mantid::Geometry::MDDimensionExtents<coord_t> >(),
const uint32_t depth=0,const size_t nBoxEvents=UNDEF_SIZET,const size_t boxID=UNDEF_SIZET);
private:
typedef API::IMDNode *(*fpCreateBox)(API::BoxController * ,const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t> > & ,
const uint32_t,const size_t ,const size_t);
// vector of function pointers to the functions which create MDBox or MDGridBox;
static std::vector<fpCreateBox> boxCreatorFP;

Expand All @@ -49,10 +60,22 @@ namespace MDEvents
// vector of function pointers to the funcions
static std::vector<fpCreateMDWS> wsCreatorFP;

// as the constructor's address can not be taken, we are writing local wrapper around the constructor. This can also help in a future when writing custom memory allocator
//local wrapper around the MDWorkspace constructor as the constructor's address can not be taken . This can also help in a future when writing custom memory allocator
template<size_t nd>
static API::IMDEventWorkspace * createMDWorkspaceND(const std::string & eventType);

//local wrappers around the MDBox/MDGridBox constructors as the constructor's address can not be taken. This can also help in a future when writing custom memory allocator
template<size_t nd>
static API::IMDNode * createMDBoxLean(API::BoxController *splitter,const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t> > & extentsVector,const uint32_t depth,const size_t nBoxEvents,const size_t boxID);
template<size_t nd>
static API::IMDNode * createMDBoxFat(API::BoxController *splitter,const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t> > & extentsVector,const uint32_t depth,const size_t nBoxEvents,const size_t boxID);
template<size_t nd>
static API::IMDNode * createMDGridBoxLean(API::BoxController *splitter,const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t> > & extentsVector,const uint32_t depth,const size_t nBoxEvents,const size_t boxID);
template<size_t nd>
static API::IMDNode * createMDGridBoxFat(API::BoxController *splitter,const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t> > & extentsVector,const uint32_t depth,const size_t nBoxEvents,const size_t boxID);
// 0-dimensions terminator
static API::IMDNode * createMDBoxWrong(API::BoxController *,const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t> > & ,const uint32_t ,const size_t ,const size_t );


// helper class to generate methaloop on MD workspaces dimensions:
template<size_t nd>
Expand Down
60 changes: 50 additions & 10 deletions Code/Mantid/Framework/MDEvents/src/MDEventFactory.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/* Auto-generated by 'D:\Data\Mantid_GIT\Code\Mantid\Framework\MDEvents\src\generate_mdevent_declarations.py'
* on 2013-05-28 12:45:23.952000
*
* DO NOT EDIT!
*/

#include <boost/shared_ptr.hpp>
#include "MantidMDEvents/MDEventFactory.h"
#include "MantidAPI/IMDEventWorkspace.h"
Expand All @@ -28,6 +22,13 @@
#include "MDBoxIterator.cpp"


/* Auto-generated by 'generate_mdevent_declarations.py'
* on 2013-05-28 12:45:23.952000
*
* DO NOT EDIT!
*/

//### BEGIN AUTO-GENERATED CODE #################################################################
namespace Mantid
{
namespace MDEvents
Expand Down Expand Up @@ -186,17 +187,18 @@ template DLLExport class MDBoxIterator<MDLeanEvent<9>, 9>;

} // namespace Mantid
} // namespace MDEvents
//### END AUTO-GENERATED CODE ##################################################################

/* THE PART OF FILE ABOWE WAS AUTO-GENERATED BY D:\Data\Mantid_GIT\Code\Mantid\Framework\MDEvents\src\generate_mdevent_declarations.py - DO NOT EDIT! */

namespace Mantid
{
namespace MDEvents
{
std::vector<MDEventFactory::fpCreateBox> MDEventFactory::boxCreatorFP(4*(MDEventFactory::MAX_MD_DIMENSIONS_NUM+1),NULL);
std::vector<MDEventFactory::fpCreateBox> MDEventFactory::boxCreatorFP(MDEventFactory::NumBoxTypes*(MDEventFactory::MAX_MD_DIMENSIONS_NUM+1),NULL);
std::vector<MDEventFactory::fpCreateMDWS> MDEventFactory::wsCreatorFP(MDEventFactory::MAX_MD_DIMENSIONS_NUM+1,NULL);


//-------------------------------------------------------------- MD Workspace constructor wrapper
template<size_t nd>
API::IMDEventWorkspace * MDEventFactory::createMDWorkspaceND(const std::string & eventType)
{
Expand All @@ -210,11 +212,40 @@ namespace Mantid
}

template<>
API::IMDEventWorkspace * MDEventFactory::createMDWorkspaceND<0>(const std::string & eventType)
API::IMDEventWorkspace * MDEventFactory::createMDWorkspaceND<0>(const std::string & /*eventType*/)
{
throw std::invalid_argument("Workspace can not have 0 dimensions");
}
//-------------------------------------------------------------- MD BOX constructor wrapper
API::IMDNode * MDEventFactory::createMDBoxWrong(API::BoxController *,const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t> > & ,const uint32_t ,const size_t ,const size_t )
{
throw std::invalid_argument("MDBox/MDGridBox can not have 0 dimensions");
}

template<size_t nd>
API::IMDNode * MDEventFactory::createMDBoxLean(API::BoxController *splitter,const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t> > & extentsVector,const uint32_t depth,const size_t nBoxEvents,const size_t boxID)
{
return new MDBox<MDLeanEvent<nd>,nd>(splitter,depth,extentsVector,nBoxEvents,boxID);
}

template<size_t nd>
API::IMDNode * MDEventFactory::createMDBoxFat(API::BoxController *splitter,const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t> > & extentsVector,const uint32_t depth,const size_t nBoxEvents,const size_t boxID)
{
return new MDBox<MDEvent<nd>,nd>(splitter,depth,extentsVector,nBoxEvents,boxID);
}

template<size_t nd>
API::IMDNode * createMDGridBoxLean(API::BoxController *splitter,const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t> > & extentsVector,const uint32_t depth,const size_t nBoxEvents,const size_t boxID)
{
return new MDGridBox<MDLeanEvent<nd>,nd>(splitter,depth,extentsVector,nBoxEvents,boxID);
}

template<size_t nd>
static API::IMDNode * createMDGridBoxFat(API::BoxController *splitter,const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t> > & extentsVector,const uint32_t depth,const size_t nBoxEvents,const size_t boxID)
{
return new MDGridBox<MDEvent<nd>,nd>(splitter,depth,extentsVector,nBoxEvents,boxID);
}
//-------------------------------------------------------------- MD BOX constructor wrapper -- END

/** Create a MDEventWorkspace of the given type
@param nd :: number of dimensions
Expand Down Expand Up @@ -248,6 +279,10 @@ namespace Mantid
LOOP< nd-1 >::EXEC();
MDEventFactory::wsCreatorFP[nd] = &MDEventFactory::createMDWorkspaceND<nd>;

MDEventFactory::boxCreatorFP[MDEventFactory::NumBoxTypes*nd+MDEventFactory::MDBoxWithLean] = &MDEventFactory::createMDBoxLean<nd>;
MDEventFactory::boxCreatorFP[MDEventFactory::NumBoxTypes*nd+MDEventFactory::MDBoxWithFat] = &MDEventFactory::createMDBoxFat<nd>;
MDEventFactory::boxCreatorFP[MDEventFactory::NumBoxTypes*nd+MDEventFactory::MDGridBoxWithLean] = &MDEventFactory::createMDGridBoxLean<nd>;
MDEventFactory::boxCreatorFP[MDEventFactory::NumBoxTypes*nd+MDEventFactory::MDGridBoxWithFat] = &MDEventFactory::createMDGridBoxFat<nd>;
}
};
// the class terminates the compitlation-time metaloop and sets up functions which process 0-dimension workspace operations
Expand All @@ -259,10 +294,15 @@ namespace Mantid
static inline void EXEC()
{
MDEventFactory::wsCreatorFP[0] = &MDEventFactory::createMDWorkspaceND<0>;

MDEventFactory::boxCreatorFP[MDEventFactory::MDBoxWithLean] = &MDEventFactory::createMDBoxWrong;
MDEventFactory::boxCreatorFP[MDEventFactory::MDBoxWithFat] = &MDEventFactory::createMDBoxWrong;
MDEventFactory::boxCreatorFP[MDEventFactory::MDGridBoxWithLean]= &MDEventFactory::createMDBoxWrong;
MDEventFactory::boxCreatorFP[MDEventFactory::MDGridBoxWithFat] = &MDEventFactory::createMDBoxWrong;
}
};


//statically instantiate the code, defined by the class above
LOOP<MDEventFactory::MAX_MD_DIMENSIONS_NUM> MDEventFactory::CODE_GENERATOR;

} // namespace Mantid
Expand Down

0 comments on commit 819bac0

Please sign in to comment.