Skip to content

Commit

Permalink
DDSim: add checking that files exists to input argument parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
andresailer committed Mar 26, 2024
1 parent 87757a3 commit da34149
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions DDG4/python/DDSim/DD4hepSimulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,10 @@ def parseOptions(self, argv=None):
self._dumpSteeringFile = parsed.dumpSteeringFile

self.compactFile = ConfigHelper.makeList(parsed.compactFile)
self.__checkFilesExist(self.compactFile, fileType='compact')
self.inputFiles = parsed.inputFiles
self.inputFiles = self.__checkFileFormat(self.inputFiles, POSSIBLEINPUTFILES)
self.__checkFilesExist(self.inputFiles, fileType='input')
self.outputFile = parsed.outputFile
self.__checkFileFormat(self.outputFile, ('.root', '.slcio'))
self.runType = parsed.runType
Expand Down Expand Up @@ -539,6 +541,19 @@ def __setMagneticFieldOptions(self, geant4):
field.delta_one_step = self.field.delta_one_step
field.largest_step = self.field.largest_step

def __checkFilesExist(self, fileNames, fileType=''):
"""Make sure all files in the given list exist, add to errorMessage otherwise.
:param list fileNames: list of files to check for existence
:param str fileType: type if file, for nicer error message
"""
if isinstance(fileNames, str):
fileNames = [fileNames]
for fileName in fileNames:
if not os.path.exists(fileName):
self._errorMessages.append(f"ERROR: The {fileType}file '{fileName}' does not exist")

def __checkFileFormat(self, fileNames, extensions):
"""check if the fileName is allowed, note that the filenames are case
sensitive, and in case of hepevt we depend on this to identify short and long versions of the content
Expand Down

0 comments on commit da34149

Please sign in to comment.