Esempio n. 1
0
 /**
  * Collect all input workspace property names in the m_workspacePropertyNames vector
  */
 void Fit::addWorkspaces()
 {
   setDomainType();
   auto multiFun = boost::dynamic_pointer_cast<API::MultiDomainFunction>(m_function);
   if (multiFun)
   {
     m_domainCreator.reset(new MultiDomainCreator(this,m_workspacePropertyNames));
   }
   auto props = getProperties();
   for(auto prop = props.begin(); prop != props.end(); ++prop)
   {
     if ((**prop).direction() == Kernel::Direction::Input && dynamic_cast<API::IWorkspaceProperty*>(*prop))
     {
       const std::string workspacePropertyName = (**prop).name();
       API::Workspace_const_sptr ws = getProperty(workspacePropertyName);
       IDomainCreator* creator = NULL;
       if ( boost::dynamic_pointer_cast<const API::MatrixWorkspace>(ws) &&
           !boost::dynamic_pointer_cast<API::IFunctionMD>(m_function) )
       {
         /* IFunction1DSpectrum needs a different domain creator. If a function
          * implements that type, we need to react appropriately at this point.
          * Otherwise, the default creator FitMW is used.
          */
         if(boost::dynamic_pointer_cast<API::IFunction1DSpectrum>(m_function)) {
           creator = new SeqDomainSpectrumCreator(this, workspacePropertyName);
         } else {
           creator = new FitMW(this, workspacePropertyName, m_domainType);
         }
       }
       else
       {// don't know what to do with this workspace
         try
         {
           creator = API::DomainCreatorFactory::Instance().createDomainCreator("FitMD",this, workspacePropertyName, m_domainType);
         }
         catch(Kernel::Exception::NotFoundError&)
         {
           throw std::invalid_argument("Unsupported workspace type" + ws->id());
         }
       }
       const size_t n = std::string("InputWorkspace").size();
       const std::string suffix = (workspacePropertyName.size() > n)? workspacePropertyName.substr(n) : "";
       const size_t index = suffix.empty() ? 0 : boost::lexical_cast<size_t>(suffix.substr(1));
       creator->declareDatasetProperties(suffix,false);
       m_workspacePropertyNames.push_back(workspacePropertyName);
       if (!m_domainCreator)
       {
         m_domainCreator.reset(creator);
       }
       auto multiCreator = boost::dynamic_pointer_cast<MultiDomainCreator>(m_domainCreator);
       if (multiCreator)
       {
         multiCreator->setCreator(index,creator);
       }
     }
   }
 }
/**
 * Add a new workspace to the fit. The workspace is in the property named
 * workspacePropertyName.
 * @param workspacePropertyName :: A workspace property name (eg InputWorkspace
 *   or InputWorkspace_2). The property must already exist in the algorithm.
 * @param addProperties :: allow for declaration of properties that specify the
 *   dataset within the workspace to fit to.
 */
void IFittingAlgorithm::addWorkspace(const std::string &workspacePropertyName,
                                     bool addProperties) {
  // get the workspace
  API::Workspace_const_sptr ws = getProperty(workspacePropertyName);
  // m_function->setWorkspace(ws);
  const size_t n = std::string("InputWorkspace").size();
  const std::string suffix =
      (workspacePropertyName.size() > n) ? workspacePropertyName.substr(n) : "";
  const size_t index =
      suffix.empty() ? 0 : boost::lexical_cast<size_t>(suffix.substr(1));

  IFunction_sptr fun = getProperty("Function");
  setDomainType();

  IDomainCreator *creator = createDomainCreator(
      fun.get(), ws.get(), workspacePropertyName, this, m_domainType);

  if (!m_domainCreator) {
    if (m_workspacePropertyNames.empty()) {
      // this defines the function and fills in m_workspacePropertyNames with
      // names of the sort InputWorkspace_#
      setFunction();
    }
    auto multiFun = boost::dynamic_pointer_cast<API::MultiDomainFunction>(fun);
    if (multiFun) {
      auto multiCreator =
          new MultiDomainCreator(this, m_workspacePropertyNames);
      multiCreator->setCreator(index, creator);
      m_domainCreator.reset(multiCreator);
      creator->declareDatasetProperties(suffix, addProperties);
    } else {
      m_domainCreator.reset(creator);
      creator->declareDatasetProperties(suffix, addProperties);
    }
  } else {
    boost::shared_ptr<MultiDomainCreator> multiCreator =
        boost::dynamic_pointer_cast<MultiDomainCreator>(m_domainCreator);
    if (!multiCreator) {
      auto &reference = *m_domainCreator.get();
      throw std::runtime_error(
          std::string("MultiDomainCreator expected, found ") +
          typeid(reference).name());
    }
    if (!multiCreator->hasCreator(index)) {
      creator->declareDatasetProperties(suffix, addProperties);
    }
    multiCreator->setCreator(index, creator);
  }
}
/**
 * Collect all input workspace property names in the m_workspacePropertyNames
 * vector.
 */
void IFittingAlgorithm::addWorkspaces() {
  setDomainType();
  auto multiFun =
      boost::dynamic_pointer_cast<API::MultiDomainFunction>(m_function);
  if (multiFun) {
    m_domainCreator.reset(
        new MultiDomainCreator(this, m_workspacePropertyNames));
  }
  auto props = getProperties();
  for (auto &prop : props) {
    if ((*prop).direction() == Kernel::Direction::Input &&
        dynamic_cast<API::IWorkspaceProperty *>(prop)) {
      const std::string workspacePropertyName = (*prop).name();
      API::Workspace_const_sptr ws = getProperty(workspacePropertyName);
      IDomainCreator *creator =
          createDomainCreator(m_function.get(), ws.get(), workspacePropertyName,
                              this, m_domainType);

      const size_t n = std::string("InputWorkspace").size();
      const std::string suffix = (workspacePropertyName.size() > n)
                                     ? workspacePropertyName.substr(n)
                                     : "";
      const size_t index =
          suffix.empty() ? 0 : boost::lexical_cast<size_t>(suffix.substr(1));
      creator->declareDatasetProperties(suffix, false);
      m_workspacePropertyNames.push_back(workspacePropertyName);
      if (!m_domainCreator) {
        m_domainCreator.reset(creator);
      }
      auto multiCreator =
          boost::dynamic_pointer_cast<MultiDomainCreator>(m_domainCreator);
      if (multiCreator) {
        multiCreator->setCreator(index, creator);
      }
    }
  }
}
Esempio n. 4
0
  /**
   * Add a new workspace to the fit. The workspace is in the property named workspacePropertyName
   * @param workspacePropertyName :: A workspace property name (eg InputWorkspace or InputWorkspace_2).
   *  The property must already exist in the algorithm.
   * @param addProperties :: allow for declaration of properties that specify the dataset
   *  within the workspace to fit to.
   */
  void Fit::addWorkspace(const std::string& workspacePropertyName, bool addProperties)
  {
    // get the workspace 
    API::Workspace_const_sptr ws = getProperty(workspacePropertyName);
    //m_function->setWorkspace(ws);
    const size_t n = std::string("InputWorkspace").size();
    const std::string suffix = (workspacePropertyName.size() > n)? workspacePropertyName.substr(n) : "";
    const size_t index = suffix.empty() ? 0 : boost::lexical_cast<size_t>(suffix.substr(1));

    API::IFunction_sptr fun = getProperty("Function");
    IDomainCreator* creator = NULL;
    setDomainType();

    if ( boost::dynamic_pointer_cast<const API::MatrixWorkspace>(ws) &&
        !boost::dynamic_pointer_cast<API::IFunctionMD>(fun) )
    {
      /* IFunction1DSpectrum needs a different domain creator. If a function
       * implements that type, we need to react appropriately at this point.
       * Otherwise, the default creator FitMW is used.
       */
      if(boost::dynamic_pointer_cast<API::IFunction1DSpectrum>(fun)) {
        creator = new SeqDomainSpectrumCreator(this, workspacePropertyName);
      } else {
        creator = new FitMW(this, workspacePropertyName, m_domainType);
      }
    }
    else
    {
      try
      {
        creator = API::DomainCreatorFactory::Instance().createDomainCreator("FitMD", this, workspacePropertyName, m_domainType);
      }
      catch(Kernel::Exception::NotFoundError&)
      {
        throw std::invalid_argument("Unsupported workspace type" + ws->id());
      }
    }

    if (!m_domainCreator)
    {
      if (m_workspacePropertyNames.empty())
      {
        // this defines the function and fills in m_workspacePropertyNames with names of the sort InputWorkspace_#
        setFunction();
      }
      auto multiFun = boost::dynamic_pointer_cast<API::MultiDomainFunction>(fun);
      if (multiFun)
      {
        auto multiCreator = new MultiDomainCreator(this,m_workspacePropertyNames);
        multiCreator->setCreator(index,creator);
        m_domainCreator.reset(multiCreator);
        creator->declareDatasetProperties(suffix,addProperties);
      }
      else
      {
        m_domainCreator.reset(creator);
        creator->declareDatasetProperties(suffix,addProperties);
      }
    }
    else
    {
      boost::shared_ptr<MultiDomainCreator> multiCreator = boost::dynamic_pointer_cast<MultiDomainCreator>(m_domainCreator);
      if (!multiCreator)
      {
        throw std::runtime_error(std::string("MultiDomainCreator expected, found ") + typeid(*m_domainCreator.get()).name());
      }
      if (!multiCreator->hasCreator(index))
      {
        creator->declareDatasetProperties(suffix,addProperties);
      }
      multiCreator->setCreator(index,creator);
    }

  }