/** Compares the properties of the input workspace with the reference * @param ws : the testee workspace * @param checkNumberHistograms : whether to check also the number of histograms * @return : empty if compatible, error message otherwises */ std::string RunCombinationHelper::checkCompatibility(MatrixWorkspace_sptr ws, bool checkNumberHistograms) { std::string errors; if (ws->getNumberHistograms() != m_numberSpectra && checkNumberHistograms) errors += "different number of histograms; "; if (ws->getAxis(0)->unit()->unitID() != m_xUnit) errors += "different X units; "; if (ws->getAxis(1)->unit()->unitID() != m_spectrumAxisUnit) errors += "different spectrum axis units; "; if (ws->YUnit() != m_yUnit) errors += "different Y units; "; if (ws->isHistogramData() != m_isHistogramData) errors += "different distribution or histogram type; "; if (ws->detectorInfo().isScanning() != m_isScanning) errors += "a mix of workspaces with and without detector scans; "; if (m_isScanning && ws->detectorInfo().size() != m_numberDetectors) errors += "workspaces with detectors scans have different number of " "detectors; "; if (ws->getInstrument()->getName() != m_instrumentName) errors += "different instrument names; "; if (ws->getNumberHistograms() == m_numberSpectra) { if (!m_hasDx.empty()) { for (unsigned int i = 0; i < m_numberSpectra; ++i) { if (m_hasDx[i] != ws->hasDx(i)) { errors += "spectra must have either Dx values or not; "; break; } } } } return errors; }
/** Checks that the input workspace all exist, that they are the same size, have * the same units * and the same instrument name. Will throw if they don't. * @param inputWorkspaces The names of the input workspaces * @return A list of pointers to the input workspace, ordered by increasing * frame starting point * @throw Exception::NotFoundError If an input workspace doesn't exist * @throw std::invalid_argument If the input workspaces are not compatible */ std::list<API::MatrixWorkspace_sptr> MergeRuns::validateInputs(const std::vector<std::string> &inputWorkspaces) { std::list<MatrixWorkspace_sptr> inWS; std::string xUnitID; std::string YUnit; bool dist(false); // Going to check that name of instrument matches - think that's the best // possible at the moment // because if instrument is created from raw file it'll be a different // object std::string instrument; for (size_t i = 0; i < inputWorkspaces.size(); ++i) { MatrixWorkspace_sptr ws; // Fetch the next input workspace - throw an error if it's not there try { ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>( inputWorkspaces[i]); if (!ws) { g_log.error() << "Input workspace " << inputWorkspaces[i] << " not found.\n"; throw Kernel::Exception::NotFoundError("Data Object", inputWorkspaces[i]); } inWS.push_back(ws); } catch (Exception::NotFoundError &) { g_log.error() << "Input workspace " << inputWorkspaces[i] << " not found.\n"; throw; } // Check that it has common binning if (!WorkspaceHelpers::commonBoundaries(inWS.back())) { g_log.error("Input workspaces must have common binning for all spectra"); throw std::invalid_argument( "Input workspaces must have common binning for all spectra"); } // Check a few things are the same for all input workspaces if (i == 0) { xUnitID = ws->getAxis(0)->unit()->unitID(); YUnit = ws->YUnit(); dist = ws->isDistribution(); instrument = ws->getInstrument()->getName(); } else { testCompatibility(ws, xUnitID, YUnit, dist, instrument); } } // Order the workspaces by ascending frame (X) starting point inWS.sort(compare); return inWS; }
/** Sets the properties of the reference (usually first) workspace, * to later check the compatibility of the others with the reference * @param ref : the reference workspace */ void RunCombinationHelper::setReferenceProperties(MatrixWorkspace_sptr ref) { m_numberSpectra = ref->getNumberHistograms(); m_numberDetectors = ref->detectorInfo().size(); m_xUnit = ref->getAxis(0)->unit()->unitID(); m_spectrumAxisUnit = ref->getAxis(1)->unit()->unitID(); m_yUnit = ref->YUnit(); m_isHistogramData = ref->isHistogramData(); m_isScanning = ref->detectorInfo().isScanning(); m_instrumentName = ref->getInstrument()->getName(); if (m_numberSpectra) { m_hasDx.reserve(m_numberSpectra); for (unsigned int i = 0; i < m_numberSpectra; ++i) m_hasDx.push_back(ref->hasDx(i)); } }