Skip to content

Commit

Permalink
Re #6192. Prefer setting spectrum number via ISpectrum class.
Browse files Browse the repository at this point in the history
Rather than going via the axis.
  • Loading branch information
RussellTaylor committed Mar 11, 2013
1 parent ec6b29d commit f77c635
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ namespace DataHandling
workspace->setX(wi, m_bins);
MantidVec& y = workspace->dataY( wi );
MantidVec& e = workspace->dataE( wi );
workspace->getAxis(1)->setValue( wi, static_cast<specid_t>( index + i ));
workspace->getSpectrum(wi)->setSpectrumNo(index+1);
size_t shift = i * (m_numberOfBins + 1);
y.assign( dataBuffer.begin() + shift, dataBuffer.begin() + shift + y.size() );
std::transform( y.begin(), y.end(), e.begin(), dblSqrt );
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/DataHandling/src/LoadAscii.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ namespace Mantid
if ( haveErrors ) localWorkspace->dataE(i) = spectra[i].dataE();
if ( haveXErrors ) localWorkspace->dataDx(i) = spectra[i].dataDx();
// Just have spectrum number start at 1 and count up
localWorkspace->getAxis(1)->setValue(i, static_cast<specid_t>(i+1));
localWorkspace->getSpectrum(i)->setSpectrumNo(static_cast<specid_t>(i)+1);
}
return localWorkspace;
}
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/DataHandling/src/LoadDAE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ namespace Mantid
// Shift the histogram to read if we're not in the first period
int histToRead = i + period*(total_specs+1);
loadData(timeChannelsVec,counter,histToRead,dae_handle,lengthIn,spectrum.get(),localWorkspace,allData.get() );
localWorkspace->getAxis(1)->setValue(counter, i);
localWorkspace->getSpectrum(counter)->setSpectrumNo(i);
counter++;
if (++histCurrent % 10 == 0) progress(double(histCurrent)/histTotal);
interruption_point();
Expand All @@ -377,7 +377,7 @@ namespace Mantid
for(unsigned int i=0; i < m_spec_list.size(); ++i)
{
loadData(timeChannelsVec,counter,m_spec_list[i],dae_handle,lengthIn,spectrum.get(), localWorkspace,allData.get() );
localWorkspace->getAxis(1)->setValue(counter, i);
localWorkspace->getSpectrum(counter)->setSpectrumNo(i);
counter++;
if (++histCurrent % 10 == 0) progress(double(histCurrent)/histTotal);
interruption_point();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,9 @@ namespace DataHandling
size_t numvectors = spectrumidgroupmap.size();
mGroupWS = DataObjects::GroupingWorkspace_sptr(new DataObjects::GroupingWorkspace(numvectors));

API::SpectraAxis * ax = dynamic_cast<API::SpectraAxis * >( mGroupWS->getAxis(1));
if (!ax)
throw std::runtime_error("MatrixWorkspace::getSpectrumToWorkspaceIndexMap: axis[1] is not a SpectraAxis, so I cannot generate a map.");

for (size_t i = 0; i < mGroupWS->getNumberHistograms(); i ++)
{
ax->setValue(i, static_cast<double>(specids[i]));
mGroupWS->getSpectrum(i)->setSpectrumNo(specids[i]);
}

return;
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/DataHandling/src/LoadISISNexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ namespace Mantid
std::transform(Y.begin(), Y.end(), E.begin(), dblSqrt);
// Populate the workspace. Loop starts from 1, hence i-1
localWorkspace->setX(hist, m_timeChannelsVec);
localWorkspace->getAxis(1)->setValue(hist, m_spec[i]);
//localWorkspace->getAxis(1)->setValue(hist, m_spec[i]);

m_filehandle->closeData();
}
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ namespace Mantid
Y.assign(mondata(),mondata() + m_numberOfChannels);
MantidVec& E = local_workspace->dataE(hist_index);
std::transform(Y.begin(), Y.end(), E.begin(), dblSqrt);
local_workspace->getAxis(1)->setValue(hist_index, static_cast<specid_t>(it->first));
//local_workspace->getAxis(1)->setValue(hist_index, static_cast<specid_t>(it->first));

NXFloat timeBins = monitor.openNXFloat("time_of_flight");
timeBins.load();
Expand Down Expand Up @@ -621,7 +621,7 @@ namespace Mantid
std::transform(Y.begin(), Y.end(), E.begin(), dblSqrt);
// Populate the workspace. Loop starts from 1, hence i-1
local_workspace->setX(hist, m_tof_data);
local_workspace->getAxis(1)->setValue(hist, static_cast<specid_t>(spec_num));
//local_workspace->getAxis(1)->setValue(hist, static_cast<specid_t>(spec_num));
++hist;
++spec_num;
}
Expand Down
7 changes: 3 additions & 4 deletions Code/Mantid/Framework/DataHandling/src/LoadNexusProcessed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ API::Workspace_sptr LoadNexusProcessed::loadEntry(NXRoot & root, const std::stri
g_log.information() << "Axis 0 set to unitless quantity \"" << unit1 << "\"\n";
}

// Setting a unit onto a SpectraAxis makes no sense.
// Setting a unit onto a TextAxis makes no sense.
if ( unit2 == "TextAxis" )
{
Mantid::API::TextAxis* newAxis = new Mantid::API::TextAxis(nspectra);
Expand Down Expand Up @@ -1020,7 +1020,6 @@ void LoadNexusProcessed::readInstrumentGroup(NXEntry & mtd_entry, API::MatrixWor

//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)
Expand All @@ -1034,11 +1033,11 @@ void LoadNexusProcessed::readInstrumentGroup(NXEntry & mtd_entry, API::MatrixWor
{
if( m_axis1vals.empty() )
{
axis1->setValue(index, spectrum);
local_workspace->getSpectrum(index)->setSpectrumNo(spectrum);
}
else
{
axis1->setValue(index, m_axis1vals[i-1]);
local_workspace->getSpectrum(index)->setSpectrumNo(static_cast<specid_t>(m_axis1vals[i-1]));
}
++index;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void LoadPreNexusMonitors::exec()
// Just have spectrum number be the same as the monitor number but -ve.
detector_numbers[i] = -monitorIDs[i];
spectra_numbers[i] = monitorIDs[i];
localWorkspace->getAxis(1)->setValue(i, monitorIDs[i]);
localWorkspace->getSpectrum(i)->setSpectrumNo(monitorIDs[i]);
}

g_log.debug() << "Setting axis zero to TOF" << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/DataHandling/src/LoadRaw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ namespace Mantid
// Populate the workspace. Loop starts from 1, hence i-1
localWorkspace->setX(hist, tcbs);

localWorkspace->getAxis(1)->setValue(hist, i);
localWorkspace->getSpectrum(hist)->setSpectrumNo(i);
// NOTE: Raw numbers go straight into the workspace
// - no account taken of bin widths/units etc.
}
Expand Down
10 changes: 6 additions & 4 deletions Code/Mantid/Framework/DataHandling/src/LoadRaw2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ namespace Mantid
progress(0.,"Reading raw file...");
helper->loadRunParameters(localWorkspace, isisRaw.get());
runLoadInstrument(localWorkspace );
for (int i = 0; i < m_numberOfSpectra; ++i)
{
localWorkspace->getSpectrum(i)->setSpectrumNo(i+1);
}
runLoadMappingTable(localWorkspace );
runLoadLog(localWorkspace );
const int period_number = 1;
Expand All @@ -173,9 +177,7 @@ namespace Mantid
localWorkspace->mutableRun().addLogData(log);
localWorkspace->mutableRun().addLogData(createCurrentPeriodLog(period_number));
}
localWorkspace->mutableRun().setProtonCharge(isisRaw->rpb.r_gd_prtn_chrg);
for (int i = 0; i < m_numberOfSpectra; ++i)
localWorkspace->getAxis(1)->setValue(i, i+1);
localWorkspace->mutableRun().setProtonCharge(isisRaw->rpb.r_gd_prtn_chrg);
localWorkspace->populateInstrumentParameters();
setProperty("OutputWorkspace",localWorkspace);
return;
Expand Down Expand Up @@ -230,7 +232,7 @@ namespace Mantid
std::transform(Y.begin(), Y.end(), E.begin(), dblSqrt);
// Set the X vector pointer and spectrum number
localWorkspace->setX(counter, timeChannelsVec);
localWorkspace->getAxis(1)->setValue(counter, i);
localWorkspace->getSpectrum(counter)->setSpectrumNo(i);
// NOTE: Raw numbers go straight into the workspace
// - no account taken of bin widths/units etc.
++counter;
Expand Down
6 changes: 1 addition & 5 deletions Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ namespace Mantid
monitorwsList.push_back(static_cast<specid_t>(wsItr->second));
if (bseparate)
{
monitorWorkspace->getAxis(1)->setValue(monitorwsIndex, static_cast<specid_t>(i + 1));
monitorWorkspace->getSpectrum(monitorwsIndex)->setSpectrumNo(i+1);
setWorkspaceData(monitorWorkspace, m_timeChannelsVec, monitorwsIndex, i + 1, m_noTimeRegimes,m_lengthIn,1);
++monitorwsIndex;
}
Expand All @@ -696,10 +696,6 @@ namespace Mantid
if ((bseparate && !monitorwsList.empty()) || bexclude)
{
localWorkspace->setMonitorList(monitorwsList);
// RJT: Comment this out on removal of method from Workspace2D. This whole method doesn't do
// the right thing anyway, so this only makes things slightly worse pending a fix.
// localWorkspace->sethistogramNumbers(
// m_numberOfSpectra - static_cast<int64_t>(monitorwsList.size()));
if (bseparate)
{
fclose(file);
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ namespace Mantid
MantidVec& E = newWorkspace->dataE(wsIndex);
std::transform(Y.begin(), Y.end(), E.begin(), dblSqrt);

newWorkspace->getAxis(1)->setValue(wsIndex, nspecNum);
newWorkspace->getSpectrum(wsIndex)->setSpectrumNo(nspecNum);
//for loadrawbin0
if(binStart==0)
{
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/DataHandling/src/LoadSNSspec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ namespace Mantid
localWorkspace->dataY(i) = spectra[i].dataY();
localWorkspace->dataE(i) = spectra[i].dataE();
// Just have spectrum number start at 1 and count up
localWorkspace->getAxis(1)->setValue(i, i+1);
localWorkspace->getSpectrum(i)->setSpectrumNo(i+1);
}

setProperty("OutputWorkspace",localWorkspace);
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/DataHandling/src/LoadSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ namespace Mantid
localWorkspace->dataY(i) = spectra[i].dataY();
localWorkspace->dataE(i) = spectra[i].dataE();
// Just have spectrum number start at 1 and count up
localWorkspace->getAxis(1)->setValue(i, i+1);
localWorkspace->getSpectrum(i)->setSpectrumNo(i+1);
}

setProperty("OutputWorkspace",localWorkspace);
Expand Down
5 changes: 1 addition & 4 deletions Code/Mantid/Framework/DataHandling/src/LoadSpice2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ namespace Mantid
X[1] = wavelength+dwavelength/2.0;
Y[0] = value;
E[0] = error;
ws->getAxis(1)->setValue(specID, specID);
ws->getSpectrum(specID)->setSpectrumNo(specID);
}


Expand Down Expand Up @@ -341,9 +341,6 @@ namespace Mantid

store_value(ws, ipixel, count, error, wavelength, dwavelength);

// Set the spectrum number
ws->getAxis(1)->setValue(ipixel, ipixel);

++pixel;
ipixel++;
}
Expand Down

0 comments on commit f77c635

Please sign in to comment.