/** * Saves the workspace (given the property) as a nexus file to the user's * default directory. * This is then used to publish the workspace (as a file) for ease of use later. * @param workspace :: The workspace to save to a file. */ void CatalogPublish::saveWorkspaceToNexus(Mantid::API::Workspace_sptr &workspace) { // Create the save nexus algorithm to use. auto saveNexus = Mantid::API::AlgorithmManager::Instance().create("SaveNexus"); saveNexus->initialize(); // Set the required properties & execute. saveNexus->setProperty("InputWorkspace", workspace->name()); saveNexus->setProperty("FileName", Mantid::Kernel::ConfigService::Instance().getString( "defaultsave.directory") + workspace->name() + ".nxs"); saveNexus->execute(); }
AlgorithmHistoryWindow::AlgorithmHistoryWindow(QWidget *parent,const Mantid::API::Workspace_sptr wsptr): MantidDialog(parent),m_algHist(wsptr->getHistory().getAlgorithmHistories()),m_histPropWindow(NULL),m_execSumGrpBox(NULL),m_envHistGrpBox(NULL),m_wsName(wsptr->getName().c_str()) { setWindowTitle(tr("Algorithm History")); setMinimumHeight(400); setMinimumWidth(570); setGeometry(50,150,540,380); //Create a tree widget to display the algorithm names in the workspacehistory m_Historytree = new AlgHistoryTreeWidget(this); if(m_Historytree) { m_Historytree->setHeaderLabel("Algorithms"); m_Historytree->setGeometry (5,5,205,200); } //Populate the History Tree widget populateAlgHistoryTreeWidget(); //create a tree widget to dispaly history properties if(!m_histPropWindow) m_histPropWindow=createAlgHistoryPropWindow(); connect(m_Historytree,SIGNAL(updateAlgorithmHistoryWindow(QString, int,int)),this,SLOT(updateAll(QString,int,int))); // The tree and the history details layout QHBoxLayout *treeLayout = new QHBoxLayout; treeLayout->addWidget(m_Historytree,1); // History stretches 1 treeLayout->addWidget(m_histPropWindow->m_histpropTree,2); // Properties gets more space //Create a GroupBox to display exec date,duration if(!m_execSumGrpBox)m_execSumGrpBox=createExecSummaryGrpBox(); //Create a Groupbox to display environment details if(!m_envHistGrpBox)m_envHistGrpBox=createEnvHistGrpBox(wsptr->getHistory().getEnvironmentHistory()); QHBoxLayout *environmentLayout = new QHBoxLayout; environmentLayout->addWidget(m_execSumGrpBox, 1); environmentLayout->addWidget(m_envHistGrpBox, 2); // The button at the bottom m_scriptButton = CreateScriptButton(); if(m_scriptButton==NULL) QMessageBox::critical(this,"Mantid","Generate script Button Creation failed"); QHBoxLayout *buttonLayout = new QHBoxLayout; buttonLayout->addStretch(1); // Align the button to the right buttonLayout->addWidget(m_scriptButton); //Main layout QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->addLayout(treeLayout); mainLayout->addLayout(environmentLayout); mainLayout->addLayout(buttonLayout); }
/** * Generate the history of a given workspace. * @param workspace :: The workspace to obtain the history from. * @return The history of a given workspace. */ const std::string CatalogPublish::generateWorkspaceHistory( Mantid::API::Workspace_sptr &workspace) { auto wsHistory = Mantid::API::AlgorithmManager::Instance().createUnmanaged( "GeneratePythonScript"); wsHistory->initialize(); wsHistory->setProperty("InputWorkspace", workspace->name()); wsHistory->execute(); return wsHistory->getPropertyValue("ScriptText"); }
/** Perform SortEvents on the output workspaces (accumulation or output) * but only if they are EventWorkspaces. This will help the GUI * cope with redrawing. * * @param ws :: any Workspace. Does nothing if not EventWorkspace. */ void LoadLiveData::doSortEvents(Mantid::API::Workspace_sptr ws) { EventWorkspace_sptr eventWS = boost::dynamic_pointer_cast<EventWorkspace>(ws); if (!eventWS) return; CPUTimer tim; Algorithm_sptr alg = this->createChildAlgorithm("SortEvents"); alg->setProperty("InputWorkspace", eventWS); alg->setPropertyValue("SortBy", "X Value"); alg->executeAsChildAlg(); g_log.debug() << tim << " to perform SortEvents on " << ws->name() << '\n'; }
void Load::loadMultipleFiles() { // allFilenames contains "rows" of filenames. If the row has more than 1 file // in it // then that row is to be summed across each file in the row const std::vector<std::vector<std::string>> allFilenames = getProperty("Filename"); std::string outputWsName = getProperty("OutputWorkspace"); std::vector<std::string> wsNames(allFilenames.size()); std::transform(allFilenames.begin(), allFilenames.end(), wsNames.begin(), generateWsNameFromFileNames); auto wsName = wsNames.cbegin(); assert(allFilenames.size() == wsNames.size()); std::vector<API::Workspace_sptr> loadedWsList; loadedWsList.reserve(allFilenames.size()); Workspace_sptr tempWs; // Cycle through the filenames and wsNames. for (auto filenames = allFilenames.cbegin(); filenames != allFilenames.cend(); ++filenames, ++wsName) { auto filename = filenames->cbegin(); Workspace_sptr sumWS = loadFileToWs(*filename, *wsName); ++filename; for (; filename != filenames->cend(); ++filename) { tempWs = loadFileToWs(*filename, "__@loadsum_temp@"); sumWS = plusWs(sumWS, tempWs); } API::WorkspaceGroup_sptr group = boost::dynamic_pointer_cast<WorkspaceGroup>(sumWS); if (group) { std::vector<std::string> childWsNames = group->getNames(); auto childWsName = childWsNames.begin(); size_t count = 1; for (; childWsName != childWsNames.end(); ++childWsName, ++count) { Workspace_sptr childWs = group->getItem(*childWsName); const std::string childName = group->getName() + "_" + std::to_string(count); API::AnalysisDataService::Instance().addOrReplace(childName, childWs); // childWs->setName(group->getName() + "_" + // boost::lexical_cast<std::string>(count)); } } // Add the sum to the list of loaded workspace names. loadedWsList.push_back(sumWS); } // If we only have one loaded ws, set it as the output. if (loadedWsList.size() == 1) { setProperty("OutputWorkspace", loadedWsList[0]); AnalysisDataService::Instance().rename(loadedWsList[0]->getName(), outputWsName); } // Else we have multiple loaded workspaces - group them and set the group as // output. else { API::WorkspaceGroup_sptr group = groupWsList(loadedWsList); setProperty("OutputWorkspace", group); std::vector<std::string> childWsNames = group->getNames(); size_t count = 1; for (auto &childWsName : childWsNames) { if (childWsName == outputWsName) { Mantid::API::Workspace_sptr child = group->getItem(childWsName); // child->setName(child->getName() + "_" + // boost::lexical_cast<std::string>(count)); const std::string childName = child->getName() + "_" + std::to_string(count); API::AnalysisDataService::Instance().addOrReplace(childName, child); count++; } } childWsNames = group->getNames(); count = 1; for (auto &childWsName : childWsNames) { Workspace_sptr childWs = group->getItem(childWsName); std::string outWsPropName = "OutputWorkspace_" + std::to_string(count); ++count; declareProperty(Kernel::make_unique<WorkspaceProperty<Workspace>>( outWsPropName, childWsName, Direction::Output)); setProperty(outWsPropName, childWs); } } // Clean up. if (tempWs) { Algorithm_sptr alg = AlgorithmManager::Instance().createUnmanaged("DeleteWorkspace"); alg->initialize(); alg->setChild(true); alg->setProperty("Workspace", tempWs); alg->execute(); } }
bool WorkspaceSelector::checkEligibility(const QString & name, Mantid::API::Workspace_sptr object) const { if ( m_algorithm && ! m_algPropName.isEmpty() ) { try { m_algorithm->setPropertyValue(m_algPropName.toStdString(), name.toStdString()); } catch ( std::invalid_argument & ) { return false; } } else if ( ( ! m_workspaceTypes.empty() ) && m_workspaceTypes.indexOf(QString::fromStdString(object->id())) == -1 ) { return false; } else if ( ( ! m_showHidden ) && name.startsWith("__") ) { return false; } else if ( ( ! m_suffix.isEmpty() ) && ( ! name.endsWith(m_suffix) ) ) { return false; } return true; }