本文整理汇总了C++中WorkspaceGroup_sptr::getItem方法的典型用法代码示例。如果您正苦于以下问题:C++ WorkspaceGroup_sptr::getItem方法的具体用法?C++ WorkspaceGroup_sptr::getItem怎么用?C++ WorkspaceGroup_sptr::getItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WorkspaceGroup_sptr
的用法示例。
在下文中一共展示了WorkspaceGroup_sptr::getItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: transmissionRunSum
/**
* Sum over transmission group workspaces to produce one
* workspace.
* @param transGroup : The transmission group to be processed
* @return A workspace pointer containing the sum of transmission workspaces.
*/
Mantid::API::Workspace_sptr
ReflectometryReductionOneAuto::sumOverTransmissionGroup(
WorkspaceGroup_sptr &transGroup) {
// Handle transmission runs
// we clone the first member of transmission group as to
// avoid addition in place which would affect the original
// workspace member.
//
// We used .release because clone() will return a unique_ptr.
// we need to release the ownership of the pointer so that it
// can be cast into a shared_ptr of type Workspace.
Workspace_sptr transmissionRunSum(transGroup->getItem(0)->clone().release());
// make a variable to store the overall total of the summation
MatrixWorkspace_sptr total;
// set up and initialize plus algorithm.
auto plusAlg = this->createChildAlgorithm("Plus");
plusAlg->setChild(true);
// plusAlg->setRethrows(true);
plusAlg->initialize();
// now accumalate the group members
for (size_t item = 1; item < transGroup->size(); ++item) {
plusAlg->setProperty("LHSWorkspace", transmissionRunSum);
plusAlg->setProperty("RHSWorkspace", transGroup->getItem(item));
plusAlg->setProperty("OutputWorkspace", transmissionRunSum);
plusAlg->execute();
total = plusAlg->getProperty("OutputWorkspace");
}
return total;
}
示例2: plotWorkspaces
/**
* Handles the plotting of workspace post algorithm completion
*/
void Stretch::plotWorkspaces() {
WorkspaceGroup_sptr fitWorkspace;
fitWorkspace = AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>(
m_fitWorkspaceName);
auto sigma = QString::fromStdString(fitWorkspace->getItem(0)->getName());
auto beta = QString::fromStdString(fitWorkspace->getItem(1)->getName());
// Check Sigma and Beta workspaces exist
if (sigma.right(5).compare("Sigma") == 0) {
if (beta.right(4).compare("Beta") == 0) {
// Plot Beta workspace
QString pyInput = "from mantidplot import plot2D\n";
if (m_plotType.compare("All") == 0 || m_plotType.compare("Beta") == 0) {
pyInput += "importMatrixWorkspace('";
pyInput += beta;
pyInput += "').plotGraph2D()\n";
}
// Plot Sigma workspace
if (m_plotType.compare("All") == 0 || m_plotType.compare("Sigma") == 0) {
pyInput += "importMatrixWorkspace('";
pyInput += sigma;
pyInput += "').plotGraph2D()\n";
}
m_pythonRunner.runPythonCode(pyInput);
}
} else {
g_log.error(
"Beta and Sigma workspace were not found and could not be plotted.");
}
}
示例3:
WorkspaceGroup_sptr
PolarizationCorrectionFredrikze::execPNR(WorkspaceGroup_sptr inWS) {
size_t itemIndex = 0;
MatrixWorkspace_sptr Ip =
boost::dynamic_pointer_cast<MatrixWorkspace>(inWS->getItem(itemIndex++));
MatrixWorkspace_sptr Ia =
boost::dynamic_pointer_cast<MatrixWorkspace>(inWS->getItem(itemIndex++));
const auto rho = this->getEfficiencyWorkspace(crhoLabel);
const auto pp = this->getEfficiencyWorkspace(cppLabel);
const auto D = pp * (rho + 1);
const auto nIp = (Ip * (rho * pp + 1.0) + Ia * (pp - 1.0)) / D;
const auto nIa = (Ip * (rho * pp - 1.0) + Ia * (pp + 1.0)) / D;
// Preserve the history of the inside workspaces
nIp->history().addHistory(Ip->getHistory());
nIa->history().addHistory(Ia->getHistory());
WorkspaceGroup_sptr dataOut = boost::make_shared<WorkspaceGroup>();
dataOut->addWorkspace(nIp);
dataOut->addWorkspace(nIa);
return dataOut;
}
示例4: execPNR
WorkspaceGroup_sptr PolarizationCorrection::execPNR(WorkspaceGroup_sptr inWS) {
size_t itemIndex = 0;
MatrixWorkspace_sptr Ip =
boost::dynamic_pointer_cast<MatrixWorkspace>(inWS->getItem(itemIndex++));
MatrixWorkspace_sptr Ia =
boost::dynamic_pointer_cast<MatrixWorkspace>(inWS->getItem(itemIndex++));
MatrixWorkspace_sptr ones = copyShapeAndFill(Ip, 1.0);
const VecDouble c_rho = getProperty(crhoLabel());
const VecDouble c_pp = getProperty(cppLabel());
const auto rho = this->execPolynomialCorrection(
ones, c_rho); // Execute polynomial expression
const auto pp = this->execPolynomialCorrection(
ones, c_pp); // Execute polynomial expression
const auto D = pp * (rho + 1);
const auto nIp = (Ip * (rho * pp + 1.0) + Ia * (pp - 1.0)) / D;
const auto nIa = (Ip * (rho * pp - 1.0) + Ia * (pp + 1.0)) / D;
// Preserve the history of the inside workspaces
nIp->history().addHistory(Ip->getHistory());
nIa->history().addHistory(Ia->getHistory());
WorkspaceGroup_sptr dataOut = boost::make_shared<WorkspaceGroup>();
dataOut->addWorkspace(nIp);
dataOut->addWorkspace(nIa);
return dataOut;
}
示例5: plotWorkspaces
/**
* Handles the plotting of workspace post algorithm completion
*/
void Stretch::plotWorkspaces() {
setPlotResultIsPlotting(true);
WorkspaceGroup_sptr fitWorkspace;
fitWorkspace = getADSWorkspaceGroup(m_fitWorkspaceName);
auto sigma = QString::fromStdString(fitWorkspace->getItem(0)->getName());
auto beta = QString::fromStdString(fitWorkspace->getItem(1)->getName());
// Check Sigma and Beta workspaces exist
if (sigma.right(5).compare("Sigma") == 0 &&
beta.right(4).compare("Beta") == 0) {
QString pyInput = "from mantidplot import plot2D\n";
std::string const plotType = m_uiForm.cbPlot->currentText().toStdString();
if (plotType == "All" || plotType == "Beta") {
pyInput += "importMatrixWorkspace('";
pyInput += beta;
pyInput += "').plotGraph2D()\n";
}
if (plotType == "All" || plotType == "Sigma") {
pyInput += "importMatrixWorkspace('";
pyInput += sigma;
pyInput += "').plotGraph2D()\n";
}
m_pythonRunner.runPythonCode(pyInput);
} else {
g_log.error(
"Beta and Sigma workspace were not found and could not be plotted.");
}
setPlotResultIsPlotting(false);
}
示例6: processViewImg
void TomographyIfacePresenter::processViewImg() {
std::string ip = m_view->showImagePath();
QString suf = QFileInfo(QString::fromStdString(ip)).suffix();
// This is not so great, as we check extensions and not really file
// content/headers, as it should be.
if ((0 == QString::compare(suf, "fit", Qt::CaseInsensitive)) ||
(0 == QString::compare(suf, "fits", Qt::CaseInsensitive))) {
WorkspaceGroup_sptr wsg = m_model->loadFITSImage(ip);
if (!wsg)
return;
MatrixWorkspace_sptr ws =
boost::dynamic_pointer_cast<MatrixWorkspace>(wsg->getItem(0));
if (!ws)
return;
m_view->showImage(ws);
// clean-up container group workspace
if (wsg)
AnalysisDataService::Instance().remove(wsg->getName());
} else if ((0 == QString::compare(suf, "tif", Qt::CaseInsensitive)) ||
(0 == QString::compare(suf, "tiff", Qt::CaseInsensitive)) ||
(0 == QString::compare(suf, "png", Qt::CaseInsensitive))) {
m_view->showImage(ip);
} else {
m_view->userWarning(
"Failed to load image - format issue",
"Could not load image because the extension of the file " + ip +
", suffix: " + suf.toStdString() +
" does not correspond to FITS or TIFF files.");
}
}
示例7: algorithmComplete
/**
* Handles completion of the algorithm.
*
* @param error If the algorithm failed
*/
void ISISDiagnostics::algorithmComplete(bool error) {
disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this,
SLOT(algorithmComplete(bool)));
if (error)
return;
WorkspaceGroup_sptr sliceOutputGroup =
AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>(
"IndirectDiagnostics_Workspaces");
if (sliceOutputGroup->size() == 0) {
g_log.warning("No result workspaces, cannot plot preview.");
return;
}
for (size_t i = 0; i < sliceOutputGroup->size(); i++) {
QString wsName =
QString::fromStdString(sliceOutputGroup->getItem(i)->name());
}
// Enable plot and save buttons
m_uiForm.pbSave->setEnabled(true);
m_uiForm.pbPlot->setEnabled(true);
// Update the preview plots
sliceAlgDone(false);
m_batchAlgoRunner->executeBatchAsync();
}
示例8:
/**
* Groups together a vector of workspaces. This is done "manually", since the
* workspaces being passed will be outside of the ADS and so the GroupWorkspaces
* alg is not an option here.
*
* @param wsList :: the list of workspaces to group
*/
API::WorkspaceGroup_sptr
Load::groupWsList(const std::vector<API::Workspace_sptr> &wsList) {
auto group = boost::make_shared<WorkspaceGroup>();
for (const auto &ws : wsList) {
WorkspaceGroup_sptr isGroup =
boost::dynamic_pointer_cast<WorkspaceGroup>(ws);
// If the ws to add is already a group, then add its children individually.
if (isGroup) {
std::vector<std::string> childrenNames = isGroup->getNames();
size_t count = 1;
for (auto childName = childrenNames.begin();
childName != childrenNames.end(); ++childName, ++count) {
Workspace_sptr childWs = isGroup->getItem(*childName);
isGroup->remove(*childName);
// childWs->setName(isGroup->getName() + "_" +
// boost::lexical_cast<std::string>(count));
group->addWorkspace(childWs);
}
// Remove the old group from the ADS
AnalysisDataService::Instance().remove(isGroup->getName());
} else {
group->addWorkspace(ws);
}
}
return group;
}
示例9: handleAlgorithmComplete
/**
* Handle completion of the algorithm.
*
* @param error If the algorithm failed
*/
void ResNorm::handleAlgorithmComplete(bool error) {
if (error)
return;
QString outputBase = (m_uiForm.dsResolution->getCurrentDataName()).toLower();
const int indexCut = outputBase.lastIndexOf("_");
outputBase = outputBase.left(indexCut);
outputBase += "_ResNorm";
std::string outputBaseStr = outputBase.toStdString();
WorkspaceGroup_sptr fitWorkspaces =
AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>(
outputBaseStr + "_Fit_Workspaces");
QString fitWsName("");
if (fitWorkspaces)
fitWsName =
QString::fromStdString(fitWorkspaces->getItem(m_previewSpec)->name());
// MantidPlot plotting
QString plotOptions(m_uiForm.cbPlot->currentText());
if (plotOptions == "Intensity" || plotOptions == "All")
plotSpectrum(QString::fromStdString(m_pythonExportWsName) + "_Intensity");
if (plotOptions == "Stretch" || plotOptions == "All")
plotSpectrum(QString::fromStdString(m_pythonExportWsName) + "_Stretch");
if (plotOptions == "Fit" || plotOptions == "All")
plotSpectrum(fitWsName, 0, 1);
loadFile(m_uiForm.dsResolution->getFullFilePath(),
m_uiForm.dsResolution->getCurrentDataName());
// Update preview plot
previewSpecChanged(m_previewSpec);
}
示例10: calPlotEnergy
/**
* Replots the energy mini plot
*/
void ISISCalibration::calPlotEnergy()
{
if ( ! m_uiForm.leRunNo->isValid() )
{
emit showMessageBox("Run number not valid.");
return;
}
QString files = m_uiForm.leRunNo->getFilenames().join(",");
QFileInfo fi(m_uiForm.leRunNo->getFirstFilename());
QString detRange = QString::number(m_dblManager->value(m_properties["ResSpecMin"])) + ","
+ QString::number(m_dblManager->value(m_properties["ResSpecMax"]));
IAlgorithm_sptr reductionAlg = AlgorithmManager::Instance().create("ISISIndirectEnergyTransfer");
reductionAlg->initialize();
reductionAlg->setProperty("Instrument", getInstrumentConfiguration()->getInstrumentName().toStdString());
reductionAlg->setProperty("Analyser", getInstrumentConfiguration()->getAnalyserName().toStdString());
reductionAlg->setProperty("Reflection", getInstrumentConfiguration()->getReflectionName().toStdString());
reductionAlg->setProperty("InputFiles", files.toStdString());
reductionAlg->setProperty("OutputWorkspace", "__IndirectCalibration_reduction");
reductionAlg->setProperty("SpectraRange", detRange.toStdString());
reductionAlg->execute();
if(!reductionAlg->isExecuted())
{
g_log.warning("Could not generate energy preview plot.");
return;
}
WorkspaceGroup_sptr reductionOutputGroup = AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>("__IndirectCalibration_reduction");
if(reductionOutputGroup->size() == 0)
{
g_log.warning("No result workspaces, cannot plot energy preview.");
return;
}
MatrixWorkspace_sptr energyWs = boost::dynamic_pointer_cast<MatrixWorkspace>(reductionOutputGroup->getItem(0));
if(!energyWs)
{
g_log.warning("No result workspaces, cannot plot energy preview.");
return;
}
const Mantid::MantidVec & dataX = energyWs->readX(0);
QPair<double, double> range(dataX.front(), dataX.back());
auto resBackground = m_uiForm.ppResolution->getRangeSelector("ResBackground");
setPlotPropertyRange(resBackground, m_properties["ResStart"], m_properties["ResEnd"], range);
m_uiForm.ppResolution->clear();
m_uiForm.ppResolution->addSpectrum("Energy", energyWs, 0);
m_uiForm.ppResolution->resizeX();
calSetDefaultResolution(energyWs);
m_uiForm.ppResolution->replot();
}
示例11: updatePlot
void IqtFit::updatePlot() {
if (!m_ffInputWS) {
g_log.error("No workspace loaded, cannot create preview plot.");
return;
}
int specNo = m_uiForm.spPlotSpectrum->value();
m_uiForm.ppPlot->clear();
m_uiForm.ppPlot->addSpectrum("Sample", m_ffInputWS, specNo);
try {
const QPair<double, double> curveRange =
m_uiForm.ppPlot->getCurveRange("Sample");
const std::pair<double, double> range(curveRange.first, curveRange.second);
m_uiForm.ppPlot->getRangeSelector("FuryFitRange")
->setRange(range.first, range.second);
m_ffRangeManager->setRange(m_properties["StartX"], range.first,
range.second);
m_ffRangeManager->setRange(m_properties["EndX"], range.first, range.second);
setDefaultParameters("Exponential1");
setDefaultParameters("Exponential2");
setDefaultParameters("StretchedExp");
m_uiForm.ppPlot->resizeX();
m_uiForm.ppPlot->setAxisRange(qMakePair(0.0, 1.0), QwtPlot::yLeft);
} catch (std::invalid_argument &exc) {
showMessageBox(exc.what());
}
// If there is a result plot then plot it
if (AnalysisDataService::Instance().doesExist(m_pythonExportWsName)) {
WorkspaceGroup_sptr outputGroup =
AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>(
m_pythonExportWsName);
if (specNo >= static_cast<int>(outputGroup->size()))
return;
MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>(
outputGroup->getItem(specNo));
if (ws) {
if (m_uiForm.ckPlotGuess->isChecked()) {
m_uiForm.ppPlot->removeSpectrum("Guess");
}
m_uiForm.ppPlot->addSpectrum("Fit", ws, 1, Qt::red);
m_uiForm.ppPlot->addSpectrum("Diff", ws, 2, Qt::blue);
}
}
}
示例12: createChildAlgorithm
/**
* Sum transmission workspaces that belong to a workspace group
* @param transGroup : The transmission group containing the transmission runs
* @return :: A workspace pointer containing the sum of transmission workspaces
*/
MatrixWorkspace_sptr ReflectometryReductionOneAuto2::sumTransmissionWorkspaces(
WorkspaceGroup_sptr &transGroup) {
const std::string transSum = "trans_sum";
Workspace_sptr sumWS = transGroup->getItem(0)->clone();
/// For this step to appear in the history of the output workspaces I need to
/// set child to false and work with the ADS
auto plusAlg = createChildAlgorithm("Plus");
plusAlg->setChild(false);
plusAlg->initialize();
for (size_t item = 1; item < transGroup->size(); item++) {
plusAlg->setProperty("LHSWorkspace", sumWS);
plusAlg->setProperty("RHSWorkspace", transGroup->getItem(item));
plusAlg->setProperty("OutputWorkspace", transSum);
plusAlg->execute();
sumWS = AnalysisDataService::Instance().retrieve(transSum);
}
MatrixWorkspace_sptr result =
boost::dynamic_pointer_cast<MatrixWorkspace>(sumWS);
AnalysisDataService::Instance().remove(transSum);
return result;
}
示例13: absCorComplete
/**
* Handles completion of the correction algorithm.
*
* @param error True of the algorithm failed
*/
void CalculatePaalmanPings::absCorComplete(bool error) {
disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this,
SLOT(absCorComplete(bool)));
if (error) {
emit showMessageBox("Absorption correction calculation failed.\nSee "
"Results Log for more details.");
return;
}
// Convert the spectrum axis of correction factors to Q
const auto sampleWsName =
m_uiForm.dsSample->getCurrentDataName().toStdString();
MatrixWorkspace_sptr sampleWs =
AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(sampleWsName);
WorkspaceGroup_sptr corrections =
AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>(
m_pythonExportWsName);
for (size_t i = 0; i < corrections->size(); i++) {
MatrixWorkspace_sptr factorWs =
boost::dynamic_pointer_cast<MatrixWorkspace>(corrections->getItem(i));
if (!factorWs || !sampleWs)
continue;
if (getEMode(sampleWs) == "Indirect") {
API::BatchAlgorithmRunner::AlgorithmRuntimeProps convertSpecProps;
IAlgorithm_sptr convertSpecAlgo =
AlgorithmManager::Instance().create("ConvertSpectrumAxis");
convertSpecAlgo->initialize();
convertSpecAlgo->setProperty("InputWorkspace", factorWs);
convertSpecAlgo->setProperty("OutputWorkspace", factorWs->getName());
convertSpecAlgo->setProperty("Target", "ElasticQ");
convertSpecAlgo->setProperty("EMode", "Indirect");
try {
convertSpecAlgo->setProperty("EFixed", getEFixed(factorWs));
} catch (std::runtime_error &) {
}
m_batchAlgoRunner->addAlgorithm(convertSpecAlgo);
}
}
// Run algorithm queue
connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this,
SLOT(postProcessComplete(bool)));
m_batchAlgoRunner->executeBatchAsync();
}
示例14: getFirstPeriodWS
/**
* Returns a workspace for the first period as specified using FirstPeriod
* property.
* @param group :: Loaded group of workspaces to use
* @return Workspace for the period
*/
MatrixWorkspace_sptr MuonLoad::getFirstPeriodWS(WorkspaceGroup_sptr group) {
int firstPeriod = getProperty("FirstPeriod");
MatrixWorkspace_sptr resultWS;
if (firstPeriod < 0 || firstPeriod >= static_cast<int>(group->size()))
throw std::invalid_argument(
"Workspace doesn't contain specified first period");
resultWS =
boost::dynamic_pointer_cast<MatrixWorkspace>(group->getItem(firstPeriod));
if (!resultWS)
throw std::invalid_argument(
"First period workspace is not a MatrixWorkspace");
return resultWS;
}
示例15: processGroups
/**
* Run instead of exec when operating on groups
*/
bool SaveNXTomo::processGroups() {
try {
std::string name = getPropertyValue("InputWorkspaces");
WorkspaceGroup_sptr groupWS =
AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>(name);
for (int i = 0; i < groupWS->getNumberOfEntries(); ++i) {
m_workspaces.push_back(
boost::dynamic_pointer_cast<Workspace2D>(groupWS->getItem(i)));
}
} catch (...) {
}
if (m_workspaces.size() != 0)
processAll();
return true;
}