Skip to content

Commit

Permalink
Fixed the system test and a memory leak. Refs #7336.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdzhou committed Jul 11, 2013
1 parent 6564527 commit 51e9bff
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ def __getWavelength(self, frequency, request):
raise RuntimeError("Failed to find wavelength: %fAngstrom" % request)

def getInfo(self, frequency, wavelength):
#print "getInfo(%f, %f)" % (frequency, wavelength)
if self.filename is not None:
if frequency is None:
raise RuntimeError("Unable to determine frequency from data")
Expand Down Expand Up @@ -313,6 +312,29 @@ def PyExec(self):
workspacelist = [] # all data workspaces that will be converted to d-spacing in the end
samwksplist = []

self._lowResTOFoffset = self.getProperty("LowResolutionSpectraOffset").value
focuspos = self._config.getFocusPos()
if self._lowResTOFoffset >= 0:
# Dealing with the parameters for editing instrument parameters
if focuspos.has_key("PrimaryFlightPath") is True:
l1 = focuspos["PrimaryFlightPath"]
if l1 > 0:
specids = focuspos['SpectrumIDs'][:]
l2s = focuspos['L2'][:]
polars = focuspos['Polar'][:]
phis = focuspos['Azimuthal'][:]

specids.extend(specids)
l2s.extend(l2s)
polars.extend(polars)
phis.extend(phis)

focuspos['SpectrumIDs'] = specids
focuspos['L2'] = l2s
focuspos['Polar'] = polars
focuspos['Azimuthal'] = phis
# ENDIF

if self.getProperty("Sum").value:
# Sum input sample runs and then do reduction
if self._splitws is not None:
Expand Down Expand Up @@ -430,10 +452,10 @@ def PyExec(self):

# process the vanadium run
vanRun = self.getProperty("VanadiumNumber").value
self.log().information("F313A: Correction SamRun = %s, VanRun = %s of type %s" % (str(samRun), str(vanRun), str(type(vanRun))))
self.log().debug("F313A: Correction SamRun = %s, VanRun = %s of type %s" % (str(samRun), str(vanRun), str(type(vanRun))))
if vanRun == 0: # use the version in the info
vanRun = self._info.van
self.log().information("F313B: Van Correction SamRun = %s, VanRun = %s" % (str(samRun), str(vanRun)))
self.log().debug("F313B: Van Correction SamRun = %s, VanRun = %s" % (str(samRun), str(vanRun)))
elif vanRun < 0: # turn off the correction
vanRun = 0
self.log().information("F313C: Correction SamRun = %s, VanRun = %s of type %s" % (str(samRun), str(vanRun), str(type(vanRun))))
Expand Down Expand Up @@ -524,11 +546,11 @@ def PyExec(self):
return
if self.getProperty("StripVanadiumPeaks").value:
vanRun = api.ConvertUnits(InputWorkspace=vanRun, OutputWorkspace=vanRun, Target="dSpacing")
api.CloneWorkspace(InputWorkspace=vanRun, OutputWorkspace=str(vanRun)+"_Raw")
# api.CloneWorkspace(InputWorkspace=vanRun, OutputWorkspace=str(vanRun)+"_Raw")
vanRun = api.StripVanadiumPeaks(InputWorkspace=vanRun, OutputWorkspace=vanRun, FWHM=self._vanPeakFWHM,
PeakPositionTolerance=self.getProperty("VanadiumPeakTol").value,
BackgroundType="Quadratic", HighBackground=True)
api.CloneWorkspace(InputWorkspace=vanRun, OutputWorkspace=str(vanRun)+"_PostStrip")
# api.CloneWorkspace(InputWorkspace=vanRun, OutputWorkspace=str(vanRun)+"_PostStrip")
else:
self.log().information("Not strip vanadium peaks")
vanRun = api.ConvertUnits(InputWorkspace=vanRun, OutputWorkspace=vanRun, Target="TOF")
Expand All @@ -546,10 +568,6 @@ def PyExec(self):
else:
vanRun = None

for iws in xrange(samRun.getNumberHistograms()):
spec1 = samRun.getSpectrum(iws)
self.log().information("[DBx157] ws %d: sample spectrum ID = %d;" % ( iws, spec1.getSpectrumNo()))

if HAVE_MPI:
if rank > 0:
return
Expand All @@ -570,18 +588,10 @@ def PyExec(self):
else:
normalized = False

for iws in xrange(samRun.getNumberHistograms()):
spec1 = samRun.getSpectrum(iws)
self.log().information("[DBx209] ws %d: sample spectrum ID = %d;" % ( iws, spec1.getSpectrumNo() ))

if not "histo" in SUFFIX and preserveEvents and HAVE_MPI is False:
samRun = api.CompressEvents(InputWorkspace=samRun, OutputWorkspace=samRun,
Tolerance=COMPRESS_TOL_TOF) # 5ns/

for iws in xrange(samRun.getNumberHistograms()):
spec1 = samRun.getSpectrum(iws)
self.log().information("[DBx210] ws %d: sample spectrum ID = %d;" % ( iws, spec1.getSpectrumNo() ))

# make sure there are no negative values - gsas hates them
if self.getProperty("PushDataPositive").value != "None":
addMin = (self.getProperty("PushDataPositive").value == "AddMinimum")
Expand All @@ -598,20 +608,13 @@ def PyExec(self):
samRun = str(samRun)
#mtd.releaseFreeMemory()

for iws in xrange(samRunws.getNumberHistograms()):
spec1 = samRunws.getSpectrum(iws)
self.log().information("[DBx211] ws %s spec %d-th: sample spectrum ID = %d;" % ( str(samRunws), iws, spec1.getSpectrumNo() ))

# ENDFOR

# convert everything into d-spacing
workspacelist = set(workspacelist) # only do each workspace once
if HAVE_MPI is False:
for wksp in workspacelist:
wksp = api.ConvertUnits(InputWorkspace=wksp, OutputWorkspace=wksp, Target=self.getProperty("FinalDataUnits").value)
for iws in xrange(wksp.getNumberHistograms()):
spec1 = wksp.getSpectrum(iws)
self.log().information("[DBx212] ws %s spec %d-th: sample spectrum ID = %d;" % ( str(wksp), iws, spec1.getSpectrumNo() ))

return

Expand Down Expand Up @@ -810,37 +813,9 @@ def _focusChunks(self, runnumber, extension, filterWall, calib, splitwksp=None,
temp = tempwslist[itemp]
# Align and focus
self.log().information("[F1141] Align and focus workspace %s; Number of events = %d of chunk %d " % (str(temp), temp.getNumberEvents(), ichunk))
# print "[DB1141] Align and focus workspace %s; Number of events = %d of chunk %d " % (str(temp), temp.getNumberEvents(), ichunk)

self._lowResTOFoffset = self.getProperty("LowResolutionSpectraOffset").value

focuspos = self._config.getFocusPos()

if self._lowResTOFoffset >= 0:
print "Reducing Low resolution TOF"

# Dealing with the parameters for editing instrument parameters
if focuspos.has_key("PrimaryFlightPath") is True:
l1 = focuspos["PrimaryFlightPath"]
if l1 > 0:
specids = focuspos['SpectrumIDs']
l2s = focuspos['L2']
polars = focuspos['Polar']
phis = focuspos['Azimuthal']

specids.extend(specids)
l2s.extend(l2s)
polars.extend(polars)
phis.extend(phis)

focuspos['SpectrumIDs'] = specids
focuspos['L2'] = l2s
focuspos['Polar'] = polars
focuspos['Azimuthal'] = phis

else:
print "Ignoring Low resolution TOF"

temp = api.AlignAndFocusPowder(InputWorkspace=temp, OutputWorkspace=temp, CalFileName=calib,
Params=self._binning, ResampleX=self._resampleX, Dspacing=self._bin_in_dspace,
DMin=self._info.dmin, DMax=self._info.dmax, TMin=self._info.tmin, TMax=self._info.tmax,
Expand All @@ -853,20 +828,6 @@ def _focusChunks(self, runnumber, extension, filterWall, calib, splitwksp=None,
spec = temp.getSpectrum(iws)
self.log().debug("[DBx131] ws %d: spectrum ID = %d. " % (iws, spec.getSpectrumNo()))

# if self._outputLowResTOF is True:
# temphighws = tempout[0]
# templowws = tempout[1]
# temp = api.AppendSpectra(InputWorkspace1=temphighws, InputWorkspace2=templowws, OutputWorkspace=str(temphighws))
# api.DeleteWorkspace(Workspace=str(templowws))
# else:
# temp = tempout

# try:
# if temp.__class__.__name__.count("IEvent") > 0:
# print "[DB1050-3] Number of events = %d of chunk %d" % (temp.getNumberEvents(), ichunk)
# except RuntimeError:
# print "[DB1050-3] Not an event workspace."

# Rename and/or add to workspace of same splitter but different chunk
wkspname = wksp
if numwksp > 1:
Expand Down Expand Up @@ -932,7 +893,7 @@ def _focusChunks(self, runnumber, extension, filterWall, calib, splitwksp=None,
# except Exception as e:
# print e

self.log().information("[F1207] Number of workspace in workspace list after clean = %d. " %(len(wksplist)))
self.log().information("[E1207] Number of workspace in workspace list after clean = %d. " %(len(wksplist)))

# About return
if splitwksp is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,22 +572,37 @@ namespace WorkflowAlgorithms
{
size_t numlow = m_lowResW->getNumberHistograms();
// FIXME : There must be some bug in constructing the vectors for EditInstrumentGeometry
#if 0

// Check size
if (tths.size() < numreg+numlow)
throw std::runtime_error("Input number of 2thetas is smaller than number of histogram (low).");
if (l2s.size() < numreg+numlow)
size_t numall = numreg+numlow;
g_log.information() << "[DBx931] Num-All = " << numall << ".\n";
if (tths.size() != numall)
{
std::stringstream errss;
errss << "Input number of 2thetas (" << tths.size() << " is not equal to "
<< "the number of normal and low resolution histograms " << numall << ".\n";
for (size_t i = 0; i < tths.size(); ++i)
{
errss << "2theta[" << i << "] = " << tths[i] << "\n";
}
g_log.error(errss.str());
throw std::runtime_error(errss.str());
}
if (l2s.size() != numall)
throw std::runtime_error("Input number of L2s is smaller than number of histogram (low).");
if (phis.size() < numreg+numlow)
if (phis.size() != numall)
throw std::runtime_error("Input number of azimuthals is smaller than number of histogram (low).");

std::vector<int32_t> vec_specid_low;
if (specids.size() == numreg+numlow)
if (specids.size() == numall)
{
vec_specid_low.resize(numlow, 0);
std::copy((specids.begin()+numreg), specids.end(), vec_specid_low.begin());
// vec_specid_low.resize(numlow, 0);
// std::copy((specids.begin()+numreg), specids.end(), vec_specid_low.begin());
for (size_t i = 0; i < numlow; ++i)
{
vec_specid_low.push_back(specids[numreg+i]);
g_log.information() << i << " : " << vec_specid_low[i] << ".\n";
}
}
else if (specids.size() == 0)
{
Expand All @@ -600,6 +615,7 @@ namespace WorkflowAlgorithms
<< ", LowResW's size = " << numlow << ".\n";
}

#if 0
std::vector<double> vec_polar_low(numlow, 0.);
std::copy((tths.begin()+numreg), tths.end(), vec_polar_low.begin());
for (size_t i = 0; i < numlow; ++i)
Expand All @@ -614,26 +630,26 @@ namespace WorkflowAlgorithms
std::copy((phis.begin()+numreg), phis.end(), vec_azimuthal_low.begin());
for (size_t i = 0; i < numlow; ++i)
g_log.information() << i << " : " << vec_azimuthal_low[i] << ".\n";
#else
std::vector<double> vec_polar_low, vec_l2_low, vec_azimuthal_low;
for (size_t i = 0; i < numlow; ++i)
{
vec_polar_low.push_back(tths[numreg+i]);
vec_l2_low.push_back(l2s[numreg+i]);
vec_azimuthal_low.push_back(phis[numreg+i]);
}
#endif

#if 0
API::IAlgorithm_sptr editAlg = createChildAlgorithm("EditInstrumentGeometry");
editAlg->setProperty("Workspace", m_lowResW);
editAlg->setProperty("PrimaryFlightPath", l1);
editAlg->setProperty("Polar", vec_polar_low);
editAlg->setProperty("SpectrumIDs", vec_specid_low);
editAlg->setProperty("L2", vec_l2_low);
editAlg->setProperty("Azimuthal", vec_azimuthal_low);
editAlg->executeAsChildAlg();
m_lowResW = editAlg->getProperty("Workspace");
#if 1
g_log.information() << vec_polar_low.size() << ".\n";
g_log.information() << vec_specid_low.size() << ".\n";
g_log.information() << vec_l2_low.size() << ".\n";
g_log.information() << vec_azimuthal_low.size() << ".\n";
m_lowResW = editInstrument(m_lowResW, vec_polar_low, vec_specid_low, vec_l2_low, vec_azimuthal_low);
#else
// g_log.information() << vec_polar_low.size() << ".\n";
// g_log.information() << vec_specid_low.size() << ".\n";
// g_log.information() << vec_l2_low.size() << ".\n";
// g_log.information() << vec_azimuthal_low.size() << ".\n";
// m_lowResW = editInstrument(m_lowResW, vec_polar_low, vec_specid_low, vec_l2_low, vec_azimuthal_low);
m_lowResW = editInstrument(m_lowResW, vec_polar_reg, vec_specid_reg, vec_l2_reg, vec_azimuthal_reg);
#endif

}
}

Expand Down

0 comments on commit 51e9bff

Please sign in to comment.