Skip to content

Commit

Permalink
refs #6449 Enabled main part of MDBoxFlatTree (except file based)
Browse files Browse the repository at this point in the history
Temporary Reverted box controller to with control of boxes to change to vanilla box controller and disabling BC copy constructor, as it is too complex for file based workspaces.
  • Loading branch information
abuts authored and martyngigg committed Apr 10, 2013
1 parent ff87e39 commit 6390352
Show file tree
Hide file tree
Showing 16 changed files with 304 additions and 305 deletions.
9 changes: 5 additions & 4 deletions Code/Mantid/Framework/API/inc/MantidAPI/BoxController.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace API
virtual ~BoxController();

// create new box controller from the existing one
boost::shared_ptr<BoxController> clone()const;
virtual boost::shared_ptr<BoxController> clone()const;
/// Serialize
std::string toXMLString() const;

Expand Down Expand Up @@ -418,10 +418,11 @@ namespace API
for (size_t depth=1; depth<m_maxNumMDBoxes.size(); depth++)
m_maxNumMDBoxes[depth] = m_maxNumMDBoxes[depth-1] * double(m_numSplit);
}

private:
/// box controller is an ws-based singleton so it should not be possible to copy it
protected:
/// box controller is an ws-based singleton so it should not be possible to copy it, left for inheritance;
BoxController(const BoxController & other );

private:
/// Number of dimensions
size_t nd;

Expand Down
4 changes: 1 addition & 3 deletions Code/Mantid/Framework/API/src/BoxController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ namespace API
*/
BoxController_sptr BoxController::clone()const
{
BoxController * theClone = new BoxController(*this);
// reset the clone file IO controller to avoid dublicated file based operations for different box controllers
theClone->m_fileIO.reset();
return BoxController_sptr(theClone);
return BoxController_sptr(new BoxController(*this));
}
/** makes box controller file based by providing class, responsible for fileIO. The box controller become responsible for the FileIO pointer
*@param newFileIO -- instance of the box controller responsible for the IO;
Expand Down
6 changes: 5 additions & 1 deletion Code/Mantid/Framework/Kernel/inc/MantidKernel/ISaveable.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ namespace Kernel
//-----------------------------------------------------------------------------------------------
// Saveable functions interface, which controls the logic of working with objects on HDD
virtual bool isBusy()const=0;
virtual bool isDataChanged()const=0;
virtual bool wasSaved()const=0;
virtual bool isLoaded()const=0;
virtual void setLoaded(bool /*Yes*/)=0;
virtual void setBusy(bool /*On*/)=0;
virtual bool isDataChanged()const=0;
virtual void setDataChanged()=0;
virtual void clearDataChanged()=0;
//-----------------------------------------------------------------------------------------------

/// Save the data - to be overriden
Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/Saveable.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace Kernel
return m_Busy;
}
/// @ set the data busy to prevent from removing them from memory. The process which does that should clean the data when finished with them
void setBusy(bool On=true)
void setBusy(bool On)
{
m_Busy=On;
}
Expand All @@ -65,7 +65,7 @@ namespace Kernel
}
/** this method has to be called if the object has been discarded from memory and is not changed any more.
It expected to be called from clearDataFromMemory. */
void resetDataChanges()
void clearDataChanged()
{
m_dataChanged=false;
}
Expand All @@ -84,7 +84,7 @@ namespace Kernel
bool isLoaded()const
{ return m_isLoaded;}

void setLoaded(bool Yes=true)
void setLoaded(bool Yes)
{ m_isLoaded = Yes;}
protected:
//--------------
Expand Down
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/Kernel/test/DiskBufferISaveableTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ class ISaveableTester : public ISaveable
virtual bool isBusy()const{return _isBusy;}
virtual bool isDataChanged()const{return true;}
virtual bool wasSaved()const{return false;}
virtual void setLoaded(bool ){};
virtual bool isLoaded()const{return true;}
virtual void setBusy(bool On=true){_isBusy=On;}
virtual void setDataChanged(){}
virtual void clearDataChanged(){}
//-----------------------------------------------------------------------------------------------

/// Save the data - to be overriden
Expand Down
12 changes: 6 additions & 6 deletions Code/Mantid/Framework/Kernel/test/DiskBufferTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SaveableTesterWithFile : public Saveable
{
// the object knows its place on file
this->setFilePosition(pos,size,wasSaved);
this->setLoaded();
this->setLoaded(true);
}
// this is testing/special routine
void setSaved(bool On=true)
Expand Down Expand Up @@ -108,7 +108,7 @@ class SaveableTesterWithFile : public Saveable
{
m_memory+=this->getFileSize();
}
this->setLoaded();
this->setLoaded(true);
}
virtual void flushData() const {}

Expand Down Expand Up @@ -160,7 +160,7 @@ class DiskBufferTest : public CxxTest::TestSuite
DiskBuffer dbuf(4);
for (size_t i=0; i<9; i++)
{
data[i]->setBusy();
data[i]->setBusy(true);
dbuf.toWrite(data[i]);
}
// We ended up with too much in the buffer since nothing could be written.
Expand All @@ -187,7 +187,7 @@ class DiskBufferTest : public CxxTest::TestSuite
DiskBuffer dbuf(4);
for (size_t i=0; i<10; i++)
{
data[i]->setBusy();
data[i]->setBusy(true);
data[i]->setSaved(false);
dbuf.toWrite(data[i]);
}
Expand Down Expand Up @@ -692,7 +692,7 @@ class SaveableTesterWithSeek : public Saveable
uint64_t myFilePos = this->getFilePosition();
//std::cout << "Block " << getFileId() << " loading at " << myFilePos << std::endl;
SaveableTesterWithSeek::fakeSeekAndWrite( myFilePos );
this->setLoaded();
this->setLoaded(true);
}

virtual void save()const
Expand Down Expand Up @@ -746,7 +746,7 @@ class SaveableTesterWithSeek : public Saveable
{
m_memory+=this->getFileSize();
}
this->setLoaded();
this->setLoaded(true);
}


Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/Framework/MDEvents/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ set ( INC_FILES
inc/MantidMDEvents/AffineMatrixParameter.h
inc/MantidMDEvents/AffineMatrixParameterParser.h
inc/MantidMDEvents/BoxControllerSettingsAlgorithm.h
inc/MantidMDEvents/BoxCtrlChangesList.h
inc/MantidMDEvents/ConvToMDBase.h
inc/MantidMDEvents/ConvToMDEventsWS.h
inc/MantidMDEvents/ConvToMDHistoWS.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ namespace MDEvents
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
template<class T >
class BoxCtrlChangesList: public API::BoxController
{
//-----------------------------------------------------------------------------------
Expand All @@ -49,27 +48,17 @@ namespace MDEvents
* @param theBox -- Box to split
*/
public:
void addBoxToSplit(const T &theBox)
void addBoxToSplit(API::IMDNode *theBox)
{
Kernel::Mutex::ScopedLock _lock(m_boxesToSplitMutex);
m_boxesToSplit.push_back(theBox);
}

//-----------------------------------------------------------------------------------
/** 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
std::vector< API::IMDNode *> getBoxesToSplit()const
{
Kernel::Mutex::ScopedLock _lock(m_boxesToSplitMutex);
return m_boxesToSplit;
Expand All @@ -81,32 +70,27 @@ namespace MDEvents
Kernel::Mutex::ScopedLock _lock(m_boxesToSplitMutex);
m_boxesToSplit.clear();
}
/**constructor with number of dimensions */
BoxCtrlChangesList(size_t nd):BoxController(nd){};

/**Copy constructor from a box controller pointer */
BoxCtrlChangesList(const API::BoxController & theController):
BoxController(theController)
boost::shared_ptr<BoxController > clone()const
{
auto *bc = dynamic_cast<const BoxCtrlChangesList<T>* >(&theController);
if(bc)m_boxesToSplit.assign(bc->m_boxesToSplit.begin(),bc->m_boxesToSplit.end());
return boost::shared_ptr<BoxController >(new BoxCtrlChangesList(*this));
}

/**Copy constructor from a BoxCtrlChangesList, not default as mutex can not be copied */
private:
/**Copy constructor from a BoxCtrlChangesList*/
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;
mutable Mantid::Kernel::Mutex m_boxesToSplitMutex;

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

}
Expand Down
27 changes: 16 additions & 11 deletions Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDBoxFlatTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,39 @@ namespace MDEvents
/**@return XML description of the workspace box controller */
const std::string &getBCXMLdescr()const {return m_bcXMLDescr;}

//---------------------------------------------------------------------------------------------------------------------
/**@return internal linearized box structure of md workspace. Defined only when the class is properly initiated*/
std::vector<API::IMDNode *> &getBoxes(){return m_Boxes;}
/**@return number of boxes */
size_t getNBoxes()const{return m_BoxType.size();}
/**@return the vector of data which describes signals and errors over boxes */
std::vector<double> &getSigErrData(){return m_BoxSignalErrorsquared;}
/**@return the vector of data which describes signals and errors locations on file */
std::vector<uint64_t> &getEventIndex(){return m_BoxEventIndex;}

//---------------------------------------------------------------------------------------------------------------------
/// 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 */
/**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>
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
make data slatially located close to each otger to be as close as possible on the HDD */
make data physiclly located close to each otger to be as close as possible on the HDD */
void setBoxesFilePositions(bool makeFileBacked);

/**Save flat box structure into a file, defined by the file name*/
void saveBoxStructure(const std::string &fileName);
/**load box structure from the file, defined by file name */
void loadBoxStructure(const std::string &fileName);

private:
/**Save flat box structure into properly open nexus file*/
void saveBoxStructure(::NeXus::File *hFile);
void saveBoxStructure(const std::string &fileName);
/**Load flat box structure from a nexus file*/
void loadBoxStructure(::NeXus::File *hFile);

void loadBoxStructure(const std::string &fileName);

void initEventFileStorage(::NeXus::File *hFile,API::BoxController_sptr bc,bool MakeFileBacked,const std::string &EventType);
void initEventFileStorage(const std::string &fileName,API::BoxController_sptr bc,bool FileBacked,const std::string &EventType);

std::vector<double> &getSigErrData(){return m_BoxSignalErrorsquared;}
std::vector<uint64_t> &getEventIndex(){return m_BoxEventIndex;}
private:
//----------------------------------------------------------------------------------------------
int m_nDim;
// The name of the file the class will be working with
std::string m_FileName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ namespace MDEvents
static uint64_t openEventNexusData(::NeXus::File * file);

static void closeNexusData(::NeXus::File * file);
void initEventFileStorage(::NeXus::File *hFile,API::BoxController_sptr bc,bool MakeFileBacked,const std::string &EventType);
void initEventFileStorage(const std::string &fileName,API::BoxController_sptr bc,bool FileBacked,const std::string &EventType);



Expand Down

0 comments on commit 6390352

Please sign in to comment.