Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/8445_icat_r…
Browse files Browse the repository at this point in the history
…efactor_algorithms. Refs #8445

Conflicts:
	Code/Mantid/Framework/ICat/src/CatalogLogin.cpp
	Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/CatalogHelper.h
  • Loading branch information
jawrainey committed Nov 18, 2013
2 parents 870e791 + 023312d commit e7ad498
Show file tree
Hide file tree
Showing 238 changed files with 3,151 additions and 5,184 deletions.
21 changes: 0 additions & 21 deletions Code/Mantid/Build/CMake/WindowsSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,6 @@ set ( PYTHON_EXECUTABLE_DEBUG "${CMAKE_LIBRARY_PATH}/Python27/python_d.exe" CACH
## The "pythonw" executable that avoids raising another terminal when it runs. Used for IPython
set ( PYTHONW_EXECUTABLE "${CMAKE_LIBRARY_PATH}/Python27/pythonw.exe" CACHE FILEPATH "The location of the pythonw executable. This suppresses the new terminal window on startup" FORCE )

# Finally create variables containing the required distribution files
set ( PY_DIST_DIRS "${CMAKE_LIBRARY_PATH}/Python27/DLLs" "${CMAKE_LIBRARY_PATH}/Python27/Lib" )
set ( PY_DLL_PREFIX "${CMAKE_LIBRARY_PATH}/Python27/Python27" )
set ( PY_DLL_SUFFIX_RELEASE ".dll" )
set ( PY_DLL_SUFFIX_RELWITHDEBINFO ${PY_DLL_SUFFIX_RELEASE} )
set ( PY_DLL_SUFFIX_MINSIZEREL ${PY_DLL_SUFFIX_RELEASE} )
set ( PY_DLL_SUFFIX_DEBUG "_d.dll" )

set ( PY_EXE_PREFIX "${CMAKE_LIBRARY_PATH}/Python27/python" )
set ( PY_EXE_SUFFIX_RELEASE ".exe" )
set ( PY_EXE_SUFFIX_RELWITHDEBINFO ${PY_EXE_SUFFIX_RELEASE} )
set ( PY_EXE_SUFFIX_MINSIZEREL ${PY_EXE_SUFFIX_RELEASE} )
set ( PY_EXE_SUFFIX_DEBUG "_d.exe" )
# No terminal version
set ( PY_EXEW_PREFIX "${CMAKE_LIBRARY_PATH}/Python27/pythonw" )
set ( PY_EXEW_SUFFIX_RELEASE ".exe" )
set ( PY_EXEW_SUFFIX_RELWITHDEBINFO ${PY_EXE_SUFFIX_RELEASE} )
set ( PY_EXEW_SUFFIX_MINSIZEREL ${PY_EXE_SUFFIX_RELEASE} )
set ( PY_EXEW_SUFFIX_DEBUG "_d.exe" )


###########################################################################
# Compiler options.
###########################################################################
Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/AlgorithmManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class MANTID_API_DLL AlgorithmManagerImpl
void setMaxAlgorithms(int n);

IAlgorithm_sptr getAlgorithm(AlgorithmID id) const;
void removeById(AlgorithmID id);
IAlgorithm_sptr newestInstanceOf(const std::string& algorithmName) const;
std::vector<IAlgorithm_const_sptr> runningInstancesOf(const std::string& algorithmName) const;

Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/AlgorithmProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ namespace Mantid
void createConcreteAlg(bool initOnly = false);
void stopped();
void addObservers();
void dropWorkspaceReferences();

/// Poco::ActiveMethod used to implement asynchronous execution.
Poco::ActiveMethod<bool, Poco::Void, AlgorithmProxy> _executeAsync;
Expand Down
25 changes: 25 additions & 0 deletions Code/Mantid/Framework/API/src/AlgorithmManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,31 @@ namespace Mantid
return IAlgorithm_sptr();
}

/**
* Removes the given algorithm from the managed list
* @param id :: The ID of the algorithm
*/
void AlgorithmManagerImpl::removeById(AlgorithmID id)
{
Mutex::ScopedLock _lock(this->m_managedMutex);
auto itend = m_managed_algs.end();
for(auto it = m_managed_algs.begin(); it != itend; ++it)
{
if((**it).getAlgorithmID() == id)
{
if(!(*it)->isRunning())
{
g_log.debug() << "Removing algorithm " << (*it)->name() << std::endl;
m_managed_algs.erase(it);
}
else
{
g_log.debug() << "Unable to remove algorithm " << (*it)->name() << ". The algorithm is running." << std::endl;
}
break;
}
}
}

/** Called by an algorithm that is executing asynchronously
* This sends out the notification.
Expand Down
21 changes: 18 additions & 3 deletions Code/Mantid/Framework/API/src/AlgorithmProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,10 @@ namespace Mantid
}
catch(...)
{
m_alg.reset();
stopped();
throw;
}
stopped();

return m_isExecuted;
}

Expand Down Expand Up @@ -117,7 +116,7 @@ namespace Mantid
}
catch(...)
{
m_alg.reset(); // Release the concrete algorithm instance
stopped();
throw;
}
stopped();
Expand Down Expand Up @@ -261,10 +260,26 @@ namespace Mantid
*/
void AlgorithmProxy::stopped()
{
if(!isChild()) dropWorkspaceReferences();
m_isExecuted = m_alg->isExecuted();
m_alg.reset();
}

/**
* Forces any workspace property to clear its internal workspace reference
*/
void AlgorithmProxy::dropWorkspaceReferences()
{
const std::vector< Property*> &props = getProperties();
for (unsigned int i = 0; i < props.size(); ++i)
{
if(auto *wsProp = dynamic_cast<IWorkspaceProperty*>(props[i]))
{
wsProp->clear();
}
}
}

/**
* Add observers stored previously in m_externalObservers
*/
Expand Down
5 changes: 1 addition & 4 deletions Code/Mantid/Framework/API/src/IPowderDiffPeakFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,6 @@ namespace API
*/
std::complex<double> E1(std::complex<double> z)
{
const double el = 0.5772156649015328;

std::complex<double> exp_e1;

double rz = real(z);
Expand Down Expand Up @@ -363,8 +361,8 @@ namespace API
}
} // ENDFOR k

// cout << "[DB] el = " << el << ", exp_e1 = " << exp_e1 << endl;

const double el = 0.5772156649015328;
exp_e1 = -el - log(z) + (z*exp_e1);
}
else
Expand All @@ -386,7 +384,6 @@ namespace API
}
}

// cout << "[DB] Final exp_e1 = " << exp_e1 << "\n";

return exp_e1;
}
Expand Down
21 changes: 20 additions & 1 deletion Code/Mantid/Framework/API/test/AlgorithmManagerTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class AlgorithmManagerTest : public CxxTest::TestSuite
static AlgorithmManagerTest *createSuite() { return new AlgorithmManagerTest(); }
static void destroySuite( AlgorithmManagerTest *suite ) { delete suite; }

AlgorithmManagerTest()
AlgorithmManagerTest()
{
// A test fails unless algorithms.retained is big enough
Mantid::Kernel::ConfigService::Instance().setString("algorithms.retained","5");
Expand Down Expand Up @@ -295,6 +295,25 @@ class AlgorithmManagerTest : public CxxTest::TestSuite
}
}

void testRemovingByIdRemovesCorrectObject()
{
auto & mgr = AlgorithmManager::Instance();
mgr.setMaxAlgorithms(10);
const size_t initialManagerSize = mgr.size();
// 2 different ids for same named algorithm
auto alg1 = mgr.create("AlgTest");
auto alg2 = mgr.create("AlgTest");
TS_ASSERT_EQUALS(initialManagerSize + 2, mgr.size());

TS_ASSERT_THROWS_NOTHING(mgr.removeById(alg1->getAlgorithmID()));
TS_ASSERT_EQUALS(initialManagerSize + 1, mgr.size());
// the right one?
auto foundAlg = mgr.getAlgorithm(alg2->getAlgorithmID());
TS_ASSERT(foundAlg);

mgr.setMaxAlgorithms(5);
}

void test_newestInstanceOf()
{
auto& am = AlgorithmManager::Instance();
Expand Down
10 changes: 9 additions & 1 deletion Code/Mantid/Framework/Algorithms/src/AsymmetryCalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,15 @@ void AsymmetryCalc::exec()
double denominator = (tmpWS->dataY(forward)[j] + alpha * tmpWS->dataY(backward)[j]);

// cal F-aB / F+aB
outputWS->dataY(0)[j] = denominator ? numerator / denominator : 0.;
if(denominator)
{
outputWS->dataY(0)[j] = numerator / denominator;
}
else
{
outputWS->dataY(0)[j] = 0.;
}


// Work out the error (as in 1st attachment of ticket #4188)
double error = 1.0;
Expand Down
32 changes: 17 additions & 15 deletions Code/Mantid/Framework/Algorithms/src/CheckWorkspacesMatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,21 +337,24 @@ bool CheckWorkspacesMatch::checkEventLists(DataObjects::EventWorkspace_const_spt
// actual time-of flight is 50 nanoseconds
if ((ews1->getAxis(0)->unit()->label() == "microsecond")
|| (ews2->getAxis(0)->unit()->label() == "microsecond"))
{
ToleranceTOF = 0.05;
}

bool mismatchedEvent = false;
int mismatchedEventWI = 0;
//PARALLEL_FOR2(ews1, ews2)
for (int i=0; i<static_cast<int>(ews1->getNumberHistograms()); i++)
PARALLEL_FOR2(ews1, ews2)
for (int i=0; i<static_cast<int>(ews1->getNumberHistograms()); ++i)
{
PARALLEL_START_INTERUPT_REGION
prog->report("EventLists");
prog->report();
if (!mismatchedEvent) // This guard will avoid checking unnecessarily
{
const EventList &el1 = ews1->getEventList(i);
const EventList &el2 = ews2->getEventList(i);
if (!el1.equals(el2, ToleranceTOF, Tolerance, 1))
{
PARALLEL_CRITICAL(mismatch)
mismatchedEvent = true;
mismatchedEventWI = i;
}
Expand Down Expand Up @@ -383,10 +386,9 @@ bool CheckWorkspacesMatch::checkData(API::MatrixWorkspace_const_sptr ws1, API::M
const size_t numHists = ws1->getNumberHistograms();
const size_t numBins = ws1->blocksize();
const bool histogram = ws1->isHistogramData();
bool checkAllData=getProperty("CheckAllData");

const bool checkAllData = getProperty("CheckAllData");
const bool RelErr = getProperty("ToleranceRelErr");


// First check that the workspace are the same size
if ( numHists != ws2->getNumberHistograms() || numBins != ws2->blocksize() )
{
Expand All @@ -405,14 +407,14 @@ bool CheckWorkspacesMatch::checkData(API::MatrixWorkspace_const_sptr ws1, API::M
bool resultBool = true;

// Now check the data itself
//PARALLEL_FOR2(ws1, ws2)
PARALLEL_FOR2(ws1, ws2)
for ( int i = 0; i < static_cast<int>(numHists); ++i )
{
PARALLEL_START_INTERUPT_REGION
prog->report("Histograms");
if (resultBool) // Avoid checking unnecessarily
{
prog->report();

if ( resultBool || checkAllData ) // Avoid checking unnecessarily
{
// Get references to the current spectrum
const MantidVec& X1 = ws1->readX(i);
const MantidVec& Y1 = ws1->readY(i);
Expand All @@ -421,7 +423,6 @@ bool CheckWorkspacesMatch::checkData(API::MatrixWorkspace_const_sptr ws1, API::M
const MantidVec& Y2 = ws2->readY(i);
const MantidVec& E2 = ws2->readE(i);

bool RelErr = getProperty("ToleranceRelErr");
for ( int j = 0; j < static_cast<int>(numBins); ++j )
{
bool err;
Expand Down Expand Up @@ -457,22 +458,23 @@ bool CheckWorkspacesMatch::checkData(API::MatrixWorkspace_const_sptr ws1, API::M
g_log.debug() << " Dataset #2 (X,Y,E) = (" << X2[j] << "," << Y2[j] << "," << E2[j] << ")\n";
g_log.debug() << " Difference (X,Y,E) = (" << std::fabs(X1[j] - X2[j]) << ","
<< std::fabs(Y1[j] - Y2[j]) << "," << std::fabs(E1[j] - E2[j]) << ")\n";
result = "Data mismatch";
resultBool = checkAllData;
PARALLEL_CRITICAL(resultBool)
resultBool = false;
}
}

// Extra one for histogram data
if ( histogram && std::fabs(X1.back() - X2.back()) > tolerance )
{
result = "Data mismatch";
resultBool = checkAllData;
PARALLEL_CRITICAL(resultBool)
resultBool = false;
}
}
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION

if ( ! resultBool ) result = "Data mismatch";
// If all is well, return true
return resultBool;
}
Expand Down
1 change: 0 additions & 1 deletion Code/Mantid/Framework/Algorithms/src/CreateWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ void CreateWorkspace::exec()
const std::string xUnit = getProperty("UnitX");
const std::string vUnit = getProperty("VerticalAxisUnit");
const std::vector<std::string> vAxis = getProperty("VerticalAxisValues");
std::string parentWorkspace = getPropertyValue("ParentWorkspace");

if ( ( vUnit != "SpectraNumber" ) && ( static_cast<int>(vAxis.size()) != nSpec ) )
{
Expand Down
4 changes: 1 addition & 3 deletions Code/Mantid/Framework/Algorithms/src/FitPeak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,6 @@ namespace Algorithms
map<string, double> errormap;
push(bkgdfunc, m_bkupBkgdFunc, errormap);

std::vector<double> vec_bkgd;
vector<double> vec_xmin(2);
vector<double> vec_xmax(2);
vec_xmin[0] = m_minFitX;
Expand Down Expand Up @@ -761,6 +760,7 @@ namespace Algorithms
push(m_bkgdFunc, m_bestBkgdFunc, m_fitErrorBkgdFunc);
m_bestRwp = rwp;
}
g_log.debug()<<"Failed due to: " << failreason <<std::endl;

return;
}
Expand Down Expand Up @@ -947,12 +947,10 @@ namespace Algorithms
{
// Fit for composite function renders a better result
goodness_final = goodness;
errorreason = "";
}
else if (goodness_init <= goodness && goodness_init < DBL_MAX)
{
goodness_final = goodness_init;
errorreason = "";
g_log.information("Fit peak/background composite function FAILS to render a better solution.");
pop(bkuppeakmap, peakfunc);
pop(bkupbkgdmap, bkgdfunc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ void NormaliseToMonitor::normaliseBinByBin(const API::MatrixWorkspace_sptr& inpu

// Calculate result and store in local variable to avoid overwriting original data if
// output workspace is same as one of the input ones
// cppcheck-suppress zerodivcond
const double newY = leftY/rightY;

if (fabs(rightY)>1.0e-12 && fabs(newY)>1.0e-12)
Expand Down
13 changes: 4 additions & 9 deletions Code/Mantid/Framework/Algorithms/src/RingProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,26 +564,21 @@ void RingProfile::getBinForPixel(const API::MatrixWorkspace_sptr ws,
// the reference to X bins (the limits for each pixel in the horizontal direction)
auto xvec = ws->dataX(spectrum_index);

double xpos;
double diffx;
double distance;
double angle;

// for each pixel inside this row
for (size_t i = 0; i< xvec.size()-1; i++){

xpos = (xvec[i] + xvec[i+1])/2.0; // the x position is the centre of the bins boundaries
diffx = xpos - centre_x;
double xpos = (xvec[i] + xvec[i+1])/2.0; // the x position is the centre of the bins boundaries
double diffx = xpos - centre_x;
// calculate the distance => norm of pixel position - centre
distance = sqrt(pow(diffx, 2.0) + diffy_quad);
double distance = sqrt(pow(diffx, 2.0) + diffy_quad);

// check if the distance is inside the ring
if (distance < min_radius || distance > max_radius || distance == 0){
bins_pos[i] = -1;
continue;
}

angle = atan2(diffy, diffx);
double angle = atan2(diffy, diffx);

// call fromAngleToBin (radians)
bins_pos[i] = fromAngleToBin(angle, false);
Expand Down

0 comments on commit e7ad498

Please sign in to comment.