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


C++ api::ITableWorkspace_sptr类代码示例

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


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

示例1: mergeTables

void EnggDiffFittingModel::mergeTables(
    const API::ITableWorkspace_sptr tableToCopy,
    API::ITableWorkspace_sptr targetTable) const {
  for (size_t i = 0; i < tableToCopy->rowCount(); ++i) {
    API::TableRow rowToCopy = tableToCopy->getRow(i);
    API::TableRow newRow = targetTable->appendRow();

    for (size_t j = 0; j < tableToCopy->columnCount(); ++j) {
      double valueToCopy;
      rowToCopy >> valueToCopy;
      newRow << valueToCopy;
    }
  }
}
开发者ID:DanNixon,项目名称:mantid,代码行数:14,代码来源:EnggDiffFittingModel.cpp

示例2: getDomainSize

size_t LatticeDomainCreator::getDomainSize() const {
  API::IPeaksWorkspace_sptr peaksWorkspace =
      boost::dynamic_pointer_cast<IPeaksWorkspace>(m_workspace);
  if (peaksWorkspace) {
    return peaksWorkspace->getNumberPeaks();
  }

  API::ITableWorkspace_sptr tableWorkspace =
      boost::dynamic_pointer_cast<ITableWorkspace>(m_workspace);
  if (tableWorkspace) {
    return tableWorkspace->rowCount();
  }

  return 0;
}
开发者ID:DanNixon,项目名称:mantid,代码行数:15,代码来源:LatticeDomainCreator.cpp

示例3: getTableRowNumbers

/* This function fills in a list of the row numbers starting 0 of the parameters
   in the table workspace, so one can find the position in a column of
   the value of the given parameter.
*/
void LoadFullprofResolution::getTableRowNumbers(
    const API::ITableWorkspace_sptr &tablews,
    std::map<std::string, size_t> &parammap) {
  parammap.clear();

  size_t numrows = tablews->rowCount();
  for (size_t i = 0; i < numrows; ++i) {
    TableRow row = tablews->getRow(i);
    std::string name;
    row >> name;
    parammap.emplace(name, i);
  }

  return;
}
开发者ID:Mantid-Test-Account,项目名称:mantid,代码行数:19,代码来源:LoadFullprofResolution.cpp

示例4: saveInvestigations

/** This method saves investigations  to a table workspace
 *  @param investigations :: a vector containing investigation data
 *  @param outputws :: shared pointer to output workspace
 */
void CICatHelper::saveInvestigations(
    const std::vector<ns1__investigation *> &investigations,
    API::ITableWorkspace_sptr &outputws) {
  try {
    std::vector<ns1__investigation *>::const_iterator citr;
    for (citr = investigations.begin(); citr != investigations.end(); ++citr) {
      API::TableRow t = outputws->appendRow();

      std::string id = std::to_string(*(*citr)->id);

      savetoTableWorkspace(&id, t);
      savetoTableWorkspace((*citr)->facility, t);
      savetoTableWorkspace((*citr)->title, t);
      savetoTableWorkspace((*citr)->instrument, t);
      savetoTableWorkspace((*citr)->invParamValue, t);

      std::string startDate = std::to_string(*(*citr)->invStartDate);
      savetoTableWorkspace(&startDate, t);

      std::string endDate = std::to_string(*(*citr)->invEndDate);
      savetoTableWorkspace(&endDate, t);

      std::string sessionID = m_session->getSessionId();
      savetoTableWorkspace(&sessionID, t);
    }
  } catch (std::runtime_error &) {
    throw std::runtime_error(
        "Error when saving  the ICat Search Results data to Workspace");
  }
}
开发者ID:DanNixon,项目名称:mantid,代码行数:34,代码来源:ICat3Helper.cpp

示例5: fitWorkspace

/** Fits each spectrum in the workspace to f(x) = A * sin( w * x + p)
* @param ws :: [input] The workspace to fit
* @param freq :: [input] Hint for the frequency (w)
* @param groupName :: [input] The name of the output workspace group
* @param resTab :: [output] Table workspace storing the asymmetries and phases
* @param resGroup :: [output] Workspace group storing the fitting results
*/
void CalMuonDetectorPhases::fitWorkspace(const API::MatrixWorkspace_sptr &ws,
                                         double freq, std::string groupName,
                                         API::ITableWorkspace_sptr &resTab,
                                         API::WorkspaceGroup_sptr &resGroup) {

  int nhist = static_cast<int>(ws->getNumberHistograms());

  // Create the fitting function f(x) = A * sin ( w * x + p )
  // The same function and initial parameters are used for each fit
  std::string funcStr = createFittingFunction(freq, true);

  // Set up results table
  resTab->addColumn("int", "Spectrum number");
  resTab->addColumn("double", "Asymmetry");
  resTab->addColumn("double", "Phase");

  // Loop through fitting all spectra individually
  const static std::string success = "success";
  for (int wsIndex = 0; wsIndex < nhist; wsIndex++) {
    reportProgress(wsIndex, nhist);
    auto fit = createChildAlgorithm("Fit");
    fit->initialize();
    fit->setPropertyValue("Function", funcStr);
    fit->setProperty("InputWorkspace", ws);
    fit->setProperty("WorkspaceIndex", wsIndex);
    fit->setProperty("CreateOutput", true);
    fit->setPropertyValue("Output", groupName);
    fit->execute();

    std::string status = fit->getProperty("OutputStatus");
    if (!fit->isExecuted() || status != success) {
      std::ostringstream error;
      error << "Fit failed for spectrum at workspace index " << wsIndex;
      error << ": " << status;
      throw std::runtime_error(error.str());
    }

    API::MatrixWorkspace_sptr fitOut = fit->getProperty("OutputWorkspace");
    resGroup->addWorkspace(fitOut);
    API::ITableWorkspace_sptr tab = fit->getProperty("OutputParameters");
    // Now we have our fitting results stored in tab
    // but we need to extract the relevant information, i.e.
    // the detector phases (parameter 'p') and asymmetries ('A')
    const auto &spectrum = ws->getSpectrum(static_cast<size_t>(wsIndex));
    extractDetectorInfo(tab, resTab, spectrum.getSpectrumNo());
  }
}
开发者ID:liyulun,项目名称:mantid,代码行数:54,代码来源:CalMuonDetectorPhases.cpp

示例6: saveSearchRessults

/** This method saves the search response( investigations )data to a table
 * workspace
 *  @param response :: const reference to response object
 *  @param outputws :: shared pointer to output workspace
 */
void CICatHelper::saveSearchRessults(
    const ns1__searchByAdvancedPaginationResponse &response,
    API::ITableWorkspace_sptr &outputws) {
  if (outputws->getColumnNames().empty()) {
    outputws->addColumn("str", "Investigation id");
    outputws->addColumn("str", "Facility");
    outputws->addColumn("str", "Title");
    outputws->addColumn("str", "Instrument");
    outputws->addColumn("str", "Run range");
    outputws->addColumn("str", "Start date");
    outputws->addColumn("str", "End date");
    outputws->addColumn("str", "SessionID");
  }
  saveInvestigations(response.return_, outputws);
}
开发者ID:DanNixon,项目名称:mantid,代码行数:20,代码来源:ICat3Helper.cpp

示例7: writeData

void SaveDiffFittingAscii::writeData(const API::ITableWorkspace_sptr workspace,
                                     std::ofstream &file,
                                     const size_t columnSize) {

  for (size_t rowIndex = 0; rowIndex < workspace->rowCount(); ++rowIndex) {
    TableRow row = workspace->getRow(rowIndex);
    for (size_t columnIndex = 0; columnIndex < columnSize; columnIndex++) {

      const auto row_str =
          boost::lexical_cast<std::string>(row.Double(columnIndex));
      g_log.debug() << row_str << std::endl;

      if (columnIndex == columnSize - 1)
        writeVal(row_str, file, true);
      else
        writeVal(row_str, file, false);
    }
  }
}
开发者ID:mantidproject,项目名称:mantid,代码行数:19,代码来源:SaveDiffFittingAscii.cpp

示例8: fitFrequencyFromAsymmetry

/**
 * Fit the asymmetry and return the frequency found.
 * Starting value for the frequency is taken from the hint.
 * If the fit fails, return the initial hint.
 * @param wsAsym :: [input] Workspace with asymmetry to fit
 * @return :: Frequency found from fit
 */
double CalMuonDetectorPhases::fitFrequencyFromAsymmetry(
    const API::MatrixWorkspace_sptr &wsAsym) {
  // Starting value for frequency is hint
  double hint = getFrequencyHint();
  std::string funcStr = createFittingFunction(hint, false);
  double frequency = hint;

  std::string fitStatus = "success";
  try {
    auto func = API::FunctionFactory::Instance().createInitialized(funcStr);
    auto fit = createChildAlgorithm("Fit");
    fit->setProperty("Function", func);
    fit->setProperty("InputWorkspace", wsAsym);
    fit->setProperty("WorkspaceIndex", 0);
    fit->setProperty("CreateOutput", true);
    fit->setProperty("OutputParametersOnly", true);
    fit->setProperty("Output", "__Invisible");
    fit->executeAsChildAlg();
    fitStatus = fit->getPropertyValue("OutputStatus");
    if (fitStatus == "success") {
      API::ITableWorkspace_sptr params = fit->getProperty("OutputParameters");
      const size_t rows = params->rowCount();
      static size_t colName(0), colValue(1);
      for (size_t iRow = 0; iRow < rows; iRow++) {
        if (params->cell<std::string>(iRow, colName) == "w") {
          frequency = params->cell<double>(iRow, colValue);
          break;
        }
      }
    }
  } catch (const std::exception &e) {
    // Report fit failure to user
    fitStatus = e.what();
  }
  if (fitStatus != "success") { // Either failed, or threw an exception
    std::ostringstream message;
    message << "Fit failed (" << fitStatus << "), using omega hint = " << hint;
    g_log.error(message.str());
  }
  return frequency;
}
开发者ID:mantidproject,项目名称:mantid,代码行数:48,代码来源:CalMuonDetectorPhases.cpp

示例9: extractDetectorInfo

/** Extracts detector asymmetries and phases from fitting results
* and adds a new row to the results table with them
* @param paramTab :: [input] Output parameter table resulting from the fit
* @param resultsTab :: [input] Results table to update with a new row
* @param spectrumNumber :: [input] Spectrum number
*/
void CalMuonDetectorPhases::extractDetectorInfo(
    const API::ITableWorkspace_sptr &paramTab,
    const API::ITableWorkspace_sptr &resultsTab,
    const specnum_t spectrumNumber) {

  double asym = paramTab->Double(0, 1);
  double phase = paramTab->Double(2, 1);
  // If asym<0, take the absolute value and add \pi to phase
  // f(x) = A * sin( w * x + p) = -A * sin( w * x + p + PI)
  if (asym < 0) {
    asym = -asym;
    phase = phase + M_PI;
  }
  // Now convert phases to interval [0, 2PI)
  int factor = static_cast<int>(floor(phase / 2 / M_PI));
  if (factor) {
    phase = phase - factor * 2 * M_PI;
  }
  // Copy parameters to new row in results table
  API::TableRow row = resultsTab->appendRow();
  row << static_cast<int>(spectrumNumber) << asym << phase;
}
开发者ID:liyulun,项目名称:mantid,代码行数:28,代码来源:CalMuonDetectorPhases.cpp

示例10: exec

/** Execute the algorithm.
 */
void CreateEPP::exec() {
  API::MatrixWorkspace_sptr inputWS =
      getProperty(PropertyNames::INPUT_WORKSPACE);
  const auto &spectrumInfo = inputWS->spectrumInfo();
  API::ITableWorkspace_sptr outputWS =
      API::WorkspaceFactory::Instance().createTable("TableWorkspace");
  addEPPColumns(outputWS);
  const double sigma = getProperty(PropertyNames::SIGMA);
  const size_t spectraCount = spectrumInfo.size();
  outputWS->setRowCount(spectraCount);
  const auto l1 = spectrumInfo.l1();
  const double EFixed = inputWS->run().getPropertyAsSingleValue("Ei");
  for (size_t i = 0; i < spectraCount; ++i) {
    const auto l2 = spectrumInfo.l2(i);
    const auto elasticTOF = Kernel::UnitConversion::run(
        "Energy", "TOF", EFixed, l1, l2, 0, Kernel::DeltaEMode::Direct, EFixed);
    outputWS->getRef<int>(ColumnNames::WS_INDEX, i) = static_cast<int>(i);
    outputWS->getRef<double>(ColumnNames::PEAK_CENTRE, i) = elasticTOF;
    outputWS->getRef<double>(ColumnNames::PEAK_CENTRE_ERR, i) = 0;
    outputWS->getRef<double>(ColumnNames::SIGMA, i) = sigma;
    outputWS->getRef<double>(ColumnNames::SIGMA_ERR, i) = 0;
    double height = 0;
    try {
      const auto elasticIndex = inputWS->binIndexOf(elasticTOF, i);
      height = inputWS->y(i)[elasticIndex];
    } catch (std::out_of_range &) {
      std::ostringstream sout;
      sout << "EPP out of TOF range for workspace index " << i
           << ". Peak height set to zero.";
      g_log.warning() << sout.str();
    }
    outputWS->getRef<double>(ColumnNames::HEIGHT, i) = height;
    outputWS->getRef<double>(ColumnNames::CHI_SQUARED, i) = 1;
    outputWS->getRef<std::string>(ColumnNames::STATUS, i) = "success";
  }
  setProperty(PropertyNames::OUTPUT_WORKSPACE, outputWS);
}
开发者ID:samueljackson92,项目名称:mantid,代码行数:39,代码来源:CreateEPP.cpp

示例11: runtime_error

/**
 * Saves result from "getDataFiles" to workspace.
 * @param response :: result response from the catalog.
 * @param outputws :: shared pointer to datasets
 */
void ICat4Catalog::saveDataFiles(std::vector<xsd__anyType *> response,
                                 API::ITableWorkspace_sptr &outputws) {
  if (outputws->getColumnNames().empty()) {
    // Add rows headers to the output workspace.
    outputws->addColumn("str", "Name");
    outputws->addColumn("str", "Location");
    outputws->addColumn("str", "Create Time");
    outputws->addColumn("long64", "Id");
    outputws->addColumn("long64", "File size(bytes)");
    outputws->addColumn("str", "File size");
    outputws->addColumn("str", "Description");
  }

  std::vector<xsd__anyType *>::const_iterator iter;
  for (iter = response.begin(); iter != response.end(); ++iter) {
    ns1__datafile *datafile = dynamic_cast<ns1__datafile *>(*iter);
    if (datafile) {
      API::TableRow table = outputws->appendRow();
      // Now add the relevant investigation data to the table.
      savetoTableWorkspace(datafile->name, table);
      savetoTableWorkspace(datafile->location, table);

      std::string createDate =
          formatDateTime(*datafile->createTime, "%Y-%m-%d %H:%M:%S");
      savetoTableWorkspace(&createDate, table);

      savetoTableWorkspace(datafile->id, table);
      savetoTableWorkspace(datafile->fileSize, table);

      std::string fileSize = bytesToString(*datafile->fileSize);
      savetoTableWorkspace(&fileSize, table);

      if (datafile->description)
        savetoTableWorkspace(datafile->description, table);
    } else {
      throw std::runtime_error("ICat4Catalog::saveDataFiles expected a "
                               "datafile. Please contact the Mantid "
                               "development team.");
    }
  }
}
开发者ID:DanNixon,项目名称:mantid,代码行数:46,代码来源:ICat4Catalog.cpp

示例12: exec

    /** Executes the algorithm. Moving detectors of input workspace to positions indicated in table workspace
    *
    *  @throw FileError Thrown if unable to get instrument from workspace, 
    *                   table workspace is incompatible with instrument
    */
    void ApplyCalibration::exec()
    {
      // Get pointers to the workspace, parameter map and table
      API::MatrixWorkspace_sptr inputWS = getProperty("Workspace");
      m_pmap = &(inputWS->instrumentParameters()); // Avoids a copy if you get the reference before the instrument

      API::ITableWorkspace_sptr PosTable = getProperty("PositionTable");
      Geometry::Instrument_const_sptr instrument = inputWS->getInstrument();
      if(!instrument)
      {
        throw std::runtime_error("Workspace to apply calibration to has no defined instrument");
      }

      size_t numDetector = PosTable->rowCount();
      ColumnVector<int> detID = PosTable->getVector("Detector ID");
      ColumnVector<V3D> detPos = PosTable->getVector("Detector Position");
      // numDetector needs to be got as the number of rows in the table and the detID got from the (i)th row of table.
      for (size_t i = 0; i < numDetector; ++i)
      {
        setDetectorPosition(instrument, detID[i], detPos[i], false );
      }
      // Ensure pointer is only valid for execution
      m_pmap = NULL;
    }
开发者ID:trnielsen,项目名称:mantid,代码行数:29,代码来源:ApplyCalibration.cpp

示例13: saveDataSets

    /** This method loops through the response return_vector and saves the datasets details to a table workspace
     * @param response :: const reference to response object
     * @param outputws ::  shred pointer to workspace
     * @returns shared pointer to table workspace which stores the data
     */
    void  CICatHelper::saveDataSets(const ns1__getInvestigationIncludesResponse& response,API::ITableWorkspace_sptr& outputws)
    {
      //create table workspace
      if (outputws->getColumnNames().empty())
      {
        outputws->addColumn("str","Name");//File name
        outputws->addColumn("str","Status");
        outputws->addColumn("str","Type");
        outputws->addColumn("str","Description");
        outputws->addColumn("long64","Sample Id");
      }
      try
      {

        std::vector<ns1__dataset*> datasetVec;
        datasetVec.assign((response.return_)->datasetCollection.begin(),(response.return_)->datasetCollection.end());

        std::vector<ns1__dataset*>::const_iterator dataset_citr;
        for(dataset_citr=datasetVec.begin();dataset_citr!=datasetVec.end();++dataset_citr)
        {
          API::TableRow t = outputws->appendRow();

          // DataSet Name
          savetoTableWorkspace((*dataset_citr)->name,t);
          // DataSet Status
          savetoTableWorkspace((*dataset_citr)->datasetStatus,t);
          //DataSet Type
          savetoTableWorkspace((*dataset_citr)->datasetType,t);
          //DataSet Type
          savetoTableWorkspace((*dataset_citr)->description,t);
          //DataSet Type
          savetoTableWorkspace((*dataset_citr)->sampleId,t);
        }
      }

      catch(std::runtime_error& )
      {
        throw;
      }

      //return outputws;
    }
开发者ID:AlistairMills,项目名称:mantid,代码行数:47,代码来源:ICat3Helper.cpp

示例14: readExpIni

/**
 * Parse the (optional) exp.ini file found on NOMAD
 * @param filename full path to a exp.ini file
 * @param wksp The table workspace to modify.
 */
void PDLoadCharacterizations::readExpIni(const std::string &filename,
                                         API::ITableWorkspace_sptr &wksp) {
  if (wksp->rowCount() == 0)
    throw std::runtime_error("Characterizations file does not have any "
                             "characterizations information");

  std::ifstream file(filename.c_str());
  if (!file) {
    throw Exception::FileError("Unable to open file", filename);
  }

  // parse the file
  for (std::string line = Strings::getLine(file); !file.eof();
       line = Strings::getLine(file)) {
    line = Strings::strip(line);
    // skip empty lines and "comments"
    if (line.empty())
      continue;
    if (line.substr(0, 1) == "#")
      continue;

    // split the line and see if it has something meaningful
    std::vector<std::string> splitted;
    boost::split(splitted, line, boost::is_any_of("\t "),
                 boost::token_compress_on);
    if (splitted.size() < 2)
      continue;

    // update the various charaterization runs
    if (splitted[0] == EXP_INI_VAN_KEY) {
      wksp->getRef<std::string>("vanadium", 0) = splitted[1];
    } else if (splitted[0] == EXP_INI_EMPTY_KEY) {
      wksp->getRef<std::string>("container", 0) = splitted[1];
    } else if (splitted[0] == EXP_INI_CAN_KEY) {
      wksp->getRef<std::string>("empty", 0) = splitted[1];
    }
  }
}
开发者ID:spaceyatom,项目名称:mantid,代码行数:43,代码来源:PDLoadCharacterizations.cpp

示例15: loadPhaseTable

/** Load PhaseTable file to a vector of HistData.
* @param phaseTable :: [input] phase table containing detector info
* @param deadTimeTable :: [output] phase table containing dead times
*/
void PhaseQuadMuon::loadPhaseTable(API::ITableWorkspace_sptr phaseTable, API::ITableWorkspace_sptr deadTimeTable)
{
  if ( phaseTable->rowCount() )
  {
    if ( phaseTable->columnCount()<4 )
    {
      throw std::invalid_argument("PhaseQuad: PhaseTable must contain at least four columns");
    }

    // Check number of histograms in inputWs match number of detectors in phase table
    if (m_nHist != static_cast<int>(phaseTable->rowCount()))
    {
      throw std::runtime_error("PhaseQuad: Number of histograms in phase table does not match number of spectra in workspace");
    }

    for (size_t i=0; i<phaseTable->rowCount(); ++i)
    {
      API::TableRow phaseRow = phaseTable->getRow(i);

      // The first three columns go to m_histData
      HistData tempHist;
      tempHist.detOK = phaseRow.Bool(0);
      tempHist.alpha = phaseRow.Double(1);
      tempHist.phi   = phaseRow.Double(2);
      m_histData.push_back(tempHist);

      // The last column goes to deadTimeTable
      API::TableRow deadRow = deadTimeTable->appendRow();
      deadRow << static_cast<int>(i)+1 << phaseRow.Double(3);
    }

  }
  else
  {
    throw std::invalid_argument("PhaseQuad: PhaseTable is empty");
  }

}
开发者ID:utkarshayachit,项目名称:mantid,代码行数:42,代码来源:PhaseQuadMuon.cpp


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