本文整理汇总了C++中api::MatrixWorkspace_sptr::replaceSpectraMap方法的典型用法代码示例。如果您正苦于以下问题:C++ MatrixWorkspace_sptr::replaceSpectraMap方法的具体用法?C++ MatrixWorkspace_sptr::replaceSpectraMap怎么用?C++ MatrixWorkspace_sptr::replaceSpectraMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api::MatrixWorkspace_sptr
的用法示例。
在下文中一共展示了MatrixWorkspace_sptr::replaceSpectraMap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readInstrumentGroup
/**
* Read the instrument group
* @param mtd_entry :: The node for the current workspace
* @param local_workspace :: The workspace to attach the instrument
*/
void LoadNexusProcessed::readInstrumentGroup(NXEntry & mtd_entry, API::MatrixWorkspace_sptr local_workspace)
{
//Instrument information
NXInstrument inst = mtd_entry.openNXInstrument("instrument");
if ( ! inst.containsGroup("detector") )
{
g_log.information() << "Detector block not found. The workspace will not contain any detector information.\n";
return;
}
//Populate the spectra-detector map
NXDetector detgroup = inst.openNXDetector("detector");
//Read necessary arrays from the file
// Detector list contains a list of all of the detector numbers. If it not present then we can't update the spectra
// map
int ndets(-1);
boost::shared_array<int> det_list(NULL);
try
{
NXInt detlist_group = detgroup.openNXInt("detector_list");
ndets = detlist_group.dim0();
detlist_group.load();
det_list.swap(detlist_group.sharedBuffer());
}
catch(std::runtime_error &)
{
g_log.information() << "detector_list block not found. The workspace will not contain any detector information."
<< std::endl;
return;
}
//Detector count contains the number of detectors associated with each spectra
NXInt det_count = detgroup.openNXInt("detector_count");
det_count.load();
//Detector index - contains the index of the detector in the workspace
NXInt det_index = detgroup.openNXInt("detector_index");
det_index.load();
int nspectra = det_index.dim0();
//Spectra block - Contains spectrum numbers for each workspace index
// This might not exist so wrap and check. If it doesn't exist create a default mapping
bool have_spectra(true);
boost::shared_array<int> spectra(NULL);
try
{
NXInt spectra_block = detgroup.openNXInt("spectra");
spectra_block.load();
spectra.swap(spectra_block.sharedBuffer());
}
catch(std::runtime_error &)
{
have_spectra = false;
}
//Now build the spectra list
int *spectra_list = new int[ndets];
API::Axis *axis1 = local_workspace->getAxis(1);
int index=0;
for(int i = 1; i <= nspectra; ++i)
{
int spectrum(-1);
if( have_spectra ) spectrum = spectra[i-1];
else spectrum = i+1 ;
if ((i >= m_spec_min && i < m_spec_max )||(m_list && find(m_spec_list.begin(), m_spec_list.end(),
i) != m_spec_list.end()))
{
if( m_axis1vals.empty() )
{
axis1->spectraNo(index) = spectrum;
}
else
{
axis1->setValue(index, m_axis1vals[i-1]);
}
++index;
}
int offset = det_index[i-1];
int detcount = det_count[i-1];
for(int j = 0; j < detcount; j++)
{
spectra_list[offset + j] = spectrum;
}
}
local_workspace->replaceSpectraMap(new SpectraDetectorMap(spectra_list, det_list.get(), ndets));
delete[] spectra_list;
}