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


C++ MatrixWorkspace_sptr::getDetectorIDToWorkspaceIndexMap方法代码示例

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


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

示例1: runtime_error

/** Convert a list of detector IDs list (string) to a list of spectra/workspace
 * indexes list
  * @param dataws :: MatrixWorkspace to mask
  * @param detidliststr :: list of detector IDs in string format
  * @return :: list of spectra/workspace index IDs in string format
  */
std::string
MaskBinsFromTable::convertToSpectraList(API::MatrixWorkspace_sptr dataws,
                                        std::string detidliststr) {
  // Use array property to get a list of detectors
  vector<int> detidvec;
  ArrayProperty<int> parser("detids", detidliststr);

  size_t numitems = parser.size();
  for (size_t i = 0; i < numitems; ++i) {
    detidvec.push_back(parser.operator()()[i]);
    g_log.debug() << "[DB] DetetorID = " << detidvec.back() << " to mask.";
  }

  // Get workspace index from
  vector<size_t> wsindexvec;

  detid2index_map refermap = dataws->getDetectorIDToWorkspaceIndexMap(false);
  for (size_t i = 0; i < numitems; ++i) {
    detid_t detid = detidvec[i];
    detid2index_map::const_iterator fiter = refermap.find(detid);
    if (fiter != refermap.end()) {
      size_t wsindex = fiter->second;
      wsindexvec.push_back(wsindex);
    } else {
      g_log.warning() << "Detector ID " << detid
                      << " cannot be mapped to any workspace index/spectrum."
                      << ".\n";
    }
  }

  // Sort the vector
  if (wsindexvec.empty())
    throw runtime_error("There is no spectrum found for input detectors list.");

  sort(wsindexvec.begin(), wsindexvec.end());

  // Convert the spectra to a string
  stringstream rss;
  size_t headid = wsindexvec[0];
  size_t previd = wsindexvec[0];

  for (size_t i = 1; i < wsindexvec.size(); ++i) {
    size_t currid = wsindexvec[i];
    if (currid > previd + 1) {
      // skipped.  previous region should be written, and a new region start
      if (headid == previd)
        rss << headid << ", ";
      else
        rss << headid << "-" << previd << ", ";
      headid = currid;
    } else {
      // Equal to continuous
      ;
    }

    // Update
    previd = currid;
  }

  // Finalize
  if (headid == previd)
    rss << headid;
  else
    rss << headid << "-" << previd;

  string spectraliststr(rss.str());

  return spectraliststr;
}
开发者ID:rosswhitfield,项目名称:mantid,代码行数:75,代码来源:MaskBinsFromTable.cpp


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