/** * 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; }
// return a workspace with collected events boost::shared_ptr<API::Workspace> ISISLiveEventDataListener::extractData() { if (m_eventBuffer.empty() || !m_eventBuffer[0]) { // extractData() is called too early throw LiveData::Exception::NotYet( "The workspace has not yet been initialized."); } if (!m_isConnected) { // the background thread stopped because of an error. the error message has // been logged at this point throw std::runtime_error("Background thread stopped."); } std::lock_guard<std::mutex> scopedLock(m_mutex); std::vector<DataObjects::EventWorkspace_sptr> outWorkspaces( m_numberOfPeriods); for (size_t i = 0; i < static_cast<size_t>(m_numberOfPeriods); ++i) { // Make a brand new EventWorkspace DataObjects::EventWorkspace_sptr temp = boost::dynamic_pointer_cast<DataObjects::EventWorkspace>( API::WorkspaceFactory::Instance().create( "EventWorkspace", m_eventBuffer[i]->getNumberHistograms(), 2, 1)); // Copy geometry over. API::WorkspaceFactory::Instance().initializeFromParent(m_eventBuffer[i], temp, false); // Clear out the old logs temp->mutableRun().clearTimeSeriesLogs(); // Swap the workspaces std::swap(m_eventBuffer[i], temp); outWorkspaces[i] = temp; } if (m_numberOfPeriods > 1) { // create a workspace group in case the data are multiperiod auto workspaceGroup = API::WorkspaceGroup_sptr(new API::WorkspaceGroup); for (size_t i = 0; i < static_cast<size_t>(m_numberOfPeriods); ++i) { workspaceGroup->addWorkspace(outWorkspaces[i]); } return workspaceGroup; } return outWorkspaces[0]; }
/** * Perform analysis on the given workspace using the parameters supplied * (using the MuonProcess algorithm) * @param inputWS :: [input] Workspace to analyse (previously grouped and * dead-time corrected) * @param options :: [input] Struct containing parameters for what sort of * analysis to do * @returns :: Workspace containing analysed data */ Workspace_sptr MuonAnalysisDataLoader::createAnalysisWorkspace( const Workspace_sptr inputWS, const AnalysisOptions &options) const { IAlgorithm_sptr alg = AlgorithmManager::Instance().createUnmanaged("MuonProcess"); alg->initialize(); // Set input workspace property auto inputGroup = boost::make_shared<WorkspaceGroup>(); // If is a group, will need to handle periods if (auto group = boost::dynamic_pointer_cast<WorkspaceGroup>(inputWS)) { for (int i = 0; i < group->getNumberOfEntries(); i++) { auto ws = boost::dynamic_pointer_cast<MatrixWorkspace>(group->getItem(i)); inputGroup->addWorkspace(ws); } alg->setProperty("SummedPeriodSet", options.summedPeriods); alg->setProperty("SubtractedPeriodSet", options.subtractedPeriods); } else if (auto ws = boost::dynamic_pointer_cast<MatrixWorkspace>(inputWS)) { // Put this single WS into a group and set it as the input property inputGroup->addWorkspace(ws); alg->setProperty("SummedPeriodSet", "1"); } else { throw std::runtime_error( "Cannot create analysis workspace: unsupported workspace type"); } alg->setProperty("InputWorkspace", inputGroup); // Set the rest of the algorithm properties setProcessAlgorithmProperties(alg, options); // We don't want workspace in the ADS so far alg->setChild(true); alg->setPropertyValue("OutputWorkspace", "__NotUsed"); alg->execute(); return alg->getProperty("OutputWorkspace"); }
void PoldiFitPeaks1D::exec() { setPeakFunction(getProperty("PeakFunction")); // Number of points around the peak center to use for the fit m_fwhmMultiples = getProperty("FwhmMultiples"); // try to construct PoldiPeakCollection from provided TableWorkspace TableWorkspace_sptr poldiPeakTable = getProperty("PoldiPeakTable"); m_peaks = getInitializedPeakCollection(poldiPeakTable); g_log.information() << "Peaks to fit: " << m_peaks->peakCount() << '\n'; Workspace2D_sptr dataWorkspace = getProperty("InputWorkspace"); auto fitPlotGroup = boost::make_shared<WorkspaceGroup>(); for (size_t i = 0; i < m_peaks->peakCount(); ++i) { PoldiPeak_sptr currentPeak = m_peaks->peak(i); IFunction_sptr currentProfile = getPeakProfile(currentPeak); IAlgorithm_sptr fit = getFitAlgorithm(dataWorkspace, currentPeak, currentProfile); bool fitSuccess = fit->execute(); if (fitSuccess) { setValuesFromProfileFunction(currentPeak, fit->getProperty("Function")); MatrixWorkspace_sptr fpg = fit->getProperty("OutputWorkspace"); fitPlotGroup->addWorkspace(fpg); } } setProperty("OutputWorkspace", m_peaks->asTableWorkspace()); setProperty("FitPlotsWorkspace", fitPlotGroup); }