/** Make a map containing spectra indexes to group, the indexes could have come from * file, or an array, spectra numbers ... * @param workspace :: the user selected input workspace * @param unUsedSpec :: spectra indexes that are not members of any group */ void GroupDetectors2::getGroups(API::MatrixWorkspace_const_sptr workspace, std::vector<int64_t> &unUsedSpec) { // this is the map that we are going to fill m_GroupSpecInds.clear(); // There are several properties that may contain the user data go through them in order of precedence const std::string filename = getProperty("MapFile"); if ( ! filename.empty() ) {// The file property has been set so try to load the file try { // check if XML file and if yes assume it is a XML grouping file std::string filenameCopy(filename); std::transform(filenameCopy.begin(), filenameCopy.end(), filenameCopy.begin(), tolower); if ( (filenameCopy.find(".xml")) != std::string::npos ) { processXMLFile(filename, workspace, unUsedSpec); } else { // the format of this input file format is described in "GroupDetectors2.h" processFile(filename, workspace, unUsedSpec); } } catch ( std::exception & ) { g_log.error() << name() << ": Error reading input file " << filename << std::endl; throw; } return; } const std::vector<specid_t> spectraList = getProperty("SpectraList"); const std::vector<detid_t> detectorList = getProperty("DetectorList"); const std::vector<size_t> indexList = getProperty("WorkspaceIndexList"); // only look at these other parameters if the file wasn't set if ( ! spectraList.empty() ) { workspace->getIndicesFromSpectra( spectraList, m_GroupSpecInds[0]); g_log.debug() << "Converted " << spectraList.size() << " spectra numbers into spectra indices to be combined\n"; } else {// go through the rest of the properties in order of decreasing presidence, abort when we get the data we need ignore the rest if ( ! detectorList.empty() ) { // we are going to group on the basis of detector IDs, convert from detectors to workspace indices workspace->getIndicesFromDetectorIDs( detectorList, m_GroupSpecInds[0]); g_log.debug() << "Found " << m_GroupSpecInds[0].size() << " spectra indices from the list of " << detectorList.size() << " detectors\n"; } else if ( ! indexList.empty() ) { m_GroupSpecInds[0] = indexList; g_log.debug() << "Read in " << m_GroupSpecInds[0].size() << " spectra indices to be combined\n"; } //check we don't have an index that is too high for the workspace size_t maxIn = static_cast<size_t>(workspace->getNumberHistograms() - 1); std::vector<size_t>::const_iterator it = m_GroupSpecInds[0].begin(); for( ; it != m_GroupSpecInds[0].end() ; ++it ) { if ( *it > maxIn ) { g_log.error() << "Spectra index " << *it << " doesn't exist in the input workspace, the highest possible index is " << maxIn << std::endl; throw std::out_of_range("One of the spectra requested to group does not exist in the input workspace"); } } } if ( m_GroupSpecInds[0].empty() ) { g_log.information() << name() << ": File, WorkspaceIndexList, SpectraList, and DetectorList properties are all empty\n"; throw std::invalid_argument("All list properties are empty, nothing to group"); } // up date unUsedSpec, this is used to find duplicates and when the user has set KeepUngroupedSpectra std::vector<size_t>::const_iterator index = m_GroupSpecInds[0].begin(); for ( ; index != m_GroupSpecInds[0].end(); ++index ) {// the vector<int> m_GroupSpecInds[0] must not index contain numbers that don't exist in the workspaace if ( unUsedSpec[*index] != USED ) { unUsedSpec[*index] = USED; } else g_log.warning() << "Duplicate index, " << *index << ", found\n"; } }
QScriptValue File::removePrivate(const QString &filename, bool noErrorDialog, bool noConfirmDialog, bool noProgressDialog, bool allowUndo, QScriptContext *context, QScriptEngine *engine) { #ifdef Q_OS_LINUX Q_UNUSED(noErrorDialog) Q_UNUSED(noConfirmDialog) Q_UNUSED(noProgressDialog) Q_UNUSED(allowUndo) QString filenameCopy(filename); filenameCopy.replace(" ", "\\ "); QString command = "sh -c \"rm -fr"; command += " "; command += QFile::encodeName(filenameCopy); command += "\""; if(QProcess::execute(command)) { throwError(context, engine, "RemoveError", tr("Remove failed")); return context->thisObject(); } #endif #ifdef Q_OS_WIN QDir filenameDir(filename); std::wstring wideFilename = QDir::toNativeSeparators(filenameDir.absolutePath()).toStdWString(); wideFilename += L'\0'; SHFILEOPSTRUCT shFileOpStruct; shFileOpStruct.hwnd = 0; shFileOpStruct.wFunc = FO_DELETE; shFileOpStruct.pFrom = wideFilename.c_str(); shFileOpStruct.pTo = 0; shFileOpStruct.fFlags = 0; shFileOpStruct.fAnyOperationsAborted = false; shFileOpStruct.lpszProgressTitle = 0; shFileOpStruct.hNameMappings = 0; if(noErrorDialog) shFileOpStruct.fFlags |= FOF_NOERRORUI; if(noConfirmDialog) shFileOpStruct.fFlags |= (FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR); if(noProgressDialog) shFileOpStruct.fFlags |= FOF_SILENT; if(allowUndo) shFileOpStruct.fFlags |= FOF_ALLOWUNDO; int result = SHFileOperation(&shFileOpStruct); if(result != 0) { throwError(context, engine, "RemoveError", tr("Remove failed: %1").arg(getErrorString(result))); return context->thisObject(); } if(shFileOpStruct.fAnyOperationsAborted) { throwError(context, engine, "RemoveAbortedError", tr("Remove failed: aborted")); return context->thisObject(); } #endif return context->thisObject(); }