Skip to content

Commit

Permalink
Refs #11632. Small fix to PoldiMerge
Browse files Browse the repository at this point in the history
PoldiMerge now skips non-existing log values for comparison but outputs a warning into the log.
  • Loading branch information
Michael Wedel committed Apr 26, 2015
1 parent 0a9177e commit 32c308a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Expand Up @@ -69,6 +69,11 @@ def canMerge(self, leftWorkspace, rightWorkspace):
if not self.timingsMatch(leftWorkspace.dataX(0), rightWorkspace.dataX(0)):
raise RuntimeError("Timings don't match")

# If this option is enabled, don't do any checks
if not self.checkInstruments:
self.log().warning('Instrument check has been disabled.')
return True

leftRun = leftWorkspace.getRun()
rightRun = rightWorkspace.getRun()

Expand Down Expand Up @@ -99,7 +104,7 @@ def instrumentsMatch(self, leftWorkspace, rightWorkspace):
leftInstrument = leftWorkspace.getInstrument()
rightInstrument = rightWorkspace.getInstrument()

return (not self.checkInstruments) or self.instrumentParametersMatch(leftInstrument, rightInstrument)
return self.instrumentParametersMatch(leftInstrument, rightInstrument)

def instrumentParametersMatch(self, leftInstrument, rightInstrument):
if not leftInstrument.getDetector(0).getPos() == rightInstrument.getDetector(0).getPos():
Expand All @@ -119,8 +124,13 @@ def getParameterValue(self, instrument, parameterTuple):

def propertiesMatch(self, leftRun, rightRun):
for propertyName in self.comparedPropertyNames:
if abs(self.getPropertyValue(leftRun.getProperty(propertyName)) - self.getPropertyValue(rightRun.getProperty(propertyName))) > 5e-3:
raise RuntimeError("Property '%s' does not match" % (propertyName))
if leftRun.hasProperty(propertyName) and rightRun.hasProperty(propertyName):
leftProperty = leftRun.getProperty(propertyName)
rightProperty = rightRun.getProperty(propertyName)
if abs(self.getPropertyValue(leftProperty) - self.getPropertyValue(rightProperty)) > 5e-3:
raise RuntimeError("Property '%s' does not match" % (propertyName))
else:
self.log().warning('Property ' + propertyName + ' is not present in data - skipping comparison.')

return True

Expand Down
Expand Up @@ -6,6 +6,7 @@

import numpy as np


class PoldiMergeTest(unittest.TestCase):
def __init__(self, *args):
unittest.TestCase.__init__(self, *args)
Expand Down Expand Up @@ -38,8 +39,9 @@ def __init__(self, *args):

self.goodTimingBadProperties.getRun().addProperty(p, badProperty, True)

def __runMerge__(self, workspaceNames):
return PoldiMerge(WorkspaceNames=workspaceNames, OutputWorkspace="PoldiMergeOutput", CheckInstruments=False)
def __runMerge__(self, workspaceNames, checkInstruments=False):
return PoldiMerge(WorkspaceNames=workspaceNames, OutputWorkspace="PoldiMergeOutput",
CheckInstruments=checkInstruments)

def test_happyCase(self):
output = self.__runMerge__("Base,GoodTiming")
Expand Down Expand Up @@ -84,12 +86,13 @@ def test_timingOffset(self):
self.assertFalse(AnalysisDataService.doesExist("PoldiMergeOutput"))

def test_badProperties(self):
self.assertRaises(RuntimeError, lambda: self.__runMerge__("Base,GoodTimingBadProperties"))
self.assertRaises(RuntimeError, lambda: self.__runMerge__("Base,GoodTimingBadProperties", True))
self.assertFalse(AnalysisDataService.doesExist("PoldiMergeOutput"))

def test_badName(self):
self.assertRaises(RuntimeError, lambda: self.__runMerge__("Base,NotExisting"))
self.assertFalse(AnalysisDataService.doesExist("PoldiMergeOutput"))


if __name__ == '__main__':
unittest.main()

0 comments on commit 32c308a

Please sign in to comment.