当前位置: 首页>>代码示例>>C++>>正文


C++ Algorithm_sptr类代码示例

本文整理汇总了C++中Algorithm_sptr的典型用法代码示例。如果您正苦于以下问题:C++ Algorithm_sptr类的具体用法?C++ Algorithm_sptr怎么用?C++ Algorithm_sptr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Algorithm_sptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getCropAlgorithmForWorkspace

/** Returns a cropped workspace with data equal to and above the specified x limit
 *
 *  @param workspace :: MatrixWorkspace
 *  @param x :: Minimum allowed x-value in the data.
 *  @return MatrixWorkspace cropped to values with x >= specified limit.
 */
MatrixWorkspace_sptr PoldiTruncateData::getWorkspaceAboveX(MatrixWorkspace_sptr workspace, double x)
{
    Algorithm_sptr crop = getCropAlgorithmForWorkspace(workspace);
    crop->setProperty("Xmin", x);

    return getOutputWorkspace(crop);
}
开发者ID:BigShows,项目名称:mantid,代码行数:13,代码来源:PoldiTruncateData.cpp

示例2: createSubAlgorithm

/** Sum all detector pixels except monitors and masked detectors
 *  @param WS ::    The workspace containing the spectrum to sum
 *  @return A Workspace2D containing the sum
 */
API::MatrixWorkspace_sptr CalculateTransmissionBeamSpreader::sumSpectra(API::MatrixWorkspace_sptr WS)
{
  Algorithm_sptr childAlg = createSubAlgorithm("SumSpectra");
  childAlg->setProperty<MatrixWorkspace_sptr>("InputWorkspace", WS);
  childAlg->setProperty<bool>("IncludeMonitors", false);
  childAlg->executeAsSubAlg();
  return childAlg->getProperty("OutputWorkspace");
}
开发者ID:,项目名称:,代码行数:12,代码来源:

示例3: getOutputWorkspace

/** Extracts OutputWorkspace property from supplied algorithm is present.
 *
 *  This methods executes the given algorithm and tries to extract the output workspace.
 *
 *  @param algorithm :: Pointer to algorithm.
 *  @return MatrixWorkspace stored in algorithm's OutputWorkspace property.
 */
MatrixWorkspace_sptr PoldiTruncateData::getOutputWorkspace(Algorithm_sptr algorithm)
{
    if(!algorithm || !algorithm->execute()) {
        throw std::runtime_error("Workspace could not be retrieved successfully.");
    }

    MatrixWorkspace_sptr outputWorkspace = algorithm->getProperty("OutputWorkspace");
    return outputWorkspace;
}
开发者ID:BigShows,项目名称:mantid,代码行数:16,代码来源:PoldiTruncateData.cpp

示例4: doSortEvents

/** Perform SortEvents on the output workspaces
 * but only if they are EventWorkspaces.
 *
 * @param ws :: any Workspace. Does nothing if not EventWorkspace.
 */
void AlignAndFocusPowder::doSortEvents(Mantid::API::Workspace_sptr ws) {
  EventWorkspace_sptr eventWS = boost::dynamic_pointer_cast<EventWorkspace>(ws);
  if (!eventWS)
    return;
  Algorithm_sptr alg = this->createChildAlgorithm("SortEvents");
  alg->setProperty("InputWorkspace", eventWS);
  alg->setPropertyValue("SortBy", "X Value");
  alg->executeAsChildAlg();
}
开发者ID:rosswhitfield,项目名称:mantid,代码行数:14,代码来源:AlignAndFocusPowder.cpp

示例5: processGroups

/** Process WorkspaceGroup inputs.
 *
 * Overriden from Algorithm base class.
 *
 * This should be called after checkGroups(), which sets up required members.
 * It goes through each member of the group(s), creates and sets an algorithm
 * for each and executes them one by one.
 *
 * If there are several group input workspaces, then the member of each group
 * is executed pair-wise.
 *
 * @param sourceAlg : Source algorithm
 * @param vecMultiPeriodGroups : Vector of pre-identified multiperiod groups.
 * @return true - if all the workspace members are executed.
 */
bool MultiPeriodGroupWorker::processGroups(
    Algorithm *const sourceAlg,
    const VecWSGroupType &vecMultiPeriodGroups) const {
  // If we are not processing multiperiod groups, use the base behaviour.
  if (vecMultiPeriodGroups.empty()) {
    return false; // Indicates that this is not a multiperiod group workspace.
  }
  Property *outputWorkspaceProperty = sourceAlg->getProperty("OutputWorkspace");
  const std::string outName = outputWorkspaceProperty->value();

  const size_t nPeriods = vecMultiPeriodGroups[0]->size();
  WorkspaceGroup_sptr outputWS = boost::make_shared<WorkspaceGroup>();
  AnalysisDataService::Instance().addOrReplace(outName, outputWS);

  double progress_proportion = 1.0 / static_cast<double>(nPeriods);
  // Loop through all the periods. Create spawned algorithms of the same type as
  // this to process pairs from the input groups.
  for (size_t i = 0; i < nPeriods; ++i) {
    const int periodNumber = static_cast<int>(i + 1);
    // use create Child Algorithm that look like this one
    Algorithm_sptr alg = sourceAlg->createChildAlgorithm(
        sourceAlg->name(), progress_proportion * periodNumber,
        progress_proportion * (1 + periodNumber), sourceAlg->isLogging(),
        sourceAlg->version());
    if (!alg) {
      throw std::runtime_error("Algorithm creation failed.");
    }
    // Don't make the new algorithm a child so that it's workspaces are stored
    // correctly
    alg->setChild(false);
    alg->setRethrows(true);
    alg->initialize();
    // Copy properties that aren't workspaces properties.
    sourceAlg->copyNonWorkspaceProperties(alg.get(), periodNumber);

    if (this->useCustomWorkspaceProperty()) {
      const std::string inputWorkspaces =
          createFormattedInputWorkspaceNames(i, vecMultiPeriodGroups);
      // Set the input workspace property.
      alg->setPropertyValue(this->m_workspacePropertyName, inputWorkspaces);
    } else {
      // Configure input properties that are group workspaces.
      copyInputWorkspaceProperties(alg.get(), sourceAlg, periodNumber);
    }
    const std::string outName_i = outName + "_" + Strings::toString(i + 1);
    alg->setPropertyValue("OutputWorkspace", outName_i);
    // Run the spawned algorithm.
    if (!alg->execute()) {
      throw std::runtime_error("Execution of " + sourceAlg->name() +
                               " for group entry " + Strings::toString(i + 1) +
                               " failed.");
    }
    // Add the output workpace from the spawned algorithm to the group.
    outputWS->add(outName_i);
  }

  sourceAlg->setProperty("OutputWorkspace", outputWS);

  return true;
}
开发者ID:mantidproject,项目名称:mantid,代码行数:75,代码来源:MultiPeriodGroupWorker.cpp

示例6: getPropertyValue

  /** Execute the algorithm.
   */
  void OneStepMDEW::exec()
  {
    std::string tempWsName = getPropertyValue("OutputWorkspace") + "_nxs";

    Algorithm_sptr childAlg;

    // -------- First we load the event nexus file -------------
    childAlg = AlgorithmFactory::Instance().create("LoadEventNexus", 1); // new Mantid::NeXus::LoadEventNexus();
    childAlg->initialize();
    childAlg->setPropertyValue("Filename", getPropertyValue("Filename"));
    childAlg->setPropertyValue("OutputWorkspace", tempWsName);
    childAlg->executeAsSubAlg();

//    Workspace_sptr tempWS = childAlg->getProperty<Workspace>("OutputWorkspace");
//    IEventWorkspace_sptr tempEventWS = boost::dynamic_pointer_cast<IEventWorkspace>(AnalysisDataService::Instance().retrieve(tempWsName));
    //    IEventWorkspace_sptr tempEventWS = boost::dynamic_pointer_cast<IEventWorkspace>(AnalysisDataService::Instance().retrieve(tempWsName));


    // --------- Now Convert -------------------------------
    //childAlg = createSubAlgorithm("ConvertToDiffractionMDWorkspace");
    childAlg = AlgorithmFactory::Instance().create("ConvertToDiffractionMDWorkspace", 1);  // new ConvertToDiffractionMDWorkspace();
    childAlg->initialize();
    childAlg->setPropertyValue("InputWorkspace", tempWsName);
    childAlg->setProperty<bool>("ClearInputWorkspace", false);
    childAlg->setProperty<bool>("LorentzCorrection", true);
    childAlg->setPropertyValue("OutputWorkspace", getPropertyValue("OutputWorkspace"));
    childAlg->executeAsSubAlg();

//    Workspace_sptr tempWS = childAlg->getProperty("OutputWorkspace");
//    IMDEventWorkspace_sptr outWS = boost::dynamic_pointer_cast<IMDEventWorkspace>(tempWS);
    IMDEventWorkspace_sptr outWS = boost::dynamic_pointer_cast<IMDEventWorkspace>(
        AnalysisDataService::Instance().retrieve(getPropertyValue("OutputWorkspace")));

    setProperty<Workspace_sptr>("OutputWorkspace", outWS);
  }
开发者ID:,项目名称:,代码行数:37,代码来源:

示例7: doSortEvents

/** Perform SortEvents on the output workspaces (accumulation or output)
 * but only if they are EventWorkspaces. This will help the GUI
 * cope with redrawing.
 *
 * @param ws :: any Workspace. Does nothing if not EventWorkspace.
 */
void LoadLiveData::doSortEvents(Mantid::API::Workspace_sptr ws) {
  EventWorkspace_sptr eventWS = boost::dynamic_pointer_cast<EventWorkspace>(ws);
  if (!eventWS)
    return;
  CPUTimer tim;
  Algorithm_sptr alg = this->createChildAlgorithm("SortEvents");
  alg->setProperty("InputWorkspace", eventWS);
  alg->setPropertyValue("SortBy", "X Value");
  alg->executeAsChildAlg();
  g_log.debug() << tim << " to perform SortEvents on " << ws->name() << '\n';
}
开发者ID:rosswhitfield,项目名称:mantid,代码行数:17,代码来源:LoadLiveData.cpp

示例8: createChildAlgorithm

/** Returns a MatrixWorkspace with all spectrum summed up.
 *
 *  The summation is done with the SumSpectra-algorithm.
 *
 *  @param workspace :: MatrixWorkspace
 *  @return MatrixWorkspace with one spectrum which contains all counts.
 */
MatrixWorkspace_sptr
PoldiTruncateData::getSummedSpectra(MatrixWorkspace_sptr workspace) {
  Algorithm_sptr sumSpectra = createChildAlgorithm("SumSpectra");

  if (!sumSpectra) {
    throw std::runtime_error("Could not create SumSpectra algorithm.");
  }

  sumSpectra->setProperty("InputWorkspace", workspace);

  return getOutputWorkspace(sumSpectra);
}
开发者ID:mantidproject,项目名称:mantid,代码行数:19,代码来源:PoldiTruncateData.cpp

示例9: getFullPathParamIDF

//-----------------------------------------------------------------------------------------------------------------------
/// Run the Child Algorithm LoadInstrument (or LoadInstrumentFromRaw)
void LoadInstrument::runLoadParameterFile() {
  g_log.debug("Loading the parameter definition...");

  // First search for XML parameter file in same folder as IDF file
  const std::string::size_type dir_end = m_filename.find_last_of("\\/");
  std::string directoryName =
      m_filename.substr(0, dir_end + 1); // include final '/'.
  std::string fullPathParamIDF = getFullPathParamIDF(directoryName);

  if (fullPathParamIDF.empty()) {
    // Not found, so search the other places were it may occur
    Kernel::ConfigServiceImpl &configService =
        Kernel::ConfigService::Instance();
    std::vector<std::string> directoryNames =
        configService.getInstrumentDirectories();

    for (auto directoryName : directoryNames) {
      // This will iterate around the directories from user ->etc ->install, and
      // find the first beat file
      fullPathParamIDF = getFullPathParamIDF(directoryName);
      // stop when you find the first one
      if (!fullPathParamIDF.empty())
        break;
    }
  }

  if (!fullPathParamIDF.empty()) {

    g_log.debug() << "Parameter file: " << fullPathParamIDF << std::endl;
    // Now execute the Child Algorithm. Catch and log any error, but don't stop.
    try {
      // To allow the use of ExperimentInfo instead of workspace, we call it
      // manually
      Algorithm_sptr loadParamAlg = createChildAlgorithm("LoadParameterFile");
      loadParamAlg->setProperty("Filename", fullPathParamIDF);
      loadParamAlg->setProperty("Workspace", m_workspace);
      loadParamAlg->execute();
      g_log.debug("Parameters loaded successfully.");
    } catch (std::invalid_argument &e) {
      g_log.information(
          "LoadParameterFile: No parameter file found for this instrument");
      g_log.information(e.what());
    } catch (std::runtime_error &e) {
      g_log.information(
          "Unable to successfully run LoadParameterFile Child Algorithm");
      g_log.information(e.what());
    }
  } else {
    g_log.information("No parameter file found for this instrument");
  }
}
开发者ID:Mantid-Test-Account,项目名称:mantid,代码行数:53,代码来源:LoadInstrument.cpp

示例10: processGroups

/**
 * Process the two groups together and set the result accordingly
 * @param groupOne :: Input group 1
 * @param groupTwo :: Input group 2
 */
void CheckWorkspacesMatch::processGroups(
    boost::shared_ptr<const API::WorkspaceGroup> groupOne,
    boost::shared_ptr<const API::WorkspaceGroup> groupTwo) {
  // Check their sizes
  const size_t totalNum = static_cast<size_t>(groupOne->getNumberOfEntries());
  if (groupOne->getNumberOfEntries() != groupTwo->getNumberOfEntries()) {
    this->result = "GroupWorkspaces size mismatch.";
    return;
  }

  // See if there are any other properties that require setting
  const std::vector<Property *> &allProps = this->getProperties();
  std::vector<Property *> nonDefaultProps;
  nonDefaultProps.reserve(allProps.size());
  for (size_t i = 0; i < allProps.size(); ++i) {
    Property *p = allProps[i];
    const std::string &propName = p->name();
    // Skip those not set and the input workspaces
    if (p->isDefault() || propName == "Workspace1" || propName == "Workspace2")
      continue;
    nonDefaultProps.push_back(p);
  }
  const size_t numNonDefault = nonDefaultProps.size();

  const double progressFraction = 1.0 / static_cast<double>(totalNum);
  std::vector<std::string> namesOne = groupOne->getNames();
  std::vector<std::string> namesTwo = groupTwo->getNames();
  for (size_t i = 0; i < totalNum; ++i) {
    // We should use an algorithm for each so that the output properties are
    // reset properly
    Algorithm_sptr checker = this->createChildAlgorithm(
        this->name(), progressFraction * (double)i,
        progressFraction * (double)(i + 1), false, this->version());
    checker->setPropertyValue("Workspace1", namesOne[i]);
    checker->setPropertyValue("Workspace2", namesTwo[i]);
    for (size_t j = 0; j < numNonDefault; ++j) {
      Property *p = nonDefaultProps[j];
      checker->setPropertyValue(p->name(), p->value());
    }
    checker->execute();
    std::string success = checker->getProperty("Result");
    if (success != this->successString()) {
      if (!this->result.empty())
        this->result += "\n";
      this->result +=
          success + ". Inputs=[" + namesOne[i] + "," + namesTwo[i] + "]";
    }
  }
}
开发者ID:quantumsteve,项目名称:mantid,代码行数:54,代码来源:CheckWorkspacesMatch.cpp

示例11: exec

void SofQW::exec() {
  // Find the approopriate algorithm
  std::string method = this->getProperty("Method");
  std::string child = "SofQW" + method;
  
  // Setup and run
  Algorithm_sptr childAlg = boost::dynamic_pointer_cast<Algorithm>(
      createChildAlgorithm(child, 0.0, 1.0));
  // This will add the Method property to the child algorithm but it will be
  // ignored anyway...
  childAlg->copyPropertiesFrom(*this);
  childAlg->execute();

  MatrixWorkspace_sptr outputWS = childAlg->getProperty("OutputWorkspace");
  this->setProperty("OutputWorkspace", outputWS);
}
开发者ID:DiegoMonserrat,项目名称:mantid,代码行数:16,代码来源:SofQW.cpp

示例12: runCompareWorkspaces

/**
 * Run new CompareWorkspaces algorithm as a child algorithm.
 *
 * Result string formatted the same way as before; "Success!" when workspaces
 * match or a newline separated list of mismatch messages.
 *
 * @param group_compare Should output be formatted like group comparison?
 * @return A string containing either successString() or mismatch messages
 */
std::string CheckWorkspacesMatch::runCompareWorkspaces(bool group_compare) {
  // This algorithm produces a single result string
  std::string result;

  // Use new CompareWorkspaces algorithm to perform comparison
  Algorithm_sptr compare = this->createChildAlgorithm("CompareWorkspaces");
  compare->setRethrows(true);
  compare->setLogging(false);

  // Forward workspace properties
  Workspace_sptr ws1 = getProperty("Workspace1");
  Workspace_sptr ws2 = getProperty("Workspace2");
  compare->setProperty("Workspace1", ws1);
  compare->setProperty("Workspace2", ws2);

  // Copy any other non-default properties
  const std::vector<Property *> &allProps = this->getProperties();
  auto propCount = allProps.size();
  for (size_t i = 0; i < propCount; ++i) {
    Property *prop = allProps[i];
    const std::string &pname = prop->name();

    if (!prop->isDefault() && pname != "Workspace1" && pname != "Workspace2" &&
        pname != "Result")
      compare->setPropertyValue(pname, prop->value());
  }

  // Execute comparison
  compare->execute();

  // Generate result string
  if (!compare->getProperty("Result")) {
    ITableWorkspace_sptr table = compare->getProperty("Messages");
    auto rowcount = table->rowCount();
    for (size_t i = 0; i < rowcount; ++i) {
      result += table->cell<std::string>(i, 0);

      // Emulate special case output format when comparing groups
      if (group_compare &&
          table->cell<std::string>(i, 0) !=
              "Type mismatch. One workspace is a group, the other is not." &&
          table->cell<std::string>(i, 0) != "GroupWorkspaces size mismatch.") {

        result += ". Inputs=[" + table->cell<std::string>(i, 1) + "," +
                  table->cell<std::string>(i, 2) + "]";
      }

      if (i < (rowcount - 1))
        result += "\n";
    }
  } else {
    result = successString();
  }

  return result;
}
开发者ID:liyulun,项目名称:mantid,代码行数:65,代码来源:CheckWorkspacesMatch.cpp

示例13:

/** Add workspace2 to workspace1 by adding spectrum.
  */
MatrixWorkspace_sptr
AlignAndFocusPowder::conjoinWorkspaces(API::MatrixWorkspace_sptr ws1,
                                       API::MatrixWorkspace_sptr ws2,
                                       size_t offset) {
  // Get information from ws1: maximum spectrum number, and store original
  // spectrum Nos
  size_t nspec1 = ws1->getNumberHistograms();
  specnum_t maxspecNo1 = 0;
  std::vector<specnum_t> origspecNos;
  for (size_t i = 0; i < nspec1; ++i) {
    specnum_t tmpspecNo = ws1->getSpectrum(i).getSpectrumNo();
    origspecNos.push_back(tmpspecNo);
    if (tmpspecNo > maxspecNo1)
      maxspecNo1 = tmpspecNo;
  }

  g_log.information() << "[DBx536] Max spectrum number of ws1 = " << maxspecNo1
                      << ", Offset = " << offset << ".\n";

  size_t nspec2 = ws2->getNumberHistograms();

  // Conjoin 2 workspaces
  Algorithm_sptr alg = this->createChildAlgorithm("AppendSpectra");
  alg->initialize();
  ;

  alg->setProperty("InputWorkspace1", ws1);
  alg->setProperty("InputWorkspace2", ws2);
  alg->setProperty("OutputWorkspace", ws1);
  alg->setProperty("ValidateInputs", false);

  alg->executeAsChildAlg();

  API::MatrixWorkspace_sptr outws = alg->getProperty("OutputWorkspace");

  // FIXED : Restore the original spectrum Nos to spectra from ws1
  for (size_t i = 0; i < nspec1; ++i) {
    specnum_t tmpspecNo = outws->getSpectrum(i).getSpectrumNo();
    outws->getSpectrum(i).setSpectrumNo(origspecNos[i]);

    g_log.information() << "[DBx540] Conjoined spectrum " << i
                        << ": restore spectrum number to "
                        << outws->getSpectrum(i).getSpectrumNo()
                        << " from spectrum number = " << tmpspecNo << ".\n";
  }

  // Rename spectrum number
  if (offset >= 1) {
    for (size_t i = 0; i < nspec2; ++i) {
      specnum_t newspecid = maxspecNo1 + static_cast<specnum_t>((i) + offset);
      outws->getSpectrum(nspec1 + i).setSpectrumNo(newspecid);
      // ISpectrum* spec = outws->getSpectrum(nspec1+i);
      // if (spec)
      // spec->setSpectrumNo(3);
    }
  }

  return outws;
}
开发者ID:rosswhitfield,项目名称:mantid,代码行数:61,代码来源:AlignAndFocusPowder.cpp

示例14: invalid_argument

/** Get a pointer to an instrument in one of 3 ways: InputWorkspace,
 * InstrumentName, InstrumentFilename
 * @param alg :: algorithm from which to get the property values.
 * */
Geometry::Instrument_const_sptr
LoadCalFile::getInstrument3Ways(Algorithm *alg) {
  MatrixWorkspace_sptr inWS = alg->getProperty("InputWorkspace");
  std::string InstrumentName = alg->getPropertyValue("InstrumentName");
  std::string InstrumentFilename = alg->getPropertyValue("InstrumentFilename");

  // Some validation
  int numParams = 0;
  if (inWS)
    numParams++;
  if (!InstrumentName.empty())
    numParams++;
  if (!InstrumentFilename.empty())
    numParams++;

  if (numParams > 1)
    throw std::invalid_argument("You must specify exactly ONE way to get an "
                                "instrument (workspace, instrument name, or "
                                "IDF file). You specified more than one.");
  if (numParams == 0)
    throw std::invalid_argument("You must specify exactly ONE way to get an "
                                "instrument (workspace, instrument name, or "
                                "IDF file). You specified none.");

  // ---------- Get the instrument one of 3 ways ---------------------------
  Instrument_const_sptr inst;
  if (inWS) {
    inst = inWS->getInstrument();
  } else {
    Algorithm_sptr childAlg =
        alg->createChildAlgorithm("LoadInstrument", 0.0, 0.2);
    MatrixWorkspace_sptr tempWS = boost::make_shared<Workspace2D>();
    childAlg->setProperty<MatrixWorkspace_sptr>("Workspace", tempWS);
    childAlg->setPropertyValue("Filename", InstrumentFilename);
    childAlg->setPropertyValue("InstrumentName", InstrumentName);
    childAlg->setProperty("RewriteSpectraMap",
                          Mantid::Kernel::OptionalBool(false));
    childAlg->executeAsChildAlg();
    inst = tempWS->getInstrument();
  }

  return inst;
}
开发者ID:mducle,项目名称:mantid,代码行数:47,代码来源:LoadCalFile.cpp

示例15: createChildAlgorithm

// Private function to load parameter file specified by a full path name into
// given workspace, returning success.
bool LoadIDFFromNexus::loadParameterFile(
    const std::string &fullPathName,
    const MatrixWorkspace_sptr localWorkspace) {

  try {
    // load and also populate instrument parameters from this 'fallback'
    // parameter file
    Algorithm_sptr loadParamAlg = createChildAlgorithm("LoadParameterFile");
    loadParamAlg->setProperty("Filename", fullPathName);
    loadParamAlg->setProperty("Workspace", localWorkspace);
    loadParamAlg->execute();
    g_log.notice() << "Instrument parameter file: " << fullPathName
                   << " has been loaded.\n\n";
    return true; // Success
  } catch (std::runtime_error &) {
    g_log.debug() << "Instrument parameter file: " << fullPathName
                  << " not found or un-parsable.\n";
    return false; // Failure
  }
}
开发者ID:stuartcampbell,项目名称:mantid,代码行数:22,代码来源:LoadIDFFromNexus.cpp


注:本文中的Algorithm_sptr类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。