本文整理汇总了C++中mantid::api::IAlgorithm_sptr类的典型用法代码示例。如果您正苦于以下问题:C++ IAlgorithm_sptr类的具体用法?C++ IAlgorithm_sptr怎么用?C++ IAlgorithm_sptr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IAlgorithm_sptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exec
/** Run any algorithm with a variable number of parameters
*
* @param algorithmName
* @param count :: number of arguments given.
* @return the algorithm created
*/
IAlgorithm_sptr FrameworkManagerImpl::exec(const std::string& algorithmName, int count, ...)
{
// Create the algorithm
Mantid::API::IAlgorithm_sptr alg;
alg = Mantid::API::AlgorithmManager::Instance().createUnmanaged(algorithmName, -1);
alg->initialize();
if (!alg->isInitialized())
throw std::runtime_error(algorithmName + " was not initialized.");
if (count % 2 == 1)
{
throw std::runtime_error("Must have an even number of parameter/value string arguments");
}
va_list Params;
va_start(Params, count);
for(int i = 0; i < count; i += 2 )
{
std::string paramName = va_arg(Params, const char *);
std::string paramValue = va_arg(Params, const char *);
alg->setPropertyValue(paramName, paramValue);
}
va_end(Params);
alg->execute();
return alg;
}
示例2: ungroupWorkspaces
void WorkspacePresenter::ungroupWorkspaces() {
auto view = lockView();
auto selected = view->getSelectedWorkspaceNames();
if (selected.size() == 0) {
view->showCriticalUserMessage("Error Ungrouping Workspaces",
"Select a group workspace to Ungroup.");
return;
}
try {
// workspace name
auto wsname = selected[0];
std::string algName("UnGroupWorkspace");
Mantid::API::IAlgorithm_sptr alg =
Mantid::API::AlgorithmManager::Instance().create(algName, -1);
alg->initialize();
alg->setProperty("InputWorkspace", wsname);
// execute the algorithm
bool bStatus = alg->execute();
if (!bStatus) {
view->showCriticalUserMessage("MantidPlot - Algorithm error",
" Error in UnGroupWorkspace algorithm");
}
} catch (...) {
view->showCriticalUserMessage("MantidPlot - Algorithm error",
" Error in UnGroupWorkspace algorithm");
}
}
示例3: algName
/** This method executes the ListInstruments algorithm
* and fills the instrument box with instrument lists returned by ICat API
* @return shared pointer to workspace which contains instrument names
*/
std::vector<std::string> ICatUtils::executeListInstruments()
{
QString algName("CatalogListInstruments");
const int version=-1;
Mantid::API::IAlgorithm_sptr alg;
try
{
alg = Mantid::API::AlgorithmManager::Instance().create(algName.toStdString(),version);
}
catch(...)
{
throw std::runtime_error("Error when Populating the instrument list box");
}
Poco::ActiveResult<bool> result(alg->executeAsync());
while( !result.available() )
{
QCoreApplication::processEvents();
}
if(!alg->isExecuted())
{
//if the algorithm failed check the session id passed is valid
if(!isSessionValid(alg))
{
//at this point session is invalid, popup loginbox to login
if(login())
{
//now populate instrument box
std::vector<std::string> instruments =executeListInstruments();
return instruments;
}
else
{
throw std::runtime_error("Please Login to the information catalog using the login menu provided to do the investigation search.");
}
}
else
{
return std::vector<std::string>();
}
}
std::vector<std::string>instrlist;
try
{
instrlist= alg->getProperty("InstrumentList");
}
catch (Mantid::Kernel::Exception::NotFoundError&)
{
throw;
}
return instrlist;
}
示例4: add
/** Add a new algorithm to the list monitored
*
* @param alg :: algorithm to monitor.
*/
void AlgorithmMonitor::add(Mantid::API::IAlgorithm_sptr alg) {
lock();
alg->addObserver(m_finishedObserver);
alg->addObserver(m_errorObserver);
alg->addObserver(m_progressObserver);
m_algorithms.push_back(alg->getAlgorithmID());
++m_nRunning;
emit algorithmStarted(alg->getAlgorithmID());
emit countChanged();
unlock();
}
示例5: executeGetdataFiles
/// execute getdatafIles algorithm
ITableWorkspace_sptr ICatInvestigation::executeGetdataFiles()
{
QString algName("CatalogGetDataFiles");
const int version=1;
Mantid::API::ITableWorkspace_sptr ws_sptr;
Mantid::API::IAlgorithm_sptr alg;
try
{
alg = Mantid::API::AlgorithmManager::Instance().create(algName.toStdString(),version);
}
catch(...)
{
throw std::runtime_error("Error when loading the data files associated to the selected investigation ");
}
try
{
alg->setProperty("InvestigationId",m_invstId);
alg->setProperty("FilterLogFiles",isDataFilesChecked());
alg->setPropertyValue("OutputWorkspace","datafiles");
}
catch(std::invalid_argument& e)
{
emit error(e.what());
return ws_sptr;
}
catch (Mantid::Kernel::Exception::NotFoundError& e)
{
emit error(e.what());
return ws_sptr;
}
try
{
Poco::ActiveResult<bool> result(alg->executeAsync());
while( !result.available() )
{
QCoreApplication::processEvents();
}
}
catch(...)
{
return ws_sptr;
}
if(AnalysisDataService::Instance().doesExist("datafiles"))
{
ws_sptr = boost::dynamic_pointer_cast<Mantid::API::ITableWorkspace>
(AnalysisDataService::Instance().retrieve("datafiles"));
}
return ws_sptr;
}
示例6: executeAsynchronously
/**
* Execute the given algorithm asynchronously.
* @param algorithm :: The algorithm to execute.
*/
void CatalogHelper::executeAsynchronously(
const Mantid::API::IAlgorithm_sptr &algorithm) {
Poco::ActiveResult<bool> result(algorithm->executeAsync());
while (!result.available()) {
QCoreApplication::processEvents();
}
}
示例7: updateAlgorithm
/**
Upadates the non-default algorithm properties in the history.
@param alg :: Pointer to the algorthm
*/
void InputHistoryImpl::updateAlgorithm(Mantid::API::IAlgorithm_sptr alg)
{
const std::vector< Property* >& props = alg->getProperties();
QList< PropertyData > prop_hist_list;
for(std::vector< Property* >::const_iterator prop=props.begin();prop!=props.end();++prop)
if (!(*prop)->isDefault())
{
PropertyData prop_hist(QString::fromStdString((*prop)->name()),QString::fromStdString((*prop)->value()));
prop_hist_list.push_back(prop_hist);
}
else
{
PropertyData prop_hist(QString::fromStdString((*prop)->name()),"");
prop_hist_list.push_back(prop_hist);
}
m_history[QString::fromStdString(alg->name())] = prop_hist_list;
}
示例8: setupFit
void ConvFit::setupFit(Mantid::API::IAlgorithm_sptr fitAlgorithm) {
if (boolSettingValue("UseTempCorrection"))
m_convFittingModel->setTemperature(doubleSettingValue("TempCorrection"));
else
m_convFittingModel->setTemperature(boost::none);
fitAlgorithm->setProperty("ExtractMembers",
boolSettingValue("ExtractMembers"));
IndirectFitAnalysisTab::setupFit(fitAlgorithm);
}
示例9: index
/**
* Create a list of file extensions from the given algorithm
* @param algName :: The name of the algorithm
* @param propName :: The name of the property
* @returns A list of file extensions
*/
QStringList
MWRunFiles::getFileExtensionsFromAlgorithm(const QString &algName,
const QString &propName) {
Mantid::API::IAlgorithm_sptr algorithm =
Mantid::API::AlgorithmManager::Instance().createUnmanaged(
algName.toStdString());
QStringList fileExts;
if (!algorithm)
return fileExts;
algorithm->initialize();
Property *prop = algorithm->getProperty(propName.toStdString());
FileProperty *fileProp = dynamic_cast<FileProperty *>(prop);
MultipleFileProperty *multiFileProp =
dynamic_cast<MultipleFileProperty *>(prop);
std::vector<std::string> allowed;
QString preferredExt;
if (fileProp) {
allowed = fileProp->allowedValues();
preferredExt = QString::fromStdString(fileProp->getDefaultExt());
} else if (multiFileProp) {
allowed = multiFileProp->allowedValues();
preferredExt = QString::fromStdString(multiFileProp->getDefaultExt());
} else {
return fileExts;
}
std::vector<std::string>::const_iterator iend = allowed.end();
int index(0);
for (std::vector<std::string>::const_iterator it = allowed.begin();
it != iend; ++it) {
if (!it->empty()) {
QString ext = QString::fromStdString(*it);
fileExts.append(ext);
if (ext == preferredExt) {
fileExts.move(index, 0);
}
++index;
}
}
return fileExts;
}
示例10: setSearchProperties
/**
* Set the "search" properties to their related input fields.
* @param catalogAlgorithm :: Algorithm to set the search properties for.
* @param userInputFields :: The search properties to set against the algorithm.
*/
void CatalogHelper::setSearchProperties(const Mantid::API::IAlgorithm_sptr &catalogAlgorithm,
const std::map<std::string, std::string> &userInputFields)
{
// This will be the workspace where the content of the search result is output to.
catalogAlgorithm->setProperty("OutputWorkspace", "__searchResults");
// Iterate over the provided map of user input fields. For each field that isn't empty (e.g. a value was input by the user)
// then we will set the algorithm property with the key and value of that specific value.
for (auto it = userInputFields.begin(); it != userInputFields.end(); it++)
{
std::string value = it->second;
// If the user has input any search terms.
if (!value.empty())
{
// Set the property that the search algorithm uses to: (key => FieldName, value => FieldValue) (e.g., (Keywords, bob))
catalogAlgorithm->setProperty(it->first, value);
}
}
}
示例11: plusWs
/**
* Plus two workspaces together, "in place".
*
* @param ws1 :: The first workspace.
* @param ws2 :: The second workspace.
*
* @returns a pointer to the result (the first workspace).
*/
API::Workspace_sptr Load::plusWs(Workspace_sptr ws1, Workspace_sptr ws2) {
WorkspaceGroup_sptr group1 = boost::dynamic_pointer_cast<WorkspaceGroup>(ws1);
WorkspaceGroup_sptr group2 = boost::dynamic_pointer_cast<WorkspaceGroup>(ws2);
if (group1 && group2) {
// If we're dealing with groups, then the child workspaces must be added
// separately - setProperty
// wont work otherwise.
std::vector<std::string> group1ChildWsNames = group1->getNames();
std::vector<std::string> group2ChildWsNames = group2->getNames();
if (group1ChildWsNames.size() != group2ChildWsNames.size())
throw std::runtime_error("Unable to add group workspaces with different "
"number of child workspaces.");
auto group1ChildWsName = group1ChildWsNames.begin();
auto group2ChildWsName = group2ChildWsNames.begin();
for (; group1ChildWsName != group1ChildWsNames.end();
++group1ChildWsName, ++group2ChildWsName) {
Workspace_sptr group1ChildWs = group1->getItem(*group1ChildWsName);
Workspace_sptr group2ChildWs = group2->getItem(*group2ChildWsName);
Mantid::API::IAlgorithm_sptr plusAlg = createChildAlgorithm("Plus", 1);
plusAlg->setProperty<Workspace_sptr>("LHSWorkspace", group1ChildWs);
plusAlg->setProperty<Workspace_sptr>("RHSWorkspace", group2ChildWs);
plusAlg->setProperty<Workspace_sptr>("OutputWorkspace", group1ChildWs);
plusAlg->executeAsChildAlg();
}
} else if (!group1 && !group2) {
Mantid::API::IAlgorithm_sptr plusAlg = createChildAlgorithm("Plus", 1);
plusAlg->setProperty<Workspace_sptr>("LHSWorkspace", ws1);
plusAlg->setProperty<Workspace_sptr>("RHSWorkspace", ws2);
plusAlg->setProperty<Workspace_sptr>("OutputWorkspace", ws1);
plusAlg->executeAsChildAlg();
} else {
throw std::runtime_error(
"Unable to add a group workspace to a non-group workspace");
}
return ws1;
}
示例12: setAlgorithm
/**
* Set the algorithm pointer
* @param alg :: A pointer to the algorithm
*/
void AlgorithmDialog::setAlgorithm(Mantid::API::IAlgorithm_sptr alg) {
m_algorithm = alg;
m_algName = QString::fromStdString(alg->name());
m_algProperties.clear();
m_tied_properties.clear();
std::vector<Mantid::Kernel::Property *>::const_iterator iend =
alg->getProperties().end();
for (std::vector<Mantid::Kernel::Property *>::const_iterator itr =
alg->getProperties().begin();
itr != iend; ++itr) {
Mantid::Kernel::Property *p = *itr;
if (dynamic_cast<Mantid::API::IWorkspaceProperty *>(p) ||
p->direction() != Mantid::Kernel::Direction::Output) {
m_algProperties.append(QString::fromStdString(p->name()));
}
}
m_validators.clear();
m_noValidation.clear();
}
示例13: optLattice
/**
@param inname Name of workspace containing peaks
@param params optimized cell parameters
@param out residuals from optimization
*/
void OptimizeLatticeForCellType::optLattice(std::string inname,
std::vector<double> ¶ms,
double *out) {
PeaksWorkspace_sptr ws = boost::dynamic_pointer_cast<PeaksWorkspace>(
AnalysisDataService::Instance().retrieve(inname));
const std::vector<Peak> &peaks = ws->getPeaks();
size_t n_peaks = ws->getNumberPeaks();
std::vector<V3D> q_vector;
std::vector<V3D> hkl_vector;
for (size_t i = 0; i < params.size(); i++)
params[i] = std::abs(params[i]);
for (size_t i = 0; i < n_peaks; i++) {
q_vector.push_back(peaks[i].getQSampleFrame());
hkl_vector.push_back(peaks[i].getHKL());
}
Mantid::API::IAlgorithm_sptr alg = createChildAlgorithm("CalculateUMatrix");
alg->setPropertyValue("PeaksWorkspace", inname);
alg->setProperty("a", params[0]);
alg->setProperty("b", params[1]);
alg->setProperty("c", params[2]);
alg->setProperty("alpha", params[3]);
alg->setProperty("beta", params[4]);
alg->setProperty("gamma", params[5]);
alg->executeAsChildAlg();
ws = alg->getProperty("PeaksWorkspace");
OrientedLattice latt = ws->mutableSample().getOrientedLattice();
DblMatrix UB = latt.getUB();
DblMatrix A = aMatrix(params);
DblMatrix Bc = A;
Bc.Invert();
DblMatrix U1_B1 = UB * A;
OrientedLattice o_lattice;
o_lattice.setUB(U1_B1);
DblMatrix U1 = o_lattice.getU();
DblMatrix U1_Bc = U1 * Bc;
for (size_t i = 0; i < hkl_vector.size(); i++) {
V3D error = U1_Bc * hkl_vector[i] - q_vector[i] / (2.0 * M_PI);
out[i] = error.norm2();
}
return;
}
示例14: isSessionValid
bool ICatUtils::isSessionValid(const Mantid::API::IAlgorithm_sptr& alg)
{
try
{
return alg->getProperty("IsValid");
}
catch (Mantid::Kernel::Exception::NotFoundError&)
{
throw;
}
}
示例15: loadFileToWs
/**
* Loads a file into a *hidden* workspace.
*
* @param fileName :: file name to load.
* @param wsName :: workspace name, which will be prefixed by a "__"
*
* @returns a pointer to the loaded workspace
*/
API::Workspace_sptr Load::loadFileToWs(const std::string &fileName,
const std::string &wsName) {
Mantid::API::IAlgorithm_sptr loadAlg = createChildAlgorithm("Load", 1);
// Get the list properties for the concrete loader load algorithm
const std::vector<Kernel::Property *> &props = getProperties();
// Loop through and set the properties on the Child Algorithm
for (auto prop : props) {
const std::string &propName = prop->name();
if (this->existsProperty(propName)) {
if (propName == "Filename") {
loadAlg->setPropertyValue("Filename", fileName);
} else if (propName == "OutputWorkspace") {
loadAlg->setPropertyValue("OutputWorkspace", wsName);
} else {
loadAlg->setPropertyValue(propName, getPropertyValue(propName));
}
}
}
loadAlg->executeAsChildAlg();
Workspace_sptr ws = loadAlg->getProperty("OutputWorkspace");
// ws->setName(wsName);
AnalysisDataService::Instance().addOrReplace(wsName, ws);
return ws;
}