Skip to content

Commit

Permalink
Execute catalog algorithms asynchronously. Refs #8321.
Browse files Browse the repository at this point in the history
- Added a helper method to execute asynchronously to prevent duplication of code.
  • Loading branch information
jawrainey committed Oct 31, 2013
1 parent 42507a3 commit 6b82094
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ namespace MantidQt
Mantid::API::IAlgorithm_sptr createCatalogAlgorithm(const std::string& algName);
/// Obtain the documentation for a given name from the given algorithm properties.
const std::string propertyDocumentation(const std::vector<Mantid::Kernel::Property*> &properties, const std::string &name);
/// Execute the given algorithm asynchronously.
void executeAsynchronously(Mantid::API::IAlgorithm_sptr algorithm);

};
} // namespace MantidWidgets
Expand Down
41 changes: 20 additions & 21 deletions Code/Mantid/MantidQt/MantidWidgets/src/ICatHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace MantidQt
std::vector<std::string> ICatHelper::getInstrumentList()
{
auto catalogAlgorithm = createCatalogAlgorithm("CatalogListInstruments");
catalogAlgorithm->execute();
executeAsynchronously(catalogAlgorithm);
// return the vector containing the list of instruments available.
return (catalogAlgorithm->getProperty("InstrumentList"));
}
Expand All @@ -28,7 +28,7 @@ namespace MantidQt
std::vector<std::string> ICatHelper::getInvestigationTypeList()
{
auto catalogAlgorithm = createCatalogAlgorithm("CatalogListInvestigationTypes");
catalogAlgorithm->execute();
executeAsynchronously(catalogAlgorithm);
// return the vector containing the list of investigation types available.
return (catalogAlgorithm->getProperty("InvestigationTypes"));
}
Expand Down Expand Up @@ -57,11 +57,7 @@ namespace MantidQt
}
}
// Allow asynchronous execution to update label while search is being carried out.
Poco::ActiveResult<bool> result(catalogAlgorithm->executeAsync());
while( !result.available() )
{
QCoreApplication::processEvents();
}
executeAsynchronously(catalogAlgorithm);
}

/**
Expand All @@ -78,11 +74,7 @@ namespace MantidQt
catalogAlgorithm->setPropertyValue("OutputWorkspace","__dataFileResults");

// Allow asynchronous execution to update label(s) while search is being carried out.
Poco::ActiveResult<bool> result(catalogAlgorithm->executeAsync());
while( !result.available() )
{
QCoreApplication::processEvents();
}
executeAsynchronously(catalogAlgorithm);
}

/**
Expand Down Expand Up @@ -115,13 +107,7 @@ namespace MantidQt
catalogAlgorithm->setProperty("FileNames",fileNames);
catalogAlgorithm->setProperty("DownloadPath",downloadPath);

Poco::ActiveResult<bool> result(catalogAlgorithm->executeAsync());
while( !result.available() )
{
//TODO: Inform the user where the file was saved to depending on result, e.g:
// (You do not have access to the archives. Downloading requested file over Internet...)
QCoreApplication::processEvents();
}
executeAsynchronously(catalogAlgorithm);
// Return a vector containing the file paths to the files to download.
return (catalogAlgorithm->getProperty("FileLocations"));
}
Expand Down Expand Up @@ -167,7 +153,7 @@ namespace MantidQt
{
auto catalogAlgorithm = createCatalogAlgorithm("CatalogListInstruments");

catalogAlgorithm->execute();
executeAsynchronously(catalogAlgorithm);

if (catalogAlgorithm->getProperty("IsValid"))
{
Expand All @@ -189,7 +175,7 @@ namespace MantidQt

if(loginDialog->exec() == QDialog::Accepted)
{
catalogAlgorithm->execute();
executeAsynchronously(catalogAlgorithm);
}
}

Expand Down Expand Up @@ -222,5 +208,18 @@ namespace MantidQt
return Mantid::API::AlgorithmManager::Instance().create(algName);
}

/**
* Execute the given algorithm asynchronously.
* @param algorithm :: The algorithm to execute.
*/
void ICatHelper::executeAsynchronously(Mantid::API::IAlgorithm_sptr algorithm)
{
Poco::ActiveResult<bool> result(algorithm->executeAsync());
while(!result.available())
{
QCoreApplication::processEvents();
}
}

} // namespace MantidWidgets
} // namespace MantidQt

0 comments on commit 6b82094

Please sign in to comment.