Skip to content

Commit

Permalink
Added another method for detector to group map. Refs #4208.
Browse files Browse the repository at this point in the history
Since vectors are significantly faster than maps, added a function to generate one.
  • Loading branch information
peterfpeterson committed Dec 8, 2011
1 parent e7e8986 commit 2ae1451
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace DataObjects
virtual const std::string id() const {return "GroupingWorkspace";}

void makeDetectorIDToGroupMap(std::map<detid_t, int> & detIDToGroup, int64_t & ngroups) const;
void makeDetectorIDToGroupVector(std::vector<int> &detIDToGroup, int64_t &ngroups) const;

private:
/// Private copy constructor. NO COPY ALLOWED
Expand Down
28 changes: 27 additions & 1 deletion Code/Mantid/Framework/DataObjects/src/GroupingWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace DataObjects
for (size_t wi=0; wi<this->m_noVectors; ++wi)
{
// Convert the Y value to a group number
int group = static_cast<int>(this->dataY(wi)[0]);
int group = static_cast<int>(this->readY(wi)[0]);
if (group == 0) group = -1;
detid_t detID = detectorIDs[wi];
detIDToGroup[detID] = group;
Expand All @@ -66,6 +66,32 @@ namespace DataObjects
}
}

/**
* Fill a map where the index is detector ID and the value is the
* group number by using the values in Y.
* Group values of 0 are converted to -1.
*
* @param detIDToGroup :: ref. to map to fill
* @param[out] ngroups :: the number of groups found (equal to the largest group number found)
*/
void GroupingWorkspace::makeDetectorIDToGroupVector(std::vector<int> &detIDToGroup, int64_t &ngroups) const
{
ngroups = 0;
for (size_t wi=0; wi<this->m_noVectors; ++wi)
{
// Convert the Y value to a group number
int group = static_cast<int>(this->readY(wi)[0]);
if (group == 0) group = -1;
detid_t detID = detectorIDs[wi];
if (detID < 0) // if you need negative detector ids, use the other function
continue;
if (detIDToGroup.size() < static_cast<size_t>(detID + 1))
detIDToGroup.resize(detID+1);
detIDToGroup[detID] = group;
if (group > ngroups)
ngroups = group;
}
}


} // namespace Mantid
Expand Down

0 comments on commit 2ae1451

Please sign in to comment.