Skip to content

Commit

Permalink
Re #6198. Fix clients of mapping methods in Crystal package.
Browse files Browse the repository at this point in the history
  • Loading branch information
RussellTaylor authored and gesnerpassos committed Sep 30, 2013
1 parent 553f7fe commit 8a44c33
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace Crystal
/// Input 2D Workspace
API::MatrixWorkspace_sptr inWS;
DataObjects::EventWorkspace_const_sptr eventW;
Mantid::detid2index_map * wi_to_detid_map;
Mantid::detid2index_map wi_to_detid_map;



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ class DLLExport IntegratePeakTimeSlices: public Mantid::API::Algorithm
boost::shared_ptr<DataModeHandler> AttributeValues ;
double ParameterValues[7] ;

Mantid::detid2index_map * wi_to_detid_map;
Mantid::detid2index_map wi_to_detid_map;

int* NeighborIDs;//Stores IDs of nearest neighbors
double R0 ; ///<for Weak Peaks, these can be set using info from close
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class DLLExport MaskPeaksWorkspace: public API::Algorithm
// Overridden Algorithm methods
void init();
void exec();
std::size_t getWkspIndex(detid2index_map * pixel_to_wi, Geometry::IComponent_const_sptr comp,
std::size_t getWkspIndex(const detid2index_map& pixel_to_wi, Geometry::IComponent_const_sptr comp,
const int x, const int y);
void getTofRange(double &tofMin, double &tofMax, const double tofPeak, const MantidVec& tof);
int findPixelID(std::string bankName, int col, int row);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class DLLExport PeakIntegration: public API::Algorithm
void fitSpectra(const int s, double TOFPeakd, double& I, double& sigI);
/// Read in all the input parameters
void retrieveProperties();
int fitneighbours(int ipeak, std::string det_name, int x0, int y0, int idet, double qspan, PeaksWorkspace_sptr &Peaks);
int fitneighbours(int ipeak, std::string det_name, int x0, int y0, int idet, double qspan,
PeaksWorkspace_sptr &Peaks, const detid2index_map& pixel_to_wi);

detid2index_map * pixel_to_wi; ///< Map of pixel to workspace index
bool IC; ///< Ikeida Carpenter fit of TOF

};
Expand Down
29 changes: 14 additions & 15 deletions Code/Mantid/Framework/Crystal/src/CentroidPeaks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Crystal
//----------------------------------------------------------------------------------------------
/** Constructor
*/
CentroidPeaks::CentroidPeaks() : wi_to_detid_map(NULL)
CentroidPeaks::CentroidPeaks()
{
}

Expand All @@ -41,7 +41,6 @@ namespace Crystal
*/
CentroidPeaks::~CentroidPeaks()
{
delete wi_to_detid_map;
}


Expand Down Expand Up @@ -101,9 +100,9 @@ namespace Crystal
int pixelID = peak.getDetectorID();

// Find the workspace index for this detector ID
if (wi_to_detid_map->find(pixelID) != wi_to_detid_map->end())
if (wi_to_detid_map.find(pixelID) != wi_to_detid_map.end())
{
size_t wi = (*wi_to_detid_map)[pixelID];
size_t wi = wi_to_detid_map[pixelID];
if(MinPeaks == -1 && peak.getRunNumber() == inWS->getRunNumber() && wi < Numberwi) MinPeaks = i;
if(peak.getRunNumber() == inWS->getRunNumber() && wi < Numberwi) MaxPeaks = i;
}
Expand All @@ -120,8 +119,8 @@ namespace Crystal
int col = peak.getCol();
int row = peak.getRow();
int pixelID = peak.getDetectorID();
detid2index_map::const_iterator it = wi_to_detid_map->find(pixelID);
if ( it == wi_to_detid_map->end() )
detid2index_map::const_iterator it = wi_to_detid_map.find(pixelID);
if ( it == wi_to_detid_map.end() )
{
continue;
}
Expand All @@ -131,8 +130,8 @@ namespace Crystal
int chan = Kernel::VectorHelper::getBinIndex(X, TOFPeakd);
std::string bankName = peak.getBankName();

double intensity = 0.0;
double chancentroid = 0.0;
double intensity = 0.0;
double chancentroid = 0.0;

int chanstart = std::max(0,chan-PeakRadius);
int chanend = std::min(static_cast<int>(X.size()),chan+PeakRadius);
Expand All @@ -149,8 +148,8 @@ namespace Crystal
for (int icol=colstart; icol<=colend; ++icol)
{
if (edgePixel(bankName, icol, irow, Edge))continue;
detid2index_map::const_iterator it = wi_to_detid_map->find(findPixelID(bankName, icol, irow));
if ( it == wi_to_detid_map->end() ) continue;
detid2index_map::const_iterator it = wi_to_detid_map.find(findPixelID(bankName, icol, irow));
if ( it == wi_to_detid_map.end() ) continue;
size_t workspaceIndex = (it->second);

const MantidVec & histogram = inWS->readY(workspaceIndex);
Expand All @@ -175,7 +174,7 @@ namespace Crystal
// Set wavelength to change tof for peak object
if (!edgePixel(bankName, col, row, Edge))
{
it = wi_to_detid_map->find(findPixelID(bankName, col, row));
it = wi_to_detid_map.find(findPixelID(bankName, col, row));
workspaceIndex = (it->second);
Mantid::Kernel::Units::Wavelength wl;
std::vector<double> timeflight;
Expand Down Expand Up @@ -240,9 +239,9 @@ namespace Crystal
int pixelID = peak.getDetectorID();

// Find the workspace index for this detector ID
if (wi_to_detid_map->find(pixelID) != wi_to_detid_map->end())
if (wi_to_detid_map.find(pixelID) != wi_to_detid_map.end())
{
size_t wi = (*wi_to_detid_map)[pixelID];
size_t wi = wi_to_detid_map[pixelID];
if(MinPeaks == -1 && peak.getRunNumber() == inWS->getRunNumber() && wi < Numberwi) MinPeaks = i;
if(peak.getRunNumber() == inWS->getRunNumber() && wi < Numberwi) MaxPeaks = i;
}
Expand All @@ -265,7 +264,7 @@ namespace Crystal
double tofcentroid = 0.0;
if (edgePixel(bankName, col, row, Edge))continue;
Mantid::detid2index_map::iterator it;
it = (*wi_to_detid_map).find(findPixelID(bankName, col, row));
it = wi_to_detid_map.find(findPixelID(bankName, col, row));

double tofstart = TOFPeakd*std::pow(1.004,-PeakRadius);
double tofend = TOFPeakd*std::pow(1.004,PeakRadius);
Expand All @@ -281,7 +280,7 @@ namespace Crystal
{
Mantid::detid2index_map::iterator it;
if (edgePixel(bankName, icol, irow, Edge))continue;
it = wi_to_detid_map->find(findPixelID(bankName, icol, irow));
it = wi_to_detid_map.find(findPixelID(bankName, icol, irow));
size_t workspaceIndex = (it->second);
EventList el = eventW->getEventList(workspaceIndex);
el.switchTo(WEIGHTED_NOTIME);
Expand Down
9 changes: 4 additions & 5 deletions Code/Mantid/Framework/Crystal/src/IntegratePeakTimeSlices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ namespace Mantid
}

IntegratePeakTimeSlices::IntegratePeakTimeSlices() :
Algorithm(), wi_to_detid_map(NULL), R0(-1)
Algorithm(), R0(-1)
{
debug = false;

Expand Down Expand Up @@ -200,7 +200,6 @@ namespace Mantid
/// Destructor
IntegratePeakTimeSlices::~IntegratePeakTimeSlices()
{
delete wi_to_detid_map;
delete [] NeighborIDs;
}

Expand Down Expand Up @@ -331,7 +330,7 @@ namespace Mantid
{

// Find the workspace index for this detector ID
detid2index_map::const_iterator it = wi_to_detid_map->find(detID);
detid2index_map::const_iterator it = wi_to_detid_map.find(detID);
size_t wsIndx = (it->second);

double R = CalculatePositionSpan( peak, dQ )/2;
Expand Down Expand Up @@ -1708,8 +1707,8 @@ namespace Mantid
int DetID = NeighborIDs[i];

size_t workspaceIndex ;
if( wi_to_detid_map->count(DetID)>0)
workspaceIndex= wi_to_detid_map->find(DetID)->second;
if( wi_to_detid_map.count(DetID)>0)
workspaceIndex= wi_to_detid_map.find(DetID)->second;
else
{
g_log.error("No workspaceIndex for detID="+DetID);
Expand Down
86 changes: 42 additions & 44 deletions Code/Mantid/Framework/Crystal/src/MaskPeaksWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace Mantid
PeaksWorkspace_const_sptr peaksW = getProperty("InPeaksWorkspace");

//To get the workspace index from the detector ID
detid2index_map * pixel_to_wi = inputW->getDetectorIDToWorkspaceIndexMap();
const detid2index_map pixel_to_wi = inputW->getDetectorIDToWorkspaceIndexMap();
//Get some stuff from the input workspace
Geometry::Instrument_const_sptr inst = inputW->getInstrument();

Expand Down Expand Up @@ -173,9 +173,6 @@ namespace Mantid
maskbinstb->setProperty("MaskingInformation", tablews);
maskbinstb->execute();

//Clean up memory
delete pixel_to_wi;

return;
}

Expand Down Expand Up @@ -207,52 +204,53 @@ namespace Mantid
}
}

size_t MaskPeaksWorkspace::getWkspIndex(detid2index_map *pixel_to_wi, Geometry::IComponent_const_sptr comp,
size_t MaskPeaksWorkspace::getWkspIndex(const detid2index_map& pixel_to_wi, Geometry::IComponent_const_sptr comp,
const int x, const int y)
{
Geometry::RectangularDetector_const_sptr det
= boost::dynamic_pointer_cast<const Geometry::RectangularDetector>(comp);
if(det)
{
if(x >= det->xpixels() || x < 0 || y >= det->ypixels() || y < 0) return EMPTY_INT();
if ( (x >= det->xpixels()) || (x < 0) // this check is unnecessary as callers are doing it too
|| (y >= det->ypixels()) || (y < 0)) // but just to make debugging easier
{
std::stringstream msg;
msg << "Failed to find workspace index for x=" << x << " y=" << y
<< "(max x=" << det->xpixels() << ", max y=" << det->ypixels() << ")";
throw std::runtime_error(msg.str());
}
if(det)
{
if(x >= det->xpixels() || x < 0 || y >= det->ypixels() || y < 0) return EMPTY_INT();
if ( (x >= det->xpixels()) || (x < 0) // this check is unnecessary as callers are doing it too
|| (y >= det->ypixels()) || (y < 0)) // but just to make debugging easier
{
std::stringstream msg;
msg << "Failed to find workspace index for x=" << x << " y=" << y
<< "(max x=" << det->xpixels() << ", max y=" << det->ypixels() << ")";
throw std::runtime_error(msg.str());
}

int pixelID = det->getAtXY(x,y)->getID();
int pixelID = det->getAtXY(x,y)->getID();

//Find the corresponding workspace index, if any
if (pixel_to_wi->find(pixelID) == pixel_to_wi->end())
{
std::stringstream msg;
msg << "Failed to find workspace index for x=" << x << " y=" << y;
throw std::runtime_error(msg.str());
}
return (*pixel_to_wi)[pixelID];
}
else
{
std::vector<Geometry::IComponent_const_sptr> children;
boost::shared_ptr<const Geometry::ICompAssembly> asmb = boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(comp);
asmb->getChildren(children, false);
boost::shared_ptr<const Geometry::ICompAssembly> asmb2 = boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(children[0]);
std::vector<Geometry::IComponent_const_sptr> grandchildren;
asmb2->getChildren(grandchildren,false);
int NROWS = static_cast<int>(grandchildren.size());
int NCOLS = static_cast<int>(children.size());
// Wish pixels and tubes start at 1 not 0
if(x-1 >= NCOLS || x-1 < 0 || y-1 >= NROWS || y-1 < 0) return EMPTY_INT();
std::string bankName = comp->getName();
detid2index_map::const_iterator it = pixel_to_wi->find(findPixelID(bankName, x, y));
if ( it == pixel_to_wi->end() ) return EMPTY_INT();
return (it->second);
}
return EMPTY_INT();
//Find the corresponding workspace index, if any
auto wiEntry = pixel_to_wi.find(pixelID);
if (wiEntry == pixel_to_wi.end())
{
std::stringstream msg;
msg << "Failed to find workspace index for x=" << x << " y=" << y;
throw std::runtime_error(msg.str());
}
return wiEntry->second;
}
else
{
std::vector<Geometry::IComponent_const_sptr> children;
boost::shared_ptr<const Geometry::ICompAssembly> asmb = boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(comp);
asmb->getChildren(children, false);
boost::shared_ptr<const Geometry::ICompAssembly> asmb2 = boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(children[0]);
std::vector<Geometry::IComponent_const_sptr> grandchildren;
asmb2->getChildren(grandchildren,false);
int NROWS = static_cast<int>(grandchildren.size());
int NCOLS = static_cast<int>(children.size());
// Wish pixels and tubes start at 1 not 0
if(x-1 >= NCOLS || x-1 < 0 || y-1 >= NROWS || y-1 < 0) return EMPTY_INT();
std::string bankName = comp->getName();
detid2index_map::const_iterator it = pixel_to_wi.find(findPixelID(bankName, x, y));
if ( it == pixel_to_wi.end() ) return EMPTY_INT();
return (it->second);
}
return EMPTY_INT();
}

/**
Expand Down

0 comments on commit 8a44c33

Please sign in to comment.