Newer
Older
Gigg, Martyn Anthony
committed
{
return sqrt(in);
}
/**Method takes input parameters which describe monitor loading and analyze them against spectra/monitor information in the file.
* The result is the option if monitors can be loaded together with spectra or mast be treated separately
* and additional information on how to treat monitor spectra.
*
*@param entry :: entry to the NeXus file, opened at root folder
*@param spectrum_index :: array of spectra indexes of the data present in the file
*@param ndets :: size of the spectrum index array
*@param n_vms_compat_spectra :: number of data entries containing common time bins (e.g. all spectra, or all spectra and monitors or some spectra (this is not fully supported)
*@param monitors :: map connecting monitor spectra ID against monitor group name in the file.
*@param excludeMonitors :: input property indicating if it is requested to exclude monitors from the target workspace
*@param separateMonitors :: input property indicating if it is requested to load monitors separately (and exclude them from target data workspace this way)
*
*@param MonitorSpectra :: output property containing the list of monitors which should be loaded separately.
*@return excludeMonitors :: indicator if monitors should or mast be excluded from the main data workspace if they can not be loaded with the data
* (contain different number of time channels)
*
*/
bool LoadISISNexus2::findSpectraDetRangeInFile(NXEntry &entry,boost::shared_array<int> &spectrum_index,int64_t ndets,int64_t n_vms_compat_spectra,
std::map<int64_t,std::string> &monitors,bool excludeMonitors,bool separateMonitors,std::set<specid_t> &MonitorSpectra)
MonitorSpectra.clear();
size_t nmons = monitors.size();
//Grab the number of channels
int nMonitorPeriods(0);
size_t nMonitorChannels(0);
if (nmons>0)
{
NXInt chans = entry.openNXInt(m_monitors.begin()->second + "/data");
nMonitorPeriods = chans.dim0();
nMonitorChannels = chans.dim2();
m_numberOfPeriodsInFile = m_numberOfPeriods = nMonitorPeriods ;
m_numberOfSpectraInFile = m_numberOfSpectra = nmons;
m_numberOfChannelsInFile = m_numberOfChannels = nMonitorChannels;
}
if( ndets == 0 )
{
separateMonitors = true;
return separateMonitors;
}
NXData nxData = entry.openNXData("detector_1");
NXInt data = nxData.openIntData();
m_numberOfPeriodsInFile = m_numberOfPeriods = data.dim0();
m_numberOfChannelsInFile = m_numberOfChannels = data.dim2();
if (((m_numberOfPeriodsInFile !=nMonitorPeriods) || (m_numberOfChannelsInFile!=nMonitorChannels)) && nmons>0)
{
if(!separateMonitors)
{
g_log.warning()<<" Performing separate loading as can not load spectra and monitors in the single workspace:\n" ;
g_log.warning()<<" Monitors data contain :"<<nMonitorChannels<<" time channels and: "<<nMonitorPeriods<<" period(s)\n";
g_log.warning()<<" Spectra data contain :"<<m_numberOfChannels<<" time channels and: "<<m_numberOfPeriods<<" period(s)\n";
}
separateMonitors = true;
}
m_numberOfSpectraInFile = m_numberOfSpectra = data.dim1();
bool removeMonitors = excludeMonitors || separateMonitors;
if(m_numberOfSpectra+nmons ==static_cast<size_t>( n_vms_compat_spectra )&& !removeMonitors)
{
// workspace contain the same number of bins for spectra and monitors. Total number of spectra in workspace will be equal to
// n_vms_compat_spectra
m_numberOfSpectraInFile = m_numberOfSpectra;
m_numberOfSpectra=n_vms_compat_spectra;
return separateMonitors;
}
//Now check if monitors expand or shrink the workspace's spectra range
// We assume again that this spectrum list increases monotonically
int64_t min_index = spectrum_index[0];
int64_t max_index = spectrum_index[ndets-1];
std::map<int64_t,std::string> remaining_monitors;
for(auto it = monitors.begin(); it!=monitors.end(); it++)
{
if(it->first>=min_index && it->first <=max_index)
{
if(removeMonitors)
MonitorSpectra.insert(static_cast<specid_t>(it->first));
if(!removeMonitors)
{
remaining_monitors.insert(*it);
m_numberOfSpectra++;
}
}
}
monitors.swap(remaining_monitors);
return separateMonitors;
}
Gigg, Martyn Anthony
committed
} // namespace DataHandling