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. The remaining uses of Axis::setValue
in this package are where the axis is (or could be) a NumericAxis.
  • Loading branch information
RussellTaylor committed Mar 11, 2013
1 parent 503080b commit 1188cc7
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 33 deletions.
11 changes: 3 additions & 8 deletions Code/Mantid/Framework/Algorithms/src/DiffractionFocussing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,10 @@ void DiffractionFocussing::exec()
// Create a new workspace that's the right size for the meaningful spectra and copy them in
int64_t newSize = tmpW->blocksize();
API::MatrixWorkspace_sptr outputW = API::WorkspaceFactory::Instance().create(tmpW,resultIndeces.size(),newSize+1,newSize);
// Copy units
outputW->getAxis(0)->unit() = tmpW->getAxis(0)->unit();
outputW->getAxis(1)->unit() = tmpW->getAxis(1)->unit();

API::Axis *spectraAxisNew = outputW->getAxis(1);

for(int64_t hist=0; hist < static_cast<int64_t>(resultIndeces.size()); hist++)
{
int64_t i = resultIndeces[hist];
double spNo = static_cast<double>(spectraAxis->spectraNo(i));
MantidVec &tmpE = tmpW->dataE(i);
MantidVec &outE = outputW->dataE(hist);
MantidVec &tmpY = tmpW->dataY(i);
Expand All @@ -194,8 +188,9 @@ void DiffractionFocussing::exec()
outE.assign(tmpE.begin(),tmpE.end());
outY.assign(tmpY.begin(),tmpY.end());
outX.assign(tmpX.begin(),tmpX.end());
spectraAxisNew->setValue(hist,spNo);
spectraAxis->setValue(i,-1);
API::ISpectrum * inSpec = tmpW->getSpectrum(i);
outputW->getSpectrum(hist)->setSpectrumNo(inSpec->getSpectrumNo());
inSpec->setSpectrumNo(-1);
}

progress(1.);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ namespace Mantid
for (int i = spec_min; i <= spec_max; i++)
{
int out_index = i - spec_min;
out->getAxis(1)->setValue(out_index, inputWS->getAxis(1)->spectraNo(i));
out->getSpectrum(out_index)->setSpectrumNo(inputWS->getSpectrum(i)->getSpectrumNo());
const MantidVec& refX = inputWS->readX(i);
const MantidVec& refY = inputWS->readY(i);
const MantidVec& refE = inputWS->readE(i);
Expand All @@ -145,10 +145,6 @@ namespace Mantid
}
setProperty("OutputWorkspace", out);

// Now do some cleanup, necessary at this time since destructor is not called
Cij.clear();
Cij2.clear();

return;
}
/** Compute the Cij
Expand Down
14 changes: 2 additions & 12 deletions Code/Mantid/Framework/Algorithms/src/GeneratePeaks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,26 +382,16 @@ namespace Algorithms
for (size_t ip = 0; ip < spectra.size(); ip ++)
std::copy(xarray.begin(), xarray.end(), ws->dataX(ip).begin());

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

// 3. Set spectrum numbers
std::map<specid_t, specid_t>::iterator spiter;
for (spiter = mSpectrumMap.begin(); spiter != mSpectrumMap.end(); ++spiter)
{
specid_t specid = spiter->first;
specid_t wsindex = spiter->second;
g_log.debug() << "Build WorkspaceIndex-Spectrum " << wsindex << " , " << specid << std::endl;
ax->setValue(wsindex, specid);
ws->getSpectrum(wsindex)->setSpectrumNo(specid);
}

// TODO Remove after test
spec2index_map* tmap = ws->getSpectrumToWorkspaceIndexMap();
spec2index_map::iterator titer;
for (titer = tmap->begin(); titer != tmap->end(); ++titer)
g_log.notice() << "Map built: wsindex = " << titer->first << "\t\tspectrum = " << titer->second << std::endl;

return ws;
}

Expand Down
8 changes: 2 additions & 6 deletions Code/Mantid/Framework/Algorithms/src/MaxMin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ void MaxMin::init()
mustBePositive->setLower(0);
declareProperty("StartWorkspaceIndex",0, mustBePositive,
"Start spectrum number (default 0)");
// As the property takes ownership of the validator pointer, have to take care to pass in a unique
// pointer to each property.
declareProperty("EndWorkspaceIndex",EMPTY_INT(), mustBePositive,
"End spectrum number (default max)");
}
Expand Down Expand Up @@ -105,10 +103,8 @@ void MaxMin::exec()
{
PARALLEL_START_INTERUPT_REGION
int newindex=i-m_MinSpec;
if (localworkspace->axes() > 1)
{
outputWorkspace->getAxis(1)->setValue(newindex, localworkspace->getAxis(1)->spectraNo(i));
}
// Copy over spectrum and detector number info
outputWorkspace->getSpectrum(newindex)->copyInfoFrom(*localworkspace->getSpectrum(i));

// Retrieve the spectrum into a vector
const MantidVec& X = localworkspace->readX(i);
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/Algorithms/src/SolidAngle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ namespace Mantid
PARALLEL_START_INTERUPT_REGION
int i = j + m_MinSpec;
try {
// Get the spectrum number for this histogram
outputWS->getAxis(1)->setValue(j, inputWS->getAxis(1)->spectraNo(i));
// Copy over the spectrum number & detector IDs
outputWS->getSpectrum(j)->copyInfoFrom(*inputWS->getSpectrum(i));
// Now get the detector to which this relates
Geometry::IDetector_const_sptr det = inputWS->getDetector(i);
// Solid angle should be zero if detector is masked ('dead')
Expand Down

0 comments on commit 1188cc7

Please sign in to comment.