Skip to content

Commit

Permalink
refs #6449 Extracted node interface and started extracting MDSaveable
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts authored and martyngigg committed Apr 10, 2013
1 parent c832061 commit f03e65b
Show file tree
Hide file tree
Showing 11 changed files with 514 additions and 294 deletions.
35 changes: 29 additions & 6 deletions Code/Mantid/Framework/API/inc/MantidAPI/IMDNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ namespace API
class IMDNode : public Kernel::INode
{
public:
//---------------- ISAVABLE
virtual Kernel::ISaveable *const getISaveable(){return NULL;}
virtual Kernel::ISaveable *const getISaveable()const{return NULL;}
//---------------- ISAVABLE
/// @return the amount of memory that the object takes up in the MRU.
virtual uint64_t getTotalDataSize() const=0;

virtual size_t getDataMemorySize()const=0;

virtual void clearDataFromMemory()=0;
//-------------------------------------------------------------
Expand Down Expand Up @@ -71,9 +67,25 @@ class IMDNode : public Kernel::INode
// -------------------------------- Events-Related -------------------------------------------
/// Clear all contained data
virtual void clear() = 0;
/// Get total number of points
/// Get total number of points both in memory and on file if present;
virtual uint64_t getNPoints() const = 0;
/// get size of the data located in memory, it is equivalent to getNPoints above for memory based workspace but may be different for file based one ;
virtual size_t getDataInMemorySize()const = 0;
/// @return the amount of memory that the object takes up in the MRU.
virtual uint64_t getTotalDataSize() const=0;

/** The method to convert events in a box into a table of coodrinates/signal/errors casted into coord_t type
* Used to save events from plain binary file
* @returns coordTable -- vector of events parameters
* @return nColumns -- number of parameters for each event
*/
virtual void getEventsData(std::vector<coord_t> &coordTable,size_t &nColumns)const =0;
/** The method to convert the table of data into vector of events
* Used to load events from plain binary file
* @param coordTable -- vector of events parameters
* @param nColumns -- number of parameters for each event
*/
virtual void setEventsData(const std::vector<coord_t> &coordTable)=0;

/// Return a copy of contained events
//virtual std::vector<coor> & getEventsCopy() = 0;
Expand Down Expand Up @@ -129,6 +141,17 @@ class IMDNode : public Kernel::INode
virtual void getBoxes(std::vector<IMDNode *> & boxes, size_t maxDepth, bool leafOnly, Mantid::Geometry::MDImplicitFunction * function) = 0;


// -------------------------------- Geometry/vertexes-Related -------------------------------------------

virtual std::vector<Mantid::Kernel::VMD> getVertexes() const =0;

virtual coord_t * getVertexesArray(size_t & numVertices) const=0;

virtual coord_t * getVertexesArray(size_t & numVertices, const size_t outDimensions, const bool * maskDim) const=0;

virtual void transformDimensions(std::vector<double> & scaling, std::vector<double> & offset)=0;




};
Expand Down
6 changes: 4 additions & 2 deletions Code/Mantid/Framework/MDEvents/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set ( SRC_FILES
src/MDBoxIterator.cpp
src/MDBoxFlatTree.cpp
src/MDBoxToChange.cpp
src/MDBoxSaveable.cpp
src/MDEventFactory.cpp
src/MDEventWSWrapper.cpp
src/MDEventWorkspace.cpp
Expand All @@ -46,8 +47,8 @@ set ( SRC_FILES
src/ReflectometryTransformKiKf.cpp
src/ReflectometryTransformP.cpp
src/ReflectometryTransformQxQz.cpp
src/Integrate3DEvents.cpp
src/IntegrateEllipsoids.cpp
src/Integrate3DEvents.cpp
src/IntegrateEllipsoids.cpp
src/SaveIsawQvector.cpp
src/UnitsConversionHelper.cpp
src/UserFunctionMD.cpp
Expand Down Expand Up @@ -90,6 +91,7 @@ set ( INC_FILES
inc/MantidMDEvents/MDBoxIterator.h
inc/MantidMDEvents/MDBoxFlatTree.h
inc/MantidMDEvents/MDBoxToChange.h
inc/MantidMDEvents/MDBoxSaveable.h
inc/MantidMDEvents/MDDimensionStats.h
inc/MantidMDEvents/MDEvent.h
inc/MantidMDEvents/MDEventFactory.h
Expand Down
34 changes: 13 additions & 21 deletions Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ namespace MDEvents
{

#pragma pack(push, 4) //Ensure the structure is no larger than it needs to

// predefinition;
class MDBoxSaveable;
//===============================================================================================
/** Templated class for a multi-dimensional event "box".
*
Expand All @@ -35,6 +36,7 @@ namespace MDEvents
* @date Dec 7, 2010
*
* */

TMDE_CLASS
class DLLExport MDBox : public MDBoxBase<MDE, nd>
{
Expand All @@ -47,26 +49,12 @@ namespace MDEvents

MDBox(const MDBox<MDE,nd> & other,const Mantid::API::BoxController * otherBC=NULL);

virtual ~MDBox() {}
virtual ~MDBox();


// ----------------------------- ISaveable Methods ------------------------------------------------------

/// Save the data to the place, specified by the object
virtual void save()const;

/// Load the data which are not in memory yet and merge them with the data in memory;
virtual void load();


/// @return the amount of memory that the object takes up in the MRU.
virtual uint64_t getTotalDataSize() const
{ return getNPoints(); }
/** @return the size of the event vector. ! Note that this is NOT necessarily the same as the number of points
(because it might be cached to disk) or the size on disk (because you might have called AddEvents) */
virtual size_t getDataMemorySize()const
{ return data.size();}
/** teturns true if it is box*/
/** returns true if it is box (avoid rtti?) */
virtual bool isBox()const{return true;}
//-----------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -126,6 +114,9 @@ namespace MDEvents

std::vector< MDE > * getEventsCopy();

virtual void getEventsData(std::vector<coord_t> &coordTable,size_t &nColumns)const ;
virtual void setEventsData(const std::vector<coord_t> &coordTable);

virtual void addEvent(const std::vector<coord_t> &point, signal_t Signal, signal_t errorSq,uint16_t runIndex,uint32_t detectorId);
virtual void addAndTraceEvent(const std::vector<coord_t> &point, signal_t Signal, signal_t errorSq,uint16_t runIndex,uint32_t detectorId,size_t index);
virtual void addEventUnsafe(const std::vector<coord_t> &point, signal_t Signal, signal_t errorSq,uint16_t runIndex,uint32_t detectorId);
Expand Down Expand Up @@ -175,14 +166,15 @@ namespace MDEvents
void unmask();

protected:


// the pointer to the class, responsible for saving/restoring this class to the hdd
mutable MDBoxSaveable * m_Saveable;
/// Mutex for modifying the event list
Mantid::Kernel::Mutex dataMutex;

/** Vector of MDLeanEvent's, in no particular order.
* */
mutable std::vector< MDE > data;

/// Mutex for modifying the event list
Mantid::Kernel::Mutex dataMutex;

/// Flag indicating that masking has been applied.
bool m_bIsMasked;
Expand Down
83 changes: 26 additions & 57 deletions Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDBoxBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,70 +57,36 @@ namespace MDEvents
virtual ~MDBoxBase() {}


// ----------------------------- ISaveable Methods ------------------------------------------------------

/// Save the data - to be overriden
virtual void save() const
{
std::cerr << "ID " << getId() << std::endl;
throw std::runtime_error("MDBoxBase::save() called and should have been overridden.");
}

/// Flush the data to disk. Allows NXS api to actually write out the file.
//TODO: DO WE WANT IT ?????, I suspect not as muliple writes can be combined in the NXS buffer
virtual void flushData() const
{
::NeXus::File * file = this->m_BoxController->getFile();
if (file)
{
API::BoxController::closeNexusData(file);
API::BoxController::openEventNexusData(file);
}
}

/// Load the data - to be overriden
virtual void load()
{ }

// -------------------------------- Parents/Children-Related -------------------------------------------
/// Return a pointer to the parent box
void setParent(MDBoxBase<MDE,nd> * parent)
void setParent(IMDNode * parent)
{ m_parent = parent; }

/// Return a pointer to the parent box
MDBoxBase<MDE,nd> * getParent()
IMDNode * getParent()
{ return m_parent; }

/// Return a pointer to the parent box (const)
const MDBoxBase<MDE,nd> * getParent() const
const IMDNode * getParent() const
{ return m_parent; }

/// Fill a vector with all the boxes up to a certain depth
//virtual void getBoxes(std::vector<MDBoxBase<MDE,nd> *> & boxes, size_t maxDepth, bool leafOnly) = 0;

/// Fill a vector with all the boxes up to a certain depth
//virtual void getBoxes(std::vector<MDBoxBase<MDE,nd> *> & boxes, size_t maxDepth, bool leafOnly, Mantid::Geometry::MDImplicitFunction * function) = 0;


/// Returns the lowest-level box at the given coordinates
virtual const MDBoxBase<MDE,nd> * getBoxAtCoord(const coord_t * /*coords*/) const
virtual const IMDNode * getBoxAtCoord(const coord_t * /*coords*/) const
{ return this; }



// -------------------------------- Geometry/vertexes-Related -------------------------------------------

std::vector<Mantid::Kernel::VMD> getVertexes() const;

coord_t * getVertexesArray(size_t & numVertices) const;

coord_t * getVertexesArray(size_t & numVertices, const size_t outDimensions, const bool * maskDim) const;

virtual void transformDimensions(std::vector<double> & scaling, std::vector<double> & offset);


// -------------------------------- Events-Related -------------------------------------------

/** The method to convert events in a box into a table of coodrinates/signal/errors casted into coord_t type
* Used to save events from plain binary file
* @returns coordTable -- vector of events parameters
* @return nColumns -- number of parameters for each event
*/
virtual void getEventsData(std::vector<coord_t> &/*coordTable*/,size_t &/*nColumns*/)const{};
/** The method to convert the table of data into vector of events
* Used to load events from plain binary file
* @param coordTable -- vector of events parameters
* @param nColumns -- number of parameters for each event
*/
virtual void setEventsData(const std::vector<coord_t> &/*coordTable*/){};
/// Return a copy of contained events
virtual std::vector< MDE > * getEventsCopy() = 0;
/// Add a single event
Expand Down Expand Up @@ -166,6 +132,16 @@ namespace MDEvents
{ m_BoxController = controller; }


// -------------------------------- Geometry/vertexes-Related -------------------------------------------

std::vector<Mantid::Kernel::VMD> getVertexes() const;

coord_t * getVertexesArray(size_t & numVertices) const;

coord_t * getVertexesArray(size_t & numVertices, const size_t outDimensions, const bool * maskDim) const;

virtual void transformDimensions(std::vector<double> & scaling, std::vector<double> & offset);

//-----------------------------------------------------------------------------------------------
/** Set the extents of this box.
* @param dim :: index of dimension
Expand Down Expand Up @@ -396,13 +372,6 @@ namespace MDEvents
/// Pointer to the parent of this box. NULL if no parent.
Mantid::API::IMDNode * m_parent;

#ifdef MDBOX_TRACK_CENTROID
/** The centroid (weighted center of mass) of the events in this MDBox.
* Set when refreshCentroid() is called.
*/
coord_t m_centroid[nd];
#endif

public:
/// Convenience typedef for a shared pointer to a this type of class
typedef boost::shared_ptr< MDBoxBase<MDE, nd> > sptr;
Expand Down
64 changes: 64 additions & 0 deletions Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDBoxSaveable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#ifndef MANTID_MDEVENTS_MDBOX_SAVEABLE_H
#define MANTID_MDEVENTS_MDBOX_SAVEABLE_H

#include "MantidKernel/Saveable.h"
#include "MantidAPI/IMDNode.h"

namespace Mantid
{
namespace MDEvents
{

//===============================================================================================
/** The class responsible for implementing methods which automatically save/load MDBox in conjuction with
DiskBuffer
@date March 15, 2013
Copyright &copy; 2008-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://github.com/mantidproject/mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport MDBoxSaveable : public Kernel::Saveable
{
public:
MDBoxSaveable(API::IMDNode *const, size_t ID);

/// Save the data to the place, specified by the object
virtual void save();

/// Load the data which are not in memory yet and merge them with the data in memory;
virtual void load();


/// @return the amount of memory that the object takes up in the MRU.
virtual uint64_t getTotalDataSize() const
{ return m_MDNode->getTotalDataSize(); }
/** @return the size of the event vector. ! Note that this is NOT necessarily the same as the number of points
(because it might be cached to disk) or the size on disk (because you might have called AddEvents) */
virtual size_t getDataMemorySize()const
{ return m_MDNode->getDataInMemorySize();}
private:
API::IMDNode *m_MDNode;
};

}
}

#endif

0 comments on commit f03e65b

Please sign in to comment.