void MantidWSIndexDialog::generateSpectraIdIntervals() { // Get the list of available intervals for each of the workspaces, and then // present the user with intervals which are the INTERSECTION of each of // those lists of intervals. QList<QString>::const_iterator it = m_wsNames.constBegin(); // Cycle through the workspaces ... for ( ; it != m_wsNames.constEnd(); ++it ) { Mantid::API::MatrixWorkspace_const_sptr ws = boost::dynamic_pointer_cast<const Mantid::API::MatrixWorkspace>(Mantid::API::AnalysisDataService::Instance().retrieve((*it).toStdString())); if ( NULL == ws ) continue; Mantid::spec2index_map * spec2index = ws->getSpectrumToWorkspaceIndexMap(); Mantid::spec2index_map::const_iterator last = spec2index->end(); --last; Mantid::spec2index_map::const_iterator first = spec2index->begin(); const int startSpectrum = static_cast<int> (first->first); const int endSpectrum = static_cast<int> (last->first); const int size = static_cast<int> (spec2index->size()); if(size == (1 + endSpectrum - startSpectrum)) { // Here we make the assumption (?) that the spectra IDs are sorted, and so // are a list of ints from startSpectrum to endSpectrum without any gaps. Interval interval(startSpectrum, endSpectrum); if(it == m_wsNames.constBegin()) m_spectraIdIntervals.addInterval(interval); else m_spectraIdIntervals.setIntervalList(IntervalList::intersect(m_spectraIdIntervals,interval)); } else { // The spectra IDs do not appear to be an uninterrupted list of numbers, // and so we must go through each one and construct the intervals that way. // TODO - is this at all feasible for large workspaces, and/or many workspaces? ++last; for ( ; first != last; ++first) { const int spectraId = static_cast<int> (first->first); Interval interval(spectraId); if(it == m_wsNames.constBegin()) m_spectraIdIntervals.addInterval(interval); else m_spectraIdIntervals.setIntervalList(IntervalList::intersect(m_spectraIdIntervals,interval)); } } } }
QMultiMap<QString,std::set<int> > MantidWSIndexDialog::getPlots() const { // Map of workspace names to set of indices to be plotted. QMultiMap<QString,std::set<int> > plots; // If the user typed in the wsField ... if(m_wsIndexChoice.getList().size() > 0) { for(int i = 0; i < m_wsNames.size(); i++) { std::set<int> intSet = m_wsIndexChoice.getIntSet(); plots.insert(m_wsNames[i],intSet); } } // Else if the user typed in the spectraField ... else if(m_spectraIdChoice.getList().size() > 0) { for(int i = 0; i < m_wsNames.size(); i++) { // Convert the spectra choices of the user into workspace indices for us to use. Mantid::API::MatrixWorkspace_const_sptr ws = boost::dynamic_pointer_cast<const Mantid::API::MatrixWorkspace>(Mantid::API::AnalysisDataService::Instance().retrieve(m_wsNames[i].toStdString())); if ( NULL == ws ) continue; Mantid::spec2index_map *spec2index = ws->getSpectrumToWorkspaceIndexMap(); std::set<int> origSet = m_spectraIdChoice.getIntSet(); std::set<int>::iterator it = origSet.begin(); std::set<int> convertedSet; for( ; it != origSet.end(); ++it) { int origInt = (*it); int convertedInt = static_cast<int>(spec2index->find(origInt)->second); convertedSet.insert(convertedInt); } plots.insert(m_wsNames[i],convertedSet); } } return plots; }