本文整理汇总了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;
}