Skip to content

Commit

Permalink
refs #5552 Couple of classes/changes to support list of changed cell
Browse files Browse the repository at this point in the history
not yet working/completed
  • Loading branch information
abuts committed Aug 4, 2012
1 parent 6291ea4 commit b43baf4
Show file tree
Hide file tree
Showing 14 changed files with 1,947 additions and 1,701 deletions.
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/API/inc/MantidAPI/BoxController.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace API

BoxController(const BoxController & other );

~BoxController();
virtual ~BoxController();

/// Serialize
std::string toXMLString() const;
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/MDEvents/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ set ( INC_FILES
inc/MantidMDEvents/MDBin.h
inc/MantidMDEvents/MDBox.h
inc/MantidMDEvents/MDBoxToChange.h
inc/MantidMDEvents/BoxCtrlChangesList.h
inc/MantidMDEvents/MDBoxBase.h
inc/MantidMDEvents/MDBoxIterator.h
inc/MantidMDEvents/MDDimensionStats.h
Expand Down Expand Up @@ -175,7 +176,6 @@ set ( TEST_FILES
test/LoadSQWTest.h
test/MDBinTest.h
test/MDBoxBaseTest.h
test/MDBoxToChangeTest.h
test/MDBoxIteratorTest.h
test/MDBoxTest.h
test/MDBoxToChangeTest.h
Expand Down
116 changes: 116 additions & 0 deletions Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/BoxCtrlChangesList.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#ifndef MANTID_BOXCONTROLLER_CHANGELIST_H_
#define MANTID_BOXCONTROLLER_CHANGELIST_H_

#include "MantidKernel/System.h"
#include "MantidKernel/ThreadPool.h"
#include <vector>
#include "MantidAPI/BoxController.h"
#include "MantidMDEvents/MDBoxToChange.h"


namespace Mantid
{
namespace MDEvents
{
/** This class is used to keep list of boxes, which have to be eventually split
*
* @date 27/07/2012
Copyright &copy; 2010 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://svn.mantidproject.org/mantid/trunk/Code/Mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
template<class T >
class BoxCtrlChangesList: public API::BoxController
{
//-----------------------------------------------------------------------------------
/** Add a MDBox pointer to the list of boxes to split.
* Thread-safe for adding.
* No duplicate checking is done!
*
* @param ptr :: void ptr that casts to a particular MDBox<> * type.
*/
public:
void addBoxToSplit(const T &theBox)
{
m_boxesToSplitMutex.lock();
m_boxesToSplit.push_back(theBox);
m_boxesToSplitMutex.unlock();
}

//-----------------------------------------------------------------------------------
/** Get a reference to the vector of boxes that must be split.
* Not thread safe!
*/
std::vector<T> getBoxesToSplit()const
{
return m_boxesToSplit;
}
//-----------------------------------------------------------------------------------
/** Get a reference to the vector of BoxesToSplit that can be split.
* thread safe!
*/

template<class MDBoxToChange >
std::vector< MDBoxToChange > getBoxesToSplit()const
{
m_boxesToSplitMutex.lock();
return m_boxesToSplit;
m_boxesToSplitMutex.unlock();
}
//-----------------------------------------------------------------------------------
/** Clears the list of boxes that are big enough to split */
void clearBoxesToSplit()
{
m_boxesToSplitMutex.lock();
m_boxesToSplit.clear();
m_boxesToSplitMutex.unlock();
}
/**Copy constructor from a box controller pointer */
BoxCtrlChangesList(const API::BoxController & theController):
BoxController(theController)
{
auto *bc = dynamic_cast<const BoxCtrlChangesList<T>* >(&theController);
if(bc)m_boxesToSplit.assign(bc->m_boxesToSplit.begin(),bc->m_boxesToSplit.end());
}

/**Copy constructor from a BoxCtrlChangesList, not default as mutex can not be copied */
BoxCtrlChangesList(const BoxCtrlChangesList & other):
BoxController(other)
{
m_boxesToSplit.assign(other.m_boxesToSplit.begin(),other.m_boxesToSplit.end());
}

/**constructor with number of dimensions */
BoxCtrlChangesList(size_t nd):BoxController(nd){};

private:
//
/// Mutex for modifying the m_boxesToSplit member
Mantid::Kernel::Mutex m_boxesToSplitMutex;

/// Vector of MDBoxes to change
std::vector<T> m_boxesToSplit;
};

}
}
#endif
1 change: 0 additions & 1 deletion Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ namespace MDEvents

void addEvent(const MDE & point);
void addAndTraceEvent(const MDE & point,size_t index);

void addEventUnsafe(const MDE & point);

size_t addEventsPart(const std::vector<MDE> & events, const size_t start_at, const size_t stop_at);
Expand Down
111 changes: 87 additions & 24 deletions Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDBoxToChange.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,110 @@ namespace Mantid
{
namespace MDEvents
{
/** The class to contain and do operations over the list of MDBox-es which have been changed and need
* to be split eventually
*
* @date 30-07-2012
/** The class to contains the information about an MDBox which has to be eventually split and aboul location of this box
* in the MDBox structure
*
* @date 30-07-2012
Copyright &copy; 2010 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
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 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.
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/>.
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://svn.mantidproject.org/mantid/trunk/Code/Mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
File/ change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/

//-----------------------------------------------
//-----------------------------------------------
template<typename MDE, size_t nd>
class DLLExport MDBoxToChange
class MDBoxToChange
{
public:
MDBoxToChange():m_ParentGridBox(NULL),m_Index(std::numeric_limits<size_t>::max()-1){};
MDBoxToChange(MDBox<MDE,nd> *box,size_t Index);

size_t getIndex()const{return m_Index;}
MDGridBox<MDE,nd>* splitToGridBox();

MDGridBox<MDE,nd>* getParent()const{return m_ParentGridBox;}

// Below for the time being:
//MDGridBox<MDE,nd>* splitToGridBox();
//MDBoxToChange(MDBox<MDE,nd> *box,size_t Index);

private:
/// the pointer to the greedbox, which contains box to split
MDGridBox<MDE,nd>* m_ParentGridBox;
/// index of the box to split in the gridbox array
size_t m_Index;
public:
/**function checks if the containing box has enough data
* the definition "enough" is also specified within this function
*/
bool isFull(size_t maxSize=1000)
{
return true;
}
/**DESCRIBE */
MDBoxToChange(MDBox<MDE,nd> *box,size_t Index)
{
m_Index = Index;
MDGridBox<MDE, nd> * parent = dynamic_cast<MDGridBox<MDE, nd> * >(box->getParent());
if(parent)
{
m_ParentGridBox=parent;
}
else //HACK! if not parent, it is probably root a box -> such type should be created but meanwhile;
{
m_ParentGridBox=reinterpret_cast<MDGridBox<MDE,nd> *>(box);
m_Index = std::numeric_limits<size_t>::max();
}

}

/**DESCRIBE */
MDGridBox<MDE,nd>* splitToGridBox()
{
MDBox<MDE, nd> *pMDBox;
bool rootBox(false);
// get the actual box to split:
if(m_Index==std::numeric_limits<size_t>::max())
{
rootBox = true;
pMDBox = reinterpret_cast<MDBox<MDE,nd>*>(m_ParentGridBox);
}
else pMDBox = dynamic_cast<MDBox<MDE,nd>*>(m_ParentGridBox->getChild(m_Index));


// Construct the grid instead of box. This should take the object out of the disk MRU
MDGridBox<MDE, nd> * gridbox = new MDGridBox<MDE, nd>(pMDBox);
// Track how many MDBoxes there are in the overall workspace
pMDBox->getBoxController()->trackNumBoxes(pMDBox->getDepth());


if(rootBox) // carefull -- root pointer is not redefined here!
{
// this makes workspace data pointer invalid, but the actual pointer will remain dangling so care should be taken not to dereference it
delete pMDBox;
m_ParentGridBox = gridbox;
}
else
{ // this will delete the old box and set new gridBox instead
m_ParentGridBox->setChild(m_Index,gridbox);
}
// make this grid box undefined again
m_Index=std::numeric_limits<size_t>::max()-1;

return gridbox;
}
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ namespace Mantid
API::IMDEventWorkspace_sptr createEmptyMDWS(const MDWSDescription &WSD);
/// add the data to the internal workspace. The workspace has to exist and be initiated
void addMDData(std::vector<float> &sig_err,std::vector<uint16_t> &run_index,std::vector<uint32_t> &det_id,std::vector<coord_t> &Coord,size_t data_size)const;
/// add the data to the internal workspace and trace boxes which changed. The workspace has to exist and be initiated
void addAndTraceMDData(std::vector<float> &sig_err,std::vector<uint16_t> &run_index,std::vector<uint32_t> &det_id,std::vector<coord_t> &Coord,size_t data_size)const;

/// releases the shared pointer to the workspace, stored by the class and makes the class instance undefined;
void releaseWorkspace();
/// get access to the internal workspace
Expand All @@ -90,7 +93,10 @@ namespace Mantid
/// vector holding function pointers to the code, creating different number of dimension worspace as function of dimensions number
std::vector<fpCreateWS> wsCreator;
/// vector holding function pointers to the code, which adds diffrent dimension number events to the workspace
std::vector<fpAddData> mdEvSummator;
std::vector<fpAddData> mdEvAddAndForget;
/// vector holding function pointers to the code, which adds diffrent dimension number events to the workspace and traces the added cells
std::vector<fpAddData> mdEvAddAndTrace;

/// vector holding function pointers to the code, which refreshes centroid (could it be moved to IMD?)
std::vector<fpVoidMethod> mdCalCentroid;
/// vector holding function pointers to the code, which split list of boxes need splitting
Expand All @@ -100,9 +106,13 @@ namespace Mantid
// helper class to generate methaloop on MD workspaces dimensions:
template< size_t i>
friend class LOOP;

// internal function tempates to generate as function of dimensions and assightn to function pointers
template<size_t nd>
void addMDDataND(float *sig_err,uint16_t *run_index,uint32_t* det_id,coord_t* Coord,size_t data_size)const;
template<size_t nd>
void addAndTraceMDDataND(float *sig_err,uint16_t *run_index,uint32_t* det_id,coord_t* Coord,size_t data_size)const;


template<size_t nd>
void calcCentroidND(void);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include "MantidAPI/IMDEventWorkspace.h"
#include "MantidKernel/ProgressBase.h"
#include "MantidKernel/System.h"
#include "MantidAPI/BoxController.h"
//#include "MantidAPI/BoxController.h"
#include "MantidMDEvents/BoxCtrlChangesList.h"
#include "MantidAPI/CoordTransform.h"
#include "MantidMDEvents/MDBoxBase.h"
#include "MantidMDEvents/MDLeanEvent.h"
Expand Down Expand Up @@ -103,7 +104,7 @@ namespace MDEvents


void addEvent(const MDE & event);
void addAndTraceEvent(const MDE & point,size_t index=0);
void addAndTraceEvent(const MDE & point,size_t index);


size_t addEvents(const std::vector<MDE> & events);
Expand Down Expand Up @@ -149,7 +150,8 @@ namespace MDEvents
MDBoxBase<MDE, nd> * data;

/// Box controller in use
Mantid::API::BoxController_sptr m_BoxController;
//Mantid::API::BoxController_sptr m_BoxController;
boost::shared_ptr<BoxCtrlChangesList<MDBoxToChange<MDE,nd> > > m_BoxController;

public:
/// Typedef for a shared pointer of this kind of event workspace
Expand Down
7 changes: 5 additions & 2 deletions Code/Mantid/Framework/MDEvents/src/MDBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,16 +526,19 @@ namespace MDEvents

// Yes, we added some data
this->m_dataAdded = true;
dataMutex.unlock();

// When we reach the split threshold exactly, track that the MDBox is too small
// We check on equality and not >= to only add a box once.
if (this->data.size() == this->m_BoxController->getSplitThreshold())
{
// this->m_BoxController->addBoxToSplit(splitBoxList(this,index));
auto BoxCtrl = dynamic_cast<BoxCtrlChangesList<MDBoxToChange<MDE,nd> >*>(m_BoxController.get());
BoxCtrl->addBoxToSplit(MDBoxToChange<MDE,nd>(this,index));

}


dataMutex.unlock();

}

//-----------------------------------------------------------------------------------------------
Expand Down

0 comments on commit b43baf4

Please sign in to comment.