本文整理汇总了C++中NXData::openNXInt方法的典型用法代码示例。如果您正苦于以下问题:C++ NXData::openNXInt方法的具体用法?C++ NXData::openNXInt怎么用?C++ NXData::openNXInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NXData
的用法示例。
在下文中一共展示了NXData::openNXInt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readBinMasking
/**
* Read the bin masking information from the mantid_workspace_i/workspace group.
* @param wksp_cls :: The data group
* @param local_workspace :: The workspace to read into
*/
void LoadNexusProcessed::readBinMasking(NXData & wksp_cls, API::MatrixWorkspace_sptr local_workspace)
{
if (wksp_cls.getDataSetInfo("masked_spectra").stat == NX_ERROR)
{
return;
}
NXInt spec = wksp_cls.openNXInt("masked_spectra");
spec.load();
NXInt bins = wksp_cls.openNXInt("masked_bins");
bins.load();
NXDouble weights = wksp_cls.openNXDouble("mask_weights");
weights.load();
const int n = spec.dim0();
const int n1 = n - 1;
for(int i = 0; i < n; ++i)
{
int si = spec(i,0);
int j0 = spec(i,1);
int j1 = i < n1 ? spec(i+1,1) : bins.dim0();
for(int j = j0; j < j1; ++j)
{
local_workspace->flagMasked(si,bins[j],weights[j]);
}
}
}
示例2: root
/**
* Loads the mapping between index -> set of detector IDs
*
* If "detector_index", "detector_count" and "detector_list" are all present,
* use these to get the mapping, otherwise spectrum number = detector ID
* (one-to-one)
*
* The spectrum spectrum_index[i] maps to detector_count[i] detectors, whose
* detector IDs are in detector_list starting at the index detector_index[i]
*
* @returns :: map of index -> detector IDs
* @throws std::runtime_error if fails to read data from file
*/
std::map<int, std::set<int>>
LoadMuonNexus2::loadDetectorMapping(const Mantid::NeXus::NXInt &spectrumIndex) {
std::map<int, std::set<int>> mapping;
const int nSpectra = spectrumIndex.dim0();
// Find and open the data group
NXRoot root(getPropertyValue("Filename"));
NXEntry entry = root.openEntry(m_entry_name);
const std::string detectorName = [&entry]() {
// Only the first NXdata found
for (auto &group : entry.groups()) {
std::string className = group.nxclass;
if (className == "NXdata") {
return group.nxname;
}
}
throw std::runtime_error("No NXdata found in file");
}();
NXData dataGroup = entry.openNXData(detectorName);
// Usually for muon data, detector id = spectrum number
// If not, the optional groups "detector_index", "detector_list" and
// "detector_count" will be present to map one to the other
const bool hasDetectorMapping = dataGroup.containsDataSet("detector_index") &&
dataGroup.containsDataSet("detector_list") &&
dataGroup.containsDataSet("detector_count");
if (hasDetectorMapping) {
// Read detector IDs
try {
const auto detIndex = dataGroup.openNXInt("detector_index");
const auto detCount = dataGroup.openNXInt("detector_count");
const auto detList = dataGroup.openNXInt("detector_list");
const int nSpectra = detIndex.dim0();
for (int i = 0; i < nSpectra; ++i) {
const int start = detIndex[i];
const int nDetectors = detCount[i];
std::set<int> detIDs;
for (int jDet = 0; jDet < nDetectors; ++jDet) {
detIDs.insert(detList[start + jDet]);
}
mapping[i] = detIDs;
}
} catch (const ::NeXus::Exception &err) {
// Throw a more user-friendly message
std::ostringstream message;
message << "Failed to read detector mapping: " << err.what();
throw std::runtime_error(message.str());
}
} else {
for (int i = 0; i < nSpectra; ++i) {
mapping[i] = std::set<int>{spectrumIndex[i]};
}
}
return mapping;
}