Skip to content

Commit

Permalink
refs #6449 enabled MDGridBox test (main part)
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Apr 5, 2013
1 parent d7f99be commit 500f32a
Show file tree
Hide file tree
Showing 14 changed files with 573 additions and 501 deletions.
1 change: 0 additions & 1 deletion Code/Mantid/Framework/API/inc/MantidAPI/IMDNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class IMDNode
/// Add a single event, with no mutex locking
virtual void addEventUnsafe(const signal_t Signal,const signal_t errorSq,const std::vector<coord_t> &point, uint16_t runIndex,uint32_t detectorId) = 0;
/// Add several events, within a given range
//virtual size_t addEventsPart(const std::vector<coord_t> &coords,const signal_t *Signal,const signal_t *errorSq,const uint16_t *runIndex,const uint32_t *detectorId, const size_t start_at, const size_t stop_at)=0;
virtual size_t addEvents(const std::vector<signal_t> &sigErrSq,const std::vector<coord_t> &Coord,const std::vector<uint16_t> &runIndex,const std::vector<uint32_t> &detectorId)=0;


Expand Down
4 changes: 3 additions & 1 deletion Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ namespace MDEvents

// add range of events
virtual size_t addEvents(const std::vector<MDE> & events);
//virtual size_t addEventsUnsafe(const std::vector<MDE> & events);
// unhide MDBoxBase methods
virtual size_t addEventsUnsafe(const std::vector<MDE> & events)
{return MDBoxBase::addEventsUnsafe( events);}

/*---------------> EVENTS from event data <-------------------------------------------------------------*/
virtual void addEvent(const signal_t Signal,const signal_t errorSq,const std::vector<coord_t> &point, uint16_t runIndex,uint32_t detectorId);
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDBoxBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ namespace MDEvents

// The id which specify location of this box in a linear chain of ordered boxes (e.g. on file)
size_t m_fileID;
private:
MDBoxBase(const MDBoxBase<MDE,nd> & box);
public:
/// Convenience typedef for a shared pointer to a this type of class
typedef boost::shared_ptr< MDBoxBase<MDE, nd> > sptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace MDEvents

size_t addEvents(const std::vector<MDE> & events);

void addManyEvents(const std::vector<MDE> & events, Mantid::Kernel::ProgressBase * prog);
//void addManyEvents(const std::vector<MDE> & events, Mantid::Kernel::ProgressBase * prog);

std::vector<Mantid::Geometry::MDDimensionExtents<coord_t> > getMinimumExtents(size_t depth=2);

Expand Down
117 changes: 60 additions & 57 deletions Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDGridBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ namespace MDEvents
void addEvent(const MDE & event);
void addEventUnsafe(const MDE & event);
void addAndTraceEvent(const MDE & point,size_t index);
// unhide MDBoxBase methods
virtual size_t addEvents(const std::vector<MDE> & events)
{ return MDBoxBase::addEvents(events); }
virtual size_t addEventsUnsafe(const std::vector<MDE> & events)
{return MDBoxBase::addEventsUnsafe( events);}


/*---------------> EVENTS from event data <-------------------------------------------------------------*/
virtual void addEvent(const signal_t Signal,const signal_t errorSq,const std::vector<coord_t> &point, uint16_t runIndex,uint32_t detectorId);
Expand Down Expand Up @@ -124,24 +130,21 @@ namespace MDEvents

// Set the box controller overrriden.
//virtual void setBoxController(Mantid::API::BoxController *controller);

// ======================= Testing/Debugging Methods =================
/** For testing: get (a reference to) the vector of boxes */
//std::vector<API::IMDNode *> & getBoxes()
//{ return m_Children; }



virtual bool getIsMasked() const;

///Setter for masking the box
virtual void mask();

///Setter for unmasking the box
virtual void unmask();
// ======================= Testing/Debugging Methods =================
/** For testing: get (a reference to) the vector of boxes */
std::vector<MDBoxBase<MDE,nd> *> & getBoxes()
{ return m_Children; }


//-------------------------------------------------------------------------
/** The function used to satisfy IMDNode interface but the physical meaning is unclear */
void calculateCentroid(coord_t * /*centroid*/= NULL) const
void calculateCentroid(coord_t * /*centroid*/) const
{
throw(std::runtime_error("This function should not be called on MDGridBox (as its meaning for MDbox is dubious too)"));
}
Expand Down Expand Up @@ -183,57 +186,57 @@ namespace MDEvents

size_t getLinearIndex(size_t * indices) const;



size_t computeSizesFromSplit();
void fillBoxShell(const size_t tot,const coord_t inverseVolume);

MDGridBox(const MDGridBox<MDE, nd> & box);
public:

//===============================================================================================
//===============================================================================================
/** Task for adding events to a MDGridBox. */
class AddEventsTask : public Mantid::Kernel::Task
{
public:
/// Pointer to MDGridBox.
MDBoxBase<MDE, nd> * box;
/// Reference to the MD events that will be added
const std::vector<MDE> & events;
/// Where to start in vector
size_t start_at;
/// Where to stop in vector
size_t stop_at;
/// Progress report
Mantid::Kernel::ProgressBase * prog;

/** Ctor
*
* @param box :: Pointer to MDGridBox
* @param events :: Reference to the MD events that will be added
* @param start_at :: Where to start in vector
* @param stop_at :: Where to stop in vector
* @param prog :: ProgressReporting
* @return
*/
AddEventsTask(MDBoxBase<MDE, nd> * box, const std::vector<MDE> & events,
const size_t start_at, const size_t stop_at, Mantid::Kernel::ProgressBase * prog)
: Mantid::Kernel::Task(),
box(box), events(events), start_at(start_at), stop_at(stop_at), prog(prog)
{
}

/// Add the events in the MDGridBox.
void run()
{
box->addEvents(events);
if (prog)
{
std::ostringstream out;
out << "Adding events " << start_at;
prog->report(out.str());
}
}
};
////===============================================================================================
////===============================================================================================
///** Task for adding events to a MDGridBox. */
//class AddEventsTask : public Mantid::Kernel::Task
//{
//public:
// /// Pointer to MDGridBox.
// MDBoxBase<MDE, nd> * box;
// /// Reference to the MD events that will be added
// const std::vector<MDE> & events;
// /// Where to start in vector
// size_t start_at;
// /// Where to stop in vector
// size_t stop_at;
// /// Progress report
// Mantid::Kernel::ProgressBase * prog;

// /** Ctor
// *
// * @param box :: Pointer to MDGridBox
// * @param events :: Reference to the MD events that will be added
// * @param start_at :: Where to start in vector
// * @param stop_at :: Where to stop in vector
// * @param prog :: ProgressReporting
// * @return
// */
// AddEventsTask(MDBoxBase<MDE, nd> * box, const std::vector<MDE> & events,
// const size_t start_at, const size_t stop_at, Mantid::Kernel::ProgressBase * prog)
// : Mantid::Kernel::Task(),
// box(box), events(events), start_at(start_at), stop_at(stop_at), prog(prog)
// {
// }

// /// Add the events in the MDGridBox.
// void run()
// {
// box->addEvents(events);
// if (prog)
// {
// std::ostringstream out;
// out << "Adding events " << start_at;
// prog->report(out.str());
// }
// }
//};



Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/MDEvents/src/MDBoxBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ namespace MDEvents
size_t numBad = 0;
// --- Go event by event and add them ----
typename std::vector<MDE>::const_iterator it = events.begin();
typename std::vector<MDE>::const_iterator it_end = events.begin();
typename std::vector<MDE>::const_iterator it_end = events.end();
for (; it != it_end; ++it)
{
//Check out-of-bounds-ness
Expand Down
160 changes: 80 additions & 80 deletions Code/Mantid/Framework/MDEvents/src/MDEventWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,86 +610,86 @@ namespace MDEvents
//TODO ThreadPool
}

//-----------------------------------------------------------------------------------------------
/** Add a large number of events to this MDEventWorkspace.
* This will use a ThreadPool/OpenMP to allocate events in parallel.
*
* @param events :: vector of events to be copied.
* @param prog :: optional Progress object to report progress back to GUI/algorithms.
* @return the number of events that were rejected (because of being out of bounds)
*/
TMDE(
void MDEventWorkspace)::addManyEvents(const std::vector<MDE> & events, Mantid::Kernel::ProgressBase * prog)
{
// Always split the MDBox into a grid box
this->splitBox();
MDGridBox<MDE,nd> * gridBox = dynamic_cast<MDGridBox<MDE,nd> *>(data);

// Get some parameters that should optimize task allocation.
size_t eventsPerTask, numTasksPerBlock;
this->m_BoxController->getAddingEventsParameters(eventsPerTask, numTasksPerBlock);

// Set up progress report, if any
if (prog)
{
size_t numTasks = events.size()/eventsPerTask;
prog->setNumSteps( int( numTasks + numTasks/numTasksPerBlock ));
}

// Where we are in the list of events
size_t event_index = 0;
while (event_index < events.size())
{
//Since the costs are not known ahead of time, use a simple FIFO buffer.
ThreadScheduler * ts = new ThreadSchedulerFIFO();
// Create the threadpool
ThreadPool tp(ts);

// Do 'numTasksPerBlock' tasks with 'eventsPerTask' events in each one.
for (size_t i = 0; i < numTasksPerBlock; i++)
{
// Calculate where to start and stop in the events vector
bool breakout = false;
size_t start_at = event_index;
event_index += eventsPerTask;
size_t stop_at = event_index;
if (stop_at >= events.size())
{
stop_at = events.size();
breakout = true;
}

// Create a task and push it into the scheduler
//std::cout << "Making a AddEventsTask " << start_at << " to " << stop_at << std::endl;
typename MDGridBox<MDE,nd>::AddEventsTask * task;
task = new typename MDGridBox<MDE,nd>::AddEventsTask(gridBox, events, start_at, stop_at, prog) ;
ts->push( task );

if (breakout) break;
}

// Finish all threads.
// std::cout << "Starting block ending at index " << event_index << " of " << events.size() << std::endl;
Timer tim;
tp.joinAll();
// std::cout << "... block took " << tim.elapsed() << " secs.\n";

//Create a threadpool for splitting.
ThreadScheduler * ts_splitter = new ThreadSchedulerFIFO();
ThreadPool tp_splitter(ts_splitter);

//Now, shake out all the sub boxes and split those if needed
// std::cout << "\nStarting splitAllIfNeeded().\n";
if (prog) prog->report("Splitting MDBox'es.");

gridBox->splitAllIfNeeded(ts_splitter);
tp_splitter.joinAll();
// std::cout << "\n... splitAllIfNeeded() took " << tim.elapsed() << " secs.\n";
}

// Refresh the counts, now that we are all done.
this->refreshCache();
}
// //-----------------------------------------------------------------------------------------------
// /** Add a large number of events to this MDEventWorkspace.
// * This will use a ThreadPool/OpenMP to allocate events in parallel.
// *
// * @param events :: vector of events to be copied.
// * @param prog :: optional Progress object to report progress back to GUI/algorithms.
// * @return the number of events that were rejected (because of being out of bounds)
// */
// TMDE(
// void MDEventWorkspace)::addManyEvents(const std::vector<MDE> & events, Mantid::Kernel::ProgressBase * prog)
// {
// // Always split the MDBox into a grid box
// this->splitBox();
// MDGridBox<MDE,nd> * gridBox = dynamic_cast<MDGridBox<MDE,nd> *>(data);
//
// // Get some parameters that should optimize task allocation.
// size_t eventsPerTask, numTasksPerBlock;
// this->m_BoxController->getAddingEventsParameters(eventsPerTask, numTasksPerBlock);
//
// // Set up progress report, if any
// if (prog)
// {
// size_t numTasks = events.size()/eventsPerTask;
// prog->setNumSteps( int( numTasks + numTasks/numTasksPerBlock ));
// }
//
// // Where we are in the list of events
// size_t event_index = 0;
// while (event_index < events.size())
// {
// //Since the costs are not known ahead of time, use a simple FIFO buffer.
// ThreadScheduler * ts = new ThreadSchedulerFIFO();
// // Create the threadpool
// ThreadPool tp(ts);
//
// // Do 'numTasksPerBlock' tasks with 'eventsPerTask' events in each one.
// for (size_t i = 0; i < numTasksPerBlock; i++)
// {
// // Calculate where to start and stop in the events vector
// bool breakout = false;
// size_t start_at = event_index;
// event_index += eventsPerTask;
// size_t stop_at = event_index;
// if (stop_at >= events.size())
// {
// stop_at = events.size();
// breakout = true;
// }
//
// // Create a task and push it into the scheduler
// //std::cout << "Making a AddEventsTask " << start_at << " to " << stop_at << std::endl;
// typename MDGridBox<MDE,nd>::AddEventsTask * task;
// task = new typename MDGridBox<MDE,nd>::AddEventsTask(gridBox, events, start_at, stop_at, prog) ;
// ts->push( task );
//
// if (breakout) break;
// }
//
// // Finish all threads.
//// std::cout << "Starting block ending at index " << event_index << " of " << events.size() << std::endl;
// Timer tim;
// tp.joinAll();
//// std::cout << "... block took " << tim.elapsed() << " secs.\n";
//
// //Create a threadpool for splitting.
// ThreadScheduler * ts_splitter = new ThreadSchedulerFIFO();
// ThreadPool tp_splitter(ts_splitter);
//
// //Now, shake out all the sub boxes and split those if needed
//// std::cout << "\nStarting splitAllIfNeeded().\n";
// if (prog) prog->report("Splitting MDBox'es.");
//
// gridBox->splitAllIfNeeded(ts_splitter);
// tp_splitter.joinAll();
//// std::cout << "\n... splitAllIfNeeded() took " << tim.elapsed() << " secs.\n";
// }
//
// // Refresh the counts, now that we are all done.
// this->refreshCache();
// }



Expand Down
7 changes: 3 additions & 4 deletions Code/Mantid/Framework/MDEvents/src/MDGridBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,17 @@ namespace MDEvents
* @param splitRecursively :: flag to split boxes recursively
*/
TMDE(MDGridBox)::MDGridBox(MDBox<MDE, nd> * box,bool splitRecursively)
: MDBoxBase<MDE, nd>(*box),
: MDBoxBase<MDE, nd>(*box,box->getBoxController()),
nPoints(0)
{
BoxController *bc = box->getBoxController();
if (!bc)
if (!this->m_BoxController)
throw std::runtime_error("MDGridBox::ctor(): constructing from box:: No BoxController specified in box.");

// std::cout << "Splitting MDBox ID " << box->getId() << " with " << box->getNPoints() << " events into MDGridBox" << std::endl;

// How many is it split?
for (size_t d=0; d<nd; d++)
split[d] = bc->getSplitInto(d);
split[d] = this->m_BoxController->getSplitInto(d);

// Compute sizes etc.
size_t tot = computeSizesFromSplit();
Expand Down
4 changes: 4 additions & 0 deletions Code/Mantid/Framework/MDEvents/test/MDBoxBaseTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class MDBoxBaseTester : public MDBoxBase<MDE,nd>
//this->setId(filePos);
// this->setFilePosition(filePos,10,false);
}
MDBoxBaseTester(const MDBoxBaseTester &source):
MDBoxBase(source,source.getBoxController())
{
}

MDBoxBaseTester(const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t> > & extentsVector)
: MDBoxBase<MDE,nd>(NULL,0,0,extentsVector)
Expand Down

0 comments on commit 500f32a

Please sign in to comment.