Skip to content

Commit

Permalink
Fix a crash when an action has dictionaries and is not hashable
Browse files Browse the repository at this point in the history
Refactor the functions to setup a calorimeter and a tracker detector into a
single one since the logic is the same. In this new function, use a
try-except and if the type is not hashable used the default value.
  • Loading branch information
jmcarcell committed Jul 11, 2024
1 parent fe64884 commit 17e5db7
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions DDG4/python/DDG4.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,35 +670,40 @@ def setupDetector(self, name, action, collections=None):
return (seq, acts)
return (seq, acts[0])

def setupCalorimeter(self, name, type=None, collections=None): # noqa: A002
def setupCaloOrTracker(self, name, detType=None, collections=None, isCalo=True): # noqa: A002
"""
Setup subdetector of type 'calorimeter' and assign the proper sensitive action
"""
self.description.sensitiveDetector(str(name))
retType = detType
if detType is None:
retType = self.sensitive_types['calorimeter' if isCalo else 'tracker']
elif detType is not None:
try:
retType = self.sensitive_types[detType]
# KeyError = not found in the dictionary
# TypeError = detType is not a hashable type
except (KeyError, TypeError):
pass
except Exception as X:
raise X
return self.setupDetector(name, retType, collections)

def setupCalorimeter(self, name, caloType=None, collections=None): # noqa: A002
"""
Setup subdetector of type 'calorimeter' and assign the proper sensitive action
\author M.Frank
"""
typ = type # noqa: A002
self.description.sensitiveDetector(str(name))
# sd.setType('calorimeter')
if typ is None:
typ = self.sensitive_types['calorimeter']
elif typ is not None and self.sensitive_types.get(typ):
typ = self.sensitive_types[typ]
return self.setupDetector(name, typ, collections)
return self.setupCaloOrTracker(name, caloType, collections, True)

def setupTracker(self, name, type=None, collections=None): # noqa: A002
def setupTracker(self, name, trackerType=None, collections=None): # noqa: A002
"""
Setup subdetector of type 'tracker' and assign the proper sensitive action
\author M.Frank
"""
typ = type
self.description.sensitiveDetector(str(name))
# sd.setType('tracker')
if typ is None:
typ = self.sensitive_types['tracker']
elif typ is not None and self.sensitive_types.get(typ):
typ = self.sensitive_types[typ]
return self.setupDetector(name, typ, collections)
return self.setupCaloOrTracker(name, trackerType, collections, False)

def _private_setupField(self, field, stepper, equation, prt):
import g4units
Expand Down

0 comments on commit 17e5db7

Please sign in to comment.