Skip to content

Commit

Permalink
Refs #5021: attempt to split MDBoxes on addEvent()
Browse files Browse the repository at this point in the history
segfaults sometimes...
  • Loading branch information
Janik Zikovsky committed Apr 12, 2012
1 parent 10f6812 commit c8a09ef
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ namespace MDEvents
size_t getEventVectorSize() const
{ return data.size(); }

/// @return the mutex for modifying the data vector
Mantid::Kernel::Mutex & getDataMutex()
{ return dataMutex; }

/// @return true if events were added to the box (using addEvent()) while the rest of the event list is cached to disk
bool getHasAddedEventsOnCached() const
{ return (!m_inMemory && (data.size() != 0)); }
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDGridBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ namespace MDEvents
/// Cached number of points contained (including all sub-boxes)
size_t nPoints;

/// Mutex for counting points and total signal
Mantid::Kernel::Mutex statsMutex;
/// Mutex for calls to splitContents()
Mantid::Kernel::Mutex m_splittingMutex;


//=================== PRIVATE METHODS =======================================
Expand Down
26 changes: 21 additions & 5 deletions Code/Mantid/Framework/MDEvents/src/MDGridBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ namespace MDEvents
typename std::vector<MDE>::const_iterator it = events.begin();
typename std::vector<MDE>::const_iterator it_end = events.end();
for (; it != it_end; ++it)
addEvent(*it);
addEventUnsafe(*it);

// Copy the cached numbers from the incoming box. This is quick - don't need to refresh cache
this->nPoints = box->getNPoints();
Expand Down Expand Up @@ -737,11 +737,16 @@ namespace MDEvents
// You can only split it if it is a MDBox (not MDGridBox).
MDBox<MDE, nd> * box = dynamic_cast<MDBox<MDE, nd> *>(boxes[index]);
if (!box) return;
// Track how many MDBoxes there are in the overall workspace
this->m_BoxController->trackNumBoxes(box->getDepth());
// Construct the grid box. This should take the object out of the disk MRU
MDGridBox<MDE, nd> * gridbox = new MDGridBox<MDE, nd>(box);
MDGridBox<MDE, nd> * gridbox;

{ // Lock against accessing the same box while splitting it
Kernel::Mutex::ScopedLock _lock(box->getDataMutex());

// Track how many MDBoxes there are in the overall workspace (thread-safe call)
this->m_BoxController->trackNumBoxes(box->getDepth());
// Construct the grid box. This should take the object out of the disk MRU
gridbox = new MDGridBox<MDE, nd>(box);
}
// Delete the old ungridded box
delete boxes[index];
// And now we have a gridded box instead of a boring old regular box.
Expand Down Expand Up @@ -783,6 +788,7 @@ namespace MDEvents
TMDE(
void MDGridBox)::splitAllIfNeeded(ThreadScheduler * ts)
{
return; // TODO: remove this method when not needeed
for (size_t i=0; i < numBoxes; ++i)
{
MDBox<MDE, nd> * box = dynamic_cast<MDBox<MDE, nd> *>(boxes[i]);
Expand Down Expand Up @@ -884,7 +890,17 @@ namespace MDEvents

// Add it to the contained box
if (index < numBoxes) // avoid segfaults for floating point round-off errors.
{
if (boxes[index]->getNPoints() >= this->m_BoxController->getSplitThreshold())
{
if (boxes[index]->getDepth() < this->m_BoxController->getMaxDepth())
{
Mantid::Kernel::Mutex::ScopedLock _lock(m_splittingMutex);
this->splitContents(index, NULL);
}
}
boxes[index]->addEvent(event);
}
}

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

0 comments on commit c8a09ef

Please sign in to comment.