/** * Declare any additional properties of the concrete loader here * @param loader A pointer to the concrete loader */ void Load::declareLoaderProperties(const API::IAlgorithm_sptr &loader) { // If we have switch loaders then the concrete loader will have different // properties // so take care of ensuring Load has the correct ones // THIS IS A COPY as the properties are mutated as we move through them const std::vector<Property *> existingProps = this->getProperties(); for (auto existingProp : existingProps) { const std::string &name = existingProp->name(); // Wipe all properties except the Load native ones if (m_baseProps.find(name) == m_baseProps.end()) { this->removeProperty(name); } } const std::vector<Property *> &loaderProps = loader->getProperties(); size_t numProps(loaderProps.size()); for (size_t i = 0; i < numProps; ++i) { Property *loadProp = loaderProps[i]; if (loadProp->name() == m_filenamePropName) continue; try { auto propClone = std::unique_ptr<Property>(loadProp->clone()); propClone->clearSettings(); // Get rid of special settings because it // does not work in custom GUI. declareProperty(std::move(propClone), loadProp->documentation()); } catch (Exception::ExistsError &) { // Already exists as a static property continue; } } }
/** Handler of the start notifications. Adds an algorithm call to the script. * @param alg :: Shared pointer to the starting algorithm. */ void RecordPythonScript::startingHandle(API::IAlgorithm_sptr alg) { auto props= alg->getProperties(); std::string algString; for(auto p = props.begin() ; p != props.end(); ++p) { std::string opener = "='"; if ((**p).value().find('\\') != std::string::npos ) { opener= "=r'"; } std::string paramString = (**p).name() + opener + (**p).value() + "'"; // Miss out parameters that are empty. if(paramString.length() != 0) { if(algString.length() != 0) { algString += ","; } algString += paramString; } } m_generatedScript += alg->name() + "(" + algString + ")\n"; }
std::string FrameworkManagerProxy::createAlgorithmDocs(const std::string& algName, const int version) { const std::string EOL="\n"; API::IAlgorithm_sptr algm = API::AlgorithmManager::Instance().createUnmanaged(algName, version); algm->initialize(); // Put in the quick overview message std::stringstream buffer; std::string temp = algm->getOptionalMessage(); if (temp.size() > 0) buffer << temp << EOL << EOL; // get a sorted copy of the properties PropertyVector properties(algm->getProperties()); std::sort(properties.begin(), properties.end(), PropertyOrdering()); // generate the sanitized names StringVector names(properties.size()); size_t numProps = properties.size(); for ( size_t i = 0; i < numProps; ++i) { names[i] = removeCharacters(properties[i]->name(), ""); } buffer << "Property descriptions: " << EOL << EOL; // write the actual property descriptions Mantid::Kernel::Property *prop; for ( size_t i = 0; i < numProps; ++i) { prop = properties[i]; buffer << names[i] << "(" << Mantid::Kernel::Direction::asText(prop->direction()); if (!prop->isValid().empty()) buffer << ":req"; buffer << ") *" << prop->type() << "* "; std::set<std::string> allowed = prop->allowedValues(); if (!prop->documentation().empty() || !allowed.empty()) { buffer << " " << prop->documentation(); if (!allowed.empty()) { buffer << " [" << Kernel::Strings::join(allowed.begin(), allowed.end(), ", "); buffer << "]"; } buffer << EOL; if( i < numProps - 1 ) buffer << EOL; } } return buffer.str(); }
/** * Set the output workspace(s) if the load's return workspace has type * API::Workspace * @param loader :: Shared pointer to load algorithm */ void Load::setOutputWorkspace(const API::IAlgorithm_sptr &loader) { // Go through each OutputWorkspace property and check whether we need to make // a counterpart here const std::vector<Property *> &loaderProps = loader->getProperties(); const size_t count = loader->propertyCount(); for (size_t i = 0; i < count; ++i) { Property *prop = loaderProps[i]; if (dynamic_cast<IWorkspaceProperty *>(prop) && prop->direction() == Direction::Output) { const std::string &name = prop->name(); if (!this->existsProperty(name)) { declareProperty(Kernel::make_unique<WorkspaceProperty<Workspace>>( name, loader->getPropertyValue(name), Direction::Output)); } Workspace_sptr wkspace = getOutputWorkspace(name, loader); setProperty(name, wkspace); } } }
void Load::findFilenameProperty(const API::IAlgorithm_sptr &loader) { // Use the first file property as the main Filename const auto &props = loader->getProperties(); for (auto prop : props) { auto *fp = dynamic_cast<API::MultipleFileProperty *>(prop); auto *fp2 = dynamic_cast<API::FileProperty *>(prop); if (fp) { m_filenamePropName = fp->name(); break; } if (fp2) { m_filenamePropName = fp2->name(); break; } } if (m_filenamePropName.empty()) { setPropertyValue("LoaderName", ""); setProperty("LoaderVersion", -1); throw std::runtime_error("Cannot find FileProperty on " + loader->name() + " algorithm."); } }
/** * Set the loader option for use as a Child Algorithm. * @param loader :: Concrete loader * @param startProgress :: The start progress fraction * @param endProgress :: The end progress fraction * @param logging:: If true, enable logging */ void Load::setUpLoader(API::IAlgorithm_sptr &loader, const double startProgress, const double endProgress, const bool logging) const { // Set as a child so that we are in control of output storage loader->setChild(true); loader->setLogging(logging); // If output workspaces are nameless, give them a temporary name to satisfy // validator const std::vector<Property *> &props = loader->getProperties(); for (auto prop : props) { auto wsProp = dynamic_cast<IWorkspaceProperty *>(prop); if (wsProp && !wsProp->isOptional() && prop->direction() == Direction::Output) { if (prop->value().empty()) prop->setValue("LoadChildWorkspace"); } } if (startProgress >= 0. && endProgress > startProgress && endProgress <= 1.) { loader->addObserver(this->progressObserver()); setChildStartProgress(startProgress); setChildEndProgress(endProgress); } }