Skip to content

Commit

Permalink
refs #7200 MDBoxFlatTree is not templated class any more --
Browse files Browse the repository at this point in the history
all code generation moved to MDEventFactory
  • Loading branch information
abuts committed May 29, 2013
1 parent d0082f8 commit 9da5cb2
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 103 deletions.
4 changes: 4 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/IMDNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ class IMDNode
virtual uint32_t getDepth() const=0;
virtual signal_t getSignalNormalized() const=0;

virtual void calcVolume()=0;
virtual void setInverseVolume(const coord_t )=0;
virtual void setSignal(const signal_t )=0;
virtual void setErrorSquared(const signal_t )=0;

// -------------------------------- Geometry/vertexes-Related -------------------------------------------
virtual std::vector<Mantid::Kernel::VMD> getVertexes() const =0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ namespace MDEvents
//-----------------------------------------------------------------------------------------------
/** Sets the inverse of the volume of the cell
* @param invVolume :: value to set. */
void setInverseVolume(coord_t invVolume)
void setInverseVolume(const coord_t invVolume)
{
m_inverseVolume = invVolume;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ namespace MDEvents
//---------------------------------------------------------------------------------------------------------------------
/// convert MDWS box structure into flat structure used for saving/loading on hdd
void initFlatStructure(API::IMDEventWorkspace_sptr pws,const std::string &fileName);
/**Method resotores the interconnected box structure in memory, namely the nodes and their connectivity -->TODO: refactor this into single fucntion and move templating into MDEventFactory */
template<typename MDE,size_t nd>
/** Method resotores the interconnected box structure in memory, namely the nodes and their connectivity*/
uint64_t restoreBoxTree(std::vector<API::IMDNode *>&Boxes ,API::BoxController_sptr bc, bool FileBackEnd,bool NoFileInfo=false);

/*** this function tries to set file positions of the boxes to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ namespace MDEvents
enum BoxType
{
MDBoxWithLean=0, //< MDBox generated for MDLeanEvent
MDBoxWithFat=1, //< MDBox generated for MDEvent
MDGridBoxWithLean=2, //< MDGridBox generated for MDLeanEvent
MDGridBoxWithLean=1, //< MDGridBox generated for MDLeanEvent
MDBoxWithFat=2, //< MDBox generated for MDEvent
MDGridBoxWithFat=3, //< MDGridBox generated for MDEvent
NumBoxTypes=4 //< Number of different types of the events, used as metaloop splitter
};
Expand All @@ -49,6 +49,8 @@ namespace MDEvents
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);
Expand Down
75 changes: 22 additions & 53 deletions Code/Mantid/Framework/MDEvents/src/MDBoxFlatTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "MantidMDEvents/MDLeanEvent.h"
#include "MantidAPI/BoxController.h"
#include "MantidAPI/ExperimentInfo.h"
#include "MantidMDEvents/MDEventFactory.h"
#include <Poco/File.h>

#if defined (__INTEL_COMPILER)
Expand Down Expand Up @@ -261,28 +262,6 @@ namespace Mantid
auto hFile = file_holder_type(createOrOpenMDWSgroup(fileName,size_t(m_nDim),m_eventType,true));


//// How many dimensions?
//std::vector<int32_t> vecDims;
//hFile->readData("dimensions", vecDims);
//if (vecDims.empty())
// throw std::runtime_error("LoadBoxStructure:: Error loading number of dimensions.");

//m_nDim = vecDims[0];
//if (m_nDim<= 0)
// throw std::runtime_error("loadBoxStructure:: number of dimensions <= 0.");

// Now load all the dimension xml
//this->loadDimensions();

//if (entryName == "MDEventWorkspace")
//{
// //The type of event
// std::string eventType;
// file->getAttr("event_type", eventType);

// // Use the factory to make the workspace of the right type
// IMDEventWorkspace_sptr ws = MDEventFactory::CreateMDWorkspace(m_numDims, eventType);
//}
this->loadBoxStructure(hFile.get(),onlyEventInfo);

// close workspace group
Expand Down Expand Up @@ -447,7 +426,6 @@ namespace Mantid



template<typename MDE,size_t nd>
uint64_t MDBoxFlatTree::restoreBoxTree(std::vector<API::IMDNode *>&Boxes,API::BoxController_sptr bc, bool FileBackEnd,bool BoxStructureOnly)
{

Expand All @@ -458,14 +436,22 @@ namespace Mantid
m_nDim = int(bc->getNDims());
if(m_nDim<=0||m_nDim>11 )throw std::runtime_error("Workspace dimesnions are not defined properly");

int iEventType(0);
if(m_eventType=="MDLeanEvent")
iEventType=0;
else if(m_eventType=="MDEvent")
iEventType=2;
else
throw std::invalid_argument(" Unknown event type provided for MDBoxFlatTree::restoreBoxTree");

for (size_t i=0; i<numBoxes; i++)
{

size_t box_type = m_BoxType[i];
if (box_type == 0)continue;

MDBoxBase<MDE,nd> * ibox = NULL;
MDBox<MDE,nd> * box;

API::IMDNode * ibox = NULL;

// Extents of the box, as a vector
std::vector<Mantid::Geometry::MDDimensionExtents<coord_t> > extentsVector(m_nDim);
Expand All @@ -476,34 +462,38 @@ namespace Mantid
uint64_t indexStart = m_BoxEventIndex[i*2];
uint64_t numEvents = m_BoxEventIndex[i*2+1];

totalNumEvents+=numEvents;
totalNumEvents+=numEvents;
if (box_type == 1)
{
// --- Make a MDBox -----
if(BoxStructureOnly)
{
box = new MDBox<MDE,nd>(bc.get(), m_Depth[i], extentsVector);
ibox = MDEventFactory::createBox(size_t(m_nDim),MDEventFactory::BoxType(iEventType),bc,extentsVector);
//box = new MDBox<MDE,nd>(bc.get(), m_Depth[i], extentsVector);
}
else // !BoxStructureOnly)
{

if(FileBackEnd)
{
box = new MDBox<MDE,nd>(bc.get(), m_Depth[i], extentsVector,UNDEF_SIZET);
ibox = MDEventFactory::createBox(size_t(m_nDim),MDEventFactory::BoxType(iEventType),bc,extentsVector,m_Depth[i]);
//box = new MDBox<MDE,nd>(bc.get(), m_Depth[i], extentsVector,UNDEF_SIZET);
// Mark the box as file backed and indicate that the box was saved
box->setFileBacked(indexStart,numEvents,true);
ibox->setFileBacked(indexStart,numEvents,true);
}
else
{
box = new MDBox<MDE,nd>(bc.get(), m_Depth[i], extentsVector,int64_t(numEvents));
ibox = MDEventFactory::createBox(size_t(m_nDim),MDEventFactory::BoxType(iEventType),bc,extentsVector,m_Depth[i],numEvents);
//box = new MDBox<MDE,nd>(bc.get(), m_Depth[i], extentsVector,int64_t(numEvents));
}
} // ifBoxStructureOnly
ibox = box;
//ibox = box;
}
else if (box_type == 2)
{
// --- Make a MDGridBox -----
ibox = new MDGridBox<MDE,nd>(bc.get(), m_Depth[i], extentsVector);
//ibox = new MDGridBox<MDE,nd>(bc.get(), m_Depth[i], extentsVector);
ibox = MDEventFactory::createBox(size_t(m_nDim),MDEventFactory::BoxType(iEventType+1),bc,extentsVector,m_Depth[i]);
}
else
continue;
Expand Down Expand Up @@ -645,27 +635,6 @@ namespace Mantid
}


// TODO: Get rid of this --> create the box generator and move all below into MDBoxFactory!

template DLLExport uint64_t MDBoxFlatTree::restoreBoxTree<MDLeanEvent<1>, 1>(std::vector<API::IMDNode * >&Boxes,API::BoxController_sptr bc, bool FileBackEnd,bool BoxStructureOnly);
template DLLExport uint64_t MDBoxFlatTree::restoreBoxTree<MDLeanEvent<2>, 2>(std::vector<API::IMDNode * >&Boxes,API::BoxController_sptr bc, bool FileBackEnd,bool BoxStructureOnly);
template DLLExport uint64_t MDBoxFlatTree::restoreBoxTree<MDLeanEvent<3>, 3>(std::vector<API::IMDNode * >&Boxes,API::BoxController_sptr bc, bool FileBackEnd,bool BoxStructureOnly);
template DLLExport uint64_t MDBoxFlatTree::restoreBoxTree<MDLeanEvent<4>, 4>(std::vector<API::IMDNode * >&Boxes,API::BoxController_sptr bc, bool FileBackEnd,bool BoxStructureOnly);
template DLLExport uint64_t MDBoxFlatTree::restoreBoxTree<MDLeanEvent<5>, 5>(std::vector<API::IMDNode * >&Boxes,API::BoxController_sptr bc, bool FileBackEnd,bool BoxStructureOnly);
template DLLExport uint64_t MDBoxFlatTree::restoreBoxTree<MDLeanEvent<6>, 6>(std::vector<API::IMDNode * >&Boxes,API::BoxController_sptr bc, bool FileBackEnd,bool BoxStructureOnly);
template DLLExport uint64_t MDBoxFlatTree::restoreBoxTree<MDLeanEvent<7>, 7>(std::vector<API::IMDNode * >&Boxes,API::BoxController_sptr bc, bool FileBackEnd,bool BoxStructureOnly);
template DLLExport uint64_t MDBoxFlatTree::restoreBoxTree<MDLeanEvent<8>, 8>(std::vector<API::IMDNode * >&Boxes,API::BoxController_sptr bc, bool FileBackEnd,bool BoxStructureOnly);
template DLLExport uint64_t MDBoxFlatTree::restoreBoxTree<MDLeanEvent<9>, 9>(std::vector<API::IMDNode * >&Boxes,API::BoxController_sptr bc, bool FileBackEnd,bool BoxStructureOnly);

template DLLExport uint64_t MDBoxFlatTree::restoreBoxTree<MDEvent<1>, 1>(std::vector<API::IMDNode * >&Boxes,API::BoxController_sptr bc, bool FileBackEnd,bool BoxStructureOnly);
template DLLExport uint64_t MDBoxFlatTree::restoreBoxTree<MDEvent<2>, 2>(std::vector<API::IMDNode * >&Boxes,API::BoxController_sptr bc, bool FileBackEnd,bool BoxStructureOnly);
template DLLExport uint64_t MDBoxFlatTree::restoreBoxTree<MDEvent<3>, 3>(std::vector<API::IMDNode * >&Boxes,API::BoxController_sptr bc, bool FileBackEnd,bool BoxStructureOnly);
template DLLExport uint64_t MDBoxFlatTree::restoreBoxTree<MDEvent<4>, 4>(std::vector<API::IMDNode * >&Boxes,API::BoxController_sptr bc, bool FileBackEnd,bool BoxStructureOnly);
template DLLExport uint64_t MDBoxFlatTree::restoreBoxTree<MDEvent<5>, 5>(std::vector<API::IMDNode * >&Boxes,API::BoxController_sptr bc, bool FileBackEnd,bool BoxStructureOnly);
template DLLExport uint64_t MDBoxFlatTree::restoreBoxTree<MDEvent<6>, 6>(std::vector<API::IMDNode * >&Boxes,API::BoxController_sptr bc, bool FileBackEnd,bool BoxStructureOnly);
template DLLExport uint64_t MDBoxFlatTree::restoreBoxTree<MDEvent<7>, 7>(std::vector<API::IMDNode * >&Boxes,API::BoxController_sptr bc, bool FileBackEnd,bool BoxStructureOnly);
template DLLExport uint64_t MDBoxFlatTree::restoreBoxTree<MDEvent<8>, 8>(std::vector<API::IMDNode * >&Boxes,API::BoxController_sptr bc, bool FileBackEnd,bool BoxStructureOnly);
template DLLExport uint64_t MDBoxFlatTree::restoreBoxTree<MDEvent<9>, 9>(std::vector<API::IMDNode * >&Boxes,API::BoxController_sptr bc, bool FileBackEnd,bool BoxStructureOnly);

}
}
93 changes: 48 additions & 45 deletions Code/Mantid/Framework/MDEvents/src/MDEventFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,53 @@ namespace Mantid
{
namespace MDEvents
{
//------------------------------- FACTORY METHODS ------------------------------------------------------------------------------------------------------------------

/** Create a MDEventWorkspace of the given type
@param nd :: number of dimensions
@param eventType :: string describing the event type (MDEvent or MDLeanEvent)
@return shared pointer to the MDEventWorkspace created (as a IMDEventWorkspace).
*/
API::IMDEventWorkspace_sptr MDEventFactory::CreateMDWorkspace(size_t nd, const std::string & eventType)
{

if(nd > MAX_MD_DIMENSIONS_NUM)
throw std::invalid_argument(" there are more dimensions requested then instantiated");

API::IMDEventWorkspace *pWs = (*(wsCreatorFP[nd]))(eventType);

return boost::shared_ptr<API::IMDEventWorkspace >(pWs);
}
/** Create a MDBox or MDGridBoxof the given type
@param nDimensions :: number of dimensions
@param Type :: enum descibing the box (MDBox or MDGridBox) and the event type (MDEvent or MDLeanEvent)
@param splitter :: shared pointer to the box controller responsible for splitting boxes. The BC is not incremented as boxes take usual pointer from this pointer
@param extentsVector:: box extents in all n-dimensions (min-max)
@param depth :: the depth of the box within the box tree
@param nBoxEvents :: if defined, specify the memory the box should allocate to accept events -- not used for MDGridBox
@param boxID :: the unique identifier, referencing location of the box in 1D linked list of boxes. -- not used for MDGridBox
@return pointer to the IMDNode with proper box created.
*/

API::IMDNode * MDEventFactory::createBox(size_t nDimensions,MDEventFactory::BoxType Type, API::BoxController_sptr & splitter,
const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t> > & extentsVector,
const uint32_t depth,const size_t nBoxEvents,const size_t boxID)
{

if(nDimensions > MAX_MD_DIMENSIONS_NUM)
throw std::invalid_argument(" there are more dimensions requested then instantiated");

size_t id = nDimensions*MDEventFactory::NumBoxTypes + Type;

return (*(boxCreatorFP[id]))(splitter.get(),extentsVector,depth,nBoxEvents,boxID);
}

//------------------------------- FACTORY METHODS END --------------------------------------------------------------------------------------------------------------

// static vector, conaining the pointers to the functions to create MD boxes
std::vector<MDEventFactory::fpCreateBox> MDEventFactory::boxCreatorFP(MDEventFactory::NumBoxTypes*(MDEventFactory::MAX_MD_DIMENSIONS_NUM+1),NULL);
// static vector, conaining the pointers to the functions to create MD Workspaces
std::vector<MDEventFactory::fpCreateMDWS> MDEventFactory::wsCreatorFP(MDEventFactory::MAX_MD_DIMENSIONS_NUM+1,NULL);


Expand Down Expand Up @@ -249,52 +295,9 @@ namespace Mantid
}
//-------------------------------------------------------------- MD BOX constructor wrapper -- END

//------------------------------- FACTORY METHODS ------------------------------------------------------------------------------------------------------------------

/** Create a MDEventWorkspace of the given type
@param nd :: number of dimensions
@param eventType :: string describing the event type (MDEvent or MDLeanEvent)
@return shared pointer to the MDEventWorkspace created (as a IMDEventWorkspace).
*/
API::IMDEventWorkspace_sptr MDEventFactory::CreateMDWorkspace(size_t nd, const std::string & eventType)
{

if(nd > MAX_MD_DIMENSIONS_NUM)
throw std::invalid_argument(" there are more dimensions requested then instantiated");

API::IMDEventWorkspace *pWs = (*(wsCreatorFP[nd]))(eventType);

return boost::shared_ptr<API::IMDEventWorkspace >(pWs);
}
/** Create a MDBox or MDGridBoxof the given type
@param nDimensions :: number of dimensions
@param Type :: enum descibing the box (MDBox or MDGridBox) and the event type (MDEvent or MDLeanEvent)
@param splitter :: shared pointer to the box controller responsible for splitting boxes. The BC is not incremented as boxes take usual pointer from this pointer
@param extentsVector:: box extents in all n-dimensions (min-max)
@param depth :: the depth of the box within the box tree
@param nBoxEvents :: if defined, specify the memory the box should allocate to accept events -- not used for MDGridBox
@param boxID :: the unique identifier, referencing location of the box in 1D linked list of boxes. -- not used for MDGridBox
@return pointer to the IMDNode with proper box created.
*/

API::IMDNode * MDEventFactory::createBox(size_t nDimensions,MDEventFactory::BoxType Type, API::BoxController_sptr & splitter,
const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t> > & extentsVector,
const uint32_t depth,const size_t nBoxEvents,const size_t boxID)
{

if(nDimensions > MAX_MD_DIMENSIONS_NUM)
throw std::invalid_argument(" there are more dimensions requested then instantiated");

size_t id = nDimensions*MDEventFactory::NumBoxTypes + Type;

return (*(boxCreatorFP[id]))(splitter.get(),extentsVector,depth,nBoxEvents,boxID);
}

//------------------------------- FACTORY METHODS END --------------------------------------------------------------------------------------------------------------

//// the class instantiated by compiler at compilation time and generates the map,
//// between the number of dimensions and the function, which process this number of dimensions
// the class instantiated by compiler at compilation time and generates the map,
// between the number of dimensions and the function, which process this number of dimensions
template<size_t nd>
class LOOP
{
Expand Down

0 comments on commit 9da5cb2

Please sign in to comment.