Ejemplo n.º 1
0
/** Gets the first extension that the algorithm passed algorithm has in it's
 *  FileProperty (the FileProperty must have the name "Filename"
 *  @param algName :: name of the Mantid save algorithm
 *  @return the first extension, if the algorithm's Filename property has an
 * extension list or ""
 */
QString SaveWorkspaces::getSaveAlgExt(const QString &algName) {
  IAlgorithm_sptr alg =
      AlgorithmManager::Instance().create(algName.toStdString());
  Property *prop = alg->getProperty("Filename");
  FileProperty *fProp = dynamic_cast<FileProperty *>(prop);
  if (fProp) {
    return QString::fromStdString(fProp->getDefaultExt());
  } else { // the algorithm doesn't have a "Filename" file property which may
           // indicate an error later on or maybe OK
    return "";
  }
}
Ejemplo n.º 2
0
/**
* Create a list of file extensions from the given algorithm
* @param algName :: The name of the algorithm
* @param propName :: The name of the property
* @returns A list of file extensions
*/
QStringList
MWRunFiles::getFileExtensionsFromAlgorithm(const QString &algName,
                                           const QString &propName) {
  Mantid::API::IAlgorithm_sptr algorithm =
      Mantid::API::AlgorithmManager::Instance().createUnmanaged(
          algName.toStdString());
  QStringList fileExts;
  if (!algorithm)
    return fileExts;
  algorithm->initialize();
  Property *prop = algorithm->getProperty(propName.toStdString());
  FileProperty *fileProp = dynamic_cast<FileProperty *>(prop);
  MultipleFileProperty *multiFileProp =
      dynamic_cast<MultipleFileProperty *>(prop);

  std::vector<std::string> allowed;
  QString preferredExt;

  if (fileProp) {
    allowed = fileProp->allowedValues();
    preferredExt = QString::fromStdString(fileProp->getDefaultExt());
  } else if (multiFileProp) {
    allowed = multiFileProp->allowedValues();
    preferredExt = QString::fromStdString(multiFileProp->getDefaultExt());
  } else {
    return fileExts;
  }

  std::vector<std::string>::const_iterator iend = allowed.end();
  int index(0);
  for (std::vector<std::string>::const_iterator it = allowed.begin();
       it != iend; ++it) {
    if (!it->empty()) {
      QString ext = QString::fromStdString(*it);
      fileExts.append(ext);
      if (ext == preferredExt) {
        fileExts.move(index, 0);
      }
      ++index;
    }
  }

  return fileExts;
}
Ejemplo n.º 3
0
/**
 * Create a list of files from the given algorithm property.
 */
void FindFilesThread::getFilesFromAlgorithm() {
  Mantid::API::IAlgorithm_sptr algorithm =
      Mantid::API::AlgorithmManager::Instance().createUnmanaged(
          m_algorithm.toStdString());

  if (!algorithm)
    throw std::invalid_argument("Cannot create algorithm " +
                                m_algorithm.toStdString() + ".");

  algorithm->initialize();
  const std::string propName = m_property.toStdString();
  algorithm->setProperty(propName, m_text);

  Property *prop = algorithm->getProperty(propName);
  m_valueForProperty = QString::fromStdString(prop->value());

  FileProperty *fileProp = dynamic_cast<FileProperty *>(prop);
  MultipleFileProperty *multiFileProp =
      dynamic_cast<MultipleFileProperty *>(prop);

  if (fileProp) {
    m_filenames.push_back(fileProp->value());
  } else if (multiFileProp) {
    // This flattens any summed files to a set of single files so that you lose
    // the information about
    // what was summed
    std::vector<std::vector<std::string>> filenames =
        algorithm->getProperty(propName);
    std::vector<std::string> flattenedNames =
        VectorHelper::flattenVector(filenames);

    for (auto filename = flattenedNames.begin();
         filename != flattenedNames.end(); ++filename) {
      m_filenames.push_back(*filename);
    }
  }
}
Ejemplo n.º 4
0
 size_t operator () (const FileProperty& fp) const
 { return std::hash<unsigned long>()(fp.getSize()); }
Ejemplo n.º 5
0
 bool operator () (const FileProperty& fp1, const FileProperty& fp2) const
 { return fp1.getFileExtension() == fp2.getFileExtension(); }
Ejemplo n.º 6
0
 size_t operator () (const FileProperty& fp) const
 { return std::hash<std::string>()(fp.getFileExtension()); }
Ejemplo n.º 7
0
 bool operator () (const FileProperty& fp1, const FileProperty& fp2) const
 { return fp1.getHashC() == fp2.getHashC(); }
Ejemplo n.º 8
0
 bool operator () (const FileProperty& fp1, const FileProperty& fp2) const
 { return (fp1.getHashB() == fp2.getHashB()) &&
             (fp1.getHashA() == fp2.getHashA()) &&
             (fp1.getSize() == fp2.getSize()); }