Skip to content

Commit

Permalink
refs #5244 further modifications to allow ConvToMD running multithread
Browse files Browse the repository at this point in the history
refs #5537 Renamed couple of classes responsible for event conversion
  • Loading branch information
abuts committed Jun 28, 2012
1 parent 46bf1fb commit 172f07b
Show file tree
Hide file tree
Showing 21 changed files with 309 additions and 215 deletions.
16 changes: 13 additions & 3 deletions Code/Mantid/Framework/API/inc/MantidAPI/BoxController.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,25 @@ namespace API
* would be a slow-down, but keeping the boxes split at an earlier stage
* should help scalability for later adding, so there is a balance to get.
*
* @param eventsAdded :: How many events were added since the last split?
* @param numMDBoxes :: How many un-split MDBoxes are there (total) in the workspace
* @param nEventsInOutput :: How many events are currently in workspace in memory;
* @param eventsAdded :: How many events were added since the last split?
* @param numMDBoxes :: How many un-split MDBoxes are there (total) in the workspace
* @return true if the boxes should get split.
*/
bool shouldSplitBoxes(size_t eventsAdded, size_t numMDBoxes) const
bool shouldSplitBoxes(size_t nEventsInOutput,size_t eventsAdded, size_t numMDBoxes) const
{
// Avoid divide by zero
if(numMDBoxes == 0)
return false;
// Performance depends pretty strongly on WHEN you split the boxes.
// This is an empirically-determined way to optimize the splitting calls.
// Split when adding 1/16^th as many events as are already in the output,
// (because when the workspace gets very large you should split less often)
// But no more often than every 10 million events.
size_t comparisonPoint = nEventsInOutput/16;
if (comparisonPoint < 10000000)
comparisonPoint = 10000000;
if (eventsAdded > (comparisonPoint))return true;

// Return true if the average # of events per box is big enough to split.
return ((eventsAdded / numMDBoxes) > m_SplitThreshold);
Expand Down
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/Kernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,13 @@ set ( INC_FILES
inc/MantidKernel/Strings.h
inc/MantidKernel/System.h
inc/MantidKernel/TestChannel.h
inc/MantidKernel/ThreadPool.h
inc/MantidKernel/ThreadPoolRunnable.h
inc/MantidKernel/ThreadSafeLogStream.h
inc/MantidKernel/ThreadScheduler.h
inc/MantidKernel/ThreadSchedulerMutexes.h
inc/MantidKernel/Task.h
inc/MantidKernel/FunctionTask.h
inc/MantidKernel/TimeSeriesProperty.h
inc/MantidKernel/TimeSplitter.h
inc/MantidKernel/Timer.h
Expand Down
5 changes: 4 additions & 1 deletion Code/Mantid/Framework/Kernel/inc/MantidKernel/FunctionTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class DLLExport FunctionTask : public Task

/// Typedef for a function with no arguments and no return
typedef void(*voidFunction)();
/// Typedef for a function with no arguments and size_t return
typedef size_t(*sizetFunction)();

//---------------------------------------------------------------------------------------------
/** Constructor for a simple void function.
Expand All @@ -40,7 +42,7 @@ class DLLExport FunctionTask : public Task
* @param cost :: computational cost
*/
FunctionTask(voidFunction func, double cost=1.0)
: Task(cost), m_voidFunc(func)
: Task(cost), m_voidFunc(func),m_sizetFunc(NULL)
{
}

Expand Down Expand Up @@ -74,6 +76,7 @@ class DLLExport FunctionTask : public Task

protected:
boost::function<void ()> m_voidFunc;
boost::function<size_t ()> m_sizetFunc;
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,7 @@ namespace MDAlgorithms
/// logger -> to provide logging, for MD dataset file operations
static Mantid::Kernel::Logger& convert_log;
/// pointer to the class, which does the particular conversion
boost::shared_ptr<MDEvents::ConvToMDEventsBase> pConvertor;

/// the class which knows about existing subalgorithms and generates alforithm ID as function of input parameters of this algorithm.
///ConvertToMD::ConvertToMDEventsParams ParamParser;
/// The class which keeps map of all existing subalgorithms converting to MDEventWorkspace.
/// It returns the pointer to the subalgorithm receiving alogID from ParamParser. Shoud be re-implemented through a singleton if used not only here.
//ConvertToMDEventsSubalgFactory subAlgFactory;
boost::shared_ptr<MDEvents::ConvToMDEventsBase> pConvertor;
//------------------------------------------------------------------------------------------------------------------------------------------
protected: //for testing
static Mantid::Kernel::Logger & getLogger();
Expand Down
3 changes: 0 additions & 3 deletions Code/Mantid/Framework/MDAlgorithms/src/ConvertToMDEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,6 @@ ConvertToMDEvents::init()
/* Execute the algorithm. */
void ConvertToMDEvents::exec()
{
// initiate all availible subalgorithms for further usage (it will do it only once, first time the algorithm is executed);
// this->subAlgFactory.init(ParamParser);

// initiate class which would deal with any dimension workspaces, handling
if(!pWSWrapper.get()){
pWSWrapper = boost::shared_ptr<MDEvents::MDEventWSWrapper>(new MDEvents::MDEventWSWrapper());
Expand Down
8 changes: 4 additions & 4 deletions Code/Mantid/Framework/MDEvents/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ set ( SRC_FILES
src/BoxControllerSettingsAlgorithm.cpp
src/CentroidPeaksMD.cpp
src/CloneMDWorkspace.cpp
src/ConvToMDEventsBase.cpp
src/ConvToMDEventsEvents.cpp
src/ConvToMDBase.cpp
src/ConvToMDEventsWS.cpp
src/ConvToMDEventsHisto.cpp
src/ConvToMDEventsSelector.cpp
src/ConvToMDPreprocDet.cpp
Expand Down Expand Up @@ -78,8 +78,8 @@ set ( INC_FILES
inc/MantidMDEvents/BoxControllerSettingsAlgorithm.h
inc/MantidMDEvents/CentroidPeaksMD.h
inc/MantidMDEvents/CloneMDWorkspace.h
inc/MantidMDEvents/ConvToMDEventsBase.h
inc/MantidMDEvents/ConvToMDEventsEvents.h
inc/MantidMDEvents/ConvToMDBase.h
inc/MantidMDEvents/ConvToMDEventsWS.h
inc/MantidMDEvents/ConvToMDEventsHisto.h
inc/MantidMDEvents/ConvToMDEventsSelector.h
inc/MantidMDEvents/ConvToMDPreprocDet.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ namespace MDEvents
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/

class DLLExport ConvToMDEventsBase
class DLLExport ConvToMDBase
{
public:
// constructor;
ConvToMDEventsBase();
ConvToMDBase();

///method which initates all main class variables
virtual size_t initialize(const MDWSDescription &WSD, boost::shared_ptr<MDEventWSWrapper> inWSWrapper);
/// method which starts the conversion procedure
virtual void runConversion(API::Progress *)=0;
/// virtual destructor
virtual ~ConvToMDEventsBase(){};
virtual ~ConvToMDBase(){};


protected:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define H_CONV_TOMDEVENTS_SELECTOR


#include "MantidMDEvents/ConvToMDEventsEvents.h"
#include "MantidMDEvents/ConvToMDEventsWS.h"
#include "MantidMDEvents/ConvToMDEventsHisto.h"

namespace Mantid
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#ifndef H_CONVERT_TO_MD_EVENTWS
#define H_CONVERT_TO_MD_EVENTWS
//
#include "MantidKernel/System.h"
#include "MantidKernel/Exception.h"
#include "MantidAPI/Algorithm.h"
#include <vector>

#include "MantidDataObjects/EventWorkspace.h"

#include "MantidAPI/NumericAxis.h"
#include "MantidAPI/Progress.h"
#include "MantidKernel/PhysicalConstants.h"

#include "MantidMDEvents/MDEventWSWrapper.h"
#include "MantidMDEvents/MDEvent.h"

#include "MantidMDEvents/ConvToMDPreprocDet.h"
#include "MantidMDEvents/ConvToMDBase.h"
// coordinate transformation
#include "MantidMDEvents/MDTransfFactory.h"

namespace Mantid
{
namespace MDEvents
{
/** The class specializes ConvToMDEventsBase for the case when the conversion occurs from Events WS to the MD events WS
*
* @date 11-10-2011
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>
*/

// Class to process event workspace by direct conversion:

class ConvToMDEventsWS: public ConvToMDBase
{
public:
size_t initialize(const MDEvents::MDWSDescription &WSD, boost::shared_ptr<MDEvents::MDEventWSWrapper> inWSWrapper);
void runConversion(API::Progress *pProg);

private:
// function runs the conversion on
virtual size_t conversionChunk(size_t workspaceIndex);
// the pointer to the source event workspace as event ws does not work through the public Matrix WS interface
DataObjects::EventWorkspace_const_sptr pEventWS;

/**function converts particular type of events into MD space and add these events to the workspace itself */
template <class T> size_t convertEventList(size_t workspaceIndex);

};

} // endNamespace MDEvents
} // endNamespace Mantid

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,7 @@ class DLLExport ConvToMDPreprocDet{
// function allocates the class detectors memory
void allocDetMemory(size_t nSpectra);

//void setEi(const API::MatrixWorkspace_sptr inputWS);


// parameter which describes the conversion mode, used to convert uints using TOF and detector's positions
// int emode;
// parameter wjocj describes the energy used to convert uints using TOF and detector's positions
// double efix;
// source-sample distance used to convert uints using TOF and detector's positions
// source-sample distance used to convert uints using TOF and detector's positions
double L1;
// minimal position for the detectors
Kernel::V3D minDetPosition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class DLLExport UnitsConversionHelper
void initialize(const MDWSDescription &TWSD,const std::string &units_to);
void updateConversion(size_t i);
double convertUnits(double val);

// copy constructor
UnitsConversionHelper(const UnitsConversionHelper &another);
protected: // for testing
/// establish and initialize proper units conversion from input to output units;
ConvertToMD::ConvertUnits analyzeUnitsConversion(const std::string &UnitsFrom,const std::string &UnitsTo);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "MantidMDEvents/ConvToMDEventsBase.h"
#include "MantidMDEvents/ConvToMDBase.h"


namespace Mantid
Expand All @@ -7,18 +7,16 @@ namespace MDEvents
{

// logger for conversion
Kernel::Logger& ConvToMDEventsBase::convert_log =Kernel::Logger::get("MD-Algorithms");
Kernel::Logger& ConvToMDBase::convert_log =Kernel::Logger::get("MD-Algorithms");


/** method which initates all main class variables
* @param pWS2D -- shared pointer to input matirx workspace to process
* @param detLoc -- class with information about datecotrs, partially transformed for convenient Q calculations
* @param WSD -- class describing the target workspace.
* the algorithm uses target workspace limints, transformation matix from source to the target workspace and the parameters, needed for
* unit conversion (if any)
* @param pWSWrapper -- shared pointer to target MD Event workspace to add converted events to.
*/
size_t ConvToMDEventsBase::initialize(const MDEvents::MDWSDescription &WSD, boost::shared_ptr<MDEvents::MDEventWSWrapper> inWSWrapper)
size_t ConvToMDBase::initialize(const MDEvents::MDWSDescription &WSD, boost::shared_ptr<MDEvents::MDEventWSWrapper> inWSWrapper)
{
pDetLoc = WSD.getDetectors();
inWS2D = WSD.getInWS();
Expand Down Expand Up @@ -49,7 +47,8 @@ size_t ConvToMDEventsBase::initialize(const MDEvents::MDWSDescription &WSD, boo
return n_spectra;
};

ConvToMDEventsBase::ConvToMDEventsBase()
/** empty default constructor */
ConvToMDBase::ConvToMDBase()
{}


Expand Down
93 changes: 0 additions & 93 deletions Code/Mantid/Framework/MDEvents/src/ConvToMDEventsEvents.cpp

This file was deleted.

0 comments on commit 172f07b

Please sign in to comment.