Skip to content

Commit

Permalink
FIX: ddsim to exit with non-zero exit code when something went wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
andresailer committed Apr 2, 2024
1 parent d704656 commit 5d1071f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions DDG4/python/DDSim/DD4hepSimulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def run(self):
uiaction = geant4.setupUI(typ="tcsh", vis=False, macro=None, ui=False)
else:
logger.error("unknown runType")
exit(1)
return 1

# User Configuration for the Geant4Phases
uiaction.ConfigureCommands = self.ui._commandsConfigure
Expand Down Expand Up @@ -476,7 +476,7 @@ def run(self):
self.filter.setupFilters(kernel)
except RuntimeError as e:
logger.error("%s", e)
exit(1)
return 1

# =================================================================================
# get lists of trackers and calorimeters in detectorDescription
Expand Down Expand Up @@ -515,8 +515,13 @@ def run(self):

startUpTime, _sysTime, _cuTime, _csTime, _elapsedTime = os.times()

kernel.run()
kernel.terminate()
exitCode = 0
if not kernel.run():
logger.error("Simulation failed!")
exitCode += 1
if not kernel.terminate():
exitCode += 1
logger.error("Termination failed!")

totalTimeUser, totalTimeSys, _cuTime, _csTime, _elapsedTime = os.times()
if self.printLevel <= 3:
Expand All @@ -527,6 +532,7 @@ def run(self):
perEventTime = eventTime / self.numberOfEvents
logger.info("DDSim INFO StartUp Time: %3.2f s, Event Processing: %3.2f s (%3.2f s/Event) "
% (startUpTime, eventTime, perEventTime))
return exitCode

def __setMagneticFieldOptions(self, geant4):
""" create and configure the magnetic tracking setup """
Expand Down
2 changes: 1 addition & 1 deletion DDG4/python/DDSim/bin/ddsim.in.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
RUNNER.parseOptions()

try:
RUNNER.run()
sys.exit(RUNNER.run())
except NameError as e:
if "global name" in str(e):
globalToSet = str(e).split("'")[1]
Expand Down

0 comments on commit 5d1071f

Please sign in to comment.