Commit 9789588a authored by Jose Borreguero's avatar Jose Borreguero
Browse files

Refs #30887 purge getDetectorID from affected algorithms and exports

parent a9635b4c
......@@ -131,7 +131,7 @@ void AddAbsorptionWeightedPathLengths::exec() {
PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS))
for (int i = 0; i < npeaks; ++i) {
PARALLEL_START_INTERUPT_REGION
IPeak &peak = inputWS->getPeak(i);
Peak peak = inputWS->getPeak(i);
auto peakWavelength = peak.getWavelength();
std::vector<double> lambdas{peakWavelength}, absFactors(NLAMBDA),
......
......@@ -1074,8 +1074,8 @@ void CompareWorkspaces::doPeaksComparison(PeaksWorkspace_sptr tws1,
const double tolerance = getProperty("Tolerance");
for (int i = 0; i < tws1->getNumberPeaks(); i++) {
const IPeak &peak1 = tws1->getPeak(i);
const IPeak &peak2 = tws2->getPeak(i);
const Peak &peak1 = tws1->getPeak(i);
const Peak &peak2 = tws2->getPeak(i);
for (size_t j = 0; j < tws1->columnCount(); j++) {
std::shared_ptr<const API::Column> col = tws1->getColumn(j);
std::string name = col->name();
......
......@@ -310,7 +310,7 @@ int PeakIntegration::fitneighbours(int ipeak, const std::string &det_name,
UNUSED_ARG(det_name);
UNUSED_ARG(x0);
UNUSED_ARG(y0);
Geometry::IPeak &peak = Peaks->getPeak(ipeak);
Peak &peak = Peaks->getPeak(ipeak);
// Number of slices
int TOFmax = 0;
......
......@@ -27,8 +27,11 @@
using Mantid::API::Algorithm;
using Mantid::API::IPeaksWorkspace_sptr;
using Mantid::API::Progress;
using Mantid::DataObjects::Peak;
using Mantid::DataObjects::PeaksWorkspace;
using Mantid::DataObjects::PeaksWorkspace_sptr;
using Mantid::DataObjects::Peak_uptr;
using Mantid::Geometry::IPeak_uptr;
using Mantid::Geometry::HKLFilter;
using Mantid::Geometry::HKLFilter_uptr;
using Mantid::Geometry::HKLGenerator;
......@@ -246,16 +249,15 @@ IPeaksWorkspace_sptr predictFractionalPeaks(
if (qLab[2] <= 0)
continue;
using Mantid::Geometry::IPeak;
std::unique_ptr<IPeak> peak;
IPeak_uptr ipeak;
try {
peak = inputPeaks.createPeak(qLab);
ipeak = inputPeaks.createPeak(qLab);
} catch (...) {
// If we can't create a valid peak we have no choice but to skip
// it
continue;
}
Peak_uptr peak(static_cast<Peak*>(ipeak.release()));
peak->setGoniometerMatrix(gonioMatrix);
if (requirePeaksOnDetector && peak->getDetectorID() < 0)
continue;
......
......@@ -134,7 +134,7 @@ void SCDCalibratePanels2ObjFunc::function1D(double *out, const double *xValues,
// update instrument
pk.setInstrument(pws->getInstrument());
// update detector ID
pk.setDetectorID(pws->getPeak(i).getDetectorID());
pk.setDetectorID(pk.getDetectorID());
// calculate&set wavelength based on new instrument
Units::Wavelength wl;
wl.initialize(pk.getL1(), pk.getL2(), pk.getScattering(), 0,
......
......@@ -309,8 +309,6 @@ double BasePeak::getValueByColName(std::string name) const {
std::transform(name.begin(), name.end(), name.begin(), ::tolower);
if (name == "runnumber")
return double(this->getRunNumber());
else if (name == "detid")
return double(this->getDetectorID());
else if (name == "h")
return this->getH();
else if (name == "k")
......
......@@ -165,8 +165,7 @@ Peak::Peak(const Peak &other)
* @return
*/
Peak::Peak(const Geometry::IPeak &ipeak)
: BasePeak(ipeak), m_detectorID(ipeak.getDetectorID()),
m_initialEnergy(ipeak.getInitialEnergy()),
: BasePeak(ipeak), m_initialEnergy(ipeak.getInitialEnergy()),
m_finalEnergy(ipeak.getFinalEnergy()) {
const auto *peak = dynamic_cast<const Peak *>(&ipeak);
if (!peak)
......
......@@ -151,8 +151,11 @@ void PeakColumn<T>::print(size_t index, std::ostream &s) const {
std::ios::fmtflags fflags(s.flags());
if (m_name == "RunNumber")
s << peak.getRunNumber();
else if (m_name == "DetID")
s << peak.getDetectorID();
else if (m_name == "DetID") {
auto fullPeak = dynamic_cast<Peak *>(&peak);
if(fullPeak)
s << fullPeak->getDetectorID();
}
else if (m_name == "BankName")
s << peak.getBankName();
else if (m_name == "QLab")
......@@ -314,7 +317,8 @@ template <class T> const void *PeakColumn<T>::void_pointer(size_t index) const {
value = peak.getPeakNumber();
return boost::get<int>(&value);
} else if (m_name == "DetID") {
value = peak.getDetectorID();
auto fatPeak = dynamic_cast<const DataObjects::Peak&>(peak);
value = fatPeak.getDetectorID();
return boost::get<int>(&value);
} else if (m_name == "BankName") {
value = peak.getBankName();
......
......@@ -206,7 +206,7 @@ set<detid_t>
SpecialWorkspace2D::getDetectorIDs(const std::size_t workspaceIndex) const {
if (size_t(workspaceIndex) > this->getNumberHistograms())
throw std::invalid_argument(
"SpecialWorkspace2D::getDetectorID(): Invalid workspaceIndex given.");
"SpecialWorkspace2D::getDetectorIDs(): Invalid workspaceIndex given.");
return this->getSpectrum(workspaceIndex).getDetectorIDs();
}
......
......@@ -38,7 +38,6 @@ public:
TS_ASSERT_EQUALS(p.getQSampleFrame(), V3D(0, 0, 0))
TS_ASSERT_EQUALS(p.getQLabFrame(), V3D())
TS_ASSERT_THROWS(p.getDetectorID(), const Exception::NotImplementedError &)
TS_ASSERT_THROWS(p.getDetector(), const Exception::NotImplementedError &)
TS_ASSERT_THROWS(p.getDetectorPosition(),
const Exception::NotImplementedError &)
......
......@@ -25,7 +25,10 @@ using namespace Mantid::API;
using namespace Mantid::MDAlgorithms;
using namespace Mantid::Kernel;
using namespace Mantid::Geometry;
using Mantid::Geometry::IPeak_uptr;
using namespace Mantid::DataObjects;
using Mantid::DataObjects::Peak;
using Mantid::DataObjects::Peak_uptr;
using Mantid::Types::Event::TofEvent;
namespace {
......@@ -35,7 +38,8 @@ void addFakeEllipsoid(const V3D &peakHKL, const int &totalNPixels,
EventWorkspace_sptr &eventWS,
PeaksWorkspace_sptr &peaksWS) {
// Create the peak and add it to the peaks ws
auto peak = peaksWS->createPeakHKL(peakHKL);
IPeak_uptr ipeak = peaksWS->createPeakHKL(peakHKL);
Peak_uptr peak(dynamic_cast<Peak*>(ipeak.release()));
peaksWS->addPeak(*peak);
const auto detectorId = peak->getDetectorID();
const auto tofExact = peak->getTOF();
......@@ -78,7 +82,9 @@ void addFakeEllipsoid(const V3D &peakHKL, const int &totalNPixels,
auto detId = detectorId;
do {
step_perp[ivect] += 0.02;
auto pk = peaksWS->createPeak(Q + eigvects[ivect] * step_perp[ivect]);
auto q = Q + eigvects[ivect] * step_perp[ivect];
IPeak_uptr ipk = peaksWS->createPeak(q);
Peak_uptr pk(dynamic_cast<Peak*>(ipk.release()));
detId = pk->getDetectorID();
} while (detId == detectorId);
}
......@@ -87,7 +93,8 @@ void addFakeEllipsoid(const V3D &peakHKL, const int &totalNPixels,
for (int istep = -1; istep < 2; istep += 2) {
for (size_t ivect = 0; ivect < step_perp.size(); ivect++) {
auto q = Q + eigvects[ivect] * step_perp[ivect] * istep;
auto pk = peaksWS->createPeak(q);
IPeak_uptr ipk = peaksWS->createPeak(q);
Peak_uptr pk(dynamic_cast<Peak*>(ipk.release()));
// add event
auto detId = pk->getDetectorID();
EventList &el = eventWS->getSpectrum(detId - totalNPixels);
......
......@@ -23,7 +23,10 @@ using namespace Mantid;
using namespace Mantid::MDAlgorithms;
using namespace Mantid::Kernel;
using namespace Mantid::Geometry;
using Mantid::Geometry::IPeak_uptr;
using namespace Mantid::DataObjects;
using Mantid::DataObjects::Peak;
using Mantid::DataObjects::Peak_uptr;
using Mantid::Types::Event::TofEvent;
namespace {
......@@ -33,7 +36,8 @@ void addFakeEllipsoid(const V3D &peakHKL, const V3D &peakMNP,
const double tofGap, EventWorkspace_sptr &eventWS,
PeaksWorkspace_sptr &peaksWS) {
// Create the peak and add it to the peaks ws
auto peak = peaksWS->createPeakHKL(peakHKL);
IPeak_uptr ipeak = peaksWS->createPeakHKL(peakHKL);
Peak_uptr peak(dynamic_cast<Peak*>(ipeak.release()));
peak->setIntMNP(peakMNP);
peaksWS->addPeak(*peak);
const auto detectorId = peak->getDetectorID();
......@@ -77,7 +81,9 @@ void addFakeEllipsoid(const V3D &peakHKL, const V3D &peakMNP,
auto detId = detectorId;
do {
step_perp[ivect] += 0.02;
auto pk = peaksWS->createPeak(Q + eigvects[ivect] * step_perp[ivect]);
auto q = Q + eigvects[ivect] * step_perp[ivect];
IPeak_uptr ipk = peaksWS->createPeak(q);
Peak_uptr pk(dynamic_cast<Peak*>(ipk.release()));
detId = pk->getDetectorID();
} while (detId == detectorId);
}
......@@ -86,7 +92,8 @@ void addFakeEllipsoid(const V3D &peakHKL, const V3D &peakMNP,
for (int istep = -1; istep < 2; istep += 2) {
for (size_t ivect = 0; ivect < step_perp.size(); ivect++) {
auto q = Q + eigvects[ivect] * step_perp[ivect] * istep;
auto pk = peaksWS->createPeak(q);
IPeak_uptr ipk = peaksWS->createPeak(q);
Peak_uptr pk(dynamic_cast<Peak*>(ipk.release()));
// add event
auto detId = pk->getDetectorID();
EventList &el = eventWS->getSpectrum(detId - totalNPixels);
......
......@@ -26,7 +26,9 @@
using namespace Mantid;
using namespace Mantid::API;
using namespace Mantid::DataObjects;
using DataObjects::Peak_uptr;
using namespace Mantid::Geometry;
using Geometry::IPeak_uptr;
using namespace Mantid::Kernel;
using Mantid::Types::Event::TofEvent;
......@@ -162,7 +164,8 @@ void WorkspaceBuilder::createPeak(const HKLPeakDescriptor &descriptor) {
const auto sigmas = std::get<2>(descriptor);
// Create the peak and add it to the peaks ws
const auto peak = m_peaksWorkspace->createPeakHKL(hkl);
auto ipeak = m_peaksWorkspace->createPeakHKL(hkl);
Peak_uptr peak(dynamic_cast<Peak*>(ipeak.release()));
m_peaksWorkspace->addPeak(*peak);
// Get detector ID and TOF position of peak
......
......@@ -64,9 +64,9 @@ class WISHSingleCrystalPeakPredictionTest(MantidSystemTest):
BasicPeak = namedtuple('Peak', ('DetID', 'BankName', 'h', 'k', 'l'))
expected = BasicPeak(DetID=9202086, BankName='WISHpanel09', h=-5.0, k=-1.0, l=-7.0)
expected_peak_found = False
for full_peak in self._filtered:
peak = BasicPeak(DetID=full_peak.getDetectorID(), BankName=full_peak.getBankName(),
h=full_peak.getH(), k=full_peak.getK(), l=full_peak.getL())
for i in self._filtered.rowCount(): # iterate of the table representation of the PeaksWorkspace
peak_row = self._filtered.row(i)
peak = BasicPeak(**{k: peak_row[k] for k in BasicPeak._fields})
if peak == expected:
expected_peak_found = True
break
......
......@@ -43,11 +43,11 @@ Usage
AddPeakHKL(peak_ws, [2, 0, -4])
# Get info on newly added peak
peak = peak_ws.getPeak(0)
print('Peak wavelength {}'.format(round(peak.getWavelength(), 4)))
print('Peak detector id {}'.format(peak.getDetectorID()))
print('Peak run number {}'.format(peak.getRunNumber()))
print('Peak HKL {}'.format(peak.getHKL()))
peak = peak_ws.row(0)
print('Peak wavelength {}'.format(round(peak['Wavelength'], 4)))
print('Peak detector id {}'.format(peak['DetID']))
print('Peak run number {}'.format(peak['RunNumber']))
print('Peak HKL [{},{},{}]'.format(peak['h'], peak['k'], peak['l']))
Output:
......
......@@ -172,10 +172,10 @@ Usage
print('Output MDEventWorkspace has {} events.'.format(mdws.getNEvents()))
peakws = mtd['PeakTable']
print('There are {} peaks found in output MDWorkspace'.format(peakws.getNumberPeaks()))
peak = peakws.getPeak(0)
qsample = peak.getQSampleFrame()
peak = peakws.row(0)
qsample = peak['QSample']
print('In Q-sample frame, center of peak 0 is at ({:.5f}, {:.5f}, {:.5f}) at detector with ID {}'.
format(qsample.X(), qsample.Y(), qsample.Z(), peak.getDetectorID()))
format(qsample.X(), qsample.Y(), qsample.Z(), peak['DetID']))
.. testcleanup:: ExConvertHB3AToMDVirtualInstrument
......@@ -216,10 +216,10 @@ Output:
print('Output MDEventWorkspace has {} events.'.format(mdws.getNEvents()))
peakws = mtd['PeakTable']
print('There are {} peaks found in output MDWorkspace'.format(peakws.getNumberPeaks()))
peak = peakws.getPeak(0)
qsample = peak.getQSampleFrame()
peak = peakws.row(0)
qsample = peak['QSample']
print('In Q-sample frame, center of peak 0 is at ({:.5f}, {:.5f}, {:.5f}) at detector with ID {}'.
format(qsample.X(), qsample.Y(), qsample.Z(), peak.getDetectorID()))
format(qsample.X(), qsample.Y(), qsample.Z(), peak['DetID']))
.. testcleanup:: ExConvertHB3AToMDCopyInstrument
......
......@@ -20,6 +20,8 @@
namespace MantidQt {
namespace MantidWidgets {
using Mantid::Geometry::IPeak;
using Mantid::DataObjects::Peak;
/// Default size in screen pixels of the marker's symbol
const int PeakMarker2D::g_defaultMarkerSize = 5;
......@@ -122,14 +124,16 @@ void PeakMarker2D::drawSquare(QPainter &painter) const {
/**
* Save some peak information.
*/
void PeakMarker2D::setPeak(const Mantid::Geometry::IPeak &peak, int row) {
m_h = peak.getH();
m_k = peak.getK();
m_l = peak.getL();
void PeakMarker2D::setPeak(const IPeak &ipeak, int row) {
m_h = ipeak.getH();
m_k = ipeak.getK();
m_l = ipeak.getL();
m_label = QString("%1 %2 %3")
.arg(QString::number(m_h, 'g', 2), QString::number(m_k, 'g', 2),
QString::number(m_l, 'g', 2));
m_detID = peak.getDetectorID();
auto peak = dynamic_cast<const Peak*>(&ipeak);
if(peak)
m_detID = peak->getDetectorID();
m_row = row;
}
......
......@@ -148,20 +148,23 @@ class PeakReport(object):
svw.saveImage(filename)
# Create an image
img = Image(filename, width=150, height = 100)
img = Image(filename, width=150, height=100)
# Get the peak object
peak = peaks_workspace.getPeak(i)
infoData = [['PeakNumber:', i],['Run Number:', peak.getRunNumber()], ['Intensity:', peak.getIntensity()],
infoData = [['PeakNumber:', i], ['Run Number:', peak.getRunNumber()], ['Intensity:', peak.getIntensity()],
['TOF:', peak.getTOF()]]
coordData = [['Detector Id:', peak.getDetectorID()], ['Q Lab:', peak.getQLabFrame()],
['Q Sample:', peak.getQSampleFrame()], ['HKL:', peak.getHKL()]]
data = [[ img , Table(infoData), Table(coordData)]]
coordData = [['Q Lab:', peak.getQLabFrame()], ['Q Sample:', peak.getQSampleFrame()],
['HKL:', peak.getHKL()]]
if 'DetID' in peaks_workspace.getColumnNames():
detector_id = peaks_workspace.row(i)['DetID']
coordData = [['Detector Id:', detector_id]] + coordData
data = [[img , Table(infoData), Table(coordData)]]
colwidths = (150, 160, 160)
table = Table(data, colwidths, hAlign='LEFT')
parts.append(table)
parts.append(Spacer(0,10))
parts.append(Spacer(0, 10))
doc.build(parts)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment