Skip to content

Commit

Permalink
Re #6198. Fix clients of mapping methods in Algorithms package.
Browse files Browse the repository at this point in the history
(At least 5 more places that weren't deleting the returned map.)
  • Loading branch information
RussellTaylor authored and gesnerpassos committed Sep 30, 2013
1 parent 59e1811 commit 553f7fe
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 61 deletions.
6 changes: 3 additions & 3 deletions Code/Mantid/Framework/API/src/MatrixWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ namespace Mantid
}
}

//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
/** Does the workspace has any grouped detectors?
* @return true if the workspace has any grouped detectors, otherwise false
*/
Expand All @@ -385,8 +385,8 @@ namespace Mantid
auto detList = getSpectrum(workspaceIndex)->getDetectorIDs();
if (detList.size() > 1)
{
retVal=true;
break;
retVal=true;
break;
}
}
return retVal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ class DLLExport GhostCorrection : public API::Algorithm, public API::DeprecatedA
/// Workspaces we are working with.
Mantid::DataObjects::EventWorkspace_const_sptr inputW;

/// Mapping between indices
detid2index_map * input_detectorIDToWorkspaceIndexMap;

/// Map where KEY = pixel ID; value = tof to D conversion factor (tof * factor = d).
std::map<detid_t, double> * tof_to_d;
};
Expand Down
9 changes: 4 additions & 5 deletions Code/Mantid/Framework/Algorithms/src/BinaryOperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1012,8 +1012,7 @@ namespace Mantid
// Initialize the table; filled with -1 meaning no match
table->resize(lhs_nhist, -1);

detid2index_map * rhs_det_to_wi;
rhs_det_to_wi = rhs->getDetectorIDToWorkspaceIndexMap();
const detid2index_map rhs_det_to_wi = rhs->getDetectorIDToWorkspaceIndexMap();

PARALLEL_FOR_NO_WSP_CHECK()
for (int lhsWI = 0; lhsWI < lhs_nhist; lhsWI++)
Expand Down Expand Up @@ -1042,7 +1041,7 @@ namespace Mantid


// ----------------- Scrambled Detector IDs with one Detector per Spectrum --------------------------------------
if (!done && rhs_det_to_wi && (lhsDets.size() == 1))
if (!done && (lhsDets.size() == 1))
{
//Didn't find it. Try to use the RHS map.

Expand All @@ -1051,8 +1050,8 @@ namespace Mantid
detid_t lhs_detector_ID = *lhsDets_it;

//Now we use the RHS map to find it. This only works if both the lhs and rhs have 1 detector per pixel
detid2index_map::iterator map_it = rhs_det_to_wi->find(lhs_detector_ID);
if (map_it != rhs_det_to_wi->end())
detid2index_map::const_iterator map_it = rhs_det_to_wi.find(lhs_detector_ID);
if (map_it != rhs_det_to_wi.end())
{
rhsWI = map_it->second; //This is the workspace index in the RHS that matched lhs_detector_ID
}
Expand Down
8 changes: 1 addition & 7 deletions Code/Mantid/Framework/Algorithms/src/DetectorDiagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,17 +553,11 @@ namespace Mantid
}

//check if not grouped. If grouped, it will throw
try
{
detid2index_map *d2i=countsWS->getDetectorIDToWorkspaceIndexMap(true);
d2i->clear();
}
catch(...)
if ( countsWS->hasGroupedDetectors() )
{
throw std::runtime_error("Median detector test: not able to create detector to spectra map. Try with LevelUp=0.");
}


for(size_t i=0;i < countsWS->getNumberHistograms();i++)
{
detid_t d=(*((countsWS->getSpectrum(i))->getDetectorIDs().begin()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ namespace Algorithms
}

// Keep original instrument and set the new instrument, if necessary
boost::shared_ptr<std::map<specid_t,size_t> > spec2indexmap(workspace->getSpectrumToWorkspaceIndexMap());
const auto spec2indexmap(workspace->getSpectrumToWorkspaceIndexMap());

// ??? Condition: spectrum has 1 and only 1 detector
size_t nspec = workspace->getNumberHistograms();
Expand All @@ -282,8 +282,8 @@ namespace Algorithms
for (size_t i = 0; i < specids.size(); i ++)
{
// Find spectrum's workspace index
spec2index_map::iterator it = spec2indexmap->find(specids[i]);
if (it == spec2indexmap->end())
spec2index_map::const_iterator it = spec2indexmap.find(specids[i]);
if (it == spec2indexmap.end())
{
stringstream errss;
errss << "Spectrum ID " << specids[i] << " is not found. "
Expand Down
11 changes: 7 additions & 4 deletions Code/Mantid/Framework/Algorithms/src/GetDetOffsetsMultiPeaks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ namespace Algorithms
// Create the output MaskWorkspace
MatrixWorkspace_sptr maskWS(new MaskWorkspace(inputW->getInstrument()));
//To get the workspace index from the detector ID
detid2index_map * pixel_to_wi = maskWS->getDetectorIDToWorkspaceIndexMap(true);
const detid2index_map pixel_to_wi = maskWS->getDetectorIDToWorkspaceIndexMap(true);
// the peak positions and where to fit
std::vector<double> peakPositions = getProperty("DReference");
std::sort(peakPositions.begin(), peakPositions.end());
Expand Down Expand Up @@ -445,16 +445,19 @@ namespace Algorithms
{
outputW->setValue(*it, offset, fitSum);
outputNP->setValue(*it, peakPosFittedSize, chisqSum);
const auto mapEntry = pixel_to_wi.find(*it);
if ( mapEntry == pixel_to_wi.end() ) continue;
const size_t workspaceIndex = mapEntry->second;
if (mask == 1.)
{
// Being masked
maskWS->maskWorkspaceIndex((*pixel_to_wi)[*it]);
maskWS->dataY((*pixel_to_wi)[*it])[0] = mask;
maskWS->maskWorkspaceIndex(workspaceIndex);
maskWS->dataY(workspaceIndex)[0] = mask;
}
else
{
// Using the detector
maskWS->dataY((*pixel_to_wi)[*it])[0] = mask;
maskWS->dataY(workspaceIndex)[0] = mask;
}
}

Expand Down
11 changes: 7 additions & 4 deletions Code/Mantid/Framework/Algorithms/src/GetDetectorOffsets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace Mantid
// Create the output MaskWorkspace
MaskWorkspace_sptr maskWS(new MaskWorkspace(inputW->getInstrument()));
//To get the workspace index from the detector ID
detid2index_map * pixel_to_wi = maskWS->getDetectorIDToWorkspaceIndexMap(true);
const detid2index_map pixel_to_wi = maskWS->getDetectorIDToWorkspaceIndexMap(true);

// Fit all the spectra with a gaussian
Progress prog(this, 0, 1.0, nspec);
Expand Down Expand Up @@ -141,16 +141,19 @@ namespace Mantid
for (it = dets.begin(); it != dets.end(); ++it)
{
outputW->setValue(*it, offset);
const auto mapEntry = pixel_to_wi.find(*it);
if ( mapEntry == pixel_to_wi.end() ) continue;
const size_t workspaceIndex = mapEntry->second;
if (mask == 1.)
{
// Being masked
maskWS->maskWorkspaceIndex((*pixel_to_wi)[*it]);
maskWS->dataY((*pixel_to_wi)[*it])[0] = mask;
maskWS->maskWorkspaceIndex(workspaceIndex);
maskWS->dataY(workspaceIndex)[0] = mask;
}
else
{
// Using the detector
maskWS->dataY((*pixel_to_wi)[*it])[0] = mask;
maskWS->dataY(workspaceIndex)[0] = mask;
}
}
}
Expand Down
13 changes: 5 additions & 8 deletions Code/Mantid/Framework/Algorithms/src/GhostCorrection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ namespace Mantid
this->tof_to_d = NULL;
this->groupedGhostMaps.clear();
this->rawGhostMap = NULL;
this->input_detectorIDToWorkspaceIndexMap = NULL;
this->useAlgorithm("");
this->deprecatedDate("2011-05-10");
}
Expand All @@ -63,7 +62,6 @@ namespace Mantid
{
delete this->tof_to_d;
delete this->rawGhostMap;
delete this->input_detectorIDToWorkspaceIndexMap;
for (size_t i=0; i < this->groupedGhostMaps.size(); i++)
delete this->groupedGhostMaps[i];
}
Expand Down Expand Up @@ -120,6 +118,9 @@ namespace Mantid
*/
void GhostCorrection::loadGhostMap(std::string ghostMapFile)
{
//Prepare the map you need
const auto input_detectorIDToWorkspaceIndexMap = inputW->getDetectorIDToWorkspaceIndexMap(true);

//Open the file
BinaryFile<GhostDestinationValue> ghostFile(ghostMapFile);

Expand All @@ -143,10 +144,9 @@ namespace Mantid
for (int inPixelId = 0; inPixelId < numInPixels; inPixelId++)
{
//Find the input workspace index corresponding to this input Pixel ID
detid2index_map::iterator it;
it = input_detectorIDToWorkspaceIndexMap->find(inPixelId);
auto it = input_detectorIDToWorkspaceIndexMap.find(inPixelId);

if (it != input_detectorIDToWorkspaceIndexMap->end())
if (it != input_detectorIDToWorkspaceIndexMap.end())
{
//A valid workspace index was found, this one:
int64_t inputWorkspaceIndex = it->second;
Expand Down Expand Up @@ -264,9 +264,6 @@ namespace Mantid
for (std::size_t i=0; i < outputWS2D->getNumberHistograms(); i++)
outputWS2D->setX(i, XValues_new);

//Prepare the maps you need
input_detectorIDToWorkspaceIndexMap = inputW->getDetectorIDToWorkspaceIndexMap(true);

//Load the ghostmapping file
this->loadGhostMap( getProperty("GhostCorrectionFilename") );

Expand Down
8 changes: 3 additions & 5 deletions Code/Mantid/Framework/Algorithms/src/MaskBinsFromTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,12 @@ namespace Algorithms
// Get workspace index from
vector<size_t> wsindexvec;

detid2index_map* refermap = dataws->getDetectorIDToWorkspaceIndexMap(false);
detid2index_map refermap = dataws->getDetectorIDToWorkspaceIndexMap(false);
for (size_t i = 0; i < numitems; ++i)
{
detid_t detid = detidvec[i];
detid2index_map::iterator fiter = refermap->find(detid);
if (fiter != refermap->end())
detid2index_map::const_iterator fiter = refermap.find(detid);
if (fiter != refermap.end())
{
size_t wsindex = fiter->second;
wsindexvec.push_back(wsindex);
Expand All @@ -282,8 +282,6 @@ namespace Algorithms
}
}

delete refermap;

// Sort the vector
if (wsindexvec.size() == 0)
throw runtime_error("There is no spectrum found for input detectors list.");
Expand Down
11 changes: 4 additions & 7 deletions Code/Mantid/Framework/Algorithms/src/MergeRuns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void MergeRuns::buildAdditionTables()
EventWorkspace_sptr lhs = m_inEventWS[0];
int lhs_nhist = static_cast<int>(lhs->getNumberHistograms());

detid2index_map * lhs_det_to_wi = NULL;
detid2index_map lhs_det_to_wi;
try
{
lhs_det_to_wi = lhs->getDetectorIDToWorkspaceIndexMap(true);
Expand Down Expand Up @@ -240,7 +240,7 @@ void MergeRuns::buildAdditionTables()
}
}

if (!done && lhs_det_to_wi && (inDets.size() == 1))
if (!done && !lhs_det_to_wi.empty() && (inDets.size() == 1))
{
//Didn't find it. Try to use the LHS map.

Expand All @@ -249,8 +249,8 @@ void MergeRuns::buildAdditionTables()
detid_t rhs_detector_ID = *inDets_it;

//Now we use the LHS map to find it. This only works if both the lhs and rhs have 1 detector per pixel
detid2index_map::iterator map_it = lhs_det_to_wi->find(rhs_detector_ID);
if (map_it != lhs_det_to_wi->end())
detid2index_map::const_iterator map_it = lhs_det_to_wi.find(rhs_detector_ID);
if (map_it != lhs_det_to_wi.end())
{
outWI = static_cast<int>(map_it->second); //This is the workspace index in the LHS that matched rhs_detector_ID
}
Expand Down Expand Up @@ -299,9 +299,6 @@ void MergeRuns::buildAdditionTables()

} //each of the workspaces being added

//Free up memory
delete lhs_det_to_wi;

if (m_tables.size() != m_inEventWS.size()-1)
throw std::runtime_error("MergeRuns::buildAdditionTables: Mismatch between the number of addition tables and the number of workspaces");

Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/Algorithms/src/RayTracerTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace Algorithms
setProperty("OutputWorkspace", mws);
Workspace2D_sptr ws = boost::dynamic_pointer_cast<Workspace2D>(mws);

detid2index_map * detTowi = ws->getDetectorIDToWorkspaceIndexMap();
detid2index_map detTowi = ws->getDetectorIDToWorkspaceIndexMap();
for (size_t i=0; i<ws->getNumberHistograms(); i++)
ws->dataY(i)[0] = 0.0;

Expand All @@ -103,7 +103,7 @@ namespace Algorithms
IDetector_const_sptr det = tracker.getDetectorResult();
if (det)
{
size_t wi = (*detTowi)[det->getID()];
size_t wi = detTowi[det->getID()];
g_log.information() << "Found detector " << det->getID() << std::endl;
ws->dataY(wi)[0] = double(int(az*57.3)*1000 + int(iz));
}
Expand Down
17 changes: 7 additions & 10 deletions Code/Mantid/Framework/Algorithms/src/SmoothNeighbours.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void SmoothNeighbours::findNeighboursRectangular()
Instrument_const_sptr inst = inWS->getInstrument();

//To get the workspace index from the detector ID
detid2index_map * pixel_to_wi = inWS->getDetectorIDToWorkspaceIndexMap(true);
const detid2index_map pixel_to_wi = inWS->getDetectorIDToWorkspaceIndexMap(true);

//std::cout << " inst->nelements() " << inst->nelements() << "\n";
Progress prog(this,0.0,1.0,inst->nelements());
Expand Down Expand Up @@ -374,9 +374,10 @@ void SmoothNeighbours::findNeighboursRectangular()
int pixelID = det->getAtXY(j+ix,k+iy)->getID();

//Find the corresponding workspace index, if any
if (pixel_to_wi->find(pixelID) != pixel_to_wi->end())
auto mapEntry = pixel_to_wi.find(pixelID);
if (mapEntry != pixel_to_wi.end())
{
size_t wi = (*pixel_to_wi)[pixelID];
size_t wi = mapEntry->second;
neighbours.push_back( weightedNeighbour(wi, smweight) );
// Count the total weight
totalWeight += smweight;
Expand All @@ -398,9 +399,6 @@ void SmoothNeighbours::findNeighboursRectangular()
prog.report(det_name);
}


delete pixel_to_wi;

}


Expand All @@ -420,7 +418,7 @@ void SmoothNeighbours::findNeighboursUbiqutious()
this->progress(0.2, "Building Neighbour Map");

Instrument_const_sptr inst = inWS->getInstrument();
spec2index_map * spec2index = inWS->getSpectrumToWorkspaceIndexMap();
const spec2index_map spec2index = inWS->getSpectrumToWorkspaceIndexMap();

// Resize the vector we are setting
m_neighbours.resize(inWS->getNumberHistograms());
Expand Down Expand Up @@ -494,8 +492,8 @@ void SmoothNeighbours::findNeighboursUbiqutious()
if (weight > 0)
{
// Find the corresponding workspace index
spec2index_map::iterator mapIt = spec2index->find(spec);
if (mapIt != spec2index->end())
spec2index_map::const_iterator mapIt = spec2index.find(spec);
if (mapIt != spec2index.end())
{
size_t neighWI = mapIt->second;
if(sum > 1)
Expand Down Expand Up @@ -523,7 +521,6 @@ void SmoothNeighbours::findNeighboursUbiqutious()
m_prog->report("Finding Neighbours");
} // each workspace index

delete spec2index;
delete [] used;
}

Expand Down

0 comments on commit 553f7fe

Please sign in to comment.